Skip to content

test: enforce 100% coverage - #239

Merged
uniqueg merged 3 commits into
devfrom
test/enforce-coverage
Oct 23, 2026
Merged

uniqueg merged 3 commits into
devfrom
test/enforce-coverage

Conversation

@uniqueg

@uniqueg uniqueg commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

Summary

Enforces 100% test coverage, as in cloud-registry (#163 there).

Closes #159

  • Config:
    • [tool.coverage] in pyproject.toml: source = ["pro_tes"], fail_under = 100, and the __main__ block excluded.
    • codecov.yml: 100% target for the project and for the patch of each pull request. It is the same file as in cloud-registry.
  • CI: the test job runs coverage run -m pytest and coverage xml, both of which fail below 100%. On Python 3.12 it uploads the report to Codecov; upload errors fail the job only on pushes, because forks and Dependabot get no token. The README badge already points to Codecov.
  • Tests: they now cover the remaining code:
    • the error branches of task creation and listing (no body, the body removed by a middleware, tasks py-tes can't represent, task IDs already taken);
    • the database connector, the model conversion, the middlewares without JSON bodies, and run_app();
    • that clients can't set logs.
    • test_create_task_next_backend was flaky in what it covered: the random middleware often skipped the unusable backend. It now relays in a fixed order.
  • Refactor: removes code that can't run:
    • a PyMongoError handler around calls that don't touch the database;
    • the handling of client-supplied logs, which the API rejects as read-only;
    • the unused allow_none parameter of convert_time().
    • proTES now always creates a task's logs itself: logs that a middleware adds are neither stored nor relayed.
  • Docs: docs/development.md (how to run with coverage, and the 100% rule) and CONTRIBUTING.md.

Verification

  • coverage run -m pytest and coverage report: 166 tests pass, 860 statements, 100%. Repeated runs with separate data files were 100% every time.
  • With MongoDB 7 (MONGODB_TEST_URI): 166 tests pass.
  • ruff check, ruff format --check, mypy pro_tes tests, ast-grep scan, semgrep --config=.semgrep, actionlint and mkdocs build --strict are clean.
  • Reviews: adversarial and quality review before pushing; fixed except as listed below.
  • CI: all checks pass on Python 3.10 and 3.12 (100% on both), with MongoDB 7.0, and for the Compose smoke test, docs, static analysis and CodeQL. The Codecov upload was first refused ("Token required because branch is protected"); after the maintainer added the CODECOV_TOKEN secret, a re-run uploaded the report.

Declined review findings

  • Raising MiddlewareException if a middleware sets logs (instead of dropping them): no middleware sets them, and logs are read-only in the TES API, so proTES owns them. The commit message documents this.
  • Moving the coverage rule to a "Tests" bullet of docs/contributing.md, as in cloud-registry: proTES's contributing guide is being migrated separately (docs: add code of conduct and contributing guide #211). For now the rule is in docs/development.md, and CONTRIBUTING.md points there.

🤖 Generated with Claude Code

Summary by Sourcery

Enforce complete unit-test coverage across the project while tightening task log ownership and removing unreachable code.

Enhancements:

  • Make proTES own task log creation and remove unreachable handling for client-supplied logs and non-database errors.
  • Simplify time conversion by removing the unused optional behavior.

Build:

  • Configure package coverage measurement to exclude the executable entry-point block and require 100% coverage.

CI:

  • Enforce 100% test coverage in CI and publish Python 3.12 coverage reports to Codecov with push-aware upload failures.
  • Require Codecov project and pull-request patch coverage targets of 100%.

Documentation:

  • Document the coverage workflow and 100% coverage requirement for contributors and developers.

Tests:

  • Expand tests to cover task creation and listing error paths, database and model conversion behavior, middleware failures, application startup, and read-only task logs.
  • Stabilize backend-selection coverage by using deterministic middleware ordering.

uniqueg and others added 3 commits October 23, 2026 00:59
The relay caught database errors where none can occur, and kept logs of
incoming tasks, which the API rejects (they are read-only). proTES now
always creates the logs itself: logs that a middleware adds are neither
stored nor relayed. convert_time() loses its unused allow_none
parameter.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Test the error branches of task creation, listing and the database
connector, the model conversion, the middlewares without JSON bodies,
run_app(), and that clients can't set logs. Fix the backend order in
test_create_task_next_backend, so that it always tries the unusable
backend first.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Measure coverage in the test job, fail below 100% (fail_under), upload
it to Codecov (failing only on pushes) and require 100% of the project
and of the changes of pull requests there (codecov.yml). Document the
requirement.

Closes #159

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

The PR raises coverage enforcement to 100% across local tooling, CI, and Codecov, adds tests for the remaining uncovered paths, and simplifies task creation by removing unreachable code and making proTES solely responsible for initial task logs.

Sequence diagram for enforced coverage reporting in CI

sequenceDiagram
    participant CI as GitHub Actions
    participant Tests as pytest
    participant Coverage as coverage.py
    participant Codecov

    CI->>Coverage: coverage run -m pytest
    Coverage->>Tests: run test suite
    Tests-->>Coverage: test results and execution data
    CI->>Coverage: coverage xml
    Coverage-->>CI: fail below 100%
    CI->>Codecov: Submit Report to Codecov
    Codecov-->>CI: enforce 100% project and patch targets
Loading

Sequence diagram for proTES-owned task logs

sequenceDiagram
    participant Client
    participant Server as create_task
    participant Database
    participant Backend as TES backend

    Client->>Server: create_task
    Server->>Server: _set_logs
    Server->>Database: store task with generated logs
    Server->>Backend: submit task without client or middleware logs
    Backend-->>Server: task response
    Server-->>Client: task response with server-owned logs
Loading

File-Level Changes

Change Details Files
Enforce complete unit-test coverage in local development and CI, with Codecov requiring full project and patch coverage.
  • Configured coverage to measure pro_tes, exclude the executable module guard, and fail below 100%.
  • Replaced the CI test step with coverage execution and XML generation on both supported Python versions.
  • Added a Python 3.12 Codecov upload with push-specific failure behavior for unavailable fork/Dependabot tokens.
  • Documented coverage commands and the 100% contribution requirement.
.github/workflows/checks.yaml
codecov.yml
pyproject.toml
docs/development.md
CONTRIBUTING.md
Expand tests to exercise previously uncovered application, model, middleware, database, and error-handling paths.
  • Added endpoint tests for malformed or missing bodies, unrepresentable tasks, duplicate IDs, user filtering, authentication, resources, and read-only logs.
  • Added model conversion, forwarding metadata, application startup, database connector, and middleware no-JSON coverage.
  • Made backend-order testing deterministic to avoid random middleware selection affecting coverage.
tests/ga4gh/tes/test_models.py
tests/ga4gh/tes/test_server.py
tests/plugins/middlewares/task_distribution/test_distance.py
tests/plugins/middlewares/task_distribution/test_random.py
tests/test_app.py
tests/utils/test_db.py
Simplify task creation and log ownership by removing unreachable behavior and ensuring proTES generates task logs itself.
  • Removed the unused database-error handler around non-database operations.
  • Stopped accepting or converting client- or middleware-supplied logs; generated a single proTES-owned initial log instead.
  • Removed the unused allow_none parameter from time conversion.
pro_tes/ga4gh/tes/task_runs.py
pro_tes/utils/models.py

Assessment against linked issues

Issue Objective Addressed Explanation
#159 Measure coverage for the project and enforce 100% coverage locally and in CI, failing when coverage is below the threshold. ✅
#159 Publish coverage to Codecov, enforce 100% project and pull-request patch targets, and show coverage in the README. ✅
#159 Bring the codebase to 100% test coverage by covering the remaining code paths. ✅

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 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (dev@abecef1). Learn more about missing BASE report.

Additional details and impacted files
@@           Coverage Diff           @@
##             dev      #239   +/-   ##
=======================================
  Coverage       ?   100.00%           
=======================================
  Files          ?        18           
  Lines          ?       860           
  Branches       ?         0           
=======================================
  Hits           ?       860           
  Misses         ?         0           
  Partials       ?         0           

☔ 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 23, 2026 00:29

@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

Needs a human reviewer. If middleware-supplied task logs are meaningful, task creation now drops them and persists only a fresh empty log entry; reverting would not restore logs already lost from affected task records. The coverage gate and remaining changes are reversible, but this persisted log change is not.


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

@uniqueg
uniqueg merged commit bada721 into dev Oct 23, 2026
22 checks passed
@uniqueg
uniqueg deleted the test/enforce-coverage branch October 23, 2026 00:33
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.

test: enforce 100% coverage

1 participant