test(engine): mock spawn so verification runner works under restart suite
47514942 switched merger verification from exec to spawn-based
execWithProcessGroup, but restart.integration.test.ts only mocked
execSync/exec. spawn() returned undefined, so the merger crashed before
running the test command and any in-review merge test that hit the
verification path failed with VerificationError.
Adds a spawn mock that funnels through the existing execSync mock so a
single mockedExecSync.mockImplementation continues to control both git
calls and verification command outcomes.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -50,6 +50,7 @@ vi.mock("../agent-session-helpers.js", async () => {
|
||||
});
|
||||
vi.mock("node:child_process", () => {
|
||||
const { promisify } = require("node:util");
|
||||
const { EventEmitter } = require("node:events");
|
||||
const execSyncFn = vi.fn().mockReturnValue(Buffer.from(""));
|
||||
const execFn: any = vi.fn((cmd: any, opts: any, cb: any) => {
|
||||
const callback = typeof opts === "function" ? opts : cb;
|
||||
@@ -77,7 +78,31 @@ vi.mock("node:child_process", () => {
|
||||
}
|
||||
});
|
||||
});
|
||||
return { execSync: execSyncFn, exec: execFn };
|
||||
// spawn() is used by the merger's verification runner. Route it through the
|
||||
// same execSyncFn mock so a single mockedExecSync.mockImplementation controls
|
||||
// both git calls (execSync) and verification commands (spawn). Throwing from
|
||||
// execSyncFn ⇒ child emits non-zero close; returning normally ⇒ exit 0.
|
||||
const spawnFn: any = vi.fn((cmd: any, _opts: any) => {
|
||||
const child: any = new EventEmitter();
|
||||
child.pid = 1234;
|
||||
child.stdout = new EventEmitter();
|
||||
child.stderr = new EventEmitter();
|
||||
queueMicrotask(() => {
|
||||
try {
|
||||
const out = execSyncFn(cmd, _opts);
|
||||
if (out !== undefined && out !== null) {
|
||||
child.stdout.emit("data", Buffer.from(out.toString()));
|
||||
}
|
||||
child.emit("close", 0, null);
|
||||
} catch (err: any) {
|
||||
const stderrText = err?.stderr?.toString?.() ?? err?.message ?? "";
|
||||
if (stderrText) child.stderr.emit("data", Buffer.from(stderrText));
|
||||
child.emit("close", typeof err?.status === "number" ? err.status : 1, null);
|
||||
}
|
||||
});
|
||||
return child;
|
||||
});
|
||||
return { execSync: execSyncFn, exec: execFn, spawn: spawnFn };
|
||||
});
|
||||
vi.mock("node:fs", () => ({
|
||||
existsSync: vi.fn().mockReturnValue(true),
|
||||
|
||||
Reference in New Issue
Block a user