test(terminal): pin cached OSC terminator reuse across BEL frames

Document that forward match reuse requires a monotonic search offset and cover a distant ST held across many intervening BEL frames.
This commit is contained in:
Neil
2026-09-07 23:28:53 -07:00
committed by github-actions[bot]
parent 5ee204bb3f
commit 5286e07bfd
3 changed files with 23 additions and 0 deletions
+1
View File
@@ -123,6 +123,7 @@
"file": "src/shared/agent-status-osc.test.ts",
"assertions": [
"uses the earliest mixed terminator and counts only parsed payload offsets",
"keeps a distant ST usable after many intervening BEL frames",
"preserves every split of prefixes, JSON, and both terminators across independent streams",
"applies the pending cap only to incomplete frames"
]
+20
View File
@@ -134,6 +134,26 @@ describe('createAgentStatusOscProcessor', () => {
}
})
it('keeps a distant ST usable after many intervening BEL frames', () => {
const count = 200
const bel = Array.from(
{ length: count },
(_, index) => `\x1b]9999;{"state":"working","prompt":"${index}"}\x07`
).join('')
const result = createAgentStatusOscProcessor()(
`${bel}\x1b]9999;{"state":"done","prompt":"last"}\x1b\\tail`
)
expect(result.payloads).toEqual([
...Array.from({ length: count }, (_, index) => ({
state: 'working',
prompt: String(index)
})),
{ state: 'done', prompt: 'last' }
])
expect(result.cleanData).toBe('tail')
})
it('applies the pending cap only to incomplete frames', () => {
const marker = '\x1b]9999;{"state":"working"}'
const atCap = marker + ' '.repeat(64 * 1024 - marker.length)
+2
View File
@@ -31,6 +31,8 @@ function findAgentStatusTerminator(
next: { belIndex: number; stIndex: number }
): { index: number; length: 1 | 2 } | null {
// Reuse forward matches, including absence, for this chunk's remaining frames.
// Requires `searchFrom` to increase on every call for one `data`; a rewind would
// reuse a match that is no longer the earliest.
if (next.belIndex !== -1 && next.belIndex < searchFrom) {
next.belIndex = data.indexOf('\x07', searchFrom)
}