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(review): don't report a health delta for code that moved between files (#4314)
berce754672e6f515
diff --git a/packages/core/src/repowise/core/analysis/review_directive.py b/packages/core/src/repowise/core/analysis/review_directive.pyindex 1a7d591c9..903dbdf1e 100644--- a/packages/core/src/repowise/core/analysis/review_directive.py+++ b/packages/core/src/repowise/core/analysis/review_directive.py@@ -268,10 +268,20 @@ def _actions(delta: ChangeHealthDelta, tests: CoveringTestEvidence) -> tuple[Revdef _net_health(delta: ChangeHealthDelta) -> str:- """The changed code's base-nloc average score on both sides, or ``""`` without one."""+ """The changed code's base-nloc average score on both sides, or ``""`` without one.++ The score reads code structure only. When code moved between files, the+ source is scored on what stayed behind and the destination has no base side,+ so a pure move would read as a gain or a loss; name the move instead.+ """change = score_change(delta.files)if change is None:return ""+ if delta.moved_total:+ return (+ " Code moved between files, so the changed code's health"+ " (structure only) is not compared."+ )base, head = round(change.base, 2), round(change.head, 2)if base == head:return f" Health of the changed code holds at {head:.2f}."diff --git a/tests/unit/analysis/test_review_directive.py b/tests/unit/analysis/test_review_directive.pyindex 03af5dd33..2c2b21926 100644--- a/tests/unit/analysis/test_review_directive.py+++ b/tests/unit/analysis/test_review_directive.py@@ -83,6 +83,19 @@ def test_the_headline_states_the_changed_codes_health_on_both_sides():assert review_directive(delta).headline.endswith("Health of the changed code holds at 9.50.")+def test_a_move_names_the_structure_only_basis_instead_of_a_delta():+ from repowise.core.analysis.change_health.file_scores import FileScoreDelta++ delta = _delta([_finding(severity="critical")])+ delta.files = [FileScoreDelta("app/a.py", 5.51, 5.70, 4.49, 4.30, 100, 60)]+ delta.moved_total = 2+ headline = review_directive(delta).headline+ assert headline.endswith(+ "Code moved between files, so the changed code's health (structure only) is not compared."+ )+ assert "5.51" not in headline++def test_low_severity_only_recommends_review():directive = review_directive(_delta([_finding(severity="low")]))assert directive.status == "review_recommended"diff --git a/tests/unit/change_health/test_moved_findings.py b/tests/unit/change_health/test_moved_findings.pyindex 979fd72e5..6e3a8eb51 100644--- a/tests/unit/change_health/test_moved_findings.py+++ b/tests/unit/change_health/test_moved_findings.py@@ -109,6 +109,36 @@ def test_a_partial_split_reports_the_moved_findings_as_moved(make_repo):assert delta.moved_total >= 1+def test_a_pure_move_claims_no_health_change_in_the_headline(make_repo):+ from repowise.core.analysis.review_directive import review_directive++ repo = make_repo()+ steps = [python_complex(f"step{i}", 12 + i) for i in range(5)]+ repo.commit("seed", {"flow.py": "".join(steps)})+ repo.commit("move", {"flow.py": "".join(steps[2:]), "moved.py": "".join(steps[:2])})++ headline = review_directive(compare(repo)).headline++ assert "Code moved between files" in headline+ assert "(structure only)" in headline+ assert "Health of the changed code:" not in headline+++def test_a_change_without_a_move_keeps_its_health_delta(make_repo):+ from repowise.core.analysis.review_directive import review_directive++ repo = make_repo()+ repo.commit("seed", {"flow.py": python_complex("step", 4) + python_complex("other", 4)})+ repo.commit("grow", {"flow.py": python_complex("step", 16) + python_complex("other", 4)})++ delta = compare(repo)+ headline = review_directive(delta).headline++ assert delta.moved_total == 0+ assert "Health of the changed code: " in headline+ assert "Code moved" not in headline++def test_a_moved_function_that_grew_surfaces_as_worsened_with_its_origin(make_repo):repo = make_repo()repo.commit("seed", {"tool.py": python_complex("tangle", 14) + python_complex("knot", 5)})