UNPKG

mira-consciousness

Version:

Memory & Intelligence Retention Archive - Preserving The Spark

76 lines 3.63 kB
import { Command } from 'commander'; import chalk from 'chalk'; import ora from 'ora'; import { TestDetector } from '../core/TestDetector.js'; export function createTestCommand() { return new Command('test') .description('Smart test detection and execution') .option('--create-hook', 'Create a sample .mira-test-hook.sh file') .option('--detect-only', 'Only detect available tests without running') .option('--verbose', 'Show detailed test detection information') .action(async (options) => { const detector = new TestDetector(); // Handle hook creation if (options.createHook) { detector.createSampleTestHook(); return; } console.log(chalk.blue('\n🧪 MIRA Smart Test Detection\n')); const spinner = ora('Detecting available test configurations...').start(); try { const configs = await detector.detectTests(); spinner.stop(); if (configs.length === 0) { console.log(chalk.yellow('⚠️ No test configurations detected')); console.log(chalk.gray('\nTo define custom tests, create .mira-test-hook.sh:')); console.log(chalk.cyan(' mira test --create-hook')); console.log(chalk.gray('\nOr ensure your project has one of:')); console.log(chalk.gray(' • package.json with test script')); console.log(chalk.gray(' • pytest.ini or setup.py (Python)')); console.log(chalk.gray(' • Cargo.toml (Rust)')); console.log(chalk.gray(' • go.mod (Go)')); console.log(chalk.gray(' • docker-compose.yml')); console.log(chalk.gray(' • And more...')); return; } // Show detected configurations console.log(chalk.green(`✅ Found ${configs.length} test configuration${configs.length > 1 ? 's' : ''}:\n`)); if (options.verbose || options.detectOnly) { configs.forEach((config, index) => { console.log(chalk.cyan(`${index + 1}. ${config.type}`)); console.log(chalk.gray(` Command: ${config.command}`)); if (config.setupCommand) { console.log(chalk.gray(` Setup: ${config.setupCommand}`)); } console.log(chalk.gray(` Description: ${config.description}`)); console.log(); }); } if (options.detectOnly) { console.log(chalk.gray('Run "mira test" without --detect-only to execute tests')); return; } // Check for custom hook const customHook = configs.find(c => c.type === 'Custom Hook'); if (!customHook) { console.log(chalk.gray('💡 Tip: Create .mira-test-hook.sh for custom test commands')); console.log(); } // Run the tests const allPassed = await detector.runTests(configs); if (allPassed) { console.log(chalk.green('\n✅ All tests passed!')); } else { console.log(chalk.red('\n❌ Some tests failed')); process.exit(1); } } catch (error) { spinner.fail('Test detection failed'); console.error(chalk.red(`Error: ${error instanceof Error ? error.message : String(error)}`)); process.exit(1); } }); } //# sourceMappingURL=test.js.map