fix(test-harness): restore promisify(exec) + unblock CLI introspection probes
The vitest child-process guard wrapped exec/execFile without preserving the
`[util.promisify.custom]` symbol, so awaited `execAsync` resolved to a raw
stdout string instead of `{stdout, stderr}`. That single regression cascaded
through ~60 "failing" tests across cli, core, engine, and dashboard whose
production code was actually correct. Also relax the AI-CLI blocklist for
cheap introspection (--version/--help/which …), give SIGTERM'd subprocesses a
brief grace period before being flagged as "left running", fix a few real
test-side bugs uncovered along the way (executor mock step transitions, iOS
last-resort keyboard path, mission SSE replay tests racing with the real AI
agent), and convert dashboard route tests' dynamic `await import("../server.js")`
to static imports so first-test timings drop from 2–5s to <200ms.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -86,10 +86,34 @@ describe("test isolation setup", () => {
|
||||
});
|
||||
|
||||
it("blocks real AI CLI subprocesses from running in tests", () => {
|
||||
expect(() => spawnSync("droid", ["--version"])).toThrow(
|
||||
// Interactive / session-launching invocations stay blocked.
|
||||
expect(() => spawnSync("droid", ["chat"])).toThrow(
|
||||
"Real AI CLI launch blocked during tests",
|
||||
);
|
||||
expect(() => execSync("claude --version", { encoding: "utf-8" })).toThrow(
|
||||
expect(() => execSync("claude -p 'hello world'", { encoding: "utf-8" })).toThrow(
|
||||
"Real AI CLI launch blocked during tests",
|
||||
);
|
||||
});
|
||||
|
||||
it("permits cheap introspection invocations (--version, --help)", () => {
|
||||
// These probe whether the binary is installed without opening an AI
|
||||
// session, and the dashboard CLI-availability probe needs them. We use
|
||||
// binaries from the blocklist that are not installed on test runners
|
||||
// (`openclaw`, `paperclipai`) so the spawn returns ENOENT quickly rather
|
||||
// than actually launching a real CLI on a developer machine.
|
||||
expect(() => spawnSync("openclaw", ["--version"])).not.toThrow(
|
||||
"Real AI CLI launch blocked during tests",
|
||||
);
|
||||
expect(() => spawnSync("paperclipai", ["--help"])).not.toThrow(
|
||||
"Real AI CLI launch blocked during tests",
|
||||
);
|
||||
});
|
||||
|
||||
it("keeps blocking prompt invocations that merely mention --version/--help", () => {
|
||||
expect(() => execSync('claude -p "please print --version literally"', { encoding: "utf-8" })).toThrow(
|
||||
"Real AI CLI launch blocked during tests",
|
||||
);
|
||||
expect(() => spawnSync("openclaw", ["-p", "say --help literally"])).toThrow(
|
||||
"Real AI CLI launch blocked during tests",
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user