/** * The list budgets, held against a run of `lists.ts`. * * COTTON_PERF_LISTS=<run dir>/lists.json pnpm perf:lists * * Without a run the budgets are not timed here (a CI runner holds no seeded * database); what the script reads is still checked. */import { existsSync, readFileSync } from'node:fs';import { join } from'node:path';import { describe, expect, it } from'vitest';import { BUDGET, keystrokes, kitTables, listCalls, typeTimed } from'./lists';const ROOT = join(__dirname, '../..');const RUN = process.env.COTTON_PERF_LISTS;describe('what lists.ts times', () => { it('opens every list the kit ships', () => {const shipped = kitTables(ROOT); expect(shipped).toContain('todo');const timed = newSet(listCalls(ROOT).map(call => call.args.table));for (const table of shipped) expect(timed.has(table)).toBe(true); }); it('types a search one letter at a time', () => { expect(keystrokes('s', 'abc', typed => ({ query: typed })).map(call => call.args.query)).toEqual(['a', 'ab', 'abc']); });});describe.skipIf(!RUN || !existsSync(RUN))('the budgets, on the lists database', () => {const timed = RUN && existsSync(RUN) ? (JSON.parse(readFileSync(RUN, 'utf8')) as { timed: Timed[] }).timed : [];const over = (prefix: string, budget: number) => timed.filter(t => t.name.startsWith(prefix) && t.median_ms > budget).map(t => `${t.name}: ${t.median_ms.toFixed(1)} ms`);/// RULE: a list's first page is read within its budget on the phone's own/// copy — the owner, 15 Oct 2026: "we're on the local database, everything/// should load instantly; users need to feel it." it('reads every list within its budget', () => { expect(over('list ', BUDGET.listMs)).toEqual([]); });/// RULE: a chat opens at its end within the budget however long it is/// (the owner's rule above; the 2,000-message chat is the one timed). it('opens the longest chat within its budget', () => { expect(over('thread ', BUDGET.threadMs)).toEqual([]); });/// RULE: search answers each keystroke within its budget (the owner's rule above). it('answers every keystroke within its budget', () => { expect(over('search ', BUDGET.keystrokeMs)).toEqual([]); });});