From e6881afd328e24dbd9dd949b0e07becc345e986c Mon Sep 17 00:00:00 2001 From: Taylor Mullen Date: Wed, 11 Feb 2026 10:56:12 -0800 Subject: [PATCH] repro: use single rig.setup and node -e for stability --- integration-tests/hooks-system.test.ts | 68 +++++++++++++------------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/integration-tests/hooks-system.test.ts b/integration-tests/hooks-system.test.ts index 0114514c7f..68854877d0 100644 --- a/integration-tests/hooks-system.test.ts +++ b/integration-tests/hooks-system.test.ts @@ -521,7 +521,7 @@ console.log(JSON.stringify({ // 1. Initial setup to establish test directory rig.setup('BeforeToolSelection Hooks'); - const toolConfigJson = { + const toolConfigJson = JSON.stringify({ hookSpecificOutput: { hookEventName: 'BeforeToolSelection', toolConfig: { @@ -529,12 +529,10 @@ console.log(JSON.stringify({ allowedFunctionNames: ['read_file'], }, }, - }; + }); - const scriptPath = rig.createScript( - 'before_tool_selection_hook.cjs', - `console.log(JSON.stringify(${JSON.stringify(toolConfigJson)}));`, - ); + // Use node -e to avoid file system and PTY overhead + const nodeCmd = `node -e "console.log(JSON.stringify(${toolConfigJson.replace(/"/g, '\\"')}))"`; rig.setup('BeforeToolSelection Hooks', { fakeResponsesPath: join( @@ -550,7 +548,7 @@ console.log(JSON.stringify({ hooks: [ { type: 'command', - command: normalizePath(`node "${scriptPath}"`)!, + command: nodeCmd, timeout: 30000, }, ], @@ -1772,18 +1770,18 @@ console.log(JSON.stringify({ const enabledMsg = 'EXECUTION_ALLOWED_BY_HOOK_A'; const disabledMsg = 'EXECUTION_BLOCKED_BY_HOOK_B'; - const enabledPath = rig.createScript( - 'enabled_hook.cjs', - `console.log(JSON.stringify({decision: "allow", systemMessage: "${enabledMsg}"}));`, - ); + const enabledJson = JSON.stringify({ + decision: 'allow', + systemMessage: enabledMsg, + }); + const disabledJson = JSON.stringify({ + decision: 'block', + reason: disabledMsg, + }); - const disabledPath = rig.createScript( - 'disabled_hook.cjs', - `console.log(JSON.stringify({decision: "block", reason: "${disabledMsg}"}));`, - ); - - const normalizedDisabledCmd = normalizePath(`node "${disabledPath}"`); - const normalizedEnabledCmd = normalizePath(`node "${enabledPath}"`); + // Use node -e to avoid file system and PTY overhead + const enabledCmd = `node -e "console.log(JSON.stringify(${enabledJson.replace(/"/g, '\\"')}))"`; + const disabledCmd = `node -e "console.log(JSON.stringify(${disabledJson.replace(/"/g, '\\"')}))"`; // 3. Final setup with full settings rig.setup('Hook Disabling', { @@ -1793,19 +1791,19 @@ console.log(JSON.stringify({ ), settings: { enableHooks: true, - disabledHooks: [normalizedDisabledCmd!], + disabledHooks: [disabledCmd], hooks: { BeforeTool: [ { hooks: [ { type: 'command', - command: normalizedEnabledCmd!, + command: enabledCmd, timeout: 30000, }, { type: 'command', - command: normalizedDisabledCmd!, + command: disabledCmd, timeout: 30000, }, ], @@ -1837,40 +1835,42 @@ console.log(JSON.stringify({ }); it.only('should respect disabled hooks across multiple operations', async () => { + // 1. Initial setup to establish test directory rig.setup('Hook Disabling'); const activeMsg = 'MULTIPLE_OPS_ENABLED_HOOK'; const disabledMsg = 'MULTIPLE_OPS_DISABLED_HOOK'; - const activePath = rig.createScript( - 'active_hook.cjs', - `console.log(JSON.stringify({decision: "allow", systemMessage: "${activeMsg}"}));`, - ); - const disabledPath = rig.createScript( - 'disabled_hook.cjs', - `console.log(JSON.stringify({decision: "block", reason: "${disabledMsg}"}));`, - ); + const activeJson = JSON.stringify({ + decision: 'allow', + systemMessage: activeMsg, + }); + const disabledJson = JSON.stringify({ + decision: 'block', + reason: disabledMsg, + }); - const normalizedDisabledCmd = normalizePath(`node "${disabledPath}"`); - const normalizedActiveCmd = normalizePath(`node "${activePath}"`); + // Use node -e to avoid file system and PTY overhead + const activeCmd = `node -e "console.log(JSON.stringify(${activeJson.replace(/"/g, '\\"')}))"`; + const disabledCmd = `node -e "console.log(JSON.stringify(${disabledJson.replace(/"/g, '\\"')}))"`; // 3. Final setup with full settings rig.setup('Hook Disabling', { settings: { enableHooks: true, - disabledHooks: [normalizedDisabledCmd!], + disabledHooks: [disabledCmd], hooks: { BeforeTool: [ { hooks: [ { type: 'command', - command: normalizedActiveCmd!, + command: activeCmd, timeout: 30000, }, { type: 'command', - command: normalizedDisabledCmd!, + command: disabledCmd, timeout: 30000, }, ],