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.
94 lines
3.8 KiB
TypeScript
94 lines
3.8 KiB
TypeScript
import { describe, it, expect, beforeEach, vi } from 'vitest';
|
|
import { createInMemoryMemoryStore, PERSONAL_SCOPE, type MemoryStore } from '@waggle/memory-contract';
|
|
import { Orchestrator } from '../src/orchestrator.js';
|
|
import { PromptAssembler, type RecalledMemory } from '../src/prompt-assembler.js';
|
|
|
|
/**
|
|
* W4.5 โ PromptAssembler recall fixes (plan ยง3 bug #9):
|
|
* - double-compute: buildAssembledPrompt reuses the caller's recallMemory
|
|
* output (opts.recalledText) instead of re-running searches
|
|
* - the assembler renders the pre-rendered multi-lane block verbatim,
|
|
* preserving the W4.3b lane sections the frame renderer can't produce
|
|
* (- double-inject is a chat.ts concat fix: recalledContext is no longer
|
|
* appended when the assembled prompt already carries the recall block)
|
|
*/
|
|
|
|
describe('W4.5 โ assembler consumes pre-rendered recall', () => {
|
|
it('renders renderedText verbatim as the recall section', () => {
|
|
const recalled: RecalledMemory = {
|
|
workspace: [],
|
|
personal: [],
|
|
scanSafe: true,
|
|
renderedText: '# Recalled Memories\n## Personal Memory\n- [2026-05-07, normal] User preference: Ana prefers dark mode',
|
|
};
|
|
const out = new PromptAssembler().assemble({
|
|
corePrompt: 'You are Waggle.',
|
|
persona: null,
|
|
context: { stateFrames: [], recentChanges: [], activeWork: [], keyEntities: [], personalPreferences: [] },
|
|
recalled,
|
|
query: 'dark mode?',
|
|
tier: 'standard',
|
|
}, {});
|
|
expect(out.system).toContain('## Personal Memory');
|
|
expect(out.system).toContain('Ana prefers dark mode');
|
|
expect(out.debug.sectionsIncluded).toContain('Recalled memory');
|
|
});
|
|
|
|
it('ignores renderedText when scanSafe is false', () => {
|
|
const recalled: RecalledMemory = {
|
|
workspace: [],
|
|
personal: [],
|
|
scanSafe: false,
|
|
renderedText: '# Recalled Memories\npoisoned content',
|
|
};
|
|
const out = new PromptAssembler().assemble({
|
|
corePrompt: 'You are Waggle.',
|
|
persona: null,
|
|
context: { stateFrames: [], recentChanges: [], activeWork: [], keyEntities: [], personalPreferences: [] },
|
|
recalled,
|
|
query: 'q',
|
|
tier: 'standard',
|
|
}, {});
|
|
expect(out.system).not.toContain('poisoned content');
|
|
});
|
|
});
|
|
|
|
describe('W4.5 โ buildAssembledPrompt skips searches when recalledText given', () => {
|
|
let memory: MemoryStore;
|
|
let orchestrator: Orchestrator;
|
|
|
|
beforeEach(() => {
|
|
memory = createInMemoryMemoryStore();
|
|
orchestrator = new Orchestrator({ memory });
|
|
});
|
|
|
|
it('uses the provided multi-lane block without re-running searches', async () => {
|
|
await memory.remember({ scope: PERSONAL_SCOPE, text: 'Ana prefers dark mode' });
|
|
const search = vi.spyOn(memory, 'search');
|
|
|
|
const assembled = await orchestrator.buildAssembledPrompt('dark mode?', null, {
|
|
recalledText: '# Recalled Memories\n## Profiles\n- Ana: designer in Belgrade\n## Events (chronological)\n- [2026-05-07] Ana visited the dentist',
|
|
});
|
|
expect(assembled.system).toContain('## Profiles');
|
|
expect(assembled.system).toContain('designer in Belgrade');
|
|
expect(search).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it('searches personal and workspace memory itself when no recalledText is given', async () => {
|
|
await memory.remember({ scope: PERSONAL_SCOPE, text: 'Ana prefers dark mode' });
|
|
orchestrator.setWorkspace('ws-1');
|
|
const search = vi.spyOn(memory, 'search');
|
|
|
|
const assembled = await orchestrator.buildAssembledPrompt('dark mode?', null);
|
|
expect(search).toHaveBeenCalledTimes(2);
|
|
expect(assembled.system).toContain('Ana prefers dark mode');
|
|
});
|
|
|
|
it('empty recalledText means no recall section (recall was empty/blocked)', async () => {
|
|
const assembled = await orchestrator.buildAssembledPrompt('anything', null, {
|
|
recalledText: '',
|
|
});
|
|
expect(assembled.debug.sectionsIncluded).not.toContain('Recalled memory');
|
|
});
|
|
});
|