spana-test 0.7.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. package/dist/agent/index.d.ts +2 -2
  2. package/dist/agent/index.js +9 -9
  3. package/dist/{allure-RNMEYTXS.js → allure-RAEK4SIH.js} +2 -2
  4. package/dist/allure-RAEK4SIH.js.map +1 -0
  5. package/dist/{android-4NVTZMHL.js → android-6BOQTMM3.js} +2 -2
  6. package/dist/app-DSh1ejLh.d.ts +1266 -0
  7. package/dist/{chunk-H27IBIGA.js → chunk-2AFWVHQK.js} +63 -43
  8. package/dist/chunk-2AFWVHQK.js.map +1 -0
  9. package/dist/{chunk-RURZVMZ7.js → chunk-2KRVN4WN.js} +3 -3
  10. package/dist/{chunk-T5CROOR7.js → chunk-3UVSUVHW.js} +1828 -299
  11. package/dist/chunk-3UVSUVHW.js.map +1 -0
  12. package/dist/{chunk-6B5Y75V4.js → chunk-ALPQES3J.js} +1001 -281
  13. package/dist/chunk-ALPQES3J.js.map +1 -0
  14. package/dist/{chunk-2IXXEXTL.js → chunk-FP6PVHHR.js} +2 -2
  15. package/dist/{chunk-KNSAHEXI.js → chunk-IGTK5MHB.js} +8 -8
  16. package/dist/chunk-JPZCZHL4.js +79 -0
  17. package/dist/chunk-JPZCZHL4.js.map +1 -0
  18. package/dist/{chunk-JYFPZRCN.js → chunk-JZZ2W2XH.js} +5 -2
  19. package/dist/chunk-JZZ2W2XH.js.map +1 -0
  20. package/dist/{chunk-HCG4CJKR.js → chunk-SF7UYW4I.js} +3 -3
  21. package/dist/{chunk-T3EBOYLS.js → chunk-UEWZ2EXL.js} +1314 -129
  22. package/dist/chunk-UEWZ2EXL.js.map +1 -0
  23. package/dist/{chunk-HYSTRWYN.js → chunk-VP6V4XEJ.js} +4 -4
  24. package/dist/{chunk-S5JNNDXS.js → chunk-WV3ALL3H.js} +65 -37
  25. package/dist/chunk-WV3ALL3H.js.map +1 -0
  26. package/dist/chunk-Z6K4QQAR.js +358 -0
  27. package/dist/chunk-Z6K4QQAR.js.map +1 -0
  28. package/dist/cli.js +23 -11
  29. package/dist/cli.js.map +1 -1
  30. package/dist/config-loader-F5YAY7RP.js +9 -0
  31. package/dist/{console-MI2XB5RG.js → console-BGAK7Z2L.js} +11 -1
  32. package/dist/{console-MI2XB5RG.js.map → console-BGAK7Z2L.js.map} +1 -1
  33. package/dist/{daemon-manager-FBISTX24.js → daemon-manager-2EQDVUVM.js} +10 -2
  34. package/dist/{discover-LHEBSUIP.js → discover-RLSKEBAX.js} +5 -5
  35. package/dist/{doctor-command-WPEVZEZ4.js → doctor-command-YTCQ2SC7.js} +26 -18
  36. package/dist/doctor-command-YTCQ2SC7.js.map +1 -0
  37. package/dist/{flow-g6AICPAl.d.ts → flow-CSMwD9Fh.d.ts} +3 -29
  38. package/dist/gherkin/steps.d.ts +2 -2
  39. package/dist/{html-IKCTZH2U.js → html-JO2YNRWX.js} +3 -3
  40. package/dist/html-JO2YNRWX.js.map +1 -0
  41. package/dist/index.d.ts +215 -21
  42. package/dist/index.js +246 -147
  43. package/dist/index.js.map +1 -1
  44. package/dist/{installer-VUPFWP5X.js → installer-5UHTYQTB.js} +4 -4
  45. package/dist/{ios-JPK43TFZ.js → ios-Y4TO5MBR.js} +7 -3
  46. package/dist/{server-EBPYK3VE.js → server-4YLBAZEM.js} +50 -36
  47. package/dist/server-4YLBAZEM.js.map +1 -0
  48. package/dist/{server-IGLBFEU7.js → server-IS4K5FCT.js} +2 -2
  49. package/dist/{session-cJ_tZjCL.d.ts → session-CgvT-Oso.d.ts} +3 -1
  50. package/dist/session-K7FCRKOC.js +18 -0
  51. package/dist/{studio-command-FLA5HKRK.js → studio-command-RFPV2DS7.js} +2 -2
  52. package/dist/{test-command-P5W7UD52.js → test-command-UEJG5AI6.js} +223 -27
  53. package/dist/test-command-UEJG5AI6.js.map +1 -0
  54. package/native/darwin-arm64/libspana_native.dylib +0 -0
  55. package/native/darwin-x64/libspana_native.dylib +0 -0
  56. package/native/linux-arm64/libspana_native.so +0 -0
  57. package/native/linux-x64/libspana_native.so +0 -0
  58. package/native/win32-x64/spana_native.dll +0 -0
  59. package/package.json +1 -1
  60. package/studio-dist/assets/index-CBFsOh-9.js +193 -0
  61. package/studio-dist/assets/index-DH_18EyL.css +1 -0
  62. package/studio-dist/index.html +2 -2
  63. package/dist/allure-RNMEYTXS.js.map +0 -1
  64. package/dist/app-D_UyZBsl.d.ts +0 -915
  65. package/dist/chunk-6B5Y75V4.js.map +0 -1
  66. package/dist/chunk-DTNK54C2.js +0 -127
  67. package/dist/chunk-DTNK54C2.js.map +0 -1
  68. package/dist/chunk-H27IBIGA.js.map +0 -1
  69. package/dist/chunk-JYFPZRCN.js.map +0 -1
  70. package/dist/chunk-OBCFACUW.js +0 -28
  71. package/dist/chunk-OBCFACUW.js.map +0 -1
  72. package/dist/chunk-S5JNNDXS.js.map +0 -1
  73. package/dist/chunk-T3EBOYLS.js.map +0 -1
  74. package/dist/chunk-T5CROOR7.js.map +0 -1
  75. package/dist/config-loader-NIDQGP3K.js +0 -9
  76. package/dist/doctor-command-WPEVZEZ4.js.map +0 -1
  77. package/dist/html-IKCTZH2U.js.map +0 -1
  78. package/dist/server-EBPYK3VE.js.map +0 -1
  79. package/dist/session-QRWH3SPW.js +0 -18
  80. package/dist/test-command-P5W7UD52.js.map +0 -1
  81. package/studio-dist/assets/index-C-Io44gy.js +0 -193
  82. package/studio-dist/assets/index-DfM9lK4p.css +0 -1
  83. /package/dist/{android-4NVTZMHL.js.map → android-6BOQTMM3.js.map} +0 -0
  84. /package/dist/{chunk-RURZVMZ7.js.map → chunk-2KRVN4WN.js.map} +0 -0
  85. /package/dist/{chunk-2IXXEXTL.js.map → chunk-FP6PVHHR.js.map} +0 -0
  86. /package/dist/{chunk-KNSAHEXI.js.map → chunk-IGTK5MHB.js.map} +0 -0
  87. /package/dist/{chunk-HCG4CJKR.js.map → chunk-SF7UYW4I.js.map} +0 -0
  88. /package/dist/{chunk-HYSTRWYN.js.map → chunk-VP6V4XEJ.js.map} +0 -0
  89. /package/dist/{config-loader-NIDQGP3K.js.map → config-loader-F5YAY7RP.js.map} +0 -0
  90. /package/dist/{daemon-manager-FBISTX24.js.map → daemon-manager-2EQDVUVM.js.map} +0 -0
  91. /package/dist/{discover-LHEBSUIP.js.map → discover-RLSKEBAX.js.map} +0 -0
  92. /package/dist/{installer-VUPFWP5X.js.map → installer-5UHTYQTB.js.map} +0 -0
  93. /package/dist/{ios-JPK43TFZ.js.map → ios-Y4TO5MBR.js.map} +0 -0
  94. /package/dist/{server-IGLBFEU7.js.map → server-IS4K5FCT.js.map} +0 -0
  95. /package/dist/{session-QRWH3SPW.js.map → session-K7FCRKOC.js.map} +0 -0
  96. /package/dist/{studio-command-FLA5HKRK.js.map → studio-command-RFPV2DS7.js.map} +0 -0
package/dist/index.js CHANGED
@@ -1,24 +1,34 @@
1
1
  import {
2
+ DEFAULT_MAX_WORKERS_PER_PROCESS,
3
+ UPLOAD_ATTACH_TIMEOUT_MS,
2
4
  buildPlaybackTraceFromSteps,
5
+ createRemoteFlowClaimer,
3
6
  exportFramesToMp4,
7
+ extractCodeFrame,
8
+ formatCodeFrame,
4
9
  launchDirectCdpBrowser,
5
10
  makeLightweightCdpDriver,
6
11
  orderFlowsLongestFirst,
12
+ partitionFlowsAcrossProcesses,
13
+ planProcessPool,
7
14
  resolveWebEngine,
15
+ runMultiProcessPool,
8
16
  speculativelyPrelaunchWebBrowser,
9
17
  startAndroidVideoRecorder,
10
18
  startCdpScreencastRecorder,
11
- startIosSimulatorVideoRecorder
12
- } from "./chunk-6B5Y75V4.js";
19
+ startIosSimulatorVideoRecorder,
20
+ startSharedFlowQueueServer,
21
+ writeWorkerProcessReport
22
+ } from "./chunk-ALPQES3J.js";
13
23
  import {
14
24
  SPANA_MCP_TOOLS,
15
25
  SpanaMcpServer,
16
26
  buildFlowFileFromLines,
17
27
  formatSelectorCode
18
- } from "./chunk-RURZVMZ7.js";
28
+ } from "./chunk-2KRVN4WN.js";
19
29
  import {
20
30
  defineConfig
21
- } from "./chunk-JYFPZRCN.js";
31
+ } from "./chunk-JZZ2W2XH.js";
22
32
  import "./chunk-X2TJP7LB.js";
23
33
  import {
24
34
  createGitHubPrReporter,
@@ -37,31 +47,44 @@ import {
37
47
  probabilityFromTopLogprobs
38
48
  } from "./chunk-3SH5JQF7.js";
39
49
  import {
50
+ byCss,
51
+ byRole,
40
52
  connectPlaywrightOverCDP,
41
53
  connectPlaywrightOverWS,
42
54
  domRectToScreenBounds,
43
55
  ensureWarmBrowserDaemon,
56
+ filterSelector,
44
57
  findWebViewFrame,
58
+ first,
59
+ inFrame,
45
60
  invalidateWebViewFrameCache,
61
+ isComposableDomSelector,
46
62
  isOffscreenInViewport,
47
63
  isSystemUISelector,
48
64
  isTestIDSelector,
65
+ last,
49
66
  launchPlaywrightBrowser,
50
67
  makeElectronDriver,
68
+ nth,
69
+ or,
51
70
  resolveElementAcrossChannels,
52
- systemUI
53
- } from "./chunk-T5CROOR7.js";
71
+ systemUI,
72
+ within
73
+ } from "./chunk-3UVSUVHW.js";
54
74
  import {
55
75
  AndroidWebViewCdpChannel,
56
76
  AppleWebInspectorClient,
57
77
  CdpDomChannel,
78
+ SPANA_INJECTED_RUNTIME_SCRIPT,
58
79
  SpanaBridgeChannel,
59
80
  TARGET_CHANNEL_MATRIX,
60
81
  WebKitInspectorChannel,
82
+ buildDomActionabilityDiagScript,
61
83
  buildDomFillScript,
62
84
  buildDomWaitForHiddenScript,
63
85
  buildDomWaitForMatchScript,
64
86
  buildDomWaitForSelectorScript,
87
+ buildInjectedCallScript,
65
88
  createAndroidWebViewCdpChannel,
66
89
  createCdpDomChannel,
67
90
  createCompositeDomChannel,
@@ -77,24 +100,35 @@ import {
77
100
  resolveElectrobunEngine,
78
101
  resolveElectrobunLaunchPlan,
79
102
  resolveTargetDescriptor
80
- } from "./chunk-T3EBOYLS.js";
81
- import "./chunk-HYSTRWYN.js";
103
+ } from "./chunk-UEWZ2EXL.js";
104
+ import "./chunk-VP6V4XEJ.js";
82
105
  import {
106
+ DEFAULT_WARM_DAEMON_IDLE_TTL_MS,
107
+ defaultDaemonStateDir,
83
108
  getHealthyWarmDaemon,
84
109
  listWarmDaemons,
110
+ reapIdleWarmDaemons,
85
111
  stopAllWarmDaemons,
86
112
  stopWarmDaemon,
113
+ sweepOrphanedSpanaBrowsers,
87
114
  updateWarmDaemonSession
88
- } from "./chunk-DTNK54C2.js";
89
- import "./chunk-S5JNNDXS.js";
90
- import "./chunk-OBCFACUW.js";
115
+ } from "./chunk-Z6K4QQAR.js";
116
+ import {
117
+ cloneIOSSimulator,
118
+ deleteIOSSimulator
119
+ } from "./chunk-WV3ALL3H.js";
120
+ import {
121
+ allocateFreePort,
122
+ assertPortAvailable,
123
+ isPortAvailable
124
+ } from "./chunk-JPZCZHL4.js";
91
125
  import {
92
126
  comparePngNative,
93
127
  getNativeAcceleratorPath,
94
128
  isNativeAcceleratorActive,
95
129
  tokenizeXmlNative
96
130
  } from "./chunk-54ASKII6.js";
97
- import "./chunk-H27IBIGA.js";
131
+ import "./chunk-2AFWVHQK.js";
98
132
  import "./chunk-DGUM43GV.js";
99
133
 
100
134
  // src/api/flow.ts
@@ -116,8 +150,10 @@ var Bounds = Schema.Struct({
116
150
  var Element = Schema.Struct({
117
151
  id: Schema.optional(Schema.String),
118
152
  text: Schema.optional(Schema.String),
153
+ textContent: Schema.optional(Schema.String),
119
154
  value: Schema.optional(Schema.String),
120
155
  accessibilityLabel: Schema.optional(Schema.String),
156
+ accessibleDescription: Schema.optional(Schema.String),
121
157
  resourceId: Schema.optional(Schema.String),
122
158
  elementType: Schema.optional(Schema.String),
123
159
  bounds: Bounds,
@@ -244,8 +280,8 @@ function extractDestructuredParamNames(fn) {
244
280
  }
245
281
  token += ch;
246
282
  }
247
- const last = parseDestructuredKey(token);
248
- if (last) names.push(last);
283
+ const last2 = parseDestructuredKey(token);
284
+ if (last2) names.push(last2);
249
285
  return names;
250
286
  }
251
287
  function parseDestructuredKey(raw) {
@@ -433,9 +469,55 @@ function createApiFixture(options) {
433
469
  function definePersona(name, config) {
434
470
  return { name, ...config };
435
471
  }
472
+ function toImportableCredentials(creds) {
473
+ if (!creds) return [];
474
+ return creds.filter(
475
+ (c) => typeof c.privateKey === "string" && c.privateKey.length > 0
476
+ ).map((c) => ({
477
+ credentialId: c.credentialId,
478
+ isResidentCredential: c.isResidentCredential,
479
+ privateKey: c.privateKey,
480
+ signCount: c.signCount,
481
+ ...c.rpId !== void 0 ? { rpId: c.rpId } : {},
482
+ ...c.userHandle !== void 0 ? { userHandle: c.userHandle } : {},
483
+ ...c.userName !== void 0 ? { userName: c.userName } : {}
484
+ }));
485
+ }
486
+ var VirtualCredentialStore = class {
487
+ store = /* @__PURE__ */ new Map();
488
+ save(persona, credentials) {
489
+ const importable = toImportableCredentials(credentials);
490
+ if (importable.length > 0) {
491
+ this.store.set(persona, importable);
492
+ }
493
+ }
494
+ get(persona) {
495
+ return [...this.store.get(persona) ?? []];
496
+ }
497
+ has(persona) {
498
+ return (this.store.get(persona)?.length ?? 0) > 0;
499
+ }
500
+ clear(persona) {
501
+ if (!persona) {
502
+ this.store.clear();
503
+ return;
504
+ }
505
+ this.store.delete(persona);
506
+ }
507
+ async restore(persona, app, opts) {
508
+ const creds = this.store.get(persona);
509
+ if (!creds || creds.length === 0) return 0;
510
+ const authId = await app.enableVirtualAuthenticator(opts);
511
+ for (const cred of creds) {
512
+ await app.addVirtualCredential(cred, authId);
513
+ }
514
+ return creds.length;
515
+ }
516
+ };
436
517
  var PersonaAuthCache = class {
437
518
  cache = /* @__PURE__ */ new Map();
438
519
  inflight = /* @__PURE__ */ new Map();
520
+ credentials = new VirtualCredentialStore();
439
521
  keyFor(persona) {
440
522
  return `${persona.name}::${persona.cacheKey ?? "default"}`;
441
523
  }
@@ -445,16 +527,20 @@ var PersonaAuthCache = class {
445
527
  invalidate(name, cacheKey = "default") {
446
528
  if (!name) {
447
529
  this.cache.clear();
530
+ this.credentials.clear();
448
531
  return;
449
532
  }
450
533
  this.cache.delete(`${name}::${cacheKey}`);
534
+ this.credentials.clear(`${name}::${cacheKey}`);
451
535
  }
452
536
  /**
453
537
  * Ensure `persona` is authenticated in `ctx`. On cache miss, executes `persona.signIn(ctx)`
454
- * once (coalescing concurrent callers); on cache hit, restores cookies/storageState directly.
538
+ * once (coalescing concurrent callers); on cache hit, restores cookies/storageState and
539
+ * imports any stored WebAuthn virtual passkeys directly into the fresh context.
455
540
  */
456
541
  async authenticate(persona, ctx) {
457
542
  const key = this.keyFor(persona);
543
+ const app = ctx.app;
458
544
  let state = this.cache.get(key);
459
545
  let wasMiss = false;
460
546
  if (!state) {
@@ -463,9 +549,23 @@ var PersonaAuthCache = class {
463
549
  if (!pending) {
464
550
  pending = (async () => {
465
551
  const produced = await persona.signIn(ctx) ?? {};
552
+ let virtualCredentials = produced.virtualCredentials;
553
+ if (!virtualCredentials && persona.captureVirtualCredentials !== false && ctx.platform === "web") {
554
+ try {
555
+ const captured = await app.getVirtualCredentials();
556
+ if (captured.length > 0) {
557
+ virtualCredentials = captured;
558
+ }
559
+ } catch {
560
+ }
561
+ }
562
+ if (virtualCredentials && virtualCredentials.length > 0) {
563
+ this.credentials.save(key, virtualCredentials);
564
+ }
466
565
  const entry = {
467
566
  storage: produced.storage,
468
567
  storageStatePath: produced.storageStatePath,
568
+ virtualCredentials,
469
569
  cachedAt: Date.now()
470
570
  };
471
571
  this.cache.set(key, entry);
@@ -477,7 +577,6 @@ var PersonaAuthCache = class {
477
577
  }
478
578
  state = await pending;
479
579
  }
480
- const app = ctx.app;
481
580
  if (!wasMiss) {
482
581
  if (state.storageStatePath && ctx.platform === "web") {
483
582
  await app.loadAuthState(state.storageStatePath);
@@ -485,6 +584,9 @@ var PersonaAuthCache = class {
485
584
  if (state.storage) {
486
585
  await app.setStorage(state.storage);
487
586
  }
587
+ if (ctx.platform === "web" && this.credentials.has(key)) {
588
+ await this.credentials.restore(key, app, persona.authenticatorOptions);
589
+ }
488
590
  }
489
591
  if (persona.navigateTo) {
490
592
  await app.openLink(persona.navigateTo);
@@ -719,141 +821,106 @@ var ReplaySession = class {
719
821
  }
720
822
  };
721
823
 
722
- // src/core/worker-pool.ts
723
- import { spawn } from "child_process";
724
- import { existsSync as existsSync2, readFileSync as readFileSync2, unlinkSync } from "fs";
725
- var DEFAULT_MAX_WORKERS_PER_PROCESS = 8;
726
- function planProcessPool(totalWorkers, maxWorkersPerProcess = DEFAULT_MAX_WORKERS_PER_PROCESS) {
727
- const safeTotal = Math.max(1, Math.floor(totalWorkers));
728
- const safeMax = Math.max(1, Math.floor(maxWorkersPerProcess));
729
- if (safeTotal <= safeMax) {
730
- return {
731
- totalWorkers: safeTotal,
732
- maxWorkersPerProcess: safeMax,
733
- processCount: 1,
734
- workersPerProcess: [safeTotal]
735
- };
736
- }
737
- const processCount = Math.ceil(safeTotal / safeMax);
738
- const base = Math.floor(safeTotal / processCount);
739
- const remainder = safeTotal % processCount;
740
- const workersPerProcess = Array.from(
741
- { length: processCount },
742
- (_v, i) => base + (i < remainder ? 1 : 0)
743
- );
744
- return {
745
- totalWorkers: safeTotal,
746
- maxWorkersPerProcess: safeMax,
747
- processCount,
748
- workersPerProcess
749
- };
824
+ // src/core/network-cache.ts
825
+ import { createHash as createHash2 } from "crypto";
826
+ import { existsSync as existsSync2, mkdirSync as mkdirSync2, readFileSync as readFileSync2, writeFileSync as writeFileSync2 } from "fs";
827
+ import { join as join2 } from "path";
828
+ function buildNetworkCacheKey(method, url) {
829
+ const normalizedMethod = method.toUpperCase();
830
+ const hash = createHash2("sha256").update(`${normalizedMethod} ${url}`).digest("hex").slice(0, 16);
831
+ const slug = url.replace(/^https?:\/\//, "").replaceAll(/[^a-zA-Z0-9-_]/g, "_").replaceAll(/_+/g, "_").slice(0, 48);
832
+ return `${normalizedMethod.toLowerCase()}-${slug}-${hash}`;
750
833
  }
751
- function partitionFlowsAcrossProcesses(items, processCount, options) {
752
- const count = Math.max(1, Math.min(Math.floor(processCount), Math.max(1, items.length)));
753
- if (count === 1 || items.length === 0) {
754
- return items.length === 0 ? [] : [items];
755
- }
756
- const hints = options?.durationHintsMs;
757
- const getName = options?.getName;
758
- const known = hints ? Object.values(hints).filter((v) => typeof v === "number" && v > 0) : [];
759
- const defaultWeight = known.length > 0 ? known.reduce((a, b) => a + b, 0) / known.length : 1e3;
760
- const indexed = items.map((item, idx) => ({
761
- item,
762
- idx,
763
- weight: hints && getName ? hints[getName(item)] ?? defaultWeight : 1e3
764
- }));
765
- const ordered = hints && getName && Object.keys(hints).length > 0 ? indexed.toSorted((a, b) => b.weight - a.weight || a.idx - b.idx) : indexed;
766
- const loads = Array.from({ length: count }, () => 0);
767
- const buckets = Array.from({ length: count }, () => []);
768
- for (const entry of ordered) {
769
- let best = 0;
770
- for (let i = 1; i < count; i++) {
771
- if (loads[i] < loads[best]) best = i;
772
- }
773
- loads[best] = loads[best] + entry.weight;
774
- buckets[best].push({ item: entry.item, idx: entry.idx });
834
+ var NetworkReplayCache = class {
835
+ cacheDir;
836
+ constructor(options = {}) {
837
+ this.cacheDir = options.cacheDir ?? join2(process.cwd(), ".spana", "network-cache");
775
838
  }
776
- return buckets.map((bucket) => bucket.toSorted((a, b) => a.idx - b.idx).map((e) => e.item)).filter((b) => b.length > 0);
777
- }
778
- function defaultReadJsonReport(reportJsonPath) {
779
- if (!existsSync2(reportJsonPath)) return [];
780
- const raw = JSON.parse(readFileSync2(reportJsonPath, "utf8"));
781
- return Array.isArray(raw.results) ? raw.results : [];
782
- }
783
- async function runMultiProcessPool(options) {
784
- const plan = planProcessPool(options.totalWorkers, options.maxWorkersPerProcess);
785
- const spawnFn = options.spawnFn ?? spawn;
786
- const readReport = options.readReportFn ?? defaultReadJsonReport;
787
- const shouldCleanup = options.cleanupReportFiles !== false;
788
- const startedAt = Date.now();
789
- const processResults = await Promise.all(
790
- plan.workersPerProcess.map(async (workerCount, shardIdx) => {
791
- const shardStart = Date.now();
792
- const spec = options.buildShardCommand(shardIdx + 1, plan.processCount, workerCount);
793
- let exitCode = null;
794
- let spawnError;
795
- try {
796
- exitCode = await new Promise((resolve, reject) => {
797
- const child = spawnFn(spec.command, spec.args, {
798
- env: { ...process.env, ...spec.env },
799
- stdio: "inherit"
800
- });
801
- child.on("error", reject);
802
- child.on("close", (code) => resolve(code));
803
- });
804
- } catch (err) {
805
- spawnError = err instanceof Error ? err.message : String(err);
806
- }
807
- let shardResults = [];
808
- try {
809
- shardResults = readReport(spec.reportJsonPath);
810
- } catch (err) {
811
- if (!spawnError) {
812
- spawnError = `Failed to parse shard ${shardIdx + 1} report: ${err instanceof Error ? err.message : String(err)}`;
813
- }
814
- }
815
- if (shouldCleanup) {
816
- try {
817
- if (existsSync2(spec.reportJsonPath)) unlinkSync(spec.reportJsonPath);
818
- } catch {
819
- }
839
+ entryPath(key) {
840
+ return join2(this.cacheDir, `${key}.json`);
841
+ }
842
+ get(method, url) {
843
+ const key = buildNetworkCacheKey(method, url);
844
+ const filePath = this.entryPath(key);
845
+ if (!existsSync2(filePath)) return null;
846
+ try {
847
+ const parsed = JSON.parse(readFileSync2(filePath, "utf8"));
848
+ if (parsed && parsed.version === 1 && typeof parsed.body === "string") {
849
+ return parsed;
820
850
  }
821
- if (exitCode !== 0 && shardResults.length === 0) {
822
- shardResults.push({
823
- name: `worker-process-${shardIdx + 1}`,
824
- platform: "web",
825
- status: "failed",
826
- durationMs: Date.now() - shardStart,
827
- error: {
828
- category: "driver-error",
829
- message: spawnError ?? `Worker process ${shardIdx + 1} exited with code ${exitCode ?? "unknown"}`
830
- }
831
- });
851
+ } catch {
852
+ }
853
+ return null;
854
+ }
855
+ set(entry) {
856
+ mkdirSync2(this.cacheDir, { recursive: true });
857
+ const key = buildNetworkCacheKey(entry.method, entry.url);
858
+ const record = {
859
+ version: 1,
860
+ key,
861
+ method: entry.method.toUpperCase(),
862
+ url: entry.url,
863
+ status: entry.status,
864
+ contentType: entry.contentType,
865
+ ...entry.headers ? { headers: entry.headers } : {},
866
+ body: entry.body,
867
+ recordedAt: (/* @__PURE__ */ new Date()).toISOString()
868
+ };
869
+ writeFileSync2(this.entryPath(key), JSON.stringify(record, null, 2), "utf8");
870
+ return record;
871
+ }
872
+ /**
873
+ * Fetch an endpoint live on cache miss (in `"record"` or `"auto"` mode) or return
874
+ * the cached response in <1ms on cache hit (in `"replay"` or `"auto"` mode).
875
+ */
876
+ async resolve(url, options) {
877
+ const method = (options?.method ?? "GET").toUpperCase();
878
+ const mode = options?.mode ?? "auto";
879
+ if (mode !== "record") {
880
+ const hit = this.get(method, url);
881
+ if (hit) return { entry: hit, source: "cache" };
882
+ if (mode === "replay") {
883
+ throw new Error(`NetworkReplayCache miss in strict replay mode for ${method} ${url}`);
832
884
  }
833
- return {
834
- shardIndex: shardIdx + 1,
835
- workerCount,
836
- exitCode,
837
- durationMs: Date.now() - shardStart,
838
- results: shardResults,
839
- ...spawnError ? { error: spawnError } : {}
840
- };
841
- })
842
- );
843
- const results = processResults.flatMap((p) => p.results);
844
- const passed = results.filter((r) => r.status === "passed").length;
845
- const failed = results.filter((r) => r.status === "failed").length;
846
- const skipped = results.filter((r) => r.status === "skipped").length;
847
- const flaky = results.filter((r) => r.flaky).length;
885
+ }
886
+ const fetchFn = options?.fetchFn ?? fetch;
887
+ const res = await fetchFn(url, { method, headers: options?.headers });
888
+ const body = await res.text();
889
+ const contentType = res.headers.get("content-type") ?? "application/json";
890
+ const entry = this.set({
891
+ method,
892
+ url,
893
+ status: res.status,
894
+ contentType,
895
+ body
896
+ });
897
+ return { entry, source: "network" };
898
+ }
899
+ };
900
+ async function attachNetworkReplayCache(app, options) {
901
+ const cache = new NetworkReplayCache({ cacheDir: options.cacheDir });
902
+ let cacheHits = 0;
903
+ let networkFetches = 0;
904
+ for (const route of options.routes) {
905
+ const { entry, source } = await cache.resolve(route.url, {
906
+ method: route.method,
907
+ mode: options.mode,
908
+ headers: route.headers,
909
+ fetchFn: options.fetchFn
910
+ });
911
+ if (source === "cache") cacheHits += 1;
912
+ else networkFetches += 1;
913
+ await app.mockNetwork(route.matcher ?? route.url, {
914
+ status: entry.status,
915
+ contentType: entry.contentType,
916
+ headers: entry.headers,
917
+ body: entry.body
918
+ });
919
+ }
848
920
  return {
849
- results,
850
- totalDurationMs: Date.now() - startedAt,
851
- passed,
852
- failed,
853
- skipped,
854
- flaky,
855
- processCount: plan.processCount,
856
- processResults
921
+ cacheHits,
922
+ networkFetches,
923
+ totalRoutes: options.routes.length
857
924
  };
858
925
  }
859
926
  export {
@@ -861,24 +928,38 @@ export {
861
928
  AppleWebInspectorClient,
862
929
  CdpDomChannel,
863
930
  DEFAULT_MAX_WORKERS_PER_PROCESS,
931
+ DEFAULT_WARM_DAEMON_IDLE_TTL_MS,
932
+ NetworkReplayCache,
864
933
  PersonaAuthCache,
865
934
  ReplayCacheStore,
866
935
  ReplaySession,
936
+ SPANA_INJECTED_RUNTIME_SCRIPT,
867
937
  SPANA_MCP_TOOLS,
868
938
  SpanaBridgeChannel,
869
939
  SpanaMcpServer,
870
940
  TARGET_CHANNEL_MATRIX,
941
+ UPLOAD_ATTACH_TIMEOUT_MS,
942
+ VirtualCredentialStore,
871
943
  WebKitInspectorChannel,
944
+ allocateFreePort,
872
945
  applyNamedSetup,
873
946
  applyTestFilters,
947
+ assertPortAvailable,
948
+ attachNetworkReplayCache,
949
+ buildDomActionabilityDiagScript,
874
950
  buildDomFillScript,
875
951
  buildDomWaitForHiddenScript,
876
952
  buildDomWaitForMatchScript,
877
953
  buildDomWaitForSelectorScript,
878
954
  buildFilterCandidates,
879
955
  buildFlowFileFromLines,
956
+ buildInjectedCallScript,
957
+ buildNetworkCacheKey,
880
958
  buildPlaybackTraceFromSteps,
881
959
  buildReplayCacheKey,
960
+ byCss,
961
+ byRole,
962
+ cloneIOSSimulator,
882
963
  collectGitChanges,
883
964
  comparePngNative,
884
965
  connectPlaywrightOverCDP,
@@ -892,39 +973,52 @@ export {
892
973
  createGitHubPrReporter,
893
974
  createLogprobDecisionJudge,
894
975
  createOllamaDecisionJudge,
976
+ createRemoteFlowClaimer,
895
977
  createSpanaBridgeChannel,
896
978
  createWebKitInspectorChannel,
897
979
  decisionFilter,
898
980
  decodeWebInspectorFrames,
981
+ defaultDaemonStateDir,
899
982
  defineConfig,
900
983
  definePersona,
901
984
  defineSetup,
985
+ deleteIOSSimulator,
902
986
  deterministicImpactFilter,
903
987
  domRectToScreenBounds,
904
988
  encodeWebInspectorPacket,
905
989
  ensureWarmBrowserDaemon,
906
990
  exportFramesToMp4,
991
+ extractCodeFrame,
907
992
  extractDestructuredParamNames,
993
+ filterSelector,
908
994
  findSimulatorWebInspectorSocket,
909
995
  findWebViewFrame,
996
+ first,
910
997
  flow,
998
+ formatCodeFrame,
911
999
  formatFilterSummary,
912
1000
  formatGitHubPrMarkdown,
913
1001
  formatSelectorCode,
914
1002
  formatTargetMatrixTable,
915
1003
  getHealthyWarmDaemon,
916
1004
  getNativeAcceleratorPath,
1005
+ inFrame,
917
1006
  invalidateWebViewFrameCache,
1007
+ isComposableDomSelector,
918
1008
  isNativeAcceleratorActive,
919
1009
  isOffscreenInViewport,
1010
+ isPortAvailable,
920
1011
  isSystemUISelector,
921
1012
  isTestIDSelector,
1013
+ last,
922
1014
  launchDirectCdpBrowser,
923
1015
  launchPlaywrightBrowser,
924
1016
  listWarmDaemons,
925
1017
  makeElectrobunDriver,
926
1018
  makeElectronDriver,
927
1019
  makeLightweightCdpDriver,
1020
+ nth,
1021
+ or,
928
1022
  orderFlowsLongestFirst,
929
1023
  parseAndroidWebViewSockets,
930
1024
  parseWebInspectorXmlFrame,
@@ -932,6 +1026,7 @@ export {
932
1026
  pathRuleFilter,
933
1027
  planProcessPool,
934
1028
  probabilityFromTopLogprobs,
1029
+ reapIdleWarmDaemons,
935
1030
  replayRecordedAction,
936
1031
  resolveElectrobunEngine,
937
1032
  resolveElectrobunLaunchPlan,
@@ -943,10 +1038,14 @@ export {
943
1038
  startAndroidVideoRecorder,
944
1039
  startCdpScreencastRecorder,
945
1040
  startIosSimulatorVideoRecorder,
1041
+ startSharedFlowQueueServer,
946
1042
  stopAllWarmDaemons,
947
1043
  stopWarmDaemon,
1044
+ sweepOrphanedSpanaBrowsers,
948
1045
  systemUI,
949
1046
  tokenizeXmlNative,
950
- updateWarmDaemonSession
1047
+ updateWarmDaemonSession,
1048
+ within,
1049
+ writeWorkerProcessReport
951
1050
  };
952
1051
  //# sourceMappingURL=index.js.map