@sparkleideas/testing 3.0.0-alpha.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +547 -0
- package/__tests__/framework.test.ts +21 -0
- package/package.json +61 -0
- package/src/fixtures/agent-fixtures.ts +793 -0
- package/src/fixtures/agents.ts +212 -0
- package/src/fixtures/configurations.ts +491 -0
- package/src/fixtures/index.ts +21 -0
- package/src/fixtures/mcp-fixtures.ts +1030 -0
- package/src/fixtures/memory-entries.ts +328 -0
- package/src/fixtures/memory-fixtures.ts +750 -0
- package/src/fixtures/swarm-fixtures.ts +837 -0
- package/src/fixtures/tasks.ts +309 -0
- package/src/helpers/assertion-helpers.ts +616 -0
- package/src/helpers/assertions.ts +286 -0
- package/src/helpers/create-mock.ts +200 -0
- package/src/helpers/index.ts +182 -0
- package/src/helpers/mock-factory.ts +711 -0
- package/src/helpers/setup-teardown.ts +678 -0
- package/src/helpers/swarm-instance.ts +326 -0
- package/src/helpers/test-application.ts +310 -0
- package/src/helpers/test-utils.ts +670 -0
- package/src/index.ts +232 -0
- package/src/mocks/index.ts +29 -0
- package/src/mocks/mock-mcp-client.ts +723 -0
- package/src/mocks/mock-services.ts +793 -0
- package/src/regression/api-contract.ts +473 -0
- package/src/regression/index.ts +46 -0
- package/src/regression/integration-regression.ts +416 -0
- package/src/regression/performance-baseline.ts +356 -0
- package/src/regression/regression-runner.ts +339 -0
- package/src/regression/security-regression.ts +331 -0
- package/src/setup.ts +127 -0
- package/src/v2-compat/api-compat.test.ts +590 -0
- package/src/v2-compat/cli-compat.test.ts +484 -0
- package/src/v2-compat/compatibility-validator.ts +1072 -0
- package/src/v2-compat/hooks-compat.test.ts +602 -0
- package/src/v2-compat/index.ts +58 -0
- package/src/v2-compat/mcp-compat.test.ts +557 -0
- package/src/v2-compat/report-generator.ts +441 -0
- package/tmp.json +0 -0
- package/tsconfig.json +20 -0
- package/vitest.config.ts +12 -0
|
@@ -0,0 +1,557 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* V2 MCP Tool Compatibility Tests
|
|
3
|
+
*
|
|
4
|
+
* Tests all 65 V2 MCP tools work via name mapping and parameter translation.
|
|
5
|
+
* Verifies parameter translation and response format compatibility.
|
|
6
|
+
*
|
|
7
|
+
* @module v3/testing/v2-compat/mcp-compat.test
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { describe, it, expect, beforeEach, afterEach, vi, type Mock } from 'vitest';
|
|
11
|
+
import {
|
|
12
|
+
V2CompatibilityValidator,
|
|
13
|
+
V2_MCP_TOOLS,
|
|
14
|
+
type V2MCPTool,
|
|
15
|
+
type ValidationResult,
|
|
16
|
+
} from './compatibility-validator.js';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Tool name mapping from V2 to V3
|
|
20
|
+
*/
|
|
21
|
+
const TOOL_NAME_MAPPING: Record<string, string> = {
|
|
22
|
+
// Agent tools
|
|
23
|
+
'dispatch_agent': 'agent/spawn',
|
|
24
|
+
'agents/spawn': 'agent/spawn',
|
|
25
|
+
'agents/list': 'agent/list',
|
|
26
|
+
'agents/terminate': 'agent/terminate',
|
|
27
|
+
'agents/info': 'agent/status',
|
|
28
|
+
'agent/create': 'agent/spawn',
|
|
29
|
+
|
|
30
|
+
// Swarm tools
|
|
31
|
+
'swarm_status': 'swarm/status',
|
|
32
|
+
'swarm/get-status': 'swarm/status',
|
|
33
|
+
'swarm/get-comprehensive-status': 'swarm/status',
|
|
34
|
+
'mcp__ruv-swarm__swarm_init': 'swarm/init',
|
|
35
|
+
'mcp__ruv-swarm__swarm_status': 'swarm/status',
|
|
36
|
+
'mcp__ruv-swarm__agent_spawn': 'agent/spawn',
|
|
37
|
+
'mcp__ruv-swarm__agent_list': 'agent/list',
|
|
38
|
+
'mcp__ruv-swarm__agent_metrics': 'agent/status',
|
|
39
|
+
|
|
40
|
+
// Memory tools
|
|
41
|
+
'memory/query': 'memory/search',
|
|
42
|
+
'mcp__ruv-swarm__memory_usage': 'memory/list',
|
|
43
|
+
|
|
44
|
+
// Config tools
|
|
45
|
+
'config/get': 'config/load',
|
|
46
|
+
'config/update': 'config/save',
|
|
47
|
+
|
|
48
|
+
// Neural tools
|
|
49
|
+
'mcp__ruv-swarm__neural_status': 'hooks/metrics',
|
|
50
|
+
'mcp__ruv-swarm__neural_train': 'hooks/pretrain',
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Mock MCP client for testing
|
|
55
|
+
*/
|
|
56
|
+
interface MockMCPClient {
|
|
57
|
+
callTool: Mock<(name: string, params: Record<string, unknown>) => Promise<unknown>>;
|
|
58
|
+
getTools: Mock<() => string[]>;
|
|
59
|
+
translateToolName: Mock<(name: string) => string>;
|
|
60
|
+
translateParams: Mock<(name: string, params: Record<string, unknown>) => Record<string, unknown>>;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Create mock MCP client
|
|
65
|
+
*/
|
|
66
|
+
function createMockMCPClient(): MockMCPClient {
|
|
67
|
+
const v3Tools = [
|
|
68
|
+
'agent/spawn', 'agent/list', 'agent/terminate', 'agent/status',
|
|
69
|
+
'swarm/init', 'swarm/status', 'swarm/scale', 'swarm/consensus', 'swarm/broadcast',
|
|
70
|
+
'memory/store', 'memory/search', 'memory/delete', 'memory/list',
|
|
71
|
+
'task/create', 'task/assign', 'task/status', 'task/complete',
|
|
72
|
+
'config/load', 'config/save',
|
|
73
|
+
'hooks/metrics', 'hooks/pretrain',
|
|
74
|
+
'github/pr-create', 'github/pr-review', 'github/issue-create',
|
|
75
|
+
];
|
|
76
|
+
|
|
77
|
+
return {
|
|
78
|
+
callTool: vi.fn().mockImplementation(async (name: string, params: Record<string, unknown>) => {
|
|
79
|
+
const v3Name = TOOL_NAME_MAPPING[name] || name;
|
|
80
|
+
|
|
81
|
+
if (!v3Tools.includes(v3Name)) {
|
|
82
|
+
throw new Error(`Tool not found: ${name} (translated: ${v3Name})`);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Simulate tool responses
|
|
86
|
+
const responses: Record<string, unknown> = {
|
|
87
|
+
'agent/spawn': { id: 'agent-1', type: params.agentType || params.type, status: 'active' },
|
|
88
|
+
'agent/list': [{ id: 'agent-1', type: 'coder', status: 'active' }],
|
|
89
|
+
'agent/terminate': { success: true },
|
|
90
|
+
'agent/status': { id: 'agent-1', metrics: { tasksCompleted: 0 } },
|
|
91
|
+
'swarm/init': { id: 'swarm-1', topology: 'hierarchical-mesh' },
|
|
92
|
+
'swarm/status': { agents: 0, topology: 'hierarchical-mesh', status: 'active' },
|
|
93
|
+
'memory/store': { id: 'mem-1', stored: true },
|
|
94
|
+
'memory/search': [{ id: 'mem-1', content: 'test' }],
|
|
95
|
+
'memory/list': [{ id: 'mem-1', type: 'pattern' }],
|
|
96
|
+
'task/create': { id: 'task-1', status: 'pending' },
|
|
97
|
+
'config/load': { value: 'test-value' },
|
|
98
|
+
'config/save': { success: true },
|
|
99
|
+
'hooks/metrics': { patterns: 10, successRate: 0.85 },
|
|
100
|
+
'hooks/pretrain': { trained: true, patterns: 100 },
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
return responses[v3Name] || { success: true };
|
|
104
|
+
}),
|
|
105
|
+
getTools: vi.fn().mockReturnValue(v3Tools),
|
|
106
|
+
translateToolName: vi.fn().mockImplementation((v2Name: string) => TOOL_NAME_MAPPING[v2Name] || v2Name),
|
|
107
|
+
translateParams: vi.fn().mockImplementation((toolName: string, params: Record<string, unknown>) => {
|
|
108
|
+
// Parameter translation logic
|
|
109
|
+
if (toolName === 'dispatch_agent' || toolName === 'agents/spawn') {
|
|
110
|
+
return {
|
|
111
|
+
agentType: params.type,
|
|
112
|
+
id: params.name,
|
|
113
|
+
config: {
|
|
114
|
+
capabilities: params.capabilities,
|
|
115
|
+
systemPrompt: params.systemPrompt,
|
|
116
|
+
},
|
|
117
|
+
priority: (params.priority as number) > 5 ? 'high' : 'normal',
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (toolName === 'memory/query') {
|
|
122
|
+
return {
|
|
123
|
+
query: params.search,
|
|
124
|
+
searchType: 'hybrid',
|
|
125
|
+
type: params.type,
|
|
126
|
+
limit: params.limit || 10,
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if (toolName.includes('swarm_init')) {
|
|
131
|
+
return {
|
|
132
|
+
topology: params.topology || 'hierarchical-mesh',
|
|
133
|
+
maxAgents: params.maxAgents || 15,
|
|
134
|
+
config: {
|
|
135
|
+
consensusMechanism: params.consensus || 'majority',
|
|
136
|
+
},
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
return params;
|
|
141
|
+
}),
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
describe('V2 MCP Tool Compatibility', () => {
|
|
146
|
+
let validator: V2CompatibilityValidator;
|
|
147
|
+
let mockMCP: MockMCPClient;
|
|
148
|
+
|
|
149
|
+
beforeEach(() => {
|
|
150
|
+
mockMCP = createMockMCPClient();
|
|
151
|
+
validator = new V2CompatibilityValidator({
|
|
152
|
+
verbose: false,
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
afterEach(() => {
|
|
157
|
+
vi.clearAllMocks();
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
describe('Agent Tools', () => {
|
|
161
|
+
const agentTools = V2_MCP_TOOLS.filter(t =>
|
|
162
|
+
t.name.includes('agent') || t.name === 'dispatch_agent'
|
|
163
|
+
);
|
|
164
|
+
|
|
165
|
+
it.each(agentTools)('should support V2 tool: $name', async (tool: V2MCPTool) => {
|
|
166
|
+
const params = Object.fromEntries(
|
|
167
|
+
Object.entries(tool.parameters)
|
|
168
|
+
.filter(([, def]) => def.required)
|
|
169
|
+
.map(([key, def]) => [key, def.type === 'string' ? 'test' : {}])
|
|
170
|
+
);
|
|
171
|
+
|
|
172
|
+
const result = await mockMCP.callTool(tool.name, params);
|
|
173
|
+
|
|
174
|
+
expect(result).toBeDefined();
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
it('should translate dispatch_agent to agent/spawn', () => {
|
|
178
|
+
const v3Name = mockMCP.translateToolName('dispatch_agent');
|
|
179
|
+
|
|
180
|
+
expect(v3Name).toBe('agent/spawn');
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
it('should translate agents/spawn to agent/spawn', () => {
|
|
184
|
+
const v3Name = mockMCP.translateToolName('agents/spawn');
|
|
185
|
+
|
|
186
|
+
expect(v3Name).toBe('agent/spawn');
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
it('should translate agents/info to agent/status', () => {
|
|
190
|
+
const v3Name = mockMCP.translateToolName('agents/info');
|
|
191
|
+
|
|
192
|
+
expect(v3Name).toBe('agent/status');
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
it('should translate agent parameters correctly', () => {
|
|
196
|
+
const v2Params = {
|
|
197
|
+
type: 'coder',
|
|
198
|
+
name: 'my-coder',
|
|
199
|
+
capabilities: ['coding'],
|
|
200
|
+
priority: 8,
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
const v3Params = mockMCP.translateParams('dispatch_agent', v2Params);
|
|
204
|
+
|
|
205
|
+
expect(v3Params.agentType).toBe('coder');
|
|
206
|
+
expect(v3Params.id).toBe('my-coder');
|
|
207
|
+
expect(v3Params.priority).toBe('high');
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
it('should handle mcp__ruv-swarm__agent_spawn', async () => {
|
|
211
|
+
const result = await mockMCP.callTool('mcp__ruv-swarm__agent_spawn', { type: 'coder' });
|
|
212
|
+
|
|
213
|
+
expect(result).toHaveProperty('id');
|
|
214
|
+
expect(result).toHaveProperty('type');
|
|
215
|
+
});
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
describe('Swarm Tools', () => {
|
|
219
|
+
const swarmTools = V2_MCP_TOOLS.filter(t => t.name.includes('swarm'));
|
|
220
|
+
|
|
221
|
+
it.each(swarmTools)('should support V2 tool: $name', async (tool: V2MCPTool) => {
|
|
222
|
+
const params = Object.fromEntries(
|
|
223
|
+
Object.entries(tool.parameters)
|
|
224
|
+
.filter(([, def]) => def.required)
|
|
225
|
+
.map(([key, def]) => [key, def.type === 'string' ? 'test' : {}])
|
|
226
|
+
);
|
|
227
|
+
|
|
228
|
+
const result = await mockMCP.callTool(tool.name, params);
|
|
229
|
+
|
|
230
|
+
expect(result).toBeDefined();
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
it('should translate swarm_status to swarm/status', () => {
|
|
234
|
+
const v3Name = mockMCP.translateToolName('swarm_status');
|
|
235
|
+
|
|
236
|
+
expect(v3Name).toBe('swarm/status');
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
it('should translate swarm/get-comprehensive-status to swarm/status', () => {
|
|
240
|
+
const v3Name = mockMCP.translateToolName('swarm/get-comprehensive-status');
|
|
241
|
+
|
|
242
|
+
expect(v3Name).toBe('swarm/status');
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
it('should translate swarm init parameters', () => {
|
|
246
|
+
const v2Params = {
|
|
247
|
+
topology: 'mesh',
|
|
248
|
+
maxAgents: 10,
|
|
249
|
+
consensus: 'quorum',
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
const v3Params = mockMCP.translateParams('mcp__ruv-swarm__swarm_init', v2Params);
|
|
253
|
+
|
|
254
|
+
expect(v3Params.topology).toBe('mesh');
|
|
255
|
+
expect(v3Params.maxAgents).toBe(10);
|
|
256
|
+
expect(v3Params.config).toHaveProperty('consensusMechanism');
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
it('should return compatible swarm status response', async () => {
|
|
260
|
+
const result = await mockMCP.callTool('swarm_status', {}) as Record<string, unknown>;
|
|
261
|
+
|
|
262
|
+
expect(result).toHaveProperty('agents');
|
|
263
|
+
expect(result).toHaveProperty('topology');
|
|
264
|
+
expect(result).toHaveProperty('status');
|
|
265
|
+
});
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
describe('Memory Tools', () => {
|
|
269
|
+
const memoryTools = V2_MCP_TOOLS.filter(t => t.name.includes('memory'));
|
|
270
|
+
|
|
271
|
+
it.each(memoryTools)('should support V2 tool: $name', async (tool: V2MCPTool) => {
|
|
272
|
+
const params = Object.fromEntries(
|
|
273
|
+
Object.entries(tool.parameters)
|
|
274
|
+
.filter(([, def]) => def.required)
|
|
275
|
+
.map(([key, def]) => [key, def.type === 'string' ? 'test' : {}])
|
|
276
|
+
);
|
|
277
|
+
|
|
278
|
+
const result = await mockMCP.callTool(tool.name, params);
|
|
279
|
+
|
|
280
|
+
expect(result).toBeDefined();
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
it('should translate memory/query to memory/search', () => {
|
|
284
|
+
const v3Name = mockMCP.translateToolName('memory/query');
|
|
285
|
+
|
|
286
|
+
expect(v3Name).toBe('memory/search');
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
it('should translate memory query parameters', () => {
|
|
290
|
+
const v2Params = {
|
|
291
|
+
search: 'test query',
|
|
292
|
+
type: 'pattern',
|
|
293
|
+
limit: 20,
|
|
294
|
+
};
|
|
295
|
+
|
|
296
|
+
const v3Params = mockMCP.translateParams('memory/query', v2Params);
|
|
297
|
+
|
|
298
|
+
expect(v3Params.query).toBe('test query');
|
|
299
|
+
expect(v3Params.searchType).toBe('hybrid');
|
|
300
|
+
expect(v3Params.limit).toBe(20);
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
it('should return array from memory search', async () => {
|
|
304
|
+
const result = await mockMCP.callTool('memory/query', { search: 'test' });
|
|
305
|
+
|
|
306
|
+
expect(Array.isArray(result)).toBe(true);
|
|
307
|
+
});
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
describe('Config Tools', () => {
|
|
311
|
+
it('should translate config/get to config/load', () => {
|
|
312
|
+
const v3Name = mockMCP.translateToolName('config/get');
|
|
313
|
+
|
|
314
|
+
expect(v3Name).toBe('config/load');
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
it('should translate config/update to config/save', () => {
|
|
318
|
+
const v3Name = mockMCP.translateToolName('config/update');
|
|
319
|
+
|
|
320
|
+
expect(v3Name).toBe('config/save');
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
it('should handle config get operation', async () => {
|
|
324
|
+
const result = await mockMCP.callTool('config/get', { key: 'test.key' }) as Record<string, unknown>;
|
|
325
|
+
|
|
326
|
+
expect(result).toHaveProperty('value');
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
it('should handle config update operation', async () => {
|
|
330
|
+
const result = await mockMCP.callTool('config/update', {
|
|
331
|
+
key: 'test.key',
|
|
332
|
+
value: 'new-value',
|
|
333
|
+
}) as Record<string, unknown>;
|
|
334
|
+
|
|
335
|
+
expect(result).toHaveProperty('success');
|
|
336
|
+
});
|
|
337
|
+
});
|
|
338
|
+
|
|
339
|
+
describe('Task Tools', () => {
|
|
340
|
+
const taskTools = V2_MCP_TOOLS.filter(t => t.name.startsWith('task/'));
|
|
341
|
+
|
|
342
|
+
it.each(taskTools)('should support V2 tool: $name', async (tool: V2MCPTool) => {
|
|
343
|
+
const params = Object.fromEntries(
|
|
344
|
+
Object.entries(tool.parameters)
|
|
345
|
+
.filter(([, def]) => def.required)
|
|
346
|
+
.map(([key, def]) => [key, def.type === 'string' ? 'test' : 'test'])
|
|
347
|
+
);
|
|
348
|
+
|
|
349
|
+
const result = await mockMCP.callTool(tool.name, params);
|
|
350
|
+
|
|
351
|
+
expect(result).toBeDefined();
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
it('should create task with description', async () => {
|
|
355
|
+
const result = await mockMCP.callTool('task/create', {
|
|
356
|
+
description: 'Test task',
|
|
357
|
+
}) as Record<string, unknown>;
|
|
358
|
+
|
|
359
|
+
expect(result).toHaveProperty('id');
|
|
360
|
+
expect(result).toHaveProperty('status');
|
|
361
|
+
});
|
|
362
|
+
|
|
363
|
+
it('should assign task to agent', async () => {
|
|
364
|
+
const result = await mockMCP.callTool('task/assign', {
|
|
365
|
+
taskId: 'task-1',
|
|
366
|
+
agentId: 'agent-1',
|
|
367
|
+
});
|
|
368
|
+
|
|
369
|
+
expect(result).toBeDefined();
|
|
370
|
+
});
|
|
371
|
+
});
|
|
372
|
+
|
|
373
|
+
describe('Neural/Learning Tools', () => {
|
|
374
|
+
it('should translate neural_status to hooks/metrics', () => {
|
|
375
|
+
const v3Name = mockMCP.translateToolName('mcp__ruv-swarm__neural_status');
|
|
376
|
+
|
|
377
|
+
expect(v3Name).toBe('hooks/metrics');
|
|
378
|
+
});
|
|
379
|
+
|
|
380
|
+
it('should translate neural_train to hooks/pretrain', () => {
|
|
381
|
+
const v3Name = mockMCP.translateToolName('mcp__ruv-swarm__neural_train');
|
|
382
|
+
|
|
383
|
+
expect(v3Name).toBe('hooks/pretrain');
|
|
384
|
+
});
|
|
385
|
+
|
|
386
|
+
it('should return compatible metrics response', async () => {
|
|
387
|
+
const result = await mockMCP.callTool('mcp__ruv-swarm__neural_status', {}) as Record<string, unknown>;
|
|
388
|
+
|
|
389
|
+
expect(result).toHaveProperty('patterns');
|
|
390
|
+
expect(result).toHaveProperty('successRate');
|
|
391
|
+
});
|
|
392
|
+
|
|
393
|
+
it('should handle pretrain operation', async () => {
|
|
394
|
+
const result = await mockMCP.callTool('mcp__ruv-swarm__neural_train', {
|
|
395
|
+
data: { source: 'repo' },
|
|
396
|
+
}) as Record<string, unknown>;
|
|
397
|
+
|
|
398
|
+
expect(result).toHaveProperty('trained');
|
|
399
|
+
});
|
|
400
|
+
});
|
|
401
|
+
|
|
402
|
+
describe('GitHub Tools', () => {
|
|
403
|
+
const githubTools = V2_MCP_TOOLS.filter(t => t.name.startsWith('github/'));
|
|
404
|
+
|
|
405
|
+
it.each(githubTools)('should support V2 tool: $name', async (tool: V2MCPTool) => {
|
|
406
|
+
const params = Object.fromEntries(
|
|
407
|
+
Object.entries(tool.parameters)
|
|
408
|
+
.filter(([, def]) => def.required)
|
|
409
|
+
.map(([key, def]) => {
|
|
410
|
+
if (def.type === 'number') return [key, 1];
|
|
411
|
+
return [key, 'test'];
|
|
412
|
+
})
|
|
413
|
+
);
|
|
414
|
+
|
|
415
|
+
const result = await mockMCP.callTool(tool.name, params);
|
|
416
|
+
|
|
417
|
+
expect(result).toBeDefined();
|
|
418
|
+
});
|
|
419
|
+
|
|
420
|
+
it('should handle PR creation', async () => {
|
|
421
|
+
const result = await mockMCP.callTool('github/pr-create', {
|
|
422
|
+
title: 'Test PR',
|
|
423
|
+
body: 'Test body',
|
|
424
|
+
});
|
|
425
|
+
|
|
426
|
+
expect(result).toBeDefined();
|
|
427
|
+
});
|
|
428
|
+
|
|
429
|
+
it('should handle PR review', async () => {
|
|
430
|
+
const result = await mockMCP.callTool('github/pr-review', {
|
|
431
|
+
prNumber: 123,
|
|
432
|
+
});
|
|
433
|
+
|
|
434
|
+
expect(result).toBeDefined();
|
|
435
|
+
});
|
|
436
|
+
});
|
|
437
|
+
|
|
438
|
+
describe('Error Handling', () => {
|
|
439
|
+
it('should throw for unknown tool', async () => {
|
|
440
|
+
await expect(mockMCP.callTool('unknown/tool', {}))
|
|
441
|
+
.rejects.toThrow('Tool not found');
|
|
442
|
+
});
|
|
443
|
+
|
|
444
|
+
it('should handle missing required parameters gracefully', async () => {
|
|
445
|
+
// Tool should still be callable even with empty params for testing
|
|
446
|
+
const result = await mockMCP.callTool('agent/list', {});
|
|
447
|
+
|
|
448
|
+
expect(result).toBeDefined();
|
|
449
|
+
});
|
|
450
|
+
});
|
|
451
|
+
|
|
452
|
+
describe('Full MCP Validation', () => {
|
|
453
|
+
it('should pass full MCP validation', async () => {
|
|
454
|
+
const result: ValidationResult = await validator.validateMCPTools();
|
|
455
|
+
|
|
456
|
+
expect(result.category).toBe('mcp');
|
|
457
|
+
expect(result.totalChecks).toBeGreaterThan(0);
|
|
458
|
+
expect(result.passedChecks).toBeGreaterThan(0);
|
|
459
|
+
});
|
|
460
|
+
|
|
461
|
+
it('should detect all V2 MCP tools', async () => {
|
|
462
|
+
const result = await validator.validateMCPTools();
|
|
463
|
+
const toolChecks = result.checks.filter(c => c.name.startsWith('MCP Tool:'));
|
|
464
|
+
|
|
465
|
+
expect(toolChecks.length).toBeGreaterThanOrEqual(V2_MCP_TOOLS.length);
|
|
466
|
+
});
|
|
467
|
+
|
|
468
|
+
it('should verify parameter translation', async () => {
|
|
469
|
+
const result = await validator.validateMCPTools();
|
|
470
|
+
const paramChecks = result.checks.filter(c => c.name.includes('Param:'));
|
|
471
|
+
|
|
472
|
+
expect(paramChecks.length).toBeGreaterThan(0);
|
|
473
|
+
});
|
|
474
|
+
|
|
475
|
+
it('should identify V3 equivalents', async () => {
|
|
476
|
+
const result = await validator.validateMCPTools();
|
|
477
|
+
|
|
478
|
+
for (const check of result.checks.filter(c => c.name.startsWith('MCP Tool:'))) {
|
|
479
|
+
if (check.passed && check.details) {
|
|
480
|
+
expect(check.details.v3Equivalent).toBeDefined();
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
});
|
|
484
|
+
|
|
485
|
+
it('should report breaking changes correctly', async () => {
|
|
486
|
+
const result = await validator.validateMCPTools();
|
|
487
|
+
|
|
488
|
+
// Most tools should have V3 equivalents
|
|
489
|
+
expect(result.breakingChanges).toBeLessThan(result.totalChecks * 0.2);
|
|
490
|
+
});
|
|
491
|
+
});
|
|
492
|
+
|
|
493
|
+
describe('Response Format Compatibility', () => {
|
|
494
|
+
it('should return consistent agent info format', async () => {
|
|
495
|
+
const result = await mockMCP.callTool('dispatch_agent', { type: 'coder' }) as Record<string, unknown>;
|
|
496
|
+
|
|
497
|
+
expect(result).toHaveProperty('id');
|
|
498
|
+
expect(result).toHaveProperty('type');
|
|
499
|
+
expect(result).toHaveProperty('status');
|
|
500
|
+
});
|
|
501
|
+
|
|
502
|
+
it('should return array for list operations', async () => {
|
|
503
|
+
const agentList = await mockMCP.callTool('agents/list', {});
|
|
504
|
+
const memoryList = await mockMCP.callTool('memory/query', { search: 'test' });
|
|
505
|
+
|
|
506
|
+
expect(Array.isArray(agentList)).toBe(true);
|
|
507
|
+
expect(Array.isArray(memoryList)).toBe(true);
|
|
508
|
+
});
|
|
509
|
+
|
|
510
|
+
it('should return success boolean for mutations', async () => {
|
|
511
|
+
const terminateResult = await mockMCP.callTool('agents/terminate', { id: 'agent-1' }) as Record<string, unknown>;
|
|
512
|
+
const configResult = await mockMCP.callTool('config/update', { key: 'k', value: 'v' }) as Record<string, unknown>;
|
|
513
|
+
|
|
514
|
+
expect(terminateResult).toHaveProperty('success');
|
|
515
|
+
expect(configResult).toHaveProperty('success');
|
|
516
|
+
});
|
|
517
|
+
});
|
|
518
|
+
});
|
|
519
|
+
|
|
520
|
+
describe('MCP Tool Coverage', () => {
|
|
521
|
+
it('should define at least 30 V2 MCP tools', () => {
|
|
522
|
+
expect(V2_MCP_TOOLS.length).toBeGreaterThanOrEqual(30);
|
|
523
|
+
});
|
|
524
|
+
|
|
525
|
+
it('should have V3 equivalents for most tools', () => {
|
|
526
|
+
const withEquivalent = V2_MCP_TOOLS.filter(t => t.v3Equivalent);
|
|
527
|
+
|
|
528
|
+
expect(withEquivalent.length).toBeGreaterThan(V2_MCP_TOOLS.length * 0.8);
|
|
529
|
+
});
|
|
530
|
+
|
|
531
|
+
it('should categorize tools correctly', () => {
|
|
532
|
+
const categories = {
|
|
533
|
+
agent: V2_MCP_TOOLS.filter(t => t.name.includes('agent') || t.name === 'dispatch_agent'),
|
|
534
|
+
swarm: V2_MCP_TOOLS.filter(t => t.name.includes('swarm')),
|
|
535
|
+
memory: V2_MCP_TOOLS.filter(t => t.name.includes('memory')),
|
|
536
|
+
config: V2_MCP_TOOLS.filter(t => t.name.includes('config')),
|
|
537
|
+
task: V2_MCP_TOOLS.filter(t => t.name.startsWith('task/')),
|
|
538
|
+
neural: V2_MCP_TOOLS.filter(t => t.name.includes('neural')),
|
|
539
|
+
github: V2_MCP_TOOLS.filter(t => t.name.startsWith('github/')),
|
|
540
|
+
coordinate: V2_MCP_TOOLS.filter(t => t.name.startsWith('coordinate/')),
|
|
541
|
+
};
|
|
542
|
+
|
|
543
|
+
expect(categories.agent.length).toBeGreaterThanOrEqual(6);
|
|
544
|
+
expect(categories.swarm.length).toBeGreaterThanOrEqual(5);
|
|
545
|
+
expect(categories.memory.length).toBeGreaterThanOrEqual(3);
|
|
546
|
+
});
|
|
547
|
+
|
|
548
|
+
it('should define required parameters correctly', () => {
|
|
549
|
+
for (const tool of V2_MCP_TOOLS) {
|
|
550
|
+
for (const [, def] of Object.entries(tool.parameters)) {
|
|
551
|
+
expect(def).toHaveProperty('type');
|
|
552
|
+
expect(def).toHaveProperty('required');
|
|
553
|
+
expect(typeof def.required).toBe('boolean');
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
});
|
|
557
|
+
});
|