Files
Codeman/test/terminal-history-schema.test.ts
T
Aamer Akhter 8c0c94540c COD-80 centralize terminal history/scrollback/buffer limits into config
Introduce src/config/terminal-history.ts: one place for terminal scrollback,
tmux history-limit, and PTY buffer byte caps, each overridable via env var or
the settings object and bounds-clamped via resolveTerminalHistoryConfig().
Defaults match the prior hardcoded values, so this is behavior-neutral. Wires
the resolver through buffer-limits, tmux-manager (incl. a setHistoryLimit so a
settings change applies live), session, server, system-routes, session-routes,
schemas, and the config port. Adds 4 optional settings keys (terminalScrollback
Lines, tmuxHistoryLimit, terminalBufferMaxBytes, terminalBufferTrimBytes) with
bounds + a trim<=max cross-check.
2026-06-30 19:52:49 -04:00

68 lines
2.4 KiB
TypeScript

import { describe, it, expect } from 'vitest';
import { SettingsUpdateSchema } from '../src/web/schemas.js';
import {
MAX_TERMINAL_SCROLLBACK_LINES,
MIN_TERMINAL_SCROLLBACK_LINES,
MAX_TERMINAL_BUFFER_BYTES,
MIN_TERMINAL_BUFFER_BYTES,
} from '../src/config/terminal-history.js';
describe('SettingsUpdateSchema — terminal history keys', () => {
it('accepts valid in-range terminal-history settings', () => {
const res = SettingsUpdateSchema.safeParse({
terminalScrollbackLines: 100_000,
tmuxHistoryLimit: 100_000,
terminalBufferMaxBytes: 32 * 1024 * 1024,
terminalBufferTrimBytes: 24 * 1024 * 1024,
});
expect(res.success).toBe(true);
});
it('accepts a settings object that omits the terminal-history keys', () => {
const res = SettingsUpdateSchema.safeParse({ allowedTools: 'Bash' });
expect(res.success).toBe(true);
});
it('rejects scrollback below the minimum', () => {
const res = SettingsUpdateSchema.safeParse({ terminalScrollbackLines: MIN_TERMINAL_SCROLLBACK_LINES - 1 });
expect(res.success).toBe(false);
});
it('rejects scrollback above the maximum', () => {
const res = SettingsUpdateSchema.safeParse({ tmuxHistoryLimit: MAX_TERMINAL_SCROLLBACK_LINES + 1 });
expect(res.success).toBe(false);
});
it('rejects buffer bytes outside the byte bounds', () => {
expect(SettingsUpdateSchema.safeParse({ terminalBufferMaxBytes: MIN_TERMINAL_BUFFER_BYTES - 1 }).success).toBe(
false
);
expect(SettingsUpdateSchema.safeParse({ terminalBufferMaxBytes: MAX_TERMINAL_BUFFER_BYTES + 1 }).success).toBe(
false
);
});
it('rejects non-integer values', () => {
expect(SettingsUpdateSchema.safeParse({ terminalScrollbackLines: 12_345.5 }).success).toBe(false);
});
it('rejects trim > max via the cross-field superRefine', () => {
const res = SettingsUpdateSchema.safeParse({
terminalBufferMaxBytes: 4 * 1024 * 1024,
terminalBufferTrimBytes: 8 * 1024 * 1024,
});
expect(res.success).toBe(false);
if (!res.success) {
expect(res.error.issues.some((i) => i.path.includes('terminalBufferTrimBytes'))).toBe(true);
}
});
it('allows trim == max', () => {
const res = SettingsUpdateSchema.safeParse({
terminalBufferMaxBytes: 8 * 1024 * 1024,
terminalBufferTrimBytes: 8 * 1024 * 1024,
});
expect(res.success).toBe(true);
});
});