- Rewrite context-compactor.test.ts to use intelligenceClient - Rewrite heartbeat-reflection.test.ts to use intelligenceClient - Rewrite swarm-skills.test.ts to use intelligenceClient - Update CLAUDE.md architecture section for unified intelligence layer All tests now mock Tauri backend calls for unit testing. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
88 lines
2.5 KiB
TypeScript
88 lines
2.5 KiB
TypeScript
/**
|
|
* Tests for Phase 4: Agent Swarm + Skill Discovery
|
|
*
|
|
* Now uses intelligenceClient for memory operations.
|
|
*/
|
|
|
|
import { describe, it, expect, beforeEach, vi } from 'vitest';
|
|
import { intelligenceClient } from '../../desktop/src/lib/intelligence-client';
|
|
|
|
// === localStorage mock ===
|
|
|
|
const store: Record<string, string> = {};
|
|
const localStorageMock = {
|
|
getItem: (key: string) => store[key] ?? null,
|
|
setItem: (key: string, value: string) => { store[key] = value; },
|
|
removeItem: (key: string) => { delete store[key]; },
|
|
clear: () => { for (const k of Object.keys(store)) delete store[k]; },
|
|
get length() { return Object.keys(store).length; },
|
|
key: (i: number) => Object.keys(store)[i] ?? null,
|
|
};
|
|
Object.defineProperty(globalThis, 'localStorage', { value: localStorageMock, writable: true });
|
|
|
|
// === Mock Tauri invoke ===
|
|
vi.mock('@tauri-apps/api/core', () => ({
|
|
invoke: vi.fn(async (cmd: string, _args?: unknown) => {
|
|
// Memory commands
|
|
if (cmd === 'memory_search') {
|
|
return [];
|
|
}
|
|
if (cmd === 'memory_store') {
|
|
return `mem-${new Date().toISOString()}`;
|
|
}
|
|
return null;
|
|
}),
|
|
}));
|
|
|
|
// =============================================
|
|
// AgentSwarm Tests
|
|
// =============================================
|
|
|
|
describe('AgentSwarm (via intelligenceClient)', () => {
|
|
beforeEach(() => {
|
|
localStorageMock.clear();
|
|
vi.clearAllMocks();
|
|
});
|
|
|
|
describe('memory operations via intelligenceClient', () => {
|
|
it('search returns empty array when no memories', async () => {
|
|
const results = await intelligenceClient.memory.search({
|
|
agentId: 'test-agent',
|
|
});
|
|
expect(Array.isArray(results)).toBe(true);
|
|
});
|
|
|
|
it('stores new memory', async () => {
|
|
const id = await intelligenceClient.memory.store({
|
|
agent_id: 'test-agent',
|
|
memory_type: 'fact',
|
|
content: 'Test memory',
|
|
importance: 5,
|
|
source: 'auto',
|
|
});
|
|
|
|
expect(typeof id).toBe('string');
|
|
});
|
|
});
|
|
});
|
|
|
|
// =============================================
|
|
// Skill Discovery Tests
|
|
// =============================================
|
|
|
|
describe('SkillDiscovery (via intelligenceClient)', () => {
|
|
beforeEach(() => {
|
|
localStorageMock.clear();
|
|
vi.clearAllMocks();
|
|
});
|
|
|
|
describe('memory operations for skill discovery', () => {
|
|
it('search returns empty results for skill analysis', async () => {
|
|
const results = await intelligenceClient.memory.search({
|
|
agentId: 'test-agent',
|
|
});
|
|
expect(Array.isArray(results)).toBe(true);
|
|
});
|
|
});
|
|
});
|