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,46 +1,46 @@
|
||||
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
||||
import { MindDB } from '@waggle/core';
|
||||
import { TEMPORAL_GUIDANCE } from '@waggle/hive-mind-core';
|
||||
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
|
||||
import { TEMPORAL_GUIDANCE } from '@waggle/core';
|
||||
import { createInMemoryMemoryStore, PERSONAL_SCOPE, workspaceScope, 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.1a — production port of the benchmark-proven temporal recall surface
|
||||
* (W4-PRODUCTION-PORT-PLAN-2026-06-11.md §5, components #1 + #2).
|
||||
* W4.1a — production port of the benchmark-proven temporal recall surface.
|
||||
*
|
||||
* #1 Date rendering + TEMPORAL_GUIDANCE: recallMemory's rendered block carries
|
||||
* a reference-date anchor line and the W1-grade temporal guidance fragment
|
||||
* (granularity clause — the #1 LoCoMo temporal lever, 84.7 final).
|
||||
* #2 Unconditional importance lane: critical/important frames reach recall on
|
||||
* EVERY query (benchmark fetchImportantFrames K=5), not only on catch-up
|
||||
* regex matches.
|
||||
* a reference-date anchor line and the temporal guidance fragment.
|
||||
* #2 Unconditional importance lane: critical/important memories reach recall
|
||||
* on EVERY query, not only on catch-up regex matches.
|
||||
* #3 Date window: a query naming an explicit period restricts search to
|
||||
* memories created in it, and falls back to unwindowed search when the
|
||||
* window holds nothing.
|
||||
*/
|
||||
|
||||
describe('W4.1a — temporal recall surface + unconditional importance lane', () => {
|
||||
let db: MindDB;
|
||||
let memory: MemoryStore;
|
||||
let orchestrator: Orchestrator;
|
||||
|
||||
beforeEach(() => {
|
||||
db = new MindDB(':memory:');
|
||||
orchestrator = new Orchestrator({
|
||||
db,
|
||||
embedder: new MockEmbedder(),
|
||||
});
|
||||
memory = createInMemoryMemoryStore();
|
||||
orchestrator = new Orchestrator({ memory });
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
db.close();
|
||||
vi.useRealTimers();
|
||||
});
|
||||
|
||||
describe('#1 TEMPORAL_GUIDANCE upgraded to W1 wording', () => {
|
||||
/** A write cannot set its own creation time, so the clock is moved instead. */
|
||||
async function rememberAt(iso: string, text: string): Promise<void> {
|
||||
vi.useFakeTimers({ toFake: ['Date'] });
|
||||
vi.setSystemTime(new Date(iso));
|
||||
await memory.remember({ scope: PERSONAL_SCOPE, text });
|
||||
vi.useRealTimers();
|
||||
}
|
||||
|
||||
describe('#1 TEMPORAL_GUIDANCE wording', () => {
|
||||
it('carries the granularity clause and relative-date worked example', () => {
|
||||
// W1 failure mining: 22 ours-only temporal fails emitted a confident exact
|
||||
// ISO day 1-7 days off where a coarse answer would have been judged correct.
|
||||
expect(TEMPORAL_GUIDANCE).toMatch(/granularit/i);
|
||||
expect(TEMPORAL_GUIDANCE).toMatch(/confidently wrong exact day/i);
|
||||
// Worked relative-date arithmetic example (Memori instruction 5 lineage)
|
||||
expect(TEMPORAL_GUIDANCE).toMatch(/last year/i);
|
||||
// Latest-wins contradiction clause preserved from the shipped version
|
||||
expect(TEMPORAL_GUIDANCE).toMatch(/most recent version is correct/i);
|
||||
});
|
||||
});
|
||||
@@ -59,22 +59,18 @@ describe('W4.1a — temporal recall surface + unconditional importance lane', ()
|
||||
expect(result.text).toContain('timestamped [YYYY-MM-DD]');
|
||||
});
|
||||
|
||||
it('anchor date equals the most recent rendered frame date', async () => {
|
||||
await orchestrator.executeTool('save_memory', {
|
||||
content: 'User preference: weekly report goes out on Fridays',
|
||||
importance: 'important',
|
||||
});
|
||||
const today = new Date().toISOString().slice(0, 10);
|
||||
it('anchor date equals the most recent rendered memory date', async () => {
|
||||
await rememberAt('2026-03-02T09:00:00.000Z', 'Weekly report template was agreed');
|
||||
await rememberAt('2026-04-15T09:00:00.000Z', 'Weekly report moved to Fridays');
|
||||
|
||||
const result = await orchestrator.recallMemory('weekly report');
|
||||
expect(result.text).toContain(`Reference date (most recent memory): ${today}`);
|
||||
expect(result.text).toContain('Reference date (most recent memory): 2026-04-15');
|
||||
});
|
||||
});
|
||||
|
||||
describe('#2 unconditional importance lane', () => {
|
||||
it('recalls a critical frame on a semantically unrelated query', async () => {
|
||||
// Disjoint vocabulary: no keyword overlap with the query, so FTS cannot
|
||||
// surface it and MockEmbedder similarity is meaningless — only the
|
||||
// unconditional importance lane can deliver this frame.
|
||||
it('recalls a critical memory on a semantically unrelated query', async () => {
|
||||
// Disjoint vocabulary: search cannot surface it; only the importance lane can.
|
||||
await orchestrator.executeTool('save_memory', {
|
||||
content: 'Production launch is locked for June 20',
|
||||
importance: 'critical',
|
||||
@@ -84,34 +80,40 @@ describe('W4.1a — temporal recall surface + unconditional importance lane', ()
|
||||
expect(result.text).toContain('Production launch is locked for June 20');
|
||||
});
|
||||
|
||||
it('does not duplicate a frame surfaced by both semantic and importance lanes', async () => {
|
||||
it('does not duplicate a memory surfaced by both semantic and importance lanes', async () => {
|
||||
await orchestrator.executeTool('save_memory', {
|
||||
content: 'Production launch is locked for June 20',
|
||||
importance: 'critical',
|
||||
});
|
||||
|
||||
const result = await orchestrator.recallMemory('production launch');
|
||||
const occurrences = result.text.split('Production launch is locked for June 20').length - 1;
|
||||
expect(occurrences).toBe(1);
|
||||
expect(result.text.split('Production launch is locked for June 20').length - 1).toBe(1);
|
||||
});
|
||||
|
||||
it('date-windowed query with no in-window frames falls back to unwindowed recall', async () => {
|
||||
// W4.1b graceful degradation: "in May 2019" parses to a window that
|
||||
// matches nothing (frame was created today) — recall must fall back
|
||||
// rather than return empty.
|
||||
await orchestrator.executeTool('save_memory', {
|
||||
content: 'User preference: weekly report goes out on Fridays',
|
||||
importance: 'important',
|
||||
});
|
||||
it('caps the lane at five memories, critical before important', async () => {
|
||||
for (let i = 1; i <= 6; i++) {
|
||||
await memory.remember({ scope: PERSONAL_SCOPE, text: `Important constraint number ${i}`, importance: 'important' });
|
||||
}
|
||||
await memory.remember({ scope: PERSONAL_SCOPE, text: 'Critical constraint alpha', importance: 'critical' });
|
||||
|
||||
const result = await orchestrator.recallMemory('what did the weekly report say in May 2019');
|
||||
expect(result.text).toContain('weekly report goes out on Fridays');
|
||||
const result = await orchestrator.recallMemory('zebra xylophone');
|
||||
expect(result.count).toBe(5);
|
||||
const lines = result.text.split('\n').filter(l => l.includes('constraint'));
|
||||
expect(lines[0]).toContain('Critical constraint alpha');
|
||||
});
|
||||
|
||||
it('importance lane respects the temporary/deprecated exclusion', async () => {
|
||||
// temporary frames must never re-enter the prompt as authoritative recall
|
||||
// (R2 sign-gate) — the lane SQL only selects critical/important, so a
|
||||
// temporary frame stays out even on unrelated queries.
|
||||
it('takes the lane from the active workspace only', async () => {
|
||||
await memory.remember({ scope: PERSONAL_SCOPE, text: 'Personal critical rule about tea', importance: 'critical' });
|
||||
await memory.remember({ scope: workspaceScope('ws-1'), text: 'Workspace critical rule about deploys', importance: 'critical' });
|
||||
orchestrator.setWorkspace('ws-1');
|
||||
|
||||
const result = await orchestrator.recallMemory('zebra xylophone');
|
||||
expect(result.text).toContain('Workspace critical rule about deploys');
|
||||
expect(result.text).not.toContain('Personal critical rule about tea');
|
||||
});
|
||||
|
||||
it('importance lane respects the temporary exclusion', async () => {
|
||||
// temporary memories must never re-enter the prompt as authoritative recall (R2 sign-gate)
|
||||
await orchestrator.executeTool('save_memory', {
|
||||
content: 'Scratch note: half-finished thought',
|
||||
importance: 'temporary',
|
||||
@@ -121,4 +123,34 @@ describe('W4.1a — temporal recall surface + unconditional importance lane', ()
|
||||
expect(result.text).not.toContain('Scratch note');
|
||||
});
|
||||
});
|
||||
|
||||
describe('#3 date window', () => {
|
||||
it('restricts search to memories created in the named period', async () => {
|
||||
await rememberAt('2026-05-12T10:00:00.000Z', 'Weekly report covered the hiring plan');
|
||||
await rememberAt('2026-06-09T10:00:00.000Z', 'Weekly report covered the budget review');
|
||||
|
||||
const result = await orchestrator.recallMemory('what did the weekly report say in May 2026');
|
||||
expect(result.text).toContain('hiring plan');
|
||||
expect(result.text).not.toContain('budget review');
|
||||
});
|
||||
|
||||
it('includes memories from the first and last day of the window', async () => {
|
||||
await rememberAt('2026-05-01T00:00:01.000Z', 'Weekly report opened the month');
|
||||
await rememberAt('2026-05-31T23:59:59.000Z', 'Weekly report closed the month');
|
||||
|
||||
const result = await orchestrator.recallMemory('weekly report in May 2026');
|
||||
expect(result.text).toContain('opened the month');
|
||||
expect(result.text).toContain('closed the month');
|
||||
});
|
||||
|
||||
it('falls back to unwindowed recall when the window holds nothing', async () => {
|
||||
await orchestrator.executeTool('save_memory', {
|
||||
content: 'User preference: weekly report goes out on Fridays',
|
||||
importance: 'normal',
|
||||
});
|
||||
|
||||
const result = await orchestrator.recallMemory('what did the weekly report say in May 2019');
|
||||
expect(result.text).toContain('weekly report goes out on Fridays');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user