Skip to content

Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.

fix(health): let a production origin keep example-named packages in Fix first (#3629)

Swati Ahuja4bf0c180d209
diff --git a/packages/core/src/repowise/core/analysis/health/queue/eligibility.py b/packages/core/src/repowise/core/analysis/health/queue/eligibility.py
index 98425980a..264423c17 100644
--- a/packages/core/src/repowise/core/analysis/health/queue/eligibility.py
+++ b/packages/core/src/repowise/core/analysis/health/queue/eligibility.py
@@ -183,13 +183,17 @@ def _path_reason(
if origin is None:
if ctx == "test":
return "test"
- if reason := ORIGIN_EXCLUSION.get(path_origin(path)):
+ origin = path_origin(path)
+ if reason := ORIGIN_EXCLUSION.get(origin):
return reason
elif ctx == "test" and _in_test_tree(path):
return "test"
- # ``unknown`` under a directory is docs, examples or demos at any depth:
- # code that may not ship. A root-level file stays eligible.
- if ctx == "tooling" or (ctx == "unknown" and "/" in path):
+ # ``unknown`` under a directory is an example, demo or docs segment at any
+ # depth. A production origin outranks it: the classifier counts such a
+ # segment only at the root or under a docs root, so ``com/example/demo/``
+ # ships. A root-level file stays eligible.
+ nested_unknown = ctx == "unknown" and "/" in path
+ if ctx == "tooling" or (nested_unknown and origin != "production"):
return "tooling"
return None
diff --git a/tests/unit/health/test_fix_first_build.py b/tests/unit/health/test_fix_first_build.py
index 4ef216239..b477676bf 100644
--- a/tests/unit/health/test_fix_first_build.py
+++ b/tests/unit/health/test_fix_first_build.py
@@ -201,6 +201,15 @@ def test_cli_code_ships_for_code_shape_but_not_for_performance() -> None:
assert [i.target.file_path for i in queue.items] == [path]
+def test_a_production_file_under_a_samples_package_is_eligible() -> None:
+ path = "src/main/java/org/springframework/samples/petclinic/owner/PetController.java"
+ row = {**METRICS[0], "file_path": path, "code_origin": "production"}
+ finding = {**FINDINGS[1], "file_path": path}
+ queue = _build(metrics=[row], findings=[finding], refactoring=[], performance=[])
+ assert queue.totals.eligible > 0
+ assert [i.target.file_path for i in queue.items] == [path]
+
+
def test_value_leads_tier_and_a_huge_function_says_so() -> None:
"""A function far past every bar outranks tidy work that is safer to start."""
huge = {**FINDINGS[1], "file_path": "src/plain.py", "function_name": "walk",
diff --git a/tests/unit/health/test_queue_eligibility.py b/tests/unit/health/test_queue_eligibility.py
index 73708b8a2..5272b4031 100644
--- a/tests/unit/health/test_queue_eligibility.py
+++ b/tests/unit/health/test_queue_eligibility.py
@@ -2,6 +2,8 @@
from __future__ import annotations
+import pytest
+
from repowise.core.analysis.health.queue.eligibility import (
ELIGIBLE,
Tally,
@@ -139,6 +141,28 @@ def test_a_stored_origin_overrules_a_test_shaped_name() -> None:
assert path_verdict("src/app.py", False, origin="test").reason == "test"
+ "path",
+ [
+ "src/main/java/com/example/demo/OrderService.java",
+ "app/src/main/java/com/example/myapp/MainActivity.kt",
+ "pkg/demo/handler.go",
+ "src/main/java/org/springframework/samples/petclinic/owner/PetController.java",
+ ],
+)
+def test_a_production_origin_outranks_an_example_segment_below_the_root(path) -> None:
+ assert path_verdict(path, False, origin="production").reason is None
+ # With no stored origin the shared classifier reads the path the same way.
+ assert path_verdict(path, None).reason is None
+
+
+def test_real_examples_and_docs_stay_out() -> None:
+ assert path_verdict("examples/foo/main.go", False, origin="docs_example").reason == (
+ "docs_example"
+ )
+ assert path_verdict("docs/x.py", None).reason == "docs_example"
+
+
def test_unit_verdict_ladder_order() -> None:
big = {"ccn": 60, "nloc": 300}
assert unit_verdict(_Shaped(big, dead=True), "a.py", "f", complexity=True).reason == (