test(core,dashboard): expand in-memory SQLite to more store tests

Extends the inMemoryDb opt-in established in 4fc58e0bb to single-instance
TaskStore/AgentStore/RoutineStore/PluginStore tests that were still
opening disk-backed fusion.db files. Cross-instance persistence tests
(open store A, close, open store B on same dir) and migration tests that
seed via a sibling Database instance keep their disk-backed stores —
swapping those would silently drop data between instances.

Sites flipped:
- core: store.test.ts (RunMutationContext, memory-toggle, diagnostics
  blocks), store-sort, settings-export, backup, plugin-loader,
  agent-instructions, agent-instructions-bundle, mission-store (all 10
  triage subtests), mission-planning-context.integration
- dashboard: routes.test.ts (Messaging routes block),
  session-reconnect, session-cross-tab, planning

Sites left disk-backed (cross-instance or sibling-Database dependency):
- run-audit*, task-documents, fts5-guard (sibling Database at same dir)
- mission-integration, mission-factory-parity (taskStore2 reopens)
- agent-store checkout-leasing (TaskStore + AgentStore at same dir)
- routes.test.ts AgentStore seed pattern (route handler opens its own)
- cli/extension.test.ts (makeCtx opens its own TaskStore)

All disk-backed tests continue to write to mkdtemp temp dirs — no live-db
risk introduced. Wall-clock impact: core 149s → 19s.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
gsxdsm
2026-04-26 20:56:31 -07:00
parent 4ccc8aed11
commit 330545d45c
13 changed files with 32 additions and 32 deletions

View File

@@ -11,7 +11,7 @@ describe("AgentStore — instructions bundle", () => {
beforeEach(async () => {
testDir = await mkdtemp(join(tmpdir(), "agent-instructions-bundle-test-"));
store = new AgentStore({ rootDir: testDir });
store = new AgentStore({ rootDir: testDir, inMemoryDb: true });
await store.init();
});

View File

@@ -11,7 +11,7 @@ describe("AgentStore — instructions fields", () => {
beforeEach(async () => {
testDir = await mkdtemp(join(tmpdir(), "agent-instructions-test-"));
store = new AgentStore({ rootDir: testDir });
store = new AgentStore({ rootDir: testDir, inMemoryDb: true });
await store.init();
});

View File

@@ -455,7 +455,7 @@ describe("syncBackupRoutine", () => {
beforeEach(async () => {
vi.useRealTimers();
tempDir = mkdtempSync(join(tmpdir(), "kb-backup-routine-test-"));
routineStore = new RoutineStore(tempDir);
routineStore = new RoutineStore(tempDir, { inMemoryDb: true });
await routineStore.init();
});

View File

@@ -28,7 +28,7 @@ describe("MissionStore planning context integration", () => {
vi.setSystemTime(new Date("2026-04-01T00:00:00.000Z"));
rootDir = makeTmpDir();
taskStore = new TaskStore(rootDir, join(rootDir, ".fusion-global-settings"));
taskStore = new TaskStore(rootDir, join(rootDir, ".fusion-global-settings"), { inMemoryDb: true });
await taskStore.init();
});

View File

@@ -1664,7 +1664,7 @@ describe("MissionStore", () => {
it("throws if feature not found", async () => {
// Need a TaskStore reference for this test
const { TaskStore } = await import("../store.js");
const ts = new TaskStore(fusionDir, join(fusionDir, ".fusion-global-settings"));
const ts = new TaskStore(fusionDir, join(fusionDir, ".fusion-global-settings"), { inMemoryDb: true });
const msWithTs = ts.getMissionStore();
await expect(msWithTs.triageFeature("F-NONEXISTENT")).rejects.toThrow(
@@ -1674,7 +1674,7 @@ describe("MissionStore", () => {
it("throws if feature is already triaged", async () => {
const { TaskStore } = await import("../store.js");
const ts = new TaskStore(fusionDir, join(fusionDir, ".fusion-global-settings"));
const ts = new TaskStore(fusionDir, join(fusionDir, ".fusion-global-settings"), { inMemoryDb: true });
const msWithTs = ts.getMissionStore();
const mission = msWithTs.createMission({ title: "Mission" });
@@ -1694,7 +1694,7 @@ describe("MissionStore", () => {
it("creates a task and links it to the feature", async () => {
const { TaskStore } = await import("../store.js");
const ts = new TaskStore(fusionDir, join(fusionDir, ".fusion-global-settings"));
const ts = new TaskStore(fusionDir, join(fusionDir, ".fusion-global-settings"), { inMemoryDb: true });
const msWithTs = ts.getMissionStore();
const mission = msWithTs.createMission({ title: "Mission" });
@@ -1726,7 +1726,7 @@ describe("MissionStore", () => {
it("uses provided title and description overrides", async () => {
const { TaskStore } = await import("../store.js");
const ts = new TaskStore(fusionDir, join(fusionDir, ".fusion-global-settings"));
const ts = new TaskStore(fusionDir, join(fusionDir, ".fusion-global-settings"), { inMemoryDb: true });
const msWithTs = ts.getMissionStore();
const mission = msWithTs.createMission({ title: "Mission" });
@@ -1747,7 +1747,7 @@ describe("MissionStore", () => {
it("emits feature:linked event", async () => {
const { TaskStore } = await import("../store.js");
const ts = new TaskStore(fusionDir, join(fusionDir, ".fusion-global-settings"));
const ts = new TaskStore(fusionDir, join(fusionDir, ".fusion-global-settings"), { inMemoryDb: true });
const msWithTs = ts.getMissionStore();
const linkedHandler = vi.fn();
@@ -1782,7 +1782,7 @@ describe("MissionStore", () => {
it("throws if slice not found", async () => {
const { TaskStore } = await import("../store.js");
const ts = new TaskStore(fusionDir, join(fusionDir, ".fusion-global-settings"));
const ts = new TaskStore(fusionDir, join(fusionDir, ".fusion-global-settings"), { inMemoryDb: true });
const msWithTs = ts.getMissionStore();
await expect(msWithTs.triageSlice("SL-NONEXISTENT")).rejects.toThrow(
@@ -1792,7 +1792,7 @@ describe("MissionStore", () => {
it("triages all defined features in a slice", async () => {
const { TaskStore } = await import("../store.js");
const ts = new TaskStore(fusionDir, join(fusionDir, ".fusion-global-settings"));
const ts = new TaskStore(fusionDir, join(fusionDir, ".fusion-global-settings"), { inMemoryDb: true });
const msWithTs = ts.getMissionStore();
const mission = msWithTs.createMission({ title: "Mission" });
@@ -1819,7 +1819,7 @@ describe("MissionStore", () => {
it("skips already triaged features", async () => {
const { TaskStore } = await import("../store.js");
const ts = new TaskStore(fusionDir, join(fusionDir, ".fusion-global-settings"));
const ts = new TaskStore(fusionDir, join(fusionDir, ".fusion-global-settings"), { inMemoryDb: true });
const msWithTs = ts.getMissionStore();
const mission = msWithTs.createMission({ title: "Mission" });
@@ -1841,7 +1841,7 @@ describe("MissionStore", () => {
it("returns empty array if no defined features", async () => {
const { TaskStore } = await import("../store.js");
const ts = new TaskStore(fusionDir, join(fusionDir, ".fusion-global-settings"));
const ts = new TaskStore(fusionDir, join(fusionDir, ".fusion-global-settings"), { inMemoryDb: true });
const msWithTs = ts.getMissionStore();
const mission = msWithTs.createMission({ title: "Mission" });
@@ -1862,7 +1862,7 @@ describe("MissionStore", () => {
ms: MissionStore;
}> {
const { TaskStore } = await import("../store.js");
const ts = new TaskStore(fusionDir, join(fusionDir, ".fusion-global-settings"));
const ts = new TaskStore(fusionDir, join(fusionDir, ".fusion-global-settings"), { inMemoryDb: true });
const ms = ts.getMissionStore();
return { ts, ms };
}

View File

@@ -146,7 +146,7 @@ describe("PluginLoader", () => {
beforeEach(() => {
rootDir = makeTmpDir();
pluginStore = new PluginStore(rootDir);
pluginStore = new PluginStore(rootDir, { inMemoryDb: true });
});
afterEach(async () => {

View File

@@ -58,7 +58,7 @@ describe("settings-export", () => {
beforeEach(async () => {
env = createTestEnv();
const { TaskStore } = await import("../store.js");
store = new TaskStore(env.tempDir, env.globalSettingsDir);
store = new TaskStore(env.tempDir, env.globalSettingsDir, { inMemoryDb: true });
await store.init();
});

View File

@@ -16,7 +16,7 @@ describe("TaskStore.listTasks() sort order", () => {
beforeEach(async () => {
rootDir = makeTmpDir();
store = new TaskStore(rootDir, join(rootDir, ".fusion-global-settings"));
store = new TaskStore(rootDir, join(rootDir, ".fusion-global-settings"), { inMemoryDb: true });
await store.init();
});

View File

@@ -8990,7 +8990,7 @@ Task with acceptance criteria
let localStore: TaskStore | undefined;
try {
localStore = new TaskStore(localRoot, localGlobal);
localStore = new TaskStore(localRoot, localGlobal, { inMemoryDb: true });
(localStore as any).configPath = join(localRoot, ".fusion", "missing-dir", "config.json");
await expect(localStore.init()).resolves.toBeUndefined();
@@ -9085,7 +9085,7 @@ Task with acceptance criteria
let localStore: TaskStore | undefined;
try {
localStore = new TaskStore(localRoot, localGlobal);
localStore = new TaskStore(localRoot, localGlobal, { inMemoryDb: true });
await expect(localStore.init()).resolves.toBeUndefined();
const warningCall = warnSpy.mock.calls.find(
@@ -9540,7 +9540,7 @@ Task with acceptance criteria
const localGlobal = makeTmpDir();
let localStore: TaskStore | undefined;
try {
localStore = new TaskStore(localRoot, localGlobal);
localStore = new TaskStore(localRoot, localGlobal, { inMemoryDb: true });
await localStore.init();
await localStore.updateSettings({ memoryEnabled: false } as any);
@@ -9568,7 +9568,7 @@ Task with acceptance criteria
const localGlobal = makeTmpDir();
let localStore: TaskStore | undefined;
try {
localStore = new TaskStore(localRoot, localGlobal);
localStore = new TaskStore(localRoot, localGlobal, { inMemoryDb: true });
await localStore.init();
const memoryPath = join(localRoot, ".fusion", "memory", "MEMORY.md");
@@ -9765,7 +9765,7 @@ describe("RunMutationContext", () => {
const localRoot = makeTmpDir();
const localGlobal = makeTmpDir();
try {
const localStore = new TaskStore(localRoot, localGlobal);
const localStore = new TaskStore(localRoot, localGlobal, { inMemoryDb: true });
await localStore.init();
const task = await localStore.createTask({ description: "Test task" });
@@ -9793,7 +9793,7 @@ describe("RunMutationContext", () => {
const localRoot = makeTmpDir();
const localGlobal = makeTmpDir();
try {
const localStore = new TaskStore(localRoot, localGlobal);
const localStore = new TaskStore(localRoot, localGlobal, { inMemoryDb: true });
await localStore.init();
const task = await localStore.createTask({ description: "Test task" });
@@ -9847,7 +9847,7 @@ describe("RunMutationContext", () => {
const localRoot = makeTmpDir();
const localGlobal = makeTmpDir();
try {
const localStore = new TaskStore(localRoot, localGlobal);
const localStore = new TaskStore(localRoot, localGlobal, { inMemoryDb: true });
await localStore.init();
const task = await localStore.createTask({ description: "Test task" });
@@ -9875,7 +9875,7 @@ describe("RunMutationContext", () => {
const localRoot = makeTmpDir();
const localGlobal = makeTmpDir();
try {
const localStore = new TaskStore(localRoot, localGlobal);
const localStore = new TaskStore(localRoot, localGlobal, { inMemoryDb: true });
await localStore.init();
const task = await localStore.createTask({ description: "Test task" });
@@ -9903,7 +9903,7 @@ describe("RunMutationContext", () => {
const localRoot = makeTmpDir();
const localGlobal = makeTmpDir();
try {
const localStore = new TaskStore(localRoot, localGlobal);
const localStore = new TaskStore(localRoot, localGlobal, { inMemoryDb: true });
await localStore.init();
const task1 = await localStore.createTask({ description: "Task 1" });
@@ -9934,7 +9934,7 @@ describe("RunMutationContext", () => {
const localRoot = makeTmpDir();
const localGlobal = makeTmpDir();
try {
const localStore = new TaskStore(localRoot, localGlobal);
const localStore = new TaskStore(localRoot, localGlobal, { inMemoryDb: true });
await localStore.init();
const task = await localStore.createTask({ description: "Test task" });
@@ -9955,7 +9955,7 @@ describe("RunMutationContext", () => {
const localRoot = makeTmpDir();
const localGlobal = makeTmpDir();
try {
const localStore = new TaskStore(localRoot, localGlobal);
const localStore = new TaskStore(localRoot, localGlobal, { inMemoryDb: true });
await localStore.init();
const task1 = await localStore.createTask({ description: "Task 1" });

View File

@@ -2087,7 +2087,7 @@ describe("planning routes lock enforcement", () => {
setupMockAgent();
tmpRoot = mkdtempSync(join(tmpdir(), "kb-planning-lock-routes-"));
taskStore = new TaskStore(tmpRoot, join(tmpRoot, ".fusion-global-settings"));
taskStore = new TaskStore(tmpRoot, join(tmpRoot, ".fusion-global-settings"), { inMemoryDb: true });
await taskStore.init();
db = new Database(join(tmpRoot, ".fusion-locks"));

View File

@@ -17172,7 +17172,7 @@ describe("Messaging Routes", () => {
rootDir = mkdtempSync(join(tmpdir(), "kb-message-routes-"));
const { TaskStore, MessageStore } = await import("@fusion/core");
store = new TaskStore(rootDir, join(rootDir, ".fusion-global-settings"));
store = new TaskStore(rootDir, join(rootDir, ".fusion-global-settings"), { inMemoryDb: true });
await store.init();
messageStore = new MessageStore(store.getDatabase());

View File

@@ -46,7 +46,7 @@ describe("cross-tab session locking", () => {
beforeEach(async () => {
tmpRoot = mkdtempSync(join(tmpdir(), "kb-session-cross-tab-"));
taskStore = new TaskStore(tmpRoot, join(tmpRoot, ".fusion-global-settings"));
taskStore = new TaskStore(tmpRoot, join(tmpRoot, ".fusion-global-settings"), { inMemoryDb: true });
await taskStore.init();
aiSessionStore = new AiSessionStore(taskStore.getDatabase());

View File

@@ -91,7 +91,7 @@ describe("session reconnect + replay", () => {
__resetMissionInterviewState();
tmpRoot = mkdtempSync(join(tmpdir(), "kb-session-reconnect-"));
store = new TaskStore(tmpRoot, join(tmpRoot, ".fusion-global-settings"));
store = new TaskStore(tmpRoot, join(tmpRoot, ".fusion-global-settings"), { inMemoryDb: true });
await store.init();
aiSessionStore = new AiSessionStore(store.getDatabase());