test(server): drop tests of the legacy memory engine (P1.5)
- harvest-provenance: tested the removed harvest pipeline (RawArchive and frame metadata), which no longer exists. - benchmarks: drop the FTS5 frame search and frame/session write benchmarks; they measured the legacy engine only.
This commit is contained in:
@@ -1,130 +0,0 @@
|
|||||||
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
|
||||||
import { MindDB, FrameStore, SessionStore, RawArchive, readArchiveUids, withArchiveUid } from '@waggle/core';
|
|
||||||
|
|
||||||
interface HItem { source: string; id: string; title: string; content: string }
|
|
||||||
|
|
||||||
// Faithfully mirrors the harvest route's per-item persistence: archive the full
|
|
||||||
// verbatim (best-effort try/catch), create the (truncated) summary frame, then
|
|
||||||
// stamp metadata.archiveUids — with the dedup/backfill else-if from the route.
|
|
||||||
function persistHarvestItem(db: MindDB, item: HItem, archive: RawArchive = new RawArchive(db)) {
|
|
||||||
const frames = new FrameStore(db);
|
|
||||||
let archiveUid: string | undefined;
|
|
||||||
try {
|
|
||||||
archiveUid = archive.append({
|
|
||||||
source: item.source, sourceRef: item.id, title: item.title, content: item.content,
|
|
||||||
}).archiveUid;
|
|
||||||
} catch { /* best-effort — frame still persists without the link */ }
|
|
||||||
const frame = frames.createIFrame('harvest', `${item.title}\n\n${item.content.slice(0, 10_000)}`, 'normal', 'import');
|
|
||||||
if (!frame.metadata || frame.metadata === '{}') {
|
|
||||||
frames.setMetadata(frame.id, JSON.stringify({ status: 'unreviewed', sourceId: item.id, ...(archiveUid ? { archiveUids: [archiveUid] } : {}) }));
|
|
||||||
} else if (archiveUid) {
|
|
||||||
const meta = JSON.parse(frame.metadata) as Record<string, unknown>;
|
|
||||||
if (!readArchiveUids(meta).includes(archiveUid)) {
|
|
||||||
frames.setMetadata(frame.id, JSON.stringify(withArchiveUid(meta, archiveUid)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return { archive, frame: frames.getById(frame.id)! };
|
|
||||||
}
|
|
||||||
|
|
||||||
describe('harvest provenance archive', () => {
|
|
||||||
let db: MindDB;
|
|
||||||
beforeEach(() => {
|
|
||||||
db = new MindDB(':memory:');
|
|
||||||
new SessionStore(db).ensure('harvest', 'harvest', 'test');
|
|
||||||
});
|
|
||||||
afterEach(() => { db.close(); });
|
|
||||||
|
|
||||||
it('a harvested frame links to its full immutable raw_archive row', () => {
|
|
||||||
const big = 'A'.repeat(25_000);
|
|
||||||
const { archive, frame } = persistHarvestItem(db, { source: 'claude', id: 'c1', title: 'T', content: big });
|
|
||||||
const rows = archive.reconstructSource(frame.id);
|
|
||||||
expect(rows).toHaveLength(1);
|
|
||||||
expect(rows[0].content.length).toBe(25_000); // full source survived (frame is capped at 10K)
|
|
||||||
expect(frame.content.length).toBeLessThanOrEqual(10_000 + 4);
|
|
||||||
// canonical link shape is the archiveUids array (no legacy scalar)
|
|
||||||
const meta = JSON.parse(frame.metadata ?? '{}') as { archiveUids?: string[]; archiveUid?: string };
|
|
||||||
expect(meta.archiveUids).toHaveLength(1);
|
|
||||||
expect(meta.archiveUid).toBeUndefined();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('re-importing the same item does not duplicate the archive row', () => {
|
|
||||||
const item = { source: 'claude', id: 'c2', title: 'T', content: 'same content' };
|
|
||||||
const { archive } = persistHarvestItem(db, item);
|
|
||||||
persistHarvestItem(db, item);
|
|
||||||
expect(archive.count()).toBe(1);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('a failed archive append still persists the frame, without an archiveUid link', () => {
|
|
||||||
const archive = new RawArchive(db);
|
|
||||||
archive.append = () => { throw new Error('boom'); };
|
|
||||||
const { frame } = persistHarvestItem(db, { source: 'claude', id: 'c3', title: 'T', content: 'body' }, archive);
|
|
||||||
expect(frame.id).toBeGreaterThan(0);
|
|
||||||
const meta = JSON.parse(frame.metadata ?? '{}');
|
|
||||||
expect(meta.archiveUids).toBeUndefined();
|
|
||||||
expect(meta.archiveUid).toBeUndefined();
|
|
||||||
expect(meta.sourceId).toBe('c3');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('backfills archiveUid on a re-import after a prior append failure', () => {
|
|
||||||
// First import: archive append throws → frame persists without a link.
|
|
||||||
const failing = new RawArchive(db);
|
|
||||||
failing.append = () => { throw new Error('boom'); };
|
|
||||||
persistHarvestItem(db, { source: 'claude', id: 'c4', title: 'T', content: 'recoverable' }, failing);
|
|
||||||
|
|
||||||
// Second import (working archive): createIFrame dedups → same frame; the
|
|
||||||
// else-if backfill adds archiveUid without clobbering the existing sourceId.
|
|
||||||
const working = new RawArchive(db);
|
|
||||||
const { frame } = persistHarvestItem(db, { source: 'claude', id: 'c4', title: 'T', content: 'recoverable' }, working);
|
|
||||||
const meta = JSON.parse(frame.metadata ?? '{}');
|
|
||||||
expect(meta.archiveUids).toHaveLength(1);
|
|
||||||
expect(typeof meta.archiveUids[0]).toBe('string');
|
|
||||||
expect(meta.sourceId).toBe('c4');
|
|
||||||
const rows = working.reconstructSource(frame.id);
|
|
||||||
expect(rows).toHaveLength(1);
|
|
||||||
expect(rows[0].content).toBe('recoverable');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('accumulates both uids on one frame when identical content arrives from two sourceRefs', () => {
|
|
||||||
// Same source + same content (→ content-dedup to ONE frame) but different
|
|
||||||
// sourceRef → two distinct per-source archive rows. Both uids must end up on
|
|
||||||
// the single frame's archiveUids array (backfill grows the set).
|
|
||||||
const archive = new RawArchive(db);
|
|
||||||
const { frame: f1 } = persistHarvestItem(db, { source: 'claude', id: 'ref-a', title: 'T', content: 'shared body' }, archive);
|
|
||||||
const { frame: f2 } = persistHarvestItem(db, { source: 'claude', id: 'ref-b', title: 'T', content: 'shared body' }, archive);
|
|
||||||
|
|
||||||
expect(f2.id).toBe(f1.id); // content-dedup → one frame
|
|
||||||
expect(archive.count()).toBe(2); // two per-source archive rows
|
|
||||||
|
|
||||||
const meta = JSON.parse(f2.metadata ?? '{}') as { archiveUids?: string[]; archiveUid?: string };
|
|
||||||
expect(meta.archiveUids).toHaveLength(2);
|
|
||||||
expect(new Set(meta.archiveUids)).toHaveProperty('size', 2);
|
|
||||||
expect(meta.archiveUid).toBeUndefined(); // no legacy scalar lingering
|
|
||||||
|
|
||||||
const rows = archive.reconstructSource(f2.id);
|
|
||||||
expect(rows).toHaveLength(2);
|
|
||||||
expect(new Set(rows.map(r => r.source_ref))).toEqual(new Set(['ref-a', 'ref-b']));
|
|
||||||
});
|
|
||||||
|
|
||||||
// (e) pins the `.includes(archiveUid)` grow-check skip-path: re-importing an
|
|
||||||
// IDENTICAL item must not duplicate the archive row NOR grow archiveUids beyond
|
|
||||||
// length 1. The existing "does not duplicate the archive row" test only asserts
|
|
||||||
// the row count; this test additionally pins uid-array cardinality and
|
|
||||||
// reconstructSource resolution.
|
|
||||||
it('idempotent backfill: re-importing the same item does not grow archiveUids or the archive row count', () => {
|
|
||||||
const archive = new RawArchive(db);
|
|
||||||
const item = { source: 'claude', id: 'idem-1', title: 'T', content: 'idem content' };
|
|
||||||
|
|
||||||
// First import: creates archive row + frame, stamps archiveUids: [uid].
|
|
||||||
const { frame: f1 } = persistHarvestItem(db, item, archive);
|
|
||||||
// Second import of the IDENTICAL item: archive.append is a no-op (INSERT OR IGNORE);
|
|
||||||
// createIFrame deduplicates; the grow-check skips setMetadata because the uid is
|
|
||||||
// already in archiveUids.
|
|
||||||
const { frame: f2 } = persistHarvestItem(db, item, archive);
|
|
||||||
|
|
||||||
expect(f2.id).toBe(f1.id); // same frame (content dedup)
|
|
||||||
expect(archive.count()).toBe(1); // archive row NOT duplicated
|
|
||||||
const meta = JSON.parse(f2.metadata ?? '{}') as { archiveUids?: string[] };
|
|
||||||
expect(meta.archiveUids).toHaveLength(1); // uid-array NOT grown by the skip-path
|
|
||||||
expect(archive.reconstructSource(f2.id)).toHaveLength(1); // resolves exactly one row
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -6,19 +6,17 @@
|
|||||||
*
|
*
|
||||||
* Coverage:
|
* Coverage:
|
||||||
* 1. Cold start: server boot → first response
|
* 1. Cold start: server boot → first response
|
||||||
* 2. FTS5 search with 1000+ frames
|
* 2. Workspace list with 50 workspaces
|
||||||
* 3. Workspace list with 50 workspaces
|
* 3. Session load with 500 messages
|
||||||
* 4. Session load with 500 messages
|
* 4. Marketplace FTS5 search (bundled DB)
|
||||||
* 5. Marketplace FTS5 search (bundled DB)
|
* 5. Vault set+get cycle
|
||||||
* 6. Vault set+get cycle
|
|
||||||
* 7. Memory frame batch write (100 frames)
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { describe, it, expect, beforeAll, afterAll, beforeEach, afterEach } from 'vitest';
|
import { describe, it, expect, beforeAll, afterAll, beforeEach, afterEach } from 'vitest';
|
||||||
import fs from 'node:fs';
|
import fs from 'node:fs';
|
||||||
import path from 'node:path';
|
import path from 'node:path';
|
||||||
import os from 'node:os';
|
import os from 'node:os';
|
||||||
import { MindDB, FrameStore, SessionStore, VaultStore, WorkspaceManager } from '@waggle/core';
|
import { VaultStore, WorkspaceManager } from '@waggle/core';
|
||||||
import { buildLocalServer } from '../../src/local/index.js';
|
import { buildLocalServer } from '../../src/local/index.js';
|
||||||
import type { FastifyInstance } from 'fastify';
|
import type { FastifyInstance } from 'fastify';
|
||||||
import { injectWithAuth } from '../test-utils.js';
|
import { injectWithAuth } from '../test-utils.js';
|
||||||
@@ -55,11 +53,6 @@ describe('Performance Benchmarks', () => {
|
|||||||
it('server boots and responds within 5 seconds', async () => {
|
it('server boots and responds within 5 seconds', async () => {
|
||||||
const tmpDir = createTmpDir('coldstart');
|
const tmpDir = createTmpDir('coldstart');
|
||||||
try {
|
try {
|
||||||
// Create a minimal personal.mind so the server can start
|
|
||||||
const personalPath = path.join(tmpDir, 'personal.mind');
|
|
||||||
const mind = new MindDB(personalPath);
|
|
||||||
mind.close();
|
|
||||||
|
|
||||||
const start = Date.now();
|
const start = Date.now();
|
||||||
const server = await buildLocalServer({ dataDir: tmpDir });
|
const server = await buildLocalServer({ dataDir: tmpDir });
|
||||||
const res = await injectWithAuth(server, { method: 'GET', url: '/health' });
|
const res = await injectWithAuth(server, { method: 'GET', url: '/health' });
|
||||||
@@ -76,97 +69,7 @@ describe('Performance Benchmarks', () => {
|
|||||||
}, 15_000);
|
}, 15_000);
|
||||||
});
|
});
|
||||||
|
|
||||||
// ── 2. FTS5 Search Performance ──────────────────────────────────────
|
// ── 2. Workspace List Performance ───────────────────────────────────
|
||||||
|
|
||||||
describe('FTS5 Search with 1000 frames', () => {
|
|
||||||
let tmpDir: string;
|
|
||||||
let mind: MindDB;
|
|
||||||
let frames: FrameStore;
|
|
||||||
let sessions: SessionStore;
|
|
||||||
let gopId: string;
|
|
||||||
|
|
||||||
beforeAll(() => {
|
|
||||||
tmpDir = createTmpDir('fts5');
|
|
||||||
const dbPath = path.join(tmpDir, 'personal.mind');
|
|
||||||
mind = new MindDB(dbPath);
|
|
||||||
frames = new FrameStore(mind);
|
|
||||||
sessions = new SessionStore(mind);
|
|
||||||
|
|
||||||
// Create a session for FK constraints
|
|
||||||
const session = sessions.create('perf-test');
|
|
||||||
gopId = session.gop_id;
|
|
||||||
|
|
||||||
// Insert 1000 frames with varied content
|
|
||||||
const topics = [
|
|
||||||
'machine learning model training optimization',
|
|
||||||
'database indexing strategies for SQLite',
|
|
||||||
'TypeScript generics and type inference',
|
|
||||||
'React component lifecycle management',
|
|
||||||
'Node.js event loop performance tuning',
|
|
||||||
'memory management garbage collection patterns',
|
|
||||||
'API design RESTful best practices',
|
|
||||||
'testing strategies unit integration e2e',
|
|
||||||
'CI/CD pipeline automation deployment',
|
|
||||||
'microservices architecture communication patterns',
|
|
||||||
];
|
|
||||||
|
|
||||||
for (let i = 0; i < 1000; i++) {
|
|
||||||
const topic = topics[i % topics.length];
|
|
||||||
frames.createIFrame(gopId, `Frame ${i}: ${topic} — detailed notes about ${topic} iteration ${i}`, 'normal');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
afterAll(() => {
|
|
||||||
mind.close();
|
|
||||||
cleanupDir(tmpDir);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('FTS5 keyword search completes within 200ms for 1000 frames', () => {
|
|
||||||
const raw = mind.getDatabase();
|
|
||||||
|
|
||||||
const start = Date.now();
|
|
||||||
const results = raw.prepare(`
|
|
||||||
SELECT mf.* FROM memory_frames mf
|
|
||||||
INNER JOIN memory_frames_fts fts ON mf.id = fts.rowid
|
|
||||||
WHERE memory_frames_fts MATCH ?
|
|
||||||
LIMIT 20
|
|
||||||
`).all('machine learning');
|
|
||||||
const elapsed = Date.now() - start;
|
|
||||||
|
|
||||||
expect(results.length).toBeGreaterThan(0);
|
|
||||||
// 200ms is generous — SQLite FTS5 on 1000 rows should be <10ms
|
|
||||||
expect(elapsed).toBeLessThan(perfBudget(200));
|
|
||||||
});
|
|
||||||
|
|
||||||
it('FTS5 wildcard search completes within 200ms', () => {
|
|
||||||
const raw = mind.getDatabase();
|
|
||||||
|
|
||||||
const start = Date.now();
|
|
||||||
const results = raw.prepare(`
|
|
||||||
SELECT mf.* FROM memory_frames mf
|
|
||||||
INNER JOIN memory_frames_fts fts ON mf.id = fts.rowid
|
|
||||||
WHERE memory_frames_fts MATCH ?
|
|
||||||
LIMIT 20
|
|
||||||
`).all('database*');
|
|
||||||
const elapsed = Date.now() - start;
|
|
||||||
|
|
||||||
expect(results.length).toBeGreaterThan(0);
|
|
||||||
expect(elapsed).toBeLessThan(perfBudget(200));
|
|
||||||
});
|
|
||||||
|
|
||||||
it('frame count query completes within 50ms', () => {
|
|
||||||
const raw = mind.getDatabase();
|
|
||||||
|
|
||||||
const start = Date.now();
|
|
||||||
const row = raw.prepare('SELECT COUNT(*) as cnt FROM memory_frames').get() as { cnt: number };
|
|
||||||
const elapsed = Date.now() - start;
|
|
||||||
|
|
||||||
expect(row.cnt).toBe(1000);
|
|
||||||
expect(elapsed).toBeLessThan(perfBudget(50));
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// ── 3. Workspace List Performance ───────────────────────────────────
|
|
||||||
|
|
||||||
describe('Workspace Listing with 50 workspaces', () => {
|
describe('Workspace Listing with 50 workspaces', () => {
|
||||||
let tmpDir: string;
|
let tmpDir: string;
|
||||||
@@ -175,11 +78,6 @@ describe('Performance Benchmarks', () => {
|
|||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
tmpDir = createTmpDir('ws-list');
|
tmpDir = createTmpDir('ws-list');
|
||||||
|
|
||||||
// Create personal.mind
|
|
||||||
const personalPath = path.join(tmpDir, 'personal.mind');
|
|
||||||
const mind = new MindDB(personalPath);
|
|
||||||
mind.close();
|
|
||||||
|
|
||||||
// Create 50 workspaces via WorkspaceManager
|
// Create 50 workspaces via WorkspaceManager
|
||||||
const wsManager = new WorkspaceManager(tmpDir);
|
const wsManager = new WorkspaceManager(tmpDir);
|
||||||
for (let i = 0; i < 50; i++) {
|
for (let i = 0; i < 50; i++) {
|
||||||
@@ -211,7 +109,7 @@ describe('Performance Benchmarks', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// ── 4. Session Load Performance ─────────────────────────────────────
|
// ── 3. Session Load Performance ─────────────────────────────────────
|
||||||
|
|
||||||
describe('Session File Loading', () => {
|
describe('Session File Loading', () => {
|
||||||
let tmpDir: string;
|
let tmpDir: string;
|
||||||
@@ -258,7 +156,7 @@ describe('Performance Benchmarks', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// ── 5. Marketplace FTS5 Search ──────────────────────────────────────
|
// ── 4. Marketplace FTS5 Search ──────────────────────────────────────
|
||||||
|
|
||||||
describe('Marketplace Search', () => {
|
describe('Marketplace Search', () => {
|
||||||
it('marketplace FTS5 search completes within 200ms (bundled DB)', () => {
|
it('marketplace FTS5 search completes within 200ms (bundled DB)', () => {
|
||||||
@@ -317,7 +215,7 @@ describe('Performance Benchmarks', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// ── 6. Vault Operations ─────────────────────────────────────────────
|
// ── 5. Vault Operations ─────────────────────────────────────────────
|
||||||
|
|
||||||
describe('Vault Encrypt/Decrypt Cycle', () => {
|
describe('Vault Encrypt/Decrypt Cycle', () => {
|
||||||
let tmpDir: string;
|
let tmpDir: string;
|
||||||
@@ -372,81 +270,4 @@ describe('Performance Benchmarks', () => {
|
|||||||
expect(elapsed).toBeLessThan(perfBudget(50));
|
expect(elapsed).toBeLessThan(perfBudget(50));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// ── 7. Memory Frame Write Performance ───────────────────────────────
|
|
||||||
|
|
||||||
describe('Memory Frame Batch Write', () => {
|
|
||||||
let tmpDir: string;
|
|
||||||
let mind: MindDB;
|
|
||||||
let frames: FrameStore;
|
|
||||||
let sessions: SessionStore;
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
tmpDir = createTmpDir('frame-write');
|
|
||||||
const dbPath = path.join(tmpDir, 'write-bench.mind');
|
|
||||||
mind = new MindDB(dbPath);
|
|
||||||
frames = new FrameStore(mind);
|
|
||||||
sessions = new SessionStore(mind);
|
|
||||||
});
|
|
||||||
|
|
||||||
afterEach(() => {
|
|
||||||
mind.close();
|
|
||||||
cleanupDir(tmpDir);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('writing 100 I-frames completes within 2 seconds', () => {
|
|
||||||
const session = sessions.create('write-bench');
|
|
||||||
const gopId = session.gop_id;
|
|
||||||
|
|
||||||
const start = Date.now();
|
|
||||||
for (let i = 0; i < 100; i++) {
|
|
||||||
frames.createIFrame(
|
|
||||||
gopId,
|
|
||||||
`Batch write test frame ${i}: This is a moderately sized content block that simulates real-world memory frame sizes with enough text to be meaningful.`,
|
|
||||||
'normal'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
const elapsed = Date.now() - start;
|
|
||||||
|
|
||||||
// Verify all frames were written
|
|
||||||
const allFrames = frames.getGopFrames(gopId);
|
|
||||||
expect(allFrames.length).toBe(100);
|
|
||||||
// 2 seconds is generous — SQLite WAL mode batch writes should be <500ms
|
|
||||||
expect(elapsed).toBeLessThan(perfBudget(2000));
|
|
||||||
});
|
|
||||||
|
|
||||||
it('writing 100 P-frames completes within 2 seconds', () => {
|
|
||||||
const session = sessions.create('pframe-bench');
|
|
||||||
const gopId = session.gop_id;
|
|
||||||
|
|
||||||
// Create an I-frame as the base
|
|
||||||
const baseFrame = frames.createIFrame(gopId, 'Base frame for P-frame benchmark', 'normal');
|
|
||||||
|
|
||||||
const start = Date.now();
|
|
||||||
for (let i = 0; i < 100; i++) {
|
|
||||||
frames.createPFrame(
|
|
||||||
gopId,
|
|
||||||
`P-frame delta ${i}: Updated information about the topic with new details and corrections.`,
|
|
||||||
baseFrame.id,
|
|
||||||
'normal'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
const elapsed = Date.now() - start;
|
|
||||||
|
|
||||||
// 1 base + 100 P-frames = 101
|
|
||||||
const allFrames = frames.getGopFrames(gopId);
|
|
||||||
expect(allFrames.length).toBe(101);
|
|
||||||
expect(elapsed).toBeLessThan(perfBudget(2000));
|
|
||||||
});
|
|
||||||
|
|
||||||
it('creating 50 sessions completes within 1 second', () => {
|
|
||||||
const start = Date.now();
|
|
||||||
for (let i = 0; i < 50; i++) {
|
|
||||||
sessions.create(`session-bench-${i}`);
|
|
||||||
}
|
|
||||||
const elapsed = Date.now() - start;
|
|
||||||
|
|
||||||
expect(elapsed).toBeLessThan(perfBudget(1000));
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user