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.
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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()) {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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/);
|
||||
|
||||
Reference in New Issue
Block a user