fix(ci): graph schema smoke — checkpoint WAL before sql.js re-read

The smoke test asserts (a) the writer (better-sqlite3) succeeds and then
(b) re-reads the DB file via sql.js to verify the insert/migration landed.
Since #2431 put the writer in WAL mode (\`journal_mode = WAL\`), inserts
sit in the \`.db-wal\` sidecar until checkpointed; sql.js reads only the
main file and saw nothing. Symptoms: tests 2c, 3b, 5b all asserted false
even though tests 2a, 3a, 5a confirmed the writer succeeded.

Closing the writer connection (\`_resetBridgeDb\` calls
\`better-sqlite3.close()\`, which checkpoints WAL by default) before
each sql.js readback unblocks the verification. This is a smoke-script
bug surfaced by the Build V3 unblock — pre-3.14.2 the build broke before
this code ran, so the latent WAL incompatibility never tripped CI.

Local: 23/23 pass (was 18/23 with 4 WAL-related fails + 1 cascade).

Co-Authored-By: RuFlo <ruv@ruv.net>
This commit is contained in:
ruv
2026-06-25 18:32:28 -04:00
parent 3cce463e19
commit 3f1747a527
+16
View File
@@ -128,6 +128,13 @@ async function testEdgeInsert() {
const count = await countGraphEdges(dbPath);
assert(count === 1, `2b: graph_edges has 1 row (found ${count})`);
// Close the better-sqlite3 connection so its WAL is checkpointed back
// into the main DB file before we re-read via sql.js (#2431 added WAL
// mode for cross-connection safety; without this checkpoint, sql.js
// sees only the pre-insert main file and the inserted rows live in
// the .db-wal sidecar).
_resetBridgeDb();
// Verify embedding_ref is inline-encoded
const SQL = await loadSqlJs();
const fileBuffer = fs.readFileSync(dbPath);
@@ -173,6 +180,9 @@ async function testLegacyIdPrefix() {
});
assert(ok, '3a: insertGraphEdge with mem:-prefixed IDs succeeds');
// Checkpoint WAL → main DB before re-reading via sql.js (#2431).
_resetBridgeDb();
// Verify row exists with the prefixed IDs
const SQL = await loadSqlJs();
const fileBuffer = fs.readFileSync(dbPath);
@@ -262,6 +272,12 @@ async function testTableAutoCreate() {
});
assert(ok, '5a: insertGraphEdge succeeds on DB without graph_edges');
// Checkpoint WAL → main DB before re-reading via sql.js (#2431).
// Without this, sql.js sees only the pre-insert main file (just
// memory_entries) and the auto-created graph_edges table sits in
// the .db-wal sidecar, failing assertion 5b.
_resetBridgeDb();
// Verify table was created
const fileBuffer = fs.readFileSync(oldDbPath);
const dbCheck = new SQL.Database(fileBuffer);