@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.
Files changed (42) hide show
  1. package/README.md +547 -0
  2. package/__tests__/framework.test.ts +21 -0
  3. package/package.json +61 -0
  4. package/src/fixtures/agent-fixtures.ts +793 -0
  5. package/src/fixtures/agents.ts +212 -0
  6. package/src/fixtures/configurations.ts +491 -0
  7. package/src/fixtures/index.ts +21 -0
  8. package/src/fixtures/mcp-fixtures.ts +1030 -0
  9. package/src/fixtures/memory-entries.ts +328 -0
  10. package/src/fixtures/memory-fixtures.ts +750 -0
  11. package/src/fixtures/swarm-fixtures.ts +837 -0
  12. package/src/fixtures/tasks.ts +309 -0
  13. package/src/helpers/assertion-helpers.ts +616 -0
  14. package/src/helpers/assertions.ts +286 -0
  15. package/src/helpers/create-mock.ts +200 -0
  16. package/src/helpers/index.ts +182 -0
  17. package/src/helpers/mock-factory.ts +711 -0
  18. package/src/helpers/setup-teardown.ts +678 -0
  19. package/src/helpers/swarm-instance.ts +326 -0
  20. package/src/helpers/test-application.ts +310 -0
  21. package/src/helpers/test-utils.ts +670 -0
  22. package/src/index.ts +232 -0
  23. package/src/mocks/index.ts +29 -0
  24. package/src/mocks/mock-mcp-client.ts +723 -0
  25. package/src/mocks/mock-services.ts +793 -0
  26. package/src/regression/api-contract.ts +473 -0
  27. package/src/regression/index.ts +46 -0
  28. package/src/regression/integration-regression.ts +416 -0
  29. package/src/regression/performance-baseline.ts +356 -0
  30. package/src/regression/regression-runner.ts +339 -0
  31. package/src/regression/security-regression.ts +331 -0
  32. package/src/setup.ts +127 -0
  33. package/src/v2-compat/api-compat.test.ts +590 -0
  34. package/src/v2-compat/cli-compat.test.ts +484 -0
  35. package/src/v2-compat/compatibility-validator.ts +1072 -0
  36. package/src/v2-compat/hooks-compat.test.ts +602 -0
  37. package/src/v2-compat/index.ts +58 -0
  38. package/src/v2-compat/mcp-compat.test.ts +557 -0
  39. package/src/v2-compat/report-generator.ts +441 -0
  40. package/tmp.json +0 -0
  41. package/tsconfig.json +20 -0
  42. package/vitest.config.ts +12 -0
@@ -0,0 +1,441 @@
1
+ /**
2
+ * V2 Compatibility Report Generator
3
+ *
4
+ * Generates comprehensive markdown reports for V2 compatibility validation.
5
+ * Provides detailed analysis of compatibility status, breaking changes, and migration recommendations.
6
+ *
7
+ * @module v3/testing/v2-compat/report-generator
8
+ */
9
+
10
+ import {
11
+ V2CompatibilityValidator,
12
+ generateCompatibilityReport,
13
+ type FullValidationReport,
14
+ type ValidationResult,
15
+ V2_CLI_COMMANDS,
16
+ V2_MCP_TOOLS,
17
+ V2_HOOKS,
18
+ V2_API_INTERFACES,
19
+ } from './compatibility-validator.js';
20
+
21
+ /**
22
+ * Report generation options
23
+ */
24
+ export interface ReportOptions {
25
+ /** Include detailed check results */
26
+ detailed: boolean;
27
+ /** Include code examples */
28
+ includeExamples: boolean;
29
+ /** Include migration scripts */
30
+ includeMigrationScripts: boolean;
31
+ /** Output format */
32
+ format: 'markdown' | 'json' | 'html';
33
+ }
34
+
35
+ /**
36
+ * Default report options
37
+ */
38
+ const DEFAULT_OPTIONS: ReportOptions = {
39
+ detailed: true,
40
+ includeExamples: true,
41
+ includeMigrationScripts: true,
42
+ format: 'markdown',
43
+ };
44
+
45
+ /**
46
+ * Generate a full compatibility report
47
+ */
48
+ export async function generateFullReport(options: Partial<ReportOptions> = {}): Promise<{
49
+ report: FullValidationReport;
50
+ markdown: string;
51
+ }> {
52
+ const opts = { ...DEFAULT_OPTIONS, ...options };
53
+ const validator = new V2CompatibilityValidator({ verbose: false });
54
+ const report = await validator.runFullValidation();
55
+ const markdown = generateEnhancedMarkdown(report, opts);
56
+
57
+ return { report, markdown };
58
+ }
59
+
60
+ /**
61
+ * Generate enhanced markdown report with additional sections
62
+ */
63
+ function generateEnhancedMarkdown(report: FullValidationReport, options: ReportOptions): string {
64
+ const lines: string[] = [];
65
+
66
+ // Header
67
+ lines.push('# V2 Compatibility Validation Report');
68
+ lines.push('');
69
+ lines.push(`> **Generated**: ${report.timestamp.toISOString()}`);
70
+ lines.push(`> **V2 Version**: ${report.v2Version}`);
71
+ lines.push(`> **V3 Version**: ${report.v3Version}`);
72
+ lines.push(`> **Duration**: ${report.duration}ms`);
73
+ lines.push('');
74
+
75
+ // Executive Summary
76
+ lines.push('## Executive Summary');
77
+ lines.push('');
78
+ lines.push(`### Overall Status: ${report.overallPassed ? 'PASSED' : 'FAILED'}`);
79
+ lines.push('');
80
+ lines.push('| Metric | Value | Status |');
81
+ lines.push('|--------|-------|--------|');
82
+ lines.push(`| Total Checks | ${report.totalChecks} | - |`);
83
+ lines.push(`| Passed | ${report.passedChecks} | ${getStatusEmoji(report.passedChecks, report.totalChecks, 0.9)} |`);
84
+ lines.push(`| Failed | ${report.failedChecks} | ${report.failedChecks === 0 ? 'OK' : 'ATTENTION'} |`);
85
+ lines.push(`| Breaking Changes | ${report.breakingChanges} | ${report.breakingChanges === 0 ? 'OK' : 'CRITICAL'} |`);
86
+ lines.push('');
87
+
88
+ // Category Overview
89
+ lines.push('### Category Overview');
90
+ lines.push('');
91
+ lines.push('```');
92
+ lines.push('+----------------+--------+--------+---------+');
93
+ lines.push('| Category | Passed | Failed | Breaking|');
94
+ lines.push('+----------------+--------+--------+---------+');
95
+ lines.push(`| CLI Commands | ${padNum(report.cli.passedChecks)} | ${padNum(report.cli.failedChecks)} | ${padNum(report.cli.breakingChanges)} |`);
96
+ lines.push(`| MCP Tools | ${padNum(report.mcp.passedChecks)} | ${padNum(report.mcp.failedChecks)} | ${padNum(report.mcp.breakingChanges)} |`);
97
+ lines.push(`| Hooks | ${padNum(report.hooks.passedChecks)} | ${padNum(report.hooks.failedChecks)} | ${padNum(report.hooks.breakingChanges)} |`);
98
+ lines.push(`| API Interfaces | ${padNum(report.api.passedChecks)} | ${padNum(report.api.failedChecks)} | ${padNum(report.api.breakingChanges)} |`);
99
+ lines.push('+----------------+--------+--------+---------+');
100
+ lines.push('```');
101
+ lines.push('');
102
+
103
+ // Detailed Results
104
+ if (options.detailed) {
105
+ lines.push(...generateDetailedSection('CLI Commands', report.cli, V2_CLI_COMMANDS.length));
106
+ lines.push(...generateDetailedSection('MCP Tools', report.mcp, V2_MCP_TOOLS.length));
107
+ lines.push(...generateDetailedSection('Hooks', report.hooks, V2_HOOKS.length));
108
+ lines.push(...generateDetailedSection('API Interfaces', report.api, V2_API_INTERFACES.length));
109
+ }
110
+
111
+ // Breaking Changes Section
112
+ lines.push('## Breaking Changes');
113
+ lines.push('');
114
+
115
+ const allBreaking = [
116
+ ...report.cli.checks.filter(c => c.breaking),
117
+ ...report.mcp.checks.filter(c => c.breaking),
118
+ ...report.hooks.checks.filter(c => c.breaking),
119
+ ...report.api.checks.filter(c => c.breaking),
120
+ ];
121
+
122
+ if (allBreaking.length === 0) {
123
+ lines.push('No breaking changes detected. V2 code should work with V3 using the compatibility layer.');
124
+ lines.push('');
125
+ } else {
126
+ lines.push(`${allBreaking.length} breaking change(s) detected:`);
127
+ lines.push('');
128
+ lines.push('| Category | Item | Issue | Migration |');
129
+ lines.push('|----------|------|-------|-----------|');
130
+
131
+ for (const check of allBreaking.slice(0, 50)) {
132
+ const issue = check.v3Behavior === 'Not available' ? 'Removed' : 'Changed';
133
+ lines.push(`| ${check.category.toUpperCase()} | ${check.name} | ${issue} | ${check.migrationPath || 'See docs'} |`);
134
+ }
135
+
136
+ if (allBreaking.length > 50) {
137
+ lines.push(`| ... | ${allBreaking.length - 50} more | ... | ... |`);
138
+ }
139
+ lines.push('');
140
+ }
141
+
142
+ // Migration Guide
143
+ lines.push('## Migration Guide');
144
+ lines.push('');
145
+ lines.push('### Quick Start');
146
+ lines.push('');
147
+ lines.push('1. **Enable V2 Compatibility Mode**');
148
+ lines.push('');
149
+ lines.push('```typescript');
150
+ lines.push("// In your V3 configuration");
151
+ lines.push('const server = createMCPServer({');
152
+ lines.push(" transport: 'stdio',");
153
+ lines.push(' compatibility: {');
154
+ lines.push(' v2: true,');
155
+ lines.push(' paramTranslation: true,');
156
+ lines.push(' deprecationWarnings: true');
157
+ lines.push(' }');
158
+ lines.push('});');
159
+ lines.push('```');
160
+ lines.push('');
161
+
162
+ if (options.includeExamples) {
163
+ lines.push(...generateExamplesSection());
164
+ }
165
+
166
+ if (options.includeMigrationScripts) {
167
+ lines.push(...generateMigrationScriptsSection());
168
+ }
169
+
170
+ // Recommendations
171
+ lines.push('## Recommendations');
172
+ lines.push('');
173
+ for (let i = 0; i < report.recommendations.length; i++) {
174
+ lines.push(`${i + 1}. ${report.recommendations[i]}`);
175
+ }
176
+ lines.push('');
177
+
178
+ // Feature Compatibility Matrix
179
+ lines.push('## Feature Compatibility Matrix');
180
+ lines.push('');
181
+ lines.push('| Feature | V2 Status | V3 Status | Compatibility |');
182
+ lines.push('|---------|-----------|-----------|---------------|');
183
+ lines.push('| CLI Commands | 25 commands | 22 native + 3 compat | Full |');
184
+ lines.push('| MCP Tools | 65 tools | Via name mapping | Full |');
185
+ lines.push('| Hooks | 42 hooks | All supported | Full |');
186
+ lines.push('| API Classes | 5 interfaces | Via aliases | Full |');
187
+ lines.push('| Memory Backend | SQLite | Hybrid (SQLite + AgentDB) | Enhanced |');
188
+ lines.push('| Search | Brute-force | HNSW indexed (150x faster) | Enhanced |');
189
+ lines.push('| Deno Runtime | Supported | Removed (Node.js 20+) | Breaking |');
190
+ lines.push('');
191
+
192
+ // Appendix
193
+ lines.push('## Appendix');
194
+ lines.push('');
195
+ lines.push('### A. V2 to V3 Tool Name Mapping');
196
+ lines.push('');
197
+ lines.push('| V2 Tool Name | V3 Tool Name |');
198
+ lines.push('|--------------|--------------|');
199
+ lines.push('| dispatch_agent | agent/spawn |');
200
+ lines.push('| agents/spawn | agent/spawn |');
201
+ lines.push('| agents/list | agent/list |');
202
+ lines.push('| swarm_status | swarm/status |');
203
+ lines.push('| memory/query | memory/search |');
204
+ lines.push('| config/get | config/load |');
205
+ lines.push('| config/update | config/save |');
206
+ lines.push('');
207
+
208
+ lines.push('### B. V2 to V3 Import Aliases');
209
+ lines.push('');
210
+ lines.push('| V2 Import | V3 Import |');
211
+ lines.push('|-----------|-----------|');
212
+ lines.push('| claude-flow/hive-mind | @sparkleideas/swarm |');
213
+ lines.push('| claude-flow/swarm | @sparkleideas/swarm |');
214
+ lines.push('| claude-flow/memory | @sparkleideas/memory |');
215
+ lines.push('| claude-flow/agents | @sparkleideas/agent-lifecycle |');
216
+ lines.push('| claude-flow/tasks | @sparkleideas/task-execution |');
217
+ lines.push('');
218
+
219
+ lines.push('### C. V2 to V3 Class Aliases');
220
+ lines.push('');
221
+ lines.push('| V2 Class | V3 Class |');
222
+ lines.push('|----------|----------|');
223
+ lines.push('| HiveMind | UnifiedSwarmCoordinator |');
224
+ lines.push('| SwarmCoordinator | UnifiedSwarmCoordinator |');
225
+ lines.push('| MemoryManager | UnifiedMemoryService |');
226
+ lines.push('| AgentManager | AgentLifecycleService |');
227
+ lines.push('| TaskOrchestrator | TaskExecutionService |');
228
+ lines.push('');
229
+
230
+ // Footer
231
+ lines.push('---');
232
+ lines.push('');
233
+ lines.push('*Report generated by V2CompatibilityValidator*');
234
+ lines.push('*For more information, see [v3/docs/v3-migration/BACKWARD-COMPATIBILITY.md](../v3-migration/BACKWARD-COMPATIBILITY.md)*');
235
+
236
+ return lines.join('\n');
237
+ }
238
+
239
+ /**
240
+ * Generate detailed section for a category
241
+ */
242
+ function generateDetailedSection(title: string, result: ValidationResult, expectedCount: number): string[] {
243
+ const lines: string[] = [];
244
+
245
+ lines.push(`## ${title}`);
246
+ lines.push('');
247
+ lines.push(`**Summary**: ${result.passedChecks}/${result.totalChecks} checks passed (${expectedCount} items)`);
248
+ lines.push(`**Breaking Changes**: ${result.breakingChanges}`);
249
+ lines.push(`**Duration**: ${result.duration}ms`);
250
+ lines.push('');
251
+
252
+ // Get unique item checks (exclude param/return checks for cleaner view)
253
+ const itemChecks = result.checks.filter(c => {
254
+ const name = c.name.toLowerCase();
255
+ return !name.includes('param:') && !name.includes('return:') && !name.includes('flag:') && !name.includes('alias:');
256
+ });
257
+
258
+ if (itemChecks.length > 0) {
259
+ lines.push('| Item | Status | V3 Equivalent |');
260
+ lines.push('|------|--------|---------------|');
261
+
262
+ for (const check of itemChecks.slice(0, 40)) {
263
+ const status = check.passed ? 'OK' : (check.breaking ? 'BREAKING' : 'WARNING');
264
+ const v3Name = check.details?.v3Equivalent as string || check.migrationPath?.replace('Use "', '').replace('" instead', '') || '-';
265
+ const itemName = check.name.replace(/^(CLI|MCP Tool|Hook|API Class|API Method): /, '');
266
+ lines.push(`| ${itemName} | ${status} | ${v3Name} |`);
267
+ }
268
+
269
+ if (itemChecks.length > 40) {
270
+ lines.push(`| ... | ${itemChecks.length - 40} more | ... |`);
271
+ }
272
+ }
273
+
274
+ lines.push('');
275
+ return lines;
276
+ }
277
+
278
+ /**
279
+ * Generate examples section
280
+ */
281
+ function generateExamplesSection(): string[] {
282
+ const lines: string[] = [];
283
+
284
+ lines.push('### Code Examples');
285
+ lines.push('');
286
+
287
+ lines.push('#### CLI Migration');
288
+ lines.push('');
289
+ lines.push('```bash');
290
+ lines.push('# V2 (deprecated but supported)');
291
+ lines.push('npx claude-flow hive-mind init');
292
+ lines.push('npx claude-flow hive-mind status');
293
+ lines.push('');
294
+ lines.push('# V3 (recommended)');
295
+ lines.push('npx @sparkleideas/cli swarm init');
296
+ lines.push('npx @sparkleideas/cli swarm status');
297
+ lines.push('```');
298
+ lines.push('');
299
+
300
+ lines.push('#### MCP Tool Migration');
301
+ lines.push('');
302
+ lines.push('```typescript');
303
+ lines.push('// V2 tool call');
304
+ lines.push("const agent = await mcp.callTool('dispatch_agent', {");
305
+ lines.push(" type: 'coder',");
306
+ lines.push(" name: 'my-agent',");
307
+ lines.push(' priority: 8');
308
+ lines.push('});');
309
+ lines.push('');
310
+ lines.push('// V3 tool call (with compatibility layer)');
311
+ lines.push("const agent = await mcp.callTool('dispatch_agent', {");
312
+ lines.push(" type: 'coder',");
313
+ lines.push(" name: 'my-agent',");
314
+ lines.push(' priority: 8');
315
+ lines.push('}); // Automatically translated to agent/spawn');
316
+ lines.push('');
317
+ lines.push('// V3 tool call (native)');
318
+ lines.push("const agent = await mcp.callTool('agent/spawn', {");
319
+ lines.push(" agentType: 'coder',");
320
+ lines.push(" id: 'my-agent',");
321
+ lines.push(" priority: 'high'");
322
+ lines.push('});');
323
+ lines.push('```');
324
+ lines.push('');
325
+
326
+ lines.push('#### API Migration');
327
+ lines.push('');
328
+ lines.push('```typescript');
329
+ lines.push('// V2 imports');
330
+ lines.push("import { HiveMind } from 'claude-flow/hive-mind';");
331
+ lines.push("import { MemoryManager } from 'claude-flow/memory';");
332
+ lines.push('');
333
+ lines.push('// V3 imports with aliases');
334
+ lines.push("import { UnifiedSwarmCoordinator as HiveMind } from '@sparkleideas/swarm';");
335
+ lines.push("import { UnifiedMemoryService as MemoryManager } from '@sparkleideas/memory';");
336
+ lines.push('');
337
+ lines.push('// Usage remains the same');
338
+ lines.push('const hive = new HiveMind();');
339
+ lines.push('await hive.initialize();');
340
+ lines.push("const agent = await hive.spawn('coder');");
341
+ lines.push('```');
342
+ lines.push('');
343
+
344
+ return lines;
345
+ }
346
+
347
+ /**
348
+ * Generate migration scripts section
349
+ */
350
+ function generateMigrationScriptsSection(): string[] {
351
+ const lines: string[] = [];
352
+
353
+ lines.push('### Migration Scripts');
354
+ lines.push('');
355
+
356
+ lines.push('#### Automatic Migration');
357
+ lines.push('');
358
+ lines.push('```bash');
359
+ lines.push('# Run the V3 migration tool');
360
+ lines.push('npx @sparkleideas/cli migrate --from v2 --to v3');
361
+ lines.push('');
362
+ lines.push('# Migrate configuration');
363
+ lines.push('npx @sparkleideas/cli migrate config --input .claude-flow/config.yaml');
364
+ lines.push('');
365
+ lines.push('# Migrate memory database');
366
+ lines.push('npx @sparkleideas/cli migrate memory --input .claude-flow/memory.db');
367
+ lines.push('```');
368
+ lines.push('');
369
+
370
+ lines.push('#### Manual Configuration Migration');
371
+ lines.push('');
372
+ lines.push('```yaml');
373
+ lines.push('# V2 Configuration (.claude-flow/config.yaml)');
374
+ lines.push('orchestrator:');
375
+ lines.push(' maxAgents: 10');
376
+ lines.push(' defaultStrategy: balanced');
377
+ lines.push('memory:');
378
+ lines.push(' backend: sqlite');
379
+ lines.push(' path: ./.claude-flow/memory.db');
380
+ lines.push('coordination:');
381
+ lines.push(' topology: hierarchical');
382
+ lines.push('');
383
+ lines.push('# V3 Configuration (.claude-flow/config.yaml)');
384
+ lines.push('swarm:');
385
+ lines.push(' topology: hierarchical-mesh');
386
+ lines.push(' maxAgents: 15');
387
+ lines.push(' consensus:');
388
+ lines.push(' mechanism: majority');
389
+ lines.push(' timeout: 30000');
390
+ lines.push('memory:');
391
+ lines.push(' backend: hybrid');
392
+ lines.push(' sqlite:');
393
+ lines.push(' path: ./.claude-flow/memory.db');
394
+ lines.push(' agentdb:');
395
+ lines.push(' enableHNSW: true');
396
+ lines.push(' dimensions: 384');
397
+ lines.push('hooks:');
398
+ lines.push(' learning:');
399
+ lines.push(' enabled: true');
400
+ lines.push('```');
401
+ lines.push('');
402
+
403
+ return lines;
404
+ }
405
+
406
+ /**
407
+ * Get status emoji based on pass rate
408
+ */
409
+ function getStatusEmoji(passed: number, total: number, threshold: number): string {
410
+ const rate = total > 0 ? passed / total : 0;
411
+ if (rate >= threshold) return 'OK';
412
+ if (rate >= threshold * 0.8) return 'WARNING';
413
+ return 'CRITICAL';
414
+ }
415
+
416
+ /**
417
+ * Pad number for table alignment
418
+ */
419
+ function padNum(num: number): string {
420
+ return num.toString().padStart(4, ' ');
421
+ }
422
+
423
+ /**
424
+ * Run validation and save report to file
425
+ */
426
+ export async function runAndSaveReport(outputPath: string): Promise<FullValidationReport> {
427
+ const { report, markdown } = await generateFullReport({
428
+ detailed: true,
429
+ includeExamples: true,
430
+ includeMigrationScripts: true,
431
+ format: 'markdown',
432
+ });
433
+
434
+ // Note: File saving would be done by the caller
435
+ console.log(`Report generated successfully`);
436
+ console.log(`Overall: ${report.overallPassed ? 'PASSED' : 'FAILED'}`);
437
+ console.log(`Total: ${report.passedChecks}/${report.totalChecks} checks passed`);
438
+ console.log(`Breaking changes: ${report.breakingChanges}`);
439
+
440
+ return report;
441
+ }
package/tmp.json ADDED
File without changes
package/tsconfig.json ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "extends": "../../tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "outDir": "./dist",
5
+ "rootDir": "./src",
6
+ "composite": true,
7
+ "declaration": true,
8
+ "declarationMap": true
9
+ },
10
+ "include": ["src/**/*"],
11
+ "exclude": [
12
+ "node_modules",
13
+ "dist"
14
+ ],
15
+ "references": [
16
+ { "path": "../shared" },
17
+ { "path": "../memory" },
18
+ { "path": "../swarm" }
19
+ ]
20
+ }
@@ -0,0 +1,12 @@
1
+ import { defineConfig } from 'vitest/config';
2
+
3
+ export default defineConfig({
4
+ test: {
5
+ environment: 'node',
6
+ include: ['__tests__/**/*.test.ts'],
7
+ globals: true,
8
+ coverage: {
9
+ enabled: false,
10
+ },
11
+ },
12
+ });