Files
orca/src/shared/terminal-reply-query-scan.test.ts
T
NeilandOrca fd6805a299 Fix mobile terminal query reply authority (#8227)
* Fix mobile terminal query reply authority

* fix(terminal): harden mobile query reply handoffs

* fix(terminal): exclude passive mobile query responders

* fix(terminal): gate mobile query replies on host capability

Older hosts strip terminal.send's inputKind (zod drops unknown keys), so a
forwarded xterm reply would land as ordinary floor-taking shell input. Hosts
now advertise terminal.query-reply-input.v1 via status.get and mobile drops
replies unless the host advertises it (pre-fix behavior). Also documents the
bounded desktop-to-mobile handoff double-reply residual.

Co-authored-by: Orca <help@stably.ai>

* fix(terminal): advance snapshot seq across recovery snapshots

The pending-overflow recovery loop trims buffered output against
recovery.seq while query replay and boundary strips kept using the
initial snapshot seq. Unreachable under today's control flow (no await
separates the initial-overflow consume from the loop), but the stale
seq would silently drop covered query replies if that ordering ever
changes. Track the seq that actually covered the buffered chunks.

Co-authored-by: Orca <help@stably.ai>

---------

Co-authored-by: Orca <help@stably.ai>
2026-07-11 02:13:15 -07:00

42 lines
1.4 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import {
EMPTY_TERMINAL_REPLY_QUERY_SCAN_STATE,
scanTerminalReplyQuerySequences
} from './terminal-reply-query-scan'
describe('terminal reply query scan', () => {
it('records reply-eliciting queries with their output high-water sequence', () => {
const data = `before\x1b[6nafter\x1b[?2031h`
const result = scanTerminalReplyQuerySequences(data, 100, EMPTY_TERMINAL_REPLY_QUERY_SCAN_STATE)
expect(result.queries).toEqual([
{ data: '\x1b[6n', startSeq: 106, endSeq: 110 },
{ data: '\x1b[?2031h', startSeq: 115, endSeq: 123 }
])
expect(result.state).toEqual(EMPTY_TERMINAL_REPLY_QUERY_SCAN_STATE)
})
it('assembles a query split across contiguous PTY chunks', () => {
const first = scanTerminalReplyQuerySequences(
'\x1b[?',
20,
EMPTY_TERMINAL_REPLY_QUERY_SCAN_STATE
)
const second = scanTerminalReplyQuerySequences('2026$p', 23, first.state)
expect(first.queries).toEqual([])
expect(second.queries).toEqual([{ data: '\x1b[?2026$p', startSeq: 20, endSeq: 29 }])
})
it('drops a partial query when output sequence continuity is lost', () => {
const first = scanTerminalReplyQuerySequences(
'\x1b[?',
20,
EMPTY_TERMINAL_REPLY_QUERY_SCAN_STATE
)
const second = scanTerminalReplyQuerySequences('2026$p', 30, first.state)
expect(second.queries).toEqual([])
})
})