test(codex): isolate hook lifecycle user data

This commit is contained in:
Brennan Benson
2026-07-17 14:30:22 -07:00
parent df38f66ddf
commit 3a40e8b88a
@@ -1,6 +1,6 @@
// Why: stdin ownership is a cross-agent process contract; one executable
// matrix catches an unread early exit without duplicating template assertions.
import { describe, expect, it, vi } from 'vitest'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { spawn } from 'node:child_process'
import { mkdtempSync, readFileSync, readdirSync, rmSync } from 'node:fs'
import { tmpdir } from 'node:os'
@@ -47,6 +47,25 @@ import { createAgentHookMemorySftp } from './agent-hook-memory-sftp.test-fixture
const REMOTE_HOME = '/home/dev'
const LARGE_PAYLOAD = Buffer.alloc(1_000_000, 'x')
let isolatedUserDataDir = ''
let previousUserDataPath: string | undefined
beforeEach(() => {
previousUserDataPath = process.env.ORCA_USER_DATA_PATH
isolatedUserDataDir = mkdtempSync(join(tmpdir(), 'orca-hook-stdin-user-data-'))
// Why: Orca-managed Codex hooks resolve through ORCA_USER_DATA_PATH before
// the mocked home; an inherited live path would let this test rewrite them.
process.env.ORCA_USER_DATA_PATH = isolatedUserDataDir
})
afterEach(() => {
if (previousUserDataPath === undefined) {
delete process.env.ORCA_USER_DATA_PATH
} else {
process.env.ORCA_USER_DATA_PATH = previousUserDataPath
}
rmSync(isolatedUserDataDir, { recursive: true, force: true })
})
const REMOTE_INSTALLERS = [
{
agent: 'antigravity',
@@ -200,6 +219,9 @@ describe('Windows managed hook stdin structure', () => {
expect(entry.install().state, `${entry.agent} install status`).toBe('installed')
}
})
expect(
readFileSync(join(isolatedUserDataDir, 'codex-runtime-home', 'home', 'hooks.json'), 'utf8')
).toContain('WindowsPowerShell')
const hooksDir = join(home, '.orca', 'agent-hooks')
const fileNames = readdirSync(hooksDir)
const mainBatchScripts = fileNames.filter(