mirror of
https://github.com/tiennm99/ccs.git
synced 2026-07-30 18:21:21 +00:00
fix(test): pin real child_process passthrough refs
- bind real spawn/spawnSync/execSync before module mocking - avoid potential rebinding recursion or mock passthrough drift in CI - keeps non-Claude process execution untouched during test mocks
This commit is contained in:
@@ -13,6 +13,9 @@ const originalPlatform = process.platform;
|
|||||||
let baselineSigintListeners: Array<(...args: unknown[]) => void> = [];
|
let baselineSigintListeners: Array<(...args: unknown[]) => void> = [];
|
||||||
let baselineSigtermListeners: Array<(...args: unknown[]) => void> = [];
|
let baselineSigtermListeners: Array<(...args: unknown[]) => void> = [];
|
||||||
let baselineSighupListeners: Array<(...args: unknown[]) => void> = [];
|
let baselineSighupListeners: Array<(...args: unknown[]) => void> = [];
|
||||||
|
const realSpawn = childProcess.spawn.bind(childProcess);
|
||||||
|
const realSpawnSync = childProcess.spawnSync.bind(childProcess);
|
||||||
|
const realExecSync = childProcess.execSync.bind(childProcess);
|
||||||
|
|
||||||
function createMockChild(): EventEmitter & {
|
function createMockChild(): EventEmitter & {
|
||||||
stdout: EventEmitter;
|
stdout: EventEmitter;
|
||||||
@@ -65,11 +68,7 @@ function registerChildProcessMock(): void {
|
|||||||
| undefined;
|
| undefined;
|
||||||
|
|
||||||
if (!shouldMockCommand(command)) {
|
if (!shouldMockCommand(command)) {
|
||||||
return childProcess.spawn(
|
return realSpawn(command, args, options as Parameters<typeof childProcess.spawn>[2]);
|
||||||
command,
|
|
||||||
args,
|
|
||||||
options as Parameters<typeof childProcess.spawn>[2]
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
spawnCalls.push({ command, args, options });
|
spawnCalls.push({ command, args, options });
|
||||||
@@ -86,14 +85,10 @@ function registerChildProcessMock(): void {
|
|||||||
| Record<string, unknown>
|
| Record<string, unknown>
|
||||||
| undefined;
|
| undefined;
|
||||||
|
|
||||||
return childProcess.spawnSync(
|
return realSpawnSync(command, args, options as Parameters<typeof childProcess.spawnSync>[2]);
|
||||||
command,
|
|
||||||
args,
|
|
||||||
options as Parameters<typeof childProcess.spawnSync>[2]
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
execSync: (...execArgs: unknown[]) =>
|
execSync: (...execArgs: unknown[]) =>
|
||||||
childProcess.execSync(
|
realExecSync(
|
||||||
execArgs[0] as Parameters<typeof childProcess.execSync>[0],
|
execArgs[0] as Parameters<typeof childProcess.execSync>[0],
|
||||||
execArgs[1] as Parameters<typeof childProcess.execSync>[1]
|
execArgs[1] as Parameters<typeof childProcess.execSync>[1]
|
||||||
),
|
),
|
||||||
|
|||||||
Reference in New Issue
Block a user