Testing
Testing
Section titled “Testing”Only external behaviour is tested. Nothing asserts a private function’s shape, a component’s internals, or that a mock was called. If a test cannot fail for a reason a user would notice, it is not worth its runtime.
1. Seams
Section titled “1. Seams”| Seam | What it proves | Where |
|---|---|---|
| Authz matrix | can() is exhaustive over visibility × link role × anon policy × role × actor kind, including every deny cell |
server/test/authz-matrix.test.ts |
| REST contract | Golden request/response per endpoint, error shapes, 404-not-403 equality, 409 with current |
server/test/contract/*.test.ts |
| MCP parity | Driven through a real MCP SDK client; same capability as REST; argument names stable | server/test/mcp/*.test.ts |
| Ranks and moves | No duplicate/out-of-order position under randomized orders; append on missing neighbours | server/test/cards/move.test.ts |
| Events | Every mutation writes exactly one event with the documented payload | server/test/events.test.ts |
| Export round trip | export → import → export byte-identical modulo timestamps; v1 fixture imports | server/test/export/*.test.ts |
| Digest rules | Golden output on a fixed event log; empty digest sends nothing | server/test/digest/*.test.ts |
| Browser journeys | signup → board → invite → drag middle of a column → reload → order persists; anonymous write; moderation approve; agent test connection | e2e/*.spec.ts |
| A11y | axe on every route, keyboard-only board and dialogs, reduced motion | e2e/a11y.spec.ts |
| Contrast | Per token, against the surface it actually renders on, in both themes | web/test/contrast.test.ts |
| Boot gate | Boot against a database containing data, run migrations, require identical row counts | server/test/boot-gate.test.ts |
2. Database isolation
Section titled “2. Database isolation”- Each test file gets its own schema (
klui_test_<random>) created inglobalSetupand dropped inglobalTeardown, or its own database. Not a shared one. - Until that exists,
fileParallelism: falseinserver/vitest.config.ts. Note thatmaxConcurrencyandpool: "forks"limit tests within a file and do nothing about two files hitting one Postgres — which is how a suite “fails one run in three, passes alone”. - Never seed demo data into the database the suite runs on. The lifecycle sweeper computes a future
nowand purges seeded boards mid-run; the failure then looks like a routing bug. - The e2e suite uses a separate database from the dev server, dropped and recreated per run.
3. Browser tests
Section titled “3. Browser tests”- Run against the built server on its own port (
KLUI_E2E_BASE_URL=http://localhost:8123), never the Vite dev server. Cross-origin cookies make every test fail for the wrong reason. networkidlenever fires on a board: the SSE stream stays open. Wait fordomcontentloadedplus a selector, orexpect(locator).toBeVisible().- One browser context per spec file; sign-in is a helper, not a UI walk, except in the two specs that test sign-in itself.
- Screenshots on failure, traces on first retry. No screenshots in the assertions — measure the DOM.
4. The drag probe (the one that catches the real bug)
Section titled “4. The drag probe (the one that catches the real bug)”1. Seed a board with one column holding five cards (A B C D E).2. Grab card E by its title with pointer events (mouse.down, stepped moves, mouse.up).3. Drop it between B and C — the MIDDLE of the column, not above the first card.4. Assert the DOM order is A B E C D.5. Reload.6. Assert the order is still A B E C D.7. Assert GET /boards/:id/state returns the same order by position.Rules that make this probe honest:
- Aim at the middle. A probe that drops above the first card cannot distinguish insert from append — that false pass is how the bug ships.
- Drag within the same column and across columns; a downward same-column move is the case where an off-by-one appears.
- Use Playwright’s mouse, not CDP
Input.dispatchMouseEvent(it times out under drag libraries). - Assert the order after a reload, not just after the drop: an optimistic UI that never reached the server looks perfect until refresh.
- Run it three consecutive times in CI before a release. A single green run on a flaky interaction is not evidence.
5. Keyboard and accessibility
Section titled “5. Keyboard and accessibility”- Keyboard drag:
Spacelift,ArrowRightto the next column,ArrowDowntwice,Spacedrop, reload, order persists. Some drag libraries attach keyboard listeners one tick late — allow ~350 ms between presses in the test; a human is slower than that anyway. - axe runs on every route in both themes; zero violations, not “zero serious”.
- A keyboard-only journey must reach every control: tab through the board, open a card, edit it, save, close, and get focus back on the card.
- Reduced motion: set
prefers-reduced-motion: reduceand assert the spinner is a static frame witharia-busy.
6. Contrast
Section titled “6. Contrast”- The test parses
tokens.css; it does not duplicate the values. Duplicated values are how a palette change passes the gate and ships wrong. - Text tokens (
--ink,--ink-muted,--ink-subtle,--danger,--primary-foreground) are measured against every surface they can sit on:--canvas,--column,--card,--surface,--surface-2,--surface-muted. Measuring only against the canvas is how a token passes at 4.7:1 and ships at 3.99:1 in the place it is used. --control-borderis measured against--canvasand--surface-2at ≥ 3:1 (a boundary the user must perceive).- Borders are measured against the surface they separate (a card border is the seam between card and column), not against their own fill. That comparison is decorative and has a lower bar (≥ 1.2).
- Both themes are measured. A test that only reads
:rootsilently ships a broken light theme.
7. Contract and parity
Section titled “7. Contract and parity”- Golden files live next to the test, in
__golden__/, and are updated deliberately (UPDATE_GOLDEN=1), never automatically in CI. - The 404 equality test compares: status, body bytes, and the absence of headers that would vary (
X-Board-Id,ETag,Last-Modified). - MCP parity is driven through the real SDK client with a real key, over HTTP, against the built server. A hand-rolled JSON body tests your assumptions, not the protocol.
- The parity table is generated from
docs/mcp.mdat test time or asserted against it, so a tool added to the doc and not the server fails.
8. Boot gate
Section titled “8. Boot gate”1. Load a database dump (or a seeded fixture) with rows in every table.2. Record counts for users, boards, cards, comments, events, columns, sessions.3. Boot the container / run the entrypoint (`prisma migrate deploy && node dist/server.js`).4. Require: exit code 0, all migrations finished, counts identical, secret files' mtimes unchanged.This is the only test that proves a deploy will not destroy data. It runs in CI with a dump that is committed as a fixture (anonymised), and again manually before any release that touches schema.prisma.
9. Performance
Section titled “9. Performance”- A load test (
server/test/perf/) seeds 20 columns / 500 cards and asserts the budgets indocs/architecture.md§9 with a 20 % tolerance, marked slow and excluded from the default run. - The activity query is
EXPLAIN-checked: it must useevents(board_id, created_at desc, id), not a sequential scan.
10. What not to test
Section titled “10. What not to test”- Private functions, internal module structure, “was this helper called”.
- Snapshot tests of whole components (a snapshot that nobody reads fails on every style change and proves nothing).
- Mocked behaviour of a third-party library we do not control.
- Anything a type already guarantees (a shape test that duplicates a Zod schema).
11. False greens (the list to keep on the wall)
Section titled “11. False greens (the list to keep on the wall)”- A green gate that never ran. A workflow that exists but has no run is not CI. Paste the log line.
- A piped exit code.
cmd | tail && echo ALLGREENreports the tail’s status. Useset -o pipefailor chain on the raw command. - A helper that always reports failure (
[ cond ] && say OK || say FAILfires FAIL whensay OKitself returns 1). Useif/else, and make every helper end withreturn 0. - A drag probe aimed at the top of a column.
- A test count that did not move. If the pre-task baseline was 42 and the report says 42 after adding tests, the tests were not written.
- A screenshot of a stale server. A rebuild without a restart serves the old bundle; a blank page with a green build.
- A contrast test that only reads one theme or one surface.
- A seeded demo board that the sweeper purges mid-run.
- A Done line without a commit and a push. Check
git statusandgit ls-remotebefore trusting “done”.
12. Commands
Section titled “12. Commands”npm cinpm run format:checknpm run typechecknpm run lintnpm test # vitest, both workspaces, serializednpm run buildnpm run test:e2e # builds, starts the built server on 8123, runs Playwrightnpm run test:perf # slow, opt-intest:e2e starts the server itself, waits for /healthz to report db:"up", and kills it on exit — including on failure. A leftover process on 8123 means the next run tests a stale build.
13. Verification protocol
Section titled “13. Verification protocol”Every wave ends with docs/verify/k<wave>.md:
## K2-04 — pragmatic drag and drop
### Exit: a card dropped into the middle of a populated column lands between the two cards
$ npx playwright test e2e/board-drag.spec.ts --reporter=lineRunning 1 test using 1 worker ✓ 1 e2e/board-drag.spec.ts:12:1 › drop between two cards, reload, order persists (4.2s)1 passed (4.6s)
Verdict: PASSRules: the command, the real trimmed output, the verdict. No invented numbers. A red gate that is not fixed is reported as red and the wave stops. A deviation from the plan is written here with its reason — silent deviation is the one unrecoverable failure.