Files
waggle-os/packages/agent/tests/combined-retrieval.test.ts
shumeiko.it b734c1d3d2 refactor: remove KVARK, enterprise packs and the compliance subsystem (P1.4, P1.6)
KVARK is the commercial enterprise product and is not part of the community
edition. The agent's KVARK tools were never wired into the server, so
removing them changes no runtime behaviour beyond the routes listed here.

- agent: delete kvark-tools; CombinedRetrieval and formatCombinedResult now
  merge workspace and personal memory only (no KVARK lane, no source
  conflict note); connector substrate is always 'waggle'
- agent: promote_skill stops at workspace scope; team and enterprise scopes
  answer "not available in this edition" instead of an upgrade prompt
- server: delete src/kvark and GET /api/marketplace/enterprise-packs
- marketplace: delete ENTERPRISE_PACKS
- compliance (EU AI Act dashboard, its templates and the KVARK template
  seeded on every boot): delete core/src/compliance, the /api/compliance/*
  routes, agent compliance-pdf and the Cockpit compliance panel. The
  ai_interactions table lives in the memory substrate and goes with P1.5.
2026-10-20 00:27:16 +02:00

151 lines
5.9 KiB
TypeScript

/**
* Combined Retrieval — merge engine tests.
*
* Tests the merge engine in isolation. MemorySearchLike (workspace + personal
* HybridSearch) is mocked. No server, no vault, no DB, no wiring.
*/
import { describe, it, expect, vi } from 'vitest';
import {
CombinedRetrieval,
mapMemoryResult,
type MemorySearchLike,
type MemorySearchResultLike,
} from '../src/combined-retrieval.js';
// ── Factories ─────────────────────────────────────────────────────────────
function makeMemoryResult(
overrides: { id?: number; content?: string; score?: number; frameType?: string; importance?: string } = {},
): MemorySearchResultLike {
return {
frame: {
id: overrides.id ?? 1,
content: overrides.content ?? 'Some memory content',
frame_type: overrides.frameType ?? 'P',
importance: overrides.importance ?? 'normal',
},
finalScore: overrides.score ?? 0.5,
};
}
function makeSearchMock(results: MemorySearchResultLike[] = []): MemorySearchLike {
return { search: vi.fn(async () => results) };
}
// ── Helper unit tests ─────────────────────────────────────────────────────
describe('mapMemoryResult', () => {
it('maps workspace memory result with correct attribution', () => {
const input = makeMemoryResult({ id: 7, content: 'decision made', score: 0.85, frameType: 'I', importance: 'important' });
const result = mapMemoryResult(input, 'workspace');
expect(result.source).toBe('workspace');
expect(result.attribution).toBe('[workspace memory]');
expect(result.content).toBe('decision made');
expect(result.score).toBe(0.85);
expect(result.metadata.frameId).toBe(7);
expect(result.metadata.frameType).toBe('I');
expect(result.metadata.importance).toBe('important');
});
it('maps personal memory result with correct attribution', () => {
const input = makeMemoryResult({ id: 3, content: 'user prefers bullets' });
const result = mapMemoryResult(input, 'personal');
expect(result.source).toBe('personal');
expect(result.attribution).toBe('[personal memory]');
expect(result.content).toBe('user prefers bullets');
});
});
// ── CombinedRetrieval class tests ─────────────────────────────────────────
describe('CombinedRetrieval', () => {
it('returns workspace + personal results', async () => {
const wsResults = [makeMemoryResult({ id: 1, content: 'ws fact', score: 0.9 })];
const pResults = [makeMemoryResult({ id: 2, content: 'personal fact', score: 0.8 })];
const cr = new CombinedRetrieval({
workspaceSearch: makeSearchMock(wsResults),
personalSearch: makeSearchMock(pResults),
});
const result = await cr.search('test');
expect(result.query).toBe('test');
expect(result.workspaceResults.map(r => r.content)).toEqual(['ws fact']);
expect(result.personalResults.map(r => r.content)).toEqual(['personal fact']);
});
it('searches only personal memory when scope=personal', async () => {
const wsMock = makeSearchMock([makeMemoryResult({ id: 1 })]);
const pMock = makeSearchMock([makeMemoryResult({ id: 2, content: 'personal only' })]);
const cr = new CombinedRetrieval({ workspaceSearch: wsMock, personalSearch: pMock });
const result = await cr.search('test', { scope: 'personal' });
expect(result.workspaceResults).toHaveLength(0);
expect(result.personalResults).toHaveLength(1);
expect(wsMock.search).not.toHaveBeenCalled();
});
it('searches only workspace memory when scope=workspace', async () => {
const wsMock = makeSearchMock([makeMemoryResult({ id: 1, content: 'ws only' })]);
const pMock = makeSearchMock([makeMemoryResult({ id: 2 })]);
const cr = new CombinedRetrieval({ workspaceSearch: wsMock, personalSearch: pMock });
const result = await cr.search('test', { scope: 'workspace' });
expect(result.workspaceResults).toHaveLength(1);
expect(result.personalResults).toHaveLength(0);
expect(pMock.search).not.toHaveBeenCalled();
});
it('works correctly when no workspace search is available', async () => {
const cr = new CombinedRetrieval({
workspaceSearch: null,
personalSearch: makeSearchMock([makeMemoryResult({ id: 1, content: 'personal fact', score: 0.6 })]),
});
const result = await cr.search('test');
expect(result.workspaceResults).toHaveLength(0);
expect(result.personalResults).toHaveLength(1);
});
it('passes limit and profile through to memory search', async () => {
const wsMock = makeSearchMock([]);
const pMock = makeSearchMock([]);
const cr = new CombinedRetrieval({ workspaceSearch: wsMock, personalSearch: pMock });
await cr.search('test', { limit: 5, profile: 'recent' });
expect(wsMock.search).toHaveBeenCalledWith('test', { limit: 5, profile: 'recent' });
expect(pMock.search).toHaveBeenCalledWith('test', { limit: 5, profile: 'recent' });
});
it('uses sensible defaults (limit=10, profile=balanced, scope=all)', async () => {
const wsMock = makeSearchMock([]);
const pMock = makeSearchMock([]);
const cr = new CombinedRetrieval({ workspaceSearch: wsMock, personalSearch: pMock });
await cr.search('test');
expect(wsMock.search).toHaveBeenCalledWith('test', { limit: 10, profile: 'balanced' });
expect(pMock.search).toHaveBeenCalledWith('test', { limit: 10, profile: 'balanced' });
});
it('returns empty lists when nothing matches', async () => {
const cr = new CombinedRetrieval({
workspaceSearch: makeSearchMock([]),
personalSearch: makeSearchMock([]),
});
const result = await cr.search('nothing');
expect(result.workspaceResults).toHaveLength(0);
expect(result.personalResults).toHaveLength(0);
});
});