Files
orca/tests/e2e/droid-notification.spec.ts
e516efcb61 Keep finished agents marked Done while their panes sleep (#41793)
* Remove finished-agent retention and keep sleeping status with panes

* Fix legacy pane projection and sleeping-agent regression fixtures

* Cover sleeping display-only status in parked terminal coverage

* Keep pane conversation identity only across continuous agent observations

* Remove duplicate import and keep sleep fixtures type checked

* Preserve conversation boundaries across replays and inherited clocks

* Cover conversation map stability across a large status batch

* Bound conversation capacity work to changed pane owners

* Pass capacity classifiers their layout input directly

* Finalize conversation provenance once per status batch

* Keep paired snapshot tests focused on observable outcomes

* Type the conversation provenance test fixtures explicitly

* Consolidate agent session imports after main merge

* Preserve provider replacement evidence when resetting conversation continuity

* Separate retention deletion from sleeping agent display

* Restore migration row bucket comparison

* Skip unusable pane identities before title ownership lookups

* Refresh conversation titles when their owning pane changes

* Update completion test sound mock after module move

* Keep finished agent status with sleeping panes and update agents by key

* Forward sleeping pane status and scope paired tab updates

* Preserve keyed selectors and compiler invalidation through final checks

* Keep bound store hooks visible to the compiler and measure published links

* Install provenance measurement before factory capture

* Use a static store hook and name presentation metadata once

* Preserve keyed freshness and atomic agent status publication

* Preserve remote folder dashboard regression after suite retirement

* Model pane wake before live identity reobservation in regression

* Share keyed row transactions and finish main integration

* Align runtime fixtures with keyed agent status reads

* Keep status projections addressed and activity summaries current

* Retire empty workspace status summaries after their source leaves

* Use the standard store fixture for parked terminal graph tests

* Align status fixtures with app types and a fixed test clock

* test: capture stored terminal render failure details

* Read terminal titles and completion prompts from keyed agent status

* Compose foreground agent state in worktree test stores

* test: complete lineage list agent state fixture

* Keep sleeping completion when retiring process authority

* Run durable agent-hook status tests with Node SQLite

* Preserve sleeping Done when renderer retires its process

* Update terminal fixtures for process retirement

* Read sleeping pane resume sources by key

* Bind sleep capture fixture to its live panes

* Pass the pane tree to the sleep capture fixture graph

* Preserve accepted completion identity through sleep

* Pass a nullable title to the status classifier

* Resolve accepted host status once and preserve delivery order

* Drop published sleep status when its host owner retires

* Use the supported remote completion test envelope

* Preserve published activity when filling completed status

* Update imports for main module moves

* Remove an unreachable native chat owner comparison

* Read host and unread card inputs by address instead of per root

A host-scoped sidebar card re-read every root's row and acknowledgement on
any store write, so one card with many sleeping roots paid for other
workspaces' updates. Card host filtering, the summary pill's unread state
and the workspace unread gate now first compare the workspace's projected
row revision and the changed keys of the tab-keyed layout/PTY maps and
the acknowledgement record. Only an addressed change re-reads the roots.
Acknowledge and unacknowledge annotate their writes so readers can skip
keys they don't show.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* Correct sleeping pane test imports after module moves

* Combine duplicate subscription test imports

* Record addressed acknowledgement deletions on row drops

* Type subscription fixture key set for string readers

* Keep accepted updates complete after observer failures

* Seed the send picker with its SSH terminal identity

* perf(layout): skip unused normalization reports in pane commands (#42615)

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* Clarify cleanup pinning and ignored-file protection (#42616)

* test: remove 55 low-value suites and assertion driver (#42605)

Co-authored-by: OrcaWin <293788423+OrcaWin@users.noreply.github.com>

* fix(skills): skip Claude sync scratch folders during skill discovery (#42610)

Claude Code parks replaced skill copies in `.trash` and in-progress syncs
in `.staging` under its skills roots. Discovery walked into both, so each
synced skill showed up as duplicates. Prune those directory names in the
native file walk and in the generated WSL `find` command.

Co-authored-by: Neil <4138956+nwparker@users.noreply.github.com>

* test: remove 78 low-value suites and trim redundant cases (#42621)

Co-authored-by: OrcaWin <293788423+OrcaWin@users.noreply.github.com>

* Keep a host card's unchanged agent rows after filtering out another host's pane

Re-lineage clones every row once a host-scoped card filters a row out, so an unrelated pane's status write rebuilt the card's row array and re-ran its signal and rollup memos. Reuse unchanged rows as main's sidebar row selector does.

* Seed the Copy Session ID shortcut test through keyed agent status

* Seed the graph payload partition test through keyed agent status

---------

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-authored-by: Jinjing <6427696+AmethystLiang@users.noreply.github.com>
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
Co-authored-by: OrcaWin <alpha-eng@stably.ai>
Co-authored-by: OrcaWin <293788423+OrcaWin@users.noreply.github.com>
Co-authored-by: BingZ <zzb@gxsmjx.com>
Co-authored-by: Neil <4138956+nwparker@users.noreply.github.com>
2026-11-15 11:38:40 -08:00

442 lines
14 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { test, expect } from './helpers/orca-app'
import type { ElectronApplication, Page } from '@stablyai/playwright-test'
import { getRendererTitleLog, installRendererTitleLog } from './helpers/terminal-title-log'
import {
sendToTerminal,
waitForActivePaneHookDescriptor,
waitForActivePanePtyId,
waitForActiveTerminalManager,
waitForTerminalOutput
} from './helpers/terminal'
import { ensureTerminalVisible, waitForActiveWorktree, waitForSessionReady } from './helpers/store'
import {
emitCodexHookStatus,
emitGrokHookPayload,
readHookEndpoint
} from './helpers/agent-hook-endpoint'
type NotificationDispatch = {
source?: string
terminalTitle?: string
paneKey?: string
isActiveWorktree?: boolean
agentType?: string
agentPrompt?: string
agentLastAssistantMessage?: string
}
type AgentStatusSummary = {
paneKey: string
state: string
agentType?: string
prompt?: string
lastAssistantMessage?: string
}
async function emitOscTitle(page: Page, ptyId: string, title: string) {
await sendToTerminal(page, ptyId, `printf '\\033]0;${title}\\007'\r`)
}
async function installMainProcessNotificationDispatchSpy(app: ElectronApplication): Promise<void> {
await app.evaluate(({ ipcMain }) => {
const g = globalThis as unknown as {
__notificationDispatchLog?: NotificationDispatch[]
__notificationDispatchSpyInstalled?: boolean
}
if (g.__notificationDispatchSpyInstalled) {
return
}
g.__notificationDispatchLog = []
g.__notificationDispatchSpyInstalled = true
ipcMain.removeHandler('notifications:dispatch')
ipcMain.handle('notifications:dispatch', (_event: unknown, args: NotificationDispatch) => {
g.__notificationDispatchLog!.push(args)
return { delivered: true }
})
})
}
async function getNotificationDispatches(
app: ElectronApplication
): Promise<NotificationDispatch[]> {
return app.evaluate(() => {
const g = globalThis as unknown as { __notificationDispatchLog?: NotificationDispatch[] }
return g.__notificationDispatchLog ?? []
})
}
async function switchToOtherExistingWorktree(page: Page): Promise<string> {
return page.evaluate(() => {
const store = window.__store
if (!store) {
throw new Error('Store unavailable')
}
const state = store.getState()
const activeWorktreeId = state.activeWorktreeId
if (!activeWorktreeId) {
throw new Error('No active worktree')
}
const activeWorktree = Object.values(state.worktreesByRepo)
.flat()
.find((worktree) => worktree.id === activeWorktreeId)
if (!activeWorktree) {
throw new Error(`Active worktree ${activeWorktreeId} not found`)
}
const otherWorktree =
Object.values(state.worktreesByRepo)
.flat()
.find(
(worktree) =>
worktree.repoId === activeWorktree.repoId &&
worktree.id !== activeWorktreeId &&
worktree.branch.replace(/^refs\/heads\//, '') === 'e2e-secondary'
) ??
Object.values(state.worktreesByRepo)
.flat()
.find(
(worktree) =>
worktree.repoId === activeWorktree.repoId && worktree.id !== activeWorktreeId
)
if (!otherWorktree) {
throw new Error(`No inactive worktree found for repo ${activeWorktree.repoId}`)
}
state.setActiveWorktree(otherWorktree.id)
return otherWorktree.id
})
}
async function getAgentStatuses(page: Page): Promise<AgentStatusSummary[]> {
return page.evaluate(() => {
const store = window.__store
if (!store) {
return []
}
return Array.from(store.getState().agentStatusByPaneKey?.values() ?? []).map((entry) => ({
paneKey: entry.paneKey,
state: entry.state,
agentType: entry.agentType,
prompt: entry.prompt,
lastAssistantMessage: entry.lastAssistantMessage
}))
})
}
async function getCachedAgentStatuses(page: Page): Promise<AgentStatusSummary[]> {
return page.evaluate(async () => {
const snapshot = await window.api.agentStatus.getSnapshot()
return snapshot.map((entry) => ({
paneKey: entry.paneKey,
state: entry.state,
agentType: entry.agentType,
prompt: entry.prompt,
lastAssistantMessage: entry.lastAssistantMessage
}))
})
}
async function getRendererOrCachedAgentStatuses(page: Page): Promise<AgentStatusSummary[]> {
const [rendererStatuses, cachedStatuses] = await Promise.all([
getAgentStatuses(page),
getCachedAgentStatuses(page)
])
return [...rendererStatuses, ...cachedStatuses]
}
async function isWorktreeUnread(page: Page, worktreeId: string): Promise<boolean> {
return page.evaluate((targetWorktreeId) => {
const store = window.__store
if (!store) {
return false
}
return (
Object.values(store.getState().worktreesByRepo)
.flat()
.find((worktree) => worktree.id === targetWorktreeId)?.isUnread === true
)
}, worktreeId)
}
test.describe('Droid notifications', () => {
test('Codex hook completion dispatches while its worktree is inactive', async ({
orcaPage,
electronApp
}) => {
await waitForSessionReady(orcaPage)
await waitForActiveWorktree(orcaPage)
await ensureTerminalVisible(orcaPage)
await waitForActiveTerminalManager(orcaPage, 30_000)
await installMainProcessNotificationDispatchSpy(electronApp)
const endpoint = await readHookEndpoint(electronApp)
// Synthetic hooks skip shell startup; wait for PTY responsiveness so the liveness gate can observe the turn.
const ptyId = await waitForActivePanePtyId(orcaPage)
const readyMarker = `__CODEX_HOOK_NOTIFY_READY_${Date.now()}__`
await sendToTerminal(orcaPage, ptyId, `printf '${readyMarker}\\n'\r`)
await waitForTerminalOutput(orcaPage, readyMarker)
const { paneKey, worktreeId } = await waitForActivePaneHookDescriptor(orcaPage)
const prompt = `codex-hook-notify-${Date.now()}`
await emitCodexHookStatus(endpoint, {
paneKey,
worktreeId,
state: 'working',
prompt
})
await expect
.poll(
async () =>
(await getRendererOrCachedAgentStatuses(orcaPage)).some(
(status) =>
status.agentType === 'codex' && status.state === 'working' && status.prompt === prompt
),
{
timeout: 30_000,
// Main’s cache recovers renderer startup/listener races; assert the direct hook reached it.
message: 'Codex UserPromptSubmit hook did not reach agent status cache'
}
)
.toBe(true)
await switchToOtherExistingWorktree(orcaPage)
const finalMessage = `Codex hook completed ${Date.now()}`
await emitCodexHookStatus(endpoint, {
paneKey,
worktreeId,
state: 'done',
prompt,
lastAssistantMessage: finalMessage
})
await expect
.poll(
async () =>
(await getAgentStatuses(orcaPage)).some(
(status) =>
status.agentType === 'codex' &&
status.state === 'done' &&
status.prompt === prompt &&
status.lastAssistantMessage === finalMessage
),
{
timeout: 30_000,
message: 'Codex Stop hook did not reach renderer agent status'
}
)
.toBe(true)
await expect
.poll(
async () => {
const dispatches = await getNotificationDispatches(electronApp)
return dispatches.filter((dispatch) => dispatch.source === 'agent-task-complete')
},
{
timeout: 30_000,
message: 'Codex hook Stop did not dispatch task-complete while worktree was inactive'
}
)
.toEqual([
expect.objectContaining({
source: 'agent-task-complete',
terminalTitle: 'codex',
isActiveWorktree: false,
agentType: 'codex',
agentPrompt: prompt,
agentLastAssistantMessage: finalMessage
})
])
await expect
.poll(async () => isWorktreeUnread(orcaPage, worktreeId), {
timeout: 10_000,
message: 'Codex hook Stop did not mark the inactive worktree unread'
})
.toBe(true)
})
test('Grok routine permission prompt hooks stay working and do not notify', async ({
orcaPage,
electronApp
}) => {
await waitForSessionReady(orcaPage)
await waitForActiveWorktree(orcaPage)
await ensureTerminalVisible(orcaPage)
await waitForActiveTerminalManager(orcaPage, 30_000)
await installMainProcessNotificationDispatchSpy(electronApp)
const endpoint = await readHookEndpoint(electronApp)
const ptyId = await waitForActivePanePtyId(orcaPage)
const readyMarker = `__GROK_HOOK_NOTIFY_READY_${Date.now()}__`
await sendToTerminal(orcaPage, ptyId, `printf '${readyMarker}\\n'\r`)
await waitForTerminalOutput(orcaPage, readyMarker)
const { paneKey, worktreeId } = await waitForActivePaneHookDescriptor(orcaPage)
const prompt = `grok-hook-notify-${Date.now()}`
await emitGrokHookPayload(endpoint, {
paneKey,
worktreeId,
payload: {
hookEventName: 'user_prompt_submit',
prompt
}
})
await expect
.poll(
async () =>
(await getAgentStatuses(orcaPage)).some(
(status) =>
status.agentType === 'grok' && status.state === 'working' && status.prompt === prompt
),
{
timeout: 30_000,
message: 'Grok UserPromptSubmit hook did not reach renderer agent status'
}
)
.toBe(true)
await emitGrokHookPayload(endpoint, {
paneKey,
worktreeId,
payload: {
hookEventName: 'pre_tool_use',
toolName: 'Shell',
toolInput: { command: 'echo hi' }
}
})
await emitGrokHookPayload(endpoint, {
paneKey,
worktreeId,
payload: {
hookEventName: 'notification',
notificationType: 'permission_prompt',
message: 'Tool permission requested',
level: 'info'
}
})
await orcaPage.waitForTimeout(500)
expect(
(await getAgentStatuses(orcaPage)).some(
(status) =>
status.agentType === 'grok' && status.prompt === prompt && status.state === 'waiting'
)
).toBe(false)
expect(
(await getNotificationDispatches(electronApp)).filter(
(dispatch) => dispatch.source === 'agent-task-complete'
)
).toEqual([])
const finalMessage = `Grok hook completed ${Date.now()}`
await emitGrokHookPayload(endpoint, {
paneKey,
worktreeId,
payload: {
hookEventName: 'stop',
lastAssistantMessage: finalMessage
}
})
await expect
.poll(
async () =>
(await getAgentStatuses(orcaPage)).some(
(status) =>
status.agentType === 'grok' &&
status.state === 'done' &&
status.prompt === prompt &&
status.lastAssistantMessage === finalMessage
),
{
timeout: 30_000,
message: 'Grok Stop hook did not reach renderer agent status'
}
)
.toBe(true)
})
test('recognized agent title completion dispatches one task-complete notification', async ({
orcaPage,
electronApp
}) => {
await waitForSessionReady(orcaPage)
await waitForActiveWorktree(orcaPage)
await ensureTerminalVisible(orcaPage)
await waitForActiveTerminalManager(orcaPage, 30_000)
// contextBridge freezes window.api; observe notification dispatch in main instead.
await installMainProcessNotificationDispatchSpy(electronApp)
await installRendererTitleLog(orcaPage)
const ptyId = await waitForActivePanePtyId(orcaPage)
const marker = `__CODEX_NOTIFY_READY_${Date.now()}__`
await sendToTerminal(orcaPage, ptyId, `printf '${marker}\\n'\r`)
await waitForTerminalOutput(orcaPage, marker)
await emitOscTitle(orcaPage, ptyId, 'Codex working')
await expect
.poll(async () => (await getRendererTitleLog(orcaPage)).includes('Codex working'), {
timeout: 10_000,
message: 'Codex working title did not reach the renderer before completion'
})
.toBe(true)
await emitOscTitle(orcaPage, ptyId, 'Codex done')
await expect
.poll(async () => (await getRendererTitleLog(orcaPage)).includes('Codex done'), {
timeout: 10_000,
message: 'Codex done title did not reach the renderer'
})
.toBe(true)
await expect
.poll(
async () => {
const dispatches = await getNotificationDispatches(electronApp)
return dispatches.filter((dispatch) => dispatch.source === 'agent-task-complete')
},
{
timeout: 10_000,
message: 'Codex working->done title transition did not dispatch task-complete'
}
)
.toEqual([
expect.objectContaining({ source: 'agent-task-complete', terminalTitle: 'Codex done' })
])
})
test('Factory Droid needs-input native title does not dispatch a task-complete notification', async ({
orcaPage,
electronApp
}) => {
await waitForSessionReady(orcaPage)
await waitForActiveWorktree(orcaPage)
await ensureTerminalVisible(orcaPage)
await waitForActiveTerminalManager(orcaPage, 30_000)
// contextBridge freezes window.api; observe notification dispatch in main instead.
await installMainProcessNotificationDispatchSpy(electronApp)
await installRendererTitleLog(orcaPage)
const ptyId = await waitForActivePanePtyId(orcaPage)
const marker = `__DROID_NOTIFY_READY_${Date.now()}__`
await sendToTerminal(orcaPage, ptyId, `printf '${marker}\\n'\r`)
await waitForTerminalOutput(orcaPage, marker)
await emitOscTitle(orcaPage, ptyId, '⠋ Droid')
await emitOscTitle(orcaPage, ptyId, 'Factory Droid needs input')
await expect
.poll(
async () => (await getRendererTitleLog(orcaPage)).includes('Factory Droid needs input'),
{
timeout: 10_000,
message: 'Factory Droid marker title did not land'
}
)
.toBe(true)
// Droid can show this title during Execute; hooks alone own its completion status.
await orcaPage.waitForTimeout(500)
const dispatches = await getNotificationDispatches(electronApp)
expect(dispatches).toEqual([])
})
})