Files
orca/tests/e2e/pi-ui-prompt-status.spec.ts
gatsby74andNeil a278d84a4e fix(pi): show input modals as waiting instead of working (#18836)
* fix(pi): show input modals as waiting instead of working

* test(pi): verify real input dialogs through Electron CDP

---------

Co-authored-by: Neil <4138956+nwparker@users.noreply.github.com>
2026-09-07 19:35:19 -07:00

73 lines
2.8 KiB
TypeScript

import { test, expect } from './helpers/orca-app'
import { readHookEndpoint } from './helpers/agent-hook-endpoint'
import { ensureTerminalVisible, waitForActiveWorktree, waitForSessionReady } from './helpers/store'
import {
sendToTerminal,
waitForActivePaneHookDescriptor,
waitForActivePanePtyId,
waitForActiveTerminalManager,
waitForTerminalOutput
} from './helpers/terminal'
test('Pi modal hooks show the existing waiting-for-input indicator', async ({
orcaPage,
electronApp
}, testInfo) => {
await waitForSessionReady(orcaPage)
await waitForActiveWorktree(orcaPage)
await ensureTerminalVisible(orcaPage)
await waitForActiveTerminalManager(orcaPage, 30_000)
const endpoint = await readHookEndpoint(electronApp)
const ptyId = await waitForActivePanePtyId(orcaPage)
const marker = '__PI_MODAL_STATUS_READY__'
await sendToTerminal(orcaPage, ptyId, `printf '${marker}\\n'\r`)
await waitForTerminalOutput(orcaPage, marker)
const { paneKey, worktreeId } = await waitForActivePaneHookDescriptor(orcaPage)
async function emit(payload: Record<string, unknown>): Promise<void> {
const response = await fetch(`http://127.0.0.1:${endpoint.port}/hook/pi`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-Orca-Agent-Hook-Token': endpoint.token
},
body: JSON.stringify({
paneKey,
tabId: paneKey.split(':')[0],
worktreeId,
env: endpoint.env,
version: endpoint.version,
payload
})
})
expect(response.status).toBe(204)
}
// Terminal tabs present both waiting and blocked as "Needs attention".
const waiting = orcaPage.locator('[aria-label="Needs attention"]')
await emit({ hook_event_name: 'before_agent_start', prompt: 'Pi modal status check' })
await expect(orcaPage.locator('[aria-label="Working"]').first()).toBeVisible()
await orcaPage.screenshot({ path: testInfo.outputPath('before-working.png') })
await emit({ hook_event_name: 'ui_prompt_start', ui_prompt_active: true })
await expect
.poll(() =>
orcaPage.evaluate(
(key) => window.__store?.getState().agentStatusByPaneKey[key]?.state,
paneKey
)
)
.toBe('waiting')
await expect(waiting.first()).toBeVisible()
await orcaPage.screenshot({ path: testInfo.outputPath('after-waiting.png') })
await emit({ hook_event_name: 'tool_execution_end', tool_name: 'bash', ui_prompt_active: true })
await expect(waiting.first()).toBeVisible()
await emit({ hook_event_name: 'ui_prompt_end', is_idle: false })
await expect(waiting).toHaveCount(0)
await expect(orcaPage.locator('[aria-label="Working"]').first()).toBeVisible()
await emit({ hook_event_name: 'agent_end' })
await expect(orcaPage.locator('[aria-label="Working"]')).toHaveCount(0)
await expect(waiting).toHaveCount(0)
})