db.init() replays SCHEMA_SQL + ~129 migrations on every fresh in-memory
DB (~40ms each), which is minutes of pure setup across thousands of
DB-backed tests. Add a test-only migrated-schema snapshot: migrate ONE
in-memory DB per test file, serialize it, and deserialize a fresh copy
per test instead of re-migrating. Each test still gets a brand-new,
fully-isolated in-memory DB; only the migration cost is amortized.
- sqlite-adapter: expose serialize()/deserialize() (node:sqlite + bun)
- db.ts: setInMemoryTemplateSnapshot() hook (test-only, null in prod) +
serializeSnapshot(); constructor deserializes the snapshot for
in-memory DBs so init() short-circuits migrate()+compat at v129
- store-test-helpers: install/clearInMemoryDbSnapshot harness
- dashboard: db-snapshot-helper mirror (core __tests__ is cross-package)
- convert agent-store, mission-store, workflow-routes suites
Measured (raw db.init(): 43ms -> 5ms, 8x):
- agent-store 13.12s -> 3.32s
- mission-store 17.62s -> 5.69s (min of 3)
- workflow-routes tests 4.38s -> 2.79s (min of 5; not init-dominated)
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>