test(hooks): fix test 5 Windows-compat — PATH=nodeDir not PATH=''
Previous test 5 stripped PATH entirely, which kills node.exe spawn resolution on Windows (CreateProcess needs PATH to find node). Changed to set PATH to node's own directory only — node spawns fine, git is not in node-dir → ENOENT → hook fail-opens per spec §4.5. All 5 tests now pass cross-platform. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -82,11 +82,15 @@ test('hook fail-open on malformed stdin', () => {
|
||||
});
|
||||
|
||||
test('hook fail-open when git not available', () => {
|
||||
// Cross-platform: set PATH to node's own directory only — node spawns OK,
|
||||
// git not in node's bin dir → ENOENT → hook fail-opens per spec §4.5.
|
||||
// (Previous approach `PATH: ''` kills node.exe spawn resolution on Windows.)
|
||||
const nodeDir = dirname(process.execPath);
|
||||
const result = spawnSync('node', [HOOK_PATH], {
|
||||
input: JSON.stringify({ tool_name: 'Task', tool_input: { prompt: 'x' } }),
|
||||
encoding: 'utf8',
|
||||
timeout: 5000,
|
||||
env: { ...process.env, PATH: '' }, // strip PATH → git not found
|
||||
env: { PATH: nodeDir, PATHEXT: process.env.PATHEXT || '.EXE' },
|
||||
});
|
||||
assert.equal(result.status, 0, `should not crash when git missing; stderr: ${result.stderr}`);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user