test(server): cover background extraction, the legacy memory copy and run results
This commit is contained in:
49
packages/server/tests/local/run-memory.test.ts
Normal file
49
packages/server/tests/local/run-memory.test.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import {
|
||||
createInMemoryMemoryStore,
|
||||
PERSONAL_SCOPE,
|
||||
workspaceScope,
|
||||
type MemoryStore,
|
||||
} from '@waggle/memory-contract';
|
||||
import { recordRunResult } from '../../src/local/run-memory.js';
|
||||
|
||||
const input = {
|
||||
workspaceId: 'ws1',
|
||||
personalText: '[Agent run]\nRun: r1\nSummary: done',
|
||||
workspaceText: '[Agent run result]\nRun: r1\nResult: done',
|
||||
metadata: { runId: 'r1', source: 'fleet', kind: 'worker' },
|
||||
};
|
||||
|
||||
describe('recordRunResult', () => {
|
||||
it('writes an index entry to personal memory and the result to the workspace', async () => {
|
||||
const memory = createInMemoryMemoryStore();
|
||||
const refs = await recordRunResult(memory, input);
|
||||
expect(refs.status).toBe('complete');
|
||||
const [personal] = await memory.list({ scopes: [PERSONAL_SCOPE] });
|
||||
const [workspace] = await memory.list({ scopes: [workspaceScope('ws1')] });
|
||||
expect(refs.personalFrameIds).toEqual([personal!.id]);
|
||||
expect(refs.workspaceFrameIds).toEqual({ ws1: [workspace!.id] });
|
||||
expect(workspace).toMatchObject({ kind: 'note', origin: 'agent-runs', source: 'agent_inferred' });
|
||||
});
|
||||
|
||||
it('renames metadata keys the contract reserves', async () => {
|
||||
const memory = createInMemoryMemoryStore();
|
||||
await recordRunResult(memory, input);
|
||||
const [record] = await memory.list({ scopes: [PERSONAL_SCOPE] });
|
||||
expect(record!.metadata).toEqual({ runId: 'r1', run_source: 'fleet', run_kind: 'worker' });
|
||||
});
|
||||
|
||||
it('reports a partial result when one write fails', async () => {
|
||||
const inner = createInMemoryMemoryStore();
|
||||
const memory: MemoryStore = {
|
||||
...inner,
|
||||
remember: async (args) => {
|
||||
if (args.scope.kind === 'workspace') throw new Error('disk full');
|
||||
return inner.remember(args);
|
||||
},
|
||||
};
|
||||
const refs = await recordRunResult(memory, input);
|
||||
expect(refs.status).toBe('partial');
|
||||
expect(refs.workspaceFrameIds).toEqual({});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user