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): give findings stored under a renamed marker id their advice (#4305)

Raghav Chamadiyabebd21532cca
diff --git a/packages/core/src/repowise/core/analysis/health/suggestions.py b/packages/core/src/repowise/core/analysis/health/suggestions.py
index 9abac6b9c..8ff85cd8d 100644
--- a/packages/core/src/repowise/core/analysis/health/suggestions.py
+++ b/packages/core/src/repowise/core/analysis/health/suggestions.py
@@ -18,6 +18,8 @@ from __future__ import annotations
from typing import Any
+from .biomarker_names import canonical_biomarker
+
_TEMPLATES: dict[str, str] = {
"brain_method": (
"Split this function. It carries high cyclomatic complexity and "
@@ -315,11 +317,12 @@ _TEMPLATES: dict[str, str] = {
def suggestion_for(biomarker_type: str) -> str:
"""Return the canonical refactoring suggestion for a biomarker.
- Unknown biomarker names fall back to a generic prompt — keeps the
- field non-null on every finding so the UI can rely on it.
+ A renamed marker's old id reads its current template, so stored findings
+ keep their advice. Unknown biomarker names fall back to a generic prompt —
+ keeps the field non-null on every finding so the UI can rely on it.
"""
return _TEMPLATES.get(
- biomarker_type,
+ canonical_biomarker(biomarker_type),
"Review this finding and decide whether the underlying smell is "
"worth refactoring or suppressing via `.repowise/health-rules.json`.",
)
diff --git a/packages/ui/__tests__/health/biomarker-glossary.test.ts b/packages/ui/__tests__/health/biomarker-glossary.test.ts
index cf29efeea..84b2f1836 100644
--- a/packages/ui/__tests__/health/biomarker-glossary.test.ts
+++ b/packages/ui/__tests__/health/biomarker-glossary.test.ts
@@ -13,10 +13,23 @@
*/
import { describe, expect, it } from "vitest";
-import { CATEGORY_CAP } from "../../src/health/biomarker-glossary.js";
+import { CATEGORY_CAP, biomarkerLabel, isKnownBiomarker } from "../../src/health/biomarker-glossary.js";
describe("CATEGORY_CAP parity", () => {
it("pins the performance cap to scoring.py's _PERFORMANCE_CATEGORY_CAPS", () => {
expect(CATEGORY_CAP.performance).toBe(2.0);
});
});
+
+describe("isKnownBiomarker", () => {
+ it("knows current ids and a renamed marker's old id", () => {
+ expect(isKnownBiomarker("repeated_nesting")).toBe(true);
+ expect(isKnownBiomarker("bumpy_road")).toBe(true);
+ expect(biomarkerLabel("bumpy_road")).toBe(biomarkerLabel("repeated_nesting"));
+ });
+
+ it("rejects ids the glossary does not describe", () => {
+ expect(isKnownBiomarker("not_a_marker")).toBe(false);
+ expect(isKnownBiomarker("constructor")).toBe(false);
+ });
+});
diff --git a/packages/ui/src/health/biomarker-glossary.ts b/packages/ui/src/health/biomarker-glossary.ts
index 182c0b27f..6ae00a842 100644
--- a/packages/ui/src/health/biomarker-glossary.ts
+++ b/packages/ui/src/health/biomarker-glossary.ts
@@ -374,6 +374,11 @@ export function biomarkerInfo(name: string): BiomarkerInfo {
);
}
+/** Whether the glossary describes *name*, a renamed marker's old id included. */
+export function isKnownBiomarker(name: string): boolean {
+ return Object.hasOwn(BIOMARKER_GLOSSARY, canonicalBiomarker(name));
+}
+
export function biomarkerLabel(name: string): string {
return biomarkerInfo(name).label;
}
diff --git a/tests/unit/health/test_suggestions.py b/tests/unit/health/test_suggestions.py
index 157f93d97..67ceaaf71 100644
--- a/tests/unit/health/test_suggestions.py
+++ b/tests/unit/health/test_suggestions.py
@@ -19,6 +19,11 @@ def test_suggestion_unknown_biomarker_falls_back():
assert "health-rules.json" in text # fallback hints at suppression
+def test_suggestion_for_a_renamed_marker_reads_its_current_template():
+ assert suggestion_for("bumpy_road") == suggestion_for("repeated_nesting")
+ assert "health-rules.json" not in suggestion_for("bumpy_road")
+
+
def test_every_registered_biomarker_has_its_own_action():
# The Findings tab shows this sentence as each row's action line, so a
# marker without one would fall back to the generic "review this" text.