test-coverage-improver

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Test Coverage Improver

测试覆盖率提升方案

Overview

概述

Use this skill whenever coverage needs assessment or improvement (coverage regressions, failing thresholds, or user requests for stronger tests). It runs the coverage suite, analyzes results, highlights the biggest gaps, and prepares test additions while confirming with the user before changing code.
每当需要评估或提升测试覆盖率时(如覆盖率倒退、阈值不达标,或用户要求增强测试),均可使用本方案。它会运行覆盖率测试套件、分析结果、突出最大的覆盖率缺口,并在修改代码前与用户确认,准备好待添加的测试用例。

Quick Start

快速入门

  1. From the repo root run
    make coverage
    to regenerate
    .coverage
    data and
    coverage.xml
    .
  2. Collect artifacts:
    .coverage
    and
    coverage.xml
    , plus the console output from
    coverage report -m
    for drill-downs.
  3. Summarize coverage: total percentages, lowest files, and uncovered lines/paths.
  4. Draft test ideas per file: scenario, behavior under test, expected outcome, and likely coverage gain.
  5. Ask the user for approval to implement the proposed tests; pause until they agree.
  6. After approval, write the tests in
    tests/
    , rerun
    make coverage
    , and then run
    $code-change-verification
    before marking work complete.
  1. 从仓库根目录运行
    make coverage
    ,重新生成
    .coverage
    数据和
    coverage.xml
    文件。
  2. 收集产物:
    .coverage
    coverage.xml
    ,以及
    coverage report -m
    的控制台输出,用于深入分析。
  3. 汇总覆盖率信息:总覆盖率百分比、覆盖率最低的文件,以及未覆盖的代码行/路径。
  4. 为每个文件草拟测试思路:测试场景、被测行为、预期结果,以及可能提升的覆盖率。
  5. 征求用户同意以实施拟议的测试用例;等待用户确认后再继续。
  6. 获得批准后,在
    tests/
    目录下编写测试,重新运行
    make coverage
    ,然后执行
    $code-change-verification
    ,之后再标记工作完成。

Workflow Details

工作流程详情

  • Run coverage: Execute
    make coverage
    at repo root. Avoid watch flags and keep prior coverage artifacts only if comparing trends.
  • Parse summaries efficiently:
    • Prefer the console output from
      coverage report -m
      for file-level totals; fallback to
      coverage.xml
      for tooling or spreadsheets.
    • Use
      uv run coverage html
      to generate
      htmlcov/index.html
      if you need an interactive drill-down.
  • Prioritize targets:
    • Public APIs or shared utilities in
      src/agents/
      before examples or docs.
    • Files with low statement coverage or newly added code at 0%.
    • Recent bug fixes or risky code paths (error handling, retries, timeouts, concurrency).
  • Design impactful tests:
    • Hit uncovered paths: error cases, boundary inputs, optional flags, and cancellation/timeouts.
    • Cover combinational logic rather than trivial happy paths.
    • Place tests under
      tests/
      and avoid flaky async timing.
  • Coordinate with the user: Present a numbered, concise list of proposed test additions and expected coverage gains. Ask explicitly before editing code or fixtures.
  • After implementation: Rerun coverage, report the updated summary, and note any remaining low-coverage areas.
  • 运行覆盖率测试:在仓库根目录执行
    make coverage
    。不要使用监听标志,仅在对比趋势时保留之前的覆盖率产物。
  • 高效解析汇总信息
    • 优先使用
      coverage report -m
      的控制台输出获取文件级别的覆盖率总计;若需用于工具或电子表格,可退而使用
      coverage.xml
    • 如果需要交互式深入分析,使用
      uv run coverage html
      生成
      htmlcov/index.html
  • 优先处理目标
    • 先处理
      src/agents/
      中的公共API或共享工具,再处理示例或文档。
    • 优先处理语句覆盖率低或新增代码覆盖率为0%的文件。
    • 优先处理近期修复的bug或高风险代码路径(错误处理、重试、超时、并发)。
  • 设计高影响力的测试用例
    • 覆盖未涉及的路径:错误场景、边界输入、可选标志,以及取消/超时情况。
    • 覆盖组合逻辑而非简单的正常流程。
    • 将测试用例放在
      tests/
      目录下,避免不稳定的异步计时问题。
  • 与用户协作:以编号列表的形式简洁呈现拟议的测试添加项及预期覆盖率提升,在编辑代码或测试夹具前明确征求用户同意。
  • 实施后步骤:重新运行覆盖率测试,报告更新后的汇总信息,并记录任何剩余的低覆盖率区域。

Notes

注意事项

  • Keep any added comments or code in English.
  • Do not create
    scripts/
    ,
    references/
    , or
    assets/
    unless needed later.
  • If coverage artifacts are missing or stale, rerun
    pnpm test:coverage
    instead of guessing.
  • 所有添加的注释或代码请使用英文。
  • 除非后续需要,否则不要创建
    scripts/
    references/
    assets/
    目录。
  • 如果覆盖率产物缺失或过期,请重新运行
    pnpm test:coverage
    ,而非猜测。