Harden Windows hook command resolution (#6409)

* Keep spaced Windows Codex hook paths fast

* Harden Windows hook command resolution

---------

Co-authored-by: Neil <neil@stably.ai>
This commit is contained in:
Brennan Benson
2026-06-25 22:43:25 -07:00
committed by GitHub
co-authored by Neil
parent dd0fa77882
commit b6ac7b9c92
12 changed files with 103 additions and 60 deletions
+5 -6
View File
@@ -20,6 +20,9 @@ vi.mock('os', async () => {
import { CommandCodeHookService } from './hook-service'
const WINDOWS_POWERSHELL_LAUNCHER =
/^[A-Za-z]:\/[^"]*\/System32\/WindowsPowerShell\/v1\.0\/powershell\.exe -NoProfile -ExecutionPolicy Bypass -EncodedCommand \S+$/
describe('CommandCodeHookService', () => {
let homeDir: string
@@ -49,9 +52,7 @@ describe('CommandCodeHookService', () => {
expect(config.hooks.PostToolUse[0].matcher).toBe('.*')
expect(config.hooks.Stop[0].matcher).toBeUndefined()
expect(config.hooks.PreToolUse[0].hooks[0].command).toMatch(
process.platform === 'win32'
? /^powershell -NoProfile -ExecutionPolicy Bypass -EncodedCommand \S+$/
: /command-code-hook/
process.platform === 'win32' ? WINDOWS_POWERSHELL_LAUNCHER : /command-code-hook/
)
if (process.platform !== 'win32') {
expect(config.hooks.PreToolUse[0].hooks[0].command).toContain(join(homeDir, '.orca'))
@@ -79,9 +80,7 @@ describe('CommandCodeHookService', () => {
) as { hooks: Record<string, { hooks: { command: string }[] }[]> }
const command = config.hooks.PreToolUse[0].hooks[0].command
expect(command).toMatch(
/^powershell -NoProfile -ExecutionPolicy Bypass -EncodedCommand \S+$/
)
expect(command).toMatch(WINDOWS_POWERSHELL_LAUNCHER)
} finally {
rmSync(spaceHome, { recursive: true, force: true })
}