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.
87 lines
3.8 KiB
TypeScript
87 lines
3.8 KiB
TypeScript
/**
|
|
* Cross-workspace tools on the memory contract: read_other_workspace reads only
|
|
* the target workspace's scope and never writes.
|
|
*/
|
|
import { describe, it, expect, beforeEach } from 'vitest';
|
|
import {
|
|
createInMemoryMemoryStore,
|
|
PERSONAL_SCOPE,
|
|
workspaceScope,
|
|
type MemoryStore,
|
|
} from '@waggle/memory-contract';
|
|
import { createCrossWorkspaceTools } from '../src/cross-workspace-tools.js';
|
|
import type { ToolDefinition } from '../src/tools.js';
|
|
|
|
describe('read_other_workspace', () => {
|
|
let memory: MemoryStore;
|
|
let read: ToolDefinition;
|
|
|
|
const workspaces = [
|
|
{ id: 'ws-a', name: 'Atlas' },
|
|
{ id: 'ws-b', name: 'Borealis' },
|
|
];
|
|
|
|
beforeEach(async () => {
|
|
memory = createInMemoryMemoryStore();
|
|
await memory.remember({ scope: workspaceScope('ws-a'), text: 'Atlas decided on per-seat pricing' });
|
|
await memory.remember({ scope: workspaceScope('ws-b'), text: 'Borealis decided on usage pricing', importance: 'important' });
|
|
await memory.remember({ scope: workspaceScope('ws-c'), text: 'Unlisted workspace pricing secret' });
|
|
await memory.remember({ scope: PERSONAL_SCOPE, text: 'Personal pricing musings' });
|
|
|
|
const tools = createCrossWorkspaceTools({ sourceWorkspaceId: 'ws-a', memory, listWorkspaces: () => workspaces });
|
|
read = tools.find(t => t.name === 'read_other_workspace')!;
|
|
});
|
|
|
|
it("returns ranked memories from the target workspace only, named for citation", async () => {
|
|
const result = JSON.parse(await read.execute({ target_workspace_id: 'ws-b', query: 'pricing' }));
|
|
|
|
expect(result).toMatchObject({
|
|
sourceWorkspace: 'ws-a',
|
|
targetWorkspace: 'ws-b',
|
|
targetWorkspaceName: 'Borealis',
|
|
matchCount: 1,
|
|
citation: '(from workspace "Borealis")',
|
|
});
|
|
expect(result.matches[0]).toMatchObject({ content: 'Borealis decided on usage pricing', importance: 'important' });
|
|
expect(typeof result.matches[0].createdAt).toBe('string');
|
|
expect(typeof result.matches[0].score).toBe('number');
|
|
});
|
|
|
|
it('never writes', async () => {
|
|
const before = await memory.count({ scopes: [PERSONAL_SCOPE, workspaceScope('ws-a'), workspaceScope('ws-b')] });
|
|
await read.execute({ target_workspace_id: 'ws-b', query: 'pricing' });
|
|
expect(await memory.count({ scopes: [PERSONAL_SCOPE, workspaceScope('ws-a'), workspaceScope('ws-b')] })).toBe(before);
|
|
});
|
|
|
|
it('refuses the source workspace itself', async () => {
|
|
const result = JSON.parse(await read.execute({ target_workspace_id: 'ws-a', query: 'pricing' }));
|
|
expect(result.error).toContain('same as the source');
|
|
});
|
|
|
|
it('refuses a workspace that is not listed, without reading it', async () => {
|
|
const result = JSON.parse(await read.execute({ target_workspace_id: 'ws-c', query: 'pricing' }));
|
|
expect(result.error).toContain('not found or not accessible');
|
|
expect(JSON.stringify(result)).not.toContain('Unlisted workspace pricing secret');
|
|
expect(result.knownWorkspaces).toEqual(workspaces);
|
|
});
|
|
|
|
it('reports no matches with a hint', async () => {
|
|
const result = JSON.parse(await read.execute({ target_workspace_id: 'ws-b', query: 'zebra xylophone' }));
|
|
expect(result.matchCount).toBe(0);
|
|
expect(result.hint).toContain('Borealis');
|
|
});
|
|
|
|
it('requires a target and a query', async () => {
|
|
expect(JSON.parse(await read.execute({ query: 'pricing' })).error).toContain('target_workspace_id is required');
|
|
expect(JSON.parse(await read.execute({ target_workspace_id: 'ws-b' })).error).toContain('query is required');
|
|
});
|
|
|
|
it('caps the number of matches at 30', async () => {
|
|
for (let i = 0; i < 35; i++) {
|
|
await memory.remember({ scope: workspaceScope('ws-b'), text: `Borealis pricing note ${i}` });
|
|
}
|
|
const result = JSON.parse(await read.execute({ target_workspace_id: 'ws-b', query: 'pricing', limit: 100 }));
|
|
expect(result.matchCount).toBe(30);
|
|
});
|
|
});
|