From 04e4e61b686b50dd685917646af97b7d47e81ba1 Mon Sep 17 00:00:00 2001 From: Tam Nhu Tran Date: Fri, 20 Feb 2026 23:41:20 +0700 Subject: [PATCH] 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 --- .../unit/utils/claudecode-env-stripping.test.ts | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/tests/unit/utils/claudecode-env-stripping.test.ts b/tests/unit/utils/claudecode-env-stripping.test.ts index d27b273d..3950ae52 100644 --- a/tests/unit/utils/claudecode-env-stripping.test.ts +++ b/tests/unit/utils/claudecode-env-stripping.test.ts @@ -13,6 +13,9 @@ const originalPlatform = process.platform; let baselineSigintListeners: Array<(...args: unknown[]) => void> = []; let baselineSigtermListeners: 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 & { stdout: EventEmitter; @@ -65,11 +68,7 @@ function registerChildProcessMock(): void { | undefined; if (!shouldMockCommand(command)) { - return childProcess.spawn( - command, - args, - options as Parameters[2] - ); + return realSpawn(command, args, options as Parameters[2]); } spawnCalls.push({ command, args, options }); @@ -86,14 +85,10 @@ function registerChildProcessMock(): void { | Record | undefined; - return childProcess.spawnSync( - command, - args, - options as Parameters[2] - ); + return realSpawnSync(command, args, options as Parameters[2]); }, execSync: (...execArgs: unknown[]) => - childProcess.execSync( + realExecSync( execArgs[0] as Parameters[0], execArgs[1] as Parameters[1] ),