Files
waggle-os/packages/agent/tests/orchestrator-workspace-recall.test.ts
shumeiko.it ac23bbd7a6 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.
2026-10-24 13:19:06 +02:00

104 lines
4.8 KiB
TypeScript

/**
* recallMemory with a workspace scope active versus personal memory only.
*/
import { describe, it, expect, beforeEach } from 'vitest';
import {
createInMemoryMemoryStore,
PERSONAL_SCOPE,
workspaceScope,
type MemoryStore,
} from '@waggle/memory-contract';
import { Orchestrator } from '../src/orchestrator.js';
describe('Orchestrator recall — workspace scope', () => {
let memory: MemoryStore;
let orchestrator: Orchestrator;
beforeEach(async () => {
memory = createInMemoryMemoryStore();
orchestrator = new Orchestrator({ memory });
await memory.remember({ scope: PERSONAL_SCOPE, text: 'I like release notes with a summary first', source: 'user_stated' });
await memory.remember({ scope: workspaceScope('ws-1'), text: 'Atlas release notes go out on Tuesday', source: 'tool_verified' });
await memory.remember({ scope: workspaceScope('ws-2'), text: 'Borealis release notes are skipped this quarter' });
});
it('recalls personal memory only when no workspace is active', async () => {
const result = await orchestrator.recallMemory('release notes');
expect(result.text).toContain('## Personal Memory');
expect(result.text).toContain('I like release notes with a summary first');
expect(result.text).not.toContain('Cross-workspace personal knowledge');
expect(result.text).not.toContain('## Workspace Memory');
expect(result.text).not.toContain('Atlas');
expect(result.text).not.toContain('Borealis');
expect(result.count).toBe(1);
});
it('recalls the active workspace first and personal memory as cross-workspace knowledge', async () => {
orchestrator.setWorkspace('ws-1');
const result = await orchestrator.recallMemory('release notes');
const workspaceIdx = result.text.indexOf('## Workspace Memory');
const personalIdx = result.text.indexOf('## Personal Memory');
expect(workspaceIdx).toBeGreaterThan(-1);
expect(personalIdx).toBeGreaterThan(workspaceIdx);
expect(result.text).toContain('Atlas release notes go out on Tuesday');
expect(result.text).toContain('_(Cross-workspace personal knowledge — not specific to this workspace)_');
expect(result.text).not.toContain('Borealis');
expect(result.count).toBe(2);
expect(result.recalledFrames).toEqual([{ source: 'tool_verified' }, { source: 'user_stated' }]);
});
it('stops recalling workspace memory after switching back to personal only', async () => {
orchestrator.setWorkspace('ws-1');
expect((await orchestrator.recallMemory('release notes')).text).toContain('Atlas');
orchestrator.setWorkspace(null);
expect((await orchestrator.recallMemory('release notes')).text).not.toContain('Atlas');
});
it('switches recall to the newly selected workspace', async () => {
orchestrator.setWorkspace('ws-1');
orchestrator.setWorkspace('ws-2');
const result = await orchestrator.recallMemory('release notes');
expect(result.text).toContain('Borealis release notes are skipped this quarter');
expect(result.text).not.toContain('Atlas');
});
it('returns nothing when no readable scope holds memory, even if another workspace does', async () => {
const fresh = createInMemoryMemoryStore();
await fresh.remember({ scope: workspaceScope('ws-2'), text: 'Borealis release notes are skipped this quarter' });
const other = new Orchestrator({ memory: fresh });
other.setWorkspace('ws-1');
expect(await other.recallMemory('release notes')).toEqual({ text: '', count: 0, recalled: [], recalledFrames: [] });
});
it('answers a catch-up from recent workspace memory without matching words', async () => {
await memory.remember({ scope: workspaceScope('ws-1'), text: 'Vendor contract signed with Northwind', kind: 'decision' });
orchestrator.setWorkspace('ws-1');
const result = await orchestrator.recallMemory('catch me up');
expect(result.text).toContain('Vendor contract signed with Northwind');
expect(result.text).toContain('Atlas release notes go out on Tuesday');
expect(result.text).not.toContain('Borealis');
});
it('treats a catch-up phrase as an ordinary search without a workspace', async () => {
const result = await orchestrator.recallMemory('catch me up');
// No shared words with any personal memory and no workspace to summarize.
expect(result.count).toBe(0);
});
it('leaves temporary memories out of both scopes', async () => {
await memory.remember({ scope: PERSONAL_SCOPE, text: 'Maybe release notes should be weekly', importance: 'temporary' });
await memory.remember({ scope: workspaceScope('ws-1'), text: 'Draft release notes idea, unverified', importance: 'temporary' });
orchestrator.setWorkspace('ws-1');
const result = await orchestrator.recallMemory('release notes');
expect(result.text).not.toContain('Maybe release notes should be weekly');
expect(result.text).not.toContain('Draft release notes idea');
});
});