refactor(test): shared createTestDb helper from migration registry (section B2, part 1)#3498
Conversation
…y (section B2, part 1) ~40 non-migration test files hand-roll `CREATE TABLE` per backend, duplicating src/db/schema. That DDL drifts: a schema column-add breaks N tests, and the PG/MySQL copies (only run in CI) diverge silently — exactly what broke #3495. Add src/server/test-helpers/testDb.ts: `createTestDb()` runs the REAL SQLite migration registry (baseline 001 + every ALTER) against a fresh `:memory:` database, so each test gets the exact production schema and a schema change is a single edit. Includes a smoke test asserting key tables and recent columns (telemetry.rxSnr from migration 089) are present and a repo round-trip works. Migrate the three SQLite-only telemetry repo tests — the ones whose hand-rolled telemetry DDL had to be patched for #3492/#3495 — to use the helper: telemetry.test.ts, telemetry.extra.test.ts, telemetry.badTimestamp.test.ts. This is part 1: the helper is proven and the most-recently-fragile DDL is gone. The remaining ~37 hand-rolled tables (nodes in ~20 files, etc.) will be migrated incrementally in follow-ups using this now-proven helper. telemetry.multidb.test.ts is intentionally left — it deliberately exercises per-backend DDL. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Claude finished @Yeraze's task —— View job PR Review: refactor(test): shared createTestDb helper from migration registryTasks:
SummaryThis is a well-targeted refactor that solves a real, documented problem. The design is sound and the implementation is clean. A few observations below, ranging from a genuine concern down to minor nits. Concern: Redundant dedupe index in
|
…ument cast claude-pr review on #3498: the 'duplicate packet dedupe' block in telemetry.test.ts still manually created telemetry_source_packet_type_uniq, now dead DDL since createTestDb() applies migration 032. Removed it (test still passes, confirming the index comes from the migration). Also documented the as-any cast in testDb.ts per the review. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Claude finished @Yeraze's task —— View job PR Review: refactor(test): shared createTestDb helper from migration registryTasks:
SummaryThis is a well-structured, correctly motivated refactor. The previous review comment on the redundant dedupe-index Positive highlights
Minor:
|
Section-B refactor #2. Addresses the test-infrastructure fragility the review flagged — the class of bug that broke #3495.
Problem
~40 non-migration test files hand-roll
CREATE TABLEper backend, duplicatingsrc/db/schema/. That DDL drifts from the real schema: a single column-add breaks N tests, and the PG/MySQL copies (only run in CI) diverge silently — which is exactly how the #3495 PostgreSQL test-table gap slipped past local runs.Change
New
src/server/test-helpers/testDb.ts:createTestDb()runs the real SQLite migration registry (baseline 001 + every subsequent ALTER) against a fresh:memory:database, returning{ sqlite, db, close }.src/db/schema/+ its migration, with zero test-DDL to update.testDb.test.ts) asserts key tables exist, recent columns are present (telemetry.rxSnrfrom migration 089), and a repo insert/read round-trip works.Migrated in this PR (part 1)
The three SQLite-only telemetry repo tests whose hand-rolled telemetry DDL had to be patched for #3492/#3495:
telemetry.test.ts,telemetry.extra.test.ts,telemetry.badTimestamp.test.tsThese were clean drop-ins (the helper provides the full telemetry table and the migration-032 dedupe index they were mirroring).
Scope / follow-ups
This is part 1 — it lands the proven helper and removes the most-recently-fragile DDL. The remaining ~37 hand-rolled tables (nodes in ~20 files, etc.) will be migrated incrementally in follow-up PRs (now trivial mechanical changes).
telemetry.multidb.test.tsis intentionally left — it deliberately exercises per-backend DDL.Design notes
registry.getAll()+m.sqlite(db, getSetting, setSetting)path production uses. It does not pre-create asettingsstub (that would block the baseline's full table); the get/set shims are defensive for the brief window beforesettingsexists.Validation
tsc --noEmit: clean🤖 Generated with Claude Code