test(server): move the remaining server tests onto the memory contract (P1.5)

- Workspace sessions, fleet runs, agent groups, loops, the file indexer,
  external tool runs, chat and the health endpoint are checked against the
  memory store instead of .mind files. Assertions on mind-cache pins and
  releases go with the pins; the drain and cancellation checks stay.
- Delete the sticky-erasure test (harvest import was removed) and the
  session-distillation test (distillation on workspace activation was
  removed).
- The saved-history retry test checks the conversation only: the failed
  user turn is kept in workspace memory by design (#3).
This commit is contained in:
shumeiko.it
2026-10-24 12:50:23 +02:00
parent 74a4e55be0
commit 122b45990e
12 changed files with 274 additions and 785 deletions

View File

@@ -3,7 +3,13 @@ import Fastify from 'fastify';
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import { MindDB } from '@waggle/core';
import {
createInMemoryMemoryStore,
PERSONAL_SCOPE,
workspaceScope,
type MemoryScope,
type MemoryStore,
} from '@waggle/memory-contract';
import type { ExternalRunEvent, ExternalToolRunRequest, ExternalToolRunResult } from '@waggle/agent';
import type { CollaborationWorkerRun } from '@waggle/shared';
import { AgentRunRegistry } from '../../src/local/agent-run-registry.js';
@@ -142,8 +148,12 @@ describe('external tool run routes', () => {
const dataDir = tempDir();
const workspaceDir = path.join(dataDir, 'workspace-files');
fs.mkdirSync(workspaceDir);
const personal = new MindDB(path.join(dataDir, 'personal.mind'));
const workspace = new MindDB(path.join(dataDir, 'workspace.mind'));
const memory = createInMemoryMemoryStore();
/** The newest memory of a scope, with its metadata serialized. */
const latest = async (scope: MemoryScope): Promise<{ content: string; metadata: string }> => {
const [record] = await memory.list({ scopes: [scope], limit: 1 });
return { content: record.text, metadata: JSON.stringify(record.metadata) };
};
const registryPath = path.join(dataDir, 'agent-runs.json');
const registry = new AgentRunRegistry(registryPath);
const bus = new SignalBus();
@@ -172,14 +182,7 @@ describe('external tool run routes', () => {
if (value.output !== undefined) traceOutputs.push(value.output);
},
} as never);
server.decorate('multiMind', { personal } as never);
server.decorate('mindCache', {
acquire: (id: string) => {
if (id !== 'workspace-a') throw new Error(`Unexpected workspace: ${id}`);
return workspace;
},
release: () => undefined,
} as never);
server.decorate('memory', memory);
server.decorate('externalCollaborationRuntime', collaborationRuntime);
server.decorate('externalToolDetector', async () => ({
platform: 'win32', detectedAt: new Date().toISOString(),
@@ -238,12 +241,8 @@ describe('external tool run routes', () => {
);
expect(registry.get(body.runs[0].runId)?.memoryRefs).toMatchObject({ status: 'complete' });
const personalFrame = personal.getDatabase().prepare(
'SELECT content, metadata FROM memory_frames ORDER BY id DESC LIMIT 1',
).get() as { content: string; metadata: string };
const workspaceFrame = workspace.getDatabase().prepare(
'SELECT content, metadata FROM memory_frames ORDER BY id DESC LIMIT 1',
).get() as { content: string; metadata: string };
const personalFrame = await latest(PERSONAL_SCOPE);
const workspaceFrame = await latest(workspaceScope('workspace-a'));
const personalMetadata = JSON.parse(personalFrame.metadata) as {
injection?: { safe?: boolean; flags?: string[] };
};
@@ -287,9 +286,7 @@ describe('external tool run routes', () => {
&& message.content.runId === semanticBody.runs[0].runId
&& message.content.phase === 'completed'),
'semantic session result was not published');
const semanticFrameMetadata = (workspace.getDatabase().prepare(
'SELECT metadata FROM memory_frames ORDER BY id DESC LIMIT 1',
).get() as { metadata: string }).metadata;
const semanticFrameMetadata = (await latest(workspaceScope('workspace-a'))).metadata;
const semanticShare = bus.query().find((message) =>
message.subtype === 'routed_share'
&& message.content.runId === semanticBody.runs[0].runId
@@ -312,12 +309,8 @@ describe('external tool run routes', () => {
return refs !== undefined && refs.status !== 'pending';
}, 'benign external result was not persisted', 400);
const benignPersonalContent = (personal.getDatabase().prepare(
'SELECT content FROM memory_frames ORDER BY id DESC LIMIT 1',
).get() as { content: string }).content;
const benignWorkspaceContent = (workspace.getDatabase().prepare(
'SELECT content FROM memory_frames ORDER BY id DESC LIMIT 1',
).get() as { content: string }).content;
const benignPersonalContent = (await latest(PERSONAL_SCOPE)).content;
const benignWorkspaceContent = (await latest(workspaceScope('workspace-a'))).content;
await waitFor(() => bus.query().some((message) =>
message.subtype === 'routed_share'
&& message.content.phase === 'completed'
@@ -377,8 +370,6 @@ describe('external tool run routes', () => {
} finally {
await server.close();
registry.close();
workspace.close();
personal.close();
}
});