Repository navigation
ci: enforce test coverage gate before merge, not just after - #2813
Conversation
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]>
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]>
|
/ok to test dbcc6e3 |
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]>
Signed-off-by: Kajal Jain <[email protected]>
|
/ok to test e841670 |
|
Is it actually working? Before the decrease to 95% just now, it said |
Reduced to 95 for now |
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]>
Yeah np, just that the CI will be longer and the servers are skipped in coverage since they dont have |
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]>
|
/ok to test b86c718 |
|
/ok to test 8480497 |
|
/ok to test b3ccf39 |
Summary
[tool.coverage.report] fail_under) previously only ran infull-test-suite.yml, which triggers onpushtomain— never a required PR check, so it never blocked a merge. The equivalent step inunit-tests.yml(the PR-time, required-check workflow) printed theFAIL 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, matchingfull-test-suite.yml's "Test" step exactly. Splitting them across separate steps was silently defeating--cov-fail-underon 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).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.scripts/ci/cov_fail_under.py, which reads the threshold frompyproject.toml. Both workflows call--cov-fail-under="$(python3 scripts/ci/cov_fail_under.py)"instead of each hardcoding the number, sopyproject.tomlis the single source of truth.maincurrently 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>passespython3 scripts/ci/cov_fail_under.pycorrectly readspyproject.tomland prints the thresholdfail_under=100, confirmed a real##[error]annotation and exit code 1 (not just a printed warning), then reverted to 95