configure-coverage

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

/configure:coverage

/configure:coverage

Check and configure code coverage thresholds and reporting for test frameworks.
为测试框架检查并配置代码覆盖率阈值与报告。

When to Use This Skill

适用场景

Use this skill when...Use another approach when...
Setting up coverage thresholds for Vitest, Jest, pytest, or RustRunning tests with coverage (
/test:coverage
)
Configuring coverage reporters (text, JSON, HTML, lcov)Configuring the test framework itself (
/configure:tests
)
Adding Codecov or Coveralls integration to CI/CDAnalyzing test failures (test-runner agent)
Auditing coverage configuration compliance across a projectWriting individual test cases
Adjusting coverage threshold percentagesConfiguring general CI/CD workflows (
/configure:workflows
)
适用此技能的场景...适用其他方法的场景...
为Vitest、Jest、pytest或Rust设置覆盖率阈值运行带覆盖率的测试(
/test:coverage
配置覆盖率报告器(text、JSON、HTML、lcov)配置测试框架本身(
/configure:tests
在CI/CD中添加Codecov或Coveralls集成分析测试失败(test-runner agent)
审计项目中覆盖率配置的合规性编写单个测试用例
调整覆盖率阈值百分比配置通用CI/CD工作流(
/configure:workflows

Context

上下文信息

  • Project root: !
    pwd
  • Package files: !
    find . -maxdepth 1 \( -name 'package.json' -o -name 'pyproject.toml' -o -name 'Cargo.toml' \) 2>/dev/null
  • Vitest config: !
    find . -maxdepth 1 -name 'vitest.config.*' 2>/dev/null
  • Jest config: !
    find . -maxdepth 1 -name 'jest.config.*' 2>/dev/null
  • Coverage dir: !
    find . -maxdepth 1 -type d -name 'coverage' 2>/dev/null
  • Codecov config: !
    find . -maxdepth 1 \( -name 'codecov.yml' -o -name '.codecov.yml' \) 2>/dev/null
  • Project standards: !
    find . -maxdepth 1 -name '.project-standards.yaml' 2>/dev/null
  • 项目根目录: !
    pwd
  • 包文件: !
    find . -maxdepth 1 \( -name 'package.json' -o -name 'pyproject.toml' -o -name 'Cargo.toml' \) 2>/dev/null
  • Vitest配置: !
    find . -maxdepth 1 -name 'vitest.config.*' 2>/dev/null
  • Jest配置: !
    find . -maxdepth 1 -name 'jest.config.*' 2>/dev/null
  • 覆盖率目录: !
    find . -maxdepth 1 -type d -name 'coverage' 2>/dev/null
  • Codecov配置: !
    find . -maxdepth 1 \( -name 'codecov.yml' -o -name '.codecov.yml' \) 2>/dev/null
  • 项目标准: !
    find . -maxdepth 1 -name '.project-standards.yaml' 2>/dev/null

Parameters

参数

Parse from command arguments:
  • --check-only
    : Report compliance status without modifications (CI/CD mode)
  • --fix
    : Apply fixes automatically without prompting
  • --threshold <percentage>
    : Set coverage threshold (default: 80)
Default threshold: 80% (lines, branches, functions, statements)
Supported frameworks:
  • Vitest:
    @vitest/coverage-v8
    or
    @vitest/coverage-istanbul
  • Jest: Built-in coverage with
    --coverage
  • pytest:
    pytest-cov
    plugin
  • Rust:
    cargo-llvm-cov
    or
    cargo-tarpaulin
从命令参数中解析:
  • --check-only
    : 仅报告合规状态,不进行修改(CI/CD模式)
  • --fix
    : 自动应用修复,无需提示
  • --threshold <percentage>
    : 设置覆盖率阈值(默认值:80)
默认阈值: 80%(行、分支、函数、语句)
支持的框架:
  • Vitest:
    @vitest/coverage-v8
    @vitest/coverage-istanbul
  • Jest: 内置覆盖率功能,使用
    --coverage
  • pytest:
    pytest-cov
    插件
  • Rust:
    cargo-llvm-cov
    cargo-tarpaulin

Execution

执行流程

Execute this code coverage compliance check:
执行以下代码覆盖率合规性检查:

Step 1: Detect test framework and coverage configuration

步骤1:检测测试框架与覆盖率配置

Check for framework indicators:
IndicatorFrameworkCoverage Tool
vitest.config.*
with coverage
Vitest@vitest/coverage-v8
jest.config.*
with coverage
JestBuilt-in
pyproject.toml
[tool.coverage]
pytestpytest-cov
.cargo/config.toml
with coverage
Rustcargo-llvm-cov
Use WebSearch or WebFetch to verify latest versions of coverage tools before configuring.
检查框架标识:
标识框架覆盖率工具
带覆盖率配置的
vitest.config.*
Vitest@vitest/coverage-v8
带覆盖率配置的
jest.config.*
Jest内置工具
pyproject.toml
中的[tool.coverage]
pytestpytest-cov
.cargo/config.toml
中的覆盖率配置
Rustcargo-llvm-cov
在配置前,使用WebSearch或WebFetch验证覆盖率工具的最新版本。

Step 2: Analyze current coverage state

步骤2:分析当前覆盖率状态

For the detected framework, check configuration completeness:
Vitest:
  • Coverage provider configured (
    v8
    or
    istanbul
    )
  • Coverage reporters configured (
    text
    ,
    json
    ,
    html
    ,
    lcov
    )
  • Thresholds set for lines, functions, branches, statements
  • Exclusions configured (node_modules, dist, tests, config files)
  • Output directory specified
Jest:
  • collectCoverage
    enabled
  • coverageProvider
    set (
    v8
    or
    babel
    )
  • collectCoverageFrom
    patterns configured
  • coverageThresholds
    configured
  • coverageReporters
    configured
pytest:
  • pytest-cov
    installed
  • [tool.coverage.run]
    section exists
  • [tool.coverage.report]
    section exists
  • Coverage threshold configured (
    --cov-fail-under
    )
Rust (cargo-llvm-cov):
  • cargo-llvm-cov
    installed
  • Coverage configuration in workspace
  • HTML/LCOV output configured
针对检测到的框架,检查配置完整性:
Vitest:
  • 已配置覆盖率提供方(
    v8
    istanbul
  • 已配置覆盖率报告器(
    text
    json
    html
    lcov
  • 已设置行、函数、分支、语句的阈值
  • 已配置排除项(node_modules、dist、tests、配置文件)
  • 已指定输出目录
Jest:
  • 已启用
    collectCoverage
  • 已设置
    coverageProvider
    v8
    babel
  • 已配置
    collectCoverageFrom
    模式
  • 已配置
    coverageThresholds
  • 已配置
    coverageReporters
pytest:
  • 已安装
    pytest-cov
  • 存在
    [tool.coverage.run]
    章节
  • 存在
    [tool.coverage.report]
    章节
  • 已配置覆盖率阈值(
    --cov-fail-under
Rust (cargo-llvm-cov):
  • 已安装
    cargo-llvm-cov
  • 工作区中存在覆盖率配置
  • 已配置HTML/LCOV输出

Step 3: Generate compliance report

步骤3:生成合规性报告

Print a formatted compliance report:
Code Coverage Compliance Report
================================
Project: [name]
Framework: [Vitest 2.x | pytest 8.x | cargo-llvm-cov 0.6.x]

Coverage Configuration:
  Provider                @vitest/coverage-v8        [CONFIGURED | MISSING]
  Reporters               text, json, html, lcov     [ALL | PARTIAL]
  Output directory        coverage/                  [CONFIGURED | DEFAULT]
  Exclusions              node_modules, dist, tests  [CONFIGURED | INCOMPLETE]

Thresholds:
  Lines                   80%                        [PASS | LOW | NOT SET]
  Branches                80%                        [PASS | LOW | NOT SET]
  Functions               80%                        [PASS | LOW | NOT SET]
  Statements              80%                        [PASS | LOW | NOT SET]

CI/CD Integration:
  Coverage upload         codecov/coveralls          [CONFIGURED | MISSING]
  Artifact upload         coverage reports           [CONFIGURED | MISSING]

Overall: [X issues found]
If
--check-only
, stop here.
打印格式化的合规性报告:
代码覆盖率合规性报告
================================
项目: [名称]
框架: [Vitest 2.x | pytest 8.x | cargo-llvm-cov 0.6.x]

覆盖率配置:
  提供方                @vitest/coverage-v8        [已配置 | 缺失]
  报告器               text、json、html、lcov     [全部配置 | 部分配置]
  输出目录              coverage/                  [已配置 | 默认]
  排除项              node_modules、dist、tests  [已配置 | 不完整]

阈值:
  行覆盖率               80%                        [通过 | 不达标 | 未设置]
  分支覆盖率                80%                        [通过 | 不达标 | 未设置]
  函数覆盖率               80%                        [通过 | 不达标 | 未设置]
  语句覆盖率              80%                        [通过 | 不达标 | 未设置]

CI/CD集成:
  覆盖率上传         codecov/coveralls          [已配置 | 缺失]
  制品上传         覆盖率报告           [已配置 | 缺失]

总体状态: [发现X个问题]
如果使用
--check-only
,在此步骤停止。

Step 4: Configure coverage (if --fix or user confirms)

步骤4:配置覆盖率(如果使用--fix或用户确认)

Apply coverage configuration based on detected framework. Use templates from REFERENCE.md:
  1. Install coverage provider (e.g.,
    @vitest/coverage-v8
    ,
    pytest-cov
    )
  2. Update config file with thresholds, reporters, exclusions
  3. Add scripts to package.json or pyproject.toml
  4. Configure CI/CD with Codecov upload and artifact storage
根据检测到的框架应用覆盖率配置。使用REFERENCE.md中的模板:
  1. 安装覆盖率提供方(例如:
    @vitest/coverage-v8
    pytest-cov
  2. 更新配置文件,添加阈值、报告器、排除项
  3. 添加脚本到package.json或pyproject.toml
  4. 配置CI/CD,添加Codecov上传与制品存储

Step 5: Update standards tracking

步骤5:更新标准跟踪

Update
.project-standards.yaml
:
yaml
standards_version: "2025.1"
last_configured: "[timestamp]"
components:
  coverage: "2025.1"
  coverage_threshold: 80
  coverage_provider: "[v8|istanbul|pytest-cov|llvm-cov]"
  coverage_reporters: ["text", "json", "html", "lcov"]
  coverage_ci: "codecov"
更新
.project-standards.yaml
yaml
standards_version: "2025.1"
last_configured: "[时间戳]"
components:
  coverage: "2025.1"
  coverage_threshold: 80
  coverage_provider: "[v8|istanbul|pytest-cov|llvm-cov]"
  coverage_reporters: ["text", "json", "html", "lcov"]
  coverage_ci: "codecov"

Step 6: Print final report

步骤6:打印最终报告

Print a summary of changes applied, scripts added, and next steps for verifying coverage.
For detailed configuration templates, see REFERENCE.md.
打印已应用的更改、添加的脚本,以及验证覆盖率的后续步骤。
有关详细配置模板,请参阅REFERENCE.md

Agentic Optimizations

智能优化命令

ContextCommand
Quick compliance check
/configure:coverage --check-only
Auto-fix all issues
/configure:coverage --fix
Custom threshold
/configure:coverage --fix --threshold 90
Check coverage config exists
find . -maxdepth 1 -name 'vitest.config.*' -o -name 'jest.config.*' 2>/dev/null
Verify coverage directory
test -d coverage && echo "EXISTS"
场景命令
快速合规性检查
/configure:coverage --check-only
自动修复所有问题
/configure:coverage --fix
自定义阈值
/configure:coverage --fix --threshold 90
检查覆盖率配置是否存在
find . -maxdepth 1 -name 'vitest.config.*' -o -name 'jest.config.*' 2>/dev/null
验证覆盖率目录
test -d coverage && echo "EXISTS"

Flags

标志参数

FlagDescription
--check-only
Report status without offering fixes
--fix
Apply all fixes automatically without prompting
--threshold <percentage>
Set coverage threshold (default: 80)
标志描述
--check-only
仅报告状态,不提供修复
--fix
自动应用所有修复,无需提示
--threshold <percentage>
设置覆盖率阈值(默认值:80)

Examples

使用示例

bash
undefined
bash
undefined

Check compliance and offer fixes

检查合规性并提供修复选项

/configure:coverage
/configure:coverage

Check only, no modifications

仅检查,不修改

/configure:coverage --check-only
/configure:coverage --check-only

Auto-fix with custom threshold

自动修复并使用自定义阈值

/configure:coverage --fix --threshold 90
undefined
/configure:coverage --fix --threshold 90
undefined

Error Handling

错误处理

  • No test framework detected: Suggest running
    /configure:tests
    first
  • Coverage provider missing: Offer to install
  • Invalid threshold: Reject values <0 or >100
  • CI token missing: Warn about Codecov/Coveralls setup
  • 未检测到测试框架: 建议先运行
    /configure:tests
  • 缺失覆盖率提供方: 提供安装选项
  • 无效阈值: 拒绝<0或>100的值
  • 缺失CI令牌: 警告Codecov/Coveralls设置

See Also

相关链接