Archive milestone artifacts: - milestones/v1.0-ROADMAP.md (full roadmap archive) - milestones/v1.0-REQUIREMENTS.md (26/26 requirements complete) - milestones/v1.0-phases/ (8 phase directories with plans, summaries, verifications) Updated: - PROJECT.md: full evolution review, all consolidation requirements validated - ROADMAP.md: collapsed to milestone summary with archive link - STATE.md: reset for next milestone - MILESTONES.md: created with stats and accomplishments - RETROSPECTIVE.md: created with lessons learned Deleted: - REQUIREMENTS.md (archived, fresh for next milestone) 8 phases, 17 plans, 34 tasks, 84 tests added, 6 days
2.6 KiB
2.6 KiB
Phase 3: Test Infrastructure - Context
Gathered: 2026-03-02 Status: Ready for planning
## Phase BoundaryCreate database.NewTestDB(t) — an in-memory SQLite test helper that mirrors production setup (migrations + PRAGMAs) — and apply production SQLite PRAGMAs (synchronous=NORMAL, cache_size=-8000, mmap_size=67108864) to the real NewDB(). This phase delivers the test foundation; actual test writing happens in Phases 4-5.
Test Helper API Shape
NewTestDB(t *testing.T)returns*DBonly — no cleanup function, no error return- Cleanup registered internally via
t.Cleanup()— callers just use the DB and forget - No functional options — every test DB gets the full production-mirror setup (PRAGMAs + all migrations)
- Does NOT expose raw
*sql.DB— tests useDB.ExecContext()/DB.Querieslike production code - Lives in
database/testhelper.go(exported, importable by other packages)
PRAGMA Behavior
- All PRAGMAs applied identically in tests and production — even
mmap_sizeon:memory:(verifies code path, true mirror) - Shared
applyPRAGMAs(*sql.DB)internal function called by bothNewDB()andNewTestDB()— single source of truth - Test DBs use the same connection string params as production (
?_busy_timeout=5000&_journal_mode=WAL) - PRAGMAs applied before schema creation — tuning first, then DDL/DML
Test Helper Scope
- No test data seeding helpers in Phase 3 — Phases 4-5 create fixtures as needed
- Future test phases should use
sqlcgen.Queries(not raw SQL) for inserting test data — same path as production - Skip the orphan cleanup query in
NewTestDB— test DBs start empty, no orphans to clean - No health check (SELECT 1) — trust that successful Open + PRAGMAs + migrations means the DB is usable
Claude's Discretion
- Internal helper function naming (
applyPRAGMAsvsconfigurePRAGMAsvs similar) - Whether
NewTestDBcallst.Fatal()ort.Helper()+t.Fatal()on setup failure - Exact error wrapping style in the shared PRAGMA function
- The shared
applyPRAGMAsfunction is the key architectural piece — it prevents production and test PRAGMA sets from drifting apart NewTestDBshould mirror theNewDBcode path as closely as possible, minus the file-path resolution and orphan cleanup- Connection string for test:
":memory:?_busy_timeout=5000&_journal_mode=WAL"(same params, in-memory URI)
None — discussion stayed within phase scope
Phase: 03-test-infrastructure Context gathered: 2026-03-02