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): break the worth -> complexity -> perf import cycle (#3538)

Cestercianf23d659cf98c
diff --git a/packages/core/src/repowise/core/analysis/health/worth.py b/packages/core/src/repowise/core/analysis/health/worth.py
index c0ae95d1a..d2d2ea014 100644
--- a/packages/core/src/repowise/core/analysis/health/worth.py
+++ b/packages/core/src/repowise/core/analysis/health/worth.py
@@ -17,8 +17,6 @@ from collections import defaultdict
from collections.abc import Callable, Iterable, Mapping, Sequence
from typing import Any, Literal
-from .complexity.dispatch import DISPATCH_SHARE
-from .complexity.terminal import TERMINAL_SHARE
from .rows import detail_map, field
#: Problem-size cut points. Each is a multiple of the detector's own bar: CCN
@@ -172,12 +170,16 @@ def magnitude(shape: Mapping[str, int]) -> int:
def dispatch_shaped(shape: Mapping[str, int]) -> bool:
"""Most of the function's branching is one dispatch on one value."""
+ from .complexity.dispatch import DISPATCH_SHARE
+
return shape.get("dispatch_pct", 0) >= DISPATCH_SHARE * 100
def terminal_shaped(shape: Mapping[str, int]) -> bool:
"""The function is a print or prompt flow: a status report, a checklist,
a setup wizard, whose branches choose what to show."""
+ from .complexity.terminal import TERMINAL_SHARE
+
return shape.get("terminal_pct", 0) >= TERMINAL_SHARE * 100
diff --git a/tests/unit/health/test_worth.py b/tests/unit/health/test_worth.py
index 4710f766f..498916199 100644
--- a/tests/unit/health/test_worth.py
+++ b/tests/unit/health/test_worth.py
@@ -2,6 +2,8 @@
from __future__ import annotations
+import subprocess
+import sys
from typing import get_args
import pytest
@@ -10,6 +12,20 @@ from repowise.core.analysis.health.fix_first import build_fix_first
from repowise.core.analysis.health.worth import LOW_PRIORITY_LABEL, LowPriority, low_priority
+ "module",
+ [
+ "repowise.core.analysis.health.worth",
+ "repowise.core.analysis.health.perf.opportunities",
+ "repowise.core.analysis.health.perf.actionability",
+ "repowise.core.analysis.health.perf.opportunity_rank",
+ ],
+)
+def test_health_module_imports_cleanly_in_fresh_interpreter(module: str) -> None:
+ """Importing worth must not pull complexity before worth is initialized."""
+ subprocess.run([sys.executable, "-c", f"import {module}"], check=True)
+
+
@pytest.mark.parametrize(
("marker", "shape", "expected"),
[
diff --git a/tests/unit/health/test_worth_after_plan.py b/tests/unit/health/test_worth_after_plan.py
index e122fcf72..2684ee4a2 100644
--- a/tests/unit/health/test_worth_after_plan.py
+++ b/tests/unit/health/test_worth_after_plan.py
@@ -4,7 +4,6 @@ from __future__ import annotations
from types import SimpleNamespace
-import repowise.core.analysis.health.refactoring # noqa: F401 (import order: worth <-> perf)
from repowise.core.analysis.health.refactoring.models import RefactoringSuggestion
from repowise.core.analysis.health.refactoring.opportunity import compose_opportunities
from repowise.core.analysis.health.refactoring.opportunity_rank import rank_sort_key