test(agent): move the agent suites onto the memory contract (P1.5)
Rewrites the orchestrator, recall, compaction, save_memory and assembler suites for MemoryStore (createInMemoryMemoryStore; mem0 with the word embedder for the M3b integration test), string ids, async prompt building and setWorkspace(). Creation times are set with fake timers, since a write cannot set its own. Stores of Waggle's own data (identity, traces) are built on WaggleDB; the session-manager stubs use the new create() signature. Kept behaviour: importance lane (cap, active scope, temporary exclusion), profile and event lanes, date window and its fallback, catch-up, injection blocking of recall and preloaded context, autosave safety, decision consent, compaction update-in-place, reranker wiring. New tests: recall with a workspace active versus personal only; fetchRecentMemories ordering; toRecallFrame; context loader; save_memory routing, dedup, rate limit, dramatic-claim downgrade and contradiction scope; search_memory and search_all_workspaces; pattern write-back kinds, scopes and sign gate; read_other_workspace; reranker off unless WAGGLE_RERANKER=1, wider rerank pool, failure fallbacks. Deleted, because the behaviour is gone: - w46-rawdetail-recall.test.ts: the raw-turn (RAWDETAIL) recall lane. - orchestrator.test.ts, query_knowledge (3 tests) and the recall-hardening M4 "Key Knowledge" test: the knowledge graph is not in v1 (ADR-0002). - orchestrator-context-frames "profile override": scoring profiles. - Assertions on I/P frame types, GOP sessions, FTS rows, the "Memory Facts" lane, cognify stages and session/entity counts were replaced by the equivalent contract-level checks.
This commit is contained in:
@@ -1,81 +1,134 @@
|
||||
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
||||
import { MindDB, FrameStore, SessionStore, MIND_FACT_PREFIX, MIND_EVENT_PREFIX, MIND_PROFILE_PREFIX } from '@waggle/core';
|
||||
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
|
||||
import {
|
||||
createInMemoryMemoryStore,
|
||||
PERSONAL_SCOPE,
|
||||
workspaceScope,
|
||||
type MemoryImportance,
|
||||
type MemoryKind,
|
||||
type MemoryScope,
|
||||
type MemoryStore,
|
||||
} from '@waggle/memory-contract';
|
||||
import { Orchestrator } from '../src/orchestrator.js';
|
||||
import { MockEmbedder } from '../../hive-mind-core/tests/mind/helpers/mock-embedder.js';
|
||||
|
||||
/**
|
||||
* W4.3b — extraction-lane rendering in recallMemory (plan components
|
||||
* #5/#6/#8 query side). Lane frames are written by extract-memory-lanes
|
||||
* (W4.3a); here we seed them directly and assert the render contract:
|
||||
* profiles first, dated facts, chronological events, windowed events
|
||||
* section, and the profile-never-as-snippet dedup rule.
|
||||
* W4.3b — profile and event lanes in recallMemory. What the model learned
|
||||
* about the user (kind 'profile') renders in full; events (kind 'event')
|
||||
* render chronologically, with a dedicated section for a period the query
|
||||
* names. Lane memories never render a second time as search snippets.
|
||||
*/
|
||||
|
||||
describe('W4.3b — recallMemory extraction lanes', () => {
|
||||
let db: MindDB;
|
||||
describe('W4.3b — recallMemory profile and event lanes', () => {
|
||||
let memory: MemoryStore;
|
||||
let orchestrator: Orchestrator;
|
||||
let frames: FrameStore;
|
||||
let gopId: string;
|
||||
|
||||
beforeEach(() => {
|
||||
db = new MindDB(':memory:');
|
||||
orchestrator = new Orchestrator({ db, embedder: new MockEmbedder() });
|
||||
frames = new FrameStore(db);
|
||||
gopId = new SessionStore(db).create().gop_id;
|
||||
memory = createInMemoryMemoryStore();
|
||||
orchestrator = new Orchestrator({ memory });
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
db.close();
|
||||
vi.useRealTimers();
|
||||
});
|
||||
|
||||
function seedLanes(): void {
|
||||
frames.createIFrame(gopId, `${MIND_PROFILE_PREFIX} Ana]\nAna is a designer based in Belgrade who plays Hollow Knight.`, 'normal', 'system');
|
||||
frames.createIFrame(gopId, `${MIND_FACT_PREFIX}\nUser preference: Ana prefers dark mode`, 'normal', 'system');
|
||||
frames.createIFrame(gopId, `${MIND_EVENT_PREFIX}\n[2026-05-07] Ana visited the dentist`, 'normal', 'system', '2026-05-07T00:00:00.000Z');
|
||||
frames.createIFrame(gopId, `${MIND_EVENT_PREFIX}\n[2026-06-02] Ana shipped the redesign`, 'normal', 'system', '2026-06-02T00:00:00.000Z');
|
||||
async function seed(
|
||||
text: string,
|
||||
kind: MemoryKind,
|
||||
opts: { at?: string; scope?: MemoryScope; importance?: MemoryImportance } = {},
|
||||
): Promise<void> {
|
||||
if (opts.at) {
|
||||
// A write cannot set its own creation time, so the clock is moved instead.
|
||||
vi.useFakeTimers({ toFake: ['Date'] });
|
||||
vi.setSystemTime(new Date(opts.at));
|
||||
}
|
||||
await memory.remember({
|
||||
scope: opts.scope ?? PERSONAL_SCOPE,
|
||||
text,
|
||||
kind,
|
||||
importance: opts.importance ?? 'normal',
|
||||
source: 'system',
|
||||
});
|
||||
vi.useRealTimers();
|
||||
}
|
||||
|
||||
it('renders profiles, facts, and chronological events sections', async () => {
|
||||
seedLanes();
|
||||
async function seedLanes(): Promise<void> {
|
||||
await seed('Ana is a designer based in Belgrade who plays Hollow Knight.', 'profile');
|
||||
await seed('User preference: Ana prefers dark mode', 'preference');
|
||||
await seed('Ana shipped the redesign', 'event', { at: '2026-06-02T09:00:00.000Z' });
|
||||
await seed('Ana visited the dentist', 'event', { at: '2026-05-07T09:00:00.000Z' });
|
||||
}
|
||||
|
||||
it('renders profile and chronological event sections', async () => {
|
||||
await seedLanes();
|
||||
const result = await orchestrator.recallMemory('what is happening');
|
||||
|
||||
expect(result.count).toBeGreaterThanOrEqual(4);
|
||||
const text = result.text;
|
||||
expect(text).toContain('## Profiles');
|
||||
expect(text).toContain('- Ana: Ana is a designer');
|
||||
expect(text).toContain('## Memory Facts');
|
||||
expect(text).toContain('Ana prefers dark mode');
|
||||
expect(result.count).toBe(3);
|
||||
expect(text).toContain('## Profiles\n- Ana is a designer based in Belgrade');
|
||||
expect(text).toContain('## Events (chronological)');
|
||||
expect(text).toContain('[2026-05-07] Ana visited the dentist');
|
||||
expect(text).toContain('- [2026-05-07] Ana visited the dentist');
|
||||
expect(text).toContain('- [2026-06-02] Ana shipped the redesign');
|
||||
|
||||
// render order: profiles before facts before events
|
||||
expect(text.indexOf('## Profiles')).toBeLessThan(text.indexOf('## Memory Facts'));
|
||||
expect(text.indexOf('## Memory Facts')).toBeLessThan(text.indexOf('## Events (chronological)'));
|
||||
// profiles before events; events oldest first even though written newest first
|
||||
expect(text.indexOf('## Profiles')).toBeLessThan(text.indexOf('## Events (chronological)'));
|
||||
expect(text.indexOf('dentist')).toBeLessThan(text.indexOf('redesign'));
|
||||
});
|
||||
|
||||
it('explicit-period query gets a dedicated windowed events section', async () => {
|
||||
seedLanes();
|
||||
await seedLanes();
|
||||
const result = await orchestrator.recallMemory('what did Ana do in May 2026?');
|
||||
expect(result.text).toContain('## Events during may 2026');
|
||||
// windowed section carries the in-window event, not the June one
|
||||
const windowed = result.text.slice(result.text.indexOf('## Events during'));
|
||||
expect(windowed).toContain('dentist');
|
||||
expect(windowed).not.toContain('redesign');
|
||||
});
|
||||
|
||||
it('profile frames never double-render as search snippets', async () => {
|
||||
seedLanes();
|
||||
// Query keyword-matches the profile card content — the semantic lane
|
||||
// would surface the profile frame; the dedup rule must keep it out.
|
||||
it('profile memories never double-render as search snippets', async () => {
|
||||
await seedLanes();
|
||||
// The query shares words with the profile, so search finds it too.
|
||||
const result = await orchestrator.recallMemory('Hollow Knight designer Belgrade');
|
||||
const occurrences = result.text.split('Hollow Knight').length - 1;
|
||||
expect(occurrences).toBe(1); // once under ## Profiles, never as a snippet
|
||||
expect(result.text.split('Hollow Knight').length - 1).toBe(1);
|
||||
expect(result.text).not.toContain('## Personal Memory');
|
||||
});
|
||||
|
||||
it('lane-only recall still returns content (no search hits required)', async () => {
|
||||
frames.createIFrame(gopId, `${MIND_FACT_PREFIX}\nUser preference: Ana prefers dark mode`, 'normal', 'system');
|
||||
await seed('Ana is a designer based in Belgrade.', 'profile');
|
||||
const result = await orchestrator.recallMemory('zebra quantum xylophone');
|
||||
expect(result.count).toBeGreaterThan(0);
|
||||
expect(result.text).toContain('## Memory Facts');
|
||||
expect(result.count).toBe(1);
|
||||
expect(result.text).toContain('## Profiles');
|
||||
expect(result.recalled).toEqual(['Ana is a designer based in Belgrade.']);
|
||||
});
|
||||
|
||||
it('leaves temporary profile and event memories out of the lanes', async () => {
|
||||
await seed('Ana might be moving to Lisbon', 'profile', { importance: 'temporary' });
|
||||
await seed('Ana possibly cancelled the trip', 'event', { importance: 'temporary' });
|
||||
const result = await orchestrator.recallMemory('zebra quantum xylophone');
|
||||
expect(result.count).toBe(0);
|
||||
expect(result.text).toBe('');
|
||||
});
|
||||
|
||||
it('renders the 40 most recent events', async () => {
|
||||
for (let day = 1; day <= 41; day++) {
|
||||
const at = new Date(Date.UTC(2026, 0, day, 9)).toISOString();
|
||||
await seed(`Daily log entry ${day}`, 'event', { at });
|
||||
}
|
||||
const result = await orchestrator.recallMemory('zebra quantum xylophone');
|
||||
expect(result.text).not.toContain('Daily log entry 1\n');
|
||||
expect(result.text).toContain('Daily log entry 2\n');
|
||||
expect(result.text).toContain('Daily log entry 41');
|
||||
expect(result.count).toBe(40);
|
||||
});
|
||||
|
||||
it('takes profiles from personal and workspace memory, events from the active scope', async () => {
|
||||
await seed('Ana is a designer based in Belgrade.', 'profile');
|
||||
await seed('Ana leads the Atlas redesign.', 'profile', { scope: workspaceScope('ws-1') });
|
||||
await seed('Atlas kickoff happened', 'event', { scope: workspaceScope('ws-1'), at: '2026-05-04T09:00:00.000Z' });
|
||||
await seed('Ana adopted a cat', 'event', { at: '2026-05-05T09:00:00.000Z' });
|
||||
orchestrator.setWorkspace('ws-1');
|
||||
|
||||
const result = await orchestrator.recallMemory('zebra quantum xylophone');
|
||||
expect(result.text).toContain('Ana is a designer based in Belgrade.');
|
||||
expect(result.text).toContain('Ana leads the Atlas redesign.');
|
||||
expect(result.text).toContain('Atlas kickoff happened');
|
||||
expect(result.text).not.toContain('Ana adopted a cat');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user