Skip to content

Soul-driven AI agent with permission-hardened tools, token budgets, and multi-channel access. Runs 24/7 from CLI, Telegram or More.

test(memory): close the SQLite file before removing the temp dir (Windows CI)

Salman Qureshi4aadfe39e8fa
diff --git a/src/core/commands/memory-commands.test.ts b/src/core/commands/memory-commands.test.ts
index 38beaf48..27c05630 100644
--- a/src/core/commands/memory-commands.test.ts
+++ b/src/core/commands/memory-commands.test.ts
@@ -21,6 +21,7 @@ import { handleChatCommand } from './chat-command.js';
const sqliteAvailable = isBetterSqlite3Available();
const dirs: string[] = [];
+const dbs: SecondBrainDB[] = [];
const DAY = 86_400_000;
function make(): { store: BeliefStore; deps: BeliefCommandDeps } {
@@ -28,6 +29,7 @@ function make(): { store: BeliefStore; deps: BeliefCommandDeps } {
dirs.push(dir);
const db = new SecondBrainDB(join(dir, 'sb.db'));
db.init();
+ dbs.push(db);
const store = new BeliefStore(db.connection, 'user:owner');
store.init();
return { store, deps: { beliefs: store, listings: new Map(), lastNoted: new Map() } };
@@ -40,7 +42,11 @@ function heldPreference(store: BeliefStore, statement: string, excerpt: string,
return store.get(r.belief.id)!;
}
-afterEach(() => { while (dirs.length) rmSync(dirs.pop()!, { recursive: true, force: true }); });
+// Close before removing: Windows refuses to unlink an open database file.
+afterEach(() => {
+ while (dbs.length) { try { dbs.pop()!.close(); } catch { /* already closed */ } }
+ while (dirs.length) rmSync(dirs.pop()!, { recursive: true, force: true });
+});
describe.skipIf(!sqliteAvailable)('memory commands (ADR-026)', () => {
it('/memory learned lists recent beliefs numbered, with status, confidence, age and excerpt', () => {
diff --git a/src/learning/reflection.test.ts b/src/learning/reflection.test.ts
index 0dcd561c..10fec91b 100644
--- a/src/learning/reflection.test.ts
+++ b/src/learning/reflection.test.ts
@@ -13,6 +13,7 @@ import { buildOwnerSections, createOwnerSectionsMemo, parseOwnerNotes, readStore
const sqliteAvailable = isBetterSqlite3Available();
const dirs: string[] = [];
+const dbs: SecondBrainDB[] = [];
const T0 = Date.UTC(2026, 9, 20, 9, 0, 0); // 2026-10-20 09:00 UTC
const HOUR = 3_600_000;
@@ -25,12 +26,17 @@ function tmp(prefix: string): string {
function makeStore(): BeliefStore {
const db = new SecondBrainDB(join(tmp('mercury-reflection-'), 'sb.db'));
db.init();
+ dbs.push(db);
const store = new BeliefStore(db.connection, 'user:owner');
store.init();
return store;
}
-afterEach(() => { while (dirs.length) rmSync(dirs.pop()!, { recursive: true, force: true }); });
+// Close before removing: Windows refuses to unlink an open database file.
+afterEach(() => {
+ while (dbs.length) { try { dbs.pop()!.close(); } catch { /* already closed */ } }
+ while (dirs.length) rmSync(dirs.pop()!, { recursive: true, force: true });
+});
let seq = 0;
function msg(sessionId: string, role: SessionMessage['role'], content: string, at: number, extra: Partial<SessionMessage> = {}): SessionMessage {
diff --git a/src/memory/beliefs.test.ts b/src/memory/beliefs.test.ts
index de6b4ce7..e2f7c9a4 100644
--- a/src/memory/beliefs.test.ts
+++ b/src/memory/beliefs.test.ts
@@ -7,6 +7,7 @@ import { BeliefStore, RETIRE_BELOW, ftsMatch, isLegacyJunk } from './beliefs.js'
const sqliteAvailable = isBetterSqlite3Available();
const dirs: string[] = [];
+const dbs: SecondBrainDB[] = [];
const DAY = 86_400_000;
function make(): { store: BeliefStore; db: SecondBrainDB } {
@@ -14,12 +15,17 @@ function make(): { store: BeliefStore; db: SecondBrainDB } {
dirs.push(dir);
const db = new SecondBrainDB(join(dir, 'sb.db'));
db.init();
+ dbs.push(db);
const store = new BeliefStore(db.connection, 'user:owner');
store.init();
return { store, db };
}
-afterEach(() => { while (dirs.length) rmSync(dirs.pop()!, { recursive: true, force: true }); });
+// Close before removing: Windows refuses to unlink an open database file.
+afterEach(() => {
+ while (dbs.length) { try { dbs.pop()!.close(); } catch { /* already closed */ } }
+ while (dirs.length) rmSync(dirs.pop()!, { recursive: true, force: true });
+});
describe.skipIf(!sqliteAvailable)('BeliefStore', () => {
it('a belief starts as a candidate and is held after support from two sessions', () => {