repro: use echo instead of node for failing tests and focus them

This commit is contained in:
Taylor Mullen
2026-02-11 00:04:01 -08:00
parent 780a8315ca
commit dcb35b2d07
+69 -51
View File
@@ -517,25 +517,26 @@ console.log(JSON.stringify({
}); });
describe('BeforeToolSelection Hooks - Tool Configuration', () => { 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 // 1. Initial setup to establish test directory
rig.setup('should modify tool selection with BeforeToolSelection hooks'); rig.setup('should modify tool selection with BeforeToolSelection hooks');
// 2. Create the script in the established directory const toolConfigJson = JSON.stringify({
const scriptPath = rig.createScript( hookSpecificOutput: {
'before_tool_selection_hook.cjs', hookEventName: 'BeforeToolSelection',
`console.log(JSON.stringify({ toolConfig: {
hookSpecificOutput: { mode: 'ANY',
hookEventName: 'BeforeToolSelection', allowedFunctionNames: ['read_file', 'run_shell_command'],
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', { rig.setup('should modify tool selection with BeforeToolSelection hooks', {
fakeResponsesPath: join( fakeResponsesPath: join(
import.meta.dirname, import.meta.dirname,
@@ -550,7 +551,7 @@ console.log(JSON.stringify({
hooks: [ hooks: [
{ {
type: 'command', type: 'command',
command: normalizePath(`node "${scriptPath}"`)!, command: echoCmd,
timeout: 5000, timeout: 5000,
}, },
], ],
@@ -1764,23 +1765,31 @@ console.log(JSON.stringify({
}); });
describe('Hook Disabling', () => { 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 // 1. Initial setup to establish test directory
rig.setup('should not execute hooks disabled in settings file'); rig.setup('should not execute hooks disabled in settings file');
// 2. Create scripts in the established directory const enabledMsg = 'EXECUTION_ALLOWED_BY_HOOK_A';
const enabledPath = rig.createScript( const disabledMsg = 'EXECUTION_BLOCKED_BY_HOOK_B';
'enabled_hook.cjs',
'console.log(JSON.stringify({decision: "allow", systemMessage: "EXECUTION_ALLOWED_BY_HOOK_A"}));',
);
const disabledPath = rig.createScript( const enabledJson = JSON.stringify({
'disabled_hook.cjs', decision: 'allow',
'console.log(JSON.stringify({decision: "block", reason: "EXECUTION_BLOCKED_BY_HOOK_B"}));', systemMessage: enabledMsg,
); });
const disabledJson = JSON.stringify({
decision: 'block',
reason: disabledMsg,
});
const normalizedDisabledCmd = normalizePath(`node "${disabledPath}"`); const enabledCmd =
const normalizedEnabledCmd = normalizePath(`node "${enabledPath}"`); 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 // 3. Final setup with full settings
rig.setup('should not execute hooks disabled in settings file', { rig.setup('should not execute hooks disabled in settings file', {
@@ -1790,19 +1799,19 @@ console.log(JSON.stringify({
), ),
settings: { settings: {
enableHooks: true, enableHooks: true,
disabledHooks: [normalizedDisabledCmd!], disabledHooks: [disabledCmd],
hooks: { hooks: {
BeforeTool: [ BeforeTool: [
{ {
hooks: [ hooks: [
{ {
type: 'command', type: 'command',
command: normalizedEnabledCmd!, command: enabledCmd,
timeout: 5000, timeout: 5000,
}, },
{ {
type: 'command', type: 'command',
command: normalizedDisabledCmd!, command: disabledCmd,
timeout: 5000, timeout: 5000,
}, },
], ],
@@ -1823,50 +1832,59 @@ console.log(JSON.stringify({
// Check hook telemetry - only enabled hook should have executed // Check hook telemetry - only enabled hook should have executed
const hookLogs = rig.readHookLogs(); const hookLogs = rig.readHookLogs();
const enabledHookLog = hookLogs.find( const enabledHookLog = hookLogs.find(
(log) => log.hookCall.hook_name === normalizedEnabledCmd, (log) => log.hookCall.hook_name === enabledCmd,
); );
const disabledHookLog = hookLogs.find( const disabledHookLog = hookLogs.find(
(log) => log.hookCall.hook_name === normalizedDisabledCmd, (log) => log.hookCall.hook_name === disabledCmd,
); );
expect(enabledHookLog).toBeDefined(); expect(enabledHookLog).toBeDefined();
expect(disabledHookLog).toBeUndefined(); 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 // 1. Initial setup to establish test directory
rig.setup('should respect disabled hooks across multiple operations'); rig.setup('should respect disabled hooks across multiple operations');
// 2. Create scripts in the established directory const activeMsg = 'MULTIPLE_OPS_ENABLED_HOOK';
const activePath = rig.createScript( const disabledMsg = 'MULTIPLE_OPS_DISABLED_HOOK';
'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 normalizedDisabledCmd = normalizePath(`node "${disabledPath}"`); const activeJson = JSON.stringify({
const normalizedActiveCmd = normalizePath(`node "${activePath}"`); 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 // 3. Final setup with full settings
rig.setup('should respect disabled hooks across multiple operations', { rig.setup('should respect disabled hooks across multiple operations', {
settings: { settings: {
enableHooks: true, enableHooks: true,
disabledHooks: [normalizedDisabledCmd!], disabledHooks: [disabledCmd],
hooks: { hooks: {
BeforeTool: [ BeforeTool: [
{ {
hooks: [ hooks: [
{ {
type: 'command', type: 'command',
command: normalizedActiveCmd!, command: activeCmd,
timeout: 5000, timeout: 5000,
}, },
{ {
type: 'command', type: 'command',
command: normalizedDisabledCmd!, command: disabledCmd,
timeout: 5000, timeout: 5000,
}, },
], ],
@@ -1888,10 +1906,10 @@ console.log(JSON.stringify({
// Check hook telemetry - only active hook should have executed // Check hook telemetry - only active hook should have executed
const hookLogs1 = rig.readHookLogs(); const hookLogs1 = rig.readHookLogs();
const activeHookLog1 = hookLogs1.find( const activeHookLog1 = hookLogs1.find(
(log) => log.hookCall.hook_name === normalizedActiveCmd, (log) => log.hookCall.hook_name === activeCmd,
); );
const disabledHookLog1 = hookLogs1.find( const disabledHookLog1 = hookLogs1.find(
(log) => log.hookCall.hook_name === normalizedDisabledCmd, (log) => log.hookCall.hook_name === disabledCmd,
); );
expect(activeHookLog1).toBeDefined(); expect(activeHookLog1).toBeDefined();
@@ -1908,7 +1926,7 @@ console.log(JSON.stringify({
// Verify disabled hook still hasn't executed // Verify disabled hook still hasn't executed
const hookLogs2 = rig.readHookLogs(); const hookLogs2 = rig.readHookLogs();
const disabledHookLog2 = hookLogs2.find( const disabledHookLog2 = hookLogs2.find(
(log) => log.hookCall.hook_name === normalizedDisabledCmd, (log) => log.hookCall.hook_name === disabledCmd,
); );
expect(disabledHookLog2).toBeUndefined(); expect(disabledHookLog2).toBeUndefined();
}); });