Files
orca/src/shared/terminal-scrollback-policy.test.ts
T
Neil fed1eca486 test: stop restating internal tuning constants, keep the ones that are contracts (#23950)
Removes ~74 assertions of the form `expect(SOME_CONSTANT).toBe(<literal>)` where
the literal is an internal tuning value — a timeout, retry count, debounce
interval, cache TTL, circuit-breaker window, Tailwind class string. Those cannot
fail for any reason a user would notice: they fail only when someone deliberately
changes the number, and then the test is simply updated. They are copies of the
declaration.

The same pattern is NOT junk when the exact value is observable outside this
process, so those were deliberately kept:
- terminal byte contracts: `\r`, `\x03` ETX, Kitty escapes, `\x1b[?1;2c`;
- wire and capability values: `agent.launch.v2`, protocol 3 / min-compatible 2,
  daemon per-feature boundary versions (a daemon survives app updates, so those
  pin what an old field daemon may be trusted with), relay header tokens;
- security invariants: the `127.0.0.1` bind default, an empty iframe `sandbox`;
- values external processes read: exit code 78 (EX_CONFIG) and exit code 3
  (systemd `RestartPreventExitStatus`), `ORCA_AGENT_SESSION_SPAWN_TOKEN`,
  `npx skills …` commands users paste, on-disk journal schema versions,
  the `orca_<hash>` filename prefix the fish sweeper matches;
- third-party names: expo-router's `unstable_settings` / `ErrorBoundary`,
  iOS Safari's 16px zoom threshold.

Where a case asserted a relation rather than a literal — `A < B`, a sum of parts,
a cap compared against a sibling budget — the relation stays and only the literal
went.

Test-only changes: no production file is touched and no test file is deleted.
2026-09-29 17:06:09 -07:00

52 lines
2.8 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import {
legacyTerminalScrollbackBytesToRows,
normalizeDesktopTerminalScrollbackRows,
normalizeDesktopTerminalSnapshotRows,
TERMINAL_OUTPUT_BACKLOG_MIN_CAP_CHARS,
terminalOutputBacklogCapChars
} from './terminal-scrollback-policy'
describe('terminal scrollback policy', () => {
it('normalizes persisted desktop rows without string coercion', () => {
expect(normalizeDesktopTerminalScrollbackRows(undefined)).toBe(5_000)
expect(normalizeDesktopTerminalScrollbackRows('25000')).toBe(5_000)
expect(normalizeDesktopTerminalScrollbackRows(Number.NaN)).toBe(5_000)
expect(normalizeDesktopTerminalScrollbackRows(500.9)).toBe(1_000)
expect(normalizeDesktopTerminalScrollbackRows(25_000.9)).toBe(25_000)
expect(normalizeDesktopTerminalScrollbackRows(100_000)).toBe(50_000)
})
it('normalizes snapshot rows while preserving visible-screen-only zero', () => {
expect(normalizeDesktopTerminalSnapshotRows(undefined)).toBeUndefined()
expect(normalizeDesktopTerminalSnapshotRows('0')).toBeUndefined()
expect(normalizeDesktopTerminalSnapshotRows(0)).toBe(0)
expect(normalizeDesktopTerminalSnapshotRows(-1)).toBe(0)
expect(normalizeDesktopTerminalSnapshotRows(25_000.9)).toBe(25_000)
expect(normalizeDesktopTerminalSnapshotRows(100_000)).toBe(50_000)
})
it('scales the output backlog cap with scrollback rows above a 2 MB floor', () => {
// Default and small scrollbacks stay on the floor; large scrollbacks get
// proportionally more so the cap never drops lines scrollback would keep.
expect(terminalOutputBacklogCapChars(undefined)).toBe(TERMINAL_OUTPUT_BACKLOG_MIN_CAP_CHARS)
expect(terminalOutputBacklogCapChars(5_000)).toBe(TERMINAL_OUTPUT_BACKLOG_MIN_CAP_CHARS)
expect(terminalOutputBacklogCapChars('garbage')).toBe(TERMINAL_OUTPUT_BACKLOG_MIN_CAP_CHARS)
expect(terminalOutputBacklogCapChars(25_000)).toBe(3_000_000)
expect(terminalOutputBacklogCapChars(50_000)).toBe(6_000_000)
// Values beyond the settings max clamp like the setting itself does.
expect(terminalOutputBacklogCapChars(1_000_000)).toBe(6_000_000)
})
it('migrates legacy decimal MB buckets by intent, not byte-to-row math', () => {
expect(legacyTerminalScrollbackBytesToRows(undefined)).toBe(5_000)
expect(legacyTerminalScrollbackBytesToRows(0)).toBe(5_000)
expect(legacyTerminalScrollbackBytesToRows(1_000_000)).toBe(1_000)
expect(legacyTerminalScrollbackBytesToRows(10_000_000)).toBe(5_000)
expect(legacyTerminalScrollbackBytesToRows(25_000_000)).toBe(10_000)
expect(legacyTerminalScrollbackBytesToRows(50_000_000)).toBe(25_000)
expect(legacyTerminalScrollbackBytesToRows(100_000_000)).toBe(50_000)
expect(legacyTerminalScrollbackBytesToRows(250_000_000)).toBe(50_000)
})
})