spana-test 0.8.0 → 0.10.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 (79) hide show
  1. package/dist/agent/index.d.ts +2 -2
  2. package/dist/agent/index.js +7 -7
  3. package/dist/{allure-RAEK4SIH.js → allure-FGVR5LND.js} +5 -1
  4. package/dist/allure-FGVR5LND.js.map +1 -0
  5. package/dist/app-xIYd2jde.d.ts +1309 -0
  6. package/dist/{chunk-3FXDOTFI.js → chunk-66D3C7NB.js} +326 -61
  7. package/dist/chunk-66D3C7NB.js.map +1 -0
  8. package/dist/{chunk-WKVU24B6.js → chunk-6GBAPW6K.js} +12 -8
  9. package/dist/chunk-6GBAPW6K.js.map +1 -0
  10. package/dist/{chunk-2T4K7BJ3.js → chunk-7QFJ7MDH.js} +4 -2
  11. package/dist/chunk-7QFJ7MDH.js.map +1 -0
  12. package/dist/{chunk-AJCSETN6.js → chunk-B35G77DN.js} +1122 -387
  13. package/dist/chunk-B35G77DN.js.map +1 -0
  14. package/dist/{chunk-SNL4X67N.js → chunk-B473XZOM.js} +441 -123
  15. package/dist/chunk-B473XZOM.js.map +1 -0
  16. package/dist/{chunk-Y2RZNOKU.js → chunk-C2HBFEMQ.js} +2 -2
  17. package/dist/{chunk-PLE7RFQE.js → chunk-DP7MGXHN.js} +26 -1
  18. package/dist/chunk-DP7MGXHN.js.map +1 -0
  19. package/dist/{chunk-PMXSU5MS.js → chunk-IXON7DMB.js} +2 -2
  20. package/dist/{chunk-QP4MDUBY.js → chunk-VP6V4XEJ.js} +2 -2
  21. package/dist/{chunk-NS2HLJO4.js → chunk-Y6KMJJ2T.js} +3 -3
  22. package/dist/{chunk-RKYKRGHB.js → chunk-Z6K4QQAR.js} +128 -6
  23. package/dist/chunk-Z6K4QQAR.js.map +1 -0
  24. package/dist/cli.js +17 -12
  25. package/dist/cli.js.map +1 -1
  26. package/dist/config-loader-WLPQ5WVH.js +9 -0
  27. package/dist/{console-BGAK7Z2L.js → console-DIYEJSSP.js} +9 -2
  28. package/dist/console-DIYEJSSP.js.map +1 -0
  29. package/dist/{daemon-manager-DDYQITPD.js → daemon-manager-2EQDVUVM.js} +8 -2
  30. package/dist/{doctor-command-HEQQOYUR.js → doctor-command-QIYBI7ZF.js} +4 -4
  31. package/dist/{flow-Md5xLwbX.d.ts → flow-CI5parw2.d.ts} +24 -3
  32. package/dist/gherkin/steps.d.ts +2 -2
  33. package/dist/{html-JO2YNRWX.js → html-FLMWPFQD.js} +2 -1
  34. package/dist/html-FLMWPFQD.js.map +1 -0
  35. package/dist/index.d.ts +50 -8
  36. package/dist/index.js +43 -13
  37. package/dist/index.js.map +1 -1
  38. package/dist/{installer-IYGMG7LS.js → installer-5UHTYQTB.js} +3 -3
  39. package/dist/{junit-HLC62MK6.js → junit-CGB3LKHD.js} +3 -2
  40. package/dist/junit-CGB3LKHD.js.map +1 -0
  41. package/dist/{runner-TF4OKPYP.js → runner-JID2YWRE.js} +6 -2
  42. package/dist/{server-JPNH33MX.js → server-6KQSTQIG.js} +13 -13
  43. package/dist/{server-4PEREPHY.js → server-UIRGHUYM.js} +2 -2
  44. package/dist/{session-V4PYJXNB.js → session-BE6U34DA.js} +6 -6
  45. package/dist/{session-D9e30RVS.d.ts → session-Bt_mbUWg.d.ts} +3 -1
  46. package/dist/{studio-command-JOIFCOHC.js → studio-command-TXQTIWRS.js} +2 -2
  47. package/dist/{test-command-JCO2HPYI.js → test-command-CCSQPKWU.js} +110 -29
  48. package/dist/test-command-CCSQPKWU.js.map +1 -0
  49. package/dist/{validator-BLOLIHUY.js → validator-YWNHCU2S.js} +3 -3
  50. package/native/win32-x64/spana_native.dll +0 -0
  51. package/package.json +1 -1
  52. package/dist/allure-RAEK4SIH.js.map +0 -1
  53. package/dist/app-CgbLADmF.d.ts +0 -1191
  54. package/dist/chunk-2T4K7BJ3.js.map +0 -1
  55. package/dist/chunk-3FXDOTFI.js.map +0 -1
  56. package/dist/chunk-AJCSETN6.js.map +0 -1
  57. package/dist/chunk-PLE7RFQE.js.map +0 -1
  58. package/dist/chunk-RKYKRGHB.js.map +0 -1
  59. package/dist/chunk-SNL4X67N.js.map +0 -1
  60. package/dist/chunk-WKVU24B6.js.map +0 -1
  61. package/dist/config-loader-5FU45FXK.js +0 -9
  62. package/dist/console-BGAK7Z2L.js.map +0 -1
  63. package/dist/html-JO2YNRWX.js.map +0 -1
  64. package/dist/junit-HLC62MK6.js.map +0 -1
  65. package/dist/test-command-JCO2HPYI.js.map +0 -1
  66. /package/dist/{chunk-Y2RZNOKU.js.map → chunk-C2HBFEMQ.js.map} +0 -0
  67. /package/dist/{chunk-PMXSU5MS.js.map → chunk-IXON7DMB.js.map} +0 -0
  68. /package/dist/{chunk-QP4MDUBY.js.map → chunk-VP6V4XEJ.js.map} +0 -0
  69. /package/dist/{chunk-NS2HLJO4.js.map → chunk-Y6KMJJ2T.js.map} +0 -0
  70. /package/dist/{config-loader-5FU45FXK.js.map → config-loader-WLPQ5WVH.js.map} +0 -0
  71. /package/dist/{daemon-manager-DDYQITPD.js.map → daemon-manager-2EQDVUVM.js.map} +0 -0
  72. /package/dist/{doctor-command-HEQQOYUR.js.map → doctor-command-QIYBI7ZF.js.map} +0 -0
  73. /package/dist/{installer-IYGMG7LS.js.map → installer-5UHTYQTB.js.map} +0 -0
  74. /package/dist/{runner-TF4OKPYP.js.map → runner-JID2YWRE.js.map} +0 -0
  75. /package/dist/{server-JPNH33MX.js.map → server-6KQSTQIG.js.map} +0 -0
  76. /package/dist/{server-4PEREPHY.js.map → server-UIRGHUYM.js.map} +0 -0
  77. /package/dist/{session-V4PYJXNB.js.map → session-BE6U34DA.js.map} +0 -0
  78. /package/dist/{studio-command-JOIFCOHC.js.map → studio-command-TXQTIWRS.js.map} +0 -0
  79. /package/dist/{validator-BLOLIHUY.js.map → validator-YWNHCU2S.js.map} +0 -0
@@ -16,7 +16,7 @@ import {
16
16
  parseWebHierarchy,
17
17
  resolveNetworkConditions,
18
18
  setupUiAutomator2
19
- } from "./chunk-AJCSETN6.js";
19
+ } from "./chunk-B35G77DN.js";
20
20
  import {
21
21
  CdpDomChannel,
22
22
  DriverError,
@@ -24,25 +24,29 @@ import {
24
24
  buildDomFindElementScript,
25
25
  createSpanaBridgeChannel,
26
26
  makeElectrobunDriver
27
- } from "./chunk-SNL4X67N.js";
28
- import {
29
- setupWDA
30
- } from "./chunk-QP4MDUBY.js";
31
- import {
32
- getHealthyWarmDaemon,
33
- registerWarmDaemon,
34
- updateWarmDaemonSession
35
- } from "./chunk-RKYKRGHB.js";
27
+ } from "./chunk-B473XZOM.js";
36
28
  import {
37
29
  connectPhysicalDevice,
38
30
  ensureAppInstalled,
39
31
  ensureIOSSimulator,
40
32
  firstIOSPhysicalDevice
41
33
  } from "./chunk-WV3ALL3H.js";
34
+ import {
35
+ setupWDA
36
+ } from "./chunk-VP6V4XEJ.js";
37
+ import {
38
+ getHealthyWarmDaemon,
39
+ registerWarmDaemon,
40
+ updateWarmDaemonSession
41
+ } from "./chunk-Z6K4QQAR.js";
42
42
  import {
43
43
  allocateFreePort,
44
44
  allocatePort
45
45
  } from "./chunk-JPZCZHL4.js";
46
+ import {
47
+ focusFlows,
48
+ getFlowSkip
49
+ } from "./chunk-DP7MGXHN.js";
46
50
  import {
47
51
  adbReverse,
48
52
  adbReverseRemove,
@@ -51,7 +55,7 @@ import {
51
55
 
52
56
  // src/core/session-manager.ts
53
57
  import { Effect } from "effect";
54
- function createSessions(manager, driverFactory, coordinatorConfig) {
58
+ function createSessions(manager, driverFactory, coordinatorConfig, flowContext) {
55
59
  const coordConfig = coordinatorConfig ?? { parse: parseWebHierarchy };
56
60
  return {
57
61
  async open(opts) {
@@ -63,9 +67,10 @@ function createSessions(manager, driverFactory, coordinatorConfig) {
63
67
  const baseUrl = opts.baseUrl ?? "http://localhost:3000";
64
68
  await Effect.runPromise(driver.launchApp(baseUrl));
65
69
  const app = createPromiseApp(driver, baseUrl, coordConfig, void 0, {
66
- platform: "web"
70
+ platform: "web",
71
+ flowContext
67
72
  });
68
- const expect = createPromiseExpect(driver, coordConfig);
73
+ const expect = createPromiseExpect(driver, coordConfig, void 0, flowContext);
69
74
  const session = {
70
75
  name: opts.name,
71
76
  platform: "web",
@@ -383,6 +388,7 @@ function parseCdpKeyDescriptor(rawKey) {
383
388
  modifiers
384
389
  };
385
390
  }
391
+ var UPLOAD_ATTACH_TIMEOUT_MS = 3e4;
386
392
  var RESOURCE_BLOCK_PATTERNS = {
387
393
  image: ["*.png", "*.jpg", "*.jpeg", "*.gif", "*.webp", "*.svg", "*.ico", "*.avif"],
388
394
  font: ["*.woff", "*.woff2", "*.ttf", "*.otf", "*.eot"],
@@ -430,6 +436,7 @@ function makeLightweightCdpDriver(options) {
430
436
  const jsErrors = [];
431
437
  const routeRules = [];
432
438
  let fetchInterceptEnabled = false;
439
+ let activeResponseWatchers = 0;
433
440
  let nextTabSeq = 1;
434
441
  let downloadDir;
435
442
  const completedDownloads = [];
@@ -618,28 +625,84 @@ function makeLightweightCdpDriver(options) {
618
625
  cdpChannel.onEvent("Target.attachedToTarget", (params) => {
619
626
  const targetInfo = params?.targetInfo;
620
627
  const childSid = params?.sessionId;
628
+ const waiting = Boolean(params?.waitingForDebugger);
621
629
  if (targetInfo?.type === "iframe" && typeof childSid === "string") {
622
630
  cdpChannel.addChildSession(childSid, {
623
631
  targetId: typeof targetInfo.targetId === "string" ? targetInfo.targetId : void 0,
624
632
  url: typeof targetInfo.url === "string" ? targetInfo.url : void 0
625
633
  });
626
- void cdpChannel.sendCommand("Runtime.enable", {}, childSid).catch(() => {
627
- });
628
- if (useInjectedRuntime) {
629
- void cdpChannel.sendCommand(
630
- "Page.addScriptToEvaluateOnNewDocument",
631
- { source: SPANA_INJECTED_RUNTIME_SCRIPT },
632
- childSid
633
- ).catch(() => {
634
+ void (async () => {
635
+ await cdpChannel.sendCommand("Runtime.enable", {}, childSid).catch(() => {
636
+ });
637
+ if (useInjectedRuntime) {
638
+ await cdpChannel.sendCommand(
639
+ "Page.addScriptToEvaluateOnNewDocument",
640
+ { source: SPANA_INJECTED_RUNTIME_SCRIPT },
641
+ childSid
642
+ ).catch(() => {
643
+ });
644
+ }
645
+ if (waiting) {
646
+ await cdpChannel.sendCommand("Runtime.runIfWaitingForDebugger", {}, childSid).catch(() => {
647
+ });
648
+ }
649
+ })();
650
+ } else if (targetInfo?.type === "page" && typeof childSid === "string" && activeSlot && targetInfo.browserContextId === activeSlot.browserContextId) {
651
+ const alreadyTracked = activeSlot.tabs.some(
652
+ (t) => t.sessionId === childSid || t.targetId === targetInfo.targetId
653
+ );
654
+ if (!alreadyTracked) {
655
+ activeSlot.tabs.push({
656
+ tabId: `tab-${nextTabSeq++}`,
657
+ targetId: String(targetInfo.targetId ?? ""),
658
+ sessionId: childSid
634
659
  });
635
660
  }
661
+ void (async () => {
662
+ const setupCalls = [
663
+ cdpChannel.sendCommand("Page.enable", {}, childSid).catch(() => {
664
+ }),
665
+ cdpChannel.sendCommand("Runtime.enable", {}, childSid).catch(() => {
666
+ })
667
+ ];
668
+ if (activeResponseWatchers > 0) {
669
+ setupCalls.push(cdpChannel.sendCommand("Network.enable", {}, childSid).catch(() => {
670
+ }));
671
+ }
672
+ if (useInjectedRuntime) {
673
+ setupCalls.push(
674
+ cdpChannel.sendCommand(
675
+ "Page.addScriptToEvaluateOnNewDocument",
676
+ { source: SPANA_INJECTED_RUNTIME_SCRIPT },
677
+ childSid
678
+ ).catch(() => {
679
+ })
680
+ );
681
+ }
682
+ await Promise.all(setupCalls);
683
+ if (waiting) {
684
+ await cdpChannel.sendCommand("Runtime.runIfWaitingForDebugger", {}, childSid).catch(() => {
685
+ });
686
+ }
687
+ })();
688
+ } else if (waiting && typeof childSid === "string") {
689
+ void cdpChannel.sendCommand("Runtime.runIfWaitingForDebugger", {}, childSid).catch(() => {
690
+ });
636
691
  }
637
692
  });
638
693
  cdpChannel.onEvent("Target.detachedFromTarget", (params) => {
639
694
  if (typeof params?.sessionId === "string") {
640
695
  cdpChannel.removeChildSession(params.sessionId);
696
+ if (activeSlot) {
697
+ activeSlot.tabs = activeSlot.tabs.filter((t) => t.sessionId !== params.sessionId);
698
+ }
641
699
  }
642
700
  });
701
+ cdpChannel.onEvent("Page.javascriptDialogOpening", (params, sid) => {
702
+ const accept = params?.type === "beforeunload";
703
+ void cdpChannel.sendCommand("Page.handleJavaScriptDialog", { accept }, sid ?? null).catch(() => {
704
+ });
705
+ });
643
706
  cdpChannel.setFrameOffsetResolver(async (child) => {
644
707
  if (!child.targetId) return { x: 0, y: 0 };
645
708
  try {
@@ -711,6 +774,20 @@ function makeLightweightCdpDriver(options) {
711
774
  });
712
775
  });
713
776
  if (useContexts) {
777
+ yield* Effect2.tryPromise({
778
+ try: () => cdpChannel.sendCommand(
779
+ "Target.setAutoAttach",
780
+ {
781
+ autoAttach: true,
782
+ waitForDebuggerOnStart: true,
783
+ flatten: true,
784
+ filter: [{ type: "page" }]
785
+ },
786
+ null
787
+ ).catch(() => {
788
+ }),
789
+ catch: () => new DriverError({ message: "Failed to enable Target.setAutoAttach" })
790
+ }).pipe(Effect2.catchAll(() => Effect2.void));
714
791
  activeSlot = yield* Effect2.tryPromise({
715
792
  try: () => createContextSlot(options.storageState),
716
793
  catch: (e) => new DriverError({ message: `Failed to create direct CDP browser context: ${e}` })
@@ -749,8 +826,49 @@ function makeLightweightCdpDriver(options) {
749
826
  fetchInterceptEnabled = true;
750
827
  await cdpChannel.sendCommand("Fetch.enable", { patterns: [{ urlPattern: "*" }] });
751
828
  };
829
+ let coverageSession;
752
830
  const service = {
753
831
  domChannel: cdpChannel,
832
+ startJSCoverage: () => Effect2.tryPromise({
833
+ try: async () => {
834
+ const session = activeSlot?.sessionId ?? null;
835
+ await cdpChannel.sendCommand("Profiler.enable", {}, session);
836
+ try {
837
+ await cdpChannel.sendCommand(
838
+ "Profiler.startPreciseCoverage",
839
+ { callCount: true, detailed: true },
840
+ session
841
+ );
842
+ coverageSession = session;
843
+ } catch (error) {
844
+ await cdpChannel.sendCommand("Profiler.disable", {}, session).catch(() => {
845
+ });
846
+ throw error;
847
+ }
848
+ },
849
+ catch: (error) => new DriverError({ message: `CDP JavaScript coverage is unavailable: ${error}` })
850
+ }),
851
+ stopJSCoverage: () => Effect2.tryPromise({
852
+ try: async () => {
853
+ const session = coverageSession;
854
+ coverageSession = void 0;
855
+ if (session === void 0) throw new Error("JavaScript coverage was not started");
856
+ try {
857
+ const { result } = await cdpChannel.sendCommand(
858
+ "Profiler.takePreciseCoverage",
859
+ {},
860
+ session
861
+ );
862
+ return result.filter(({ url }) => url && !url.startsWith("extensions::"));
863
+ } finally {
864
+ await cdpChannel.sendCommand("Profiler.stopPreciseCoverage", {}, session).catch(() => {
865
+ });
866
+ await cdpChannel.sendCommand("Profiler.disable", {}, session).catch(() => {
867
+ });
868
+ }
869
+ },
870
+ catch: (error) => new DriverError({ message: `CDP JavaScript coverage collection failed: ${error}` })
871
+ }),
754
872
  beginFlow: (_flowName) => Effect2.tryPromise({
755
873
  try: async () => {
756
874
  consoleLogs.length = 0;
@@ -1133,12 +1251,39 @@ function makeLightweightCdpDriver(options) {
1133
1251
  waitForResponse: (matcher, waitOpts) => Effect2.tryPromise({
1134
1252
  try: async () => {
1135
1253
  const timeoutMs = waitOpts?.timeout ?? 15e3;
1136
- const targetSid = activeSlot?.sessionId;
1137
- await cdpChannel.sendCommand("Network.enable").catch(() => {
1138
- });
1254
+ const slotSessions = () => {
1255
+ if (!activeSlot) return null;
1256
+ const set = /* @__PURE__ */ new Set([activeSlot.sessionId]);
1257
+ for (const t of activeSlot.tabs) {
1258
+ if (t.sessionId) set.add(t.sessionId);
1259
+ }
1260
+ return set;
1261
+ };
1262
+ const matchesActiveSlot = (sid) => {
1263
+ const allowed = slotSessions();
1264
+ if (!allowed || !sid) return true;
1265
+ return allowed.has(sid);
1266
+ };
1267
+ activeResponseWatchers += 1;
1268
+ const initialSessions = slotSessions();
1269
+ if (initialSessions && initialSessions.size > 0) {
1270
+ await Promise.all(
1271
+ Array.from(initialSessions).map(
1272
+ (sid) => cdpChannel.sendCommand("Network.enable", {}, sid).catch(() => {
1273
+ })
1274
+ )
1275
+ );
1276
+ } else {
1277
+ await cdpChannel.sendCommand("Network.enable").catch(() => {
1278
+ });
1279
+ }
1139
1280
  const requestMethods = /* @__PURE__ */ new Map();
1140
1281
  return await new Promise((resolve, reject) => {
1282
+ let cleaned = false;
1141
1283
  const cleanup = () => {
1284
+ if (cleaned) return;
1285
+ cleaned = true;
1286
+ activeResponseWatchers = Math.max(0, activeResponseWatchers - 1);
1142
1287
  clearTimeout(timer);
1143
1288
  offReq();
1144
1289
  offRes();
@@ -1148,13 +1293,16 @@ function makeLightweightCdpDriver(options) {
1148
1293
  reject(new Error(`Timed out waiting for response after ${timeoutMs}ms`));
1149
1294
  }, timeoutMs);
1150
1295
  const offReq = cdpChannel.onEvent("Network.requestWillBeSent", (params, sid) => {
1151
- if (targetSid && sid && sid !== targetSid) return;
1296
+ if (!matchesActiveSlot(sid)) return;
1152
1297
  if (params?.requestId && params?.request?.method) {
1153
- requestMethods.set(String(params.requestId), String(params.request.method));
1298
+ requestMethods.set(
1299
+ `${sid ?? ""}:${String(params.requestId)}`,
1300
+ String(params.request.method)
1301
+ );
1154
1302
  }
1155
1303
  });
1156
1304
  const offRes = cdpChannel.onEvent("Network.responseReceived", (params, sid) => {
1157
- if (targetSid && sid && sid !== targetSid) return;
1305
+ if (!matchesActiveSlot(sid)) return;
1158
1306
  const resp = params?.response;
1159
1307
  if (!resp) return;
1160
1308
  const requestId = String(params?.requestId ?? "");
@@ -1163,16 +1311,19 @@ function makeLightweightCdpDriver(options) {
1163
1311
  for (const [k, v] of Object.entries(rawHeaders)) {
1164
1312
  headers[k.toLowerCase()] = String(v);
1165
1313
  }
1314
+ const responseSid = sid ?? activeSlot?.sessionId ?? null;
1166
1315
  const info = {
1167
1316
  url: String(resp.url ?? ""),
1168
1317
  status: Number(resp.status ?? 0),
1169
1318
  statusText: String(resp.statusText ?? ""),
1170
1319
  headers,
1171
- method: requestMethods.get(requestId),
1320
+ method: requestMethods.get(`${sid ?? ""}:${requestId}`),
1172
1321
  body: async () => {
1173
- const bodyRes = await cdpChannel.sendCommand("Network.getResponseBody", {
1174
- requestId
1175
- });
1322
+ const bodyRes = await cdpChannel.sendCommand(
1323
+ "Network.getResponseBody",
1324
+ { requestId },
1325
+ responseSid
1326
+ );
1176
1327
  if (bodyRes?.base64Encoded && bodyRes.body) {
1177
1328
  return Buffer.from(bodyRes.body, "base64").toString("utf8");
1178
1329
  }
@@ -1340,14 +1491,24 @@ function makeLightweightCdpDriver(options) {
1340
1491
  await cdpChannel.sendCommand("DOM.enable");
1341
1492
  await cdpChannel.sendCommand("DOM.getDocument", { depth: 0 }).catch(() => {
1342
1493
  });
1343
- const evalRes = await cdpChannel.sendCommand("Runtime.evaluate", {
1344
- expression: expr,
1345
- returnByValue: false
1346
- });
1347
- const objectId = evalRes?.result?.objectId;
1494
+ const envTimeout = Number(process.env["SPANA_UPLOAD_TIMEOUT_MS"]);
1495
+ const attachTimeout = Number.isFinite(envTimeout) && envTimeout > 0 ? envTimeout : UPLOAD_ATTACH_TIMEOUT_MS;
1496
+ const deadline = Date.now() + attachTimeout;
1497
+ let objectId;
1498
+ while (Date.now() < deadline) {
1499
+ const evalRes = await cdpChannel.sendCommand("Runtime.evaluate", {
1500
+ expression: expr,
1501
+ returnByValue: false
1502
+ });
1503
+ if (evalRes?.result?.objectId) {
1504
+ objectId = evalRes.result.objectId;
1505
+ break;
1506
+ }
1507
+ await new Promise((r) => setTimeout(r, 50));
1508
+ }
1348
1509
  if (!objectId) {
1349
1510
  throw new Error(
1350
- `No matching file input found for selector ${JSON.stringify(selector)}`
1511
+ `No matching file input found within ${attachTimeout}ms for selector ${JSON.stringify(selector)}`
1351
1512
  );
1352
1513
  }
1353
1514
  const nodeRes = await cdpChannel.sendCommand("DOM.requestNode", { objectId }).catch(() => ({}));
@@ -1508,7 +1669,8 @@ function buildEngineConfig(appId, platform, parseFn, config, screenSize) {
1508
1669
  initialPollInterval: config.defaults?.initialPollInterval,
1509
1670
  tapMode: config.defaults?.tapMode,
1510
1671
  platform,
1511
- failFastWhenIdle: config.defaults?.failFastWhenIdle
1672
+ failFastWhenIdle: config.defaults?.failFastWhenIdle,
1673
+ actionStableFrames: config.defaults?.actionStableFrames
1512
1674
  },
1513
1675
  waitForIdleTimeout: config.defaults?.waitForIdleTimeout,
1514
1676
  typingDelay: config.defaults?.typingDelay,
@@ -2071,7 +2233,7 @@ async function buildLocalIOSRuntime(config, targetDevice, resolveFromConfig) {
2071
2233
  });
2072
2234
  }
2073
2235
  if (signing?.teamId) {
2074
- const { setupWDAForDevice } = await import("./installer-IYGMG7LS.js");
2236
+ const { setupWDAForDevice } = await import("./installer-5UHTYQTB.js");
2075
2237
  const wdaPort2 = allocatePort(8100);
2076
2238
  conn = await setupWDAForDevice(
2077
2239
  physicalDevice2.udid,
@@ -2580,6 +2742,7 @@ var DEFAULT_ARTIFACT_CONFIG = {
2580
2742
  consoleLogs: true,
2581
2743
  jsErrors: true,
2582
2744
  har: true,
2745
+ jsCoverage: false,
2583
2746
  video: "off",
2584
2747
  playback: false
2585
2748
  };
@@ -2868,6 +3031,22 @@ function createStepRecorder(driver, artifactConfig, flowName, platform) {
2868
3031
 
2869
3032
  // src/report/classify-error.ts
2870
3033
  var TAG_KEY = "_tag";
3034
+ var FIBER_FAILURE_CAUSE_SYMBOL = /* @__PURE__ */ Symbol.for("effect/Runtime/FiberFailure/Cause");
3035
+ function unwrapTaggedError(error) {
3036
+ if (!error || typeof error !== "object") return {};
3037
+ const obj = error;
3038
+ if (typeof obj[TAG_KEY] === "string") {
3039
+ return obj;
3040
+ }
3041
+ const cause = obj[FIBER_FAILURE_CAUSE_SYMBOL];
3042
+ if (cause && typeof cause === "object") {
3043
+ const inner = cause["error"] ?? cause["defect"];
3044
+ if (inner && typeof inner === "object" && typeof inner[TAG_KEY] === "string") {
3045
+ return inner;
3046
+ }
3047
+ }
3048
+ return obj;
3049
+ }
2871
3050
  function selectorHint(selector) {
2872
3051
  if (selector && typeof selector === "object") {
2873
3052
  const s = selector;
@@ -3062,7 +3241,7 @@ var heuristicRules = [
3062
3241
  suggestion: "The operation timed out. Try increasing `defaults.waitTimeout` in spana.config.ts."
3063
3242
  },
3064
3243
  {
3065
- pattern: /not found|not visible/,
3244
+ pattern: /not found|not visible|not fillable|covered by/,
3066
3245
  category: (msg) => categorizeElementFailure(msg),
3067
3246
  suggestion: (_error, msg) => {
3068
3247
  if (msg.includes("scroll(s) toward")) {
@@ -3115,11 +3294,11 @@ function categorize(error) {
3115
3294
  return { category: "unknown" };
3116
3295
  }
3117
3296
  function classifyError(error, opts) {
3118
- const tagged = error;
3297
+ const tagged = unwrapTaggedError(error);
3119
3298
  const { category, suggestion } = categorize(tagged);
3120
3299
  const extracted = extractCodeFrame(error.stack, opts?.flowFilePath) ?? extractCodeFrame(opts?.fallbackStack, opts?.flowFilePath);
3121
3300
  return {
3122
- message: error.message,
3301
+ message: tagged.message ?? error.message,
3123
3302
  stack: error.stack,
3124
3303
  category,
3125
3304
  suggestion,
@@ -3254,8 +3433,9 @@ function createFailureBundle(flowName, platform, steps, error, artifactDir, atta
3254
3433
  nearbyAlternatives
3255
3434
  };
3256
3435
  }
3436
+ const shellQuote = (value) => `'${value.replaceAll("'", `'\\''`)}'`;
3257
3437
  const flowFile = flowPath ?? `flows/${flowName.replaceAll(" ", "-")}.flow.ts`;
3258
- const reproCommand = `spana test ${flowFile} --platform ${platform} --grep '${flowName}'`;
3438
+ const reproCommand = `spana test ${shellQuote(flowFile)} --platform ${platform} --grep ${shellQuote(flowName)}`;
3259
3439
  let runtimeDiagnostics;
3260
3440
  const consolePath = join4(artifactDir, "console-logs.json");
3261
3441
  const jsErrPath = join4(artifactDir, "js-errors.json");
@@ -3313,6 +3493,14 @@ function createFailureBundle(flowName, platform, steps, error, artifactDir, atta
3313
3493
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
3314
3494
  failedStep,
3315
3495
  lastPassedStep,
3496
+ steps: steps.map((s, index) => ({
3497
+ index,
3498
+ command: s.command,
3499
+ selector: s.selector ?? null,
3500
+ durationMs: s.durationMs,
3501
+ status: s.status,
3502
+ ...s.error !== void 0 ? { error: s.error } : {}
3503
+ })),
3316
3504
  error: {
3317
3505
  message: error.message,
3318
3506
  category: error.category,
@@ -3362,6 +3550,8 @@ function buildPlaybackStepMarkers(steps) {
3362
3550
  async function executeFlow(flow, driver, config) {
3363
3551
  const start2 = Date.now();
3364
3552
  const { platform, coordinatorConfig, appId } = config;
3553
+ const skip = getFlowSkip(flow, platform);
3554
+ if (skip) return skip;
3365
3555
  const autoLaunch = flow.config.autoLaunch ?? config.autoLaunch ?? true;
3366
3556
  const timeout = flow.config.timeout ?? config.flowTimeout ?? 6e4;
3367
3557
  const artifactConfig = resolveArtifactConfig(config.artifactConfig, flow.config.artifacts);
@@ -3381,11 +3571,27 @@ async function executeFlow(flow, driver, config) {
3381
3571
  typingDelay: flowDefaults.typingDelay ?? coordinatorConfig.typingDelay,
3382
3572
  hierarchyCacheTtl: flowDefaults.hierarchyCacheTtl ?? coordinatorConfig.hierarchyCacheTtl
3383
3573
  } : coordinatorConfig;
3574
+ const softFailures = [];
3575
+ const aggregateFailures = (hardFailure) => {
3576
+ const messages = softFailures.map(
3577
+ (error, i) => `${i + 1}. ${error instanceof Error ? error.message : String(error)}`
3578
+ );
3579
+ return new AggregateError(
3580
+ hardFailure ? [hardFailure, ...softFailures] : softFailures,
3581
+ `${hardFailure ? `${hardFailure.message}
3582
+ ` : ""}${softFailures.length} soft assertion(s) failed:
3583
+ ${messages.join("\n")}`,
3584
+ { cause: hardFailure ?? softFailures[0] }
3585
+ );
3586
+ };
3384
3587
  const flowMeta = {
3385
3588
  flowFilePath: flow.sourcePath ?? "",
3386
3589
  flowName: flow.name,
3387
3590
  platform,
3388
- updateBaselines: config.updateBaselines ?? false
3591
+ updateBaselines: config.updateBaselines ?? false,
3592
+ recordSoftFailure: (error) => {
3593
+ softFailures.push(error);
3594
+ }
3389
3595
  };
3390
3596
  const extraCleanups = [];
3391
3597
  const app = createPromiseApp(driver, appId, mergedCoordinatorConfig, stepRecorder, {
@@ -3419,12 +3625,29 @@ async function executeFlow(flow, driver, config) {
3419
3625
  );
3420
3626
  return pwDriver;
3421
3627
  },
3422
- { parse: (raw) => parseWebHierarchy(raw) }
3628
+ { parse: (raw) => parseWebHierarchy(raw) },
3629
+ { ...flowMeta, platform: "web" }
3423
3630
  );
3424
3631
  flowCtx.sessions = sessions;
3425
3632
  let videoRecorder;
3633
+ let collectingCoverage = false;
3426
3634
  let recordingFinalized = false;
3427
3635
  const wantRecording = artifactConfig.video !== "off" || artifactConfig.playback;
3636
+ const captureCoverage = async (attachments, status) => {
3637
+ if (!collectingCoverage || !driver.stopJSCoverage) return;
3638
+ collectingCoverage = false;
3639
+ try {
3640
+ const entries = await Effect6.runPromise(driver.stopJSCoverage());
3641
+ const path = join5(flowArtifactDir(artifactConfig, flow.name, platform), "js-coverage.json");
3642
+ writeFileSync4(path, JSON.stringify(entries), "utf8");
3643
+ attachments.push({ name: "js-coverage", contentType: "application/json", path });
3644
+ } catch (error) {
3645
+ if (status === "passed") throw error;
3646
+ console.warn(
3647
+ `Failed to capture JavaScript coverage: ${error instanceof Error ? error.message : String(error)}`
3648
+ );
3649
+ }
3650
+ };
3428
3651
  const finalizeRecording = async (status, attachments, steps, durationMs) => {
3429
3652
  if (recordingFinalized || !wantRecording) return;
3430
3653
  recordingFinalized = true;
@@ -3494,6 +3717,7 @@ async function executeFlow(flow, driver, config) {
3494
3717
  platform,
3495
3718
  "failed"
3496
3719
  );
3720
+ await captureCoverage(attachments, "failed");
3497
3721
  const steps = stepRecorder.getSteps();
3498
3722
  const durationMs = Date.now() - start2;
3499
3723
  await finalizeRecording("failed", attachments, steps, durationMs);
@@ -3519,6 +3743,21 @@ async function executeFlow(flow, driver, config) {
3519
3743
  return buildFailureResult(error);
3520
3744
  }
3521
3745
  }
3746
+ if (artifactConfig.jsCoverage && platform === "web") {
3747
+ if (!driver.startJSCoverage || !driver.stopJSCoverage) {
3748
+ return buildFailureResult(
3749
+ new Error(
3750
+ "JavaScript coverage is not supported on web with the current driver; use Chromium with Playwright or direct CDP"
3751
+ )
3752
+ );
3753
+ }
3754
+ try {
3755
+ await Effect6.runPromise(driver.startJSCoverage());
3756
+ collectingCoverage = true;
3757
+ } catch (error) {
3758
+ return buildFailureResult(error);
3759
+ }
3760
+ }
3522
3761
  if (wantRecording) {
3523
3762
  try {
3524
3763
  if (isCdpScreencastCapable(driver.domChannel)) {
@@ -3548,6 +3787,7 @@ async function executeFlow(flow, driver, config) {
3548
3787
  }
3549
3788
  }
3550
3789
  let result;
3790
+ let softFailureError;
3551
3791
  try {
3552
3792
  if (autoLaunch) {
3553
3793
  await app.launch();
@@ -3561,6 +3801,10 @@ async function executeFlow(flow, driver, config) {
3561
3801
  )
3562
3802
  )
3563
3803
  ]);
3804
+ if (softFailures.length > 0) {
3805
+ softFailureError = aggregateFailures();
3806
+ throw softFailureError;
3807
+ }
3564
3808
  const attachments = await captureArtifacts(
3565
3809
  driver,
3566
3810
  artifactConfig,
@@ -3568,6 +3812,7 @@ async function executeFlow(flow, driver, config) {
3568
3812
  platform,
3569
3813
  "passed"
3570
3814
  );
3815
+ await captureCoverage(attachments, "passed");
3571
3816
  const steps = stepRecorder.getSteps();
3572
3817
  const durationMs = Date.now() - start2;
3573
3818
  await finalizeRecording("passed", attachments, steps, durationMs);
@@ -3588,10 +3833,12 @@ async function executeFlow(flow, driver, config) {
3588
3833
  platform,
3589
3834
  "failed"
3590
3835
  );
3836
+ await captureCoverage(attachments, "failed");
3591
3837
  const steps = stepRecorder.getSteps();
3592
3838
  const durationMs = Date.now() - start2;
3593
3839
  await finalizeRecording("failed", attachments, steps, durationMs);
3594
- const flowError = error instanceof Error ? error : new Error(String(error));
3840
+ const normalized = error instanceof Error ? error : new Error(String(error));
3841
+ const flowError = softFailures.length > 0 && error !== softFailureError ? aggregateFailures(normalized) : normalized;
3595
3842
  result = {
3596
3843
  name: flow.name,
3597
3844
  platform,
@@ -3677,7 +3924,7 @@ async function runParallel(config) {
3677
3924
  durationHintsMs,
3678
3925
  claimNextFlow
3679
3926
  } = config;
3680
- const flows = orderFlowsLongestFirst(rawFlows, durationHintsMs);
3927
+ const flows = orderFlowsLongestFirst(focusFlows(rawFlows), durationHintsMs);
3681
3928
  const start2 = Date.now();
3682
3929
  const results = [];
3683
3930
  let nextFlowIndex = 0;
@@ -3697,16 +3944,22 @@ async function runParallel(config) {
3697
3944
  if (flowIdx >= flows.length) break;
3698
3945
  flow = flows[flowIdx];
3699
3946
  }
3700
- let result;
3701
- let attempts = 0;
3947
+ const skip = getFlowSkip(flow, worker.engineConfig.platform);
3948
+ if (skip) {
3949
+ results.push(skip);
3950
+ onFlowComplete?.(skip, worker.name);
3951
+ continue;
3952
+ }
3953
+ const flowRetries = flow.config.retries ?? retries;
3702
3954
  onFlowStart?.(flow.name, worker.name);
3703
- for (let attempt = 0; attempt <= retries; attempt++) {
3704
- if (attempt > 0 && retryDelay > 0) {
3955
+ let result = await executeFlow(flow, worker.driver, worker.engineConfig);
3956
+ let attempts = 1;
3957
+ while (result.status === "failed" && attempts <= flowRetries) {
3958
+ if (retryDelay > 0) {
3705
3959
  await new Promise((resolve) => setTimeout(resolve, retryDelay));
3706
3960
  }
3707
3961
  result = await executeFlow(flow, worker.driver, worker.engineConfig);
3708
3962
  attempts++;
3709
- if (result.status === "passed") break;
3710
3963
  }
3711
3964
  if (result.status === "passed" && attempts > 1) {
3712
3965
  result.flaky = true;
@@ -3727,13 +3980,15 @@ async function runParallel(config) {
3727
3980
  bailedOut = true;
3728
3981
  while (nextFlowIndex < flows.length) {
3729
3982
  const flow = flows[nextFlowIndex++];
3730
- results.push({
3731
- name: flow.name,
3732
- platform: workers[0].engineConfig.platform,
3733
- status: "skipped",
3734
- durationMs: 0,
3735
- attempts: 0
3736
- });
3983
+ results.push(
3984
+ getFlowSkip(flow, workers[0].engineConfig.platform) ?? {
3985
+ name: flow.name,
3986
+ platform: workers[0].engineConfig.platform,
3987
+ status: "skipped",
3988
+ durationMs: 0,
3989
+ attempts: 0
3990
+ }
3991
+ );
3737
3992
  }
3738
3993
  }
3739
3994
  const workerStats = /* @__PURE__ */ new Map();
@@ -3754,8 +4009,9 @@ async function runParallel(config) {
3754
4009
 
3755
4010
  // src/core/worker-pool.ts
3756
4011
  import { spawn as spawn3 } from "child_process";
3757
- import { readFile as readFile2, unlink } from "fs/promises";
4012
+ import { mkdir, readFile as readFile2, unlink, writeFile as writeFile2 } from "fs/promises";
3758
4013
  import { createServer } from "http";
4014
+ import { dirname } from "path";
3759
4015
  var DEFAULT_MAX_WORKERS_PER_PROCESS = 8;
3760
4016
  async function startSharedFlowQueueServer(orderedFlowNames) {
3761
4017
  const queue = [...orderedFlowNames];
@@ -3846,6 +4102,13 @@ function partitionFlowsAcrossProcesses(items, processCount, options) {
3846
4102
  }
3847
4103
  return buckets.map((bucket) => bucket.toSorted((a, b) => a.idx - b.idx).map((e) => e.item)).filter((b) => b.length > 0);
3848
4104
  }
4105
+ async function writeWorkerProcessReport(results, env = process.env) {
4106
+ const reportPath = env["SPANA_WORKER_REPORT_PATH"];
4107
+ if (!reportPath) return null;
4108
+ await mkdir(dirname(reportPath), { recursive: true });
4109
+ await writeFile2(reportPath, JSON.stringify({ results }, null, 2), "utf8");
4110
+ return reportPath;
4111
+ }
3849
4112
  async function defaultReadJsonReport(reportJsonPath) {
3850
4113
  let content;
3851
4114
  try {
@@ -3939,6 +4202,7 @@ async function runMultiProcessPool(options) {
3939
4202
 
3940
4203
  export {
3941
4204
  launchDirectCdpBrowser,
4205
+ UPLOAD_ATTACH_TIMEOUT_MS,
3942
4206
  makeLightweightCdpDriver,
3943
4207
  resolveWebEngine,
3944
4208
  speculativelyPrelaunchWebBrowser,
@@ -3964,6 +4228,7 @@ export {
3964
4228
  createRemoteFlowClaimer,
3965
4229
  planProcessPool,
3966
4230
  partitionFlowsAcrossProcesses,
4231
+ writeWorkerProcessReport,
3967
4232
  runMultiProcessPool
3968
4233
  };
3969
- //# sourceMappingURL=chunk-3FXDOTFI.js.map
4234
+ //# sourceMappingURL=chunk-66D3C7NB.js.map