- doctest, wired into CMake as a
ctesttarget (doctest_discover_tests). ctestruns the full suite. CI builds the binary and runsctest.
- The suite must stay green (
ctest) at all times; add tests alongside the code they cover. - Fixtures are generated at test time with the SQLite C API (known schema and page size) so expected page numbers, types, and rowids are deterministic.
- Pure logic (varint/record decoders, page-number math, CSV/profile aggregation, CLI parsing) is unit-tested directly; commands are covered end to end.
- The visualize server and API are tested (a server is started on an
ephemeral port and driven with an HTTP client); the canvas pixels are not
browser-tested — verify rendering by running
visualize serveand looking.
- Generate small SQLite databases at build/test time with a known schema and page size so expected page indices are deterministic.
- Keep one fixture with a single table small enough to fit in a few pages, and one larger fixture that forces multi-page reads (B-tree spanning several pages).
- Statements file parsing — valid files produce the expected sessions and statements; malformed JSON and missing required fields fail with a clear error.
- Page number derivation —
offset / pageSize + 1(1-based) for representative offsets, including the offset-0 header read mapping to page 0 and the page-size = 1 (65536) header encoding. - CSV writer — header row plus correct column order and escaping.
- Run
profileagainst a fixture with aSELECTsession and assert the output CSV containsReadrows for the expected pages, in order. - Run a session with an
INSERT/UPDATEand assertWriterows appear and the in-place database reflects the change afterward. - Assert journal/WAL/temp files produce no rows (main DB only).
- Assert
Statement IndexandSession Namecolumns match the input across a multi-session, multi-statement run.
- Build fixtures (table + index + overflow row, an
auto_vacuumDB with pointer-map pages, a post-delete DB with freelist pages), runmap, then open the output with SQLite and assert:pagescount equalsmeta.pageCount; object→page assignment viapages.objectId; rowid ranges;cellswith decoded keys for known pages; everypointers.toPageis valid;runstile every page with no gaps/overlaps;type_countsandobjects.pageCountagree withpages.
- Build a small map, start the server on an ephemeral port, and assert the query
API (
/api/meta,/api/pages,/api/runs,/api/page/:n,/api/object/pages,/api/profile/*) returns correct JSON; the per-block range cap returns 413 and a missing page 404; static assets serve with correct content types. - Profile aggregation (CSV → per-page reads/writes) and run coalescing are unit-tested directly.
AggregatingSinkaggregates reads/writes per page (unit test).augmentWithRowidsprepends"table".rowidfor plain selects and refuses DISTINCT / GROUP BY / non-select queries (unit test).QueryEngineagainst a db + map fixture: run captures columns/rows and a cold-cache profile; row slices paginate; bad SQL errors; explain returns both plans; history lists newest-first; the schema tree joins to map counts; and row→page resolves single-table cells while leaving expressions/aggregates null.- HTTP: with a
--db-file,/api/metareportshasDb,/api/query/runreturns results (400 on bad SQL), and/api/schemareturns the tree.
Run with cd web && npm test. The framework-agnostic web/src/core/* modules
(palette, overlay tint/darken, layout/zoom math, profile aggregates, selParam)
and the query store (windowed row loading, loadMoreRows growth, history restore
without re-running) are unit-tested. Canvas rendering is verified by running
visualize serve and looking.
sqlinsite profile --test-file sample.db --statements sample.json --out-file out.csv
Inspect out.csv for plausible page access patterns.