fix(test): scope child_process mock to test lifecycle

- register child_process module mock in beforeAll instead of module load

- keep passthrough for non-Claude commands and restore after suite

- avoids cross-suite side effects that stalled cursor daemon CI tests
This commit is contained in:
Tam Nhu Tran committed 2026-02-20 23:36:22 +07:00
1 parent 5b164a6486
commit 873b7adb70
1 file changed
+4
@@ -53,6 +53,7 @@ function shouldMockCommand(command: string): boolean {
return normalized.includes('claude'); return normalized.includes('claude');
} }
function registerChildProcessMock(): void {
mock.module('child_process', () => ({ mock.module('child_process', () => ({
...childProcess, ...childProcess,
spawn: (...spawnArgs: unknown[]) => { spawn: (...spawnArgs: unknown[]) => {
@@ -97,12 +98,15 @@ mock.module('child_process', () => ({
execArgs[1] as Parameters<typeof childProcess.execSync>[1] execArgs[1] as Parameters<typeof childProcess.execSync>[1]
), ),
})); }));
}
let execClaude: typeof import('../../../src/utils/shell-executor').execClaude; let execClaude: typeof import('../../../src/utils/shell-executor').execClaude;
let stripClaudeCodeEnv: typeof import('../../../src/utils/shell-executor').stripClaudeCodeEnv; let stripClaudeCodeEnv: typeof import('../../../src/utils/shell-executor').stripClaudeCodeEnv;
let HeadlessExecutor: typeof import('../../../src/delegation/headless-executor').HeadlessExecutor; let HeadlessExecutor: typeof import('../../../src/delegation/headless-executor').HeadlessExecutor;
beforeAll(async () => { beforeAll(async () => {
registerChildProcessMock();
const shellExecutor = await import('../../../src/utils/shell-executor'); const shellExecutor = await import('../../../src/utils/shell-executor');
execClaude = shellExecutor.execClaude; execClaude = shellExecutor.execClaude;
stripClaudeCodeEnv = shellExecutor.stripClaudeCodeEnv; stripClaudeCodeEnv = shellExecutor.stripClaudeCodeEnv;