--- import DocsLayout from '../../../layouts/DocsLayout.astro'; ---

测试集成 (Test Integration)

在代码修改后自动运行测试,并在测试失败时将错误信息反馈给 AI 进行修复,形成"编辑-测试-修复"的闭环。

工作流程

  1. AI 编辑代码
  2. 运行相关测试
  3. 如果测试失败,解析错误信息
  4. 将错误反馈给 AI
  5. AI 修复代码
  6. 重复直到测试通过或达到限制

设计方案

类型定义

export interface TestResult {
  success: boolean;
  passed: number;
  failed: number;
  skipped: number;
  duration: number;
  failures: TestFailure[];
  output: string;
}

export interface TestFailure {
  testName: string;
  file?: string;
  line?: number;
  message: string;
  stack?: string;
  expected?: string;
  actual?: string;
}

默认测试配置

export const DEFAULT_TEST_CONFIGS = {
  jest: {
    command: 'npx',
    args: ['jest', '--json', '--testLocationInResults'],
    testFilePatterns: ['**/*.test.ts', '**/*.spec.ts'],
  },
  vitest: {
    command: 'npx',
    args: ['vitest', 'run', '--reporter=json'],
    testFilePatterns: ['**/*.test.ts', '**/*.spec.ts'],
  },
  pytest: {
    command: 'python',
    args: ['-m', 'pytest', '--tb=short', '-v'],
    testFilePatterns: ['**/test_*.py', '**/*_test.py'],
  },
};

配置示例

# .ai-assistant.yml
testing:
  enabled: true
  runner: vitest
  autoRun: true
  autoFix: true
  maxFixAttempts: 3
  timeout: 60000
  runRelatedOnly: true

实现状态

优先级: 高 | 状态: 待实现