mirror of
https://github.com/stablyai/orca.git
synced 2026-10-31 00:57:45 +00:00
test: exercise interrupt admission and exit preconditions (#29719)
Co-authored-by: OrcaWin <293788423+OrcaWin@users.noreply.github.com>
This commit is contained in:
+12
-4
@@ -549,7 +549,7 @@ export function registerPtyConnectionInterruptInferenceTests(): void {
|
||||
prompt: 'ssh style write',
|
||||
updatedAt: 1_000,
|
||||
stateStartedAt: 900,
|
||||
agentType: 'codex',
|
||||
agentType: 'custom-agent',
|
||||
paneKey,
|
||||
terminalTitle: 'Codex working',
|
||||
stateHistory: []
|
||||
@@ -566,7 +566,7 @@ export function registerPtyConnectionInterruptInferenceTests(): void {
|
||||
throw new Error('expected onData handler to be registered')
|
||||
}
|
||||
;(onDataHandler as unknown as (data: string) => void)('\x03')
|
||||
vi.advanceTimersByTime(500)
|
||||
await vi.advanceTimersByTimeAsync(500)
|
||||
await flushAsyncTicks()
|
||||
|
||||
expect(transport.sendInput).toHaveBeenCalledWith('\x03', 'query-reply')
|
||||
@@ -591,7 +591,7 @@ export function registerPtyConnectionInterruptInferenceTests(): void {
|
||||
prompt: 'stop then exit',
|
||||
updatedAt: 1_000,
|
||||
stateStartedAt: 900,
|
||||
agentType: 'codex',
|
||||
agentType: 'custom-agent',
|
||||
paneKey,
|
||||
terminalTitle: 'Codex working',
|
||||
stateHistory: []
|
||||
@@ -613,8 +613,16 @@ export function registerPtyConnectionInterruptInferenceTests(): void {
|
||||
terminalTarget.dispatch(keyEvent({ key: 'c', ctrlKey: true }))
|
||||
;(onDataHandler as unknown as (data: string) => void)('\x03')
|
||||
await flushAsyncTicks()
|
||||
vi.advanceTimersByTime(500)
|
||||
await vi.advanceTimersByTimeAsync(500)
|
||||
await flushAsyncTicks()
|
||||
expect(window.api.agentStatus.inferInterrupt).toHaveBeenCalledWith({
|
||||
paneKey,
|
||||
baselineUpdatedAt: 1_000,
|
||||
baselineStateStartedAt: 900,
|
||||
baselinePrompt: 'stop then exit',
|
||||
baselineAgentType: 'custom-agent',
|
||||
intent: 'ctrl-c'
|
||||
})
|
||||
const onPtyExit = createdTransportOptions[0]?.onPtyExit as
|
||||
| ((ptyId: string) => void)
|
||||
| undefined
|
||||
|
||||
+46
-43
@@ -630,48 +630,7 @@ export function registerPtyConnectionTerminalInputGatingTests(): void {
|
||||
prompt: 'disconnected input',
|
||||
updatedAt: 1_000,
|
||||
stateStartedAt: 900,
|
||||
agentType: 'codex',
|
||||
stateHistory: []
|
||||
}
|
||||
|
||||
const pane = createPane(1)
|
||||
const terminalTarget = createKeyboardEventTarget()
|
||||
;(pane.terminal as { element?: unknown }).element = terminalTarget.target
|
||||
let onDataHandler: ((data: string) => void) | null = null
|
||||
pane.terminal.onData = vi.fn(((handler: (data: string) => void) => {
|
||||
onDataHandler = handler
|
||||
return { dispose: vi.fn() }
|
||||
}) as typeof pane.terminal.onData)
|
||||
|
||||
connectPanePty(pane as never, createManager(1) as never, createDeps() as never)
|
||||
|
||||
if (!onDataHandler) {
|
||||
throw new Error('expected onData handler to be registered')
|
||||
}
|
||||
terminalTarget.dispatch(keyEvent({ key: 'c', ctrlKey: true }))
|
||||
;(onDataHandler as unknown as (data: string) => void)('\x03')
|
||||
vi.advanceTimersByTime(500)
|
||||
|
||||
expect(transport.sendInput).toHaveBeenCalledWith('\x03')
|
||||
expect(window.api.agentStatus.inferInterrupt).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('does not infer interrupts when the main process rejects acknowledged input', async () => {
|
||||
const { connectPanePty } = await import('./pty-connection')
|
||||
|
||||
vi.useFakeTimers()
|
||||
vi.setSystemTime(1_100)
|
||||
const transport = createMockTransport('pty-mobile-race')
|
||||
transport.sendInputAccepted = vi.fn().mockResolvedValue(false)
|
||||
transportFactoryQueue.push(transport)
|
||||
const paneKey = makePaneKey('tab-1', LEAF_1)
|
||||
mockStoreState.agentStatusByPaneKey[paneKey] = {
|
||||
paneKey,
|
||||
state: 'working',
|
||||
prompt: 'mobile race input',
|
||||
updatedAt: 1_000,
|
||||
stateStartedAt: 900,
|
||||
agentType: 'codex',
|
||||
agentType: 'custom-agent',
|
||||
stateHistory: []
|
||||
}
|
||||
|
||||
@@ -692,7 +651,51 @@ export function registerPtyConnectionTerminalInputGatingTests(): void {
|
||||
terminalTarget.dispatch(keyEvent({ key: 'c', ctrlKey: true }))
|
||||
;(onDataHandler as unknown as (data: string) => void)('\x03')
|
||||
await flushAsyncTicks()
|
||||
vi.advanceTimersByTime(500)
|
||||
await vi.advanceTimersByTimeAsync(500)
|
||||
await flushAsyncTicks()
|
||||
|
||||
expect(transport.sendInput).toHaveBeenCalledWith('\x03')
|
||||
expect(window.api.agentStatus.inferInterrupt).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('does not infer interrupts when the main process rejects acknowledged input', async () => {
|
||||
const { connectPanePty } = await import('./pty-connection')
|
||||
|
||||
vi.useFakeTimers()
|
||||
vi.setSystemTime(1_100)
|
||||
const transport = createMockTransport('pty-mobile-race')
|
||||
transport.sendInputAccepted = vi.fn().mockResolvedValue(false)
|
||||
transportFactoryQueue.push(transport)
|
||||
const paneKey = makePaneKey('tab-1', LEAF_1)
|
||||
mockStoreState.agentStatusByPaneKey[paneKey] = {
|
||||
paneKey,
|
||||
state: 'working',
|
||||
prompt: 'mobile race input',
|
||||
updatedAt: 1_000,
|
||||
stateStartedAt: 900,
|
||||
agentType: 'custom-agent',
|
||||
stateHistory: []
|
||||
}
|
||||
|
||||
const pane = createPane(1)
|
||||
const terminalTarget = createKeyboardEventTarget()
|
||||
;(pane.terminal as { element?: unknown }).element = terminalTarget.target
|
||||
let onDataHandler: ((data: string) => void) | null = null
|
||||
pane.terminal.onData = vi.fn(((handler: (data: string) => void) => {
|
||||
onDataHandler = handler
|
||||
return { dispose: vi.fn() }
|
||||
}) as typeof pane.terminal.onData)
|
||||
|
||||
connectPanePty(pane as never, createManager(1) as never, createDeps() as never)
|
||||
|
||||
if (!onDataHandler) {
|
||||
throw new Error('expected onData handler to be registered')
|
||||
}
|
||||
terminalTarget.dispatch(keyEvent({ key: 'c', ctrlKey: true }))
|
||||
;(onDataHandler as unknown as (data: string) => void)('\x03')
|
||||
await flushAsyncTicks()
|
||||
await vi.advanceTimersByTimeAsync(500)
|
||||
await flushAsyncTicks()
|
||||
|
||||
expect(transport.sendInputAccepted).toHaveBeenCalledWith('\x03', 'query-reply')
|
||||
expect(transport.sendInput).not.toHaveBeenCalled()
|
||||
|
||||
Reference in New Issue
Block a user