UNPKG

initrepo-claude-agent

Version:

Autonomous AI agent for Claude Code - Build InitRepo projects with minimal human intervention

174 lines (149 loc) โ€ข 4.9 kB
#!/usr/bin/env node /** * Test InitRepo Claude Code Commands * * Verifies that all commands can execute properly and handle errors gracefully. */ import { spawn } from 'child_process'; import { existsSync } from 'fs'; import path from 'path'; class CommandTester { constructor() { this.workingDirectory = process.cwd(); this.passed = 0; this.failed = 0; this.results = []; } async runTests() { console.log('๐Ÿงช Testing InitRepo Claude Code Commands'); console.log('========================================'); console.log(`๐Ÿ“ Working Directory: ${this.workingDirectory}\n`); const tests = [ { name: 'Status Command', command: 'node', args: ['node_modules/initrepo-claude-agent/claude-code-extension/commands/status.js'], expectSuccess: true }, { name: 'Check Command', command: 'npx', args: ['initrepo-claude', '--check'], expectSuccess: true }, { name: 'Verify Command (no args)', command: 'node', args: ['node_modules/initrepo-claude-agent/claude-code-extension/commands/verify.js'], expectSuccess: true }, { name: 'Search Command', command: 'node', args: ['node_modules/initrepo-claude-agent/claude-code-extension/commands/smart-search.js', 'test'], expectSuccess: true } ]; for (const test of tests) { await this.runTest(test); } this.printSummary(); } async runTest(test) { console.log(`๐Ÿ” Testing: ${test.name}`); try { const result = await this.executeCommand(test.command, test.args); if (result.success === test.expectSuccess) { console.log(` โœ… PASSED - ${test.name}`); this.passed++; this.results.push({ test: test.name, status: 'PASSED', details: result.output.substring(0, 100) }); } else { console.log(` โŒ FAILED - ${test.name}`); console.log(` Expected success: ${test.expectSuccess}, Got: ${result.success}`); console.log(` Error: ${result.error}`); this.failed++; this.results.push({ test: test.name, status: 'FAILED', details: result.error }); } } catch (error) { console.log(` โŒ FAILED - ${test.name}`); console.log(` Exception: ${error.message}`); this.failed++; this.results.push({ test: test.name, status: 'FAILED', details: error.message }); } console.log(); } executeCommand(command, args) { return new Promise((resolve) => { const process = spawn(command, args, { cwd: this.workingDirectory, stdio: ['pipe', 'pipe', 'pipe'] }); let stdout = ''; let stderr = ''; process.stdout.on('data', (data) => { stdout += data.toString(); }); process.stderr.on('data', (data) => { stderr += data.toString(); }); process.on('close', (code) => { resolve({ success: code === 0, code, output: stdout, error: stderr, fullOutput: stdout + stderr }); }); process.on('error', (error) => { resolve({ success: false, code: -1, output: '', error: error.message, fullOutput: error.message }); }); // Timeout after 30 seconds setTimeout(() => { process.kill(); resolve({ success: false, code: -1, output: stdout, error: 'Command timeout', fullOutput: stdout + stderr + '\nCommand timeout' }); }, 30000); }); } printSummary() { console.log('๐Ÿ“Š Test Summary'); console.log('==============='); console.log(`โœ… Passed: ${this.passed}`); console.log(`โŒ Failed: ${this.failed}`); console.log(`๐Ÿ“Š Total: ${this.passed + this.failed}`); if (this.failed > 0) { console.log('\nโŒ Failed Tests:'); this.results.filter(r => r.status === 'FAILED').forEach(result => { console.log(` โ€ข ${result.test}: ${result.details}`); }); } const successRate = (this.passed / (this.passed + this.failed)) * 100; console.log(`\n๐ŸŽฏ Success Rate: ${successRate.toFixed(1)}%`); if (successRate >= 75) { console.log('๐ŸŽ‰ Commands are working well!'); } else { console.log('โš ๏ธ Some commands need attention.'); } } } // CLI execution if (import.meta.url === `file://${process.argv[1]}`) { const tester = new CommandTester(); tester.runTests().catch(error => { console.error('โŒ Test runner failed:', error.message); process.exit(1); }); } export default CommandTester;