Skip to content

feat(coverage-gate): add target-specific policies - #101

Open
martin-kolinek wants to merge 13 commits into
mainfrom
coverage-gate-issues
Open

feat(coverage-gate): add target-specific policies#101
martin-kolinek wants to merge 13 commits into
mainfrom
coverage-gate-issues

Conversation

@martin-kolinek

@martin-kolinek martin-kolinek commented Aug 25, 2026

Copy link
Copy Markdown
Collaborator

🤖

Summary

  • add Cargo-style target policy selectors to cargo-coverage-gate
  • support target-specific threshold overrides and no-coverable-lines assertions
  • keep every selected test binary instrumented so cross-package coverage is preserved
  • accept empty lcov input according to each package's effective policy
  • bump cargo-coverage-gate to 0.4.0

Motivation

Addresses the coverage policy gaps reported in:

expect-no-coverable-lines remains appropriate for facades and re-export crates: those packages stay instrumented, their tests can cover dependencies, and the gate asserts that the package itself owns no coverable lines. Platform-gated packages can apply that assertion only on unsupported targets while retaining a positive threshold on supported targets.

Thresholds control verdicts, not instrumentation. A target-specific zero threshold disables gating without removing the package's tests from the instrumented run. If cargo-llvm-cov reports that an instrumented run produced no coverage data, an orchestrator can pass an empty lcov tracefile and let the effective policies determine whether the result is valid.

Cargo Anvil adoption is intentionally deferred until 0.4.0 has been published to crates.io; otherwise its generated setup would pin an unavailable version.

Configuration

[package.metadata.coverage-gate]
min-lines-percent = 100

[package.metadata.coverage-gate.target.'cfg(not(windows))']
expect-no-coverable-lines = true

Exact target triples take precedence over matching cfg(...) selectors; ambiguous matching cfg policies fail closed.

martin-kolinek and others added 2 commits August 25, 2026 18:11
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Keep the target-aware coverage-gate implementation publishable on its own. Cargo Anvil can consume version 0.4.0 after the crate has been released to crates.io.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@codecov-commenter

Codecov Comments Bot (codecov-commenter) commented Aug 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.7%. Comparing base (95089c5) to head (eaf6995).

❌ Your project status has failed because the head coverage (97.7%) is below the target coverage (100.0%). You can increase the head coverage or adjust the target coverage.

Additional details and impacted files
@@          Coverage Diff           @@
##            main    #101    +/-   ##
======================================
  Coverage   97.7%   97.7%            
======================================
  Files        286     287     +1     
  Lines      62174   62363   +189     
======================================
+ Hits       60751   60942   +191     
+ Misses      1423    1421     -2     
Flag Coverage Δ
linux 97.6% <100.0%> (?)
linux-arm 97.6% <100.0%> (?)
windows 97.9% <100.0%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

martin-kolinek and others added 2 commits August 26, 2026 11:44
Exercise rustc target discovery failures and every target policy shape so coverage and mutation gates validate the new behavior.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The rustc discovery tests require filesystem and process access, both forbidden by Miri isolation.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
min-lines-percent = 100

[package.metadata.coverage-gate.target.'cfg(not(windows))']
enabled = false

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why introduce a new enabled flag when we already have min-lines-percent and expect-no-coverable-lines?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Agreed — enabled was redundant with the existing policy keys. I removed it in 0070062.

Target opt-outs now use min-lines-percent = 0; a positive target-specific threshold restores gating for an exact-triple override, and expect-no-coverable-lines = true remains the self-validating assertion. I updated the design, generated README, parser, tests, and metadata-only package query accordingly.

Remove the redundant target enabled flag. Target policies now use the existing min-lines-percent and expect-no-coverable-lines keys exclusively.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Comment thread crates/cargo-coverage-gate/src/lib.rs Outdated
Comment thread crates/cargo-coverage-gate/src/lib.rs Outdated
Comment thread crates/cargo-coverage-gate/src/lib.rs Outdated
Comment thread crates/cargo-coverage-gate/src/lib.rs
martin-kolinek and others added 2 commits August 27, 2026 09:44
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@martin-kolinek
martin-kolinek marked this pull request as ready for review August 27, 2026 17:06
Copilot AI lite review requested due to automatic review settings August 27, 2026 17:06

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR extends cargo-coverage-gate with Cargo-style target selectors so packages can vary coverage policy by target triple / cfg(...), and adds CLI + library surfaces to evaluate policy for an explicit target and to query “test-only” (non-instrumented) packages.

Changes:

  • Add target-policy parsing and application during workspace metadata load (exact triple precedence; ambiguous matching cfg policies fail closed).
  • Add --target and a metadata-only --print-test-only-packages mode (plus a new test_only_packages library API).
  • Introduce target discovery/matching via cargo-platform and a new TargetContext module, and bump cargo-coverage-gate to 0.4.0.

Reviewed changes

Copilot reviewed 12 out of 13 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
crates/cargo-coverage-gate/tests/cli.rs Adds CLI integration tests for --target and --print-test-only-packages, plus workspace test helpers.
crates/cargo-coverage-gate/src/workspace.rs Implements parsing + resolution of target-specific policies during workspace load, including ambiguity rejection.
crates/cargo-coverage-gate/src/verdict.rs Exposes resolve_gated internally so it can be reused by the new metadata-only query API.
crates/cargo-coverage-gate/src/target.rs New module to resolve a target triple + rustc --print cfg and match against cargo-platform selectors.
crates/cargo-coverage-gate/src/lib.rs Updates public API/docs: adds evaluate_many_for_target and test_only_packages, wires workspace loading with target.
crates/cargo-coverage-gate/src/error.rs Adds error types for invalid/ambiguous target policies and target resolution failures.
crates/cargo-coverage-gate/src/bin/cargo-coverage-gate/run.rs Adds early-exit --print-test-only-packages flow and passes target into evaluation.
crates/cargo-coverage-gate/src/bin/cargo-coverage-gate/cli.rs Defines --target and --print-test-only-packages CLI flags and help text.
crates/cargo-coverage-gate/README.md Regenerates user-facing docs to describe target policies and new CLI/API surfaces.
crates/cargo-coverage-gate/docs/design/README.md Updates design doc to specify target policy schema, precedence rules, and new CLI behavior.
crates/cargo-coverage-gate/Cargo.toml Bumps crate version to 0.4.0 and adds cargo-platform dependency.
Cargo.toml Adds cargo-platform as a workspace dependency.
Cargo.lock Updates lockfile for the new dependency and crate version bump.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread crates/cargo-coverage-gate/src/workspace.rs Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Copilot speaking]

Published 25 findings. No finding follows up on an existing discussion thread.

See diagnostics
Diagnostic Value
Cache Miss

Comment thread Cargo.toml
Comment thread crates/cargo-coverage-gate/tests/cli.rs Outdated
Comment thread crates/cargo-coverage-gate/src/workspace.rs Outdated
Comment thread crates/cargo-coverage-gate/tests/cli.rs Outdated
Comment thread crates/cargo-coverage-gate/docs/design/README.md Outdated
Comment thread crates/cargo-coverage-gate/src/error.rs Outdated
Comment thread crates/cargo-coverage-gate/src/bin/cargo-coverage-gate/cli.rs Outdated
Comment thread crates/cargo-coverage-gate/src/bin/cargo-coverage-gate/run.rs Outdated
Comment thread crates/cargo-coverage-gate/src/bin/cargo-coverage-gate/run.rs Outdated
Comment thread crates/cargo-coverage-gate/src/workspace.rs
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings August 28, 2026 12:27

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 12 out of 13 changed files in this pull request and generated 1 comment.

Suppressed comments (1)

crates/cargo-coverage-gate/src/workspace.rs:234

  • The PR description and config example mention a target-specific enabled = false, but target policy parsing here only accepts min-lines-percent or expect-no-coverable-lines = true (and errors if neither is set). As-is, configs using enabled = false will fail to load; either implement enabled in target policy tables (and define how it interacts with threshold/expect), or update the PR description/example to match the actual supported schema.
            let policy = if expect_no_coverable_lines {
                PolicyOverride::ExpectNoCoverableLines
            } else if let Some(value) = min_lines_percent {
                PolicyOverride::Threshold(value)
            } else {

Comment thread crates/cargo-coverage-gate/src/bin/cargo-coverage-gate/cli.rs
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings August 28, 2026 12:44

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 12 out of 13 changed files in this pull request and generated no new comments.

Suppressed comments (1)

Previously missed (1) — in code that hasn't changed since the last review.

crates/cargo-coverage-gate/src/verdict.rs:157

  • resolve_gated is only used within this module, so widening it to pub(crate) is unnecessary and increases the internal surface area for no clear benefit. Keeping it private makes refactors easier and prevents accidental cross-module coupling.
pub(crate) fn resolve_gated<'w>(workspace: &'w Workspace, packages: &[String]) -> Result<Vec<&'w Member>, CoverageGateError> {

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings August 28, 2026 13:02

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 12 out of 13 changed files in this pull request and generated no new comments.

Suppressed comments (1)

Previously missed (1) — in code that hasn't changed since the last review.

crates/cargo-coverage-gate/src/verdict.rs:157

  • resolve_gated was widened to pub(crate) but appears to still be used only within verdict.rs. Keeping it private reduces the API surface inside the crate and makes future refactors easier (callers can’t accidentally start depending on it).
pub(crate) fn resolve_gated<'w>(workspace: &'w Workspace, packages: &[String]) -> Result<Vec<&'w Member>, CoverageGateError> {

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings August 28, 2026 17:18

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 12 out of 13 changed files in this pull request and generated 1 comment.

Comment thread crates/cargo-coverage-gate/Cargo.toml
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings August 28, 2026 17:25
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 13 out of 14 changed files in this pull request and generated no new comments.

Suppressed comments (1)

Previously missed (1) — in code that hasn't changed since the last review.

crates/cargo-coverage-gate/src/verdict.rs:157

  • resolve_gated is only used within verdict.rs (the only call site is evaluate(...) above), so making it pub(crate) unnecessarily expands the crate-internal surface area and makes refactors harder. Keeping it private avoids accidental cross-module coupling.
pub(crate) fn resolve_gated<'w>(workspace: &'w Workspace, packages: &[String]) -> Result<Vec<&'w Member>, CoverageGateError> {

Copilot AI review requested due to automatic review settings August 28, 2026 17:29

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 13 out of 14 changed files in this pull request and generated 1 comment.

Comment thread crates/cargo-coverage-gate/CHANGELOG.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants