Skip to content

TEST: Add coverage enforcement (fail-under 78%, diff-cover 90%)#1605

Open
romanlutz wants to merge 5 commits intomicrosoft:mainfrom
romanlutz:test/coverage-enforcement
Open

TEST: Add coverage enforcement (fail-under 78%, diff-cover 90%)#1605
romanlutz wants to merge 5 commits intomicrosoft:mainfrom
romanlutz:test/coverage-enforcement

Conversation

@romanlutz
Copy link
Copy Markdown
Contributor

Summary

Adds automated coverage enforcement to prevent regressions and ensure new code is well-tested.

Changes

1. Overall coverage floor: 78%

  • Added --cov-fail-under=78 to all unit-test Makefile targets (unit-test, unit-test-cov-html, unit-test-cov-xml)
  • Current baseline is ~79%, so this prevents regression without blocking existing work
  • This threshold should be ratcheted up as coverage improves

2. Diff coverage: 90% on new/changed lines

  • Added diff-cover (>=9.0.0) as a dev dependency
  • Added CI step that runs on PRs only: checks that >=90% of new/changed lines in pyrit/ are covered by tests
  • Added make diff-cover target for local use
  • This is the highest-signal check: it doesn't penalize legacy gaps but ensures new code is tested

How it works in CI

  1. Unit tests run with --cov-fail-under=78 (fails build if overall coverage drops below 78%)
  2. On PRs, diff-cover compares coverage against origin/main and fails if <90% of changed lines are covered

Local usage

make unit-test        # runs tests, fails if coverage < 78%
make diff-cover       # runs tests + checks diff coverage vs main >= 90%

romanlutz and others added 5 commits April 12, 2026 04:49
- Add --cov-fail-under=78 to all unit-test Makefile targets to prevent
  overall coverage regression (current baseline: ~79%)
- Add diff-cover>=9.0.0 as dev dependency
- Add diff-cover step to CI workflow (PR-only) requiring >=90% coverage
  on new/changed lines
- Add 'make diff-cover' target for local use

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Runs in parallel with build_and_test on a single Ubuntu/Python 3.12
runner instead of blocking the full OS x Python matrix.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Use 'python -m diff_cover.diff_cover_tool' instead of '-m diff_cover'
  (diff_cover is a package, not directly executable)
- Fix test_simple_initializer assertion: check for 'converter_target'
  instead of 'PromptConverter.converter_target' since apply_defaults
  registers concrete class names, not the abstract base

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Remove --cov from build_and_test.yml matrix jobs (24 jobs now run
  faster without coverage overhead)
- Move CodeCoverageSummary report to coverage workflow
- coverage workflow runs once on Ubuntu/Python 3.12:
  1. Overall threshold: --cov-fail-under=78
  2. Coverage summary report (badge + markdown)
  3. Diff coverage on PRs: >=90% on changed lines
- Rename diff_cover.yml workflow to 'coverage'
- Add unit-test-cov Makefile target (local coverage without xml/junit)
- Keep unit-test target clean (no coverage, for quick local runs)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Add unit-test-junit target (tests + junit xml, no coverage)
- Add diff-cover-only target (just diff-cover, assumes coverage.xml exists)
- Both workflows now use make instead of inline commands
- Removed --doctest-modules from unit-test-cov-xml (not needed for coverage)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.

1 participant