78 lines
2.1 KiB
TypeScript
78 lines
2.1 KiB
TypeScript
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
|
import { mkdtempSync, readFileSync, rmSync } from 'fs'
|
|
import { tmpdir } from 'os'
|
|
import type * as Os from 'os'
|
|
import { join } from 'path'
|
|
|
|
const { getPathMock, homedirMock } = vi.hoisted(() => ({
|
|
getPathMock: vi.fn<(name: string) => string>(),
|
|
homedirMock: vi.fn<() => string>()
|
|
}))
|
|
|
|
vi.mock('electron', () => ({
|
|
app: {
|
|
getPath: getPathMock
|
|
}
|
|
}))
|
|
|
|
vi.mock('os', async (importOriginal) => {
|
|
const actual = await importOriginal<typeof Os>()
|
|
return {
|
|
...actual,
|
|
homedir: homedirMock
|
|
}
|
|
})
|
|
|
|
import { CodexHookService } from './hook-service'
|
|
|
|
let tmpHome: string
|
|
let userDataDir: string
|
|
|
|
beforeEach(() => {
|
|
tmpHome = mkdtempSync(join(tmpdir(), 'orca-codex-home-'))
|
|
userDataDir = mkdtempSync(join(tmpdir(), 'orca-codex-user-data-'))
|
|
homedirMock.mockReturnValue(tmpHome)
|
|
getPathMock.mockImplementation((name: string) => {
|
|
if (name === 'userData') {
|
|
return userDataDir
|
|
}
|
|
throw new Error(`unexpected app.getPath(${name})`)
|
|
})
|
|
})
|
|
|
|
afterEach(() => {
|
|
rmSync(tmpHome, { recursive: true, force: true })
|
|
rmSync(userDataDir, { recursive: true, force: true })
|
|
vi.clearAllMocks()
|
|
})
|
|
|
|
describe('CodexHookService', () => {
|
|
it('installs PermissionRequest with trust so Codex approval prompts reach Orca', () => {
|
|
const status = new CodexHookService().install()
|
|
|
|
expect(status.state).toBe('installed')
|
|
|
|
const hooksConfig = JSON.parse(
|
|
readFileSync(join(tmpHome, '.codex', 'hooks.json'), 'utf-8')
|
|
) as {
|
|
hooks: Record<string, { hooks?: { command?: string }[] }[]>
|
|
}
|
|
|
|
expect(Object.keys(hooksConfig.hooks).sort()).toEqual(
|
|
[
|
|
'PermissionRequest',
|
|
'PostToolUse',
|
|
'PreToolUse',
|
|
'SessionStart',
|
|
'Stop',
|
|
'UserPromptSubmit'
|
|
].sort()
|
|
)
|
|
expect(hooksConfig.hooks.PermissionRequest?.[0]?.hooks?.[0]?.command).toContain('agent-hooks')
|
|
expect(hooksConfig.hooks.PermissionRequest?.[0]?.hooks?.[0]?.command).toContain('codex-hook')
|
|
|
|
const trustConfig = readFileSync(join(tmpHome, '.codex', 'config.toml'), 'utf-8')
|
|
expect(trustConfig).toContain(':permission_request:0:0')
|
|
})
|
|
})
|