Repository navigation
test(runtime): enforce ANSI preview-final pre-filter invariant - #27376
Conversation
Follow-up to #27344. isTerminalPreviewLineControl now gates on isTerminalPreviewLineControlFinal, so the normalizeTerminalChunk pre-filter cannot drop a final the predicate accepts. Add a test over every CSI final 0x40-0x7e and replace String.prototype.charCodeAt spies with behavior assertions.
📝 Walkthrough
Priority: ⬇️ Low Merge Risk: 🔵 Low · up to Terminal detection still returns the expected results, but a future broad scan of large output could pass these tests unnoticed. Restoring the small inspection bound keeps that performance regression detectable. Pre-merge checks |
|
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/main/runtime/terminal-vertical-control-scan.test.ts (1)
56-62: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick winRestore the code-unit bound for the large-input detector test.
The boolean assertions do not detect broader scanning when output remains unchanged. No other runtime test bounds
charCodeAtcalls forcontainsTerminalVerticalLineControl. Restore the previous bound in this test.Suggested fix
-import { describe, expect, it } from 'vitest' +import { describe, expect, it, vi } from 'vitest' ... - ] as const)('detects vertical controls in %s output', (_name, input, expected) => { - expect(containsTerminalVerticalLineControl(input)).toBe(expected) + ] as const)('bounds code-unit inspections on %s output', (_name, input, expected) => { + const charCodeAt = vi.spyOn(String.prototype, 'charCodeAt') + let actual: boolean + let inspections: number + try { + actual = containsTerminalVerticalLineControl(input) + inspections = charCodeAt.mock.calls.length + } finally { + charCodeAt.mockRestore() + } + + expect(actual).toBe(expected) + expect(inspections).toBeLessThan(16) })
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
1450071a-2b18-4a79-b0ea-c72405b97689
📒 Files selected for processing (2)
src/main/runtime/terminal-ansi-normalization.tssrc/main/runtime/terminal-vertical-control-scan.test.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.
ELI5
Follow-up to #27344, which sped up how Orca cleans terminal output for previews. That change was correct, but one of its shortcuts depended on two lists staying in sync by hand, and one test counted internal steps instead of checking results. This makes the shortcut safe by construction and makes the tests check what users actually see.
What Changed
No user-visible change; terminal previews keep exactly the same text.
normalizeTerminalChunkonly parses a CSI escape whenisTerminalPreviewLineControlFinal(final)is true. Before,isTerminalPreviewLineControldecided retention on its own, so a final byte added there but not to the pre-filter would have been silently dropped. NowisTerminalPreviewLineControlreturns false for any final the pre-filter rejects, soisTerminalPreviewLineControlFinalis the single source of truth for which finals can be kept.normalizeTerminalChunkand asserts exactly `A C D G K `` are retained and everything else is stripped. Removing a final from the pre-filter fails this test (checked by mutation).terminal-vertical-control-scan.test.tsno longer spies on the globalString.prototype.charCodeAtto count inspections, which tied the test to how the code is written. The same inputs are still asserted for output; the separate equivalence and fuzz work from perf(runtime): reduce terminal ANSI scanning work #27344 covers correctness.Why
A structural gate is cheaper to keep correct than a comment asking people to update two functions, and the exhaustive final-byte test pins the retained set so any future change is deliberate. Removing the spy keeps the tests stable under refactors that do not change behavior.
Linked Issue
Follow-up to #27344 (part of #27023).
Visual Proof
N/A — no UI or output change; the pre-filter and predicate accept the same finals as before.
Testing
macOS:
terminal-vertical-control-scan,terminal-ansi-pending-retention, allterminal-tail*,terminal-command-paintandorca-runtime-on-pty-data-redrawsuites pass (12 files / 115 tests).Mutation check: removing
GfromisTerminalPreviewLineControlFinalmakes the new final-byte test fail.oxlintandoxfmtclean on changed files.I manually tested these changes locally
Automated tests added/updated, or explained why not below
AI Disclosure
Review
Check that the reordered guard in
isTerminalPreviewLineControlreturns the same result for every input (the final check moved first;Kmode handling is unchanged).Agent skill upstream boundary
Notes
Pure-function change; platform-independent and applies equally to local, SSH and folder-workspace terminals. No wire, state or allocation changes.
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)