SuperAPI AI 工具集

qe-defect-intelligence

测试与质量

查看项目

更新于 10-16 10:52

技能介绍

用途

QE Defect Intelligence 用于指导使用 v3 的缺陷智能能力,包括基于机器学习的缺陷预测、基于历史数据的模式识别,以及自动化根因分析。它面向在缺陷逃逸前预测易产生缺陷的代码这一目标。

激活时机

该技能在以下情况被激活:预测易产生缺陷的代码时;分析失败模式时;执行根因分析时;从过往缺陷中学习时;基于风险对测试进行优先级排序时。

使用方式

该技能提供命令行(aqe defect)与 Agent 工作流两种使用方式。

快速开始命令示例:

  • 预测变更代码中的缺陷:aqe defect predict --changes HEAD~5..HEAD
  • 分析失败模式:aqe defect patterns --period 90d --min-occurrences 3
  • 根因分析:aqe defect rca --failure "test/auth.test.ts:45"
  • 从已解决的缺陷中学习:aqe defect learn --source jira --status resolved

Agent 工作流(TypeScript 示例)包括缺陷预测与根因分析两类任务:

// Defect prediction
Task("Predict defect-prone code", `
  Analyze PR #456 changes and predict defect likelihood:
  - Historical defect correlation
  - Code complexity factors
  - Author experience with module
  - Test coverage gaps
  Flag high-risk changes requiring extra review.
`, "qe-defect-predictor")

// Root cause analysis
Task("Analyze test failure", `
  Investigate recurring failure in AuthService tests:
  - Collect failure history (last 30 days)
  - Identify common patterns
  - Trace to potential root causes
  - Suggest fixes using 5-whys analysis
`, "qe-root-cause-analyzer")

主要能力

预测模型

  1. 基于变更的预测:可配置各因素的权重(代码变更量 codeChurn 0.2、复杂度 complexity 0.25、作者经验 authorExperience 0.15、文件历史 fileHistory 0.2、测试覆盖率 testCoverage 0.2),并可设置 high/medium/low 阈值(分别为 0.7/0.4/0.2)。
await defectPredictor.predictFromChanges({
  changes: prChanges,
  factors: {
    codeChurn: { weight: 0.2 },
    complexity: { weight: 0.25 },
    authorExperience: { weight: 0.15 },
    fileHistory: { weight: 0.2 },
    testCoverage: { weight: 0.2 }
  },
  threshold: {
    high: 0.7,
    medium: 0.4,
    low: 0.2
  }
});
  1. 模式学习:可从缺陷(jira)、提交(git)、测试(test-results)等来源学习模式,识别的模式类型包括 code-smell-to-defect、change-coupling、test-gap-correlation、complexity-defect-density,输出可包含规则、可视化和建议。
await patternLearner.learnPatterns({
  source: {
    defects: 'jira:project=MYAPP&type=bug',
    commits: 'git:last-6-months',
    tests: 'test-results:last-1000-runs'
  },
  patterns: [
    'code-smell-to-defect',
    'change-coupling',
    'test-gap-correlation',
    'complexity-defect-density'
  ],
  output: {
    rules: true,
    visualizations: true,
    recommendations: true
  }
});
  1. 根因分析:支持 five-whys、fishbone-diagram、fault-tree、change-impact 等方法,并可结合最近变更、环境差异、依赖变更、相似失败等上下文。
await rootCauseAnalyzer.analyze({
  failure: testFailure,
  methods: [
    'five-whys',
    'fishbone-diagram',
    'fault-tree',
    'change-impact'
  ],
  context: {
    recentChanges: true,
    environmentDiff: true,
    dependencyChanges: true,
    similarFailures: true
  }
});

缺陷预测报告结构

interface DefectPrediction {
  file: string;
  riskScore: number;  // 0-1
  riskLevel: 'critical' | 'high' | 'medium' | 'low';
  factors: {
    name: string;
    contribution: number;
    details: string;
  }[];
  historicalDefects: {
    count: number;
    recent: Defect[];
    patterns: string[];
  };
  recommendations: {
    action: string;
    priority: string;
    expectedRiskReduction: number;
  }[];
}

模式类别

该技能列出了常见缺陷模式及其检测与预防方式:

  • 空指针(Null pointer):检测方式为静态分析,预防方式为空值检查、Optional。
  • 竞态条件(Race condition):检测方式为并发分析,预防方式为锁、原子操作。
  • 内存泄漏(Memory leak):检测方式为堆分析,预防方式为资源清理。
  • 差一错误(Off-by-one):检测方式为边界分析,预防方式为循环不变式。
  • 注入(Injection):检测方式为污点分析,预防方式为输入校验。

根因分析模板

root_cause_analysis:
  five_whys:
    max_depth: 5
    prompt_template: "Why did {effect} happen?"

  fishbone:
    categories:
      - people
      - process
      - tools
      - environment
      - materials
      - measurement

  fault_tree:
    top_event: "Test Failure"
    gate_types: [AND, OR, NOT]
    basic_events: true

与问题跟踪系统集成

await defectIntelligence.syncWithTracker({
  source: 'jira',
  project: 'MYAPP',
  sync: {
    defectData: 'bidirectional',
    predictions: 'create-tasks',
    patterns: 'update-labels'
  },
  automation: {
    flagHighRisk: true,
    suggestAssignee: true,
    linkRelated: true
  }
});

协调关系

主要 Agent:qe-defect-predictor、qe-pattern-learner、qe-root-cause-analyzer。协调者:qe-defect-intelligence-coordinator。相关技能:qe-coverage-analysis、qe-quality-assessment。

适用场景

适用于变更代码的缺陷预测、失败模式分析、根因分析、历史缺陷学习,以及基于风险的测试优先级排序。

限制

资料未提供关于该技能的收费、价格、平台支持范围或效果保证等信息,暂未提供。