spana-test 0.4.0 → 0.5.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/.agents/skills/spana-testing/SKILL.md +0 -0
- package/LICENSE +0 -0
- package/README.md +199 -68
- package/dist/{accessibility-audit-RS3VIWRT.js → accessibility-audit-YZOPUY3D.js} +7 -3
- package/dist/accessibility-audit-YZOPUY3D.js.map +1 -0
- package/dist/agent/index.d.ts +3 -84
- package/dist/agent/index.js +11 -10
- package/dist/agent/index.js.map +0 -0
- package/dist/allure-RNMEYTXS.js +0 -0
- package/dist/allure-RNMEYTXS.js.map +0 -0
- package/dist/{android-GFW6OXPQ.js → android-4NVTZMHL.js} +6 -2
- package/dist/{android-GFW6OXPQ.js.map → android-4NVTZMHL.js.map} +0 -0
- package/dist/appium-server-66GVUL24.js +0 -0
- package/dist/appium-server-66GVUL24.js.map +0 -0
- package/dist/baseline-manager-5TIUCNP5.js +0 -0
- package/dist/baseline-manager-5TIUCNP5.js.map +0 -0
- package/dist/chunk-3FSZNKEF.js +0 -0
- package/dist/chunk-3FSZNKEF.js.map +0 -0
- package/dist/chunk-3TRMQCUT.js +0 -0
- package/dist/chunk-3TRMQCUT.js.map +0 -0
- package/dist/chunk-3YE2POGD.js +471 -0
- package/dist/chunk-3YE2POGD.js.map +1 -0
- package/dist/chunk-5245YBLL.js +0 -0
- package/dist/chunk-5245YBLL.js.map +0 -0
- package/dist/{chunk-3J4NG7JU.js → chunk-CY3DKTBZ.js} +8 -2
- package/dist/chunk-CY3DKTBZ.js.map +1 -0
- package/dist/chunk-DGUM43GV.js +0 -0
- package/dist/chunk-DGUM43GV.js.map +0 -0
- package/dist/chunk-DTNK54C2.js +127 -0
- package/dist/chunk-DTNK54C2.js.map +1 -0
- package/dist/{chunk-EWIR2GVV.js → chunk-H27IBIGA.js} +19 -2
- package/dist/chunk-H27IBIGA.js.map +1 -0
- package/dist/chunk-H3RWZCID.js +439 -0
- package/dist/chunk-H3RWZCID.js.map +1 -0
- package/dist/{chunk-PZYZ4O6D.js → chunk-HCG4CJKR.js} +23 -5
- package/dist/chunk-HCG4CJKR.js.map +1 -0
- package/dist/{chunk-YGHDMA6D.js → chunk-HYSTRWYN.js} +142 -41
- package/dist/chunk-HYSTRWYN.js.map +1 -0
- package/dist/chunk-IHVZKQQW.js +0 -0
- package/dist/chunk-IHVZKQQW.js.map +0 -0
- package/dist/chunk-KJPHH2TW.js +0 -0
- package/dist/chunk-KJPHH2TW.js.map +0 -0
- package/dist/chunk-LAMTF4LX.js +89 -0
- package/dist/chunk-LAMTF4LX.js.map +1 -0
- package/dist/chunk-LRGT342X.js +2300 -0
- package/dist/chunk-LRGT342X.js.map +1 -0
- package/dist/chunk-OBCFACUW.js +0 -0
- package/dist/chunk-OBCFACUW.js.map +0 -0
- package/dist/chunk-PJKIXVSO.js +5019 -0
- package/dist/chunk-PJKIXVSO.js.map +1 -0
- package/dist/chunk-S5JNNDXS.js +0 -0
- package/dist/chunk-S5JNNDXS.js.map +0 -0
- package/dist/{chunk-7VOWF42B.js → chunk-SQL3YRR5.js} +74 -8
- package/dist/chunk-SQL3YRR5.js.map +1 -0
- package/dist/{chunk-KYPLYRKW.js → chunk-UJQ7PID5.js} +47 -15
- package/dist/chunk-UJQ7PID5.js.map +1 -0
- package/dist/{chunk-FJAJ4YNC.js → chunk-WSA5QPTA.js} +2 -2
- package/dist/{chunk-FJAJ4YNC.js.map → chunk-WSA5QPTA.js.map} +0 -0
- package/dist/chunk-X2TJP7LB.js +0 -0
- package/dist/chunk-X2TJP7LB.js.map +0 -0
- package/dist/chunk-XENRC3YO.js +2486 -0
- package/dist/chunk-XENRC3YO.js.map +1 -0
- package/dist/cli.js +60 -20
- package/dist/cli.js.map +1 -1
- package/dist/compiler-X6WTFMYF.js +0 -0
- package/dist/compiler-X6WTFMYF.js.map +0 -0
- package/dist/config-loader-XGDDJGVY.js +9 -0
- package/dist/{config-loader-QM72GKEL.js.map → config-loader-XGDDJGVY.js.map} +0 -0
- package/dist/{console-7UW7VROK.js → console-MI2XB5RG.js} +8 -2
- package/dist/console-MI2XB5RG.js.map +1 -0
- package/dist/daemon-manager-FBISTX24.js +28 -0
- package/dist/{discover-CAQY6EG6.js.map → daemon-manager-FBISTX24.js.map} +0 -0
- package/dist/{discover-CAQY6EG6.js → discover-LHEBSUIP.js} +3 -3
- package/dist/{installer-PVBSX7UC.js.map → discover-LHEBSUIP.js.map} +0 -0
- package/dist/doctor-command-WB3O2H64.js +378 -0
- package/dist/doctor-command-WB3O2H64.js.map +1 -0
- package/dist/filters-Q3ALKWZ5.js +24 -0
- package/dist/{session-2MZVGYAC.js.map → filters-Q3ALKWZ5.js.map} +0 -0
- package/dist/{flow-thjUxXXx.d.ts → flow-CyRC-tTc.d.ts} +15 -7
- package/dist/gherkin/steps.d.ts +2 -2
- package/dist/gherkin/steps.js +0 -0
- package/dist/gherkin/steps.js.map +0 -0
- package/dist/github-pr-YMWIPCCZ.js +10 -0
- package/dist/github-pr-YMWIPCCZ.js.map +1 -0
- package/dist/html-F3X3XPSX.js +0 -0
- package/dist/html-F3X3XPSX.js.map +0 -0
- package/dist/index.d.ts +1129 -6
- package/dist/index.js +575 -6
- package/dist/index.js.map +1 -1
- package/dist/{init-command-U66XCM66.js → init-command-Z3QREABL.js} +60 -1
- package/dist/init-command-Z3QREABL.js.map +1 -0
- package/dist/{init-flow-command-PR7J5FBM.js → init-flow-command-4EKRVTNT.js} +2 -2
- package/dist/{init-flow-command-PR7J5FBM.js.map → init-flow-command-4EKRVTNT.js.map} +0 -0
- package/dist/{installer-PVBSX7UC.js → installer-VUPFWP5X.js} +7 -2
- package/dist/installer-VUPFWP5X.js.map +1 -0
- package/dist/ios-JPK43TFZ.js +0 -0
- package/dist/ios-JPK43TFZ.js.map +0 -0
- package/dist/json-JMRPUVY2.js +0 -0
- package/dist/json-JMRPUVY2.js.map +0 -0
- package/dist/junit-HLC62MK6.js +0 -0
- package/dist/junit-HLC62MK6.js.map +0 -0
- package/dist/machine-6H25TRTU.js +0 -0
- package/dist/machine-6H25TRTU.js.map +0 -0
- package/dist/provider-YIPU5K42.js +0 -0
- package/dist/provider-YIPU5K42.js.map +0 -0
- package/dist/redact-U72BUBBR.js +0 -0
- package/dist/redact-U72BUBBR.js.map +0 -0
- package/dist/runner-6HK62Q7B.js +0 -0
- package/dist/runner-6HK62Q7B.js.map +0 -0
- package/dist/screenshot-compare-3QRHHSFZ.js +116 -0
- package/dist/screenshot-compare-3QRHHSFZ.js.map +1 -0
- package/dist/{server-PZBRGU7P.js → server-PRM7BVVD.js} +14 -13
- package/dist/{server-PZBRGU7P.js.map → server-PRM7BVVD.js.map} +1 -1
- package/dist/server-QWJJB3WG.js +14 -0
- package/dist/server-QWJJB3WG.js.map +1 -0
- package/dist/session-2E6OK6BH.js +18 -0
- package/dist/session-2E6OK6BH.js.map +1 -0
- package/dist/session-Ddem-Q5n.d.ts +119 -0
- package/dist/{storybook-pBOPe_1D.d.ts → storybook-CxaP3YDz.d.ts} +265 -4
- package/dist/{studio-command-YDWQOMRX.js → studio-command-O3NN5BCG.js} +2 -2
- package/dist/{studio-command-YDWQOMRX.js.map → studio-command-O3NN5BCG.js.map} +0 -0
- package/dist/{test-command-B2VLWGDK.js → test-command-FYOZ6QAE.js} +231 -1341
- package/dist/test-command-FYOZ6QAE.js.map +1 -0
- package/dist/validator-HZ2A3NEI.js +0 -0
- package/dist/validator-HZ2A3NEI.js.map +0 -0
- package/package.json +7 -3
- package/studio-dist/assets/index-C-Io44gy.js +0 -0
- package/studio-dist/assets/index-DfM9lK4p.css +0 -0
- package/studio-dist/index.html +0 -0
- package/dist/accessibility-audit-RS3VIWRT.js.map +0 -1
- package/dist/chunk-3J4NG7JU.js.map +0 -1
- package/dist/chunk-7VOWF42B.js.map +0 -1
- package/dist/chunk-EWIR2GVV.js.map +0 -1
- package/dist/chunk-KYPLYRKW.js.map +0 -1
- package/dist/chunk-LC3QJIHY.js +0 -440
- package/dist/chunk-LC3QJIHY.js.map +0 -1
- package/dist/chunk-MCT4DYDK.js +0 -2671
- package/dist/chunk-MCT4DYDK.js.map +0 -1
- package/dist/chunk-PZYZ4O6D.js.map +0 -1
- package/dist/chunk-YAV6KBSW.js +0 -1318
- package/dist/chunk-YAV6KBSW.js.map +0 -1
- package/dist/chunk-YGHDMA6D.js.map +0 -1
- package/dist/config-loader-QM72GKEL.js +0 -9
- package/dist/console-7UW7VROK.js.map +0 -1
- package/dist/doctor-command-YGQPO7GH.js +0 -71
- package/dist/doctor-command-YGQPO7GH.js.map +0 -1
- package/dist/element-DZ0HyJ3C.d.ts +0 -25
- package/dist/init-command-U66XCM66.js.map +0 -1
- package/dist/screenshot-compare-JFHH2WR4.js +0 -75
- package/dist/screenshot-compare-JFHH2WR4.js.map +0 -1
- package/dist/session-2MZVGYAC.js +0 -17
- package/dist/test-command-B2VLWGDK.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,9 +1,82 @@
|
|
|
1
|
-
import
|
|
1
|
+
import {
|
|
2
|
+
makeLightweightCdpDriver,
|
|
3
|
+
orderFlowsLongestFirst,
|
|
4
|
+
speculativelyPrelaunchWebBrowser
|
|
5
|
+
} from "./chunk-LRGT342X.js";
|
|
6
|
+
import {
|
|
7
|
+
SPANA_MCP_TOOLS,
|
|
8
|
+
SpanaMcpServer,
|
|
9
|
+
buildFlowFileFromLines,
|
|
10
|
+
formatSelectorCode
|
|
11
|
+
} from "./chunk-H3RWZCID.js";
|
|
2
12
|
import {
|
|
3
13
|
defineConfig
|
|
4
|
-
} from "./chunk-
|
|
5
|
-
import "./chunk-YAV6KBSW.js";
|
|
14
|
+
} from "./chunk-SQL3YRR5.js";
|
|
6
15
|
import "./chunk-X2TJP7LB.js";
|
|
16
|
+
import {
|
|
17
|
+
createGitHubPrReporter,
|
|
18
|
+
formatGitHubPrMarkdown
|
|
19
|
+
} from "./chunk-LAMTF4LX.js";
|
|
20
|
+
import {
|
|
21
|
+
applyTestFilters,
|
|
22
|
+
buildFilterCandidates,
|
|
23
|
+
collectGitChanges,
|
|
24
|
+
createLogprobDecisionJudge,
|
|
25
|
+
createOllamaDecisionJudge,
|
|
26
|
+
decisionFilter,
|
|
27
|
+
formatFilterSummary,
|
|
28
|
+
pathRuleFilter,
|
|
29
|
+
probabilityFromTopLogprobs
|
|
30
|
+
} from "./chunk-3YE2POGD.js";
|
|
31
|
+
import {
|
|
32
|
+
connectPlaywrightOverCDP,
|
|
33
|
+
domRectToScreenBounds,
|
|
34
|
+
ensureWarmBrowserDaemon,
|
|
35
|
+
findWebViewFrame,
|
|
36
|
+
invalidateWebViewFrameCache,
|
|
37
|
+
isOffscreenInViewport,
|
|
38
|
+
isSystemUISelector,
|
|
39
|
+
isTestIDSelector,
|
|
40
|
+
launchPlaywrightBrowser,
|
|
41
|
+
makeElectronDriver,
|
|
42
|
+
resolveElementAcrossChannels,
|
|
43
|
+
systemUI
|
|
44
|
+
} from "./chunk-PJKIXVSO.js";
|
|
45
|
+
import {
|
|
46
|
+
AndroidWebViewCdpChannel,
|
|
47
|
+
AppleWebInspectorClient,
|
|
48
|
+
CdpDomChannel,
|
|
49
|
+
SpanaBridgeChannel,
|
|
50
|
+
TARGET_CHANNEL_MATRIX,
|
|
51
|
+
WebKitInspectorChannel,
|
|
52
|
+
buildDomWaitForSelectorScript,
|
|
53
|
+
createAndroidWebViewCdpChannel,
|
|
54
|
+
createCdpDomChannel,
|
|
55
|
+
createCompositeDomChannel,
|
|
56
|
+
createSpanaBridgeChannel,
|
|
57
|
+
createWebKitInspectorChannel,
|
|
58
|
+
decodeWebInspectorFrames,
|
|
59
|
+
encodeWebInspectorPacket,
|
|
60
|
+
findSimulatorWebInspectorSocket,
|
|
61
|
+
formatTargetMatrixTable,
|
|
62
|
+
makeElectrobunDriver,
|
|
63
|
+
parseAndroidWebViewSockets,
|
|
64
|
+
parseWebInspectorXmlFrame,
|
|
65
|
+
resolveElectrobunEngine,
|
|
66
|
+
resolveElectrobunLaunchPlan,
|
|
67
|
+
resolveTargetDescriptor
|
|
68
|
+
} from "./chunk-XENRC3YO.js";
|
|
69
|
+
import "./chunk-HYSTRWYN.js";
|
|
70
|
+
import {
|
|
71
|
+
getHealthyWarmDaemon,
|
|
72
|
+
listWarmDaemons,
|
|
73
|
+
stopAllWarmDaemons,
|
|
74
|
+
stopWarmDaemon,
|
|
75
|
+
updateWarmDaemonSession
|
|
76
|
+
} from "./chunk-DTNK54C2.js";
|
|
77
|
+
import "./chunk-S5JNNDXS.js";
|
|
78
|
+
import "./chunk-OBCFACUW.js";
|
|
79
|
+
import "./chunk-H27IBIGA.js";
|
|
7
80
|
import "./chunk-DGUM43GV.js";
|
|
8
81
|
|
|
9
82
|
// src/api/flow.ts
|
|
@@ -47,16 +120,512 @@ var ViewHierarchy = Schema.Struct({
|
|
|
47
120
|
// src/schemas/device.ts
|
|
48
121
|
import { Schema as Schema2 } from "effect";
|
|
49
122
|
var DeviceInfo = Schema2.Struct({
|
|
50
|
-
platform: Schema2.Literal("android", "ios", "web"),
|
|
123
|
+
platform: Schema2.Literal("android", "ios", "web", "electron", "electrobun"),
|
|
51
124
|
deviceId: Schema2.String,
|
|
52
125
|
name: Schema2.String,
|
|
53
126
|
isEmulator: Schema2.Boolean,
|
|
54
127
|
screenWidth: Schema2.Number,
|
|
55
128
|
screenHeight: Schema2.Number,
|
|
56
|
-
driverType: Schema2.Literal(
|
|
129
|
+
driverType: Schema2.Literal(
|
|
130
|
+
"playwright",
|
|
131
|
+
"uiautomator2",
|
|
132
|
+
"wda",
|
|
133
|
+
"appium",
|
|
134
|
+
"electron",
|
|
135
|
+
"electrobun"
|
|
136
|
+
)
|
|
57
137
|
});
|
|
138
|
+
|
|
139
|
+
// src/api/fixtures.ts
|
|
140
|
+
function defineSetup(name, config) {
|
|
141
|
+
return { name, ...config };
|
|
142
|
+
}
|
|
143
|
+
async function applyNamedSetup(setup, ctx) {
|
|
144
|
+
const app = ctx.app;
|
|
145
|
+
if (setup.storageStatePath && ctx.platform === "web") {
|
|
146
|
+
await app.loadAuthState(setup.storageStatePath);
|
|
147
|
+
}
|
|
148
|
+
if (setup.clearBefore !== false && setup.storage) {
|
|
149
|
+
const clearOpts = typeof setup.clearBefore === "object" ? setup.clearBefore : void 0;
|
|
150
|
+
try {
|
|
151
|
+
await app.clearStorage(clearOpts);
|
|
152
|
+
} catch {
|
|
153
|
+
if (ctx.platform === "web") {
|
|
154
|
+
await app.evaluate("localStorage.clear(); sessionStorage.clear();");
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
if (setup.storage) {
|
|
159
|
+
try {
|
|
160
|
+
await app.setStorage(setup.storage);
|
|
161
|
+
} catch {
|
|
162
|
+
if (ctx.platform === "web") {
|
|
163
|
+
const serialized = JSON.stringify(setup.storage);
|
|
164
|
+
await app.evaluate(
|
|
165
|
+
`(() => { const entries = ${serialized}; if (entries.localStorage) { for (const [k, v] of Object.entries(entries.localStorage)) localStorage.setItem(k, v); } if (entries.sessionStorage) { for (const [k, v] of Object.entries(entries.sessionStorage)) sessionStorage.setItem(k, v); } })()`
|
|
166
|
+
);
|
|
167
|
+
} else {
|
|
168
|
+
throw new Error(
|
|
169
|
+
`Named setup "${setup.name}" requires spana-bridge or a DOM channel to inject storage on ${ctx.platform}.`
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
if (setup.navigateTo) {
|
|
174
|
+
await app.openLink(setup.navigateTo);
|
|
175
|
+
} else if (setup.reloadAfterStorage !== false) {
|
|
176
|
+
try {
|
|
177
|
+
await app.resetFast();
|
|
178
|
+
} catch {
|
|
179
|
+
if (ctx.platform === "web") {
|
|
180
|
+
await app.evaluate("window.location.reload();");
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
} else if (setup.navigateTo) {
|
|
185
|
+
await app.openLink(setup.navigateTo);
|
|
186
|
+
}
|
|
187
|
+
if (setup.run) {
|
|
188
|
+
await setup.run(ctx);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
function extractDestructuredParamNames(fn) {
|
|
192
|
+
const src = fn.toString().trim();
|
|
193
|
+
const openParen = src.indexOf("(");
|
|
194
|
+
if (openParen < 0) return [];
|
|
195
|
+
let i = openParen + 1;
|
|
196
|
+
while (i < src.length && /\s/.test(src[i])) i++;
|
|
197
|
+
if (src[i] !== "{") return [];
|
|
198
|
+
let depth = 0;
|
|
199
|
+
const start = i + 1;
|
|
200
|
+
let end = -1;
|
|
201
|
+
for (; i < src.length; i++) {
|
|
202
|
+
const ch = src[i];
|
|
203
|
+
if (ch === "{") depth++;
|
|
204
|
+
else if (ch === "}") {
|
|
205
|
+
depth--;
|
|
206
|
+
if (depth === 0) {
|
|
207
|
+
end = i;
|
|
208
|
+
break;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
if (end < 0) return [];
|
|
213
|
+
const inner = src.slice(start, end);
|
|
214
|
+
const names = [];
|
|
215
|
+
let token = "";
|
|
216
|
+
let nested = 0;
|
|
217
|
+
for (let j = 0; j < inner.length; j++) {
|
|
218
|
+
const ch = inner[j];
|
|
219
|
+
if (ch === "{" || ch === "[" || ch === "(") nested++;
|
|
220
|
+
else if (ch === "}" || ch === "]" || ch === ")") nested--;
|
|
221
|
+
else if (ch === "," && nested === 0) {
|
|
222
|
+
const parsed = parseDestructuredKey(token);
|
|
223
|
+
if (parsed) names.push(parsed);
|
|
224
|
+
token = "";
|
|
225
|
+
continue;
|
|
226
|
+
}
|
|
227
|
+
token += ch;
|
|
228
|
+
}
|
|
229
|
+
const last = parseDestructuredKey(token);
|
|
230
|
+
if (last) names.push(last);
|
|
231
|
+
return names;
|
|
232
|
+
}
|
|
233
|
+
function parseDestructuredKey(raw) {
|
|
234
|
+
const cleaned = raw.trim();
|
|
235
|
+
if (!cleaned || cleaned.startsWith("...")) return null;
|
|
236
|
+
const keyMatch = cleaned.match(/^([A-Za-z_$][A-Za-z0-9_$]*)/);
|
|
237
|
+
return keyMatch?.[1] ?? null;
|
|
238
|
+
}
|
|
239
|
+
function createFlowWithFixtures(options) {
|
|
240
|
+
const fixtureMap = /* @__PURE__ */ new Map();
|
|
241
|
+
const rawFixtures = options.fixtures ?? {};
|
|
242
|
+
const setups = options.setups ?? {};
|
|
243
|
+
for (const [name, def] of Object.entries(rawFixtures)) {
|
|
244
|
+
const fn = typeof def === "function" ? def : def.setup;
|
|
245
|
+
const auto = typeof def === "function" ? false : Boolean(def.auto);
|
|
246
|
+
const explicitDeps = typeof def === "function" ? void 0 : def.deps;
|
|
247
|
+
const inferredDeps = explicitDeps ?? extractDestructuredParamNames(fn);
|
|
248
|
+
fixtureMap.set(name, { name, setup: fn, auto, deps: inferredDeps });
|
|
249
|
+
}
|
|
250
|
+
function resolveFixtureOrder(requested) {
|
|
251
|
+
const ordered = [];
|
|
252
|
+
const visiting = /* @__PURE__ */ new Set();
|
|
253
|
+
const visited = /* @__PURE__ */ new Set();
|
|
254
|
+
const visit = (name) => {
|
|
255
|
+
if (visited.has(name)) return;
|
|
256
|
+
const fix = fixtureMap.get(name);
|
|
257
|
+
if (!fix) return;
|
|
258
|
+
if (visiting.has(name)) {
|
|
259
|
+
throw new Error(`Circular fixture dependency detected involving "${name}"`);
|
|
260
|
+
}
|
|
261
|
+
visiting.add(name);
|
|
262
|
+
for (const dep of fix.deps) {
|
|
263
|
+
if (fixtureMap.has(dep)) {
|
|
264
|
+
visit(dep);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
visiting.delete(name);
|
|
268
|
+
visited.add(name);
|
|
269
|
+
ordered.push(fix);
|
|
270
|
+
};
|
|
271
|
+
for (const fix of fixtureMap.values()) {
|
|
272
|
+
if (fix.auto) visit(fix.name);
|
|
273
|
+
}
|
|
274
|
+
for (const name of requested) {
|
|
275
|
+
visit(name);
|
|
276
|
+
}
|
|
277
|
+
return ordered;
|
|
278
|
+
}
|
|
279
|
+
function extendedFlow(name, configOrFn, maybeFn) {
|
|
280
|
+
const isFnOnly = typeof configOrFn === "function";
|
|
281
|
+
const extConfig = isFnOnly ? {} : configOrFn;
|
|
282
|
+
const userFn = isFnOnly ? configOrFn : maybeFn;
|
|
283
|
+
const requestedNames = [
|
|
284
|
+
...extConfig.uses ?? [],
|
|
285
|
+
...extractDestructuredParamNames(userFn).filter((n) => fixtureMap.has(n))
|
|
286
|
+
];
|
|
287
|
+
const wrappedFn = async (baseCtx) => {
|
|
288
|
+
if (extConfig.session) {
|
|
289
|
+
const setup = setups[extConfig.session];
|
|
290
|
+
if (!setup) {
|
|
291
|
+
throw new Error(
|
|
292
|
+
`Unknown setup session "${extConfig.session}". Registered setups: ${Object.keys(setups).join(", ") || "(none)"}`
|
|
293
|
+
);
|
|
294
|
+
}
|
|
295
|
+
await applyNamedSetup(setup, baseCtx);
|
|
296
|
+
}
|
|
297
|
+
const orderedFixtures = resolveFixtureOrder(requestedNames);
|
|
298
|
+
const mergedCtx = { ...baseCtx };
|
|
299
|
+
const runChain = async (idx) => {
|
|
300
|
+
if (idx >= orderedFixtures.length) {
|
|
301
|
+
await userFn(mergedCtx);
|
|
302
|
+
return;
|
|
303
|
+
}
|
|
304
|
+
const fix = orderedFixtures[idx];
|
|
305
|
+
let useCalled = false;
|
|
306
|
+
let flowError;
|
|
307
|
+
let hasFlowError = false;
|
|
308
|
+
await fix.setup(mergedCtx, async (val) => {
|
|
309
|
+
useCalled = true;
|
|
310
|
+
mergedCtx[fix.name] = val;
|
|
311
|
+
try {
|
|
312
|
+
await runChain(idx + 1);
|
|
313
|
+
} catch (err) {
|
|
314
|
+
flowError = err;
|
|
315
|
+
hasFlowError = true;
|
|
316
|
+
}
|
|
317
|
+
});
|
|
318
|
+
if (!useCalled) {
|
|
319
|
+
throw new Error(`Fixture "${fix.name}" finished without calling use(value).`);
|
|
320
|
+
}
|
|
321
|
+
if (hasFlowError) {
|
|
322
|
+
throw flowError;
|
|
323
|
+
}
|
|
324
|
+
};
|
|
325
|
+
await runChain(0);
|
|
326
|
+
};
|
|
327
|
+
const { session: _session, uses: _uses, ...baseFlowConfig } = extConfig;
|
|
328
|
+
return {
|
|
329
|
+
name,
|
|
330
|
+
config: baseFlowConfig,
|
|
331
|
+
fn: wrappedFn
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
return extendedFlow;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
// src/core/replay-cache.ts
|
|
338
|
+
import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "fs";
|
|
339
|
+
import { dirname, join } from "path";
|
|
340
|
+
import { createHash } from "crypto";
|
|
341
|
+
function buildReplayCacheKey(flowName, platform, goal) {
|
|
342
|
+
const hash = createHash("sha256").update(`${flowName}\0${platform}\0${goal.trim()}`).digest("hex").slice(0, 16);
|
|
343
|
+
const slug = flowName.toLowerCase().replaceAll(/[^a-z0-9]+/g, "-").replaceAll(/^-|-$/g, "").slice(0, 40);
|
|
344
|
+
return `${slug || "flow"}-${platform}-${hash}`;
|
|
345
|
+
}
|
|
346
|
+
var ReplayCacheStore = class {
|
|
347
|
+
cacheDir;
|
|
348
|
+
constructor(cacheDir = ".spana/cache") {
|
|
349
|
+
this.cacheDir = cacheDir;
|
|
350
|
+
}
|
|
351
|
+
filePath(key) {
|
|
352
|
+
return join(this.cacheDir, `${key}.json`);
|
|
353
|
+
}
|
|
354
|
+
get(key) {
|
|
355
|
+
const p = this.filePath(key);
|
|
356
|
+
if (!existsSync(p)) return null;
|
|
357
|
+
try {
|
|
358
|
+
const raw = readFileSync(p, "utf-8");
|
|
359
|
+
const parsed = JSON.parse(raw);
|
|
360
|
+
if (parsed.schemaVersion !== 1 || !Array.isArray(parsed.actions)) return null;
|
|
361
|
+
return parsed;
|
|
362
|
+
} catch {
|
|
363
|
+
return null;
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
set(entry) {
|
|
367
|
+
const p = this.filePath(entry.key);
|
|
368
|
+
mkdirSync(dirname(p), { recursive: true });
|
|
369
|
+
writeFileSync(p, JSON.stringify(entry, null, 2), "utf-8");
|
|
370
|
+
}
|
|
371
|
+
delete(key) {
|
|
372
|
+
const p = this.filePath(key);
|
|
373
|
+
if (!existsSync(p)) return false;
|
|
374
|
+
rmSync(p, { force: true });
|
|
375
|
+
return true;
|
|
376
|
+
}
|
|
377
|
+
};
|
|
378
|
+
async function replayRecordedAction(app, action) {
|
|
379
|
+
switch (action.kind) {
|
|
380
|
+
case "tap":
|
|
381
|
+
await app.tap(action.selector);
|
|
382
|
+
break;
|
|
383
|
+
case "doubleTap":
|
|
384
|
+
await app.doubleTap(action.selector);
|
|
385
|
+
break;
|
|
386
|
+
case "longPress":
|
|
387
|
+
await app.longPress(action.selector);
|
|
388
|
+
break;
|
|
389
|
+
case "inputText":
|
|
390
|
+
await app.inputText(action.text);
|
|
391
|
+
break;
|
|
392
|
+
case "pressKey":
|
|
393
|
+
await app.pressKey(action.key);
|
|
394
|
+
break;
|
|
395
|
+
case "scroll":
|
|
396
|
+
await app.scroll(action.direction);
|
|
397
|
+
break;
|
|
398
|
+
case "scrollUntilVisible":
|
|
399
|
+
await app.scrollUntilVisible(action.selector);
|
|
400
|
+
break;
|
|
401
|
+
case "openLink":
|
|
402
|
+
await app.openLink(action.url);
|
|
403
|
+
break;
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
var ReplaySession = class {
|
|
407
|
+
flowName;
|
|
408
|
+
platform;
|
|
409
|
+
app;
|
|
410
|
+
store;
|
|
411
|
+
mode;
|
|
412
|
+
executor;
|
|
413
|
+
pendingWrites = [];
|
|
414
|
+
replayedKeys = [];
|
|
415
|
+
outcomes = [];
|
|
416
|
+
constructor(options) {
|
|
417
|
+
this.flowName = options.flowName;
|
|
418
|
+
this.platform = options.platform;
|
|
419
|
+
this.app = options.app;
|
|
420
|
+
this.store = options.store ?? new ReplayCacheStore();
|
|
421
|
+
this.mode = options.mode ?? "read-write";
|
|
422
|
+
this.executor = options.executor;
|
|
423
|
+
}
|
|
424
|
+
/** Execute a natural-language goal using replay cache first, falling back to `executor`. */
|
|
425
|
+
async act(goal) {
|
|
426
|
+
const key = buildReplayCacheKey(this.flowName, this.platform, goal);
|
|
427
|
+
const cached = this.mode === "off" ? null : this.store.get(key);
|
|
428
|
+
if (cached && cached.actions.length > 0) {
|
|
429
|
+
try {
|
|
430
|
+
for (const action of cached.actions) {
|
|
431
|
+
await replayRecordedAction(this.app, action);
|
|
432
|
+
}
|
|
433
|
+
const outcome = {
|
|
434
|
+
goal,
|
|
435
|
+
key,
|
|
436
|
+
status: "replayed",
|
|
437
|
+
writeStatus: "kept",
|
|
438
|
+
actionCount: cached.actions.length
|
|
439
|
+
};
|
|
440
|
+
const idx = this.outcomes.push(outcome) - 1;
|
|
441
|
+
this.replayedKeys.push({ key, outcomeIndex: idx });
|
|
442
|
+
return outcome;
|
|
443
|
+
} catch (err) {
|
|
444
|
+
const errMsg = err instanceof Error ? err.message : String(err);
|
|
445
|
+
if (this.mode === "strict") {
|
|
446
|
+
throw new Error(
|
|
447
|
+
`Strict replay cache mismatch for "${goal}" (${key}): ${errMsg}. Re-run locally without --strict-cache to self-heal and update .spana/cache/.`,
|
|
448
|
+
{ cause: err }
|
|
449
|
+
);
|
|
450
|
+
}
|
|
451
|
+
return this.runLiveAndQueue(goal, key, true, errMsg);
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
if (this.mode === "strict") {
|
|
455
|
+
throw new Error(
|
|
456
|
+
`Strict replay cache miss for "${goal}" (${key}). No verified recording found in ${this.store.cacheDir}.`
|
|
457
|
+
);
|
|
458
|
+
}
|
|
459
|
+
return this.runLiveAndQueue(goal, key, false);
|
|
460
|
+
}
|
|
461
|
+
async runLiveAndQueue(goal, key, wasExisting, handoffReason) {
|
|
462
|
+
if (!this.executor) {
|
|
463
|
+
throw new Error(
|
|
464
|
+
`No agent executor configured for goal "${goal}" and no cached replay exists.`
|
|
465
|
+
);
|
|
466
|
+
}
|
|
467
|
+
const result = await this.executor.act({
|
|
468
|
+
goal,
|
|
469
|
+
app: this.app,
|
|
470
|
+
handoffReason
|
|
471
|
+
});
|
|
472
|
+
const outcome = {
|
|
473
|
+
goal,
|
|
474
|
+
key,
|
|
475
|
+
status: wasExisting ? "handed-off" : this.mode === "off" ? "live" : "missed",
|
|
476
|
+
writeStatus: this.mode === "off" ? "skipped" : "unconfirmed",
|
|
477
|
+
actionCount: result.actions.length
|
|
478
|
+
};
|
|
479
|
+
const idx = this.outcomes.push(outcome) - 1;
|
|
480
|
+
if (this.mode === "read-write" && result.actions.length > 0) {
|
|
481
|
+
this.pendingWrites.push({
|
|
482
|
+
wasExisting,
|
|
483
|
+
outcomeIndex: idx,
|
|
484
|
+
entry: {
|
|
485
|
+
schemaVersion: 1,
|
|
486
|
+
key,
|
|
487
|
+
goal,
|
|
488
|
+
flowName: this.flowName,
|
|
489
|
+
platform: this.platform,
|
|
490
|
+
actions: result.actions,
|
|
491
|
+
recordedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
492
|
+
verifiedBy: ""
|
|
493
|
+
}
|
|
494
|
+
});
|
|
495
|
+
}
|
|
496
|
+
return outcome;
|
|
497
|
+
}
|
|
498
|
+
/**
|
|
499
|
+
* Call when a real post-action assertion (`expect(...).toBeVisible()`, `toHaveText()`, etc.)
|
|
500
|
+
* succeeds. Flushes all preceding pending recordings to disk in `read-write` mode.
|
|
501
|
+
*/
|
|
502
|
+
markVerified(verifierName) {
|
|
503
|
+
if (this.mode !== "read-write") return 0;
|
|
504
|
+
let saved = 0;
|
|
505
|
+
for (const pending of this.pendingWrites) {
|
|
506
|
+
pending.entry.verifiedBy = verifierName;
|
|
507
|
+
this.store.set(pending.entry);
|
|
508
|
+
this.outcomes[pending.outcomeIndex].writeStatus = "saved";
|
|
509
|
+
saved += 1;
|
|
510
|
+
}
|
|
511
|
+
this.pendingWrites = [];
|
|
512
|
+
return saved;
|
|
513
|
+
}
|
|
514
|
+
/**
|
|
515
|
+
* Call when the flow attempt fails: evicts any replayed recordings involved in the
|
|
516
|
+
* failure (in `read-write` mode) and discards unconfirmed recordings so broken paths
|
|
517
|
+
* are never persisted.
|
|
518
|
+
*/
|
|
519
|
+
markFailed() {
|
|
520
|
+
let evicted = 0;
|
|
521
|
+
if (this.mode === "read-write") {
|
|
522
|
+
for (const replayed of this.replayedKeys) {
|
|
523
|
+
if (this.store.delete(replayed.key)) {
|
|
524
|
+
this.outcomes[replayed.outcomeIndex].writeStatus = "evicted";
|
|
525
|
+
evicted += 1;
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
for (const pending of this.pendingWrites) {
|
|
529
|
+
if (pending.wasExisting && this.store.delete(pending.entry.key)) {
|
|
530
|
+
this.outcomes[pending.outcomeIndex].writeStatus = "evicted";
|
|
531
|
+
evicted += 1;
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
this.pendingWrites = [];
|
|
536
|
+
this.replayedKeys = [];
|
|
537
|
+
return evicted;
|
|
538
|
+
}
|
|
539
|
+
getOutcomes() {
|
|
540
|
+
return [...this.outcomes];
|
|
541
|
+
}
|
|
542
|
+
getSummary() {
|
|
543
|
+
const summary = {
|
|
544
|
+
replayed: 0,
|
|
545
|
+
handedOff: 0,
|
|
546
|
+
missed: 0,
|
|
547
|
+
saved: 0,
|
|
548
|
+
evicted: 0,
|
|
549
|
+
unconfirmed: 0
|
|
550
|
+
};
|
|
551
|
+
for (const o of this.outcomes) {
|
|
552
|
+
if (o.status === "replayed") summary.replayed++;
|
|
553
|
+
else if (o.status === "handed-off") summary.handedOff++;
|
|
554
|
+
else if (o.status === "missed") summary.missed++;
|
|
555
|
+
if (o.writeStatus === "saved") summary.saved++;
|
|
556
|
+
else if (o.writeStatus === "evicted") summary.evicted++;
|
|
557
|
+
else if (o.writeStatus === "unconfirmed") summary.unconfirmed++;
|
|
558
|
+
}
|
|
559
|
+
return summary;
|
|
560
|
+
}
|
|
561
|
+
};
|
|
58
562
|
export {
|
|
563
|
+
AndroidWebViewCdpChannel,
|
|
564
|
+
AppleWebInspectorClient,
|
|
565
|
+
CdpDomChannel,
|
|
566
|
+
ReplayCacheStore,
|
|
567
|
+
ReplaySession,
|
|
568
|
+
SPANA_MCP_TOOLS,
|
|
569
|
+
SpanaBridgeChannel,
|
|
570
|
+
SpanaMcpServer,
|
|
571
|
+
TARGET_CHANNEL_MATRIX,
|
|
572
|
+
WebKitInspectorChannel,
|
|
573
|
+
applyNamedSetup,
|
|
574
|
+
applyTestFilters,
|
|
575
|
+
buildDomWaitForSelectorScript,
|
|
576
|
+
buildFilterCandidates,
|
|
577
|
+
buildFlowFileFromLines,
|
|
578
|
+
buildReplayCacheKey,
|
|
579
|
+
collectGitChanges,
|
|
580
|
+
connectPlaywrightOverCDP,
|
|
581
|
+
createAndroidWebViewCdpChannel,
|
|
582
|
+
createCdpDomChannel,
|
|
583
|
+
createCompositeDomChannel,
|
|
584
|
+
createFlowWithFixtures,
|
|
585
|
+
createGitHubPrReporter,
|
|
586
|
+
createLogprobDecisionJudge,
|
|
587
|
+
createOllamaDecisionJudge,
|
|
588
|
+
createSpanaBridgeChannel,
|
|
589
|
+
createWebKitInspectorChannel,
|
|
590
|
+
decisionFilter,
|
|
591
|
+
decodeWebInspectorFrames,
|
|
59
592
|
defineConfig,
|
|
60
|
-
|
|
593
|
+
defineSetup,
|
|
594
|
+
domRectToScreenBounds,
|
|
595
|
+
encodeWebInspectorPacket,
|
|
596
|
+
ensureWarmBrowserDaemon,
|
|
597
|
+
extractDestructuredParamNames,
|
|
598
|
+
findSimulatorWebInspectorSocket,
|
|
599
|
+
findWebViewFrame,
|
|
600
|
+
flow,
|
|
601
|
+
formatFilterSummary,
|
|
602
|
+
formatGitHubPrMarkdown,
|
|
603
|
+
formatSelectorCode,
|
|
604
|
+
formatTargetMatrixTable,
|
|
605
|
+
getHealthyWarmDaemon,
|
|
606
|
+
invalidateWebViewFrameCache,
|
|
607
|
+
isOffscreenInViewport,
|
|
608
|
+
isSystemUISelector,
|
|
609
|
+
isTestIDSelector,
|
|
610
|
+
launchPlaywrightBrowser,
|
|
611
|
+
listWarmDaemons,
|
|
612
|
+
makeElectrobunDriver,
|
|
613
|
+
makeElectronDriver,
|
|
614
|
+
makeLightweightCdpDriver,
|
|
615
|
+
orderFlowsLongestFirst,
|
|
616
|
+
parseAndroidWebViewSockets,
|
|
617
|
+
parseWebInspectorXmlFrame,
|
|
618
|
+
pathRuleFilter,
|
|
619
|
+
probabilityFromTopLogprobs,
|
|
620
|
+
replayRecordedAction,
|
|
621
|
+
resolveElectrobunEngine,
|
|
622
|
+
resolveElectrobunLaunchPlan,
|
|
623
|
+
resolveElementAcrossChannels,
|
|
624
|
+
resolveTargetDescriptor,
|
|
625
|
+
speculativelyPrelaunchWebBrowser,
|
|
626
|
+
stopAllWarmDaemons,
|
|
627
|
+
stopWarmDaemon,
|
|
628
|
+
systemUI,
|
|
629
|
+
updateWarmDaemonSession
|
|
61
630
|
};
|
|
62
631
|
//# sourceMappingURL=index.js.map
|