()
| 67 | } |
| 68 | |
| 69 | function runTests() { |
| 70 | console.log('\n=== Testing command registry generation ===\n'); |
| 71 | |
| 72 | let passed = 0; |
| 73 | let failed = 0; |
| 74 | |
| 75 | if (test('generates deterministic command metadata and usage statistics', () => { |
| 76 | const testDir = createTestDir(); |
| 77 | try { |
| 78 | writeFixture(testDir); |
| 79 | |
| 80 | const registry = generateRegistry({ root: testDir }); |
| 81 | |
| 82 | assert.strictEqual(registry.schemaVersion, 1); |
| 83 | assert.strictEqual(registry.totalCommands, 2); |
| 84 | assert.deepStrictEqual( |
| 85 | registry.commands.map(command => command.command), |
| 86 | ['review', 'tdd'] |
| 87 | ); |
| 88 | assert.deepStrictEqual(registry.commands[0].allAgents, ['code-reviewer']); |
| 89 | assert.deepStrictEqual(registry.commands[0].skills, ['security-review']); |
| 90 | assert.deepStrictEqual(registry.commands[1].allAgents, ['test-writer']); |
| 91 | assert.deepStrictEqual(registry.commands[1].skills, ['tdd-workflow']); |
| 92 | assert.deepStrictEqual(registry.statistics.byType, { review: 1, testing: 1 }); |
| 93 | assert.deepStrictEqual(registry.statistics.topAgents[0], { agent: 'code-reviewer', count: 1 }); |
| 94 | } finally { |
| 95 | cleanupTestDir(testDir); |
| 96 | } |
| 97 | })) passed++; else failed++; |
| 98 | |
| 99 | if (test('write and check modes use stable JSON without timestamps', () => { |
| 100 | const testDir = createTestDir(); |
| 101 | try { |
| 102 | writeFixture(testDir); |
| 103 | const outputPath = path.join(testDir, 'docs', 'COMMAND-REGISTRY.json'); |
| 104 | const registry = generateRegistry({ root: testDir }); |
| 105 | |
| 106 | writeRegistry(registry, outputPath); |
| 107 | const firstWrite = fs.readFileSync(outputPath, 'utf8'); |
| 108 | writeRegistry(registry, outputPath); |
| 109 | const secondWrite = fs.readFileSync(outputPath, 'utf8'); |
| 110 | |
| 111 | assert.strictEqual(firstWrite, secondWrite); |
| 112 | assert.ok(!firstWrite.includes('generated')); |
| 113 | assert.doesNotThrow(() => checkRegistry(registry, outputPath)); |
| 114 | } finally { |
| 115 | cleanupTestDir(testDir); |
| 116 | } |
| 117 | })) passed++; else failed++; |
| 118 | |
| 119 | if (test('check mode fails when the registry file is stale', () => { |
| 120 | const testDir = createTestDir(); |
| 121 | try { |
| 122 | writeFixture(testDir); |
| 123 | const outputPath = path.join(testDir, 'docs', 'COMMAND-REGISTRY.json'); |
| 124 | const registry = generateRegistry({ root: testDir }); |
| 125 | |
| 126 | fs.mkdirSync(path.dirname(outputPath), { recursive: true }); |
no test coverage detected