mirror of
https://github.com/stablyai/orca.git
synced 2026-10-31 00:57:45 +00:00
test: verify terminal chunk yields without waiting for Enter delay (#29752)
Co-authored-by: OrcaWin <293788423+OrcaWin@users.noreply.github.com>
This commit is contained in:
+37
-17
@@ -280,29 +280,49 @@ describe('OrcaRuntimeService', () => {
|
||||
})
|
||||
|
||||
it('yields chunked terminal input through immediates between writes', async () => {
|
||||
const immediate = vi.spyOn(globalThis, 'setImmediate')
|
||||
const writes: string[] = []
|
||||
const bodyWritten = Promise.withResolvers<void>()
|
||||
let turnObserved = false
|
||||
let secondWriteFollowedTurn = false
|
||||
const runtime = new OrcaRuntimeService(store)
|
||||
runtime.setPtyController({
|
||||
spawn: vi.fn().mockResolvedValue({ id: 'pty-bg' }),
|
||||
write: (_ptyId, data) => {
|
||||
writes.push(data)
|
||||
if (writes.length === 1) {
|
||||
setImmediate(() => {
|
||||
turnObserved = true
|
||||
})
|
||||
} else if (writes.length === 2) {
|
||||
secondWriteFollowedTurn = turnObserved
|
||||
bodyWritten.resolve()
|
||||
}
|
||||
return true
|
||||
},
|
||||
kill: () => true,
|
||||
getForegroundProcess: async () => null
|
||||
})
|
||||
const { handle } = await runtime.createTerminal(`path:${TEST_WORKTREE_PATH}`)
|
||||
|
||||
vi.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout'], shouldClearNativeTimers: true })
|
||||
try {
|
||||
const writes: string[] = []
|
||||
const runtime = new OrcaRuntimeService(store)
|
||||
runtime.setPtyController({
|
||||
spawn: vi.fn().mockResolvedValue({ id: 'pty-bg' }),
|
||||
write: (_ptyId, data) => {
|
||||
writes.push(data)
|
||||
return true
|
||||
},
|
||||
kill: () => true,
|
||||
getForegroundProcess: async () => null
|
||||
})
|
||||
const { handle } = await runtime.createTerminal(`path:${TEST_WORKTREE_PATH}`)
|
||||
|
||||
const text = `${'x'.repeat(TERMINAL_INPUT_CHUNK_MAX_BYTES)}\nline two\nline three`
|
||||
await runtime.sendTerminal(handle, { text, enter: true }, { inputKind: 'driving' })
|
||||
await Promise.all([
|
||||
runtime.sendTerminal(handle, { text, enter: true }, { inputKind: 'driving' }),
|
||||
(async () => {
|
||||
await bodyWritten.promise
|
||||
// Let the write continuation arm the separate Enter timeout.
|
||||
await new Promise<void>((resolve) => setImmediate(resolve))
|
||||
await vi.runAllTimersAsync()
|
||||
})()
|
||||
])
|
||||
|
||||
expect(secondWriteFollowedTurn).toBe(true)
|
||||
expect(writes.at(-1)).toBe('\r')
|
||||
expect(writes.slice(0, -1).join('')).toBe(text)
|
||||
expect(immediate).toHaveBeenCalled()
|
||||
} finally {
|
||||
immediate.mockRestore()
|
||||
vi.clearAllTimers()
|
||||
vi.useRealTimers()
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user