From dcb35b2d0721cedea1ef896bb82d3b456d208fc6 Mon Sep 17 00:00:00 2001 From: Taylor Mullen Date: Wed, 11 Feb 2026 00:04:01 -0800 Subject: [PATCH] repro: use echo instead of node for failing tests and focus them --- integration-tests/hooks-system.test.ts | 120 ++++++++++++++----------- 1 file changed, 69 insertions(+), 51 deletions(-) diff --git a/integration-tests/hooks-system.test.ts b/integration-tests/hooks-system.test.ts index d157be6801..cc8eb9ca76 100644 --- a/integration-tests/hooks-system.test.ts +++ b/integration-tests/hooks-system.test.ts @@ -517,25 +517,26 @@ console.log(JSON.stringify({ }); describe('BeforeToolSelection Hooks - Tool Configuration', () => { - it('should modify tool selection with BeforeToolSelection hooks', async () => { + it.only('should modify tool selection with BeforeToolSelection hooks', async () => { // 1. Initial setup to establish test directory rig.setup('should modify tool selection with BeforeToolSelection hooks'); - // 2. Create the script in the established directory - const scriptPath = rig.createScript( - 'before_tool_selection_hook.cjs', - `console.log(JSON.stringify({ - hookSpecificOutput: { - hookEventName: 'BeforeToolSelection', - toolConfig: { - mode: 'ANY', - allowedFunctionNames: ['read_file', 'run_shell_command'] - } - } -}));`, - ); + const toolConfigJson = JSON.stringify({ + hookSpecificOutput: { + hookEventName: 'BeforeToolSelection', + toolConfig: { + mode: 'ANY', + allowedFunctionNames: ['read_file', 'run_shell_command'], + }, + }, + }); + + // Use simple echo to avoid node-pty instability in CI + const echoCmd = + process.platform === 'win32' + ? `powershell -NoProfile -Command "echo '${toolConfigJson.replace(/"/g, '\"')}'"` + : `echo '${toolConfigJson}'`; - // 3. Final setup with full settings rig.setup('should modify tool selection with BeforeToolSelection hooks', { fakeResponsesPath: join( import.meta.dirname, @@ -550,7 +551,7 @@ console.log(JSON.stringify({ hooks: [ { type: 'command', - command: normalizePath(`node "${scriptPath}"`)!, + command: echoCmd, timeout: 5000, }, ], @@ -1764,23 +1765,31 @@ console.log(JSON.stringify({ }); describe('Hook Disabling', () => { - it('should not execute hooks disabled in settings file', async () => { + it.only('should not execute hooks disabled in settings file', async () => { // 1. Initial setup to establish test directory rig.setup('should not execute hooks disabled in settings file'); - // 2. Create scripts in the established directory - const enabledPath = rig.createScript( - 'enabled_hook.cjs', - 'console.log(JSON.stringify({decision: "allow", systemMessage: "EXECUTION_ALLOWED_BY_HOOK_A"}));', - ); + const enabledMsg = 'EXECUTION_ALLOWED_BY_HOOK_A'; + const disabledMsg = 'EXECUTION_BLOCKED_BY_HOOK_B'; - const disabledPath = rig.createScript( - 'disabled_hook.cjs', - 'console.log(JSON.stringify({decision: "block", reason: "EXECUTION_BLOCKED_BY_HOOK_B"}));', - ); + const enabledJson = JSON.stringify({ + decision: 'allow', + systemMessage: enabledMsg, + }); + const disabledJson = JSON.stringify({ + decision: 'block', + reason: disabledMsg, + }); - const normalizedDisabledCmd = normalizePath(`node "${disabledPath}"`); - const normalizedEnabledCmd = normalizePath(`node "${enabledPath}"`); + const enabledCmd = + process.platform === 'win32' + ? `powershell -NoProfile -Command "echo '${enabledJson.replace(/"/g, '\"')}'"` + : `echo '${enabledJson}'`; + + const disabledCmd = + process.platform === 'win32' + ? `powershell -NoProfile -Command "echo '${disabledJson.replace(/"/g, '\"')}'"` + : `echo '${disabledJson}'`; // 3. Final setup with full settings rig.setup('should not execute hooks disabled in settings file', { @@ -1790,19 +1799,19 @@ console.log(JSON.stringify({ ), settings: { enableHooks: true, - disabledHooks: [normalizedDisabledCmd!], + disabledHooks: [disabledCmd], hooks: { BeforeTool: [ { hooks: [ { type: 'command', - command: normalizedEnabledCmd!, + command: enabledCmd, timeout: 5000, }, { type: 'command', - command: normalizedDisabledCmd!, + command: disabledCmd, timeout: 5000, }, ], @@ -1823,50 +1832,59 @@ console.log(JSON.stringify({ // Check hook telemetry - only enabled hook should have executed const hookLogs = rig.readHookLogs(); const enabledHookLog = hookLogs.find( - (log) => log.hookCall.hook_name === normalizedEnabledCmd, + (log) => log.hookCall.hook_name === enabledCmd, ); const disabledHookLog = hookLogs.find( - (log) => log.hookCall.hook_name === normalizedDisabledCmd, + (log) => log.hookCall.hook_name === disabledCmd, ); expect(enabledHookLog).toBeDefined(); expect(disabledHookLog).toBeUndefined(); }); - it('should respect disabled hooks across multiple operations', async () => { + it.only('should respect disabled hooks across multiple operations', async () => { // 1. Initial setup to establish test directory rig.setup('should respect disabled hooks across multiple operations'); - // 2. Create scripts in the established directory - const activePath = rig.createScript( - 'active_hook.cjs', - 'console.log(JSON.stringify({decision: "allow", systemMessage: "MULTIPLE_OPS_ENABLED_HOOK"}));', - ); - const disabledPath = rig.createScript( - 'disabled_hook.cjs', - 'console.log(JSON.stringify({decision: "block", reason: "MULTIPLE_OPS_DISABLED_HOOK"}));', - ); + const activeMsg = 'MULTIPLE_OPS_ENABLED_HOOK'; + const disabledMsg = 'MULTIPLE_OPS_DISABLED_HOOK'; - const normalizedDisabledCmd = normalizePath(`node "${disabledPath}"`); - const normalizedActiveCmd = normalizePath(`node "${activePath}"`); + const activeJson = JSON.stringify({ + decision: 'allow', + systemMessage: activeMsg, + }); + const disabledJson = JSON.stringify({ + decision: 'block', + reason: disabledMsg, + }); + + const activeCmd = + process.platform === 'win32' + ? `powershell -NoProfile -Command "echo '${activeJson.replace(/"/g, '\"')}'"` + : `echo '${activeJson}'`; + + const disabledCmd = + process.platform === 'win32' + ? `powershell -NoProfile -Command "echo '${disabledJson.replace(/"/g, '\"')}'"` + : `echo '${disabledJson}'`; // 3. Final setup with full settings rig.setup('should respect disabled hooks across multiple operations', { settings: { enableHooks: true, - disabledHooks: [normalizedDisabledCmd!], + disabledHooks: [disabledCmd], hooks: { BeforeTool: [ { hooks: [ { type: 'command', - command: normalizedActiveCmd!, + command: activeCmd, timeout: 5000, }, { type: 'command', - command: normalizedDisabledCmd!, + command: disabledCmd, timeout: 5000, }, ], @@ -1888,10 +1906,10 @@ console.log(JSON.stringify({ // Check hook telemetry - only active hook should have executed const hookLogs1 = rig.readHookLogs(); const activeHookLog1 = hookLogs1.find( - (log) => log.hookCall.hook_name === normalizedActiveCmd, + (log) => log.hookCall.hook_name === activeCmd, ); const disabledHookLog1 = hookLogs1.find( - (log) => log.hookCall.hook_name === normalizedDisabledCmd, + (log) => log.hookCall.hook_name === disabledCmd, ); expect(activeHookLog1).toBeDefined(); @@ -1908,7 +1926,7 @@ console.log(JSON.stringify({ // Verify disabled hook still hasn't executed const hookLogs2 = rig.readHookLogs(); const disabledHookLog2 = hookLogs2.find( - (log) => log.hookCall.hook_name === normalizedDisabledCmd, + (log) => log.hookCall.hook_name === disabledCmd, ); expect(disabledHookLog2).toBeUndefined(); });