perf(core): opt-in in-memory SQLite for *-store tests

Adds an opt-in `inMemory` flag to `Database`/`ArchiveDatabase` (and
`{ inMemoryDb }` to TaskStore, AgentStore, RoutineStore,
AutomationStore, PluginStore) that swaps the on-disk fusion.db /
archive.db for SQLite's `:memory:` connection. Production callers
never set the flag, so behavior is unchanged.

Test files for each store now flip the flag in `beforeEach`. The
handful of tests that exercise cross-instance persistence (open store
A, close, open store B on same dir, expect data) construct disk-backed
stores explicitly inside the test body, marked with a comment at each
site.

Wall-clock impact:
- core:      69.4s → 18.5s  (3.7× faster, 3038 tests)
- dashboard: 156.6s → 30.0s (5.2× faster — improvement ripples through
                              any test that constructs a TaskStore)

The refactor eliminates the per-test SQLite open + WAL fsync + tmp
dir cleanup loop that dominated setup cost: ~50ms/test → ~5ms/test.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
gsxdsm
2026-04-26 18:45:14 -07:00
parent e2bc644fd5
commit 6e4797ff14
17 changed files with 179 additions and 34 deletions

View File

@@ -67,8 +67,11 @@ export class RoutineStore extends EventEmitter<RoutineStoreEvents> {
/** Per-routine promise chain for serializing writes. */
private routineLocks: Map<string, Promise<void>> = new Map();
constructor(private rootDir: string) {
private readonly inMemoryDb: boolean;
constructor(private rootDir: string, options?: { inMemoryDb?: boolean }) {
super();
this.inMemoryDb = options?.inMemoryDb === true;
}
// ── Database Access ────────────────────────────────────────────────
@@ -79,7 +82,7 @@ export class RoutineStore extends EventEmitter<RoutineStoreEvents> {
private get db(): Database {
if (!this._db) {
const fusionDir = `${this.rootDir}/.fusion`;
this._db = new Database(fusionDir);
this._db = new Database(fusionDir, { inMemory: this.inMemoryDb });
this._db.init();
}
return this._db;