Split The code is public; the app answers only to the crew.

The check fails on a busy machine: `db.test.ts` times one cold `standings` call against a 10 ms wall clock #241

open told opened this
opened this

Intent: the test that guards the standings query proves the cost does not grow with the table, and it proves that the same way on a loaded CI runner as on an idle laptop.

Why now. #126 was parked twice on 2026-09-23 (01:35, 01:42). Both runs found nothing to build, and the second reported bun run check red on src/db.test.ts:236: standings answers in a budget that does not grow with the table: 20,000 matches in under 10ms. It passed on a rerun. The test times a single first call, so the statement compile and a cold page cache are inside the 10 ms, with no warm-up and no repeats (src/db.test.ts:241-243). A check that fails on load fails previews for pulls that never touched db.ts.

The property the test title claims is structural. standings reads the standing table through standing_by_rank (src/db.ts:147, :232). The query plan can pin that deterministically, and the plan is what keeps the cost from growing with the table.

Done looks like:

  • [ ] The 20,000-row test asserts the plan. EXPLAIN QUERY PLAN for the statement standings runs uses the standing_by_rank index. It has no SCAN match, and it has no USE TEMP B-TREE FOR ORDER BY. Export the SQL as a constant from db.ts if the test needs it; do not duplicate the string.
  • [ ] The timing assertion stays as a coarse guard, written the way src/client/textures.test.ts:55-63 already does it: one warm-up call, then the median (or mean) of several calls, with a bound that has headroom. A comment says why the bound has that value.
  • [ ] The test would still fail without the index. Show it in the pull by dropping standing_by_rank in a scratch run: the plan assertion goes red.
  • [ ] bun run check passes 20 times in a row locally (for i in $(seq 20); do bun run check || break; done), and the pull says so.
  • [ ] No other test changes. db.ts behaviour does not change, apart from exporting the SQL if that is needed.

Files: src/db.test.ts, and possibly src/db.ts (one exported constant).

Risks: SQLite's plan text wording differs between versions. Match on standing_by_rank and the absence of SCAN match / TEMP B-TREE, not on the whole line. Do not loosen the bound to 100 ms and call it fixed: that leaves the flake in place, only rarer.

Suggested builder: scout, who found it while on #126. A person assigns.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs