Files
archived-orca/src/shared/codebuddy-agent.test.ts
T
EdgerHaoandNeil 554a16f328 fix(agent-hooks): keep CodeBuddy PermissionRequest from reporting waiting (#38009)
CodeBuddy fires PermissionRequest even when its auto-review approves the
tool, so the pane flashed "waiting" for calls that never needed the user.
Real prompts still arrive as Notification(permission_prompt), so drop
PermissionRequest for CodeBuddy only; Qoder keeps the existing mapping.

Co-authored-by: Neil <neil@stably.ai>
2026-11-05 17:35:57 -08:00

61 lines
2.6 KiB
TypeScript

import { readFileSync } from 'node:fs'
import { join } from 'node:path'
import { describe, expect, it } from 'vitest'
import { createHookListenerState } from './agent-hook-listener/listener-state'
import { normalizeAndAccept } from './agent-hook-listener/normalization/agent-hook-listener-test-harness'
import { recognizeAgentProcessFromCommandLine } from './agent-status/process/agent-process-recognition'
import { getAgentResumeArgv } from './agent-launch/startup/agent-resume-argv'
describe('CodeBuddy harness', () => {
it('replays the live question lifecycle without settling at late SessionStart', () => {
const state = createHookListenerState()
const events = readFileSync(
join(__dirname, '__fixtures__/codebuddy-question-hooks.jsonl'),
'utf8'
)
.trim()
.split('\n')
.map((line) => JSON.parse(line))
const rows = events.map((event) => normalizeAndAccept(state, 'codebuddy', event))
expect(rows.map((row) => row?.payload.state ?? null)).toEqual([
'working',
null,
'waiting',
'working',
'working',
'done'
])
expect(rows[2]?.payload).toMatchObject({ agentType: 'codebuddy', toolName: 'AskUserQuestion' })
expect(rows[5]?.payload).toMatchObject({ agentType: 'codebuddy', lastAssistantMessage: 'Red' })
expect(rows[5]?.providerSession?.id).toBe('codebuddy-verification')
})
it('waits on the permission prompt notification, not the auto-reviewed PermissionRequest', () => {
const state = createHookListenerState()
const send = (event: Record<string, unknown>) => normalizeAndAccept(state, 'codebuddy', event)
const bash = { tool_name: 'Bash', tool_input: { command: 'curl -sfL https://example.test' } }
send({ hook_event_name: 'UserPromptSubmit', prompt: 'download it' })
send({ hook_event_name: 'PreToolUse', ...bash })
expect(send({ hook_event_name: 'PermissionRequest', ...bash })).toBeNull()
expect(
send({
hook_event_name: 'Notification',
notification_type: 'permission_prompt',
message: 'needs your permission to use Bash'
})?.payload
).toMatchObject({ state: 'waiting', toolName: 'Bash' })
})
it('excludes print runs and resumes the original provider session', () => {
for (const flag of ['--print', '--serve', '--acp', '--bg', '--background']) {
expect(recognizeAgentProcessFromCommandLine(`codebuddy ${flag}`)).toBeNull()
}
expect(recognizeAgentProcessFromCommandLine('codebuddy -- --serve')?.agent).toBe('codebuddy')
expect(getAgentResumeArgv('codebuddy', { key: 'session_id', id: 'session-1' })).toEqual([
'codebuddy',
'--resume',
'session-1'
])
})
})