Files
ruflo/v3/@claude-flow/cli/__tests__/shared-sqlite-host-driver.test.ts
T
Dragan Spiridonov d4458abdff fix(memory,cli): keep the CLI's better-sqlite3 handles on AgentDB's copy
Follow-up to the AgentDB driver change. shared-sqlite.ts (#3693/#3883)
resolved better-sqlite3 from agentdb's location so CLI handles share
AgentDB's native copy. With AgentDB now opened through
@claude-flow/memory's better-sqlite3, that put graph-edge-writer, the
memory-initializer repair paths, backup restore, distillation, tuning and
the attestation log back on agentdb's nested 11.x: `hooks post-task` still
loaded both addons (and aborted on Node 24), and mixing copies on one file
can delete the -wal/-shm sidecars under AgentDB's live handle.

- @claude-flow/memory exports getHostSqliteDriver(), the one source of the
  constructor; useHostSqliteDriver() opens AgentDB with it and reports
  whether it replaced the loader.
- shared-sqlite resolves better-sqlite3 from @claude-flow/memory when the
  installed memory carries agentdb-native-driver.js, else from agentdb as
  before, so either memory version keeps one copy per process.
- @claude-flow/memory 3.0.3, CLI pin 3.0.3 (leaf-publish gate).

Tests: identity between AgentDB's handle constructor and
loadBetterSqlite3(); #3693 owner model for the memory holder and the
pre-3.0.3 fallback; both AgentDB construction sites; routing against a
real nested copy; a drift guard on agentdb's initializeDatabase contract.
2026-10-10 09:44:50 +02:00

37 lines
1.6 KiB
TypeScript

/**
* #3693/#3883 single-copy invariant after @claude-flow/memory started opening
* AgentDB with its own better-sqlite3 (Node 24 Statement-GC abort): the CLI's
* shared loader must hand out the exact constructor AgentDB's handle uses.
*/
import { describe, expect, it } from 'vitest';
import { createRequire } from 'node:module';
import { pathToFileURL } from 'node:url';
const req = createRequire(import.meta.url);
// This package's vitest config externalizes both; import the resolved files natively.
const importInstalled = (name: string): Promise<any> => import(pathToFileURL(req.resolve(name)).href);
describe('shared-sqlite follows @claude-flow/memory getHostSqliteDriver()', () => {
it('resolves the owner to the installed @claude-flow/memory', async () => {
const { resolveSqliteOwnerEntry } = await import('../src/memory/shared-sqlite.js');
expect(resolveSqliteOwnerEntry()).toBe(req.resolve('@claude-flow/memory'));
});
it("loadBetterSqlite3() is the constructor of AgentDB's handle", async () => {
const memory = await importInstalled('@claude-flow/memory');
const { AgentDB } = await importInstalled('agentdb');
const { loadBetterSqlite3 } = await import('../src/memory/shared-sqlite.js');
const agentdb = new AgentDB({ dbPath: ':memory:' });
expect(memory.useHostSqliteDriver(agentdb)).toBe(true);
const handle = await agentdb.initializeDatabase(':memory:');
try {
expect(await loadBetterSqlite3()).toBe(memory.getHostSqliteDriver());
expect(handle.constructor).toBe(await loadBetterSqlite3());
} finally {
handle.close();
}
});
});