返回提示词目录第 1183 页

配置持续集成增量覆盖率门禁

为代码变更设置测试覆盖率门槛与整体降幅限制,输出配置修改、排除项及验证结果。

完整提示词

<context>
A global coverage threshold either blocks nobody (set below the current number) or blocks the unlucky person who touches a poorly covered legacy file, and it invites tests written to execute lines rather than check behaviour. Gating on the coverage of changed lines in each pull request (diff or patch coverage) asks the right question: is the new code tested? Pair it with a rule that overall coverage must not drop by more than a small tolerance. Exclusions decide whether the number means anything: generated code, migrations, type-only files, vendored code and test files themselves should be excluded, but excluding hard-to-test business logic to raise the number defeats the gate. Branch coverage reveals untested conditions that line coverage hides. Coverage still does not prove assertions exist; mutation testing does that.
</context>

<task>
Set up a coverage gate for:
{{project}}
{{#target}}
Changed-lines target: {{target}}
{{/target}}

1. Read the test configuration, CI pipeline and any existing coverage config or service integration. Run the test suite with coverage to get the current line and branch numbers; report them.
2. Configure the coverage tool for the stack: enable branch coverage where supported, set the source roots, and write a machine-readable report (LCOV, Cobertura XML or the tool's JSON) for CI.
3. Define exclusions with a one-line reason each: generated code, migrations, vendored code, test files, type-only or interface-only files, entry-point bootstrapping. Do not exclude business logic.
4. Add the diff coverage gate in CI: compute coverage on lines changed relative to the target branch using the project's existing coverage service if there is one, or a diff-coverage tool for the stack otherwise. Set the target (default 80% of changed lines if none given) and make the check fail the pipeline with a message pointing to the uncovered lines.
5. Add the no-drop rule: overall coverage may not fall more than a stated tolerance (for example 0.5 points) below the target branch, or below a floor set just under today's number.
6. Make sure the CI job fetches enough git history for the diff and handles pull requests from forks without leaking secrets (no token-based upload where secrets are unavailable, or use the service's tokenless mode).
7. Verify: run the check locally or in a test pull request against a branch with a deliberately uncovered change, and confirm it fails, then covered, and confirm it passes. Report anything you could not run.
</task>

<constraints>
- Do not set a global threshold above today's coverage that would block all work.
- Do not add exclusions to raise the number.
- No coverage service tokens in the repository; reference CI secrets by name.
- Keep the CI change limited to coverage; do not restructure unrelated jobs.
{{> guardrails/verify-before-done}}
</constraints>

<output_format>
## Current coverage
Line and branch numbers measured, with the command.

## Configuration
Diff of the coverage tool config.

## CI gate
Diff of the CI change, the diff-coverage target and the no-drop rule.

## Exclusions
Table: path or pattern | reason.

## Verification
How the gate was shown to fail and pass, or what remains to check.
</output_format>

可替换内容

  • {{project}}
  • {{#target}}
  • {{target}}
  • {{/target}}
  • {{> guardrails/verify-before-done}}

分类与标签

编程开发、持续集成、增量覆盖率、自动化测试、代码质量

前往 AI 图片创作