repository-analyzer
Version:
Transform code repositories into strategic intelligence using extensible AI agents. Analyze technical debt, business value, and deployment readiness automatically.
161 lines (141 loc) โข 5.68 kB
JavaScript
/**
* Test installation script for Repository Analyzer
* Validates that the package was installed correctly
*/
const fs = require('fs-extra');
const path = require('path');
const { execSync } = require('child_process');
const chalk = require('chalk');
async function testInstallation() {
console.log(chalk.blue('๐งช Testing Repository Analyzer installation...\n'));
let allTestsPassed = true;
// Test 1: Check if main binary exists and is executable
console.log(chalk.blue('1. Testing CLI executable...'));
try {
const result = execSync('repo-analyze --version', { encoding: 'utf8' });
console.log(chalk.green(`โ
CLI working: ${result.trim()}`));
} catch (error) {
console.log(chalk.red('โ CLI not working'));
console.log(chalk.gray(` Error: ${error.message}`));
allTestsPassed = false;
}
// Test 2: Check core agents
console.log(chalk.blue('\n2. Testing agent discovery...'));
try {
const result = execSync('repo-analyze --list-agents', { encoding: 'utf8' });
if (result.includes('CORE AGENTS')) {
console.log(chalk.green('โ
Core agents found'));
} else {
console.log(chalk.yellow('โ ๏ธ Core agents may not be loaded properly'));
allTestsPassed = false;
}
} catch (error) {
console.log(chalk.red('โ Agent discovery failed'));
console.log(chalk.gray(` Error: ${error.message}`));
allTestsPassed = false;
}
// Test 3: Validate setup
console.log(chalk.blue('\n3. Testing system validation...'));
try {
const result = execSync('repo-analyze --validate', { encoding: 'utf8', stdio: 'pipe' });
if (result.includes('Setup validation passed')) {
console.log(chalk.green('โ
System validation passed'));
} else {
console.log(chalk.yellow('โ ๏ธ System validation has warnings'));
console.log(chalk.gray(' This may be normal if Claude CLI is not installed'));
}
} catch (error) {
console.log(chalk.yellow('โ ๏ธ System validation failed'));
console.log(chalk.gray(' This is expected if Claude CLI is not installed'));
}
// Test 4: Check package structure
console.log(chalk.blue('\n4. Testing package structure...'));
try {
const packageRoot = findPackageRoot();
const requiredPaths = [
'bin/repo-analyze.js',
'agents',
'dist',
'package.json'
];
let structureOK = true;
for (const requiredPath of requiredPaths) {
const fullPath = path.join(packageRoot, requiredPath);
if (await fs.pathExists(fullPath)) {
console.log(chalk.green(` โ
${requiredPath}`));
} else {
console.log(chalk.red(` โ ${requiredPath} missing`));
structureOK = false;
allTestsPassed = false;
}
}
if (structureOK) {
console.log(chalk.green('โ
Package structure is complete'));
}
} catch (error) {
console.log(chalk.red('โ Package structure test failed'));
console.log(chalk.gray(` Error: ${error.message}`));
allTestsPassed = false;
}
// Test 5: Test with sample data (dry run)
console.log(chalk.blue('\n5. Testing analysis preview...'));
try {
const tempDir = await fs.mkdtemp(path.join(require('os').tmpdir(), 'repo-test-'));
// Create a minimal test repository
await fs.writeFile(path.join(tempDir, 'package.json'), JSON.stringify({
name: 'test-repo',
version: '1.0.0',
description: 'Test repository for validation'
}, null, 2));
await fs.writeFile(path.join(tempDir, 'README.md'), '# Test Repository\n\nThis is a test repository for validation.');
const result = execSync(`repo-analyze "${tempDir}" --preview`, { encoding: 'utf8' });
if (result.includes('Analysis Preview')) {
console.log(chalk.green('โ
Analysis preview working'));
} else {
console.log(chalk.yellow('โ ๏ธ Analysis preview has issues'));
allTestsPassed = false;
}
// Cleanup
await fs.remove(tempDir);
} catch (error) {
console.log(chalk.red('โ Analysis preview test failed'));
console.log(chalk.gray(` Error: ${error.message}`));
allTestsPassed = false;
}
// Summary
console.log(chalk.blue('\n' + '='.repeat(50)));
if (allTestsPassed) {
console.log(chalk.green('๐ All installation tests passed!'));
console.log(chalk.blue('\nRepository Analyzer is ready to use:'));
console.log(chalk.gray(' repo-analyze /path/to/your/repository'));
process.exit(0);
} else {
console.log(chalk.red('๐ฅ Some installation tests failed'));
console.log(chalk.yellow('\nTroubleshooting:'));
console.log(chalk.gray(' 1. Try reinstalling: npm uninstall -g @repo-agents/analyzer && npm install -g @repo-agents/analyzer'));
console.log(chalk.gray(' 2. Check Node.js version: node --version (requires 16+)'));
console.log(chalk.gray(' 3. Install Claude CLI: https://claude.ai/code'));
console.log(chalk.gray(' 4. Check permissions: ensure you can write to current directory'));
console.log(chalk.gray(' 5. Report issues: https://github.com/repo-agents/analyzer/issues'));
process.exit(1);
}
}
function findPackageRoot() {
let currentDir = __dirname;
while (currentDir !== path.dirname(currentDir)) {
if (fs.existsSync(path.join(currentDir, 'package.json'))) {
return currentDir;
}
currentDir = path.dirname(currentDir);
}
throw new Error('Could not find package root');
}
// Only run test if called directly
if (require.main === module) {
testInstallation().catch(error => {
console.error(chalk.red('Test error:'), error.message);
process.exit(1);
});
}
module.exports = testInstallation;