Policies
Policies define the minimum coverage requirements for your project. coverctl supports domain-level and file-level policies.
Policy Structure
Section titled “Policy Structure”policy: default: min: 75 domains: - name: core match: ["./internal/core/..."] min: 85Default Policy
Section titled “Default Policy”The default policy applies to any code not matched by a specific domain:
policy: default: min: 75If a file doesn’t match any domain, it must meet the default minimum.
Domain Policies
Section titled “Domain Policies”Each domain can have its own coverage requirement:
policy: domains: - name: core match: ["./internal/core/..."] min: 85 - name: api match: ["./internal/api/..."] min: 80 - name: utils match: ["./pkg/utils/..."] min: 60Policy Evaluation
Section titled “Policy Evaluation”- Files are matched to domains based on
matchpatterns - Coverage is calculated per domain
- Each domain is compared against its
minthreshold - If any domain fails, the overall check fails
File-Level Policies
Section titled “File-Level Policies”For granular control, define per-file rules:
files: - match: ["internal/core/critical/*.go"] min: 95 - match: ["internal/api/handlers/*.go"] min: 85File rules take precedence over domain rules.
Use Cases
Section titled “Use Cases”- Critical paths: Require 95%+ coverage for payment processing
- Legacy code: Allow lower thresholds during migration
- Generated code: Exclude entirely or require 0%
CLI Policy Enforcement
Section titled “CLI Policy Enforcement”fail-under
Section titled “fail-under”Fail if overall coverage is below a threshold:
coverctl check --fail-under 80This is additive to config policies—both must pass.
ratchet
Section titled “ratchet”Prevent coverage regression:
coverctl check --ratchetFails if current coverage is lower than the last recorded value.
Combined
Section titled “Combined”# Must be above 80% AND not decreasecoverctl check --fail-under 80 --ratchetThreshold Guidelines
Section titled “Threshold Guidelines”| Code Type | Suggested Threshold |
|---|---|
| Core business logic | 85-95% |
| API handlers | 80-90% |
| Utilities/helpers | 70-80% |
| CLI/presentation | 60-75% |
| Generated code | Excluded |
Suggested Thresholds
Section titled “Suggested Thresholds”Use coverctl suggest to get recommendations:
# Based on current coveragecoverctl suggest
# Push for higher thresholdscoverctl suggest --strategy aggressive
# More relaxed thresholdscoverctl suggest --strategy conservativeOutput
Section titled “Output”Suggested Thresholds────────────────────Domain Current Suggested Reasoncore 87.3% 85% Buffer for varianceapi 81.2% 80% Slightly below currentcli 76.4% 75% Slightly below currentBest Practices
Section titled “Best Practices”- Start conservative: Begin with achievable thresholds
- Ratchet up: Use
--ratchetto prevent regression, then increase thresholds - Review debt: Use
coverctl debtto find improvement opportunities - Exclude wisely: Don’t exclude code just to pass; write tests instead
- CI enforcement: Use
--fail-underand--ratchetin CI pipelines
Example: Gradual Improvement
Section titled “Example: Gradual Improvement”# Week 1: Start with current coverage - 5%policy: default: min: 70 domains: - name: core match: ["./internal/core/..."] min: 80
# Week 4: Increase after adding testspolicy: default: min: 75 domains: - name: core match: ["./internal/core/..."] min: 85See Also
Section titled “See Also”- Domains - Domain configuration
- CI Integration - Enforce policies in CI