test(cli): run the CLI suites on the mem0 store and waggle.db (P1.5)
The comprehensive and hard-persistence suites open a data directory the way the REPL does: mem0 in <dir>/memory (word embedder, no model download) and waggle.db for the profile card and tasks. Persistence across sessions now also checks identity and tasks after reopening. The packaged-runtime tests install @waggle/memory-contract and @waggle/memory-mem0 with the CLI (the weaver package is gone) and check that the REPL creates the memory store and waggle.db instead of default.mind. Deleted: T4 and T18 (knowledge graph entities and their persistence) and the knowledge-graph steps of the hard-persistence run; the graph is not in v1 (ADR-0002).
This commit is contained in:
@@ -6,46 +6,51 @@
|
||||
* that matters — not trivia, but the kind of context that makes
|
||||
* an assistant feel like it was there the whole time.
|
||||
*
|
||||
* This is the crown jewel test: .mind file = portable brain. The profile
|
||||
* card and awareness items persist next to it in waggle.db (ADR-0007).
|
||||
* This is the crown jewel test: the data directory = portable brain. Memory
|
||||
* lives in the mem0 store under <dataDir>/memory; the profile card and
|
||||
* awareness items persist next to it in waggle.db (ADR-0007).
|
||||
*/
|
||||
import { describe, it, expect, afterAll } from 'vitest';
|
||||
import * as fs from 'node:fs';
|
||||
import * as path from 'node:path';
|
||||
import * as os from 'node:os';
|
||||
import { MindDB, WaggleDB } from '@waggle/core';
|
||||
import { WaggleDB } from '@waggle/core';
|
||||
import type { MemoryStore } from '@waggle/memory-contract';
|
||||
import { createMem0MemoryStore, createWordEmbedder } from '@waggle/memory-mem0';
|
||||
import { Orchestrator } from '@waggle/agent';
|
||||
import { MockEmbedder } from '../../hive-mind-core/tests/mind/helpers/mock-embedder.js';
|
||||
|
||||
const MIND_PATH = path.join(os.tmpdir(), `waggle-hard-memory-${Date.now()}.mind`);
|
||||
const WAGGLE_DB_PATH = path.join(os.tmpdir(), `waggle-hard-memory-${Date.now()}.waggle.db`);
|
||||
let lastDb: MindDB | null = null;
|
||||
let lastWaggleDb: WaggleDB | null = null;
|
||||
const DATA_DIR = fs.mkdtempSync(path.join(os.tmpdir(), 'waggle-hard-memory-'));
|
||||
|
||||
function cleanup() {
|
||||
lastDb?.close();
|
||||
lastDb = null;
|
||||
lastWaggleDb?.close();
|
||||
lastWaggleDb = null;
|
||||
for (const base of [MIND_PATH, WAGGLE_DB_PATH]) {
|
||||
for (const f of [base, base + '-wal', base + '-shm']) {
|
||||
try { if (fs.existsSync(f)) fs.unlinkSync(f); } catch { /* ignore */ }
|
||||
}
|
||||
}
|
||||
interface Session {
|
||||
memory: MemoryStore;
|
||||
waggleDb: WaggleDB;
|
||||
orch: Orchestrator;
|
||||
}
|
||||
|
||||
afterAll(cleanup);
|
||||
/** Opens the data directory the way the REPL does. */
|
||||
async function openSession(): Promise<Session> {
|
||||
const memory = await createMem0MemoryStore({ directory: path.join(DATA_DIR, 'memory'), embedder: createWordEmbedder() });
|
||||
const waggleDb = WaggleDB.openInDataDir(DATA_DIR);
|
||||
return { memory, waggleDb, orch: new Orchestrator({ memory, waggleDb }) };
|
||||
}
|
||||
|
||||
async function closeSession(session: Session): Promise<void> {
|
||||
await session.memory.close();
|
||||
session.waggleDb.close();
|
||||
}
|
||||
|
||||
afterAll(() => {
|
||||
fs.rmSync(DATA_DIR, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
describe('Hard Memory Persistence — Real Work Simulation', () => {
|
||||
const embedder = new MockEmbedder();
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
// SESSION 1: Monday morning — project kickoff
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
it('Session 1: Project kickoff — identity, decisions, architecture', async () => {
|
||||
const db = new MindDB(MIND_PATH);
|
||||
const waggleDb = new WaggleDB(WAGGLE_DB_PATH);
|
||||
const orch = new Orchestrator({ db, waggleDb, embedder });
|
||||
const session = await openSession();
|
||||
const { orch } = session;
|
||||
|
||||
// Set up identity
|
||||
orch.getIdentity().create({
|
||||
@@ -53,7 +58,7 @@ describe('Hard Memory Persistence — Real Work Simulation', () => {
|
||||
role: 'Senior Engineering Assistant',
|
||||
department: 'Platform Team',
|
||||
personality: 'Thorough, opinionated, remembers everything',
|
||||
capabilities: 'Code review, architecture, memory, search, knowledge graph',
|
||||
capabilities: 'Code review, architecture, memory, search',
|
||||
system_prompt: 'You are Waggle, a senior engineering assistant for Marko.',
|
||||
});
|
||||
|
||||
@@ -85,32 +90,15 @@ describe('Hard Memory Persistence — Real Work Simulation', () => {
|
||||
importance: 'important',
|
||||
});
|
||||
|
||||
// Knowledge graph — people and their roles
|
||||
const kg = orch.getKnowledge();
|
||||
const marko = kg.createEntity('person', 'Marko Markovic', { role: 'Tech Lead', preference: 'direct communication' });
|
||||
const alice = kg.createEntity('person', 'Alice Chen', { role: 'DevOps Lead', team: 'Infrastructure' });
|
||||
const bob = kg.createEntity('person', 'Bob Kumar', { role: 'Backend Engineer', expertise: 'Go' });
|
||||
const paymentSvc = kg.createEntity('service', 'payment-service', { language: 'Go', status: 'in-development', repo: 'github.com/acme/payment-service-go' });
|
||||
const fraudSvc = kg.createEntity('service', 'fraud-check-service', { url: 'http://fraud.internal:8080', owner: 'Risk Team' });
|
||||
const stripe = kg.createEntity('integration', 'Stripe', { sdk: 'stripe-go', env: 'production' });
|
||||
|
||||
kg.createRelation(marko.id, paymentSvc.id, 'leads', 0.95);
|
||||
kg.createRelation(alice.id, paymentSvc.id, 'provides_infra', 0.9);
|
||||
kg.createRelation(bob.id, paymentSvc.id, 'implements', 0.9);
|
||||
kg.createRelation(paymentSvc.id, fraudSvc.id, 'depends_on', 1.0);
|
||||
kg.createRelation(paymentSvc.id, stripe.id, 'integrates', 1.0);
|
||||
|
||||
db.close();
|
||||
waggleDb.close();
|
||||
await closeSession(session);
|
||||
});
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
// SESSION 2: Tuesday — deep implementation work
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
it('Session 2: Implementation day — code decisions, bugs found, PR reviews', async () => {
|
||||
const db = new MindDB(MIND_PATH);
|
||||
const waggleDb = new WaggleDB(WAGGLE_DB_PATH);
|
||||
const orch = new Orchestrator({ db, waggleDb, embedder });
|
||||
const session = await openSession();
|
||||
const { orch } = session;
|
||||
|
||||
await orch.executeTool('save_memory', {
|
||||
content: 'Started implementing the charge endpoint. Using chi router with middleware chain: logging → auth → rate-limit → handler. Bob suggested using errgroup for parallel Stripe + fraud-check calls — good idea, adopted it.',
|
||||
@@ -137,22 +125,15 @@ describe('Hard Memory Persistence — Real Work Simulation', () => {
|
||||
importance: 'normal',
|
||||
});
|
||||
|
||||
// Update knowledge graph
|
||||
const kg = orch.getKnowledge();
|
||||
kg.createEntity('bug', 'PAY-142: Double refund vulnerability', { severity: 'high', status: 'open', found_in: 'Python payment service' });
|
||||
kg.createEntity('pr', 'PR #87: Charge handler', { author: 'Bob Kumar', status: 'changes-requested', issue: 'race condition on DB write' });
|
||||
|
||||
db.close();
|
||||
waggleDb.close();
|
||||
await closeSession(session);
|
||||
});
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
// SESSION 3: Wednesday — blockers, decisions, progress
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
it('Session 3: Midweek check-in — credentials arrived, new blocker, scope change', async () => {
|
||||
const db = new MindDB(MIND_PATH);
|
||||
const waggleDb = new WaggleDB(WAGGLE_DB_PATH);
|
||||
const orch = new Orchestrator({ db, waggleDb, embedder });
|
||||
const session = await openSession();
|
||||
const { orch } = session;
|
||||
|
||||
await orch.executeTool('save_memory', {
|
||||
content: 'Alice delivered Stripe production credentials to Vault as promised. Verified access works. Removed from pending items.',
|
||||
@@ -179,19 +160,15 @@ describe('Hard Memory Persistence — Real Work Simulation', () => {
|
||||
importance: 'normal',
|
||||
});
|
||||
|
||||
db.close();
|
||||
waggleDb.close();
|
||||
await closeSession(session);
|
||||
});
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
// SESSION 4: Thursday — COLD START. Can the agent pick up where we left off?
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
it('Session 4 (COLD START): Agent must recall project state without being told', async () => {
|
||||
const db = new MindDB(MIND_PATH);
|
||||
lastDb = db; // Track for cleanup
|
||||
const waggleDb = new WaggleDB(WAGGLE_DB_PATH);
|
||||
lastWaggleDb = waggleDb;
|
||||
const orch = new Orchestrator({ db, waggleDb, embedder });
|
||||
const session = await openSession();
|
||||
const { orch } = session;
|
||||
|
||||
// ─── Test A: Identity survives ───
|
||||
const identity = await orch.executeTool('get_identity', {});
|
||||
@@ -239,21 +216,6 @@ describe('Hard Memory Persistence — Real Work Simulation', () => {
|
||||
expect(bug).toContain('PAY-142');
|
||||
expect(bug).toContain('refund');
|
||||
|
||||
// ─── Test H: "What's Bob working on?" (knowledge graph) ───
|
||||
const bobInfo = await orch.executeTool('query_knowledge', {
|
||||
query: 'Bob',
|
||||
});
|
||||
expect(bobInfo).toContain('Bob Kumar');
|
||||
expect(bobInfo).toContain('implements');
|
||||
|
||||
// ─── Test I: "What does our service depend on?" ───
|
||||
const deps = await orch.executeTool('query_knowledge', {
|
||||
query: 'payment-service',
|
||||
});
|
||||
expect(deps).toContain('payment-service');
|
||||
expect(deps).toContain('depends_on');
|
||||
expect(deps).toContain('fraud-check');
|
||||
|
||||
// ─── Test J: "What was the error handling decision?" ───
|
||||
const errorHandling = await orch.executeTool('search_memory', {
|
||||
query: 'error handling JSON status codes',
|
||||
@@ -281,19 +243,20 @@ describe('Hard Memory Persistence — Real Work Simulation', () => {
|
||||
expect(schema).toContain('amount_cents');
|
||||
expect(schema).toContain('bigint');
|
||||
|
||||
// ─── Test N: Memory stats show realistic data ───
|
||||
const stats = orch.getMemoryStats();
|
||||
expect(stats.frameCount).toBeGreaterThanOrEqual(15); // We saved ~17 memories
|
||||
expect(stats.sessionCount).toBeGreaterThanOrEqual(1); // At least 1 session (CognifyPipeline reuses active)
|
||||
expect(stats.entityCount).toBeGreaterThanOrEqual(6); // 6+ entities in knowledge graph
|
||||
// ─── Test N: Memory stats count every saved memory ───
|
||||
expect((await orch.getMemoryStats()).memoryCount).toBe(17);
|
||||
|
||||
// ─── Test O: System prompt has everything for a cold-start ───
|
||||
const prompt = orch.buildSystemPrompt();
|
||||
// ─── Test O: Automatic recall surfaces the newest critical memories on any query ───
|
||||
const recall = await orch.recallMemory('where do things stand');
|
||||
expect(recall.text).toContain('PCI DSS');
|
||||
expect(recall.text).toContain('descope the refund endpoint');
|
||||
|
||||
// ─── Test P: System prompt has everything for a cold-start ───
|
||||
const prompt = await orch.buildSystemPrompt();
|
||||
expect(prompt).toContain('Waggle');
|
||||
expect(prompt).toContain('payment service');
|
||||
expect(prompt).toContain('search_memory');
|
||||
|
||||
db.close();
|
||||
waggleDb.close();
|
||||
await closeSession(session);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user