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:
@@ -222,11 +222,12 @@ async function stopProcess(child: ChildProcessWithoutNullStreams): Promise<void>
|
||||
|
||||
const CLI_PACKAGE_CLOSURE = [
|
||||
'@waggle/shared',
|
||||
'@waggle/memory-contract',
|
||||
'@waggle/memory-mem0',
|
||||
'@waggle/hive-mind-core',
|
||||
'@waggle/core',
|
||||
'@waggle/marketplace',
|
||||
'@waggle/agent',
|
||||
'@waggle/weaver',
|
||||
'@waggle/cli',
|
||||
] as const;
|
||||
|
||||
@@ -438,7 +439,7 @@ describe('@waggle/cli runtime UX', () => {
|
||||
|
||||
const install = await runInCwdAsync(
|
||||
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.
|
||||
['install', '--no-audit', '--no-fund', '--prefer-offline'],
|
||||
projectDir,
|
||||
@@ -503,7 +504,10 @@ describe('@waggle/cli runtime UX', () => {
|
||||
expect(stdout).toContain('Conversation cleared.');
|
||||
expect(stdout).toContain('Goodbye!');
|
||||
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 {
|
||||
if (child) await stopProcess(child);
|
||||
fs.rmSync(home, { recursive: true, force: true });
|
||||
|
||||
@@ -2,15 +2,18 @@
|
||||
* Comprehensive E2E test — exercises the same code paths as the CLI REPL
|
||||
* but programmatically (no LiteLLM/API needed).
|
||||
*
|
||||
* Tests 14 scenarios covering identity, awareness, memory persistence,
|
||||
* knowledge graph, cross-session recall, tool execution, system prompt,
|
||||
* hooks, permissions, and more.
|
||||
* Covers identity, awareness, memory persistence, cross-session recall, tool
|
||||
* execution, system prompt, hooks, permissions, and more. Memory is the mem0
|
||||
* 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 * as fs from 'node:fs';
|
||||
import * as path from 'node:path';
|
||||
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 {
|
||||
Orchestrator,
|
||||
createSystemTools,
|
||||
@@ -21,36 +24,42 @@ import {
|
||||
filterToolsForContext,
|
||||
needsConfirmation,
|
||||
} 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
|
||||
function createTmpMind(): { path: string; db: MindDB } {
|
||||
const p = path.join(os.tmpdir(), `waggle-e2e-${Date.now()}-${Math.random().toString(36).slice(2)}.mind`);
|
||||
return { path: p, db: new MindDB(p) };
|
||||
interface Session {
|
||||
memory: MemoryStore;
|
||||
waggleDb: WaggleDB;
|
||||
orchestrator: Orchestrator;
|
||||
}
|
||||
|
||||
function cleanup(filePath: string) {
|
||||
for (const f of [filePath, filePath + '-wal', filePath + '-shm']) {
|
||||
if (fs.existsSync(f)) fs.unlinkSync(f);
|
||||
}
|
||||
/** Opens a data directory the way the REPL does: memory in <dir>/memory, waggle.db next to it. */
|
||||
async function openSession(dataDir: string): Promise<Session> {
|
||||
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', () => {
|
||||
let mindPath: string;
|
||||
let db: MindDB;
|
||||
let dataDir: string;
|
||||
let session: Session;
|
||||
let orchestrator: Orchestrator;
|
||||
const embedder = new MockEmbedder();
|
||||
|
||||
beforeEach(() => {
|
||||
const tmp = createTmpMind();
|
||||
mindPath = tmp.path;
|
||||
db = tmp.db;
|
||||
orchestrator = new Orchestrator({ db, embedder });
|
||||
beforeEach(async () => {
|
||||
dataDir = fs.mkdtempSync(path.join(os.tmpdir(), 'waggle-e2e-'));
|
||||
session = await openSession(dataDir);
|
||||
orchestrator = session.orchestrator;
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
db.close();
|
||||
cleanup(mindPath);
|
||||
afterEach(async () => {
|
||||
await closeSession(session);
|
||||
fs.rmSync(dataDir, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
// ─── Test 1: Identity CRUD ───
|
||||
@@ -60,7 +69,7 @@ describe('Comprehensive CLI E2E Test', () => {
|
||||
role: 'Personal AI Assistant',
|
||||
department: 'Engineering',
|
||||
personality: 'Helpful and precise',
|
||||
capabilities: 'Memory, search, knowledge graph',
|
||||
capabilities: 'Memory, search',
|
||||
system_prompt: 'You are Waggle.',
|
||||
});
|
||||
|
||||
@@ -103,24 +112,18 @@ describe('Comprehensive CLI E2E Test', () => {
|
||||
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 ───
|
||||
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
|
||||
await orchestrator.executeTool('save_memory', {
|
||||
content: 'My name is Marko and I work on the Waggle project',
|
||||
@@ -135,12 +138,12 @@ describe('Comprehensive CLI E2E Test', () => {
|
||||
importance: 'normal',
|
||||
});
|
||||
|
||||
// Close DB (simulates CLI exit)
|
||||
db.close();
|
||||
// Close everything (simulates CLI exit)
|
||||
await closeSession(session);
|
||||
|
||||
// Session 2: reopen same .mind file
|
||||
const db2 = new MindDB(mindPath);
|
||||
const orchestrator2 = new Orchestrator({ db: db2, embedder });
|
||||
// Session 2: reopen the same data directory
|
||||
session = await openSession(dataDir);
|
||||
const orchestrator2 = session.orchestrator;
|
||||
|
||||
// Search for memories from previous session
|
||||
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' });
|
||||
expect(result3).toContain('Python');
|
||||
|
||||
db2.close();
|
||||
|
||||
// Reassign so afterEach cleanup works
|
||||
db = new MindDB(mindPath);
|
||||
orchestrator = new Orchestrator({ db, embedder });
|
||||
expect(await orchestrator2.executeTool('get_identity', {})).toContain('Personal AI Assistant');
|
||||
expect(await orchestrator2.executeTool('get_awareness', {})).toContain('Prepare the quarterly review');
|
||||
expect((await orchestrator2.getMemoryStats()).memoryCount).toBe(3);
|
||||
});
|
||||
|
||||
// ─── 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({
|
||||
name: 'TestBot',
|
||||
role: 'Tester',
|
||||
@@ -172,7 +173,7 @@ describe('Comprehensive CLI E2E Test', () => {
|
||||
});
|
||||
orchestrator.getAwareness().add('task', 'Run integration tests', 10);
|
||||
|
||||
const prompt = orchestrator.buildSystemPrompt();
|
||||
const prompt = await orchestrator.buildSystemPrompt();
|
||||
expect(prompt).toContain('TestBot');
|
||||
expect(prompt).toContain('Run integration tests');
|
||||
// System prompt includes self-awareness block with tool summary
|
||||
@@ -183,7 +184,7 @@ describe('Comprehensive CLI E2E Test', () => {
|
||||
// ─── Test 7: Tool Definitions ───
|
||||
it('T7: All required tools are defined with correct shape', () => {
|
||||
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) {
|
||||
const tool = tools.find(t => t.name === name);
|
||||
@@ -191,6 +192,8 @@ describe('Comprehensive CLI E2E Test', () => {
|
||||
expect(tool!.description).toBeTruthy();
|
||||
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 ───
|
||||
@@ -288,20 +291,14 @@ describe('Comprehensive CLI E2E Test', () => {
|
||||
// ─── Test 14: Memory Stats ───
|
||||
it('T14: Memory stats reflect actual data', async () => {
|
||||
// Start with empty
|
||||
let stats = orchestrator.getMemoryStats();
|
||||
expect(stats.frameCount).toBe(0);
|
||||
expect(stats.sessionCount).toBe(0);
|
||||
expect(stats.entityCount).toBe(0);
|
||||
expect((await orchestrator.getMemoryStats()).memoryCount).toBe(0);
|
||||
|
||||
// Save some memories
|
||||
await orchestrator.executeTool('save_memory', { content: 'Memory one' });
|
||||
await orchestrator.executeTool('save_memory', { content: 'Memory two' });
|
||||
orchestrator.getKnowledge().createEntity('test', 'Entity1', {});
|
||||
await orchestrator.executeTool('save_memory', { content: 'Memory one about the roadmap' });
|
||||
await orchestrator.executeTool('save_memory', { content: 'Memory two about the hiring plan' });
|
||||
|
||||
stats = orchestrator.getMemoryStats();
|
||||
expect(stats.frameCount).toBeGreaterThanOrEqual(2);
|
||||
expect(stats.sessionCount).toBeGreaterThanOrEqual(1);
|
||||
expect(stats.entityCount).toBeGreaterThanOrEqual(1);
|
||||
expect((await orchestrator.getMemoryStats()).memoryCount).toBe(2);
|
||||
expect(await session.memory.count({ scopes: [PERSONAL_SCOPE] })).toBe(2);
|
||||
});
|
||||
|
||||
// ─── Test 15: Empty state handling ───
|
||||
@@ -315,8 +312,7 @@ describe('Comprehensive CLI E2E Test', () => {
|
||||
const search = await orchestrator.executeTool('search_memory', { query: 'anything' });
|
||||
expect(search).toContain('No relevant memories');
|
||||
|
||||
const kg = await orchestrator.executeTool('query_knowledge', { query: 'nobody' });
|
||||
expect(kg).toContain('No entities found');
|
||||
expect(await orchestrator.recallMemory('anything')).toEqual({ text: '', count: 0, recalled: [], recalledFrames: [] });
|
||||
});
|
||||
|
||||
// ─── 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.
|
||||
// Save 60 — first 50 succeed, remaining are rate-limited.
|
||||
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++) {
|
||||
await orchestrator.executeTool('save_memory', {
|
||||
content: `Observation ${i}: topic-${i % 10} with detail about area-${i % 5}`,
|
||||
results.push(await orchestrator.executeTool('save_memory', {
|
||||
content: `Observation ${i}: topic ${TOPICS[i % 10]} with detail about ${AREAS[i % 5]}`,
|
||||
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)
|
||||
const result = await orchestrator.executeTool('search_memory', { query: 'topic-7' });
|
||||
expect(result).toContain('topic-7');
|
||||
// Search by topic and by area
|
||||
const result = await orchestrator.executeTool('search_memory', { query: 'topic hotel' });
|
||||
expect(result).toContain('topic hotel');
|
||||
|
||||
// Search by area
|
||||
const result2 = await orchestrator.executeTool('search_memory', { query: 'area-3' });
|
||||
expect(result2).toContain('area-3');
|
||||
const result2 = await orchestrator.executeTool('search_memory', { query: 'reporting' });
|
||||
expect(result2).toContain('reporting');
|
||||
|
||||
// Stats should show exactly the rate limit count (50 saved, rest blocked)
|
||||
const stats = orchestrator.getMemoryStats();
|
||||
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 });
|
||||
// Exactly the rate limit count was saved, the rest blocked
|
||||
expect((await orchestrator.getMemoryStats()).memoryCount).toBe(RATE_LIMIT);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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