spana-test 0.8.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent/index.d.ts +2 -2
- package/dist/agent/index.js +7 -7
- package/dist/{allure-RAEK4SIH.js → allure-FGVR5LND.js} +5 -1
- package/dist/allure-FGVR5LND.js.map +1 -0
- package/dist/app-xIYd2jde.d.ts +1309 -0
- package/dist/{chunk-3FXDOTFI.js → chunk-66D3C7NB.js} +326 -61
- package/dist/chunk-66D3C7NB.js.map +1 -0
- package/dist/{chunk-WKVU24B6.js → chunk-6GBAPW6K.js} +12 -8
- package/dist/chunk-6GBAPW6K.js.map +1 -0
- package/dist/{chunk-2T4K7BJ3.js → chunk-7QFJ7MDH.js} +4 -2
- package/dist/chunk-7QFJ7MDH.js.map +1 -0
- package/dist/{chunk-AJCSETN6.js → chunk-B35G77DN.js} +1122 -387
- package/dist/chunk-B35G77DN.js.map +1 -0
- package/dist/{chunk-SNL4X67N.js → chunk-B473XZOM.js} +441 -123
- package/dist/chunk-B473XZOM.js.map +1 -0
- package/dist/{chunk-Y2RZNOKU.js → chunk-C2HBFEMQ.js} +2 -2
- package/dist/{chunk-PLE7RFQE.js → chunk-DP7MGXHN.js} +26 -1
- package/dist/chunk-DP7MGXHN.js.map +1 -0
- package/dist/{chunk-PMXSU5MS.js → chunk-IXON7DMB.js} +2 -2
- package/dist/{chunk-QP4MDUBY.js → chunk-VP6V4XEJ.js} +2 -2
- package/dist/{chunk-NS2HLJO4.js → chunk-Y6KMJJ2T.js} +3 -3
- package/dist/{chunk-RKYKRGHB.js → chunk-Z6K4QQAR.js} +128 -6
- package/dist/chunk-Z6K4QQAR.js.map +1 -0
- package/dist/cli.js +17 -12
- package/dist/cli.js.map +1 -1
- package/dist/config-loader-WLPQ5WVH.js +9 -0
- package/dist/{console-BGAK7Z2L.js → console-DIYEJSSP.js} +9 -2
- package/dist/console-DIYEJSSP.js.map +1 -0
- package/dist/{daemon-manager-DDYQITPD.js → daemon-manager-2EQDVUVM.js} +8 -2
- package/dist/{doctor-command-HEQQOYUR.js → doctor-command-QIYBI7ZF.js} +4 -4
- package/dist/{flow-Md5xLwbX.d.ts → flow-CI5parw2.d.ts} +24 -3
- package/dist/gherkin/steps.d.ts +2 -2
- package/dist/{html-JO2YNRWX.js → html-FLMWPFQD.js} +2 -1
- package/dist/html-FLMWPFQD.js.map +1 -0
- package/dist/index.d.ts +50 -8
- package/dist/index.js +43 -13
- package/dist/index.js.map +1 -1
- package/dist/{installer-IYGMG7LS.js → installer-5UHTYQTB.js} +3 -3
- package/dist/{junit-HLC62MK6.js → junit-CGB3LKHD.js} +3 -2
- package/dist/junit-CGB3LKHD.js.map +1 -0
- package/dist/{runner-TF4OKPYP.js → runner-JID2YWRE.js} +6 -2
- package/dist/{server-JPNH33MX.js → server-6KQSTQIG.js} +13 -13
- package/dist/{server-4PEREPHY.js → server-UIRGHUYM.js} +2 -2
- package/dist/{session-V4PYJXNB.js → session-BE6U34DA.js} +6 -6
- package/dist/{session-D9e30RVS.d.ts → session-Bt_mbUWg.d.ts} +3 -1
- package/dist/{studio-command-JOIFCOHC.js → studio-command-TXQTIWRS.js} +2 -2
- package/dist/{test-command-JCO2HPYI.js → test-command-CCSQPKWU.js} +110 -29
- package/dist/test-command-CCSQPKWU.js.map +1 -0
- package/dist/{validator-BLOLIHUY.js → validator-YWNHCU2S.js} +3 -3
- package/native/win32-x64/spana_native.dll +0 -0
- package/package.json +1 -1
- package/dist/allure-RAEK4SIH.js.map +0 -1
- package/dist/app-CgbLADmF.d.ts +0 -1191
- package/dist/chunk-2T4K7BJ3.js.map +0 -1
- package/dist/chunk-3FXDOTFI.js.map +0 -1
- package/dist/chunk-AJCSETN6.js.map +0 -1
- package/dist/chunk-PLE7RFQE.js.map +0 -1
- package/dist/chunk-RKYKRGHB.js.map +0 -1
- package/dist/chunk-SNL4X67N.js.map +0 -1
- package/dist/chunk-WKVU24B6.js.map +0 -1
- package/dist/config-loader-5FU45FXK.js +0 -9
- package/dist/console-BGAK7Z2L.js.map +0 -1
- package/dist/html-JO2YNRWX.js.map +0 -1
- package/dist/junit-HLC62MK6.js.map +0 -1
- package/dist/test-command-JCO2HPYI.js.map +0 -1
- /package/dist/{chunk-Y2RZNOKU.js.map → chunk-C2HBFEMQ.js.map} +0 -0
- /package/dist/{chunk-PMXSU5MS.js.map → chunk-IXON7DMB.js.map} +0 -0
- /package/dist/{chunk-QP4MDUBY.js.map → chunk-VP6V4XEJ.js.map} +0 -0
- /package/dist/{chunk-NS2HLJO4.js.map → chunk-Y6KMJJ2T.js.map} +0 -0
- /package/dist/{config-loader-5FU45FXK.js.map → config-loader-WLPQ5WVH.js.map} +0 -0
- /package/dist/{daemon-manager-DDYQITPD.js.map → daemon-manager-2EQDVUVM.js.map} +0 -0
- /package/dist/{doctor-command-HEQQOYUR.js.map → doctor-command-QIYBI7ZF.js.map} +0 -0
- /package/dist/{installer-IYGMG7LS.js.map → installer-5UHTYQTB.js.map} +0 -0
- /package/dist/{runner-TF4OKPYP.js.map → runner-JID2YWRE.js.map} +0 -0
- /package/dist/{server-JPNH33MX.js.map → server-6KQSTQIG.js.map} +0 -0
- /package/dist/{server-4PEREPHY.js.map → server-UIRGHUYM.js.map} +0 -0
- /package/dist/{session-V4PYJXNB.js.map → session-BE6U34DA.js.map} +0 -0
- /package/dist/{studio-command-JOIFCOHC.js.map → studio-command-TXQTIWRS.js.map} +0 -0
- /package/dist/{validator-BLOLIHUY.js.map → validator-YWNHCU2S.js.map} +0 -0
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
discoverStepFiles,
|
|
4
4
|
loadStepFiles,
|
|
5
5
|
loadTestSource
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-DP7MGXHN.js";
|
|
7
7
|
|
|
8
8
|
// src/core/validator.ts
|
|
9
9
|
import { stat } from "fs/promises";
|
|
@@ -124,4 +124,4 @@ export {
|
|
|
124
124
|
validateFlows,
|
|
125
125
|
validateProject
|
|
126
126
|
};
|
|
127
|
-
//# sourceMappingURL=chunk-
|
|
127
|
+
//# sourceMappingURL=chunk-C2HBFEMQ.js.map
|
|
@@ -113,6 +113,29 @@ function filterFlows(flows, opts) {
|
|
|
113
113
|
return true;
|
|
114
114
|
});
|
|
115
115
|
}
|
|
116
|
+
function focusFlows(flows) {
|
|
117
|
+
return flows.some((flow) => flow.config.only) ? flows.filter((flow) => flow.config.only) : flows;
|
|
118
|
+
}
|
|
119
|
+
function getFlowSkip(flow, platform) {
|
|
120
|
+
const matches = (condition) => {
|
|
121
|
+
if (typeof condition !== "object") return condition === true;
|
|
122
|
+
const platforms = [condition.platform ?? []].flat();
|
|
123
|
+
return (!platforms.length || platforms.includes(platform)) && (!condition.env || Boolean(process.env[condition.env]));
|
|
124
|
+
};
|
|
125
|
+
for (const modifier of ["fixme", "skip"]) {
|
|
126
|
+
const condition = flow.config[modifier];
|
|
127
|
+
if (matches(condition)) {
|
|
128
|
+
return {
|
|
129
|
+
name: flow.name,
|
|
130
|
+
platform,
|
|
131
|
+
status: "skipped",
|
|
132
|
+
durationMs: 0,
|
|
133
|
+
modifier,
|
|
134
|
+
...typeof condition === "object" && condition.reason ? { skipReason: condition.reason } : {}
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
116
139
|
function applyShard(items, shard, options) {
|
|
117
140
|
if (!shard || shard.total === 1 || items.length === 0) {
|
|
118
141
|
return items;
|
|
@@ -159,6 +182,8 @@ export {
|
|
|
159
182
|
discoverFlows,
|
|
160
183
|
discoverStepFiles,
|
|
161
184
|
filterFlows,
|
|
185
|
+
focusFlows,
|
|
186
|
+
getFlowSkip,
|
|
162
187
|
applyShard
|
|
163
188
|
};
|
|
164
|
-
//# sourceMappingURL=chunk-
|
|
189
|
+
//# sourceMappingURL=chunk-DP7MGXHN.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/core/runner.ts"],"sourcesContent":["import { readdir, readFile, stat } from \"node:fs/promises\";\nimport { join, resolve } from \"node:path\";\nimport type { FlowDefinition, FlowConfig, FlowSkipCondition } from \"../api/flow.js\";\nimport type { Platform } from \"../schemas/selector.js\";\nimport type { FlowResult } from \"../report/types.js\";\n\nexport interface DiscoverOptions {\n tags?: string[];\n grep?: string;\n platforms?: Platform[];\n /** Glob patterns for step definition files (relative to flowDir). */\n stepFiles?: string[];\n}\n\nexport interface ShardOptions {\n current: number;\n total: number;\n}\n\nexport async function loadFlowFile(filePath: string): Promise<FlowDefinition> {\n const absolutePath = resolve(filePath);\n const mod = await import(absolutePath);\n\n if (!mod.default) {\n throw new Error(`No default export found in ${filePath}`);\n }\n\n const flowDef = mod.default as FlowDefinition;\n if (!flowDef.name || typeof flowDef.fn !== \"function\") {\n throw new Error(`Invalid flow definition in ${filePath}`);\n }\n\n // Merge exported settings if present\n if (mod.settings) {\n Object.assign(flowDef.config, mod.settings as FlowConfig);\n }\n\n flowDef.sourcePath ??= absolutePath;\n return flowDef;\n}\n\n/**\n * Load a test source file and return one or more FlowDefinitions.\n * Handles both native .flow.ts/.test.ts files and .feature files.\n */\nexport async function loadTestSource(filePath: string): Promise<FlowDefinition[]> {\n const absolutePath = resolve(filePath);\n\n if (absolutePath.endsWith(\".feature\")) {\n return loadFeatureFile(absolutePath);\n }\n\n const flow = await loadFlowFile(absolutePath);\n return [flow];\n}\n\nasync function loadFeatureFile(filePath: string): Promise<FlowDefinition[]> {\n let compileFeature: typeof import(\"../gherkin/compiler.js\").compileFeature;\n try {\n const mod = await import(\"../gherkin/compiler.js\");\n compileFeature = mod.compileFeature;\n } catch {\n throw new Error(\n `Cannot load .feature files: install @cucumber/gherkin, @cucumber/messages, and @cucumber/cucumber-expressions as dependencies.`,\n );\n }\n\n const source = await readFile(filePath, \"utf-8\");\n return compileFeature(source, filePath);\n}\n\n/**\n * Load step definition files so their Given/When/Then registrations\n * are available before feature compilation.\n */\nexport async function loadStepFiles(paths: string[]): Promise<void> {\n for (const p of paths) {\n await import(resolve(p));\n }\n}\n\nexport async function discoverFlows(pathOrDir: string): Promise<string[]> {\n const absolute = resolve(pathOrDir);\n const stats = await stat(absolute);\n\n if (!stats.isDirectory()) {\n return [absolute];\n }\n\n const results: string[] = [];\n\n async function walk(dir: string): Promise<void> {\n const entries = await readdir(dir, { withFileTypes: true });\n for (const entry of entries) {\n const fullPath = join(dir, entry.name);\n if (entry.isDirectory()) {\n await walk(fullPath);\n } else if (\n entry.name.endsWith(\".flow.ts\") ||\n entry.name.endsWith(\".test.ts\") ||\n entry.name.endsWith(\".feature\")\n ) {\n results.push(fullPath);\n }\n }\n }\n\n await walk(absolute);\n return results.toSorted();\n}\n\n/**\n * Discover step definition files within a directory.\n * Looks for files in steps/ directories or matching *.steps.ts pattern.\n */\nexport async function discoverStepFiles(pathOrDir: string): Promise<string[]> {\n const absolute = resolve(pathOrDir);\n const stats = await stat(absolute).catch(() => null);\n if (!stats?.isDirectory()) return [];\n\n const results: string[] = [];\n\n async function walk(dir: string): Promise<void> {\n const entries = await readdir(dir, { withFileTypes: true });\n for (const entry of entries) {\n const fullPath = join(dir, entry.name);\n if (entry.isDirectory()) {\n await walk(fullPath);\n } else if (entry.name.endsWith(\".steps.ts\") || dir.includes(\"/steps\")) {\n if (entry.name.endsWith(\".ts\")) {\n results.push(fullPath);\n }\n }\n }\n }\n\n await walk(absolute);\n return results.toSorted();\n}\n\nexport function filterFlows(flows: FlowDefinition[], opts: DiscoverOptions): FlowDefinition[] {\n return flows.filter((flow) => {\n if (opts.tags && opts.tags.length > 0) {\n const flowTags = flow.config.tags ?? [];\n if (!opts.tags.some((t) => flowTags.includes(t))) return false;\n }\n if (opts.grep) {\n if (!flow.name.toLowerCase().includes(opts.grep.toLowerCase())) return false;\n }\n if (opts.platforms && opts.platforms.length > 0) {\n const flowPlatforms = flow.config.platforms;\n if (flowPlatforms && !opts.platforms.some((p) => flowPlatforms.includes(p))) return false;\n }\n // Evaluate when conditions\n if (flow.config.when) {\n const when = flow.config.when;\n\n if (when.platform) {\n const allowedPlatforms = Array.isArray(when.platform) ? when.platform : [when.platform];\n if (opts.platforms && opts.platforms.length > 0) {\n if (!opts.platforms.some((p) => allowedPlatforms.includes(p))) return false;\n }\n }\n\n if (when.env && !process.env[when.env]) {\n return false;\n }\n }\n return true;\n });\n}\n\nexport function focusFlows(flows: FlowDefinition[]): FlowDefinition[] {\n return flows.some((flow) => flow.config.only) ? flows.filter((flow) => flow.config.only) : flows;\n}\n\nexport function getFlowSkip(flow: FlowDefinition, platform: Platform): FlowResult | undefined {\n const matches = (condition: FlowSkipCondition | undefined) => {\n if (typeof condition !== \"object\") return condition === true;\n const platforms = [condition.platform ?? []].flat();\n return (\n (!platforms.length || platforms.includes(platform)) &&\n (!condition.env || Boolean(process.env[condition.env]))\n );\n };\n for (const modifier of [\"fixme\", \"skip\"] as const) {\n const condition = flow.config[modifier];\n if (matches(condition)) {\n return {\n name: flow.name,\n platform,\n status: \"skipped\",\n durationMs: 0,\n modifier,\n ...(typeof condition === \"object\" && condition.reason\n ? { skipReason: condition.reason }\n : {}),\n };\n }\n }\n}\n\nexport interface BalancedShardOptions<T> {\n /** Historical per-flow durations in ms (e.g. from `.spana/last-run.json`) for LPT balanced sharding. */\n durationHintsMs?: Record<string, number>;\n /** Extract flow name from each item when using `durationHintsMs`. */\n getName?: (item: T) => string;\n}\n\n/**\n * Partition items across CI shards.\n * When `durationHintsMs` are provided (e.g. from `.spana/last-run.json`), uses\n * Longest-Processing-Time-First (LPT) bin packing so every shard finishes at\n * roughly the same wall-clock time instead of stranding slow tests on one shard.\n */\nexport function applyShard<T>(\n items: T[],\n shard?: ShardOptions,\n options?: BalancedShardOptions<T>,\n): T[] {\n if (!shard || shard.total === 1 || items.length === 0) {\n return items;\n }\n\n const hints = options?.durationHintsMs;\n const getName = options?.getName;\n if (hints && getName && Object.keys(hints).length > 0) {\n const knownDurations = Object.values(hints).filter((d) => typeof d === \"number\" && d > 0);\n const defaultDuration =\n knownDurations.length > 0\n ? knownDurations.reduce((a, b) => a + b, 0) / knownDurations.length\n : 1000;\n\n const indexed = items.map((item, originalIndex) => {\n const weight = hints[getName(item)] ?? defaultDuration;\n return { item, originalIndex, weight };\n });\n\n // Sort descending by predicted duration (stable tie-breaker by original index)\n indexed.sort((a, b) => b.weight - a.weight || a.originalIndex - b.originalIndex);\n\n const loads = Array.from({ length: shard.total }, () => 0);\n const buckets: Array<Array<{ item: T; originalIndex: number }>> = Array.from(\n { length: shard.total },\n () => [],\n );\n\n for (const entry of indexed) {\n let bestBucket = 0;\n for (let b = 1; b < shard.total; b++) {\n if (loads[b]! < loads[bestBucket]!) {\n bestBucket = b;\n }\n }\n loads[bestBucket] = loads[bestBucket]! + entry.weight;\n buckets[bestBucket]!.push({ item: entry.item, originalIndex: entry.originalIndex });\n }\n\n const chosen = buckets[shard.current - 1] ?? [];\n chosen.sort((a, b) => a.originalIndex - b.originalIndex);\n return chosen.map((c) => c.item);\n }\n\n const itemsPerShard = Math.max(Math.ceil(items.length / shard.total), 1);\n const start = (shard.current - 1) * itemsPerShard;\n const end =\n shard.current === shard.total ? items.length : Math.min(start + itemsPerShard, items.length);\n\n return items.slice(start, end);\n}\n"],"mappings":";AAAA,SAAS,SAAS,UAAU,YAAY;AACxC,SAAS,MAAM,eAAe;AAkB9B,eAAsB,aAAa,UAA2C;AAC5E,QAAM,eAAe,QAAQ,QAAQ;AACrC,QAAM,MAAM,MAAM,OAAO;AAEzB,MAAI,CAAC,IAAI,SAAS;AAChB,UAAM,IAAI,MAAM,8BAA8B,QAAQ,EAAE;AAAA,EAC1D;AAEA,QAAM,UAAU,IAAI;AACpB,MAAI,CAAC,QAAQ,QAAQ,OAAO,QAAQ,OAAO,YAAY;AACrD,UAAM,IAAI,MAAM,8BAA8B,QAAQ,EAAE;AAAA,EAC1D;AAGA,MAAI,IAAI,UAAU;AAChB,WAAO,OAAO,QAAQ,QAAQ,IAAI,QAAsB;AAAA,EAC1D;AAEA,UAAQ,eAA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,WAAO,OAAO,IAAI,CAAC,MAAM,EAAE,IAAI;AAAA,EACjC;AAEA,QAAM,gBAAgB,KAAK,IAAI,KAAK,KAAK,MAAM,SAAS,MAAM,KAAK,GAAG,CAAC;AACvE,QAAM,SAAS,MAAM,UAAU,KAAK;AACpC,QAAM,MACJ,MAAM,YAAY,MAAM,QAAQ,MAAM,SAAS,KAAK,IAAI,QAAQ,eAAe,MAAM,MAAM;AAE7F,SAAO,MAAM,MAAM,OAAO,GAAG;AAC/B;","names":[]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
formatConfigValidationError,
|
|
3
3
|
validateConfig
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-7QFJ7MDH.js";
|
|
5
5
|
|
|
6
6
|
// src/cli/config-loader.ts
|
|
7
7
|
import { existsSync } from "fs";
|
|
@@ -123,4 +123,4 @@ ${formatConfigValidationError(error)}`,
|
|
|
123
123
|
export {
|
|
124
124
|
loadConfig
|
|
125
125
|
};
|
|
126
|
-
//# sourceMappingURL=chunk-
|
|
126
|
+
//# sourceMappingURL=chunk-IXON7DMB.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
getHealthyWarmDaemon,
|
|
3
3
|
registerWarmDaemon
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-Z6K4QQAR.js";
|
|
5
5
|
import {
|
|
6
6
|
allocatePort,
|
|
7
7
|
releasePort
|
|
@@ -342,4 +342,4 @@ export {
|
|
|
342
342
|
setupWDAForDevice,
|
|
343
343
|
setupWDA
|
|
344
344
|
};
|
|
345
|
-
//# sourceMappingURL=chunk-
|
|
345
|
+
//# sourceMappingURL=chunk-VP6V4XEJ.js.map
|
|
@@ -199,11 +199,11 @@ var SpanaMcpServer = class {
|
|
|
199
199
|
runFlowFn;
|
|
200
200
|
constructor(options = {}) {
|
|
201
201
|
this.connectFn = options.connectFn ?? (async (opts) => {
|
|
202
|
-
const { connect } = await import("./session-
|
|
202
|
+
const { connect } = await import("./session-BE6U34DA.js");
|
|
203
203
|
return connect(opts);
|
|
204
204
|
});
|
|
205
205
|
this.runFlowFn = options.runFlowFn ?? (async ({ flowPath, platform }) => {
|
|
206
|
-
const { runTestCommand } = await import("./test-command-
|
|
206
|
+
const { runTestCommand } = await import("./test-command-CCSQPKWU.js");
|
|
207
207
|
return runTestCommand({
|
|
208
208
|
flowPath,
|
|
209
209
|
platforms: platform ? [platform] : [],
|
|
@@ -537,4 +537,4 @@ export {
|
|
|
537
537
|
SPANA_MCP_TOOLS,
|
|
538
538
|
SpanaMcpServer
|
|
539
539
|
};
|
|
540
|
-
//# sourceMappingURL=chunk-
|
|
540
|
+
//# sourceMappingURL=chunk-Y6KMJJ2T.js.map
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// src/runtime/daemon-manager.ts
|
|
2
|
+
import { execFileSync } from "child_process";
|
|
2
3
|
import { createHash } from "crypto";
|
|
3
4
|
import {
|
|
4
5
|
existsSync,
|
|
@@ -12,6 +13,7 @@ import {
|
|
|
12
13
|
} from "fs";
|
|
13
14
|
import { tmpdir } from "os";
|
|
14
15
|
import { dirname, join } from "path";
|
|
16
|
+
var DEFAULT_WARM_DAEMON_IDLE_TTL_MS = 30 * 60 * 1e3;
|
|
15
17
|
function defaultDaemonStatePath() {
|
|
16
18
|
return join(tmpdir(), "spana-warm-daemons.json");
|
|
17
19
|
}
|
|
@@ -71,7 +73,7 @@ function deleteScopeRecord(kind, deviceId) {
|
|
|
71
73
|
}
|
|
72
74
|
}
|
|
73
75
|
function killPidTree(pid) {
|
|
74
|
-
if (!pid || pid <= 0) return;
|
|
76
|
+
if (!pid || pid <= 0 || pid === process.pid) return;
|
|
75
77
|
const targets = process.platform !== "win32" ? [-pid, pid] : [pid];
|
|
76
78
|
for (const target of targets) {
|
|
77
79
|
try {
|
|
@@ -108,6 +110,15 @@ function loadDaemonRegistry(stateFile = defaultDaemonStatePath()) {
|
|
|
108
110
|
function saveDaemonRegistry(registry, stateFile = defaultDaemonStatePath()) {
|
|
109
111
|
atomicWriteJson(stateFile, registry);
|
|
110
112
|
}
|
|
113
|
+
function resolveIdleTtlMs(explicit) {
|
|
114
|
+
if (explicit !== void 0) return explicit;
|
|
115
|
+
const envRaw = process.env["SPANA_DAEMON_IDLE_TTL_MS"];
|
|
116
|
+
if (envRaw !== void 0) {
|
|
117
|
+
const parsed = Number(envRaw);
|
|
118
|
+
if (Number.isFinite(parsed) && parsed >= 0) return parsed;
|
|
119
|
+
}
|
|
120
|
+
return DEFAULT_WARM_DAEMON_IDLE_TTL_MS;
|
|
121
|
+
}
|
|
111
122
|
function registerWarmDaemon(record, stateFile = defaultDaemonStatePath()) {
|
|
112
123
|
const key = daemonKey(record.kind, record.deviceId);
|
|
113
124
|
const existing = loadDaemonRegistry(stateFile);
|
|
@@ -118,11 +129,30 @@ function registerWarmDaemon(record, stateFile = defaultDaemonStatePath()) {
|
|
|
118
129
|
);
|
|
119
130
|
}
|
|
120
131
|
}
|
|
132
|
+
const prev = existing.daemons[key];
|
|
133
|
+
if (prev) {
|
|
134
|
+
if (prev.pid && prev.pid !== record.pid && isPidAlive(prev.pid)) {
|
|
135
|
+
killPidTree(prev.pid);
|
|
136
|
+
}
|
|
137
|
+
if (prev.tunnelPid && prev.tunnelPid !== record.tunnelPid && isPidAlive(prev.tunnelPid)) {
|
|
138
|
+
killPidTree(prev.tunnelPid);
|
|
139
|
+
}
|
|
140
|
+
if (prev.userDataDir && prev.userDataDir !== record.userDataDir) {
|
|
141
|
+
try {
|
|
142
|
+
rmSync(prev.userDataDir, { recursive: true, force: true });
|
|
143
|
+
} catch {
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
const stamped = {
|
|
148
|
+
...record,
|
|
149
|
+
lastUsedAt: record.lastUsedAt ?? record.startedAt ?? (/* @__PURE__ */ new Date()).toISOString()
|
|
150
|
+
};
|
|
121
151
|
if (isUsingDefaultStateFile(stateFile)) {
|
|
122
|
-
atomicWriteJson(scopeRecordPath(record.kind, record.deviceId),
|
|
152
|
+
atomicWriteJson(scopeRecordPath(record.kind, record.deviceId), stamped);
|
|
123
153
|
return;
|
|
124
154
|
}
|
|
125
|
-
existing.daemons[key] =
|
|
155
|
+
existing.daemons[key] = stamped;
|
|
126
156
|
saveDaemonRegistry(existing, stateFile);
|
|
127
157
|
}
|
|
128
158
|
function updateWarmDaemonSession(kind, deviceId, sessionId, bundleId, stateFile = defaultDaemonStatePath()) {
|
|
@@ -173,8 +203,17 @@ async function getHealthyWarmDaemon(kind, deviceId, options = {}) {
|
|
|
173
203
|
const fetchFn = options.fetchFn ?? fetch;
|
|
174
204
|
const timeoutMs = options.timeoutMs ?? 1500;
|
|
175
205
|
const statusPath = options.statusPath ?? (kind === "chromium" ? "/json/version" : "/status");
|
|
206
|
+
const idleTtlMs = resolveIdleTtlMs(options.idleTtlMs);
|
|
207
|
+
const nowMs = options.nowMs ?? Date.now();
|
|
176
208
|
const record = isUsingDefaultStateFile(stateFile) ? readScopeRecord(kind, deviceId) ?? loadDaemonRegistry(stateFile).daemons[daemonKey(kind, deviceId)] : loadDaemonRegistry(stateFile).daemons[daemonKey(kind, deviceId)];
|
|
177
209
|
if (!record) return null;
|
|
210
|
+
if (idleTtlMs > 0) {
|
|
211
|
+
const lastTs = Date.parse(record.lastUsedAt ?? record.startedAt);
|
|
212
|
+
if (Number.isFinite(lastTs) && nowMs - lastTs > idleTtlMs) {
|
|
213
|
+
stopWarmDaemon(kind, deviceId, stateFile);
|
|
214
|
+
return null;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
178
217
|
try {
|
|
179
218
|
const controller = new AbortController();
|
|
180
219
|
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
@@ -183,16 +222,93 @@ async function getHealthyWarmDaemon(kind, deviceId, options = {}) {
|
|
|
183
222
|
signal: controller.signal
|
|
184
223
|
});
|
|
185
224
|
if (res.ok) {
|
|
186
|
-
|
|
225
|
+
const touched = {
|
|
226
|
+
...record,
|
|
227
|
+
lastUsedAt: new Date(nowMs).toISOString()
|
|
228
|
+
};
|
|
229
|
+
if (isUsingDefaultStateFile(stateFile)) {
|
|
230
|
+
try {
|
|
231
|
+
atomicWriteJson(scopeRecordPath(kind, deviceId), touched);
|
|
232
|
+
} catch {
|
|
233
|
+
}
|
|
234
|
+
} else {
|
|
235
|
+
try {
|
|
236
|
+
const registry = loadDaemonRegistry(stateFile);
|
|
237
|
+
registry.daemons[daemonKey(kind, deviceId)] = touched;
|
|
238
|
+
saveDaemonRegistry(registry, stateFile);
|
|
239
|
+
} catch {
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
return touched;
|
|
187
243
|
}
|
|
188
244
|
} finally {
|
|
189
245
|
clearTimeout(timer);
|
|
190
246
|
}
|
|
191
247
|
} catch {
|
|
192
248
|
}
|
|
193
|
-
|
|
249
|
+
stopWarmDaemon(kind, deviceId, stateFile);
|
|
194
250
|
return null;
|
|
195
251
|
}
|
|
252
|
+
function reapIdleWarmDaemons(options = {}) {
|
|
253
|
+
const stateFile = options.stateFile ?? defaultDaemonStatePath();
|
|
254
|
+
const idleTtlMs = resolveIdleTtlMs(options.idleTtlMs);
|
|
255
|
+
if (idleTtlMs <= 0) return 0;
|
|
256
|
+
const nowMs = options.nowMs ?? Date.now();
|
|
257
|
+
const records = listWarmDaemons(stateFile);
|
|
258
|
+
let reaped = 0;
|
|
259
|
+
for (const record of records) {
|
|
260
|
+
const lastTs = Date.parse(record.lastUsedAt ?? record.startedAt);
|
|
261
|
+
if (Number.isFinite(lastTs) && nowMs - lastTs > idleTtlMs) {
|
|
262
|
+
if (stopWarmDaemon(record.kind, record.deviceId, stateFile)) {
|
|
263
|
+
reaped++;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
return reaped;
|
|
268
|
+
}
|
|
269
|
+
var SPANA_BROWSER_PROFILE_MARKERS = [
|
|
270
|
+
"spana-cdp-profile-",
|
|
271
|
+
"spana-pw-profile-",
|
|
272
|
+
"spana-browser-profile-"
|
|
273
|
+
];
|
|
274
|
+
function sweepOrphanedSpanaBrowsers(options = {}) {
|
|
275
|
+
if (process.platform === "win32") return 0;
|
|
276
|
+
let psOut = "";
|
|
277
|
+
try {
|
|
278
|
+
psOut = execFileSync("ps", ["-ax", "-o", "pid=,command="], {
|
|
279
|
+
encoding: "utf8",
|
|
280
|
+
stdio: ["ignore", "pipe", "ignore"]
|
|
281
|
+
});
|
|
282
|
+
} catch {
|
|
283
|
+
return 0;
|
|
284
|
+
}
|
|
285
|
+
const exclude = options.excludePids ?? /* @__PURE__ */ new Set();
|
|
286
|
+
let killed = 0;
|
|
287
|
+
const profileDirsToClean = /* @__PURE__ */ new Set();
|
|
288
|
+
for (const rawLine of psOut.split("\n")) {
|
|
289
|
+
const line = rawLine.trim();
|
|
290
|
+
if (!line) continue;
|
|
291
|
+
const match = /^(\d+)\s+(.*)$/.exec(line);
|
|
292
|
+
if (!match) continue;
|
|
293
|
+
const pid = Number.parseInt(match[1], 10);
|
|
294
|
+
const cmd = match[2] ?? "";
|
|
295
|
+
if (!Number.isFinite(pid) || pid <= 0 || pid === process.pid || exclude.has(pid)) continue;
|
|
296
|
+
if (!SPANA_BROWSER_PROFILE_MARKERS.some((marker) => cmd.includes(marker))) continue;
|
|
297
|
+
const dirMatch = /--user-data-dir=([^\s]+)/.exec(cmd);
|
|
298
|
+
if (dirMatch?.[1] && SPANA_BROWSER_PROFILE_MARKERS.some((m) => dirMatch[1].includes(m))) {
|
|
299
|
+
profileDirsToClean.add(dirMatch[1]);
|
|
300
|
+
}
|
|
301
|
+
killPidTree(pid);
|
|
302
|
+
killed++;
|
|
303
|
+
}
|
|
304
|
+
for (const dir of profileDirsToClean) {
|
|
305
|
+
try {
|
|
306
|
+
rmSync(dir, { recursive: true, force: true });
|
|
307
|
+
} catch {
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
return killed;
|
|
311
|
+
}
|
|
196
312
|
function stopWarmDaemon(kind, deviceId, stateFile = defaultDaemonStatePath()) {
|
|
197
313
|
const key = daemonKey(kind, deviceId);
|
|
198
314
|
const record = isUsingDefaultStateFile(stateFile) ? readScopeRecord(kind, deviceId) ?? loadDaemonRegistry(stateFile).daemons[key] : loadDaemonRegistry(stateFile).daemons[key];
|
|
@@ -216,10 +332,14 @@ function stopAllWarmDaemons(stateFile = defaultDaemonStatePath()) {
|
|
|
216
332
|
stopped++;
|
|
217
333
|
}
|
|
218
334
|
}
|
|
335
|
+
if (isUsingDefaultStateFile(stateFile)) {
|
|
336
|
+
stopped += sweepOrphanedSpanaBrowsers();
|
|
337
|
+
}
|
|
219
338
|
return stopped;
|
|
220
339
|
}
|
|
221
340
|
|
|
222
341
|
export {
|
|
342
|
+
DEFAULT_WARM_DAEMON_IDLE_TTL_MS,
|
|
223
343
|
defaultDaemonStatePath,
|
|
224
344
|
defaultDaemonStateDir,
|
|
225
345
|
loadDaemonRegistry,
|
|
@@ -230,7 +350,9 @@ export {
|
|
|
230
350
|
listWarmDaemons,
|
|
231
351
|
isPidAlive,
|
|
232
352
|
getHealthyWarmDaemon,
|
|
353
|
+
reapIdleWarmDaemons,
|
|
354
|
+
sweepOrphanedSpanaBrowsers,
|
|
233
355
|
stopWarmDaemon,
|
|
234
356
|
stopAllWarmDaemons
|
|
235
357
|
};
|
|
236
|
-
//# sourceMappingURL=chunk-
|
|
358
|
+
//# sourceMappingURL=chunk-Z6K4QQAR.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/runtime/daemon-manager.ts"],"sourcesContent":["import { execFileSync } from \"node:child_process\";\nimport { createHash } from \"node:crypto\";\nimport {\n existsSync,\n mkdirSync,\n readdirSync,\n readFileSync,\n renameSync,\n rmSync,\n unlinkSync,\n writeFileSync,\n} from \"node:fs\";\nimport { tmpdir } from \"node:os\";\nimport { dirname, join } from \"node:path\";\n\nexport type WarmDaemonKind = \"wda\" | \"uiautomator2\" | \"iproxy\" | \"chromium\";\n\nexport const DEFAULT_WARM_DAEMON_IDLE_TTL_MS = 30 * 60 * 1000;\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 temporary profile directory created for this daemon (cleaned up on stop). */\n userDataDir?: string;\n /** Optional reusable WDA/UiAutomator2 session ID persisted across runs */\n sessionId?: string;\n bundleId?: string;\n startedAt: string;\n /** Last timestamp this daemon was verified healthy / reused (used for idle TTL reaping). */\n lastUsedAt?: 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\n/** Per-scope atomic state directory so concurrent OS processes never overwrite each other's daemon records. */\nexport function defaultDaemonStateDir(): string {\n return join(tmpdir(), \"spana-daemons\");\n}\n\nfunction daemonKey(kind: WarmDaemonKind, deviceId: string): string {\n return `${kind}:${deviceId}`;\n}\n\nfunction scopeRecordPath(kind: WarmDaemonKind, deviceId: string): string {\n const safe = `${kind}-${deviceId}`.replaceAll(/[^a-zA-Z0-9._-]/g, \"_\").slice(0, 64);\n const hash = createHash(\"sha256\").update(daemonKey(kind, deviceId)).digest(\"hex\").slice(0, 10);\n return join(defaultDaemonStateDir(), `${safe}-${hash}.json`);\n}\n\nfunction isUsingDefaultStateFile(stateFile?: string): boolean {\n return !stateFile || stateFile === defaultDaemonStatePath();\n}\n\nfunction atomicWriteJson(filePath: string, data: unknown): void {\n mkdirSync(dirname(filePath), { recursive: true });\n const tmpPath = `${filePath}.${process.pid}.${Math.random().toString(36).slice(2, 8)}.tmp`;\n writeFileSync(tmpPath, JSON.stringify(data, null, 2), \"utf-8\");\n renameSync(tmpPath, filePath);\n}\n\nfunction loadScopeRecords(): Record<string, WarmDaemonRecord> {\n const dir = defaultDaemonStateDir();\n const out: Record<string, WarmDaemonRecord> = {};\n if (!existsSync(dir)) return out;\n try {\n for (const file of readdirSync(dir)) {\n if (!file.endsWith(\".json\")) continue;\n try {\n const parsed = JSON.parse(readFileSync(join(dir, file), \"utf-8\")) as WarmDaemonRecord;\n if (parsed && typeof parsed.kind === \"string\" && typeof parsed.deviceId === \"string\") {\n out[daemonKey(parsed.kind, parsed.deviceId)] = parsed;\n }\n } catch {\n // skip corrupted scope file\n }\n }\n } catch {\n // ignore unreadable dir\n }\n return out;\n}\n\nfunction readScopeRecord(kind: WarmDaemonKind, deviceId: string): WarmDaemonRecord | undefined {\n const filePath = scopeRecordPath(kind, deviceId);\n if (!existsSync(filePath)) return undefined;\n try {\n return JSON.parse(readFileSync(filePath, \"utf-8\")) as WarmDaemonRecord;\n } catch {\n return undefined;\n }\n}\n\nfunction deleteScopeRecord(kind: WarmDaemonKind, deviceId: string): void {\n const filePath = scopeRecordPath(kind, deviceId);\n try {\n if (existsSync(filePath)) unlinkSync(filePath);\n } catch {\n // already removed\n }\n}\n\nfunction killPidTree(pid: number | undefined): void {\n if (!pid || pid <= 0 || pid === process.pid) return;\n const targets = process.platform !== \"win32\" ? [-pid, pid] : [pid];\n for (const target of targets) {\n try {\n process.kill(target, \"SIGTERM\");\n } catch {\n // process or group already exited\n }\n }\n // If the detached daemon ignores SIGTERM, escalate to SIGKILL immediately when still alive\n if (isPidAlive(pid)) {\n for (const target of targets) {\n try {\n process.kill(target, \"SIGKILL\");\n } catch {\n // already exited\n }\n }\n }\n}\n\nexport function loadDaemonRegistry(stateFile = defaultDaemonStatePath()): DaemonRegistryFile {\n const merged: Record<string, WarmDaemonRecord> = {};\n if (existsSync(stateFile)) {\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 Object.assign(merged, parsed.daemons);\n }\n } catch {\n // corrupted state file — reset cleanly\n }\n }\n if (isUsingDefaultStateFile(stateFile)) {\n Object.assign(merged, loadScopeRecords());\n }\n return { version: 1, daemons: merged };\n}\n\nexport function saveDaemonRegistry(\n registry: DaemonRegistryFile,\n stateFile = defaultDaemonStatePath(),\n): void {\n atomicWriteJson(stateFile, registry);\n}\n\nfunction resolveIdleTtlMs(explicit?: number): number {\n if (explicit !== undefined) return explicit;\n const envRaw = process.env[\"SPANA_DAEMON_IDLE_TTL_MS\"];\n if (envRaw !== undefined) {\n const parsed = Number(envRaw);\n if (Number.isFinite(parsed) && parsed >= 0) return parsed;\n }\n return DEFAULT_WARM_DAEMON_IDLE_TTL_MS;\n}\n\nexport function registerWarmDaemon(\n record: WarmDaemonRecord,\n stateFile = defaultDaemonStatePath(),\n): void {\n const key = daemonKey(record.kind, record.deviceId);\n const existing = loadDaemonRegistry(stateFile);\n // Fail loudly if another live daemon with a DIFFERENT scope already owns this exact host:port\n for (const [otherKey, other] of Object.entries(existing.daemons)) {\n if (\n otherKey !== key &&\n other.host === record.host &&\n other.port === record.port &&\n isPidAlive(other.pid)\n ) {\n throw new Error(\n `Warm daemon port clash on ${record.host}:${record.port}: scope \"${otherKey}\" (pid ${other.pid}) already owns this port.`,\n );\n }\n }\n\n // If this exact scope already had a previous live daemon PID, terminate & clean it up\n // before overwriting the scope record so we never orphan a running browser/daemon process.\n const prev = existing.daemons[key];\n if (prev) {\n if (prev.pid && prev.pid !== record.pid && isPidAlive(prev.pid)) {\n killPidTree(prev.pid);\n }\n if (prev.tunnelPid && prev.tunnelPid !== record.tunnelPid && isPidAlive(prev.tunnelPid)) {\n killPidTree(prev.tunnelPid);\n }\n if (prev.userDataDir && prev.userDataDir !== record.userDataDir) {\n try {\n rmSync(prev.userDataDir, { recursive: true, force: true });\n } catch {\n // ignore temp profile cleanup error\n }\n }\n }\n\n const stamped: WarmDaemonRecord = {\n ...record,\n lastUsedAt: record.lastUsedAt ?? record.startedAt ?? new Date().toISOString(),\n };\n\n if (isUsingDefaultStateFile(stateFile)) {\n atomicWriteJson(scopeRecordPath(record.kind, record.deviceId), stamped);\n return;\n }\n\n existing.daemons[key] = stamped;\n saveDaemonRegistry(existing, 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 if (isUsingDefaultStateFile(stateFile)) {\n const scopeRec = readScopeRecord(kind, deviceId);\n if (scopeRec) {\n atomicWriteJson(scopeRecordPath(kind, deviceId), {\n ...scopeRec,\n sessionId,\n ...(bundleId ? { bundleId } : {}),\n });\n return;\n }\n }\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 if (isUsingDefaultStateFile(stateFile)) {\n deleteScopeRecord(kind, deviceId);\n }\n if (existsSync(stateFile)) {\n const raw = loadDaemonRegistry(stateFile);\n if (daemonKey(kind, deviceId) in raw.daemons) {\n delete raw.daemons[daemonKey(kind, deviceId)];\n saveDaemonRegistry(raw, stateFile);\n }\n }\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 / Chromium daemon is still healthy.\n * Removes stale or idle-expired 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 /** Idle TTL in ms (default: 30 minutes or `SPANA_DAEMON_IDLE_TTL_MS`). Pass 0 to disable. */\n idleTtlMs?: number;\n /** Current wall-clock time in ms (for deterministic testing). */\n nowMs?: number;\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 const idleTtlMs = resolveIdleTtlMs(options.idleTtlMs);\n const nowMs = options.nowMs ?? Date.now();\n\n const record = isUsingDefaultStateFile(stateFile)\n ? (readScopeRecord(kind, deviceId) ??\n loadDaemonRegistry(stateFile).daemons[daemonKey(kind, deviceId)])\n : loadDaemonRegistry(stateFile).daemons[daemonKey(kind, deviceId)];\n if (!record) return null;\n\n if (idleTtlMs > 0) {\n const lastTs = Date.parse(record.lastUsedAt ?? record.startedAt);\n if (Number.isFinite(lastTs) && nowMs - lastTs > idleTtlMs) {\n stopWarmDaemon(kind, deviceId, stateFile);\n return null;\n }\n }\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 const touched: WarmDaemonRecord = {\n ...record,\n lastUsedAt: new Date(nowMs).toISOString(),\n };\n if (isUsingDefaultStateFile(stateFile)) {\n try {\n atomicWriteJson(scopeRecordPath(kind, deviceId), touched);\n } catch {\n // ignore touch errors\n }\n } else {\n try {\n const registry = loadDaemonRegistry(stateFile);\n registry.daemons[daemonKey(kind, deviceId)] = touched;\n saveDaemonRegistry(registry, stateFile);\n } catch {\n // ignore touch errors\n }\n }\n return touched;\n }\n } finally {\n clearTimeout(timer);\n }\n } catch {\n // unreachable — prune stale entry\n }\n\n stopWarmDaemon(kind, deviceId, stateFile);\n return null;\n}\n\n/**\n * Stop any warm daemons whose `lastUsedAt` (or `startedAt`) exceeds `idleTtlMs`.\n */\nexport function reapIdleWarmDaemons(\n options: { stateFile?: string; idleTtlMs?: number; nowMs?: number } = {},\n): number {\n const stateFile = options.stateFile ?? defaultDaemonStatePath();\n const idleTtlMs = resolveIdleTtlMs(options.idleTtlMs);\n if (idleTtlMs <= 0) return 0;\n const nowMs = options.nowMs ?? Date.now();\n const records = listWarmDaemons(stateFile);\n let reaped = 0;\n for (const record of records) {\n const lastTs = Date.parse(record.lastUsedAt ?? record.startedAt);\n if (Number.isFinite(lastTs) && nowMs - lastTs > idleTtlMs) {\n if (stopWarmDaemon(record.kind, record.deviceId, stateFile)) {\n reaped++;\n }\n }\n }\n return reaped;\n}\n\nconst SPANA_BROWSER_PROFILE_MARKERS = [\n \"spana-cdp-profile-\",\n \"spana-pw-profile-\",\n \"spana-browser-profile-\",\n];\n\n/**\n * Sweep orphaned Chromium processes launched by Spana (identified by Spana's unique\n * temporary `--user-data-dir=.../spana-*-profile-*` argument) whose PIDs are no longer\n * tracked in the daemon registry, and remove their temporary profile directories.\n */\nexport function sweepOrphanedSpanaBrowsers(options: { excludePids?: Set<number> } = {}): number {\n if (process.platform === \"win32\") return 0;\n let psOut = \"\";\n try {\n psOut = execFileSync(\"ps\", [\"-ax\", \"-o\", \"pid=,command=\"], {\n encoding: \"utf8\",\n stdio: [\"ignore\", \"pipe\", \"ignore\"],\n });\n } catch {\n return 0;\n }\n\n const exclude = options.excludePids ?? new Set<number>();\n let killed = 0;\n const profileDirsToClean = new Set<string>();\n\n for (const rawLine of psOut.split(\"\\n\")) {\n const line = rawLine.trim();\n if (!line) continue;\n const match = /^(\\d+)\\s+(.*)$/.exec(line);\n if (!match) continue;\n const pid = Number.parseInt(match[1]!, 10);\n const cmd = match[2] ?? \"\";\n if (!Number.isFinite(pid) || pid <= 0 || pid === process.pid || exclude.has(pid)) continue;\n if (!SPANA_BROWSER_PROFILE_MARKERS.some((marker) => cmd.includes(marker))) continue;\n\n // Extract --user-data-dir=<path> for cleanup\n const dirMatch = /--user-data-dir=([^\\s]+)/.exec(cmd);\n if (dirMatch?.[1] && SPANA_BROWSER_PROFILE_MARKERS.some((m) => dirMatch[1]!.includes(m))) {\n profileDirsToClean.add(dirMatch[1]!);\n }\n\n killPidTree(pid);\n killed++;\n }\n\n for (const dir of profileDirsToClean) {\n try {\n rmSync(dir, { recursive: true, force: true });\n } catch {\n // ignore temp profile cleanup errors\n }\n }\n\n return killed;\n}\n\n/**\n * Stop the specific process PIDs (and process groups) started by Spana for this daemon record.\n */\nexport function stopWarmDaemon(\n kind: WarmDaemonKind,\n deviceId: string,\n stateFile = defaultDaemonStatePath(),\n): boolean {\n const key = daemonKey(kind, deviceId);\n const record = isUsingDefaultStateFile(stateFile)\n ? (readScopeRecord(kind, deviceId) ?? loadDaemonRegistry(stateFile).daemons[key])\n : loadDaemonRegistry(stateFile).daemons[key];\n if (!record) return false;\n\n killPidTree(record.pid);\n killPidTree(record.tunnelPid);\n\n if (record.userDataDir) {\n try {\n rmSync(record.userDataDir, { recursive: true, force: true });\n } catch {\n // ignore temp profile cleanup error\n }\n }\n\n unregisterWarmDaemon(kind, deviceId, 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 if (isUsingDefaultStateFile(stateFile)) {\n stopped += sweepOrphanedSpanaBrowsers();\n }\n return stopped;\n}\n"],"mappings":";AAAA,SAAS,oBAAoB;AAC7B,SAAS,kBAAkB;AAC3B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,cAAc;AACvB,SAAS,SAAS,YAAY;AAIvB,IAAM,kCAAkC,KAAK,KAAK;AAyBlD,SAAS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M,MAAM,UAAU,MAAM,QAAQ;AACpC,QAAM,SAAS,wBAAwB,SAAS,IAC3C,gBAAgB,MAAM,QAAQ,KAAK,mBAAmB,SAAS,EAAE,QAAQ,GAAG,IAC7E,mBAAmB,SAAS,EAAE,QAAQ,GAAG;AAC7C,MAAI,CAAC,OAAQ,QAAO;AAEpB,cAAY,OAAO,GAAG;AACtB,cAAY,OAAO,SAAS;AAE5B,MAAI,OAAO,aAAa;AACtB,QAAI;AACF,aAAO,OAAO,aAAa,EAAE,WAAW,MAAM,OAAO,KAAK,CAAC;AAAA,IAC7D,QAAQ;AAAA,IAER;AAAA,EACF;AAEA,uBAAqB,MAAM,UAAU,SAAS;AAC9C,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,MAAI,wBAAwB,SAAS,GAAG;AACtC,eAAW,2BAA2B;AAAA,EACxC;AACA,SAAO;AACT;","names":[]}
|
package/dist/cli.js
CHANGED
|
@@ -59,6 +59,7 @@ if (command === "test") {
|
|
|
59
59
|
let strictCache = false;
|
|
60
60
|
let watch = false;
|
|
61
61
|
let updateBaselines = false;
|
|
62
|
+
let jsCoverage = false;
|
|
62
63
|
for (let i = 1; i < args.length; i++) {
|
|
63
64
|
const arg = args[i];
|
|
64
65
|
if (arg === "--platform" && args[i + 1]) {
|
|
@@ -134,11 +135,13 @@ if (command === "test") {
|
|
|
134
135
|
watch = true;
|
|
135
136
|
} else if (arg === "--update-baselines") {
|
|
136
137
|
updateBaselines = true;
|
|
138
|
+
} else if (arg === "--js-coverage") {
|
|
139
|
+
jsCoverage = true;
|
|
137
140
|
} else if (!arg.startsWith("--")) {
|
|
138
141
|
flowPath = arg;
|
|
139
142
|
}
|
|
140
143
|
}
|
|
141
|
-
const { runTestCommand } = await import("./test-command-
|
|
144
|
+
const { runTestCommand } = await import("./test-command-CCSQPKWU.js");
|
|
142
145
|
const success = await runTestCommand({
|
|
143
146
|
platforms,
|
|
144
147
|
tags,
|
|
@@ -170,7 +173,8 @@ if (command === "test") {
|
|
|
170
173
|
changedSince,
|
|
171
174
|
strictCache,
|
|
172
175
|
watch,
|
|
173
|
-
updateBaselines
|
|
176
|
+
updateBaselines,
|
|
177
|
+
jsCoverage
|
|
174
178
|
});
|
|
175
179
|
process.exit(success ? 0 : 1);
|
|
176
180
|
} else if (command === "hierarchy" || command === "selectors") {
|
|
@@ -186,7 +190,7 @@ if (command === "test") {
|
|
|
186
190
|
}
|
|
187
191
|
let config = {};
|
|
188
192
|
try {
|
|
189
|
-
const { loadConfig } = await import("./config-loader-
|
|
193
|
+
const { loadConfig } = await import("./config-loader-WLPQ5WVH.js");
|
|
190
194
|
config = (await loadConfig({ configPath, allowMissing: true })).config;
|
|
191
195
|
} catch (error) {
|
|
192
196
|
const message = normalizeErrorMessage(error);
|
|
@@ -197,7 +201,7 @@ if (command === "test") {
|
|
|
197
201
|
}
|
|
198
202
|
process.exit(1);
|
|
199
203
|
}
|
|
200
|
-
const { connect } = await import("./session-
|
|
204
|
+
const { connect } = await import("./session-BE6U34DA.js");
|
|
201
205
|
let session;
|
|
202
206
|
try {
|
|
203
207
|
session = await connect({
|
|
@@ -274,8 +278,8 @@ if (command === "test") {
|
|
|
274
278
|
path = arg;
|
|
275
279
|
}
|
|
276
280
|
}
|
|
277
|
-
const { discoverFlows } = await import("./runner-
|
|
278
|
-
const { validateProject, isValidationIssue, summarizeValidationResults } = await import("./validator-
|
|
281
|
+
const { discoverFlows } = await import("./runner-JID2YWRE.js");
|
|
282
|
+
const { validateProject, isValidationIssue, summarizeValidationResults } = await import("./validator-YWNHCU2S.js");
|
|
279
283
|
const results = await validateProject(path);
|
|
280
284
|
const { errorCount, warningCount } = summarizeValidationResults(results);
|
|
281
285
|
let flowCount = 0;
|
|
@@ -324,7 +328,7 @@ if (command === "test") {
|
|
|
324
328
|
configPath = arg;
|
|
325
329
|
}
|
|
326
330
|
}
|
|
327
|
-
const { loadConfig } = await import("./config-loader-
|
|
331
|
+
const { loadConfig } = await import("./config-loader-WLPQ5WVH.js");
|
|
328
332
|
try {
|
|
329
333
|
const result = await loadConfig({ configPath });
|
|
330
334
|
if (jsonMode) {
|
|
@@ -375,7 +379,7 @@ if (command === "test") {
|
|
|
375
379
|
pretty = true;
|
|
376
380
|
}
|
|
377
381
|
}
|
|
378
|
-
const { runDoctorCommand } = await import("./doctor-command-
|
|
382
|
+
const { runDoctorCommand } = await import("./doctor-command-QIYBI7ZF.js");
|
|
379
383
|
const success = await runDoctorCommand({
|
|
380
384
|
configPath,
|
|
381
385
|
platforms,
|
|
@@ -398,13 +402,13 @@ if (command === "test") {
|
|
|
398
402
|
}
|
|
399
403
|
let config = {};
|
|
400
404
|
try {
|
|
401
|
-
const { loadConfig } = await import("./config-loader-
|
|
405
|
+
const { loadConfig } = await import("./config-loader-WLPQ5WVH.js");
|
|
402
406
|
config = (await loadConfig({ configPath, allowMissing: true })).config;
|
|
403
407
|
} catch (error) {
|
|
404
408
|
console.log(error instanceof Error ? error.message : String(error));
|
|
405
409
|
process.exit(1);
|
|
406
410
|
}
|
|
407
|
-
const { runStudioCommand } = await import("./studio-command-
|
|
411
|
+
const { runStudioCommand } = await import("./studio-command-TXQTIWRS.js");
|
|
408
412
|
await runStudioCommand({ port, open, config });
|
|
409
413
|
} else if (command === "init") {
|
|
410
414
|
const force = args.includes("--force");
|
|
@@ -491,7 +495,7 @@ if (command === "test") {
|
|
|
491
495
|
}
|
|
492
496
|
} else if (command === "daemon") {
|
|
493
497
|
const sub = args[1] ?? "status";
|
|
494
|
-
const { listWarmDaemons, stopAllWarmDaemons } = await import("./daemon-manager-
|
|
498
|
+
const { listWarmDaemons, stopAllWarmDaemons } = await import("./daemon-manager-2EQDVUVM.js");
|
|
495
499
|
if (sub === "stop") {
|
|
496
500
|
const count = stopAllWarmDaemons();
|
|
497
501
|
console.log(`Stopped ${count} warm daemon(s).`);
|
|
@@ -508,7 +512,7 @@ if (command === "test") {
|
|
|
508
512
|
}
|
|
509
513
|
}
|
|
510
514
|
} else if (command === "mcp") {
|
|
511
|
-
const { SpanaMcpServer } = await import("./server-
|
|
515
|
+
const { SpanaMcpServer } = await import("./server-UIRGHUYM.js");
|
|
512
516
|
const server = new SpanaMcpServer();
|
|
513
517
|
await server.runStdio();
|
|
514
518
|
} else if (command === "version" || args.includes("--version") || args.includes("-v")) {
|
|
@@ -559,6 +563,7 @@ if (command === "test") {
|
|
|
559
563
|
" --processes <m> OS worker processes sharing a dynamic longest-first queue"
|
|
560
564
|
);
|
|
561
565
|
console.log(" --browser <name> Web browser target: chromium|firefox|webkit");
|
|
566
|
+
console.log(" --js-coverage Save JavaScript coverage for Chromium web flows");
|
|
562
567
|
console.log(" --devices <id1>,<id2> Select specific devices for parallel execution");
|
|
563
568
|
console.log(" --verbose Dump detailed failure diagnostics and hierarchy");
|
|
564
569
|
console.log(
|