Skip to content

test: enforce 100% coverage - #377

Merged
uniqueg merged 2 commits into
devfrom
test/enforce-coverage
Oct 22, 2026
Merged

uniqueg merged 2 commits into
devfrom
test/enforce-coverage

Conversation

@uniqueg

@uniqueg uniqueg commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

Summary

FOCA's coverage is already at 100%, so this PR only enforces it, as cloud-registry does (elixir-cloud-aai/cloud-registry#163):

  • pyproject.toml: [tool.coverage.run] source = ["foca"] and [tool.coverage.report] fail_under = 100, so coverage report and coverage xml fail below 100%.
  • if TYPE_CHECKING: blocks are excluded explicitly (exclude_also): coverage excludes them by default only in recent versions (7.16 does, 7.6 doesn't), and the dev extra allows coverage>=7.6; with 7.6 the total was 99% (3 lines).
  • New codecov.yml with project and patch targets of 100% (same file as cloud-registry's).
  • CI (checks.yml, unit test jobs): coverage run -m pytest (source from the config), then coverage report -m (prints the missing lines, fails below 100%), then coverage xml. All Python versions (3.11 to 3.14, MongoDB 7.0, plus 3.13 with MongoDB 8.0 where the kernel allows it) run this step, so each fails below 100%.
  • README, "Contributing": describes the rule and how to measure coverage locally.

Closes #345

Light lane: the PR changes only configuration, a CI step and docs (no code), so the reviewer subagents and the Sourcery wait are skipped, per the user's rule; I reviewed the diff myself.

Verification

  • coverage run -m pytest (Python 3.13, MongoDB 7.0 on port 12345): 1390 passed; coverage report and coverage xml exit 0 at 100% (2120 statements, 0 missed)
  • Same data with coverage 7.6.0 (lowest allowed): 100% with the new exclude_also (99% without it)
  • Partial run (tests/test_foca.py only, 52%): coverage report and coverage xml exit 2 ("total of 52 is less than fail-under=100")
  • ruff check, ruff format --check, mypy (71 files), mkdocs build --strict pass; codecov.yml parses as YAML
  • actionlint 1.7.12 with shellcheck 0.11.0: only a pre-existing info finding on an untouched line (SC2102 on pip install -e .[dev,docs], line 41)
  • CI: all checks pass (unit tests on Python 3.11 to 3.14 with the new threshold, codecov/patch and codecov/project with the 100% targets, charts, docs); the MongoDB 8.0 job skips its tests on the runner kernel (SERVER-121912), as before

Open questions

None.

🤖 Generated with Claude Code

Summary by Sourcery

Enforce complete test coverage consistently across local checks, CI, and Codecov.

Enhancements:

  • Enforce 100% test coverage through coverage configuration and Codecov project and patch thresholds.

CI:

  • Require unit-test CI jobs to generate, report, and validate coverage against the 100% threshold.

Documentation:

  • Document the 100% coverage requirement and local coverage commands in the contributing guidance.

FOCA's coverage is at 100% (1390 tests). Set fail_under = 100 in
[tool.coverage.report], so coverage report and coverage xml (CI) fail
below it, and add a codecov.yml with project and patch targets of 100%,
as in cloud-registry. Exclude TYPE_CHECKING blocks explicitly, since
coverage only excludes them by default from 7.10 on and the dev extra
allows 7.6. CI also prints the missing lines with coverage report -m.
The README's contributing section describes the rule.

Closes #345

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@sourcery-ai

sourcery-ai Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

This PR enforces FOCA’s existing 100% test-coverage level by centralizing coverage settings in pyproject.toml, applying report/XML failure checks in every applicable unit-test CI job, configuring Codecov project and patch targets at 100%, and documenting the local workflow and prerequisites.

Flow diagram for enforced 100% coverage checks

flowchart LR
    Tests[Run pytest with coverage] --> Report[coverage report -m]
    Report --> Threshold{Coverage reaches 100%}
    Threshold -->|Yes| XML[coverage xml]
    Threshold -->|No| Fail[Fail CI and local command]
    XML --> Codecov[Codecov project and patch checks]
    Codecov -->|Target 100%| Pass[Coverage checks pass]
Loading

File-Level Changes

Change Details Files
Centralize coverage configuration and enforce a 100% threshold across local and CI measurement.
  • Configure foca as the coverage source.
  • Exclude TYPE_CHECKING blocks for compatibility with the supported coverage versions.
  • Make coverage reports and XML generation fail when total coverage is below 100%.
pyproject.toml
Apply the coverage threshold during unit-test CI runs and preserve detailed failure diagnostics.
  • Use the configured coverage source when running pytest.
  • Print missing lines with coverage report -m before generating XML.
  • Run enforcement across the existing Python and MongoDB test matrix.
.github/workflows/checks.yml
Require complete coverage for both the full project and pull-request changes in Codecov.
  • Set project coverage target to 100%.
  • Set patch coverage target to 100%.
codecov.yml
Document the enforced coverage policy and local verification workflow.
  • Explain the 100% requirement and Codecov checks.
  • Provide commands and MongoDB prerequisites for measuring coverage locally.
README.md

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@codecov

codecov Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (46aff3e) to head (66d224c).

Additional details and impacted files
@@            Coverage Diff            @@
##               dev      #377   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           25        25           
  Lines         2133      2133           
=========================================
  Hits          2133      2133           
Flag Coverage Δ
test_unit 100.00% <ø> (ø)

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.

@uniqueg
uniqueg marked this pull request as ready for review October 22, 2026 01:48

@sourcery-ai sourcery-ai Bot 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.

Hey - I've reviewed your changes and they look great!

Sourcery assessment

Approved.


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

@uniqueg
uniqueg merged commit 7ae827f into dev Oct 22, 2026
15 checks passed
@uniqueg
uniqueg deleted the test/enforce-coverage branch October 22, 2026 02:09
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