smoke-test.js 2.85 KB
/**
 * 进化引擎端到端冒烟测试
 *
 * 用法:
 *   node packages/evolution/smoke-test.js code-review
 *   node packages/evolution/smoke-test.js --phase2 <runId>
 */
const { RunController } = require('./run-controller');
const path = require('path');

const DEFAULT_SKILLS_DIR = path.join(require('os').homedir(), '.gemini/antigravity/skills');

async function main() {
  const args = process.argv.slice(2);
  const skillName = args.find(a => !a.startsWith('--')) || 'code-review';
  const isPhase2 = args.includes('--phase2');
  const generations = parseInt(args.find(a => a.startsWith('--gens='))?.split('=')[1]) || 1;

  const controller = new RunController({
    skillsDir: DEFAULT_SKILLS_DIR,
    populationSize: 3,   // 冒烟测试用小种群
    convergenceThreshold: 0.95,
  });

  console.log('╔════════════════════════════════════════╗');
  console.log('║   进化引擎 — 端到端冒烟测试           ║');
  console.log('╚════════════════════════════════════════╝\n');

  if (isPhase2) {
    if (!skillName || skillName.startsWith('--')) {
      console.error('Usage: node smoke-test.js --phase2 <runId> [--gens=1]');
      process.exit(1);
    }
    console.log(`🧪 Phase 2: 自然选择 [${skillName}] × ${generations} 代\n`);
    const result = await controller.runPhase2(skillName, generations);
    printResult('Phase 2', result);
  } else {
    console.log(`🧪 Phase 1: 初始化 [${skillName}]\n`);
    const result = await controller.runPhase1(skillName);
    printResult('Phase 1', result);

    if (result.success && result.runId) {
      console.log(`\n🧪 Phase 2: 自然选择 [${skillName}] × ${generations} 代\n`);
      const p2Result = await controller.runPhase2(result.runId, generations);
      printResult('Phase 2', p2Result);
    }
  }
}

function printResult(phase, result) {
  console.log('\n┌────────────────────────────────────────┐');
  console.log(`│ ${phase} 结果`);
  console.log('├────────────────────────────────────────┤');
  for (const [key, value] of Object.entries(result)) {
    if (key === 'generationLog') continue;
    const val = typeof value === 'object' ? JSON.stringify(value) : value;
    console.log(`│ ${key}: ${val}`);
  }
  console.log('└────────────────────────────────────────┘');
}

main()
  .then(() => {
    console.log('\n✅ 冒烟测试完成');
  })
  .catch(err => {
    console.error('\n💥 冒烟测试失败:', err.message);
    console.error(err.stack);
    process.exitCode = 1;
  });