spana-test 0.7.0 → 0.8.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.
- package/dist/agent/index.d.ts +2 -2
- package/dist/agent/index.js +9 -9
- package/dist/{allure-RNMEYTXS.js → allure-RAEK4SIH.js} +2 -2
- package/dist/allure-RAEK4SIH.js.map +1 -0
- package/dist/{android-4NVTZMHL.js → android-6BOQTMM3.js} +2 -2
- package/dist/app-CgbLADmF.d.ts +1191 -0
- package/dist/{chunk-H27IBIGA.js → chunk-2AFWVHQK.js} +63 -43
- package/dist/chunk-2AFWVHQK.js.map +1 -0
- package/dist/{chunk-JYFPZRCN.js → chunk-2T4K7BJ3.js} +3 -1
- package/dist/chunk-2T4K7BJ3.js.map +1 -0
- package/dist/{chunk-6B5Y75V4.js → chunk-3FXDOTFI.js} +840 -271
- package/dist/chunk-3FXDOTFI.js.map +1 -0
- package/dist/{chunk-T5CROOR7.js → chunk-AJCSETN6.js} +1329 -245
- package/dist/chunk-AJCSETN6.js.map +1 -0
- package/dist/chunk-JPZCZHL4.js +79 -0
- package/dist/chunk-JPZCZHL4.js.map +1 -0
- package/dist/{chunk-RURZVMZ7.js → chunk-NS2HLJO4.js} +3 -3
- package/dist/{chunk-2IXXEXTL.js → chunk-PMXSU5MS.js} +2 -2
- package/dist/{chunk-HYSTRWYN.js → chunk-QP4MDUBY.js} +4 -4
- package/dist/chunk-RKYKRGHB.js +236 -0
- package/dist/chunk-RKYKRGHB.js.map +1 -0
- package/dist/{chunk-HCG4CJKR.js → chunk-SF7UYW4I.js} +3 -3
- package/dist/{chunk-T3EBOYLS.js → chunk-SNL4X67N.js} +1043 -99
- package/dist/chunk-SNL4X67N.js.map +1 -0
- package/dist/{chunk-KNSAHEXI.js → chunk-WKVU24B6.js} +8 -8
- package/dist/{chunk-S5JNNDXS.js → chunk-WV3ALL3H.js} +65 -37
- package/dist/chunk-WV3ALL3H.js.map +1 -0
- package/dist/cli.js +23 -11
- package/dist/cli.js.map +1 -1
- package/dist/config-loader-5FU45FXK.js +9 -0
- package/dist/{console-MI2XB5RG.js → console-BGAK7Z2L.js} +11 -1
- package/dist/{console-MI2XB5RG.js.map → console-BGAK7Z2L.js.map} +1 -1
- package/dist/{daemon-manager-FBISTX24.js → daemon-manager-DDYQITPD.js} +4 -2
- package/dist/{discover-LHEBSUIP.js → discover-RLSKEBAX.js} +5 -5
- package/dist/{doctor-command-WPEVZEZ4.js → doctor-command-HEQQOYUR.js} +26 -18
- package/dist/doctor-command-HEQQOYUR.js.map +1 -0
- package/dist/{flow-g6AICPAl.d.ts → flow-Md5xLwbX.d.ts} +3 -29
- package/dist/gherkin/steps.d.ts +2 -2
- package/dist/{html-IKCTZH2U.js → html-JO2YNRWX.js} +3 -3
- package/dist/html-JO2YNRWX.js.map +1 -0
- package/dist/index.d.ts +184 -20
- package/dist/index.js +230 -147
- package/dist/index.js.map +1 -1
- package/dist/{installer-VUPFWP5X.js → installer-IYGMG7LS.js} +4 -4
- package/dist/{ios-JPK43TFZ.js → ios-Y4TO5MBR.js} +7 -3
- package/dist/{server-IGLBFEU7.js → server-4PEREPHY.js} +2 -2
- package/dist/{server-EBPYK3VE.js → server-JPNH33MX.js} +50 -36
- package/dist/server-JPNH33MX.js.map +1 -0
- package/dist/{session-cJ_tZjCL.d.ts → session-D9e30RVS.d.ts} +1 -1
- package/dist/session-V4PYJXNB.js +18 -0
- package/dist/{studio-command-FLA5HKRK.js → studio-command-JOIFCOHC.js} +2 -2
- package/dist/{test-command-P5W7UD52.js → test-command-JCO2HPYI.js} +221 -27
- package/dist/test-command-JCO2HPYI.js.map +1 -0
- package/native/darwin-arm64/libspana_native.dylib +0 -0
- package/native/darwin-x64/libspana_native.dylib +0 -0
- package/native/linux-arm64/libspana_native.so +0 -0
- package/native/linux-x64/libspana_native.so +0 -0
- package/native/win32-x64/spana_native.dll +0 -0
- package/package.json +1 -1
- package/studio-dist/assets/index-CBFsOh-9.js +193 -0
- package/studio-dist/assets/index-DH_18EyL.css +1 -0
- package/studio-dist/index.html +2 -2
- package/dist/allure-RNMEYTXS.js.map +0 -1
- package/dist/app-D_UyZBsl.d.ts +0 -915
- package/dist/chunk-6B5Y75V4.js.map +0 -1
- package/dist/chunk-DTNK54C2.js +0 -127
- package/dist/chunk-DTNK54C2.js.map +0 -1
- package/dist/chunk-H27IBIGA.js.map +0 -1
- package/dist/chunk-JYFPZRCN.js.map +0 -1
- package/dist/chunk-OBCFACUW.js +0 -28
- package/dist/chunk-OBCFACUW.js.map +0 -1
- package/dist/chunk-S5JNNDXS.js.map +0 -1
- package/dist/chunk-T3EBOYLS.js.map +0 -1
- package/dist/chunk-T5CROOR7.js.map +0 -1
- package/dist/config-loader-NIDQGP3K.js +0 -9
- package/dist/doctor-command-WPEVZEZ4.js.map +0 -1
- package/dist/html-IKCTZH2U.js.map +0 -1
- package/dist/server-EBPYK3VE.js.map +0 -1
- package/dist/session-QRWH3SPW.js +0 -18
- package/dist/test-command-P5W7UD52.js.map +0 -1
- package/studio-dist/assets/index-C-Io44gy.js +0 -193
- package/studio-dist/assets/index-DfM9lK4p.css +0 -1
- /package/dist/{android-4NVTZMHL.js.map → android-6BOQTMM3.js.map} +0 -0
- /package/dist/{chunk-RURZVMZ7.js.map → chunk-NS2HLJO4.js.map} +0 -0
- /package/dist/{chunk-2IXXEXTL.js.map → chunk-PMXSU5MS.js.map} +0 -0
- /package/dist/{chunk-HYSTRWYN.js.map → chunk-QP4MDUBY.js.map} +0 -0
- /package/dist/{chunk-HCG4CJKR.js.map → chunk-SF7UYW4I.js.map} +0 -0
- /package/dist/{chunk-KNSAHEXI.js.map → chunk-WKVU24B6.js.map} +0 -0
- /package/dist/{config-loader-NIDQGP3K.js.map → config-loader-5FU45FXK.js.map} +0 -0
- /package/dist/{daemon-manager-FBISTX24.js.map → daemon-manager-DDYQITPD.js.map} +0 -0
- /package/dist/{discover-LHEBSUIP.js.map → discover-RLSKEBAX.js.map} +0 -0
- /package/dist/{installer-VUPFWP5X.js.map → installer-IYGMG7LS.js.map} +0 -0
- /package/dist/{ios-JPK43TFZ.js.map → ios-Y4TO5MBR.js.map} +0 -0
- /package/dist/{server-IGLBFEU7.js.map → server-4PEREPHY.js.map} +0 -0
- /package/dist/{session-QRWH3SPW.js.map → session-V4PYJXNB.js.map} +0 -0
- /package/dist/{studio-command-FLA5HKRK.js.map → studio-command-JOIFCOHC.js.map} +0 -0
package/dist/index.js
CHANGED
|
@@ -1,24 +1,32 @@
|
|
|
1
1
|
import {
|
|
2
|
+
DEFAULT_MAX_WORKERS_PER_PROCESS,
|
|
2
3
|
buildPlaybackTraceFromSteps,
|
|
4
|
+
createRemoteFlowClaimer,
|
|
3
5
|
exportFramesToMp4,
|
|
6
|
+
extractCodeFrame,
|
|
7
|
+
formatCodeFrame,
|
|
4
8
|
launchDirectCdpBrowser,
|
|
5
9
|
makeLightweightCdpDriver,
|
|
6
10
|
orderFlowsLongestFirst,
|
|
11
|
+
partitionFlowsAcrossProcesses,
|
|
12
|
+
planProcessPool,
|
|
7
13
|
resolveWebEngine,
|
|
14
|
+
runMultiProcessPool,
|
|
8
15
|
speculativelyPrelaunchWebBrowser,
|
|
9
16
|
startAndroidVideoRecorder,
|
|
10
17
|
startCdpScreencastRecorder,
|
|
11
|
-
startIosSimulatorVideoRecorder
|
|
12
|
-
|
|
18
|
+
startIosSimulatorVideoRecorder,
|
|
19
|
+
startSharedFlowQueueServer
|
|
20
|
+
} from "./chunk-3FXDOTFI.js";
|
|
13
21
|
import {
|
|
14
22
|
SPANA_MCP_TOOLS,
|
|
15
23
|
SpanaMcpServer,
|
|
16
24
|
buildFlowFileFromLines,
|
|
17
25
|
formatSelectorCode
|
|
18
|
-
} from "./chunk-
|
|
26
|
+
} from "./chunk-NS2HLJO4.js";
|
|
19
27
|
import {
|
|
20
28
|
defineConfig
|
|
21
|
-
} from "./chunk-
|
|
29
|
+
} from "./chunk-2T4K7BJ3.js";
|
|
22
30
|
import "./chunk-X2TJP7LB.js";
|
|
23
31
|
import {
|
|
24
32
|
createGitHubPrReporter,
|
|
@@ -37,24 +45,34 @@ import {
|
|
|
37
45
|
probabilityFromTopLogprobs
|
|
38
46
|
} from "./chunk-3SH5JQF7.js";
|
|
39
47
|
import {
|
|
48
|
+
byCss,
|
|
49
|
+
byRole,
|
|
40
50
|
connectPlaywrightOverCDP,
|
|
41
51
|
connectPlaywrightOverWS,
|
|
42
52
|
domRectToScreenBounds,
|
|
43
53
|
ensureWarmBrowserDaemon,
|
|
54
|
+
filterSelector,
|
|
44
55
|
findWebViewFrame,
|
|
56
|
+
first,
|
|
57
|
+
inFrame,
|
|
45
58
|
invalidateWebViewFrameCache,
|
|
59
|
+
isComposableDomSelector,
|
|
46
60
|
isOffscreenInViewport,
|
|
47
61
|
isSystemUISelector,
|
|
48
62
|
isTestIDSelector,
|
|
63
|
+
last,
|
|
49
64
|
launchPlaywrightBrowser,
|
|
50
65
|
makeElectronDriver,
|
|
66
|
+
nth,
|
|
51
67
|
resolveElementAcrossChannels,
|
|
52
|
-
systemUI
|
|
53
|
-
|
|
68
|
+
systemUI,
|
|
69
|
+
within
|
|
70
|
+
} from "./chunk-AJCSETN6.js";
|
|
54
71
|
import {
|
|
55
72
|
AndroidWebViewCdpChannel,
|
|
56
73
|
AppleWebInspectorClient,
|
|
57
74
|
CdpDomChannel,
|
|
75
|
+
SPANA_INJECTED_RUNTIME_SCRIPT,
|
|
58
76
|
SpanaBridgeChannel,
|
|
59
77
|
TARGET_CHANNEL_MATRIX,
|
|
60
78
|
WebKitInspectorChannel,
|
|
@@ -62,6 +80,7 @@ import {
|
|
|
62
80
|
buildDomWaitForHiddenScript,
|
|
63
81
|
buildDomWaitForMatchScript,
|
|
64
82
|
buildDomWaitForSelectorScript,
|
|
83
|
+
buildInjectedCallScript,
|
|
65
84
|
createAndroidWebViewCdpChannel,
|
|
66
85
|
createCdpDomChannel,
|
|
67
86
|
createCompositeDomChannel,
|
|
@@ -77,24 +96,32 @@ import {
|
|
|
77
96
|
resolveElectrobunEngine,
|
|
78
97
|
resolveElectrobunLaunchPlan,
|
|
79
98
|
resolveTargetDescriptor
|
|
80
|
-
} from "./chunk-
|
|
81
|
-
import "./chunk-
|
|
99
|
+
} from "./chunk-SNL4X67N.js";
|
|
100
|
+
import "./chunk-QP4MDUBY.js";
|
|
82
101
|
import {
|
|
102
|
+
defaultDaemonStateDir,
|
|
83
103
|
getHealthyWarmDaemon,
|
|
84
104
|
listWarmDaemons,
|
|
85
105
|
stopAllWarmDaemons,
|
|
86
106
|
stopWarmDaemon,
|
|
87
107
|
updateWarmDaemonSession
|
|
88
|
-
} from "./chunk-
|
|
89
|
-
import
|
|
90
|
-
|
|
108
|
+
} from "./chunk-RKYKRGHB.js";
|
|
109
|
+
import {
|
|
110
|
+
cloneIOSSimulator,
|
|
111
|
+
deleteIOSSimulator
|
|
112
|
+
} from "./chunk-WV3ALL3H.js";
|
|
113
|
+
import {
|
|
114
|
+
allocateFreePort,
|
|
115
|
+
assertPortAvailable,
|
|
116
|
+
isPortAvailable
|
|
117
|
+
} from "./chunk-JPZCZHL4.js";
|
|
91
118
|
import {
|
|
92
119
|
comparePngNative,
|
|
93
120
|
getNativeAcceleratorPath,
|
|
94
121
|
isNativeAcceleratorActive,
|
|
95
122
|
tokenizeXmlNative
|
|
96
123
|
} from "./chunk-54ASKII6.js";
|
|
97
|
-
import "./chunk-
|
|
124
|
+
import "./chunk-2AFWVHQK.js";
|
|
98
125
|
import "./chunk-DGUM43GV.js";
|
|
99
126
|
|
|
100
127
|
// src/api/flow.ts
|
|
@@ -244,8 +271,8 @@ function extractDestructuredParamNames(fn) {
|
|
|
244
271
|
}
|
|
245
272
|
token += ch;
|
|
246
273
|
}
|
|
247
|
-
const
|
|
248
|
-
if (
|
|
274
|
+
const last2 = parseDestructuredKey(token);
|
|
275
|
+
if (last2) names.push(last2);
|
|
249
276
|
return names;
|
|
250
277
|
}
|
|
251
278
|
function parseDestructuredKey(raw) {
|
|
@@ -433,9 +460,55 @@ function createApiFixture(options) {
|
|
|
433
460
|
function definePersona(name, config) {
|
|
434
461
|
return { name, ...config };
|
|
435
462
|
}
|
|
463
|
+
function toImportableCredentials(creds) {
|
|
464
|
+
if (!creds) return [];
|
|
465
|
+
return creds.filter(
|
|
466
|
+
(c) => typeof c.privateKey === "string" && c.privateKey.length > 0
|
|
467
|
+
).map((c) => ({
|
|
468
|
+
credentialId: c.credentialId,
|
|
469
|
+
isResidentCredential: c.isResidentCredential,
|
|
470
|
+
privateKey: c.privateKey,
|
|
471
|
+
signCount: c.signCount,
|
|
472
|
+
...c.rpId !== void 0 ? { rpId: c.rpId } : {},
|
|
473
|
+
...c.userHandle !== void 0 ? { userHandle: c.userHandle } : {},
|
|
474
|
+
...c.userName !== void 0 ? { userName: c.userName } : {}
|
|
475
|
+
}));
|
|
476
|
+
}
|
|
477
|
+
var VirtualCredentialStore = class {
|
|
478
|
+
store = /* @__PURE__ */ new Map();
|
|
479
|
+
save(persona, credentials) {
|
|
480
|
+
const importable = toImportableCredentials(credentials);
|
|
481
|
+
if (importable.length > 0) {
|
|
482
|
+
this.store.set(persona, importable);
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
get(persona) {
|
|
486
|
+
return [...this.store.get(persona) ?? []];
|
|
487
|
+
}
|
|
488
|
+
has(persona) {
|
|
489
|
+
return (this.store.get(persona)?.length ?? 0) > 0;
|
|
490
|
+
}
|
|
491
|
+
clear(persona) {
|
|
492
|
+
if (!persona) {
|
|
493
|
+
this.store.clear();
|
|
494
|
+
return;
|
|
495
|
+
}
|
|
496
|
+
this.store.delete(persona);
|
|
497
|
+
}
|
|
498
|
+
async restore(persona, app, opts) {
|
|
499
|
+
const creds = this.store.get(persona);
|
|
500
|
+
if (!creds || creds.length === 0) return 0;
|
|
501
|
+
const authId = await app.enableVirtualAuthenticator(opts);
|
|
502
|
+
for (const cred of creds) {
|
|
503
|
+
await app.addVirtualCredential(cred, authId);
|
|
504
|
+
}
|
|
505
|
+
return creds.length;
|
|
506
|
+
}
|
|
507
|
+
};
|
|
436
508
|
var PersonaAuthCache = class {
|
|
437
509
|
cache = /* @__PURE__ */ new Map();
|
|
438
510
|
inflight = /* @__PURE__ */ new Map();
|
|
511
|
+
credentials = new VirtualCredentialStore();
|
|
439
512
|
keyFor(persona) {
|
|
440
513
|
return `${persona.name}::${persona.cacheKey ?? "default"}`;
|
|
441
514
|
}
|
|
@@ -445,16 +518,20 @@ var PersonaAuthCache = class {
|
|
|
445
518
|
invalidate(name, cacheKey = "default") {
|
|
446
519
|
if (!name) {
|
|
447
520
|
this.cache.clear();
|
|
521
|
+
this.credentials.clear();
|
|
448
522
|
return;
|
|
449
523
|
}
|
|
450
524
|
this.cache.delete(`${name}::${cacheKey}`);
|
|
525
|
+
this.credentials.clear(`${name}::${cacheKey}`);
|
|
451
526
|
}
|
|
452
527
|
/**
|
|
453
528
|
* Ensure `persona` is authenticated in `ctx`. On cache miss, executes `persona.signIn(ctx)`
|
|
454
|
-
* once (coalescing concurrent callers); on cache hit, restores cookies/storageState
|
|
529
|
+
* once (coalescing concurrent callers); on cache hit, restores cookies/storageState and
|
|
530
|
+
* imports any stored WebAuthn virtual passkeys directly into the fresh context.
|
|
455
531
|
*/
|
|
456
532
|
async authenticate(persona, ctx) {
|
|
457
533
|
const key = this.keyFor(persona);
|
|
534
|
+
const app = ctx.app;
|
|
458
535
|
let state = this.cache.get(key);
|
|
459
536
|
let wasMiss = false;
|
|
460
537
|
if (!state) {
|
|
@@ -463,9 +540,23 @@ var PersonaAuthCache = class {
|
|
|
463
540
|
if (!pending) {
|
|
464
541
|
pending = (async () => {
|
|
465
542
|
const produced = await persona.signIn(ctx) ?? {};
|
|
543
|
+
let virtualCredentials = produced.virtualCredentials;
|
|
544
|
+
if (!virtualCredentials && persona.captureVirtualCredentials !== false && ctx.platform === "web") {
|
|
545
|
+
try {
|
|
546
|
+
const captured = await app.getVirtualCredentials();
|
|
547
|
+
if (captured.length > 0) {
|
|
548
|
+
virtualCredentials = captured;
|
|
549
|
+
}
|
|
550
|
+
} catch {
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
if (virtualCredentials && virtualCredentials.length > 0) {
|
|
554
|
+
this.credentials.save(key, virtualCredentials);
|
|
555
|
+
}
|
|
466
556
|
const entry = {
|
|
467
557
|
storage: produced.storage,
|
|
468
558
|
storageStatePath: produced.storageStatePath,
|
|
559
|
+
virtualCredentials,
|
|
469
560
|
cachedAt: Date.now()
|
|
470
561
|
};
|
|
471
562
|
this.cache.set(key, entry);
|
|
@@ -477,7 +568,6 @@ var PersonaAuthCache = class {
|
|
|
477
568
|
}
|
|
478
569
|
state = await pending;
|
|
479
570
|
}
|
|
480
|
-
const app = ctx.app;
|
|
481
571
|
if (!wasMiss) {
|
|
482
572
|
if (state.storageStatePath && ctx.platform === "web") {
|
|
483
573
|
await app.loadAuthState(state.storageStatePath);
|
|
@@ -485,6 +575,9 @@ var PersonaAuthCache = class {
|
|
|
485
575
|
if (state.storage) {
|
|
486
576
|
await app.setStorage(state.storage);
|
|
487
577
|
}
|
|
578
|
+
if (ctx.platform === "web" && this.credentials.has(key)) {
|
|
579
|
+
await this.credentials.restore(key, app, persona.authenticatorOptions);
|
|
580
|
+
}
|
|
488
581
|
}
|
|
489
582
|
if (persona.navigateTo) {
|
|
490
583
|
await app.openLink(persona.navigateTo);
|
|
@@ -719,141 +812,106 @@ var ReplaySession = class {
|
|
|
719
812
|
}
|
|
720
813
|
};
|
|
721
814
|
|
|
722
|
-
// src/core/
|
|
723
|
-
import {
|
|
724
|
-
import { existsSync as existsSync2, readFileSync as readFileSync2,
|
|
725
|
-
|
|
726
|
-
function
|
|
727
|
-
const
|
|
728
|
-
const
|
|
729
|
-
|
|
730
|
-
|
|
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
|
-
};
|
|
815
|
+
// src/core/network-cache.ts
|
|
816
|
+
import { createHash as createHash2 } from "crypto";
|
|
817
|
+
import { existsSync as existsSync2, mkdirSync as mkdirSync2, readFileSync as readFileSync2, writeFileSync as writeFileSync2 } from "fs";
|
|
818
|
+
import { join as join2 } from "path";
|
|
819
|
+
function buildNetworkCacheKey(method, url) {
|
|
820
|
+
const normalizedMethod = method.toUpperCase();
|
|
821
|
+
const hash = createHash2("sha256").update(`${normalizedMethod} ${url}`).digest("hex").slice(0, 16);
|
|
822
|
+
const slug = url.replace(/^https?:\/\//, "").replaceAll(/[^a-zA-Z0-9-_]/g, "_").replaceAll(/_+/g, "_").slice(0, 48);
|
|
823
|
+
return `${normalizedMethod.toLowerCase()}-${slug}-${hash}`;
|
|
750
824
|
}
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
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 });
|
|
825
|
+
var NetworkReplayCache = class {
|
|
826
|
+
cacheDir;
|
|
827
|
+
constructor(options = {}) {
|
|
828
|
+
this.cacheDir = options.cacheDir ?? join2(process.cwd(), ".spana", "network-cache");
|
|
775
829
|
}
|
|
776
|
-
|
|
777
|
-
}
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
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
|
-
}
|
|
830
|
+
entryPath(key) {
|
|
831
|
+
return join2(this.cacheDir, `${key}.json`);
|
|
832
|
+
}
|
|
833
|
+
get(method, url) {
|
|
834
|
+
const key = buildNetworkCacheKey(method, url);
|
|
835
|
+
const filePath = this.entryPath(key);
|
|
836
|
+
if (!existsSync2(filePath)) return null;
|
|
837
|
+
try {
|
|
838
|
+
const parsed = JSON.parse(readFileSync2(filePath, "utf8"));
|
|
839
|
+
if (parsed && parsed.version === 1 && typeof parsed.body === "string") {
|
|
840
|
+
return parsed;
|
|
820
841
|
}
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
842
|
+
} catch {
|
|
843
|
+
}
|
|
844
|
+
return null;
|
|
845
|
+
}
|
|
846
|
+
set(entry) {
|
|
847
|
+
mkdirSync2(this.cacheDir, { recursive: true });
|
|
848
|
+
const key = buildNetworkCacheKey(entry.method, entry.url);
|
|
849
|
+
const record = {
|
|
850
|
+
version: 1,
|
|
851
|
+
key,
|
|
852
|
+
method: entry.method.toUpperCase(),
|
|
853
|
+
url: entry.url,
|
|
854
|
+
status: entry.status,
|
|
855
|
+
contentType: entry.contentType,
|
|
856
|
+
...entry.headers ? { headers: entry.headers } : {},
|
|
857
|
+
body: entry.body,
|
|
858
|
+
recordedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
859
|
+
};
|
|
860
|
+
writeFileSync2(this.entryPath(key), JSON.stringify(record, null, 2), "utf8");
|
|
861
|
+
return record;
|
|
862
|
+
}
|
|
863
|
+
/**
|
|
864
|
+
* Fetch an endpoint live on cache miss (in `"record"` or `"auto"` mode) or return
|
|
865
|
+
* the cached response in <1ms on cache hit (in `"replay"` or `"auto"` mode).
|
|
866
|
+
*/
|
|
867
|
+
async resolve(url, options) {
|
|
868
|
+
const method = (options?.method ?? "GET").toUpperCase();
|
|
869
|
+
const mode = options?.mode ?? "auto";
|
|
870
|
+
if (mode !== "record") {
|
|
871
|
+
const hit = this.get(method, url);
|
|
872
|
+
if (hit) return { entry: hit, source: "cache" };
|
|
873
|
+
if (mode === "replay") {
|
|
874
|
+
throw new Error(`NetworkReplayCache miss in strict replay mode for ${method} ${url}`);
|
|
832
875
|
}
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
876
|
+
}
|
|
877
|
+
const fetchFn = options?.fetchFn ?? fetch;
|
|
878
|
+
const res = await fetchFn(url, { method, headers: options?.headers });
|
|
879
|
+
const body = await res.text();
|
|
880
|
+
const contentType = res.headers.get("content-type") ?? "application/json";
|
|
881
|
+
const entry = this.set({
|
|
882
|
+
method,
|
|
883
|
+
url,
|
|
884
|
+
status: res.status,
|
|
885
|
+
contentType,
|
|
886
|
+
body
|
|
887
|
+
});
|
|
888
|
+
return { entry, source: "network" };
|
|
889
|
+
}
|
|
890
|
+
};
|
|
891
|
+
async function attachNetworkReplayCache(app, options) {
|
|
892
|
+
const cache = new NetworkReplayCache({ cacheDir: options.cacheDir });
|
|
893
|
+
let cacheHits = 0;
|
|
894
|
+
let networkFetches = 0;
|
|
895
|
+
for (const route of options.routes) {
|
|
896
|
+
const { entry, source } = await cache.resolve(route.url, {
|
|
897
|
+
method: route.method,
|
|
898
|
+
mode: options.mode,
|
|
899
|
+
headers: route.headers,
|
|
900
|
+
fetchFn: options.fetchFn
|
|
901
|
+
});
|
|
902
|
+
if (source === "cache") cacheHits += 1;
|
|
903
|
+
else networkFetches += 1;
|
|
904
|
+
await app.mockNetwork(route.matcher ?? route.url, {
|
|
905
|
+
status: entry.status,
|
|
906
|
+
contentType: entry.contentType,
|
|
907
|
+
headers: entry.headers,
|
|
908
|
+
body: entry.body
|
|
909
|
+
});
|
|
910
|
+
}
|
|
848
911
|
return {
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
failed,
|
|
853
|
-
skipped,
|
|
854
|
-
flaky,
|
|
855
|
-
processCount: plan.processCount,
|
|
856
|
-
processResults
|
|
912
|
+
cacheHits,
|
|
913
|
+
networkFetches,
|
|
914
|
+
totalRoutes: options.routes.length
|
|
857
915
|
};
|
|
858
916
|
}
|
|
859
917
|
export {
|
|
@@ -861,24 +919,35 @@ export {
|
|
|
861
919
|
AppleWebInspectorClient,
|
|
862
920
|
CdpDomChannel,
|
|
863
921
|
DEFAULT_MAX_WORKERS_PER_PROCESS,
|
|
922
|
+
NetworkReplayCache,
|
|
864
923
|
PersonaAuthCache,
|
|
865
924
|
ReplayCacheStore,
|
|
866
925
|
ReplaySession,
|
|
926
|
+
SPANA_INJECTED_RUNTIME_SCRIPT,
|
|
867
927
|
SPANA_MCP_TOOLS,
|
|
868
928
|
SpanaBridgeChannel,
|
|
869
929
|
SpanaMcpServer,
|
|
870
930
|
TARGET_CHANNEL_MATRIX,
|
|
931
|
+
VirtualCredentialStore,
|
|
871
932
|
WebKitInspectorChannel,
|
|
933
|
+
allocateFreePort,
|
|
872
934
|
applyNamedSetup,
|
|
873
935
|
applyTestFilters,
|
|
936
|
+
assertPortAvailable,
|
|
937
|
+
attachNetworkReplayCache,
|
|
874
938
|
buildDomFillScript,
|
|
875
939
|
buildDomWaitForHiddenScript,
|
|
876
940
|
buildDomWaitForMatchScript,
|
|
877
941
|
buildDomWaitForSelectorScript,
|
|
878
942
|
buildFilterCandidates,
|
|
879
943
|
buildFlowFileFromLines,
|
|
944
|
+
buildInjectedCallScript,
|
|
945
|
+
buildNetworkCacheKey,
|
|
880
946
|
buildPlaybackTraceFromSteps,
|
|
881
947
|
buildReplayCacheKey,
|
|
948
|
+
byCss,
|
|
949
|
+
byRole,
|
|
950
|
+
cloneIOSSimulator,
|
|
882
951
|
collectGitChanges,
|
|
883
952
|
comparePngNative,
|
|
884
953
|
connectPlaywrightOverCDP,
|
|
@@ -892,39 +961,51 @@ export {
|
|
|
892
961
|
createGitHubPrReporter,
|
|
893
962
|
createLogprobDecisionJudge,
|
|
894
963
|
createOllamaDecisionJudge,
|
|
964
|
+
createRemoteFlowClaimer,
|
|
895
965
|
createSpanaBridgeChannel,
|
|
896
966
|
createWebKitInspectorChannel,
|
|
897
967
|
decisionFilter,
|
|
898
968
|
decodeWebInspectorFrames,
|
|
969
|
+
defaultDaemonStateDir,
|
|
899
970
|
defineConfig,
|
|
900
971
|
definePersona,
|
|
901
972
|
defineSetup,
|
|
973
|
+
deleteIOSSimulator,
|
|
902
974
|
deterministicImpactFilter,
|
|
903
975
|
domRectToScreenBounds,
|
|
904
976
|
encodeWebInspectorPacket,
|
|
905
977
|
ensureWarmBrowserDaemon,
|
|
906
978
|
exportFramesToMp4,
|
|
979
|
+
extractCodeFrame,
|
|
907
980
|
extractDestructuredParamNames,
|
|
981
|
+
filterSelector,
|
|
908
982
|
findSimulatorWebInspectorSocket,
|
|
909
983
|
findWebViewFrame,
|
|
984
|
+
first,
|
|
910
985
|
flow,
|
|
986
|
+
formatCodeFrame,
|
|
911
987
|
formatFilterSummary,
|
|
912
988
|
formatGitHubPrMarkdown,
|
|
913
989
|
formatSelectorCode,
|
|
914
990
|
formatTargetMatrixTable,
|
|
915
991
|
getHealthyWarmDaemon,
|
|
916
992
|
getNativeAcceleratorPath,
|
|
993
|
+
inFrame,
|
|
917
994
|
invalidateWebViewFrameCache,
|
|
995
|
+
isComposableDomSelector,
|
|
918
996
|
isNativeAcceleratorActive,
|
|
919
997
|
isOffscreenInViewport,
|
|
998
|
+
isPortAvailable,
|
|
920
999
|
isSystemUISelector,
|
|
921
1000
|
isTestIDSelector,
|
|
1001
|
+
last,
|
|
922
1002
|
launchDirectCdpBrowser,
|
|
923
1003
|
launchPlaywrightBrowser,
|
|
924
1004
|
listWarmDaemons,
|
|
925
1005
|
makeElectrobunDriver,
|
|
926
1006
|
makeElectronDriver,
|
|
927
1007
|
makeLightweightCdpDriver,
|
|
1008
|
+
nth,
|
|
928
1009
|
orderFlowsLongestFirst,
|
|
929
1010
|
parseAndroidWebViewSockets,
|
|
930
1011
|
parseWebInspectorXmlFrame,
|
|
@@ -943,10 +1024,12 @@ export {
|
|
|
943
1024
|
startAndroidVideoRecorder,
|
|
944
1025
|
startCdpScreencastRecorder,
|
|
945
1026
|
startIosSimulatorVideoRecorder,
|
|
1027
|
+
startSharedFlowQueueServer,
|
|
946
1028
|
stopAllWarmDaemons,
|
|
947
1029
|
stopWarmDaemon,
|
|
948
1030
|
systemUI,
|
|
949
1031
|
tokenizeXmlNative,
|
|
950
|
-
updateWarmDaemonSession
|
|
1032
|
+
updateWarmDaemonSession,
|
|
1033
|
+
within
|
|
951
1034
|
};
|
|
952
1035
|
//# sourceMappingURL=index.js.map
|