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
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
// src/runtime/daemon-manager.ts
|
|
2
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
|
|
3
|
+
import { tmpdir } from "os";
|
|
4
|
+
import { dirname, join } from "path";
|
|
5
|
+
function defaultDaemonStatePath() {
|
|
6
|
+
return join(tmpdir(), "spana-warm-daemons.json");
|
|
7
|
+
}
|
|
8
|
+
function daemonKey(kind, deviceId) {
|
|
9
|
+
return `${kind}:${deviceId}`;
|
|
10
|
+
}
|
|
11
|
+
function loadDaemonRegistry(stateFile = defaultDaemonStatePath()) {
|
|
12
|
+
if (!existsSync(stateFile)) {
|
|
13
|
+
return { version: 1, daemons: {} };
|
|
14
|
+
}
|
|
15
|
+
try {
|
|
16
|
+
const raw = readFileSync(stateFile, "utf-8");
|
|
17
|
+
const parsed = JSON.parse(raw);
|
|
18
|
+
if (parsed && parsed.version === 1 && typeof parsed.daemons === "object") {
|
|
19
|
+
return parsed;
|
|
20
|
+
}
|
|
21
|
+
} catch {
|
|
22
|
+
}
|
|
23
|
+
return { version: 1, daemons: {} };
|
|
24
|
+
}
|
|
25
|
+
function saveDaemonRegistry(registry, stateFile = defaultDaemonStatePath()) {
|
|
26
|
+
mkdirSync(dirname(stateFile), { recursive: true });
|
|
27
|
+
writeFileSync(stateFile, JSON.stringify(registry, null, 2), "utf-8");
|
|
28
|
+
}
|
|
29
|
+
function registerWarmDaemon(record, stateFile = defaultDaemonStatePath()) {
|
|
30
|
+
const registry = loadDaemonRegistry(stateFile);
|
|
31
|
+
registry.daemons[daemonKey(record.kind, record.deviceId)] = record;
|
|
32
|
+
saveDaemonRegistry(registry, stateFile);
|
|
33
|
+
}
|
|
34
|
+
function updateWarmDaemonSession(kind, deviceId, sessionId, bundleId, stateFile = defaultDaemonStatePath()) {
|
|
35
|
+
const registry = loadDaemonRegistry(stateFile);
|
|
36
|
+
const key = daemonKey(kind, deviceId);
|
|
37
|
+
const existing = registry.daemons[key];
|
|
38
|
+
if (!existing) return;
|
|
39
|
+
registry.daemons[key] = { ...existing, sessionId, ...bundleId ? { bundleId } : {} };
|
|
40
|
+
saveDaemonRegistry(registry, stateFile);
|
|
41
|
+
}
|
|
42
|
+
function unregisterWarmDaemon(kind, deviceId, stateFile = defaultDaemonStatePath()) {
|
|
43
|
+
const registry = loadDaemonRegistry(stateFile);
|
|
44
|
+
delete registry.daemons[daemonKey(kind, deviceId)];
|
|
45
|
+
saveDaemonRegistry(registry, stateFile);
|
|
46
|
+
}
|
|
47
|
+
function listWarmDaemons(stateFile = defaultDaemonStatePath()) {
|
|
48
|
+
return Object.values(loadDaemonRegistry(stateFile).daemons);
|
|
49
|
+
}
|
|
50
|
+
function isPidAlive(pid) {
|
|
51
|
+
if (!pid || pid <= 0) return false;
|
|
52
|
+
try {
|
|
53
|
+
process.kill(pid, 0);
|
|
54
|
+
return true;
|
|
55
|
+
} catch {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
async function getHealthyWarmDaemon(kind, deviceId, options = {}) {
|
|
60
|
+
const stateFile = options.stateFile ?? defaultDaemonStatePath();
|
|
61
|
+
const fetchFn = options.fetchFn ?? fetch;
|
|
62
|
+
const timeoutMs = options.timeoutMs ?? 1500;
|
|
63
|
+
const statusPath = options.statusPath ?? (kind === "chromium" ? "/json/version" : "/status");
|
|
64
|
+
const registry = loadDaemonRegistry(stateFile);
|
|
65
|
+
const record = registry.daemons[daemonKey(kind, deviceId)];
|
|
66
|
+
if (!record) return null;
|
|
67
|
+
try {
|
|
68
|
+
const controller = new AbortController();
|
|
69
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
70
|
+
try {
|
|
71
|
+
const res = await fetchFn(`http://${record.host}:${record.port}${statusPath}`, {
|
|
72
|
+
signal: controller.signal
|
|
73
|
+
});
|
|
74
|
+
if (res.ok) {
|
|
75
|
+
return record;
|
|
76
|
+
}
|
|
77
|
+
} finally {
|
|
78
|
+
clearTimeout(timer);
|
|
79
|
+
}
|
|
80
|
+
} catch {
|
|
81
|
+
}
|
|
82
|
+
delete registry.daemons[daemonKey(kind, deviceId)];
|
|
83
|
+
saveDaemonRegistry(registry, stateFile);
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
function stopWarmDaemon(kind, deviceId, stateFile = defaultDaemonStatePath()) {
|
|
87
|
+
const registry = loadDaemonRegistry(stateFile);
|
|
88
|
+
const key = daemonKey(kind, deviceId);
|
|
89
|
+
const record = registry.daemons[key];
|
|
90
|
+
if (!record) return false;
|
|
91
|
+
for (const pid of [record.pid, record.tunnelPid]) {
|
|
92
|
+
if (pid && pid > 0) {
|
|
93
|
+
try {
|
|
94
|
+
process.kill(pid);
|
|
95
|
+
} catch {
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
delete registry.daemons[key];
|
|
100
|
+
saveDaemonRegistry(registry, stateFile);
|
|
101
|
+
return true;
|
|
102
|
+
}
|
|
103
|
+
function stopAllWarmDaemons(stateFile = defaultDaemonStatePath()) {
|
|
104
|
+
const records = listWarmDaemons(stateFile);
|
|
105
|
+
let stopped = 0;
|
|
106
|
+
for (const record of records) {
|
|
107
|
+
if (stopWarmDaemon(record.kind, record.deviceId, stateFile)) {
|
|
108
|
+
stopped++;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return stopped;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export {
|
|
115
|
+
defaultDaemonStatePath,
|
|
116
|
+
loadDaemonRegistry,
|
|
117
|
+
saveDaemonRegistry,
|
|
118
|
+
registerWarmDaemon,
|
|
119
|
+
updateWarmDaemonSession,
|
|
120
|
+
unregisterWarmDaemon,
|
|
121
|
+
listWarmDaemons,
|
|
122
|
+
isPidAlive,
|
|
123
|
+
getHealthyWarmDaemon,
|
|
124
|
+
stopWarmDaemon,
|
|
125
|
+
stopAllWarmDaemons
|
|
126
|
+
};
|
|
127
|
+
//# sourceMappingURL=chunk-DTNK54C2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/runtime/daemon-manager.ts"],"sourcesContent":["import { existsSync, mkdirSync, readFileSync, writeFileSync } from \"node:fs\";\nimport { tmpdir } from \"node:os\";\nimport { dirname, join } from \"node:path\";\n\nexport type WarmDaemonKind = \"wda\" | \"uiautomator2\" | \"iproxy\" | \"chromium\";\n\nexport interface WarmDaemonRecord {\n kind: WarmDaemonKind;\n deviceId: string;\n host: string;\n port: number;\n pid?: number;\n tunnelPid?: number;\n xctestrunPath?: string;\n /** Optional reusable WDA/UiAutomator2 session ID persisted across runs */\n sessionId?: string;\n bundleId?: string;\n startedAt: string;\n}\n\ninterface DaemonRegistryFile {\n version: 1;\n daemons: Record<string, WarmDaemonRecord>;\n}\n\nexport function defaultDaemonStatePath(): string {\n return join(tmpdir(), \"spana-warm-daemons.json\");\n}\n\nfunction daemonKey(kind: WarmDaemonKind, deviceId: string): string {\n return `${kind}:${deviceId}`;\n}\n\nexport function loadDaemonRegistry(stateFile = defaultDaemonStatePath()): DaemonRegistryFile {\n if (!existsSync(stateFile)) {\n return { version: 1, daemons: {} };\n }\n try {\n const raw = readFileSync(stateFile, \"utf-8\");\n const parsed = JSON.parse(raw) as DaemonRegistryFile;\n if (parsed && parsed.version === 1 && typeof parsed.daemons === \"object\") {\n return parsed;\n }\n } catch {\n // corrupted state file — reset cleanly\n }\n return { version: 1, daemons: {} };\n}\n\nexport function saveDaemonRegistry(\n registry: DaemonRegistryFile,\n stateFile = defaultDaemonStatePath(),\n): void {\n mkdirSync(dirname(stateFile), { recursive: true });\n writeFileSync(stateFile, JSON.stringify(registry, null, 2), \"utf-8\");\n}\n\nexport function registerWarmDaemon(\n record: WarmDaemonRecord,\n stateFile = defaultDaemonStatePath(),\n): void {\n const registry = loadDaemonRegistry(stateFile);\n registry.daemons[daemonKey(record.kind, record.deviceId)] = record;\n saveDaemonRegistry(registry, stateFile);\n}\n\n/** Persist a warm WDA/UiAutomator2 session ID on an existing daemon record for cross-run reuse. */\nexport function updateWarmDaemonSession(\n kind: WarmDaemonKind,\n deviceId: string,\n sessionId: string,\n bundleId?: string,\n stateFile = defaultDaemonStatePath(),\n): void {\n const registry = loadDaemonRegistry(stateFile);\n const key = daemonKey(kind, deviceId);\n const existing = registry.daemons[key];\n if (!existing) return;\n registry.daemons[key] = { ...existing, sessionId, ...(bundleId ? { bundleId } : {}) };\n saveDaemonRegistry(registry, stateFile);\n}\n\nexport function unregisterWarmDaemon(\n kind: WarmDaemonKind,\n deviceId: string,\n stateFile = defaultDaemonStatePath(),\n): void {\n const registry = loadDaemonRegistry(stateFile);\n delete registry.daemons[daemonKey(kind, deviceId)];\n saveDaemonRegistry(registry, stateFile);\n}\n\nexport function listWarmDaemons(stateFile = defaultDaemonStatePath()): WarmDaemonRecord[] {\n return Object.values(loadDaemonRegistry(stateFile).daemons);\n}\n\nexport function isPidAlive(pid: number | undefined): boolean {\n if (!pid || pid <= 0) return false;\n try {\n process.kill(pid, 0);\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * Probe whether a recorded warm WDA / UiAutomator2 daemon is still healthy on\n * `GET http://<host>:<port>/status`. Removes stale records automatically.\n */\nexport async function getHealthyWarmDaemon(\n kind: WarmDaemonKind,\n deviceId: string,\n options: {\n stateFile?: string;\n fetchFn?: typeof fetch;\n timeoutMs?: number;\n /** HTTP health endpoint path (default: \"/status\", use \"/json/version\" for chromium). */\n statusPath?: string;\n } = {},\n): Promise<WarmDaemonRecord | null> {\n const stateFile = options.stateFile ?? defaultDaemonStatePath();\n const fetchFn = options.fetchFn ?? fetch;\n const timeoutMs = options.timeoutMs ?? 1500;\n const statusPath = options.statusPath ?? (kind === \"chromium\" ? \"/json/version\" : \"/status\");\n\n const registry = loadDaemonRegistry(stateFile);\n const record = registry.daemons[daemonKey(kind, deviceId)];\n if (!record) return null;\n\n try {\n const controller = new AbortController();\n const timer = setTimeout(() => controller.abort(), timeoutMs);\n try {\n const res = await fetchFn(`http://${record.host}:${record.port}${statusPath}`, {\n signal: controller.signal,\n });\n if (res.ok) {\n return record;\n }\n } finally {\n clearTimeout(timer);\n }\n } catch {\n // unreachable — prune stale entry\n }\n\n delete registry.daemons[daemonKey(kind, deviceId)];\n saveDaemonRegistry(registry, stateFile);\n return null;\n}\n\n/**\n * Stop only the specific process PIDs started by Spana for this daemon record.\n */\nexport function stopWarmDaemon(\n kind: WarmDaemonKind,\n deviceId: string,\n stateFile = defaultDaemonStatePath(),\n): boolean {\n const registry = loadDaemonRegistry(stateFile);\n const key = daemonKey(kind, deviceId);\n const record = registry.daemons[key];\n if (!record) return false;\n\n for (const pid of [record.pid, record.tunnelPid]) {\n if (pid && pid > 0) {\n try {\n process.kill(pid);\n } catch {\n // already exited\n }\n }\n }\n\n delete registry.daemons[key];\n saveDaemonRegistry(registry, stateFile);\n return true;\n}\n\nexport function stopAllWarmDaemons(stateFile = defaultDaemonStatePath()): number {\n const records = listWarmDaemons(stateFile);\n let stopped = 0;\n for (const record of records) {\n if (stopWarmDaemon(record.kind, record.deviceId, stateFile)) {\n stopped++;\n }\n }\n return stopped;\n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,qBAAmB,UAAU,SAAS;AACtC,SAAO;AACT;AAKO,SAAS,eACd,MACA,UACA,YAAY,uBAAuB,GAC1B;AACT,QAAM,WAAW,mBAAmB,SAAS;AAC7C,QAAM,MAAM,UAAU,MAAM,QAAQ;AACpC,QAAM,SAAS,SAAS,QAAQ,GAAG;AACnC,MAAI,CAAC,OAAQ,QAAO;AAEpB,aAAW,OAAO,CAAC,OAAO,KAAK,OAAO,SAAS,GAAG;AAChD,QAAI,OAAO,MAAM,GAAG;AAClB,UAAI;AACF,gBAAQ,KAAK,GAAG;AAAA,MAClB,QAAQ;AAAA,MAER;AAAA,IACF;AAAA,EACF;AAEA,SAAO,SAAS,QAAQ,GAAG;AAC3B,qBAAmB,UAAU,SAAS;AACtC,SAAO;AACT;AAEO,SAAS,mBAAmB,YAAY,uBAAuB,GAAW;AAC/E,QAAM,UAAU,gBAAgB,SAAS;AACzC,MAAI,UAAU;AACd,aAAW,UAAU,SAAS;AAC5B,QAAI,eAAe,OAAO,MAAM,OAAO,UAAU,SAAS,GAAG;AAC3D;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;","names":[]}
|
|
@@ -127,6 +127,19 @@ function adbForward(serial, hostPort, devicePort) {
|
|
|
127
127
|
if (!adb) throw new Error("adb not found");
|
|
128
128
|
execSync(`${adb} -s ${serial} forward tcp:${hostPort} tcp:${devicePort}`);
|
|
129
129
|
}
|
|
130
|
+
function adbReverse(serial, devicePort, hostPort = devicePort) {
|
|
131
|
+
const adb = findADB();
|
|
132
|
+
if (!adb) throw new Error("adb not found");
|
|
133
|
+
execSync(`${adb} -s ${serial} reverse tcp:${devicePort} tcp:${hostPort}`, { stdio: "ignore" });
|
|
134
|
+
}
|
|
135
|
+
function adbReverseRemove(serial, devicePort) {
|
|
136
|
+
const adb = findADB();
|
|
137
|
+
if (!adb) return;
|
|
138
|
+
try {
|
|
139
|
+
execSync(`${adb} -s ${serial} reverse --remove tcp:${devicePort}`, { stdio: "ignore" });
|
|
140
|
+
} catch {
|
|
141
|
+
}
|
|
142
|
+
}
|
|
130
143
|
function adbShell(serial, command) {
|
|
131
144
|
const adb = findADB();
|
|
132
145
|
if (!adb) throw new Error("adb not found");
|
|
@@ -165,7 +178,9 @@ var ADB_PROFILE_MAP = {
|
|
|
165
178
|
function adbSetAirplaneMode(serial, enable) {
|
|
166
179
|
const adb = findADB();
|
|
167
180
|
if (!adb) throw new Error("adb not found");
|
|
168
|
-
execSync(
|
|
181
|
+
execSync(
|
|
182
|
+
`${adb} -s ${serial} shell cmd connectivity airplane-mode ${enable ? "enable" : "disable"}`
|
|
183
|
+
);
|
|
169
184
|
}
|
|
170
185
|
function adbSetWifi(serial, enable) {
|
|
171
186
|
const adb = findADB();
|
|
@@ -231,6 +246,8 @@ export {
|
|
|
231
246
|
startEmulator,
|
|
232
247
|
ensureAndroidDevice,
|
|
233
248
|
adbForward,
|
|
249
|
+
adbReverse,
|
|
250
|
+
adbReverseRemove,
|
|
234
251
|
adbShell,
|
|
235
252
|
adbInstall,
|
|
236
253
|
adbLaunchApp,
|
|
@@ -245,4 +262,4 @@ export {
|
|
|
245
262
|
adbResetNetwork,
|
|
246
263
|
adbOpenLink
|
|
247
264
|
};
|
|
248
|
-
//# sourceMappingURL=chunk-
|
|
265
|
+
//# sourceMappingURL=chunk-H27IBIGA.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/device/android.ts"],"sourcesContent":["import { execFileSync, execSync } from \"node:child_process\";\n\nexport interface AndroidDevice {\n serial: string;\n state: string; // \"device\", \"offline\", \"unauthorized\"\n type: \"emulator\" | \"device\";\n}\n\n/** Find the adb binary */\nexport function findADB(): string | null {\n // Check common locations\n const candidates = [\n \"adb\", // on PATH\n `${process.env.ANDROID_HOME}/platform-tools/adb`,\n `${process.env.ANDROID_SDK_ROOT}/platform-tools/adb`,\n \"/usr/local/bin/adb\",\n `${process.env.HOME}/Library/Android/sdk/platform-tools/adb`,\n ];\n\n for (const candidate of candidates) {\n if (!candidate) continue;\n try {\n execSync(`${candidate} version`, { stdio: \"ignore\" });\n return candidate;\n } catch {\n // try next\n }\n }\n return null;\n}\n\n/** List connected Android devices */\nexport function listAndroidDevices(): AndroidDevice[] {\n const adb = findADB();\n if (!adb) return [];\n\n try {\n const output = execSync(`${adb} devices`, { encoding: \"utf-8\" });\n return parseDeviceList(output);\n } catch {\n return [];\n }\n}\n\nfunction parseDeviceList(output: string): AndroidDevice[] {\n const devices: AndroidDevice[] = [];\n const lines = output.split(\"\\n\");\n\n for (const line of lines) {\n const trimmed = line.trim();\n if (!trimmed || trimmed.startsWith(\"List of\")) continue;\n\n const parts = trimmed.split(/\\s+/);\n if (parts.length < 2) continue;\n\n const serial = parts[0]!;\n const state = parts[1]!;\n\n devices.push({\n serial,\n state,\n type: serial.startsWith(\"emulator-\") ? \"emulator\" : \"device\",\n });\n }\n\n return devices;\n}\n\nfunction shellQuote(value: string): string {\n return `'${value.replaceAll(\"'\", \"'\\\\''\")}'`;\n}\n\n/** Get first available (state === \"device\") Android device */\nexport function firstAndroidDevice(): AndroidDevice | null {\n const devices = listAndroidDevices();\n return devices.find((d) => d.state === \"device\") ?? null;\n}\n\n/** Find the emulator binary */\nexport function findEmulator(): string | null {\n const candidates = [\n \"emulator\",\n `${process.env.ANDROID_HOME}/emulator/emulator`,\n `${process.env.ANDROID_SDK_ROOT}/emulator/emulator`,\n `${process.env.HOME}/Library/Android/sdk/emulator/emulator`,\n ];\n for (const candidate of candidates) {\n if (!candidate) continue;\n try {\n execSync(`${candidate} -version`, { stdio: \"ignore\" });\n return candidate;\n } catch {\n // try next\n }\n }\n return null;\n}\n\n/** List available Android Virtual Devices */\nexport function listAVDs(): string[] {\n const emulator = findEmulator();\n if (!emulator) return [];\n try {\n const output = execSync(`${emulator} -list-avds`, { encoding: \"utf-8\" });\n return output\n .split(\"\\n\")\n .map((l) => l.trim())\n .filter(Boolean);\n } catch {\n return [];\n }\n}\n\n/**\n * Start an Android emulator and wait for it to boot.\n * Returns the device serial (e.g. \"emulator-5554\") once ready.\n */\nexport function startEmulator(avdName: string, timeoutMs = 60_000): string {\n const emulator = findEmulator();\n if (!emulator) throw new Error(\"Android emulator not found\");\n\n // Launch in background\n const { spawn } = require(\"node:child_process\") as typeof import(\"node:child_process\");\n const proc = spawn(emulator, [\"-avd\", avdName, \"-no-snapshot-save\", \"-no-audio\", \"-no-window\"], {\n detached: true,\n stdio: \"ignore\",\n });\n proc.unref();\n\n // Wait for device to appear in adb\n const adb = findADB();\n if (!adb) throw new Error(\"adb not found\");\n\n const start = Date.now();\n while (Date.now() - start < timeoutMs) {\n const device = firstAndroidDevice();\n if (device) {\n // Wait for boot to complete\n try {\n const bootAnim = execSync(`${adb} -s ${device.serial} shell getprop sys.boot_completed`, {\n encoding: \"utf-8\",\n timeout: 5000,\n }).trim();\n if (bootAnim === \"1\") return device.serial;\n } catch {\n // not ready yet\n }\n }\n execSync(\"sleep 2\");\n }\n\n throw new Error(`Emulator \"${avdName}\" did not boot within ${timeoutMs / 1000}s`);\n}\n\n/**\n * Ensure an Android device is available.\n * If none connected, attempts to start the first available AVD.\n * Returns the device or null if no AVDs available.\n */\nexport function ensureAndroidDevice(timeoutMs = 60_000): AndroidDevice | null {\n const existing = firstAndroidDevice();\n if (existing) return existing;\n\n const avds = listAVDs();\n if (avds.length === 0) return null;\n\n console.log(`No Android device connected. Starting emulator \"${avds[0]}\"...`);\n const serial = startEmulator(avds[0]!, timeoutMs);\n return { serial, state: \"device\", type: \"emulator\" };\n}\n\n/** Forward a port from host to device via adb */\nexport function adbForward(serial: string, hostPort: number, devicePort: number): void {\n const adb = findADB();\n if (!adb) throw new Error(\"adb not found\");\n execSync(`${adb} -s ${serial} forward tcp:${hostPort} tcp:${devicePort}`);\n}\n\n/**\n * Reverse-forward a port from device localhost to host localhost via adb.\n * Allows both physical USB Android phones and emulators to reach Spana's\n * `spana-bridge` WebSocket server at `ws://127.0.0.1:<port>` with zero config.\n */\nexport function adbReverse(serial: string, devicePort: number, hostPort = devicePort): void {\n const adb = findADB();\n if (!adb) throw new Error(\"adb not found\");\n execSync(`${adb} -s ${serial} reverse tcp:${devicePort} tcp:${hostPort}`, { stdio: \"ignore\" });\n}\n\n/** Remove an adb reverse port mapping (best-effort). */\nexport function adbReverseRemove(serial: string, devicePort: number): void {\n const adb = findADB();\n if (!adb) return;\n try {\n execSync(`${adb} -s ${serial} reverse --remove tcp:${devicePort}`, { stdio: \"ignore\" });\n } catch {\n // mapping may already be removed\n }\n}\n\n/** Run adb shell command on device */\nexport function adbShell(serial: string, command: string): string {\n const adb = findADB();\n if (!adb) throw new Error(\"adb not found\");\n return execSync(`${adb} -s ${serial} shell ${command}`, { encoding: \"utf-8\" });\n}\n\n/** Install APK on device */\nexport function adbInstall(serial: string, apkPath: string): void {\n const adb = findADB();\n if (!adb) throw new Error(\"adb not found\");\n execSync(`${adb} -s ${serial} install -r ${apkPath}`, { stdio: \"ignore\" });\n}\n\n/** Launch an installed app via the launcher intent */\nexport function adbLaunchApp(serial: string, packageName: string): void {\n const adb = findADB();\n if (!adb) throw new Error(\"adb not found\");\n execSync(\n `${adb} -s ${serial} shell monkey -p ${packageName} -c android.intent.category.LAUNCHER 1`,\n { stdio: \"ignore\" },\n );\n}\n\n/** Force-stop an installed app */\nexport function adbForceStop(serial: string, packageName: string): void {\n const adb = findADB();\n if (!adb) throw new Error(\"adb not found\");\n execSync(`${adb} -s ${serial} shell am force-stop ${packageName}`, { stdio: \"ignore\" });\n}\n\n/** Clear app data and cache */\nexport function adbClearApp(serial: string, packageName: string): void {\n const adb = findADB();\n if (!adb) throw new Error(\"adb not found\");\n execSync(`${adb} -s ${serial} shell pm clear ${packageName}`, { stdio: \"ignore\" });\n}\n\n// ── Network control helpers ──────────────────────────────────────────\n\n/** Maps friendly profile names to ADB emulator network presets */\nexport const ADB_PROFILE_MAP: Record<string, { speed: string; delay: string }> = {\n \"2g\": { speed: \"gprs\", delay: \"gprs\" },\n edge: { speed: \"edge\", delay: \"edge\" },\n \"3g\": { speed: \"umts\", delay: \"umts\" },\n \"4g\": { speed: \"lte\", delay: \"none\" },\n wifi: { speed: \"full\", delay: \"none\" },\n};\n\n/** Toggle airplane mode on/off */\nexport function adbSetAirplaneMode(serial: string, enable: boolean): void {\n const adb = findADB();\n if (!adb) throw new Error(\"adb not found\");\n execSync(\n `${adb} -s ${serial} shell cmd connectivity airplane-mode ${enable ? \"enable\" : \"disable\"}`,\n );\n}\n\n/** Toggle Wi-Fi on/off */\nexport function adbSetWifi(serial: string, enable: boolean): void {\n const adb = findADB();\n if (!adb) throw new Error(\"adb not found\");\n execSync(`${adb} -s ${serial} shell svc wifi ${enable ? \"enable\" : \"disable\"}`);\n}\n\n/** Toggle mobile data on/off */\nexport function adbSetData(serial: string, enable: boolean): void {\n const adb = findADB();\n if (!adb) throw new Error(\"adb not found\");\n execSync(`${adb} -s ${serial} shell svc data ${enable ? \"enable\" : \"disable\"}`);\n}\n\n/** Apply a named network profile (emulator only) */\nexport function adbSetNetworkProfile(serial: string, profile: string): void {\n const adb = findADB();\n if (!adb) throw new Error(\"adb not found\");\n const mapping = ADB_PROFILE_MAP[profile];\n if (!mapping) throw new Error(`Unknown network profile \"${profile}\"`);\n execSync(`${adb} -s ${serial} emu network speed ${mapping.speed}`);\n execSync(`${adb} -s ${serial} emu network delay ${mapping.delay}`);\n}\n\n/** Apply custom network throttling (emulator only) */\nexport function adbSetCustomNetwork(\n serial: string,\n downloadKbps: number,\n uploadKbps: number,\n delayMs: number,\n): void {\n const adb = findADB();\n if (!adb) throw new Error(\"adb not found\");\n execSync(`${adb} -s ${serial} emu network speed ${downloadKbps}:${uploadKbps}`);\n execSync(`${adb} -s ${serial} emu network delay ${delayMs}:${delayMs}`);\n}\n\n/** Reset network to full speed and disable airplane mode */\nexport function adbResetNetwork(serial: string): void {\n const adb = findADB();\n if (!adb) throw new Error(\"adb not found\");\n execSync(`${adb} -s ${serial} emu network speed full`);\n execSync(`${adb} -s ${serial} emu network delay none`);\n try {\n execSync(`${adb} -s ${serial} shell cmd connectivity airplane-mode disable`);\n } catch {\n // best-effort: may fail on physical devices\n }\n}\n\n/** Open a deep link or URL on the device */\nexport function adbOpenLink(serial: string, url: string, packageName?: string): void {\n const adb = findADB();\n if (!adb) throw new Error(\"adb not found\");\n\n // FLAG_ACTIVITY_CLEAR_TOP (0x04000000) + FLAG_ACTIVITY_NEW_TASK (0x10000000)\n // ensures the deeplink resets the navigation stack\n const flags = 0x04000000 | 0x10000000;\n const command = [\n \"am\",\n \"start\",\n \"-W\",\n \"-a\",\n \"android.intent.action.VIEW\",\n \"-f\",\n String(flags),\n \"-d\",\n shellQuote(url),\n ];\n\n if (packageName) {\n command.push(shellQuote(packageName));\n }\n\n execFileSync(adb, [\"-s\", serial, \"shell\", command.join(\" \")], { stdio: \"ignore\" });\n}\n"],"mappings":";;;;;AAAA,SAAS,cAAc,gBAAgB;AAShC,SAAS,UAAyB;AAEvC,QAAM,aAAa;AAAA,IACjB;AAAA;AAAA,IACA,GAAG,QAAQ,IAAI,YAAY;AAAA,IAC3B,GAAG,QAAQ,IAAI,gBAAgB;AAAA,IAC/B;AAAA,IACA,GAAG,QAAQ,IAAI,IAAI;AAAA,EACrB;AAEA,aAAW,aAAa,YAAY;AAClC,QAAI,CAAC,UAAW;AAChB,QAAI;AACF,eAAS,GAAG,SAAS,YAAY,EAAE,OAAO,SAAS,CAAC;AACpD,aAAO;AAAA,IACT,QAAQ;AAAA,IAER;AAAA,EACF;AACA,SAAO;AACT;AAGO,SAAS,qBAAsC;AACpD,QAAM,MAAM,QAAQ;AACpB,MAAI,CAAC,IAAK,QAAO,CAAC;AAElB,MAAI;AACF,UAAM,SAAS,SAAS,GAAG,GAAG,YAAY,EAAE,UAAU,QAAQ,CAAC;AAC/D,WAAO,gBAAgB,MAAM;AAAA,EAC/B,QAAQ;AACN,WAAO,CAAC;AAAA,EACV;AACF;AAEA,SAAS,gBAAgB,QAAiC;AACxD,QAAM,UAA2B,CAAC;AAClC,QAAM,QAAQ,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@@
|
|
|
1
|
+
// src/mcp/server.ts
|
|
2
|
+
import { createInterface } from "readline";
|
|
3
|
+
function formatSelectorCode(selector) {
|
|
4
|
+
if (typeof selector === "string") {
|
|
5
|
+
return JSON.stringify(selector);
|
|
6
|
+
}
|
|
7
|
+
const sel = selector;
|
|
8
|
+
if (sel.systemUI === true) {
|
|
9
|
+
const rest = { ...sel };
|
|
10
|
+
delete rest.systemUI;
|
|
11
|
+
return `systemUI(${JSON.stringify(rest)})`;
|
|
12
|
+
}
|
|
13
|
+
return JSON.stringify(selector);
|
|
14
|
+
}
|
|
15
|
+
function buildFlowFileFromLines(flowName, lines) {
|
|
16
|
+
const usesSystemUI = lines.some((l) => l.includes("systemUI("));
|
|
17
|
+
const imports = usesSystemUI ? 'import { flow, systemUI } from "spana-test";' : 'import { flow } from "spana-test";';
|
|
18
|
+
const body = lines.length > 0 ? lines.map((l) => ` ${l}`).join("\n") : " // Add verified steps here";
|
|
19
|
+
return `${imports}
|
|
20
|
+
|
|
21
|
+
export default flow(${JSON.stringify(flowName)}, async ({ app, expect }) => {
|
|
22
|
+
${body}
|
|
23
|
+
});
|
|
24
|
+
`;
|
|
25
|
+
}
|
|
26
|
+
var SPANA_MCP_TOOLS = [
|
|
27
|
+
{
|
|
28
|
+
name: "spana_session_start",
|
|
29
|
+
description: "Connect Spana to a live target (web, android, ios, electron, electrobun) and begin recording verified .flow.ts lines.",
|
|
30
|
+
inputSchema: {
|
|
31
|
+
type: "object",
|
|
32
|
+
properties: {
|
|
33
|
+
platform: {
|
|
34
|
+
type: "string",
|
|
35
|
+
enum: ["web", "android", "ios", "electron", "electrobun"]
|
|
36
|
+
},
|
|
37
|
+
baseUrl: { type: "string" },
|
|
38
|
+
packageName: { type: "string" },
|
|
39
|
+
bundleId: { type: "string" },
|
|
40
|
+
device: { type: "string" },
|
|
41
|
+
headless: { type: "boolean" },
|
|
42
|
+
cdpUrl: { type: "string" }
|
|
43
|
+
},
|
|
44
|
+
required: ["platform"]
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
name: "spana_session_stop",
|
|
49
|
+
description: "Disconnect the active Spana session and return the generated .flow.ts file containing every verified step.",
|
|
50
|
+
inputSchema: {
|
|
51
|
+
type: "object",
|
|
52
|
+
properties: {
|
|
53
|
+
flowName: { type: "string" }
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
name: "spana_observe",
|
|
59
|
+
description: "Inspect the current screen: returns actionable elements with suggested { testID } / systemUI() selectors plus recent console logs and JS errors.",
|
|
60
|
+
inputSchema: {
|
|
61
|
+
type: "object",
|
|
62
|
+
properties: {
|
|
63
|
+
maxElements: { type: "number" }
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
name: "spana_tap",
|
|
69
|
+
description: "Tap an element via Spana's dual-channel resolver and return the verified `.flow.ts` line.",
|
|
70
|
+
inputSchema: {
|
|
71
|
+
type: "object",
|
|
72
|
+
properties: {
|
|
73
|
+
selector: { type: "object" }
|
|
74
|
+
},
|
|
75
|
+
required: ["selector"]
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
name: "spana_input_text",
|
|
80
|
+
description: "Type text into the focused element and return the verified `.flow.ts` line.",
|
|
81
|
+
inputSchema: {
|
|
82
|
+
type: "object",
|
|
83
|
+
properties: {
|
|
84
|
+
text: { type: "string" }
|
|
85
|
+
},
|
|
86
|
+
required: ["text"]
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
name: "spana_assert_visible",
|
|
91
|
+
description: "Verify that an element matching selector is currently visible on screen and return the verified `expect(...)` line.",
|
|
92
|
+
inputSchema: {
|
|
93
|
+
type: "object",
|
|
94
|
+
properties: {
|
|
95
|
+
selector: { type: "object" }
|
|
96
|
+
},
|
|
97
|
+
required: ["selector"]
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
name: "spana_open_link",
|
|
102
|
+
description: "Navigate the active target to a URL or deep link and record the verified line.",
|
|
103
|
+
inputSchema: {
|
|
104
|
+
type: "object",
|
|
105
|
+
properties: {
|
|
106
|
+
url: { type: "string" }
|
|
107
|
+
},
|
|
108
|
+
required: ["url"]
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
name: "spana_screenshot",
|
|
113
|
+
description: "Capture a live PNG screenshot of the current screen for visual verification.",
|
|
114
|
+
inputSchema: {
|
|
115
|
+
type: "object",
|
|
116
|
+
properties: {}
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
name: "spana_diagnostics",
|
|
121
|
+
description: "Argent-inspired live runtime diagnostics: returns captured console logs, JS errors, element count, and platform metadata.",
|
|
122
|
+
inputSchema: {
|
|
123
|
+
type: "object",
|
|
124
|
+
properties: {}
|
|
125
|
+
}
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
name: "spana_export_flow",
|
|
129
|
+
description: "Export all verified actions from the current session as a runnable TypeScript `.flow.ts` file without disconnecting.",
|
|
130
|
+
inputSchema: {
|
|
131
|
+
type: "object",
|
|
132
|
+
properties: {
|
|
133
|
+
flowName: { type: "string" }
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
name: "spana_run_flow",
|
|
139
|
+
description: "Run an existing `.flow.ts` test file via Spana and return pass/fail status for rapid agent fix-and-verify loops.",
|
|
140
|
+
inputSchema: {
|
|
141
|
+
type: "object",
|
|
142
|
+
properties: {
|
|
143
|
+
flowPath: { type: "string" },
|
|
144
|
+
platform: {
|
|
145
|
+
type: "string",
|
|
146
|
+
enum: ["web", "android", "ios", "electron", "electrobun"]
|
|
147
|
+
}
|
|
148
|
+
},
|
|
149
|
+
required: ["flowPath"]
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
];
|
|
153
|
+
var SpanaMcpServer = class {
|
|
154
|
+
session = null;
|
|
155
|
+
recordedLines = [];
|
|
156
|
+
connectFn;
|
|
157
|
+
runFlowFn;
|
|
158
|
+
constructor(options = {}) {
|
|
159
|
+
this.connectFn = options.connectFn ?? (async (opts) => {
|
|
160
|
+
const { connect } = await import("./session-2E6OK6BH.js");
|
|
161
|
+
return connect(opts);
|
|
162
|
+
});
|
|
163
|
+
this.runFlowFn = options.runFlowFn ?? (async ({ flowPath, platform }) => {
|
|
164
|
+
const { runTestCommand } = await import("./test-command-FYOZ6QAE.js");
|
|
165
|
+
return runTestCommand({
|
|
166
|
+
flowPath,
|
|
167
|
+
platforms: platform ? [platform] : [],
|
|
168
|
+
quiet: true
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
requireSession() {
|
|
173
|
+
if (!this.session) {
|
|
174
|
+
throw new Error(
|
|
175
|
+
"No active Spana MCP session. Call `spana_session_start` first with a target platform."
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
return this.session;
|
|
179
|
+
}
|
|
180
|
+
async handleRequest(req) {
|
|
181
|
+
const id = req.id ?? null;
|
|
182
|
+
if (req.method === "notifications/initialized" || req.id === void 0) {
|
|
183
|
+
return null;
|
|
184
|
+
}
|
|
185
|
+
try {
|
|
186
|
+
switch (req.method) {
|
|
187
|
+
case "initialize":
|
|
188
|
+
return {
|
|
189
|
+
jsonrpc: "2.0",
|
|
190
|
+
id,
|
|
191
|
+
result: {
|
|
192
|
+
protocolVersion: "2024-11-05",
|
|
193
|
+
capabilities: { tools: {} },
|
|
194
|
+
serverInfo: { name: "spana-mcp", version: "1.0.0" }
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
case "ping":
|
|
198
|
+
return { jsonrpc: "2.0", id, result: {} };
|
|
199
|
+
case "tools/list":
|
|
200
|
+
return {
|
|
201
|
+
jsonrpc: "2.0",
|
|
202
|
+
id,
|
|
203
|
+
result: { tools: SPANA_MCP_TOOLS }
|
|
204
|
+
};
|
|
205
|
+
case "tools/call": {
|
|
206
|
+
const name = String(req.params?.["name"] ?? "");
|
|
207
|
+
const args = req.params?.["arguments"] ?? {};
|
|
208
|
+
const toolResult = await this.callTool(name, args);
|
|
209
|
+
return { jsonrpc: "2.0", id, result: toolResult };
|
|
210
|
+
}
|
|
211
|
+
default:
|
|
212
|
+
return {
|
|
213
|
+
jsonrpc: "2.0",
|
|
214
|
+
id,
|
|
215
|
+
error: { code: -32601, message: `Method not found: ${req.method}` }
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
} catch (err) {
|
|
219
|
+
return {
|
|
220
|
+
jsonrpc: "2.0",
|
|
221
|
+
id,
|
|
222
|
+
error: {
|
|
223
|
+
code: -32603,
|
|
224
|
+
message: err instanceof Error ? err.message : String(err)
|
|
225
|
+
}
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
async callTool(name, args) {
|
|
230
|
+
try {
|
|
231
|
+
switch (name) {
|
|
232
|
+
case "spana_session_start": {
|
|
233
|
+
if (this.session) {
|
|
234
|
+
await this.session.disconnect().catch(() => void 0);
|
|
235
|
+
this.session = null;
|
|
236
|
+
}
|
|
237
|
+
const platform = args["platform"];
|
|
238
|
+
this.session = await this.connectFn({
|
|
239
|
+
platform,
|
|
240
|
+
baseUrl: args["baseUrl"],
|
|
241
|
+
packageName: args["packageName"],
|
|
242
|
+
bundleId: args["bundleId"],
|
|
243
|
+
device: args["device"],
|
|
244
|
+
headless: args["headless"] ?? true,
|
|
245
|
+
cdpUrl: args["cdpUrl"]
|
|
246
|
+
});
|
|
247
|
+
this.recordedLines = [];
|
|
248
|
+
return this.jsonResult({ connected: true, platform });
|
|
249
|
+
}
|
|
250
|
+
case "spana_session_stop": {
|
|
251
|
+
const flowName = args["flowName"] ?? "recorded flow";
|
|
252
|
+
const code = buildFlowFileFromLines(flowName, this.recordedLines);
|
|
253
|
+
if (this.session) {
|
|
254
|
+
await this.session.disconnect().catch(() => void 0);
|
|
255
|
+
this.session = null;
|
|
256
|
+
}
|
|
257
|
+
return this.jsonResult({
|
|
258
|
+
disconnected: true,
|
|
259
|
+
stepCount: this.recordedLines.length,
|
|
260
|
+
code
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
case "spana_observe": {
|
|
264
|
+
const session = this.requireSession();
|
|
265
|
+
const maxElements = args["maxElements"] ?? 60;
|
|
266
|
+
const elements = (await session.selectors()).slice(0, maxElements);
|
|
267
|
+
const consoleLogs = await session.getConsoleLogs().catch(() => []);
|
|
268
|
+
const jsErrors = await session.getJSErrors().catch(() => []);
|
|
269
|
+
return this.jsonResult({
|
|
270
|
+
platform: session.platform,
|
|
271
|
+
elementCount: elements.length,
|
|
272
|
+
elements,
|
|
273
|
+
recentConsoleLogs: consoleLogs.slice(-15),
|
|
274
|
+
jsErrors: jsErrors.slice(-10)
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
case "spana_tap": {
|
|
278
|
+
const session = this.requireSession();
|
|
279
|
+
const selector = args["selector"];
|
|
280
|
+
await session.tap(selector);
|
|
281
|
+
const codeLine = `await app.tap(${formatSelectorCode(selector)});`;
|
|
282
|
+
this.recordedLines.push(codeLine);
|
|
283
|
+
return this.jsonResult({ ok: true, codeLine });
|
|
284
|
+
}
|
|
285
|
+
case "spana_input_text": {
|
|
286
|
+
const session = this.requireSession();
|
|
287
|
+
const text = String(args["text"] ?? "");
|
|
288
|
+
await session.inputText(text);
|
|
289
|
+
const codeLine = `await app.inputText(${JSON.stringify(text)});`;
|
|
290
|
+
this.recordedLines.push(codeLine);
|
|
291
|
+
return this.jsonResult({ ok: true, codeLine });
|
|
292
|
+
}
|
|
293
|
+
case "spana_assert_visible": {
|
|
294
|
+
const session = this.requireSession();
|
|
295
|
+
const selector = args["selector"];
|
|
296
|
+
const elements = await session.selectors();
|
|
297
|
+
const sel = selector;
|
|
298
|
+
const matched = elements.some((el) => {
|
|
299
|
+
if (typeof sel["testID"] === "string") return el.id === sel["testID"];
|
|
300
|
+
if (typeof sel["text"] === "string") return el.text?.includes(sel["text"]);
|
|
301
|
+
if (typeof sel["accessibilityLabel"] === "string") {
|
|
302
|
+
return el.accessibilityLabel === sel["accessibilityLabel"];
|
|
303
|
+
}
|
|
304
|
+
return false;
|
|
305
|
+
});
|
|
306
|
+
if (!matched) {
|
|
307
|
+
return {
|
|
308
|
+
isError: true,
|
|
309
|
+
content: [
|
|
310
|
+
{
|
|
311
|
+
type: "text",
|
|
312
|
+
text: JSON.stringify({
|
|
313
|
+
ok: false,
|
|
314
|
+
message: `Element not visible: ${formatSelectorCode(selector)}`,
|
|
315
|
+
availableTestIDs: elements.map((e) => e.id).filter(Boolean).slice(0, 20)
|
|
316
|
+
})
|
|
317
|
+
}
|
|
318
|
+
]
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
const codeLine = `await expect(${formatSelectorCode(selector)}).toBeVisible();`;
|
|
322
|
+
this.recordedLines.push(codeLine);
|
|
323
|
+
return this.jsonResult({ ok: true, codeLine });
|
|
324
|
+
}
|
|
325
|
+
case "spana_open_link": {
|
|
326
|
+
const session = this.requireSession();
|
|
327
|
+
const url = String(args["url"] ?? "");
|
|
328
|
+
await session.openLink(url);
|
|
329
|
+
const codeLine = `await app.openLink(${JSON.stringify(url)});`;
|
|
330
|
+
this.recordedLines.push(codeLine);
|
|
331
|
+
return this.jsonResult({ ok: true, codeLine });
|
|
332
|
+
}
|
|
333
|
+
case "spana_screenshot": {
|
|
334
|
+
const session = this.requireSession();
|
|
335
|
+
const png = await session.screenshot();
|
|
336
|
+
return {
|
|
337
|
+
content: [
|
|
338
|
+
{
|
|
339
|
+
type: "image",
|
|
340
|
+
data: Buffer.from(png).toString("base64"),
|
|
341
|
+
mimeType: "image/png"
|
|
342
|
+
}
|
|
343
|
+
]
|
|
344
|
+
};
|
|
345
|
+
}
|
|
346
|
+
case "spana_diagnostics": {
|
|
347
|
+
const session = this.requireSession();
|
|
348
|
+
const [elements, consoleLogs, jsErrors] = await Promise.all([
|
|
349
|
+
session.selectors().catch(() => []),
|
|
350
|
+
session.getConsoleLogs().catch(() => []),
|
|
351
|
+
session.getJSErrors().catch(() => [])
|
|
352
|
+
]);
|
|
353
|
+
return this.jsonResult({
|
|
354
|
+
platform: session.platform,
|
|
355
|
+
actionableElements: elements.length,
|
|
356
|
+
testIDCount: elements.filter((e) => Boolean(e.id)).length,
|
|
357
|
+
consoleLogCount: consoleLogs.length,
|
|
358
|
+
consoleLogs: consoleLogs.slice(-25),
|
|
359
|
+
jsErrorCount: jsErrors.length,
|
|
360
|
+
jsErrors: jsErrors.slice(-15)
|
|
361
|
+
});
|
|
362
|
+
}
|
|
363
|
+
case "spana_export_flow": {
|
|
364
|
+
const flowName = args["flowName"] ?? "recorded flow";
|
|
365
|
+
return this.jsonResult({
|
|
366
|
+
flowName,
|
|
367
|
+
stepCount: this.recordedLines.length,
|
|
368
|
+
code: buildFlowFileFromLines(flowName, this.recordedLines)
|
|
369
|
+
});
|
|
370
|
+
}
|
|
371
|
+
case "spana_run_flow": {
|
|
372
|
+
const flowPath = String(args["flowPath"] ?? "");
|
|
373
|
+
const platform = args["platform"];
|
|
374
|
+
const passed = await this.runFlowFn({ flowPath, platform });
|
|
375
|
+
return this.jsonResult({ flowPath, platform: platform ?? "default", passed });
|
|
376
|
+
}
|
|
377
|
+
default:
|
|
378
|
+
return {
|
|
379
|
+
isError: true,
|
|
380
|
+
content: [{ type: "text", text: `Unknown tool: ${name}` }]
|
|
381
|
+
};
|
|
382
|
+
}
|
|
383
|
+
} catch (err) {
|
|
384
|
+
return {
|
|
385
|
+
isError: true,
|
|
386
|
+
content: [
|
|
387
|
+
{
|
|
388
|
+
type: "text",
|
|
389
|
+
text: err instanceof Error ? err.message : String(err)
|
|
390
|
+
}
|
|
391
|
+
]
|
|
392
|
+
};
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
jsonResult(payload) {
|
|
396
|
+
return {
|
|
397
|
+
content: [{ type: "text", text: JSON.stringify(payload, null, 2) }]
|
|
398
|
+
};
|
|
399
|
+
}
|
|
400
|
+
/** Run the server over newline-delimited JSON-RPC stdio until stdin closes. */
|
|
401
|
+
async runStdio() {
|
|
402
|
+
const rl = createInterface({ input: process.stdin, crlfDelay: Infinity });
|
|
403
|
+
for await (const line of rl) {
|
|
404
|
+
const trimmed = line.trim();
|
|
405
|
+
if (!trimmed) continue;
|
|
406
|
+
try {
|
|
407
|
+
const req = JSON.parse(trimmed);
|
|
408
|
+
const res = await this.handleRequest(req);
|
|
409
|
+
if (res) {
|
|
410
|
+
process.stdout.write(`${JSON.stringify(res)}
|
|
411
|
+
`);
|
|
412
|
+
}
|
|
413
|
+
} catch (err) {
|
|
414
|
+
const parseErr = {
|
|
415
|
+
jsonrpc: "2.0",
|
|
416
|
+
id: null,
|
|
417
|
+
error: {
|
|
418
|
+
code: -32700,
|
|
419
|
+
message: err instanceof Error ? err.message : "Parse error"
|
|
420
|
+
}
|
|
421
|
+
};
|
|
422
|
+
process.stdout.write(`${JSON.stringify(parseErr)}
|
|
423
|
+
`);
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
if (this.session) {
|
|
427
|
+
await this.session.disconnect().catch(() => void 0);
|
|
428
|
+
this.session = null;
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
};
|
|
432
|
+
|
|
433
|
+
export {
|
|
434
|
+
formatSelectorCode,
|
|
435
|
+
buildFlowFileFromLines,
|
|
436
|
+
SPANA_MCP_TOOLS,
|
|
437
|
+
SpanaMcpServer
|
|
438
|
+
};
|
|
439
|
+
//# sourceMappingURL=chunk-H3RWZCID.js.map
|