♻️ SQLite state foundation with migrations and full metadata parity#231
♻️ SQLite state foundation with migrations and full metadata parity#231
Conversation
Introduce schema-versioned SQLite migrations for reporter state and metadata.\nPort baseline/hotspot/region/baseline-build metadata and server registry off JSON files with one-time legacy imports.\nUpdate routers, context, handlers, and tests to read/write through the DB-backed state store.
This comment has been minimized.
This comment has been minimized.
PR Review: SQLite state foundation with migrations and full metadata parityOverall this is a solid, well-scoped migration. The schema versioning story is clean, the file/SQLite backends share a coherent interface, and the dependency injection pattern preserves testability throughout. A few things worth addressing before merge: Performance: store opened/closed per HTTP requestIn The events router shows the right pattern — create one store, subscribe, close on disconnect. Dashboard and health should receive the store as a dependency (injected at server startup) the same way the TDD handler does with Per-operation store opening in metadata modules
function withStateStore(workingDir, operation) {
let store = createStateStore({ workingDir });
try { return operation(store); }
finally { store.close(); }
}Every Module-level
|
Break the monolithic state store into a small facade plus dedicated files for schema migrations, sqlite backend, file backend, events, constants, and shared helpers. This keeps DB evolution isolated and gives us a cleaner foundation for future migrations.
This comment has been minimized.
This comment has been minimized.
- remove file state-store fallback and backend toggles\n- tighten registry/event/state utilities for cleaner behavior\n- move handler/service coverage to real sqlite-backed tests
This comment has been minimized.
This comment has been minimized.
Introduce explicit read/write store modes, enforce a single writer path, and add one-time legacy JSON bootstrap on CLI startup.\n\nAlso updates routers/services/tests for read-mode access, resets in-memory TDD runtime state on baseline reset, and adds migration/mode contract coverage.
Vizzly - Visual Test Results
|
Why
This refactor is about making local TDD state durable and predictable as the CLI grows.
The old JSON files worked for early usage, but they were starting to create complexity around consistency, migration, and multi-process behavior. SQLite gives us a real schema, safer state evolution, and cleaner concurrency boundaries.
What changed
src/tdd/state-store/sqlite-store.jssrc/tdd/state-store/migrations.jsmode: 'write'for the TDD writer pathmode: 'read'for routers/services/commands that should never mutate statesrc/server/handlers/tdd-handler.jsstate.dbis created for the first timestate.db)Migration behavior (final)
.vizzly/exists,state.dbdoes not exist, and legacy state files exist, we bootstrap migration once.state.dbexists, migration does not run again.This keeps startup safe and predictable, and avoids hidden write behavior in read-only code paths.
Test plan
npm run lintnode --test tests/tdd/state-store-mode.test.js tests/tdd/metadata/baseline-metadata.test.js tests/tdd/metadata/hotspot-metadata.test.js tests/tdd/metadata/region-metadata.test.js tests/server/routers/events.test.js tests/tdd/tdd-service.integration.test.jsnode --test tests/server/handlers/tdd-handler.test.js tests/server/http-server.test.js tests/server/routers/dashboard.test.js tests/tdd/tdd-service.test.js tests/utils/context.test.jsNotes:
npm testin this sandbox still reports existingtests/utils/colors.test.jscolor assertions (TTY/env behavior). The SQLite/state suites above are green.