Coverage Guardrails
Validate that code coverage data is collected in CI and meets minimum thresholds. Works with any coverage collector that writes to standard testing.coverage paths.
coverage to your lunar-config.yml:uses: github://earthly/lunar-lib/policies/coverage@v1.0.0
Included Guardrails
This policy includes 3 guardrails that enforce standards for your testing and quality.
collected
Verifies that code coverage data is being collected. Catches misconfigurations where coverage tools are not running or uploading.
reported
Ensures that a coverage percentage is available and reported. Fails if coverage runs but the percentage metric is not captured.
min-coverage
Enforces a minimum code coverage threshold (default 80%). Fails when coverage percentage is below the configured minimum.
How Guardrails Fit into Lunar
Lunar guardrails define your engineering standards as code. They evaluate data collected by integrations and produce pass/fail checks with actionable feedback.
Policies support gradual enforcement—from silent scoring to blocking PRs or deployments—letting you roll out standards at your own pace without disrupting existing workflows.
Learn How Lunar Works →Required Integrations
This policy evaluates data gathered by one or more of the following integration(s).
Make sure to enable them in your lunar-config.yml.
Configuration
Configure this policy in your lunar-config.yml.
Inputs
| Input | Required | Default | Description |
|---|---|---|---|
min_coverage
|
Optional |
80
|
Minimum required coverage percentage |
Documentation
View on GitHubCoverage Guardrails
Validates code coverage collection and thresholds.
Overview
This policy enforces that code coverage data is collected in CI and meets a minimum threshold. It is vendor-agnostic and works with any coverage collector that writes to the standard .testing.coverage paths (e.g., Codecov, Coveralls, or custom collectors).
Policies
This plugin provides the following policies (use include to select a subset):
| Policy | Description | Failure Meaning |
|---|---|---|
collected |
Coverage data should be collected in CI | No coverage data found |
reported |
Coverage percentage should be reported | Coverage percentage not available |
min-coverage |
Coverage should meet minimum threshold | Coverage is below required percentage |
Required Data
This policy reads from the following Component JSON paths:
| Path | Type | Provided By |
|---|---|---|
.testing.coverage |
object | Any coverage collector (e.g., codecov) |
.testing.coverage.percentage |
number | Any coverage collector |
Note: Object presence is the signal—the collected policy uses assert_exists(".testing.coverage") and the reported policy uses assert_exists(".testing.coverage.percentage").
Installation
Add to your lunar-config.yml:
policies:
- uses: github://earthly/lunar-lib/policies/coverage@main
on: [backend]
enforcement: block-pr
# include: [collected] # Only run specific checks (omit to run all)
# with:
# min_coverage: "90"
Examples
Passing Example
{
"testing": {
"coverage": {
"source": {
"tool": "codecov",
"integration": "ci"
},
"percentage": 85.5
}
}
}
Failing Example
{
"testing": {
"coverage": {
"source": {
"tool": "codecov",
"integration": "ci"
},
"percentage": 72.0
}
}
}
Failure message: "Coverage 72.0% is below minimum 80%"
Remediation
When this policy fails, you can resolve it by:
collectedfailure: Configure a coverage collector to run in your CI pipelinereportedfailure: Ensure your coverage tool successfully uploads/reports coverage datamin-coveragefailure: Add more tests to increase code coverage, or adjust themin_coverageinput if the threshold is too aggressive
Open Source
This policy is open source and available on GitHub. Contribute improvements, report issues, or fork it for your own use.
Common Use Cases
Explore how individual guardrails work with specific integrations.
Ready to Automate Your Standards?
See how Lunar can turn your engineering wiki, compliance docs, or postmortem action items into automated guardrails with our 100+ built-in guardrails.