Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.
Python aicode-complexitycode-healthcode-intelligencecode-qualitydead-codedeveloper-toolsdocumentationgit-analyticsmcpopen-sourcepythonrefactoringstatic-analysistechnical-debt
fix(coverage): let any unapplied gate give way to the project verdict (#3519)
Aman4b8b85be629d
diff --git a/packages/core/src/repowise/core/analysis/patch_coverage/compute.py b/packages/core/src/repowise/core/analysis/patch_coverage/compute.pyindex 07dafc052..d69b7a332 100644--- a/packages/core/src/repowise/core/analysis/patch_coverage/compute.py+++ b/packages/core/src/repowise/core/analysis/patch_coverage/compute.py@@ -278,9 +278,9 @@ class PatchCoverage:verdicts = [self.flat_gate, self.risky_gate, self.branch_gate, project]if self.failing_path_gates or "fail" in verdicts:return "fail"- # An unapplied branch gate gives way to a project verdict.- if project != "not_set" and verdicts[2] == "no_data":- verdicts[2] = "not_set"+ # An unapplied gate (no_data) ahead of the project gives way to a project verdict.+ if project != "not_set":+ verdicts[:3] = ["not_set" if v == "no_data" else v for v in verdicts[:3]]return next((v for v in verdicts if v != "not_set"), "not_set")@propertydiff --git a/tests/unit/analysis/test_patch_coverage_branches.py b/tests/unit/analysis/test_patch_coverage_branches.pyindex e8f845646..ff2b04426 100644--- a/tests/unit/analysis/test_patch_coverage_branches.py+++ b/tests/unit/analysis/test_patch_coverage_branches.py@@ -4,6 +4,9 @@ from __future__ import annotationsfrom dataclasses import replacefrom pathlib import Path+from types import SimpleNamespace++import pytestfrom repowise.core.analysis.health.coverage import (file_coverage,@@ -24,6 +27,7 @@ from repowise.core.analysis.patch_coverage import (headline,render_markdown,)+from repowise.core.analysis.patch_coverage.compute import PatchCoverageFIXTURES = Path(__file__).resolve().parents[2] / "fixtures" / "coverage"@@ -186,6 +190,37 @@ def test_no_changed_line_branching_is_nothing_to_judge() -> None:)+def _gate(flat, risky, branch, project):+ """PatchCoverage.gate on stand-in sub-verdicts, so only the precedence is tested."""+ fake = SimpleNamespace(+ flat_gate=flat,+ risky_gate=risky,+ branch_gate=branch,+ project=None if project == "not_set" else SimpleNamespace(gate=project),+ failing_path_gates=[],+ )+ return PatchCoverage.gate.fget(fake)+++ ("flat", "risky", "branch", "project", "expected"),+ [+ # An unapplied gate ahead of the project gives way to it (#2860).+ ("not_set", "no_data", "not_set", "pass", "pass"), # the reported bug+ ("no_data", "not_set", "not_set", "pass", "pass"),+ ("no_data", "no_data", "no_data", "pass", "pass"),+ # Unchanged behaviour.+ ("not_set", "no_data", "not_set", "not_set", "no_data"), # no project gate+ ("not_set", "no_data", "not_set", "no_data", "no_data"), # project unapplied too+ ("pass", "no_data", "not_set", "pass", "pass"),+ ("fail", "no_data", "not_set", "pass", "fail"), # a real failure is never demoted+ ("not_set", "no_data", "not_set", "fail", "fail"), # a failing project wins+ ],+)+def test_unapplied_gates_ahead_of_the_project_give_way(flat, risky, branch, project, expected):+ assert _gate(flat, risky, branch, project) == expected++def test_coverage_without_per_line_branch_data_says_so() -> None:cov = {"src/a.py": file_coverage("src/a.py", [1], [1])}gated = replace(compute_patch_coverage({"src/a.py": {1}}, cov), branch_threshold=80)