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(health): canonicalize legacy biomarker ids in as_biomarker_result (#4177)
Abdullah Azmieac526cfd9b9
diff --git a/packages/core/src/repowise/core/analysis/health/history_refresh.py b/packages/core/src/repowise/core/analysis/health/history_refresh.pyindex 1faa3c728..a217847b1 100644--- a/packages/core/src/repowise/core/analysis/health/history_refresh.py+++ b/packages/core/src/repowise/core/analysis/health/history_refresh.py@@ -17,6 +17,7 @@ from __future__ import annotationsfrom dataclasses import dataclassfrom typing import Any+from .biomarker_names import canonical_biomarkerfrom .biomarkers.base import BiomarkerResult, FileContextfrom .biomarkers.registry import registered_biomarkersfrom .complexity.languages import has_health_dialect@@ -83,7 +84,7 @@ def as_biomarker_result(finding: Any) -> BiomarkerResult:details = detail_map(finding)raw = details.get("deduction")return BiomarkerResult(- biomarker_type=field(finding, "biomarker_type", ""),+ biomarker_type=canonical_biomarker(field(finding, "biomarker_type", "")),severity=Severity(field(finding, "severity", Severity.LOW)),function_name=field(finding, "function_name"),line_start=field(finding, "line_start"),diff --git a/tests/unit/health/test_history_refresh.py b/tests/unit/health/test_history_refresh.pyindex 93c0cc539..ffd79b168 100644--- a/tests/unit/health/test_history_refresh.py+++ b/tests/unit/health/test_history_refresh.py@@ -161,3 +161,19 @@ def test_rebuild_reads_a_stored_row_shape() -> None:rebuilt = as_biomarker_result(_Row())assert rebuilt.deduction == 2.5assert rebuilt.reason == "half the lines uncovered"+++def test_stored_legacy_biomarker_id_refreshes_as_canonical() -> None:+ """A stored `bumpy_road` finding maps to `repeated_nesting` on replay."""+ legacy = _finding("bumpy_road", Severity.HIGH)+ canonical = _finding("repeated_nesting", Severity.HIGH)++ assert as_biomarker_result(legacy).biomarker_type == "repeated_nesting"++ (from_legacy,) = _run(git_meta={"prior_defect_count": 0}, findings=[legacy])+ (from_canonical,) = _run(git_meta={"prior_defect_count": 0}, findings=[canonical])++ assert [f.biomarker_type for f in from_legacy.findings] == ["repeated_nesting"]+ assert from_legacy.score == from_canonical.score+ assert from_legacy.defect_score == from_canonical.defect_score+ assert from_legacy.structure_deduction == from_canonical.structure_deduction