Files
wehub-resource-sync 23f7624596
ADR-166 MCP Bridge Security Lock / Static-source security lock (push) Failing after 0s
ADR-166 MCP Bridge Security Lock / Compose default binds loopback + Mongo has auth (push) Failing after 2s
CodeQL Advanced / Analyze (rust) (push) Failing after 0s
ADR-166 MCP Bridge Security Lock / plugin-agent-federation bindHost default (push) Failing after 1s
ADR-166 MCP Bridge Security Lock / Runtime behavior — 401 + terminal gate + fail-closed (push) Failing after 4s
business-pods-smoke / smoke (push) Failing after 1s
all-plugins-smoke / smoke-all (push) Failing after 2s
CI/CD Pipeline / Security & Code Quality (push) Failing after 1s
CI/CD Pipeline / Test Suite (ubuntu-latest) (push) Failing after 1s
CI/CD Pipeline / Build & Package (macos-latest) (push) Has been skipped
CI/CD Pipeline / Build & Package (ubuntu-latest) (push) Has been skipped
CI/CD Pipeline / Build & Package (windows-latest) (push) Has been skipped
CI/CD Pipeline / Documentation & Examples (push) Failing after 1s
Clone Tracker (14-day rolling) / Snapshot clones for ruflo ecosystem (push) Failing after 1s
CodeQL Advanced / Analyze (actions) (push) Failing after 1s
CodeQL Advanced / Analyze (javascript-typescript) (push) Failing after 1s
federation-peer-rust / stable-noop (push) Failing after 1s
metaharness-ci / score (push) Failing after 1s
metaharness-ci / router-compat (push) Failing after 0s
metaharness-ci / similarity-tests (push) Failing after 0s
no-agentbbs-smoke / smoke-without-agentbbs (push) Failing after 1s
V3 CI/CD Pipeline / Build V3 (windows-latest) (push) Has been skipped
codex-integration-audit / Codex integration audit (push) Failing after 1s
helpers-manifest-guard / guard (push) Failing after 1s
🔗 Cross-Agent Integration Tests / 🤝 Agent Coordination Tests (push) Has been skipped
🔗 Cross-Agent Integration Tests / 🧠 Memory Sharing Integration (push) Has been skipped
🔗 Cross-Agent Integration Tests / 🛡️ Fault Tolerance Tests (push) Has been skipped
🔗 Cross-Agent Integration Tests / ⚡ Performance Integration Tests (push) Has been skipped
metaharness-ci / mcp-scan (push) Failing after 1s
metaharness-ci / eject-dryrun (push) Failing after 1s
metaharness-ci / metaharness-real-data (push) Failing after 0s
no-cli-optdep-bloat-2561 / guard (push) Failing after 1s
no-metaharness-smoke / smoke-without-metaharness (push) Failing after 1s
no-phantom-agentic-flow-subpath / guard (push) Failing after 1s
🔄 Automated Rollback Manager / 🚨 Failure Detection (push) Failing after 1s
V3 CI/CD Pipeline / Plugin hooks smoke / ubuntu-latest / Node 22 (push) Failing after 1s
V3 CI/CD Pipeline / ruflo-graph-intelligence build + test smoke (#2044, ADR-123) (push) Failing after 1s
CVE Audit Gate / Audit root (critical-blocking) (push) Failing after 2s
cost-tracker-smoke / smoke (push) Failing after 3s
oia-audit-weekly / audit (push) Failing after 2s
ruflo-agent-smoke / ruflo-agent structural smoke (push) Failing after 1s
📊 Status Badges Update / 📊 Update Status Badges (push) Failing after 1s
V3 CI/CD Pipeline / Static regression guards (#2267 YAML + (push) Failing after 1s
V3 CI/CD Pipeline / Test V3 Packages (push) Failing after 0s
V3 CI/CD Pipeline / agent_execute provider routing smoke (#2042) (push) Failing after 0s
CVE Audit Gate / Audit v3 (critical-blocking) (push) Failing after 1s
federation-peer-rust / stable-native (push) Failing after 2s
🔗 Cross-Agent Integration Tests / 🚀 Integration Test Setup (push) Failing after 2s
neural-trader-smoke / runtime-smoke (push) Failing after 1s
V3 CI/CD Pipeline / Build V3 (macos-latest) (push) Has been skipped
V3 CI/CD Pipeline / Build V3 (ubuntu-latest) (push) Has been skipped
V3 CI/CD Pipeline / Type Check V3 (push) Failing after 1s
V3 CI/CD Pipeline / Smoke (no better-sqlite3) / ubuntu-latest / Node 24 (push) Failing after 1s
V3 CI/CD Pipeline / Smoke (no better-sqlite3) / ubuntu-latest / Node 22 (push) Failing after 2s
V3 CI/CD Pipeline / browser rvf create flag smoke (#2015) (push) Failing after 0s
V3 CI/CD Pipeline / Dependency review (#2046) (push) Has been skipped
V3 CI/CD Pipeline / Supply-chain audit (#2046) (push) Failing after 0s
V3 CI/CD Pipeline / witness marker drift smoke (#2021) (push) Failing after 1s
V3 CI/CD Pipeline / neural-trader portfolio CG smoke (#2068, ADR-126 Phase 3) (push) Failing after 1s
V3 CI/CD Pipeline / neural-trader backtest signing smoke (#2068, ADR-126 Phase 4) (push) Failing after 1s
V3 CI/CD Pipeline / kg-extract type-import classification smoke (#2049) (push) Failing after 0s
V3 CI/CD Pipeline / witness verify precondition smoke (#1880) (push) Failing after 2s
V3 CI/CD Pipeline / neural-trader pipeline risk-gate smoke (#2068, ADR-126 Phase 5) (push) Failing after 0s
V3 CI/CD Pipeline / neural-trader feature attribution smoke (#2068, ADR-126 Phase 6) (push) Failing after 0s
V3 CI/CD Pipeline / plugin-registry signature verification smoke (#1922, CWE-347) (push) Failing after 4s
V3 CI/CD Pipeline / memory stats legacy-DB smoke (#2120) (push) Failing after 4s
V3 CI/CD Pipeline / github deprecated actions smoke (#2089, ADR-127 Phase 3) (push) Failing after 1s
V3 CI/CD Pipeline / graph query + pathfinder smoke (ADR-130 P2+P5) (push) Has been skipped
V3 CI/CD Pipeline / graph trajectory hooks smoke (ADR-130 P3) (push) Has been skipped
V3 CI/CD Pipeline / graph plugin adapter smoke (ADR-130 P4) (push) Has been skipped
V3 CI/CD Pipeline / graph benchmark (ADR-130 P6) (push) Has been skipped
V3 CI/CD Pipeline / statusline generator delegation smoke (#2195) (push) Failing after 1s
V3 CI/CD Pipeline / wizard init regression guard (#2206 (push) Failing after 1s
V3 CI/CD Pipeline / memory no-stray-db smoke (ADR-125 P7) (push) Failing after 1s
V3 CI/CD Pipeline / github-safe injection smoke (#2089, ADR-127 Phase 1) (push) Failing after 1s
V3 CI/CD Pipeline / github actions pin smoke (#2089, ADR-127 Phase 1) (push) Failing after 1s
V3 CI/CD Pipeline / github attribution opt-in smoke (#2089, ADR-127 Phase 4) (push) Failing after 1s
V3 CI/CD Pipeline / pre-bash hook safety smoke (#2017) (push) Failing after 1s
V3 CI/CD Pipeline / Memory import smoke / ubuntu-latest (push) Failing after 0s
V3 CI/CD Pipeline / MCP protocol smoke / ubuntu-latest (push) Failing after 2s
V3 CI/CD Pipeline / ruvllm WASM auto-init smoke (#2086) (push) Failing after 4s
V3 CI/CD Pipeline / MCP paired-tool round-trip smoke (#1889) (push) Failing after 1s
V3 CI/CD Pipeline / Plugin package install-safety (#1902/#1903/#1904) (push) Failing after 1s
V3 CI/CD Pipeline / Tool description discoverability (ADR-112) (push) Failing after 3s
V3 CI/CD Pipeline / CLI npx-install smoke (#1147 / (22) (push) Failing after 1s
V3 CI/CD Pipeline / CLI npx-install smoke (#1147 / (24) (push) Failing after 1s
V3 CI/CD Pipeline / Windows hook shim smoke (#2132) / ubuntu-latest (push) Failing after 2s
V3 CI/CD Pipeline / Windows hook execution smoke (#2132) / ubuntu-latest (push) Failing after 1s
V3 CI/CD Pipeline / Windows init hooks smoke (#2132) / ubuntu-latest (push) Failing after 1s
V3 CI/CD Pipeline / Vector-index dimension audit (#1947) (push) Failing after 0s
V3 CI/CD Pipeline / Hook-command install safety (#1921) (push) Failing after 1s
V3 CI/CD Pipeline / ToolOutputGuardrail smoke (ADR-131, (push) Failing after 1s
V3 CI/CD Pipeline / init-bundle invariants smoke (#2095, ADR-128 Phase 5) (push) Failing after 1s
V3 CI/CD Pipeline / wasm provider bridge smoke (ADR-129 P1) (push) Failing after 2s
V3 CI/CD Pipeline / wasm gallery CRUD smoke (ADR-129 P3) (push) Failing after 1s
V3 CI/CD Pipeline / wasm plugin bridge smoke (ADR-129 P4) (push) Failing after 0s
V3 CI/CD Pipeline / wasm compose smoke (ADR-129 P2) (push) Failing after 4s
V3 CI/CD Pipeline / graph schema smoke (ADR-130 P1) (push) Failing after 0s
Validate Marketplace / validate (push) Failing after 1s
🔍 Verification Pipeline / 🚀 Setup Verification (push) Failing after 1s
🔍 Verification Pipeline / 🛡️ Security Verification (push) Has been skipped
🔍 Verification Pipeline / 📝 Code Quality (push) Has been skipped
🔍 Verification Pipeline / 🧪 Test Verification (${{ matrix.os }}, Node ${{ matrix.node }}) (push) Has been skipped
🔍 Verification Pipeline / 🏗️ Build Verification (push) Has been skipped
🔍 Verification Pipeline / 📚 Documentation Verification (push) Has been skipped
CVE Audit Gate / High-severity report (warn only) (push) Has been cancelled
🔄 Automated Rollback Manager / 🔄 Execute Rollback (push) Has been cancelled
🔄 Automated Rollback Manager / ✅ Post-Rollback Verification (push) Has been cancelled
🔄 Automated Rollback Manager / 📊 Rollback Monitoring (push) Has been cancelled
V3 CI/CD Pipeline / Windows init hooks smoke (#2132) / windows-latest (push) Has been cancelled
V3 CI/CD Pipeline / Windows hook execution smoke (#2132) / macos-latest (push) Has been cancelled
V3 CI/CD Pipeline / Windows hook execution smoke (#2132) / windows-latest (push) Has been cancelled
🔄 Automated Rollback Manager / ⏳ Manual Rollback Approval (push) Has been cancelled
V3 CI/CD Pipeline / MCP protocol smoke / macos-latest (push) Has been cancelled
V3 CI/CD Pipeline / Memory import smoke / macos-latest (push) Has been cancelled
V3 CI/CD Pipeline / Windows hook shim smoke (#2132) / macos-latest (push) Has been cancelled
V3 CI/CD Pipeline / Windows hook shim smoke (#2132) / windows-latest (push) Has been cancelled
V3 CI/CD Pipeline / Windows init hooks smoke (#2132) / macos-latest (push) Has been cancelled
V3 CI/CD Pipeline / Witness verify (signed manifest) / macos-latest (push) Has been cancelled
V3 CI/CD Pipeline / Witness verify (signed manifest) / ubuntu-latest (push) Has been cancelled
V3 CI/CD Pipeline / Witness verify (signed manifest) / windows-latest (push) Has been cancelled
V3 CI/CD Pipeline / Publish to npm (alpha) (push) Has been cancelled
V3 CI/CD Pipeline / Smoke (no better-sqlite3) / macos-latest / Node 22 (push) Has been cancelled
V3 CI/CD Pipeline / Plugin hooks smoke / macos-latest / Node 22 (push) Has been cancelled
CI/CD Pipeline / Deploy & Release (push) Has been cancelled
CI/CD Pipeline / CI Status (push) Has been cancelled
🔗 Cross-Agent Integration Tests / 📊 Integration Test Report (push) Has been cancelled
🔄 Automated Rollback Manager / 🔍 Pre-Rollback Validation (push) Has been cancelled
🔍 Verification Pipeline / ⚡ Performance Verification (push) Has been cancelled
🔍 Verification Pipeline / 📊 Verification Report (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:02:19 +08:00

571 lines
17 KiB
TypeScript

/**
* V3 MCP Session Tools Tests
*
* Tests for session management MCP tools:
* - session/save
* - session/restore
* - session/list
*/
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
import {
saveSessionTool,
restoreSessionTool,
listSessionsTool,
sessionTools,
} from '../tools/session-tools.js';
import { ToolContext } from '../types.js';
import * as fs from 'fs/promises';
import * as path from 'path';
// Mock fs module
vi.mock('fs/promises', () => ({
mkdir: vi.fn().mockResolvedValue(undefined),
writeFile: vi.fn().mockResolvedValue(undefined),
readFile: vi.fn(),
readdir: vi.fn().mockResolvedValue([]),
stat: vi.fn().mockResolvedValue({ size: 1024 }),
}));
describe('Session Tools', () => {
let mockContext: ToolContext;
let mockOrchestrator: any;
let mockSwarmCoordinator: any;
let mockResourceManager: any;
let savedSessionId: string;
beforeEach(() => {
vi.clearAllMocks();
mockOrchestrator = {
listTasks: vi.fn().mockResolvedValue({
tasks: [
{ id: 'task-1', type: 'code', description: 'Task 1', status: 'pending', priority: 5, dependencies: [] },
{ id: 'task-2', type: 'review', description: 'Task 2', status: 'queued', priority: 3, dependencies: ['task-1'] },
],
}),
submitTask: vi.fn().mockImplementation(async (task) => ({ id: task.id })),
cancelAll: vi.fn().mockResolvedValue(true),
};
mockSwarmCoordinator = {
getStatus: vi.fn().mockResolvedValue({
swarmId: 'swarm-1',
agents: [
{ id: 'agent-1', type: 'coder', status: 'active', config: {}, metadata: {} },
{ id: 'agent-2', type: 'tester', status: 'idle', config: {}, metadata: {} },
],
topology: {
type: 'hierarchical-mesh',
edges: [{ from: 'agent-1', to: 'agent-2' }],
},
consensus: { algorithm: 'majority' },
}),
spawnAgent: vi.fn().mockResolvedValue({}),
terminateAll: vi.fn().mockResolvedValue(true),
setTopology: vi.fn().mockResolvedValue(true),
};
mockResourceManager = {
memoryService: {
query: vi.fn().mockResolvedValue([
{ id: 'mem-1', content: 'Memory 1', type: 'episodic', namespace: 'default', tags: [], metadata: {}, createdAt: new Date() },
{ id: 'mem-2', content: 'Memory 2', type: 'semantic', namespace: 'code', tags: ['important'], metadata: { importance: 0.8 }, createdAt: new Date() },
]),
storeEntry: vi.fn().mockResolvedValue({}),
},
};
mockContext = {
sessionId: 'test-session',
orchestrator: mockOrchestrator,
swarmCoordinator: mockSwarmCoordinator,
resourceManager: mockResourceManager,
};
});
afterEach(() => {
vi.clearAllMocks();
});
describe('session/save', () => {
it('should have correct tool definition', () => {
expect(saveSessionTool.name).toBe('session/save');
expect(saveSessionTool.category).toBe('session');
});
it('should save a session with default options', async () => {
const result = await saveSessionTool.handler({}, mockContext);
expect(result).toBeDefined();
expect(result.sessionId).toBeDefined();
expect(result.sessionId).toMatch(/^session-/);
expect(result.name).toBeDefined();
expect(result.savedAt).toBeDefined();
expect(result.size).toBeGreaterThan(0);
savedSessionId = result.sessionId;
});
it('should save a session with custom name', async () => {
const result = await saveSessionTool.handler({
name: 'My Custom Session',
}, mockContext);
expect(result.name).toBe('My Custom Session');
});
it('should save a session with description', async () => {
const result = await saveSessionTool.handler({
name: 'Test Session',
description: 'This is a test session',
}, mockContext);
expect(result).toBeDefined();
expect(result.sessionId).toBeDefined();
});
it('should include agent states when requested', async () => {
const result = await saveSessionTool.handler({
includeAgents: true,
}, mockContext);
expect(result.agentCount).toBe(2);
expect(mockSwarmCoordinator.getStatus).toHaveBeenCalled();
});
it('should include tasks when requested', async () => {
const result = await saveSessionTool.handler({
includeTasks: true,
}, mockContext);
expect(result.taskCount).toBe(2);
expect(mockOrchestrator.listTasks).toHaveBeenCalled();
});
it('should include memory entries when requested', async () => {
const result = await saveSessionTool.handler({
includeMemory: true,
}, mockContext);
expect(result.memoryCount).toBe(2);
expect(mockResourceManager.memoryService.query).toHaveBeenCalled();
});
it('should include swarm state when requested', async () => {
const result = await saveSessionTool.handler({
includeSwarmState: true,
}, mockContext);
expect(result).toBeDefined();
expect(mockSwarmCoordinator.getStatus).toHaveBeenCalled();
});
it('should save session with tags', async () => {
const result = await saveSessionTool.handler({
tags: ['production', 'important'],
}, mockContext);
expect(result).toBeDefined();
});
it('should save session with metadata', async () => {
const result = await saveSessionTool.handler({
metadata: { source: 'test', version: '1.0' },
}, mockContext);
expect(result).toBeDefined();
});
it('should exclude components when not requested', async () => {
const result = await saveSessionTool.handler({
includeAgents: false,
includeTasks: false,
includeMemory: false,
includeSwarmState: false,
}, mockContext);
expect(result.agentCount).toBeUndefined();
expect(result.taskCount).toBeUndefined();
expect(result.memoryCount).toBeUndefined();
});
});
describe('session/restore', () => {
it('should have correct tool definition', () => {
expect(restoreSessionTool.name).toBe('session/restore');
expect(restoreSessionTool.category).toBe('session');
expect(restoreSessionTool.inputSchema.required).toContain('sessionId');
});
it('should restore a saved session', async () => {
// First save a session
const saveResult = await saveSessionTool.handler({
includeAgents: true,
includeTasks: true,
}, mockContext);
// Then restore it
const result = await restoreSessionTool.handler({
sessionId: saveResult.sessionId,
}, mockContext);
expect(result).toBeDefined();
expect(result.sessionId).toBe(saveResult.sessionId);
expect(result.restoredAt).toBeDefined();
});
it('should restore agents when requested', async () => {
const saveResult = await saveSessionTool.handler({
includeAgents: true,
}, mockContext);
const result = await restoreSessionTool.handler({
sessionId: saveResult.sessionId,
restoreAgents: true,
}, mockContext);
expect(result.restored.agents).toBeDefined();
});
it('should restore tasks when requested', async () => {
const saveResult = await saveSessionTool.handler({
includeTasks: true,
}, mockContext);
const result = await restoreSessionTool.handler({
sessionId: saveResult.sessionId,
restoreTasks: true,
}, mockContext);
expect(result.restored.tasks).toBeDefined();
});
it('should restore memory when requested', async () => {
const saveResult = await saveSessionTool.handler({
includeMemory: true,
}, mockContext);
const result = await restoreSessionTool.handler({
sessionId: saveResult.sessionId,
restoreMemory: true,
}, mockContext);
expect(result.restored.memory).toBeDefined();
});
it('should restore swarm state when requested', async () => {
const saveResult = await saveSessionTool.handler({
includeSwarmState: true,
}, mockContext);
const result = await restoreSessionTool.handler({
sessionId: saveResult.sessionId,
restoreSwarmState: true,
}, mockContext);
expect(result.restored.swarmState).toBeDefined();
});
it('should clear existing state when requested', async () => {
const saveResult = await saveSessionTool.handler({}, mockContext);
const result = await restoreSessionTool.handler({
sessionId: saveResult.sessionId,
clearExisting: true,
}, mockContext);
expect(result).toBeDefined();
});
it('should skip restoring components when not requested', async () => {
const saveResult = await saveSessionTool.handler({
includeAgents: true,
includeTasks: true,
includeMemory: true,
}, mockContext);
const result = await restoreSessionTool.handler({
sessionId: saveResult.sessionId,
restoreAgents: false,
restoreTasks: false,
restoreMemory: false,
restoreSwarmState: false,
}, mockContext);
expect(result.restored.agents).toBe(0);
expect(result.restored.tasks).toBe(0);
expect(result.restored.memory).toBe(0);
expect(result.restored.swarmState).toBe(false);
});
it('should throw error for non-existent session', async () => {
await expect(restoreSessionTool.handler({
sessionId: 'non-existent-session',
}, mockContext)).rejects.toThrow();
});
it('should report errors during restore', async () => {
const saveResult = await saveSessionTool.handler({
includeAgents: true,
}, mockContext);
// Make spawnAgent fail
mockSwarmCoordinator.spawnAgent.mockRejectedValue(new Error('Spawn failed'));
const result = await restoreSessionTool.handler({
sessionId: saveResult.sessionId,
restoreAgents: true,
}, mockContext);
// Should still complete but with errors
expect(result).toBeDefined();
if (result.errors) {
expect(result.errors.length).toBeGreaterThan(0);
}
});
});
describe('session/list', () => {
it('should have correct tool definition', () => {
expect(listSessionsTool.name).toBe('session/list');
expect(listSessionsTool.category).toBe('session');
expect(listSessionsTool.cacheable).toBe(true);
});
it('should list saved sessions', async () => {
// Save some sessions
await saveSessionTool.handler({ name: 'Session 1' }, mockContext);
await saveSessionTool.handler({ name: 'Session 2' }, mockContext);
const result = await listSessionsTool.handler({}, mockContext);
expect(result).toBeDefined();
expect(result.sessions).toBeDefined();
expect(Array.isArray(result.sessions)).toBe(true);
expect(result.total).toBeGreaterThanOrEqual(2);
expect(result.limit).toBeDefined();
expect(result.offset).toBeDefined();
});
it('should apply pagination', async () => {
const result = await listSessionsTool.handler({
limit: 10,
offset: 0,
}, mockContext);
expect(result.limit).toBe(10);
expect(result.offset).toBe(0);
});
it('should filter by tags', async () => {
await saveSessionTool.handler({
name: 'Tagged Session',
tags: ['production'],
}, mockContext);
const result = await listSessionsTool.handler({
tags: ['production'],
}, mockContext);
expect(result).toBeDefined();
});
it('should sort by created date', async () => {
const result = await listSessionsTool.handler({
sortBy: 'created',
sortOrder: 'desc',
}, mockContext);
expect(result).toBeDefined();
});
it('should sort by name', async () => {
const result = await listSessionsTool.handler({
sortBy: 'name',
sortOrder: 'asc',
}, mockContext);
expect(result).toBeDefined();
});
it('should sort by size', async () => {
const result = await listSessionsTool.handler({
sortBy: 'size',
sortOrder: 'desc',
}, mockContext);
expect(result).toBeDefined();
});
it('should include metadata when requested', async () => {
await saveSessionTool.handler({
name: 'Session with Metadata',
metadata: { key: 'value' },
}, mockContext);
const result = await listSessionsTool.handler({
includeMetadata: true,
}, mockContext);
expect(result).toBeDefined();
});
it('should exclude metadata when not requested', async () => {
await saveSessionTool.handler({
name: 'Session without Metadata',
metadata: { key: 'value' },
}, mockContext);
const result = await listSessionsTool.handler({
includeMetadata: false,
}, mockContext);
expect(result).toBeDefined();
// Sessions should not have metadata property
result.sessions.forEach(session => {
expect(session.metadata).toBeUndefined();
});
});
it('should return session summaries', async () => {
await saveSessionTool.handler({
name: 'Full Session',
includeAgents: true,
includeTasks: true,
includeMemory: true,
}, mockContext);
const result = await listSessionsTool.handler({}, mockContext);
result.sessions.forEach(session => {
expect(session.id).toBeDefined();
expect(session.name).toBeDefined();
expect(session.createdAt).toBeDefined();
expect(session.size).toBeDefined();
expect(session.agentCount).toBeDefined();
expect(session.taskCount).toBeDefined();
expect(session.memoryCount).toBeDefined();
});
});
});
describe('Session Persistence', () => {
it('should persist session to file system', async () => {
const result = await saveSessionTool.handler({
name: 'Persisted Session',
}, mockContext);
expect(fs.mkdir).toHaveBeenCalled();
expect(fs.writeFile).toHaveBeenCalled();
expect(result.path).toBeDefined();
});
it('should load session from file when not in memory', async () => {
const sessionData = {
id: 'file-session-123',
name: 'File Session',
version: '3.0.0',
createdAt: new Date().toISOString(),
agents: [],
tasks: [],
memory: [],
};
(fs.readFile as any).mockResolvedValue(JSON.stringify(sessionData));
const result = await restoreSessionTool.handler({
sessionId: 'file-session-123',
}, mockContext);
expect(result.sessionId).toBe('file-session-123');
});
});
describe('Tool Collection', () => {
it('should export all 3 session tools', () => {
expect(sessionTools).toHaveLength(3);
});
it('should have unique tool names', () => {
const names = sessionTools.map(t => t.name);
const uniqueNames = new Set(names);
expect(uniqueNames.size).toBe(names.length);
});
it('should all have handlers', () => {
sessionTools.forEach(tool => {
expect(tool.handler).toBeDefined();
expect(typeof tool.handler).toBe('function');
});
});
it('should all have inputSchema', () => {
sessionTools.forEach(tool => {
expect(tool.inputSchema).toBeDefined();
expect(tool.inputSchema.type).toBe('object');
});
});
it('should all be in session category', () => {
sessionTools.forEach(tool => {
expect(tool.category).toBe('session');
});
});
it('should include expected tool names', () => {
const names = sessionTools.map(t => t.name);
expect(names).toContain('session/save');
expect(names).toContain('session/restore');
expect(names).toContain('session/list');
});
});
describe('Error Handling', () => {
it('should handle missing context gracefully', async () => {
const emptyContext: ToolContext = { sessionId: 'test' };
const result = await saveSessionTool.handler({}, emptyContext);
expect(result).toBeDefined();
expect(result.sessionId).toBeDefined();
});
it('should handle orchestrator errors gracefully', async () => {
mockOrchestrator.listTasks.mockRejectedValue(new Error('Orchestrator error'));
const result = await saveSessionTool.handler({
includeTasks: true,
}, mockContext);
// Should still save, just without tasks
expect(result).toBeDefined();
expect(result.sessionId).toBeDefined();
});
it('should handle swarm coordinator errors gracefully', async () => {
mockSwarmCoordinator.getStatus.mockRejectedValue(new Error('Swarm error'));
const result = await saveSessionTool.handler({
includeAgents: true,
}, mockContext);
// Should still save, just without agents
expect(result).toBeDefined();
expect(result.sessionId).toBeDefined();
});
it('should handle memory service errors gracefully', async () => {
mockResourceManager.memoryService.query.mockRejectedValue(new Error('Memory error'));
const result = await saveSessionTool.handler({
includeMemory: true,
}, mockContext);
// Should still save, just without memory
expect(result).toBeDefined();
expect(result.sessionId).toBeDefined();
});
});
});