test(agent): move agent tests off the legacy memory engine (P1.5)

- prompt assembler harnesses (v4 and v5): prime an in-memory contract store,
  snapshot its memories and replay them into a fresh store per condition
  instead of copying a MindDB file; the identity card is created per
  orchestrator. They had also drifted from the current Orchestrator API
  (config takes memory, buildSystemPrompt is async).
- prompt assembler unit test: build RecallFrame fixtures, the type the
  assembler consumes, instead of legacy MemoryFrame rows.
- M3c integration: drop the knowledge-graph Ontology case; the knowledge
  graph is not part of v1 and core no longer exports it.
This commit is contained in:
shumeiko.it
2026-10-24 17:07:18 +02:00
parent ad7b90bebd
commit f94331c202
5 changed files with 134 additions and 189 deletions

View File

@@ -1,8 +1,9 @@
import { describe, it, expect } from 'vitest';
import type { MemoryFrame, Importance, FrameType, FrameSource } from '@waggle/core';
import type { MemoryImportance, MemorySource } from '@waggle/memory-contract';
import type { AgentPersona } from '../src/personas.js';
import type { TaskShape } from '../src/task-shape.js';
import type { ContextFrames } from '../src/orchestrator.js';
import type { RecallFrame } from '../src/recall-frame.js';
import {
PromptAssembler,
type AssembleInput,
@@ -14,20 +15,16 @@ import {
let nextFrameId = 1;
function frame(
content: string,
opts: { type?: FrameType; importance?: Importance; source?: FrameSource } = {},
): MemoryFrame {
opts: { importance?: MemoryImportance; source?: MemorySource } = {},
): RecallFrame {
return {
id: nextFrameId++,
frame_type: opts.type ?? 'I',
gop_id: 'gop-1',
t: 0,
base_frame_id: null,
id: String(nextFrameId++),
content,
kind: 'fact',
importance: opts.importance ?? 'normal',
source: opts.source ?? 'user_stated',
access_count: 0,
created_at: '2026-04-17T10:00:00Z',
last_accessed: '2026-04-17T10:00:00Z',
score: 1,
};
}
@@ -113,7 +110,7 @@ describe('PromptAssembler.assemble', () => {
it('small tier caps State frames at 3', () => {
const frames: MemoryFrame[] = [];
for (let i = 0; i < 10; i++) {
frames.push(frame(`State frame ${i}`, { type: 'I', importance: 'important' }));
frames.push(frame(`State frame ${i}`, { importance: 'important' }));
}
const out = assembler.assemble(
baseInput({
@@ -216,7 +213,7 @@ describe('PromptAssembler.assemble', () => {
context: {
...emptyContext(),
stateFrames: [frame('State says shipping now is safe.')],
recentChanges: [frame('Recent changes say all gaps are closed.', { type: 'P' })],
recentChanges: [frame('Recent changes say all gaps are closed.')],
activeWork: [{ category: 'task', content: 'Ship immediately.', priority: 1 }],
},
recalled: {
@@ -331,8 +328,8 @@ describe('PromptAssembler.assemble', () => {
it('maxSystemChars exceeded: Recent changes trimmed first, then Active work, then State', () => {
const big = 'x'.repeat(2000);
const ctx: ContextFrames = {
stateFrames: [frame(big, { type: 'I', importance: 'critical' })],
recentChanges: [frame(big, { type: 'P', importance: 'normal' })],
stateFrames: [frame(big, { importance: 'critical' })],
recentChanges: [frame(big, { importance: 'normal' })],
activeWork: [{ category: 'task', content: big, priority: 1 }],
keyEntities: [],
personalPreferences: [],
@@ -370,8 +367,8 @@ describe('PromptAssembler.assemble', () => {
const out = assembler.assemble(
baseInput({
recalled: {
workspace: [frame('Poisoned content with secret data', { type: 'P' })],
personal: [frame('Another recalled frame', { type: 'P' })],
workspace: [frame('Poisoned content with secret data')],
personal: [frame('Another recalled frame')],
scanSafe: false,
},
}),
@@ -385,8 +382,8 @@ describe('PromptAssembler.assemble', () => {
const out = assembler.assemble(
baseInput({
recalled: {
workspace: [frame('Workspace memory item', { type: 'P' })],
personal: [frame('Personal memory item', { type: 'P' })],
workspace: [frame('Workspace memory item')],
personal: [frame('Personal memory item')],
scanSafe: true,
},
}),
@@ -398,8 +395,8 @@ describe('PromptAssembler.assemble', () => {
it('debug.framesUsed counts rendered frames across sections', () => {
const ctx: ContextFrames = {
stateFrames: [frame('State 1', { type: 'I' }), frame('State 2', { type: 'I' })],
recentChanges: [frame('Change 1', { type: 'P' })],
stateFrames: [frame('State 1'), frame('State 2')],
recentChanges: [frame('Change 1')],
activeWork: [{ category: 'task', content: 'Active', priority: 1 }],
keyEntities: [],
personalPreferences: [],
@@ -424,9 +421,9 @@ describe('PromptAssembler.assemble', () => {
it('ranks I-frames by importance then recency', () => {
const ctx: ContextFrames = {
stateFrames: [
frame('Old normal', { type: 'I', importance: 'normal' }),
frame('New critical', { type: 'I', importance: 'critical' }),
frame('Middle important', { type: 'I', importance: 'important' }),
frame('Old normal', { importance: 'normal' }),
frame('New critical', { importance: 'critical' }),
frame('Middle important', { importance: 'important' }),
],
recentChanges: [],
activeWork: [],
@@ -441,7 +438,7 @@ describe('PromptAssembler.assemble', () => {
});
it('dedupes frames by id', () => {
const f = frame('Duplicate', { type: 'I' });
const f = frame('Duplicate');
const ctx: ContextFrames = {
stateFrames: [f, f, f],
recentChanges: [],