/** * 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'); }); });