Skip to content

ci: enforce test coverage gate before merge, not just after - #2813

Merged
cmunley1 merged 11 commits into
mainfrom
enforce-coverage-pre-merge
Aug 27, 2026
Merged

cmunley1 merged 11 commits into
mainfrom
enforce-coverage-pre-merge

Conversation

@kajalj22

@kajalj22 kajalj22 commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • The 96% coverage gate ([tool.coverage.report] fail_under) previously only ran in full-test-suite.yml, which triggers on push to main — never a required PR check, so it never blocked a merge. The equivalent step in unit-tests.yml (the PR-time, required-check workflow) printed the FAIL Required test coverage... banner on every PR but reported itself green anyway.
  • unit-tests.yml's coverage-producing steps ("Core unit tests", sandbox env setup, "Sandbox unit tests") are now merged into one step, matching full-test-suite.yml's "Test" step exactly. Splitting them across separate steps was silently defeating --cov-fail-under on GitHub's runners for reasons not fully diagnosable without a matching Linux environment to inspect; the merged single-step form is the one we've verified reliably fails when it should (see Test plan).
  • This step now runs unconditionally (not gated on run_full), so the gate can't be silently skipped by change-detection misclassifying a PR — intentional tradeoff of a bit of extra CI time on every PR for the gate always actually running.
  • Added scripts/ci/cov_fail_under.py, which reads the threshold from pyproject.toml. Both workflows call --cov-fail-under="$(python3 scripts/ci/cov_fail_under.py)" instead of each hardcoding the number, so pyproject.toml is the single source of truth.
  • Lowered the threshold from 96.0% to 95.0%. 96% was an undocumented ratchet inherited from an unrelated PR (feat: CPU Profiling #763, Feb 2026), and main currently measures ~95.99% — enforcing 96% pre-merge would immediately block every subsequent PR touching core code on pre-existing debt. 95% gives a small buffer below current measured coverage so the gate is real and passing today.

Test plan

  • pre-commit run --files <changed files> passes
  • python3 scripts/ci/cov_fail_under.py correctly reads pyproject.toml and prints the threshold
  • Verified live on this PR's own CI that the gate actually fails: temporarily pushed fail_under=100, confirmed a real ##[error] annotation and exit code 1 (not just a printed warning), then reverted to 95
  • CI green on this PR at the final 95% threshold

The 96% coverage gate only ran in full-test-suite.yml (push-to-main
only) and was never a required PR check, so it never blocked a merge.
Worse: the same pytest-cov invocation used implicitly in unit-tests.yml
printed the FAIL banner on every PR but exited 0 anyway, since no
--cov-fail-under flag was passed explicitly.

- Add explicit --cov-fail-under=96 to unit-tests.yml's "Sandbox unit
  tests" step (the PR-time, required-check job) and to
  full-test-suite.yml for consistency, so a coverage regression now
  actually fails the check instead of only printing a warning.
- Add unit tests closing real, previously-uncovered branches in
  low-risk discovery/registry/listing/utility modules (not on the
  live rollout/serving path) to narrow the pre-existing gap ahead of
  the gate landing.

Signed-off-by: Kajal Jain <[email protected]>
@copy-pr-bot

copy-pr-bot Bot commented Aug 26, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

Addresses review feedback on this branch:
- The coverage gate previously only ran when run_full was true, so a
  server-only-scoped PR (which still touches the measured coverage
  surface: resources_servers/, responses_api_agents/) could merge
  without the check ever running. Core/sandbox test steps now run
  unconditionally in unit-tests.yml.
- --cov-fail-under=96 was hardcoded in two workflow files on top of
  pyproject.toml's [tool.coverage.report] fail_under = 96.0, three
  places to keep in sync. Both workflows now read the threshold via
  a new scripts/ci/cov_fail_under.py, making pyproject.toml the only
  source of truth.
- test_registry.py's new _entry() helper now builds paths under the
  tmp_path fixture instead of hardcoded /tmp literals, matching the
  rest of the file's convention.

Signed-off-by: Kajal Jain <[email protected]>
@kajalj22
kajalj22 marked this pull request as ready for review August 27, 2026 07:35
@kajalj22
kajalj22 requested a review from a team as a code owner August 27, 2026 07:35
@kajalj22

Copy link
Copy Markdown
Contributor Author

/ok to test dbcc6e3

ko3n1g
ko3n1g previously approved these changes Aug 27, 2026
adil-a
adil-a previously approved these changes Aug 27, 2026
@ananthsub

Copy link
Copy Markdown
Contributor

This means the very next PR that touches core nemo_gym/ code will be blocked by this pre-existing debt until someone closes the remaining gap or the threshold is temporarily adjusted.

how was 96% chosen? since this is now exposed on PRs, can we lower the threshold to something passing (eg 95%) so we don't block the merge, and then work on increasing the threshold back up after?

96.0 was inherited from a Feb 2026 drive-by bump (PR #763) with no
documented rationale, and main currently sits at ~95.99% even after
this PR's added tests. Set fail_under = 95.9 (a small buffer below
measured coverage) so the newly-enforced gate is real and achievable
today, instead of blocking on debt this PR doesn't fully close.

Also fixes cov_fail_under.py, which truncated fractional thresholds
(e.g. 95.9 -> 95) since it always cast to int; it previously only
worked by coincidence because 96.0 has no fractional part.

Signed-off-by: Kajal Jain <[email protected]>
… enforce-coverage-pre-merge

Signed-off-by: Kajal Jain <[email protected]>
@kajalj22
kajalj22 dismissed stale reviews from adil-a and ko3n1g via e841670 August 27, 2026 08:10
@kajalj22

Copy link
Copy Markdown
Contributor Author

/ok to test e841670

@cmunley1

Copy link
Copy Markdown
Contributor

Is it actually working? Before the decrease to 95% just now, it said
FAIL Required test coverage of 96% not reached. Total coverage: 95.99%
But showed pass.

@cmunley1

Copy link
Copy Markdown
Contributor

@kajalj22

Copy link
Copy Markdown
Contributor Author

This means the very next PR that touches core nemo_gym/ code will be blocked by this pre-existing debt until someone closes the remaining gap or the threshold is temporarily adjusted.

how was 96% chosen? since this is now exposed on PRs, can we lower the threshold to something passing (eg 95%) so we don't block the merge, and then work on increasing the threshold back up after?

Reduced to 95 for now

@kajalj22

Copy link
Copy Markdown
Contributor Author

Is it actually working? Before the decrease to 95% just now, it said FAIL Required test coverage of 96% not reached. Total coverage: 95.99% But showed pass.

Yea fixing it now, the gating is not being checked /enforced

full-test-suite.yml's coverage gate (push to main) reliably fails when
coverage is below threshold -- that's why Slack alerts fire on main.
unit-tests.yml split the equivalent work across three separate steps
(Core unit tests / Setup sandbox env / Sandbox unit tests); on that
PR-time workflow, --cov-fail-under stopped actually failing the job
even though it printed the FAIL banner (confirmed via GitHub's own
check-run annotations, not just log text -- no error was recorded).

Rather than a step split with unclear GitHub Actions semantics behind
it, merge all three into one step, mirroring full-test-suite.yml's
single "Test" step exactly. Same command, same known-working shape.

Signed-off-by: Kajal Jain <[email protected]>
@cmunley1

cmunley1 commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

Also does this drop the run_full guard on Core unit tests, Setup public sandbox test environment and Sandbox unit tests, so those now run on every PR? Was that intentional, given a server-only PR wont move the coverage number i think?

Yea, intentional, you're right it usually won't move the number much. Keeping it this way so the gate works across the board regardless.

Happy to revisit if it becomes a pain point!

Yeah np, just that the CI will be longer and the servers are skipped in coverage since they dont have __init__.py

Confirmed live on this PR's own CI that the gate now genuinely fails
when it should (pushed fail_under=100 temporarily, saw a real
##[error] and exit code 1, then reverting here). Restore fail_under
to 95.0 -- 100 was only for that verification.

Drop the unit tests added earlier to nudge coverage upward: with the
threshold now realistically set to what main already achieves, closing
the gap test-by-test isn't needed to land this change.

Also trim the workflow comments down to the essential "why", not a
narration of the debugging process that got here.

Signed-off-by: Kajal Jain <[email protected]>
@kajalj22

Copy link
Copy Markdown
Contributor Author

/ok to test b86c718

@kajalj22
kajalj22 marked this pull request as ready for review August 27, 2026 08:50
@kajalj22
kajalj22 requested review from adil-a, cmunley1 and ko3n1g August 27, 2026 08:51
@kajalj22
kajalj22 enabled auto-merge (squash) August 27, 2026 08:53
@kajalj22

Copy link
Copy Markdown
Contributor Author

/ok to test 8480497

@cmunley1

Copy link
Copy Markdown
Contributor

/ok to test b3ccf39

@cmunley1
cmunley1 disabled auto-merge August 27, 2026 18:16
@cmunley1
cmunley1 merged commit 5de32d3 into main Aug 27, 2026
36 checks passed
@cmunley1
cmunley1 deleted the enforce-coverage-pre-merge branch August 27, 2026 18:16

This branch was previously deployed

1 inactive deployment
public — b3ccf397 Deployed Aug 27, 2026 by copy-pr-bot[bot] via release / finalize / notify #2121
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.

5 participants