test: read run memories through the contract in the live collaboration test (P1.5)
The live external-agent test (skipped unless WAGGLE_LIVE_EXTERNAL_AGENTS=1) looked up run memory receipts as frames in server.multiMind and server.mindCache, which the server no longer has. Look them up with server.memory.get and check that personal and workspace receipts sit in their own scopes. Also type the prompt assembler's bulk fixture as RecallFrame.
This commit is contained in:
@@ -108,7 +108,7 @@ describe('PromptAssembler.assemble', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('small tier caps State frames at 3', () => {
|
it('small tier caps State frames at 3', () => {
|
||||||
const frames: MemoryFrame[] = [];
|
const frames: RecallFrame[] = [];
|
||||||
for (let i = 0; i < 10; i++) {
|
for (let i = 0; i < 10; i++) {
|
||||||
frames.push(frame(`State frame ${i}`, { importance: 'important' }));
|
frames.push(frame(`State frame ${i}`, { importance: 'important' }));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import os from 'node:os';
|
|||||||
import path from 'node:path';
|
import path from 'node:path';
|
||||||
import type { FastifyInstance } from 'fastify';
|
import type { FastifyInstance } from 'fastify';
|
||||||
import { detectInstalledTools, getToolRegistry, runExternalTool } from '@waggle/agent';
|
import { detectInstalledTools, getToolRegistry, runExternalTool } from '@waggle/agent';
|
||||||
import { FrameStore } from '@waggle/core';
|
import { scopeKey, workspaceScope } from '@waggle/memory-contract';
|
||||||
import { AgentRunRegistry } from '../../packages/server/src/local/agent-run-registry.js';
|
import { AgentRunRegistry } from '../../packages/server/src/local/agent-run-registry.js';
|
||||||
import { buildLocalServer } from '../../packages/server/src/local/index.js';
|
import { buildLocalServer } from '../../packages/server/src/local/index.js';
|
||||||
import { injectWithAuth } from '../../packages/server/tests/test-utils.js';
|
import { injectWithAuth } from '../../packages/server/tests/test-utils.js';
|
||||||
@@ -222,41 +222,43 @@ describeLive('live external-agent collaboration', () => {
|
|||||||
expect(durable?.memoryRefs, diagnostic).toEqual(server.agentRunRegistry.get(id)?.memoryRefs);
|
expect(durable?.memoryRefs, diagnostic).toEqual(server.agentRunRegistry.get(id)?.memoryRefs);
|
||||||
}
|
}
|
||||||
|
|
||||||
const personalFrames = new FrameStore(server.multiMind.personal);
|
|
||||||
for (const run of runs) {
|
for (const run of runs) {
|
||||||
const workspaceId = run.kind === 'worker' ? run.workspaceId : undefined;
|
const workspaceId = run.kind === 'worker' ? run.workspaceId : undefined;
|
||||||
expect(Object.keys(run.memoryRefs.workspaceFrameIds), diagnostic).toEqual([workspaceId]);
|
expect(Object.keys(run.memoryRefs.workspaceFrameIds), diagnostic).toEqual([workspaceId]);
|
||||||
const personal = run.memoryRefs.personalFrameIds.map((id) => personalFrames.getById(id));
|
const personal = await Promise.all(
|
||||||
let workspace = [] as ReturnType<FrameStore['getById']>[];
|
run.memoryRefs.personalFrameIds.map((id) => server.memory.get(id)),
|
||||||
if (workspaceId) {
|
);
|
||||||
const workspaceMind = server.mindCache.acquire(workspaceId);
|
const workspace = workspaceId
|
||||||
try {
|
? await Promise.all(
|
||||||
const frames = new FrameStore(workspaceMind);
|
run.memoryRefs.workspaceFrameIds[workspaceId].map((id) => server.memory.get(id)),
|
||||||
workspace = run.memoryRefs.workspaceFrameIds[workspaceId].map((id) => frames.getById(id));
|
)
|
||||||
} finally {
|
: [];
|
||||||
server.mindCache.release(workspaceId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect(personal.length, diagnostic).toBeGreaterThan(0);
|
expect(personal.length, diagnostic).toBeGreaterThan(0);
|
||||||
expect(workspace.length, diagnostic).toBeGreaterThan(0);
|
expect(workspace.length, diagnostic).toBeGreaterThan(0);
|
||||||
for (const frame of [...personal, ...workspace]) {
|
for (const memory of personal) {
|
||||||
expect(frame, diagnostic).toBeDefined();
|
expect(memory?.scope.kind, diagnostic).toBe('personal');
|
||||||
const metadata = JSON.parse(frame?.metadata ?? '{}') as Record<string, unknown>;
|
}
|
||||||
|
for (const memory of workspace) {
|
||||||
|
expect(memory && scopeKey(memory.scope), diagnostic).toBe(scopeKey(workspaceScope(workspaceId!)));
|
||||||
|
}
|
||||||
|
for (const memory of [...personal, ...workspace]) {
|
||||||
|
expect(memory, diagnostic).not.toBeNull();
|
||||||
|
const metadata = memory?.metadata ?? {};
|
||||||
expect(metadata).toMatchObject({
|
expect(metadata).toMatchObject({
|
||||||
runId: run.id,
|
runId: run.id,
|
||||||
roomId: run.roomId,
|
roomId: run.roomId,
|
||||||
workspaceId: run.kind === 'worker' ? run.workspaceId : undefined,
|
workspaceId: run.kind === 'worker' ? run.workspaceId : undefined,
|
||||||
toolId: run.executor.toolId,
|
toolId: run.executor.toolId,
|
||||||
});
|
});
|
||||||
expect(frame?.content.includes(run.id), diagnostic).toBe(true);
|
expect(memory?.text.includes(run.id), diagnostic).toBe(true);
|
||||||
for (const forbiddenPath of [dataDir, sourceWorkspaceDir, synthesisWorkspaceDir]) {
|
for (const forbiddenPath of [dataDir, sourceWorkspaceDir, synthesisWorkspaceDir]) {
|
||||||
expect(frame?.content.includes(forbiddenPath), diagnostic).toBe(false);
|
expect(memory?.text.includes(forbiddenPath), diagnostic).toBe(false);
|
||||||
expect(JSON.stringify(metadata).includes(forbiddenPath), diagnostic).toBe(false);
|
expect(JSON.stringify(metadata).includes(forbiddenPath), diagnostic).toBe(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const expectedSummary = run.result?.summary.trim() ?? '';
|
const expectedSummary = run.result?.summary.trim() ?? '';
|
||||||
expect(personal.some((frame) => frame?.content.includes(expectedSummary)), diagnostic).toBe(true);
|
expect(personal.some((memory) => memory?.text.includes(expectedSummary)), diagnostic).toBe(true);
|
||||||
expect(workspace.some((frame) => frame?.content.includes(expectedSummary)), diagnostic).toBe(true);
|
expect(workspace.some((memory) => memory?.text.includes(expectedSummary)), diagnostic).toBe(true);
|
||||||
}
|
}
|
||||||
expect(new Set(room?.memoryRefs.personalFrameIds)).toEqual(
|
expect(new Set(room?.memoryRefs.personalFrameIds)).toEqual(
|
||||||
new Set(runs.flatMap((run) => run.memoryRefs.personalFrameIds)),
|
new Set(runs.flatMap((run) => run.memoryRefs.personalFrameIds)),
|
||||||
|
|||||||
Reference in New Issue
Block a user