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:
shumeiko.it
2026-10-24 12:37:42 +02:00
parent ac23bbd7a6
commit 424b46db19
3 changed files with 134 additions and 190 deletions

View File

@@ -222,11 +222,12 @@ async function stopProcess(child: ChildProcessWithoutNullStreams): Promise<void>
const CLI_PACKAGE_CLOSURE = [ const CLI_PACKAGE_CLOSURE = [
'@waggle/shared', '@waggle/shared',
'@waggle/memory-contract',
'@waggle/memory-mem0',
'@waggle/hive-mind-core', '@waggle/hive-mind-core',
'@waggle/core', '@waggle/core',
'@waggle/marketplace', '@waggle/marketplace',
'@waggle/agent', '@waggle/agent',
'@waggle/weaver',
'@waggle/cli', '@waggle/cli',
] as const; ] as const;
@@ -438,7 +439,7 @@ describe('@waggle/cli runtime UX', () => {
const install = await runInCwdAsync( const install = await runInCwdAsync(
bin('npm'), bin('npm'),
// The REPL opens MindDB on startup, so this install must allow better-sqlite3's // The REPL opens SQLite stores on startup, so this install must allow better-sqlite3's
// native binding lifecycle rather than using the help-only --ignore-scripts path. // native binding lifecycle rather than using the help-only --ignore-scripts path.
['install', '--no-audit', '--no-fund', '--prefer-offline'], ['install', '--no-audit', '--no-fund', '--prefer-offline'],
projectDir, projectDir,
@@ -503,7 +504,10 @@ describe('@waggle/cli runtime UX', () => {
expect(stdout).toContain('Conversation cleared.'); expect(stdout).toContain('Conversation cleared.');
expect(stdout).toContain('Goodbye!'); expect(stdout).toContain('Goodbye!');
expect(stderr).not.toContain('Fatal error'); expect(stderr).not.toContain('Fatal error');
expect(fs.existsSync(path.join(home, '.waggle', 'default.mind'))).toBe(true); // Memory (mem0) and Waggle's own database live in the data directory (ADR-0007).
expect(fs.existsSync(path.join(home, '.waggle', 'memory', 'waggle-memory.json'))).toBe(true);
expect(fs.existsSync(path.join(home, '.waggle', 'waggle.db'))).toBe(true);
expect(fs.existsSync(path.join(home, '.waggle', 'default.mind'))).toBe(false);
} finally { } finally {
if (child) await stopProcess(child); if (child) await stopProcess(child);
fs.rmSync(home, { recursive: true, force: true }); fs.rmSync(home, { recursive: true, force: true });

View File

@@ -2,15 +2,18 @@
* Comprehensive E2E test — exercises the same code paths as the CLI REPL * Comprehensive E2E test — exercises the same code paths as the CLI REPL
* but programmatically (no LiteLLM/API needed). * but programmatically (no LiteLLM/API needed).
* *
* Tests 14 scenarios covering identity, awareness, memory persistence, * Covers identity, awareness, memory persistence, cross-session recall, tool
* knowledge graph, cross-session recall, tool execution, system prompt, * execution, system prompt, hooks, permissions, and more. Memory is the mem0
* hooks, permissions, and more. * store the REPL opens (ADR-0007), with the word embedder so no model is
* downloaded; the profile card and awareness live in waggle.db.
*/ */
import { describe, it, expect, beforeEach, afterEach } from 'vitest'; import { describe, it, expect, beforeEach, afterEach } from 'vitest';
import * as fs from 'node:fs'; import * as fs from 'node:fs';
import * as path from 'node:path'; import * as path from 'node:path';
import * as os from 'node:os'; import * as os from 'node:os';
import { MindDB } from '@waggle/core'; import { WaggleDB } from '@waggle/core';
import { PERSONAL_SCOPE, type MemoryStore } from '@waggle/memory-contract';
import { createMem0MemoryStore, createWordEmbedder } from '@waggle/memory-mem0';
import { import {
Orchestrator, Orchestrator,
createSystemTools, createSystemTools,
@@ -21,36 +24,42 @@ import {
filterToolsForContext, filterToolsForContext,
needsConfirmation, needsConfirmation,
} from '@waggle/agent'; } from '@waggle/agent';
import { MockEmbedder } from '../../hive-mind-core/tests/mind/helpers/mock-embedder.js';
// Helper: create a file-backed .mind DB in temp dir interface Session {
function createTmpMind(): { path: string; db: MindDB } { memory: MemoryStore;
const p = path.join(os.tmpdir(), `waggle-e2e-${Date.now()}-${Math.random().toString(36).slice(2)}.mind`); waggleDb: WaggleDB;
return { path: p, db: new MindDB(p) }; orchestrator: Orchestrator;
} }
function cleanup(filePath: string) { /** Opens a data directory the way the REPL does: memory in <dir>/memory, waggle.db next to it. */
for (const f of [filePath, filePath + '-wal', filePath + '-shm']) { async function openSession(dataDir: string): Promise<Session> {
if (fs.existsSync(f)) fs.unlinkSync(f); const memory = await createMem0MemoryStore({
directory: path.join(dataDir, 'memory'),
embedder: createWordEmbedder(),
});
const waggleDb = WaggleDB.openInDataDir(dataDir);
return { memory, waggleDb, orchestrator: new Orchestrator({ memory, waggleDb }) };
} }
async function closeSession(session: Session): Promise<void> {
await session.memory.close();
session.waggleDb.close();
} }
describe('Comprehensive CLI E2E Test', () => { describe('Comprehensive CLI E2E Test', () => {
let mindPath: string; let dataDir: string;
let db: MindDB; let session: Session;
let orchestrator: Orchestrator; let orchestrator: Orchestrator;
const embedder = new MockEmbedder();
beforeEach(() => { beforeEach(async () => {
const tmp = createTmpMind(); dataDir = fs.mkdtempSync(path.join(os.tmpdir(), 'waggle-e2e-'));
mindPath = tmp.path; session = await openSession(dataDir);
db = tmp.db; orchestrator = session.orchestrator;
orchestrator = new Orchestrator({ db, embedder });
}); });
afterEach(() => { afterEach(async () => {
db.close(); await closeSession(session);
cleanup(mindPath); fs.rmSync(dataDir, { recursive: true, force: true });
}); });
// ─── Test 1: Identity CRUD ─── // ─── Test 1: Identity CRUD ───
@@ -60,7 +69,7 @@ describe('Comprehensive CLI E2E Test', () => {
role: 'Personal AI Assistant', role: 'Personal AI Assistant',
department: 'Engineering', department: 'Engineering',
personality: 'Helpful and precise', personality: 'Helpful and precise',
capabilities: 'Memory, search, knowledge graph', capabilities: 'Memory, search',
system_prompt: 'You are Waggle.', system_prompt: 'You are Waggle.',
}); });
@@ -103,24 +112,18 @@ describe('Comprehensive CLI E2E Test', () => {
expect(result).toContain('March 15th'); expect(result).toContain('March 15th');
}); });
// ─── Test 4: Knowledge Graph ───
it('T4: Create entities and relations, query them', async () => {
const kg = orchestrator.getKnowledge();
const alice = kg.createEntity('person', 'Alice', { role: 'Tech Lead' });
const project = kg.createEntity('project', 'Phoenix', { status: 'active' });
const react = kg.createEntity('technology', 'React', { version: '18' });
kg.createRelation(alice.id, project.id, 'leads', 0.95);
kg.createRelation(project.id, react.id, 'uses', 0.9);
const result = await orchestrator.executeTool('query_knowledge', { query: 'Alice' });
expect(result).toContain('Alice');
expect(result).toContain('leads');
expect(result).toContain('Phoenix');
});
// ─── Test 5: Cross-Session Memory Persistence ─── // ─── Test 5: Cross-Session Memory Persistence ───
it('T5: Memories persist across sessions (file-backed .mind)', async () => { it('T5: Memories, identity and tasks persist across sessions (file-backed data directory)', async () => {
orchestrator.getIdentity().create({
name: 'Waggle',
role: 'Personal AI Assistant',
department: '',
personality: '',
capabilities: '',
system_prompt: '',
});
await orchestrator.executeTool('add_task', { content: 'Prepare the quarterly review', priority: 7 });
// Session 1: save memories // Session 1: save memories
await orchestrator.executeTool('save_memory', { await orchestrator.executeTool('save_memory', {
content: 'My name is Marko and I work on the Waggle project', content: 'My name is Marko and I work on the Waggle project',
@@ -135,12 +138,12 @@ describe('Comprehensive CLI E2E Test', () => {
importance: 'normal', importance: 'normal',
}); });
// Close DB (simulates CLI exit) // Close everything (simulates CLI exit)
db.close(); await closeSession(session);
// Session 2: reopen same .mind file // Session 2: reopen the same data directory
const db2 = new MindDB(mindPath); session = await openSession(dataDir);
const orchestrator2 = new Orchestrator({ db: db2, embedder }); const orchestrator2 = session.orchestrator;
// Search for memories from previous session // Search for memories from previous session
const result1 = await orchestrator2.executeTool('search_memory', { query: 'Marko Waggle' }); const result1 = await orchestrator2.executeTool('search_memory', { query: 'Marko Waggle' });
@@ -153,15 +156,13 @@ describe('Comprehensive CLI E2E Test', () => {
const result3 = await orchestrator2.executeTool('search_memory', { query: 'Python data' }); const result3 = await orchestrator2.executeTool('search_memory', { query: 'Python data' });
expect(result3).toContain('Python'); expect(result3).toContain('Python');
db2.close(); expect(await orchestrator2.executeTool('get_identity', {})).toContain('Personal AI Assistant');
expect(await orchestrator2.executeTool('get_awareness', {})).toContain('Prepare the quarterly review');
// Reassign so afterEach cleanup works expect((await orchestrator2.getMemoryStats()).memoryCount).toBe(3);
db = new MindDB(mindPath);
orchestrator = new Orchestrator({ db, embedder });
}); });
// ─── Test 6: System Prompt Builder ─── // ─── Test 6: System Prompt Builder ───
it('T6: System prompt includes identity, awareness, and tools', () => { it('T6: System prompt includes identity, awareness, and tools', async () => {
orchestrator.getIdentity().create({ orchestrator.getIdentity().create({
name: 'TestBot', name: 'TestBot',
role: 'Tester', role: 'Tester',
@@ -172,7 +173,7 @@ describe('Comprehensive CLI E2E Test', () => {
}); });
orchestrator.getAwareness().add('task', 'Run integration tests', 10); orchestrator.getAwareness().add('task', 'Run integration tests', 10);
const prompt = orchestrator.buildSystemPrompt(); const prompt = await orchestrator.buildSystemPrompt();
expect(prompt).toContain('TestBot'); expect(prompt).toContain('TestBot');
expect(prompt).toContain('Run integration tests'); expect(prompt).toContain('Run integration tests');
// System prompt includes self-awareness block with tool summary // System prompt includes self-awareness block with tool summary
@@ -183,7 +184,7 @@ describe('Comprehensive CLI E2E Test', () => {
// ─── Test 7: Tool Definitions ─── // ─── Test 7: Tool Definitions ───
it('T7: All required tools are defined with correct shape', () => { it('T7: All required tools are defined with correct shape', () => {
const tools = orchestrator.getTools(); const tools = orchestrator.getTools();
const required = ['get_identity', 'get_awareness', 'search_memory', 'save_memory', 'query_knowledge', 'add_task', 'correct_knowledge']; const required = ['get_identity', 'get_awareness', 'search_memory', 'search_all_workspaces', 'save_memory', 'add_task'];
for (const name of required) { for (const name of required) {
const tool = tools.find(t => t.name === name); const tool = tools.find(t => t.name === name);
@@ -191,6 +192,8 @@ describe('Comprehensive CLI E2E Test', () => {
expect(tool!.description).toBeTruthy(); expect(tool!.description).toBeTruthy();
expect(typeof tool!.execute).toBe('function'); expect(typeof tool!.execute).toBe('function');
} }
// The knowledge graph is not part of v1 (ADR-0002).
expect(tools.map(t => t.name)).not.toContain('query_knowledge');
}); });
// ─── Test 8: System Tools ─── // ─── Test 8: System Tools ───
@@ -288,20 +291,14 @@ describe('Comprehensive CLI E2E Test', () => {
// ─── Test 14: Memory Stats ─── // ─── Test 14: Memory Stats ───
it('T14: Memory stats reflect actual data', async () => { it('T14: Memory stats reflect actual data', async () => {
// Start with empty // Start with empty
let stats = orchestrator.getMemoryStats(); expect((await orchestrator.getMemoryStats()).memoryCount).toBe(0);
expect(stats.frameCount).toBe(0);
expect(stats.sessionCount).toBe(0);
expect(stats.entityCount).toBe(0);
// Save some memories // Save some memories
await orchestrator.executeTool('save_memory', { content: 'Memory one' }); await orchestrator.executeTool('save_memory', { content: 'Memory one about the roadmap' });
await orchestrator.executeTool('save_memory', { content: 'Memory two' }); await orchestrator.executeTool('save_memory', { content: 'Memory two about the hiring plan' });
orchestrator.getKnowledge().createEntity('test', 'Entity1', {});
stats = orchestrator.getMemoryStats(); expect((await orchestrator.getMemoryStats()).memoryCount).toBe(2);
expect(stats.frameCount).toBeGreaterThanOrEqual(2); expect(await session.memory.count({ scopes: [PERSONAL_SCOPE] })).toBe(2);
expect(stats.sessionCount).toBeGreaterThanOrEqual(1);
expect(stats.entityCount).toBeGreaterThanOrEqual(1);
}); });
// ─── Test 15: Empty state handling ─── // ─── Test 15: Empty state handling ───
@@ -315,8 +312,7 @@ describe('Comprehensive CLI E2E Test', () => {
const search = await orchestrator.executeTool('search_memory', { query: 'anything' }); const search = await orchestrator.executeTool('search_memory', { query: 'anything' });
expect(search).toContain('No relevant memories'); expect(search).toContain('No relevant memories');
const kg = await orchestrator.executeTool('query_knowledge', { query: 'nobody' }); expect(await orchestrator.recallMemory('anything')).toEqual({ text: '', count: 0, recalled: [], recalledFrames: [] });
expect(kg).toContain('No entities found');
}); });
// ─── Test 16: Unknown tool throws ─── // ─── Test 16: Unknown tool throws ───
@@ -329,45 +325,26 @@ describe('Comprehensive CLI E2E Test', () => {
// W2.10: save_memory is rate-limited to 50 per session to prevent flooding. // W2.10: save_memory is rate-limited to 50 per session to prevent flooding.
// Save 60 — first 50 succeed, remaining are rate-limited. // Save 60 — first 50 succeed, remaining are rate-limited.
const RATE_LIMIT = 50; const RATE_LIMIT = 50;
const TOPICS = ['alpha', 'bravo', 'charlie', 'delta', 'echo', 'foxtrot', 'golf', 'hotel', 'india', 'juliett'];
const AREAS = ['billing', 'search', 'onboarding', 'reporting', 'security'];
const results: string[] = [];
for (let i = 0; i < 60; i++) { for (let i = 0; i < 60; i++) {
await orchestrator.executeTool('save_memory', { results.push(await orchestrator.executeTool('save_memory', {
content: `Observation ${i}: topic-${i % 10} with detail about area-${i % 5}`, content: `Observation ${i}: topic ${TOPICS[i % 10]} with detail about ${AREAS[i % 5]}`,
importance: i % 20 === 0 ? 'important' : 'normal', importance: i % 20 === 0 ? 'important' : 'normal',
}); }));
} }
expect(results.filter(r => r.startsWith('Memory saved'))).toHaveLength(RATE_LIMIT);
expect(results.slice(RATE_LIMIT).every(r => r.includes('rate limit reached'))).toBe(true);
// Search by topic (hyphens in queries should work after FTS5 sanitization) // Search by topic and by area
const result = await orchestrator.executeTool('search_memory', { query: 'topic-7' }); const result = await orchestrator.executeTool('search_memory', { query: 'topic hotel' });
expect(result).toContain('topic-7'); expect(result).toContain('topic hotel');
// Search by area const result2 = await orchestrator.executeTool('search_memory', { query: 'reporting' });
const result2 = await orchestrator.executeTool('search_memory', { query: 'area-3' }); expect(result2).toContain('reporting');
expect(result2).toContain('area-3');
// Stats should show exactly the rate limit count (50 saved, rest blocked) // Exactly the rate limit count was saved, the rest blocked
const stats = orchestrator.getMemoryStats(); expect((await orchestrator.getMemoryStats()).memoryCount).toBe(RATE_LIMIT);
expect(stats.frameCount).toBeGreaterThanOrEqual(RATE_LIMIT);
});
// ─── Test 18: Cross-session knowledge graph persistence ───
it('T18: Knowledge graph persists across sessions', async () => {
const kg = orchestrator.getKnowledge();
const alice = kg.createEntity('person', 'Alice', { role: 'Engineer' });
const bob = kg.createEntity('person', 'Bob', { role: 'Designer' });
kg.createRelation(alice.id, bob.id, 'collaborates_with', 0.85);
// Close and reopen
db.close();
const db2 = new MindDB(mindPath);
const orchestrator2 = new Orchestrator({ db: db2, embedder });
const result = await orchestrator2.executeTool('query_knowledge', { query: 'Alice' });
expect(result).toContain('Alice');
expect(result).toContain('collaborates_with');
expect(result).toContain('Bob');
db2.close();
db = new MindDB(mindPath);
orchestrator = new Orchestrator({ db, embedder });
}); });
}); });

View File

@@ -6,46 +6,51 @@
* that matters — not trivia, but the kind of context that makes * that matters — not trivia, but the kind of context that makes
* an assistant feel like it was there the whole time. * an assistant feel like it was there the whole time.
* *
* This is the crown jewel test: .mind file = portable brain. The profile * This is the crown jewel test: the data directory = portable brain. Memory
* card and awareness items persist next to it in waggle.db (ADR-0007). * 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 { describe, it, expect, afterAll } from 'vitest';
import * as fs from 'node:fs'; import * as fs from 'node:fs';
import * as path from 'node:path'; import * as path from 'node:path';
import * as os from 'node:os'; 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 { 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 DATA_DIR = fs.mkdtempSync(path.join(os.tmpdir(), 'waggle-hard-memory-'));
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;
function cleanup() { interface Session {
lastDb?.close(); memory: MemoryStore;
lastDb = null; waggleDb: WaggleDB;
lastWaggleDb?.close(); orch: Orchestrator;
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 */ }
}
}
} }
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', () => { describe('Hard Memory Persistence — Real Work Simulation', () => {
const embedder = new MockEmbedder();
// ═══════════════════════════════════════════════════════════════════ // ═══════════════════════════════════════════════════════════════════
// SESSION 1: Monday morning — project kickoff // SESSION 1: Monday morning — project kickoff
// ═══════════════════════════════════════════════════════════════════ // ═══════════════════════════════════════════════════════════════════
it('Session 1: Project kickoff — identity, decisions, architecture', async () => { it('Session 1: Project kickoff — identity, decisions, architecture', async () => {
const db = new MindDB(MIND_PATH); const session = await openSession();
const waggleDb = new WaggleDB(WAGGLE_DB_PATH); const { orch } = session;
const orch = new Orchestrator({ db, waggleDb, embedder });
// Set up identity // Set up identity
orch.getIdentity().create({ orch.getIdentity().create({
@@ -53,7 +58,7 @@ describe('Hard Memory Persistence — Real Work Simulation', () => {
role: 'Senior Engineering Assistant', role: 'Senior Engineering Assistant',
department: 'Platform Team', department: 'Platform Team',
personality: 'Thorough, opinionated, remembers everything', 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.', system_prompt: 'You are Waggle, a senior engineering assistant for Marko.',
}); });
@@ -85,32 +90,15 @@ describe('Hard Memory Persistence — Real Work Simulation', () => {
importance: 'important', importance: 'important',
}); });
// Knowledge graph — people and their roles await closeSession(session);
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();
}); });
// ═══════════════════════════════════════════════════════════════════ // ═══════════════════════════════════════════════════════════════════
// SESSION 2: Tuesday — deep implementation work // SESSION 2: Tuesday — deep implementation work
// ═══════════════════════════════════════════════════════════════════ // ═══════════════════════════════════════════════════════════════════
it('Session 2: Implementation day — code decisions, bugs found, PR reviews', async () => { it('Session 2: Implementation day — code decisions, bugs found, PR reviews', async () => {
const db = new MindDB(MIND_PATH); const session = await openSession();
const waggleDb = new WaggleDB(WAGGLE_DB_PATH); const { orch } = session;
const orch = new Orchestrator({ db, waggleDb, embedder });
await orch.executeTool('save_memory', { 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.', 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', importance: 'normal',
}); });
// Update knowledge graph await closeSession(session);
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();
}); });
// ═══════════════════════════════════════════════════════════════════ // ═══════════════════════════════════════════════════════════════════
// SESSION 3: Wednesday — blockers, decisions, progress // SESSION 3: Wednesday — blockers, decisions, progress
// ═══════════════════════════════════════════════════════════════════ // ═══════════════════════════════════════════════════════════════════
it('Session 3: Midweek check-in — credentials arrived, new blocker, scope change', async () => { it('Session 3: Midweek check-in — credentials arrived, new blocker, scope change', async () => {
const db = new MindDB(MIND_PATH); const session = await openSession();
const waggleDb = new WaggleDB(WAGGLE_DB_PATH); const { orch } = session;
const orch = new Orchestrator({ db, waggleDb, embedder });
await orch.executeTool('save_memory', { await orch.executeTool('save_memory', {
content: 'Alice delivered Stripe production credentials to Vault as promised. Verified access works. Removed from pending items.', 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', importance: 'normal',
}); });
db.close(); await closeSession(session);
waggleDb.close();
}); });
// ═══════════════════════════════════════════════════════════════════ // ═══════════════════════════════════════════════════════════════════
// SESSION 4: Thursday — COLD START. Can the agent pick up where we left off? // 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 () => { it('Session 4 (COLD START): Agent must recall project state without being told', async () => {
const db = new MindDB(MIND_PATH); const session = await openSession();
lastDb = db; // Track for cleanup const { orch } = session;
const waggleDb = new WaggleDB(WAGGLE_DB_PATH);
lastWaggleDb = waggleDb;
const orch = new Orchestrator({ db, waggleDb, embedder });
// ─── Test A: Identity survives ─── // ─── Test A: Identity survives ───
const identity = await orch.executeTool('get_identity', {}); 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('PAY-142');
expect(bug).toContain('refund'); 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?" ─── // ─── Test J: "What was the error handling decision?" ───
const errorHandling = await orch.executeTool('search_memory', { const errorHandling = await orch.executeTool('search_memory', {
query: 'error handling JSON status codes', 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('amount_cents');
expect(schema).toContain('bigint'); expect(schema).toContain('bigint');
// ─── Test N: Memory stats show realistic data ─── // ─── Test N: Memory stats count every saved memory ───
const stats = orch.getMemoryStats(); expect((await orch.getMemoryStats()).memoryCount).toBe(17);
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 O: System prompt has everything for a cold-start ─── // ─── Test O: Automatic recall surfaces the newest critical memories on any query ───
const prompt = orch.buildSystemPrompt(); 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('Waggle');
expect(prompt).toContain('payment service'); expect(prompt).toContain('payment service');
expect(prompt).toContain('search_memory'); expect(prompt).toContain('search_memory');
db.close(); await closeSession(session);
waggleDb.close();
}); });
}); });