openvibers/openvibe.sdk Commits

Load test databases from a migrated PGlite snapshot in createTestDb (#12)

OP OpenVibers committed 5 Oct 2026 · tag v0.29. · 0 files, +0 −0

* Load test databases from a migrated PGlite snapshot in createTestDb

Asked: Part of a cross-repository initiative (init-every-service-repository-s-f-1005T0017): Every service repository's full verify (test and test-pg) finishes in 10 minutes or less on this machine, starting with OpenVibe.Network (34 min now against a 20-min check limit). When done: ds-observe.js measures …
Harness job init-every-service-re-0017-s3-002045.

* Refresh migration ages on a snapshot hit and fix the review's findings

All findings verified and fixed. Summary:

**Finding 1 — contract migrations become eligible ~7 days after a snapshot is built: fixed.** `src/testing/db.js:160` now runs `UPDATE ov_migrations SET applied_at = now()` on a hit, before the behind-check, so a loaded snapshot looks freshly migrated and an ADR-028 contract stays held as it would on a fresh migrate. Regression test at `test/testing-db.test.js:163` (ages the expand in the snapshot via the seed, then asserts on a hit that the contract is not applied). Verified it fails without the fix (`contracted` was created).

**Finding 2 — `seedKey` alone collides with `seedKey` + `seed`: fixed.** `src/testing/db.js:95` now gates on `seed` first (`seed ? (seedKey ? key:… : fn:…) : 'none'`). Test at `test/testing-db.test.js:151` asserts the keys differ and that a seeded call is not served the unseeded snapshot. Verified it fails without the fix.

**Finding 3 — the lock's cross-process path is untested: fixed (test only).** The `takeLock` live-other-pid/wait path was correct; it had no coverage. `test/testing-db.test.js:84` forks a child that builds the same key (holding the lock through a slow seed) while this process waits and loads its file, asserting `hit`, that it waited rather than double-built, and that no lock/tmp file is left. No source change was needed.

**Finding 4 — `seed` has owner rights on PGlite but DML-only rights on pg: fixed.** `src/testing/db.js:251-257` now runs the pg seed on the owner connection (`OV_TEST_PG_DIRECT_URL`), matching PGlite, so owner-only ops (DDL, `TRUNCATE`, `ALTER SEQUENCE … RESTART`) behave the same on both stores. Documentation updated (`types/testing.d.ts:172`, module comment, CHANGELOG). Test added under `pgAvailable()` using `ALTER SEQUENCE … RESTART`; it is skipped in this checkout (no `OV_TEST_PG_URL`).

**Minor notes — not addressed (advisory, non-blocking).** The `snapshotDir` trust/umask and `pruneSnapshots`-on-a-user-supplied-dir remarks are hardening suggestions, not correctness bugs: `OV_TEST_SNAPSHOT_DIR` is by contract a dedicated snapshot directory, and the recommended `mode: 0o700` only applies at creation (it cannot re-secure a pre-existing directory), so I left the snapshot code unchanged rather than add unrelated behavior.

**Test results**
- All 13 cases in `test/testing-db.test.js` pass, including the three new tests (the pg-only case is skipped without containers, as the file already does).
- `ov test`: `21 passed, 12 skipped (unchanged since green) in 264 s`; `test/testing-db.test.js` ran (79.1 s) and passed. The pg-conditional seed test was not executed here because `OV_TEST_PG_URL`/`OV_TEST_PG_DIRECT_URL` are unset.

* Stop tracking the node_modules link and ignore it as a link too

* Pin openvibe-contracts v0.97.0 (the pin-drift check allows at most 10 minors behind)

* Re-copy the identity.service-token-claims types from openvibe-contracts v0.97.0

This commit has no diff to show.