test(storage): integration test for migrate-tier PGlite → federated PG (FED-M1-08)
All checks were successful
ci/woodpecker/push/ci Pipeline was successful
ci/woodpecker/pr/ci Pipeline was successful

Seeds a temp PGlite with representative cross-table data (users, teams,
team_members, conversations, messages), runs mosaic storage migrate-tier
against a live federated PG+pgvector profile, asserts exact row counts and
spot-checks key columns. Gated by FEDERATED_INTEGRATION=1.

Caught and fixed P0 bug in migrate-tier:

  PostgresMigrationTarget passed Drizzle-selected camelCase keys
  (emailVerified, userId, ...) verbatim as SQL identifiers, failing on
  Postgres which expects snake_case. The 32 unit tests missed this because
  both source and target were mocked. normaliseSourceRow now applies
  toSnakeCase conversion that is idempotent on already-snake_case keys.

Test infrastructure:

- packages/storage/src/test-utils/pglite-with-vector.ts: PGlite +
  @electric-sql/pglite/vector (JS-native pgvector) and migration runner.
  Co-located with storage tests rather than exposed on @mosaicstack/db
  public surface (would have polluted prod consumers with WASM bundle).
- packages/storage now declared "type": "module" (codebase convention,
  required for import.meta.url in test-utils).

afterAll cleanup deletes prefix-namespaced rows even on test panic.

Refs #460
This commit is contained in:
Jarvis
2026-04-19 20:39:11 -05:00
parent 78251d4af8
commit efdbb13ab4
6 changed files with 452 additions and 7 deletions

View File

@@ -6,6 +6,7 @@
"url": "https://git.mosaicstack.dev/mosaicstack/stack.git",
"directory": "packages/storage"
},
"type": "module",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"exports": {
@@ -29,6 +30,7 @@
"postgres": "^3.4.8"
},
"devDependencies": {
"drizzle-orm": "^0.45.1",
"typescript": "^5.8.0",
"vitest": "^2.0.0"
},