CoverageRatchet 0.10.0-alpha.1
See the version list below for details.
dotnet tool install --global CoverageRatchet --version 0.10.0-alpha.1
dotnet new tool-manifest
dotnet tool install --local CoverageRatchet --version 0.10.0-alpha.1
#tool dotnet:?package=CoverageRatchet&version=0.10.0-alpha.1&prerelease
nuke :add-package CoverageRatchet --version 0.10.0-alpha.1
CoverageRatchet
Per-file code coverage enforcement that only goes up. CoverageRatchet reads your Cobertura XML coverage reports, compares each file against its threshold, and helps prevent coverage from regressing.
How It Works
- Your test suite generates a Cobertura XML coverage report (most .NET coverage tools support this format).
- CoverageRatchet reads the report and compares each file's line and branch coverage against its threshold.
checkfails the build if any file drops below its threshold.ratchet(the default command) updates thresholds to match current coverage -- thresholds only go up, not down.loosensets thresholds to whatever coverage is right now, socheckpasses immediately.
The default threshold for every file is 100% line and branch coverage. Files that can't easily reach 100% (like CLI entry points) can get per-file overrides with a documented reason.
Installation
dotnet tool install -g CoverageRatchet
Usage
Ratchet (default)
Just run coverageratchet with no arguments to ratchet thresholds upward:
coverageratchet
This recursively searches for a coverage.cobertura.xml file, compares each file against its threshold, and tightens thresholds where coverage has improved. Exit codes:
| Exit code | Meaning |
|---|---|
| 0 | All thresholds met, no config changes needed |
| 1 | Config was updated (some thresholds tightened) |
| 2 | Some files are below their threshold |
You can also run it explicitly as coverageratchet ratchet.
Check coverage (CI)
coverageratchet check
Exits with code 0 if all files meet their thresholds, 1 if any file is below.
Loosen thresholds
If you need check to pass right now (e.g., after a big refactor that dropped coverage), loosen sets every file's threshold to its current actual coverage:
coverageratchet loosen
This always exits 0. Files that were already at 100% don't get an override. New overrides get the reason "loosened automatically".
Export coverage as JSON (for CI)
coverageratchet check-json [config-path] [output-path]
Writes machine-readable coverage results. Exit code matches check (non-zero if any file fails). Used by CI workflows to upload coverage data as an artifact.
Sync thresholds from CI
coverageratchet loosen-from-ci [config-path]
Pushes current code, polls CI, and if coverage fails:
- Downloads the
coverage-thresholdsartifact - Merges CI platform thresholds into local config (splitting non-platform entries if needed)
- Commits, pushes, and re-polls CI
Requires gh CLI and jj (or git).
Custom config path
coverageratchet check path/to/my-config.json
coverageratchet ratchet path/to/my-config.json
coverageratchet loosen path/to/my-config.json
Configuration
CoverageRatchet uses a JSON config file (default: coverage-ratchet.json in the current directory).
Example coverage-ratchet.json
{
"overrides": {
"Program.fs": {
"line": 85.5,
"branch": 77.0,
"reason": "CLI entry point -- exit calls are not coverable"
},
"Api.fs": {
"line": 92.38,
"branch": 73.33,
"reason": "Reflection branches generated by compiler"
}
}
}
Config fields
| Field | Type | Description |
|---|---|---|
overrides |
object | Per-file threshold overrides, keyed by filename |
overrides.<file>.line |
number | Minimum line coverage percentage (0-100) |
overrides.<file>.branch |
number | Minimum branch coverage percentage (0-100) |
overrides.<file>.reason |
string | Why this file has a lower threshold |
Files not listed in overrides must have 100% line and branch coverage.
Example Output
Program.fs: line 87.2% >= 85.5% PASS | branch 80.0% >= 77.0% PASS
Sync.fs: line 100% >= 100% PASS | branch 100% >= 100% PASS
Api.fs: line 90.0% >= 92.38% FAIL | branch 75.0% >= 73.33% PASS
Typical CI Setup
- Run your tests with coverage enabled (e.g.,
dotnet test --collect:"XPlat Code Coverage") - Run
coverageratchet checkto enforce thresholds - Run
coverageratchetlocally after improving tests to lock in coverage gains
License
MIT
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
This package has no dependencies.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.12.0-alpha.2 | 38 | 4/15/2026 |
| 0.12.0-alpha.1 | 64 | 4/13/2026 |
| 0.11.0-alpha.1 | 61 | 4/13/2026 |
| 0.10.0-alpha.3 | 59 | 4/11/2026 |
| 0.10.0-alpha.1 | 65 | 4/8/2026 |
| 0.9.0-alpha.1 | 52 | 4/8/2026 |
| 0.8.0-alpha.4 | 56 | 4/8/2026 |
| 0.8.0-alpha.1 | 37 | 4/8/2026 |
| 0.4.0-alpha.1 | 46 | 4/8/2026 |
| 0.3.0-alpha.1 | 60 | 4/7/2026 |
| 0.2.0-alpha.1 | 72 | 4/7/2026 |
| 0.1.0-alpha.1 | 92 | 4/6/2026 |