From 63ca18bd53f2d2fef878da59e6650bd87ff3ab6e Mon Sep 17 00:00:00 2001 From: Cyrus Date: Thu, 30 Jul 2026 19:53:57 +0800 Subject: [PATCH] test(mnemopi): release prepared statements in file-backed suites Six suites build a real DB under a temp dir and then `rmSync` it in `afterEach`. Each leaked its own one-shot statement the same way the source did, so the teardown hit EBUSY on Windows and failed tests whose assertions had already passed. Only the suites that touch a file-backed DB are changed. The remaining `prepare()` calls in the package tests run against `:memory:`, where there is nothing to unlink and no cleanup to fail. --- packages/mnemopi/test/annotations.test.ts | 3 ++- packages/mnemopi/test/beam-e3-e4-e6.test.ts | 2 +- packages/mnemopi/test/cli-stats-parity.test.ts | 9 ++++++--- packages/mnemopi/test/cli.test.ts | 9 ++++++--- packages/mnemopi/test/diagnose.test.ts | 9 ++++++--- packages/mnemopi/test/recovery.test.ts | 4 ++-- 6 files changed, 23 insertions(+), 13 deletions(-) diff --git a/packages/mnemopi/test/annotations.test.ts b/packages/mnemopi/test/annotations.test.ts index 929c878aa..dad2f4f58 100644 --- a/packages/mnemopi/test/annotations.test.ts +++ b/packages/mnemopi/test/annotations.test.ts @@ -134,7 +134,8 @@ describe("AnnotationStore", () => { try { const store = new AnnotationStore({ conn: db }); store.add("mem-1", "has_source", "custom-tool"); - const rows = db.prepare("SELECT memory_id, kind, value FROM annotations").all() as { + using statement = db.prepare("SELECT memory_id, kind, value FROM annotations"); + const rows = statement.all() as { memory_id: string; kind: string; value: string; diff --git a/packages/mnemopi/test/beam-e3-e4-e6.test.ts b/packages/mnemopi/test/beam-e3-e4-e6.test.ts index d4ae15f09..a1376c012 100644 --- a/packages/mnemopi/test/beam-e3-e4-e6.test.ts +++ b/packages/mnemopi/test/beam-e3-e4-e6.test.ts @@ -33,7 +33,7 @@ function oldTimestamp(): string { } function seedOldWorking(beam: BeamMemory, ids: readonly string[], sessionId = "s1"): void { - const insert = beam.db.prepare( + using insert = beam.db.prepare( "INSERT INTO working_memory (id, content, source, timestamp, session_id, importance, veracity) VALUES (?, ?, ?, ?, ?, ?, ?)", ); for (const [index, id] of ids.entries()) { diff --git a/packages/mnemopi/test/cli-stats-parity.test.ts b/packages/mnemopi/test/cli-stats-parity.test.ts index 9c1f8279e..f9e4a5222 100644 --- a/packages/mnemopi/test/cli-stats-parity.test.ts +++ b/packages/mnemopi/test/cli-stats-parity.test.ts @@ -44,9 +44,12 @@ function seed(dbPath: string): BeamMemory { const memory = new BeamMemory({ sessionId: "stats-parity", dbPath }); const id = memory.remember("Working memory item", { source: "user", importance: 0.5 }); memory.consolidateToEpisodic("Episodic summary", [id], "consolidation", 0.6); - memory.db - .prepare("INSERT INTO triples (subject, predicate, object, source) VALUES (?, ?, ?, ?)") - .run("alice", "likes", "typescript", "test"); + memory.db.run("INSERT INTO triples (subject, predicate, object, source) VALUES (?, ?, ?, ?)", [ + "alice", + "likes", + "typescript", + "test", + ]); return memory; } diff --git a/packages/mnemopi/test/cli.test.ts b/packages/mnemopi/test/cli.test.ts index 1ed467dd9..db3913148 100644 --- a/packages/mnemopi/test/cli.test.ts +++ b/packages/mnemopi/test/cli.test.ts @@ -56,9 +56,12 @@ describe("CLI command handlers", () => { try { const id = memory.remember("Working memory item", { source: "test", importance: 0.5 }); memory.consolidateToEpisodic("Episodic summary", [id], "test", 0.6); - memory.db - .prepare("INSERT INTO triples (subject, predicate, object, source) VALUES (?, ?, ?, ?)") - .run("alice", "likes", "typescript", "test"); + memory.db.run("INSERT INTO triples (subject, predicate, object, source) VALUES (?, ?, ?, ?)", [ + "alice", + "likes", + "typescript", + "test", + ]); } finally { memory.close(); } diff --git a/packages/mnemopi/test/diagnose.test.ts b/packages/mnemopi/test/diagnose.test.ts index 2172952ac..4c496bf57 100644 --- a/packages/mnemopi/test/diagnose.test.ts +++ b/packages/mnemopi/test/diagnose.test.ts @@ -29,9 +29,12 @@ describe("diagnose helpers", () => { const id = memory.remember("Diagnose working row", { source: "test" }); memory.consolidateToEpisodic("Diagnose episodic row", [id], "test", 0.6); memory.scratchpadWrite("diagnose scratchpad row"); - memory.db - .prepare("INSERT INTO triples (subject, predicate, object, source) VALUES (?, ?, ?, ?)") - .run("alice", "uses", "beam", "test"); + memory.db.run("INSERT INTO triples (subject, predicate, object, source) VALUES (?, ?, ?, ?)", [ + "alice", + "uses", + "beam", + "test", + ]); } finally { memory.close(); } diff --git a/packages/mnemopi/test/recovery.test.ts b/packages/mnemopi/test/recovery.test.ts index 54137e919..aff4ec8ee 100644 --- a/packages/mnemopi/test/recovery.test.ts +++ b/packages/mnemopi/test/recovery.test.ts @@ -19,7 +19,7 @@ function createSqliteDb(path: string): void { const db = new Database(path, { create: true, readwrite: true, strict: true }); try { db.exec("CREATE TABLE memories (id INTEGER PRIMARY KEY, content TEXT NOT NULL)"); - db.prepare("INSERT INTO memories (content) VALUES (?)").run("backup me"); + db.run("INSERT INTO memories (content) VALUES (?)", ["backup me"]); } finally { db.close(); } @@ -152,7 +152,7 @@ describe("SQLite recovery helpers", () => { try { db.exec("PRAGMA journal_mode=WAL"); db.exec("CREATE TABLE memories (id INTEGER PRIMARY KEY, content TEXT NOT NULL)"); - db.prepare("INSERT INTO memories (content) VALUES (?)").run("wal protected"); + db.run("INSERT INTO memories (content) VALUES (?)", ["wal protected"]); expect(existsSync(`${dbPath}-wal`)).toBe(true); expect(() => restoreBackup(badBackup, dbPath)).toThrow(/integrity/);