Hamburger Cross Icon
Coverage Guardrails - Lunar Policy for Testing And Quality

Coverage Guardrails

Policy Stable Testing And Quality

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.

Add 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.

Guardrail

collected

Verifies that code coverage data is being collected. Catches misconfigurations where coverage tools are not running or uploading.

code coverage ci coverage test coverage
View Guardrail
Guardrail

reported

Ensures that a coverage percentage is available and reported. Fails if coverage runs but the percentage metric is not captured.

coverage percentage coverage reporting
View Guardrail
Guardrail

min-coverage

Enforces a minimum code coverage threshold (default 80%). Fails when coverage percentage is below the configured minimum.

coverage threshold minimum coverage quality gates
View Guardrail

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
1
Integrations Gather Data
Collectors extract metadata from code, CI pipelines, tool outputs, and scans
2
{ } Centralized as JSON
All data merged into each component's unified metadata document
3
Guardrails Enforce Standards This Policy
Real-time feedback in PRs and AI workflows

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 GitHub

Coverage 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:

  1. collected failure: Configure a coverage collector to run in your CI pipeline
  2. reported failure: Ensure your coverage tool successfully uploads/reports coverage data
  3. min-coverage failure: Add more tests to increase code coverage, or adjust the min_coverage input 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.

View Repository

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.

Works with any process
check Infrastructure conventions
check Post-mortem action items
check Security & compliance policies
check Testing & quality requirements
Book a Demo
See it work with your own use cases
See How It Works