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(actions): state graph absence, not untested, when no test reaches a fragile file (#4394)
Amane5bf0b592ebe
diff --git a/packages/core/src/repowise/core/analysis/actions/rules/code.py b/packages/core/src/repowise/core/analysis/actions/rules/code.pyindex 556af3d4d..9477b694f 100644--- a/packages/core/src/repowise/core/analysis/actions/rules/code.py+++ b/packages/core/src/repowise/core/analysis/actions/rules/code.py@@ -372,8 +372,19 @@ def _fragile_step(f: FileFacts) -> tuple[str, str, str] | None:# tests" nor "tests reach it" is a claim the facts support.return Noneif cov is None and f.tests_reaching == 0:+ if f.tests_reaching_via == MOCKED_ONLY_VIA:+ # Tests reach it but replace it: that is a real gap, stated as one.+ title = f"Add tests around {code(f.path)} before its next change"+ else:+ # The graph cannot see code a framework invokes (URL routes, CLI+ # commands, registries), so an empty walk is absence of evidence,+ # not proof the file is untested. Say what the graph found.+ title = (+ f"No test reaches {code(f.path)} in the code graph: "+ "confirm it is tested before its next change"+ )return (- f"Add tests around {code(f.path)} before its next change",+ title,"A coverage report includes it at 80% or more.","unknown",)@@ -674,7 +685,9 @@ def _first_step(includes: tuple[str, ...], production: dict[str, FileFacts]) ->for path in includes:step = _fragile_step(production[path])if step is not None:- title = step[0].split(": ", 1)[0]+ # The unknown variant's title carries its own ask after the colon,+ # so it stays whole; the others drop their ": tests reach it" tail.+ title = step[0] if step[2] == "unknown" else step[0].split(": ", 1)[0]return title[0].lower() + title[1:]return Nonediff --git a/tests/unit/analysis/test_actions_rules.py b/tests/unit/analysis/test_actions_rules.pyindex 7fd51f4c6..92591818b 100644--- a/tests/unit/analysis/test_actions_rules.py+++ b/tests/unit/analysis/test_actions_rules.py@@ -73,10 +73,13 @@ def _text(a: Action) -> str:# ----------------------------------------------------------------------------def test_fragile_without_coverage_says_add_tests_and_basis_unknown() -> None:+def test_fragile_without_coverage_states_graph_absence_and_basis_unknown() -> None:out = _run(code.fragile_file, _facts([_file("src/a.py")]))(a,) = out.actions- assert a.title.startswith("Add tests around `src/a.py`")+ assert a.title == (+ "No test reaches `src/a.py` in the code graph: "+ "confirm it is tested before its next change"+ )cov = next(w for w in a.why if w.label == "line coverage")assert cov.basis == "unknown"assert a.confidence == "medium"@@ -362,8 +365,8 @@ def test_a_folder_names_its_first_step() -> None:(a,) = _run(code.fix_concentration, _concentration_facts()).actions# Every file here is untested; the most fixed one comes first.assert a.title == (- "Stabilise `pkg/cli/update/`: first, add tests around `pkg/cli/update/a0.py` "- "before its next change"+ "Stabilise `pkg/cli/update/`: first, no test reaches `pkg/cli/update/a0.py` "+ "in the code graph: confirm it is tested before its next change")assert "10 of the 25 bug-fix commits" in a.impact@@ -909,9 +912,10 @@ def test_fragile_reached_by_tests_without_a_lead_is_silent() -> None:assert out.actions == ()-def test_fragile_no_test_reaches_says_add_tests() -> None:+def test_fragile_no_test_reaches_states_graph_absence_not_untested() -> None:(a,) = _run(code.fragile_file, _facts([_file("src/a.py", tests_reaching=0)])).actions- assert a.title.startswith("Add tests around `src/a.py`")+ assert a.title.startswith("No test reaches `src/a.py` in the code graph")+ assert "Add tests" not in a.titlereach = next(w for w in a.why if w.label == "tests that reach it")assert (reach.value, reach.basis) == ("None in the code graph", "inferred")@@ -931,7 +935,7 @@ def test_fragile_unknown_reach_is_not_zero() -> None:facts = _facts([unknown], unavailable={"test_map": "Not in this index yet."})assert _run(code.fragile_file, facts).actions == ()(zero,) = _run(code.fragile_file, _facts([replace(unknown, tests_reaching=0)])).actions- assert zero.title.startswith("Add tests around")+ assert zero.title.startswith("No test reaches")def test_an_anonymous_lead_function_is_left_out_of_the_title() -> None: