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): stop dropping a file's same-named functions before a marker sees them (#2408)
Raghav Chamadiya04e1dc67afda
diff --git a/docs/architecture/code-health.md b/docs/architecture/code-health.mdindex b748c5eb3..b9940feeb 100644--- a/docs/architecture/code-health.md+++ b/docs/architecture/code-health.md@@ -945,7 +945,7 @@ phases may revisit; the constraints kept v1 shippable.flag.- **No symbol-level scoring.** Score lives at the file granularity tomatch how engineers think about refactor units. Symbol-level CCN- still feeds the file score via `function_metrics`.+ still feeds the file score via `all_functions`.- **No `complexity_estimate` propagation backfill.** The walker writesthe field as a side effect during the current run; old indexes don'tget touched until a re-index.diff --git a/docs/layers/LANGUAGE_SUPPORT.md b/docs/layers/LANGUAGE_SUPPORT.mdindex 4ae153b9c..3600c9426 100644--- a/docs/layers/LANGUAGE_SUPPORT.md+++ b/docs/layers/LANGUAGE_SUPPORT.md@@ -566,9 +566,11 @@ Every one of those 15 findings was the grammar rather than the test, which iswhy the marker declined `.tsx` files until now. The second corpus's one newfinding is a test that genuinely asserts nothing, hidden by that same rule.-Two calibrated markers read the same walk, and both read it through the-name-keyed `function_metrics`, which keeps one row per distinct function name-and so drops all but one of a file's anonymous `it` callbacks. That key is the+Two calibrated markers read the same walk, and at the time both read it+through the name-keyed `function_metrics`, which kept one row per distinct+function name and so dropped all but one of a file's anonymous `it` callbacks.+The section below removes that key; what follows here is the state as this+grammar fix left it. That key is thething to understand here. Recovery had been swallowing whole source spans intoeach callback's *name*, and those accidentally unique names were defeating it,so a `.tsx` file kept rows that a `.ts` file has always lost. Counting names@@ -578,19 +580,19 @@ corpus, 0 after. Measured as the share of walked functions that survive the key,`large_assertion_block` does not move on either corpus (0 and 0, then 1 and 1).Its floor is fifteen assertions in one run and React cases are short, but the-same name key drops most of the newly visible runs before that floor is ever-consulted, so the floor is not the whole reason.+same name key dropped most of the newly visible runs before that floor was+ever consulted, so the floor was not the whole reason. Removing the key turns+that marker's 0 into a 6 on the second corpus below.`duplicated_assertion_block` falls from 304 to 262 on the first corpus, and thisis a loss rather than a correction. Six of the lost findings were read by handand every one is a genuine run of consecutive assertions, correctly bounded; therows were real and the clone partner was real. What was not real is themechanism that kept them visible, which was a mangled name defeating a lossy-key. So `.tsx` files now under-report duplicated assertion blocks exactly as-`.ts` files always have. The corpus carries more real assertion runs after this+key. So at this point `.tsx` files under-reported duplicated assertion blocks+exactly as `.ts` files always had, which the next section then fixes for both. The corpus carries more real assertion runs after thischange, 264 to 391, and the marker reports fewer of them. Re-keying-`function_metrics` is the fix for that, it moves every calibrated marker at-once, and it is a change of its own.+`function_metrics` is the fix for that, and the next section is that change.Svelte and Vue stay `later` rather than following TypeScript: an SFC is walked asa TypeScript buffer, but a single-file component is essentially never a test@@ -599,6 +601,96 @@ file, so the row would be untestable rather than useful.The marker is advisory and never deducts. See[CODE_HEALTH.md](CODE_HEALTH.md).+### A marker reads the whole walked file, not one row per name++Eleven markers used to read a `function_metrics` map keyed by function name. A+map keyed that way keeps one row per distinct name, and a function name is not+unique inside a file. Every `it(...)` callback in a spec file walks under the name+`it callback`; `__init__` walks under one name on each class in a module. Every+row after the first was dropped before a marker ever saw it. They read+`all_functions` now, the whole walked list, which is what the two advisory+test-quality markers already read for this reason.++How much a file loses to that key is a property of how a language names its+functions rather than of any marker. Measured across the walked functions of+four corpora:++| Corpus | Language | Walked functions | Survive the name key |+|---|---|---|---|+| 1,336 files | TypeScript / TSX | 12,257 | 37.8% |+| 2,194 files | TypeScript / TSX | 17,261 | 72.3% |+| 1,949 files | Python | 12,926 | 91.4% |+| 1,714 files | Python | 30,747 | 87.9% |++These count every walked file, so they do not line up with the test-file-only+`.tsx` figures above and are not meant to.++A JS/TS spec suite is the worst case by a wide margin, because its test bodies+are anonymous callbacks that all walk under one name. Python loses about a tenth+of its rows, mostly same-named methods on neighbouring classes.++What each scoring marker sees, before the change and after. Note that the two+assertion-block markers score but were never fitted on a defect corpus, and they+are the two that move furthest:++| Marker | TS/TSX (1,336 files) | TS/TSX (2,194 files) | Python (1,949 files) | Python (1,714 files) |+|---|---|---|---|---|+| `complex_method` | 496 to 506 | 1,005 to 1,015 | 443 to 468 | 483 to 537 |+| `large_method` | 347 to 382 | 608 to 649 | 192 to 203 | 157 to 168 |+| `nested_complexity` | 232 to 233 | 338 to 341 | 236 to 253 | 286 to 317 |+| `bumpy_road` | 80 to 80 | 161 to 162 | 65 to 71 | 99 to 108 |+| `complex_conditional` | 92 to 96 | 163 to 168 | 67 to 69 | 91 to 101 |+| `primitive_obsession` | 54 to 54 | 106 to 107 | 685 to 859 | 449 to 599 |+| `large_assertion_block` | 0 to 0 | 0 to 6 | 0 to 0 | 11 to 11 |+| `duplicated_assertion_block` | 262 to 2,831 | 175 to 1,711 | 1,098 to 1,108 | 2,360 to 2,477 |++Three markers are missing from that table because they need inputs this+measurement does not build: `brain_method` needs graph centrality, and+`code_age_volatility` and `function_hotspot` need git blame. They read the same+list as the other eight, which is visible in the diff, but how far they move was+not observed.++Most of those cells are single-digit percentages. `complex_method`,+`large_method`, `nested_complexity` and `complex_conditional` each clear ten+percent on one corpus and stay below it on the other three. Two markers move+much further, and they are the two worth reading carefully.++`primitive_obsession` gains a quarter to a third of its findings on both Python+corpora, 685 to 859 and 449 to 599, and almost nothing on either JS/TS one.+Python modules define the same method name on several classes each, and the+row that survived the key was the first of them in the file, so a wide signature+on any of the others was invisible.++`duplicated_assertion_block` is the large one: it rises about tenfold on both+JS/TS corpora and barely moves on either Python one. That is the same fact as+the survival table, seen from the other end.++Six of the gained rows were read in the source, and each of those six is a+correctly bounded run of consecutive assertions. Six labels cannot speak for+2,569 rows, so that is evidence the marker is bounding blocks correctly, not a+precision figure. What does speak for the population is its shape. On the first+corpus the two arms' assertion-run-length histograms have closely matching+profiles while the new arm is about eleven times larger, which is what uniform+thinning looks like and not what a filter that selected for anything would look+like. On that same corpus the marker goes from a median of one finding per test+file to five, with one file at sixty. Neither measurement says whether a gained+row is worth showing a reader; only counts and block lengths were measured.++No floor was added to hold that number down. The name key was an accidental+limiter and replacing it with a deliberate one is a calibration change, which+needs its own defect-corpus evidence rather than a number that looks+comfortable. What bounds the damage today is the `test_quality` category cap of+0.5, which a single medium finding already exceeds: a test file with sixty of+these loses the same half point as a test file with one, so the scores move far+less than the counts do. Whether the finding list itself wants a cap is a+question for the marker, not for the container it reads.++The six findings `large_assertion_block` gains on the second JS/TS corpus were+also read by hand. All six are runs of fifteen or more consecutive assertions in+a single test, which is exactly what that marker declares it looks for, and all+six are anonymous callbacks, so each sat in a file where another function of the+same name had been holding the only row.+Per-marker mechanics, every per-language precision ceiling and the reasoningbehind each `n/a`: [CODE_HEALTH.md](CODE_HEALTH.md) and[architecture/language-support.md](../architecture/language-support.md).diff --git a/packages/core/src/repowise/core/analysis/health/biomarkers/README.md b/packages/core/src/repowise/core/analysis/health/biomarkers/README.mdindex c2f98cd61..ab895300e 100644--- a/packages/core/src/repowise/core/analysis/health/biomarkers/README.md+++ b/packages/core/src/repowise/core/analysis/health/biomarkers/README.md@@ -108,7 +108,10 @@ table alone would allow.`FileContext` (see `base.py`) carries:- `file_path`, `language`, `nloc`, `module`, `has_test_file`.-- `function_metrics` — `dict[symbol_name → FunctionComplexity]`.+- `all_functions` — `tuple[FunctionComplexity, ...]`, every walked+ function in document order. Not keyed by name: a name key drops a+ file's anonymous `it` callbacks and same-named methods on a second+ class. Empty for SQL.- `class_metrics` — `list[ClassComplexity]` (LCOM4, method count, size).Empty for languages whose walker map doesn't opt into class analysis.- `git_meta` — per-file git metadata (commits, owners, bus factor,diff --git a/packages/core/src/repowise/core/analysis/health/biomarkers/assertion_free_test.py b/packages/core/src/repowise/core/analysis/health/biomarkers/assertion_free_test.pyindex 075276b06..f14294838 100644--- a/packages/core/src/repowise/core/analysis/health/biomarkers/assertion_free_test.py+++ b/packages/core/src/repowise/core/analysis/health/biomarkers/assertion_free_test.py@@ -52,8 +52,6 @@ class AssertionFreeTestDetector:if not is_test_file(ctx.file_path):return []out: list[BiomarkerResult] = []- # ``all_functions``, not ``function_metrics``: name-keying collapses a- # file's anonymous ``it`` callbacks into one row. See ``FileContext``.oracles = _asserting_names(ctx)for fn in ctx.all_functions:# ``is_test_case`` is the whole gate. Every other test-qualitydiff --git a/packages/core/src/repowise/core/analysis/health/biomarkers/base.py b/packages/core/src/repowise/core/analysis/health/biomarkers/base.pyindex b8a56fee0..e49595d0b 100644--- a/packages/core/src/repowise/core/analysis/health/biomarkers/base.py+++ b/packages/core/src/repowise/core/analysis/health/biomarkers/base.py@@ -26,14 +26,12 @@ class FileContext:nloc: inthas_test_file: boolmodule: str | None- # Map symbol-name → complexity metrics for functions/methods in this- # file. Symbols without a complexity row default to CCN=1, nesting=0.- function_metrics: dict[str, FunctionComplexity] = field(default_factory=dict)- # Every walked function, in document order and NOT keyed by name, because- # name-keying drops all but one of a file's anonymous ``it`` callbacks.- # Read by the advisory test-quality markers only: re-keying- # ``function_metrics`` is the real fix and would change what every- # calibrated marker sees, so it needs its own defect-corpus evidence.+ # Every walked function in this file, in document order. Not keyed by+ # name: a name key drops all but one of a file's anonymous ``it``+ # callbacks, and every same-named method on a second class beside it.+ # This replaced the name-keyed ``function_metrics`` map every marker used+ # to read. Empty for SQL, whose routine metrics are text-counted and+ # defect-uncalibrated.all_functions: tuple[FunctionComplexity, ...] = ()# Per-class aggregate metrics (LCOM4, method count, size). Empty for# languages whose walker map doesn't opt into class-level analysisdiff --git a/packages/core/src/repowise/core/analysis/health/biomarkers/brain_method.py b/packages/core/src/repowise/core/analysis/health/biomarkers/brain_method.pyindex 131a9ae39..50dbd846f 100644--- a/packages/core/src/repowise/core/analysis/health/biomarkers/brain_method.py+++ b/packages/core/src/repowise/core/analysis/health/biomarkers/brain_method.py@@ -55,7 +55,7 @@ class BrainMethodDetector:return []out: list[BiomarkerResult] = []- for fn in ctx.function_metrics.values():+ for fn in ctx.all_functions:if fn.nloc < self._NLOC_THRESHOLD:continueif fn.ccn < self._CCN_THRESHOLD:diff --git a/packages/core/src/repowise/core/analysis/health/biomarkers/bumpy_road.py b/packages/core/src/repowise/core/analysis/health/biomarkers/bumpy_road.pyindex fd2c8c048..fc2d0614d 100644--- a/packages/core/src/repowise/core/analysis/health/biomarkers/bumpy_road.py+++ b/packages/core/src/repowise/core/analysis/health/biomarkers/bumpy_road.py@@ -25,7 +25,7 @@ class BumpyRoadDetector:def detect(self, ctx: FileContext) -> list[BiomarkerResult]:out: list[BiomarkerResult] = []- for fn in ctx.function_metrics.values():+ for fn in ctx.all_functions:if fn.bumps < self._BUMP_THRESHOLD:continueif fn.ccn < self._CCN_THRESHOLD:diff --git a/packages/core/src/repowise/core/analysis/health/biomarkers/code_age_volatility.py b/packages/core/src/repowise/core/analysis/health/biomarkers/code_age_volatility.pyindex 545a185ef..95b5ac58c 100644--- a/packages/core/src/repowise/core/analysis/health/biomarkers/code_age_volatility.py+++ b/packages/core/src/repowise/core/analysis/health/biomarkers/code_age_volatility.py@@ -66,7 +66,7 @@ class CodeAgeVolatilityDetector:since = now - _RECENT_WINDOW_SECSfindings: list[BiomarkerResult] = []- for fn_name, fc in ctx.function_metrics.items():+ for fc in ctx.all_functions:median_ts = median_author_time_in_range(idx, fc.start_line, fc.end_line)if median_ts is None:continue@@ -82,7 +82,7 @@ class CodeAgeVolatilityDetector:BiomarkerResult(biomarker_type=self.name,severity=_severity_for(median_age_days, recent_mod),- function_name=fn_name,+ function_name=fc.name,line_start=fc.start_line,line_end=fc.end_line,details={@@ -90,7 +90,7 @@ class CodeAgeVolatilityDetector:"recent_mod_count": int(recent_mod),},reason=(- f"{fn_name} has a median line age of "+ f"{fc.name} has a median line age of "f"{int(median_age_days)} days but has been "f"modified by {recent_mod} commits in the last 30 days"),diff --git a/packages/core/src/repowise/core/analysis/health/biomarkers/complex_conditional.py b/packages/core/src/repowise/core/analysis/health/biomarkers/complex_conditional.pyindex 7a2eab9bd..1c92c8226 100644--- a/packages/core/src/repowise/core/analysis/health/biomarkers/complex_conditional.py+++ b/packages/core/src/repowise/core/analysis/health/biomarkers/complex_conditional.py@@ -40,7 +40,7 @@ class ComplexConditionalDetector:def detect(self, ctx: FileContext) -> list[BiomarkerResult]:out: list[BiomarkerResult] = []- for fn_name, fc in ctx.function_metrics.items():+ for fc in ctx.all_functions:for cond in fc.complex_conditions or []:if cond.operator_count < _LOW:continue@@ -48,7 +48,7 @@ class ComplexConditionalDetector:BiomarkerResult(biomarker_type=self.name,severity=_severity_for(cond.operator_count),- function_name=fn_name,+ function_name=fc.name,line_start=cond.line,line_end=cond.line,details={diff --git a/packages/core/src/repowise/core/analysis/health/biomarkers/complex_method.py b/packages/core/src/repowise/core/analysis/health/biomarkers/complex_method.pyindex 0b81782c7..920103d7b 100644--- a/packages/core/src/repowise/core/analysis/health/biomarkers/complex_method.py+++ b/packages/core/src/repowise/core/analysis/health/biomarkers/complex_method.py@@ -18,7 +18,7 @@ class ComplexMethodDetector:def detect(self, ctx: FileContext) -> list[BiomarkerResult]:out: list[BiomarkerResult] = []- for fn in ctx.function_metrics.values():+ for fn in ctx.all_functions:if fn.ccn < self._CCN_THRESHOLD:continueseverity = (diff --git a/packages/core/src/repowise/core/analysis/health/biomarkers/duplicated_assertion_block.py b/packages/core/src/repowise/core/analysis/health/biomarkers/duplicated_assertion_block.pyindex b5e01ace3..8c7a8e949 100644--- a/packages/core/src/repowise/core/analysis/health/biomarkers/duplicated_assertion_block.py+++ b/packages/core/src/repowise/core/analysis/health/biomarkers/duplicated_assertion_block.py@@ -31,7 +31,7 @@ class DuplicatedAssertionBlockDetector:return []blocks = [(start, end)- for fn in ctx.function_metrics.values()+ for fn in ctx.all_functionsfor start, end, _count in fn.assertion_blocks]if not blocks:diff --git a/packages/core/src/repowise/core/analysis/health/biomarkers/function_hotspot.py b/packages/core/src/repowise/core/analysis/health/biomarkers/function_hotspot.pyindex ffc338a4d..b82c06619 100644--- a/packages/core/src/repowise/core/analysis/health/biomarkers/function_hotspot.py+++ b/packages/core/src/repowise/core/analysis/health/biomarkers/function_hotspot.py@@ -61,7 +61,7 @@ class FunctionHotspotDetector:return []findings: list[BiomarkerResult] = []- for fn_name, fc in ctx.function_metrics.items():+ for fc in ctx.all_functions:mod_count = len(distinct_commits_in_range(idx, fc.start_line, fc.end_line))if mod_count < p80:continue@@ -72,7 +72,7 @@ class FunctionHotspotDetector:BiomarkerResult(biomarker_type=self.name,severity=severity,- function_name=fn_name,+ function_name=fc.name,line_start=fc.start_line,line_end=fc.end_line,details={@@ -82,7 +82,7 @@ class FunctionHotspotDetector:"max_nesting": fc.max_nesting,},reason=(- f"{fn_name} has been modified across {mod_count} "+ f"{fc.name} has been modified across {mod_count} "f"commits (repo p80={p80}) and carries CCN={fc.ccn} / "f"nesting={fc.max_nesting}"),diff --git a/packages/core/src/repowise/core/analysis/health/biomarkers/large_assertion_block.py b/packages/core/src/repowise/core/analysis/health/biomarkers/large_assertion_block.pyindex e2d202525..11ca2057c 100644--- a/packages/core/src/repowise/core/analysis/health/biomarkers/large_assertion_block.py+++ b/packages/core/src/repowise/core/analysis/health/biomarkers/large_assertion_block.py@@ -28,7 +28,7 @@ class LargeAssertionBlockDetector:if not is_test_file(ctx.file_path):return []out: list[BiomarkerResult] = []- for fn in ctx.function_metrics.values():+ for fn in ctx.all_functions:for start, end, count in fn.assertion_blocks:if count < self._MIN_COUNT:continuediff --git a/packages/core/src/repowise/core/analysis/health/biomarkers/large_method.py b/packages/core/src/repowise/core/analysis/health/biomarkers/large_method.pyindex 6f3e6d1ca..6a09a6260 100644--- a/packages/core/src/repowise/core/analysis/health/biomarkers/large_method.py+++ b/packages/core/src/repowise/core/analysis/health/biomarkers/large_method.py@@ -35,7 +35,7 @@ class LargeMethodDetector:def detect(self, ctx: FileContext) -> list[BiomarkerResult]:out: list[BiomarkerResult] = []- for fn in ctx.function_metrics.values():+ for fn in ctx.all_functions:if fn.nloc < self._NLOC_THRESHOLD or fn.ccn < self._CCN_FLOOR:continueseverity = (diff --git a/packages/core/src/repowise/core/analysis/health/biomarkers/mock_saturated_test.py b/packages/core/src/repowise/core/analysis/health/biomarkers/mock_saturated_test.pyindex 35727a6ab..e2f5158be 100644--- a/packages/core/src/repowise/core/analysis/health/biomarkers/mock_saturated_test.py+++ b/packages/core/src/repowise/core/analysis/health/biomarkers/mock_saturated_test.py@@ -47,8 +47,6 @@ class MockSaturatedTestDetector:return []prefixes = _name_prefixes(ctx.language)out: list[BiomarkerResult] = []- # ``all_functions``, not ``function_metrics``: name-keying collapses a- # file's anonymous ``it`` callbacks into one row. See ``FileContext``.for fn in ctx.all_functions:mocks = fn.mock_setup_countasserts = fn.assertion_countdiff --git a/packages/core/src/repowise/core/analysis/health/biomarkers/nested_complexity.py b/packages/core/src/repowise/core/analysis/health/biomarkers/nested_complexity.pyindex 23b3e1a53..c37b1a000 100644--- a/packages/core/src/repowise/core/analysis/health/biomarkers/nested_complexity.py+++ b/packages/core/src/repowise/core/analysis/health/biomarkers/nested_complexity.py@@ -18,7 +18,7 @@ class NestedComplexityDetector:def detect(self, ctx: FileContext) -> list[BiomarkerResult]:out: list[BiomarkerResult] = []- for fn in ctx.function_metrics.values():+ for fn in ctx.all_functions:if fn.max_nesting < self._NESTING_THRESHOLD:continueseverity = (diff --git a/packages/core/src/repowise/core/analysis/health/biomarkers/primitive_obsession.py b/packages/core/src/repowise/core/analysis/health/biomarkers/primitive_obsession.pyindex 5dcc28c8c..5cfc1aa58 100644--- a/packages/core/src/repowise/core/analysis/health/biomarkers/primitive_obsession.py+++ b/packages/core/src/repowise/core/analysis/health/biomarkers/primitive_obsession.py@@ -41,7 +41,7 @@ class PrimitiveObsessionDetector:if ctx.nloc < _MIN_FILE_NLOC:return []out: list[BiomarkerResult] = []- for fn in ctx.function_metrics.values():+ for fn in ctx.all_functions:threshold = _PARAM_THRESHOLDif fn.name in _CTOR_NAMES:threshold += _CTOR_GRACEdiff --git a/packages/core/src/repowise/core/analysis/health/engine.py b/packages/core/src/repowise/core/analysis/health/engine.pyindex 5f9529b57..1018a529f 100644--- a/packages/core/src/repowise/core/analysis/health/engine.py+++ b/packages/core/src/repowise/core/analysis/health/engine.py@@ -100,7 +100,16 @@ log = structlog.get_logger(__name__)# Not a licence to move a calibrated scoring weight — those are frozen# independently of this stamp.#-# Current stamp: the walker records one new ``FunctionComplexity`` field,+# Current stamp: every marker now reads ``FileContext.all_functions``, the full+# walked list, where eleven of them used to read a ``function_metrics`` map keyed+# by function name. That key kept one row per distinct name, so a file's anonymous+# ``it`` callbacks collapsed into one and a method shadowed its same-named+# neighbour on another class. What moves is how much of that walk each marker+# sees, on every scoring marker at once, which makes persisted rows wrong. The+# walk itself is unchanged, but this stamp keys the walk and duplication-token+# caches, so bumping it re-walks and re-tokenizes anyway.+#+# v17: the walker records one new ``FunctionComplexity`` field,# ``called_names``, which a cached v16 walk does not carry at all. It feeds the# advisory ``assertion_free_test``, which no longer calls a test assertion-free# when it handed its checks to a function in the same file that asserts. It@@ -162,7 +171,28 @@ log = structlog.get_logger(__name__)# forms. Files that were counted untested and are not become tested, which# moves untested-hotspot findings and the scores that carry them, on every# language with a prefix or spec convention rather than Ruby alone.-HEALTH_ANALYZER_VERSION = 17+HEALTH_ANALYZER_VERSION = 18+++def walked_functions(+ fc_list: list[FunctionComplexity], language: str+) -> tuple[FunctionComplexity, ...]:+ """The functions a file's biomarkers see, in document order.++ Sorted because the walker collects sibling nodes off a LIFO stack and so+ returns them last-first, and a marker should report a file top-down. Two+ rows can share a span (a one-line callback and its enclosing call), and a+ stable sort leaves those in walk order.++ SQL routine metrics are text-counted and defect-uncalibrated; they exist+ for symbol stamping and the ``sql_high_complexity`` marker+ (maintainability). Holding them back here keeps the calibrated method+ biomarkers (defect dimension) from firing on SQL.+ """+ if language == "sql":+ return ()+ return tuple(sorted(fc_list, key=lambda fc: (fc.start_line, fc.end_line)))+# Method-level smells that make the dataflow / Extract Method pass worthwhile.# Only files carrying one of these get a CFG + def/use + reaching pass built.@@ -1082,14 +1112,7 @@ class HealthAnalyzer:file_path = pf.file_info.pathfc_list = fcx.functions- # SQL routine metrics are text-counted and defect-uncalibrated; they- # exist for symbol stamping and the sql_high_complexity marker- # (maintainability). Keeping them out of function_metrics keeps the- # calibrated method biomarkers (defect dimension) from firing on SQL.- fns: tuple[FunctionComplexity, ...] = (- () if pf.file_info.language == "sql" else tuple(fc_list)- )- fn_metrics: dict[str, FunctionComplexity] = {fc.name: fc for fc in fns}+ fns = walked_functions(fc_list, pf.file_info.language)max_ccn = max((fc.ccn for fc in fc_list), default=1)max_nesting = max((fc.max_nesting for fc in fc_list), default=0)nloc = fcx.file_nloc@@ -1140,7 +1163,6 @@ class HealthAnalyzer:# answered, or that one of them over-claims.reached_by_tests=file_path in self._files_reached_by_tests(),module=module,- function_metrics=fn_metrics,all_functions=fns,class_metrics=fcx.classes,git_meta=file_git_meta,diff --git a/tests/unit/health/test_assertion_free_test.py b/tests/unit/health/test_assertion_free_test.pyindex c4715aef4..a975b91dd 100644--- a/tests/unit/health/test_assertion_free_test.py+++ b/tests/unit/health/test_assertion_free_test.py@@ -36,7 +36,6 @@ def _detect(source: str, path: str = "tests/test_sample.py", language: str = "pynloc=fc.file_nloc,has_test_file=True,module=None,- function_metrics={f.name: f for f in fc.functions},all_functions=tuple(fc.functions),)return BIOMARKER.detect(ctx)diff --git a/tests/unit/health/test_biomarkers.py b/tests/unit/health/test_biomarkers.pyindex 675800121..25bfc8f95 100644--- a/tests/unit/health/test_biomarkers.py+++ b/tests/unit/health/test_biomarkers.py@@ -20,7 +20,7 @@ def _ctx(nloc=sum(f.nloc for f in fns),has_test_file=False,module=None,- function_metrics={f.name: f for f in fns},+ all_functions=tuple(fns),git_meta={},dependents_count=dependents,repo_dependents_p80=repo_dependents_p80,diff --git a/tests/unit/health/test_code_age_volatility.py b/tests/unit/health/test_code_age_volatility.pyindex 2cdd3b226..0d82623ac 100644--- a/tests/unit/health/test_code_age_volatility.py+++ b/tests/unit/health/test_code_age_volatility.py@@ -34,7 +34,7 @@ def _ctx(fc: FunctionComplexity, blame: BlameIndex | None) -> FileContext:nloc=10,has_test_file=False,module=None,- function_metrics={fc.name: fc},+ all_functions=(fc,),blame_index=blame,)diff --git a/tests/unit/health/test_complex_conditional.py b/tests/unit/health/test_complex_conditional.pyindex 2b3353f93..23b75d409 100644--- a/tests/unit/health/test_complex_conditional.py+++ b/tests/unit/health/test_complex_conditional.py@@ -33,7 +33,7 @@ def _ctx(metrics):nloc=10,has_test_file=False,module=None,- function_metrics={fc.name: fc for fc in metrics},+ all_functions=tuple(metrics),)diff --git a/tests/unit/health/test_dry_violation.py b/tests/unit/health/test_dry_violation.pyindex 81309219b..ede1e47d1 100644--- a/tests/unit/health/test_dry_violation.py+++ b/tests/unit/health/test_dry_violation.py@@ -14,7 +14,6 @@ def _ctx(file_path: str, pairs: list[ClonePair], dup_pct: float | None) -> FileCnloc=200,has_test_file=False,module=None,- function_metrics={},git_meta={},dependents_count=0,pagerank_score=0.0,diff --git a/tests/unit/health/test_ff_mcp_payload_churn.py b/tests/unit/health/test_ff_mcp_payload_churn.pyindex 2b03c8261..260df271d 100644--- a/tests/unit/health/test_ff_mcp_payload_churn.py+++ b/tests/unit/health/test_ff_mcp_payload_churn.py@@ -18,7 +18,6 @@ def _ctx(meta: dict, *, nloc: int = 120) -> FileContext:nloc=nloc,has_test_file=False,module=None,- function_metrics={},git_meta=meta,dependents_count=4,pagerank_score=0.0,diff --git a/tests/unit/health/test_ff_track_iljk_structural.py b/tests/unit/health/test_ff_track_iljk_structural.pyindex 9508deb83..e9ccd82d7 100644--- a/tests/unit/health/test_ff_track_iljk_structural.py+++ b/tests/unit/health/test_ff_track_iljk_structural.py@@ -95,7 +95,7 @@ def _fn_ctx(functions) -> FileContext:nloc=200,has_test_file=False,module=None,- function_metrics={f.name: f for f in functions},+ all_functions=tuple(functions),)@@ -209,7 +209,6 @@ def test_detector_caps_small_sample_pair_at_medium():nloc=120,has_test_file=False,module=None,- function_metrics={},git_meta={"commit_count_total": 5,"co_change_partners_json": json.dumps(diff --git a/tests/unit/health/test_function_hotspot.py b/tests/unit/health/test_function_hotspot.pyindex f2c0e7749..5cef8d496 100644--- a/tests/unit/health/test_function_hotspot.py+++ b/tests/unit/health/test_function_hotspot.py@@ -56,7 +56,7 @@ def _ctx(nloc=20,has_test_file=False,module=None,- function_metrics={fc.name: fc},+ all_functions=(fc,),blame_index=blame,repo_function_mod_p80=p80,)diff --git a/tests/unit/health/test_hidden_coupling.py b/tests/unit/health/test_hidden_coupling.pyindex a36edd5cf..af0f6df3d 100644--- a/tests/unit/health/test_hidden_coupling.py+++ b/tests/unit/health/test_hidden_coupling.py@@ -52,7 +52,6 @@ def _ctx(nloc=120,has_test_file=False,module=None,- function_metrics={},git_meta={"commit_count_total": self_commits,"co_change_partners_json": _partners(@@ -130,7 +129,6 @@ def test_unlabelled_partner_is_not_a_finding():nloc=120,has_test_file=False,module=None,- function_metrics={},git_meta={"commit_count_total": 20,"co_change_partners_json": json.dumps(@@ -178,7 +176,6 @@ def test_essential_tier_empty_partners_short_circuits():nloc=120,has_test_file=False,module=None,- function_metrics={},git_meta={"commit_count_total": 100, "co_change_partners_json": "[]"},dependents_count=0,)diff --git a/tests/unit/health/test_mock_saturated_test.py b/tests/unit/health/test_mock_saturated_test.pyindex a3f3813b5..e4c5ef751 100644--- a/tests/unit/health/test_mock_saturated_test.py+++ b/tests/unit/health/test_mock_saturated_test.py@@ -52,7 +52,6 @@ def _detect(source: str, path: str = "tests/test_sample.py", language: str = "pynloc=fc.file_nloc,has_test_file=True,module=None,- function_metrics={f.name: f for f in fc.functions},all_functions=tuple(fc.functions),)return BIOMARKER.detect(ctx)diff --git a/tests/unit/health/test_model_version_coupling.py b/tests/unit/health/test_model_version_coupling.pyindex 6d1a6325f..776c98b0b 100644--- a/tests/unit/health/test_model_version_coupling.py+++ b/tests/unit/health/test_model_version_coupling.py@@ -22,7 +22,7 @@ from repowise.core.analysis.health.refactoring.identity import (# The three stamps as they stand together. Moving either identity model means# moving the analyzer with it, and updating this tuple in the same commit.-_STAMPS = (17, 2, 2)+_STAMPS = (18, 2, 2)def test_the_identity_models_and_the_analyzer_stamp_are_pinned_together() -> None:diff --git a/tests/unit/health/test_organizational_biomarkers.py b/tests/unit/health/test_organizational_biomarkers.pyindex b53f115d3..9ca22030c 100644--- a/tests/unit/health/test_organizational_biomarkers.py+++ b/tests/unit/health/test_organizational_biomarkers.py@@ -38,7 +38,6 @@ def _ctx(meta: dict, *, active_contributors: int | None = None) -> FileContext:nloc=120,has_test_file=False,module=None,- function_metrics={},git_meta=meta,dependents_count=4,pagerank_score=0.0,diff --git a/tests/unit/health/test_structural_biomarkers.py b/tests/unit/health/test_structural_biomarkers.pyindex d127c29ac..3fe333e7a 100644--- a/tests/unit/health/test_structural_biomarkers.py+++ b/tests/unit/health/test_structural_biomarkers.py@@ -18,7 +18,7 @@ def _ctx(fns: list[FunctionComplexity]) -> FileContext:nloc=sum(f.nloc for f in fns),has_test_file=False,module=None,- function_metrics={f.name: f for f in fns},+ all_functions=tuple(fns),git_meta={},dependents_count=0,pagerank_score=0.0,diff --git a/tests/unit/health/test_test_quality_biomarkers.py b/tests/unit/health/test_test_quality_biomarkers.pyindex ef85c21d4..14ebabcac 100644--- a/tests/unit/health/test_test_quality_biomarkers.py+++ b/tests/unit/health/test_test_quality_biomarkers.py@@ -16,8 +16,9 @@ from repowise.core.analysis.health.biomarkers.large_assertion_block import (LargeAssertionBlockDetector,)from repowise.core.analysis.health.biomarkers.large_method import LargeMethodDetector-from repowise.core.analysis.health.complexity import FunctionComplexity+from repowise.core.analysis.health.complexity import FunctionComplexity, walk_filefrom repowise.core.analysis.health.duplication import ClonePair+from repowise.core.analysis.health.engine import walked_functionsfrom repowise.core.analysis.health.models import Severity@@ -52,7 +53,7 @@ def _ctx(nloc=200,has_test_file=False,module=None,- function_metrics={fn.name: fn for fn in functions},+ all_functions=tuple(functions),clones=clones or [],)@@ -156,3 +157,68 @@ def test_large_method_fires_with_real_branching():out = LargeMethodDetector().detect(_ctx(file_path="src/x.py", functions=[branchy]))assert len(out) == 1assert out[0].details["nloc"] == 150+++# ---- the name key the markers used to read through ------------------------+++def test_two_callbacks_sharing_a_name_are_both_seen():+ """A spec file's ``it`` callbacks all walk under one name.++ The markers used to read a map keyed by that name, which kept one row+ per distinct name. They read the walked list now, so both are reported.+ """+ asserts = "\n".join(f"\t\texpect(v).toBe({i})" for i in range(18))+ source = (+ "describe('s', () => {\n"+ f"\tit('a', () => {{\n{asserts}\n\t}})\n"+ f"\tit('b', () => {{\n{asserts}\n\t}})\n"+ "})\n"+ ).encode()++ walked = walk_file("thing.spec.ts", "typescript", source).functions+ callbacks = [fn for fn in walked if fn.assertion_blocks]+ assert len(callbacks) == 2+ # The premise: one name, two functions. Without it this test proves nothing.+ assert len({fn.name for fn in callbacks}) == 1++ out = LargeAssertionBlockDetector().detect(+ _ctx(+ file_path="src/__tests__/thing.spec.ts",+ functions=list(walked_functions(walked, "typescript")),+ )+ )+ assert len(out) == 2+++def test_a_python_method_shadowed_by_its_namesake_is_seen():+ """Two classes in one module, each with a ``run``.++ The name key kept the first and dropped the second, which is most of what+ it cost Python.+ """+ source = (+ b"class A:\n"+ b" def run(self):\n"+ b" assert 1\n"+ b"class B:\n"+ b" def run(self):\n"+ b" assert 2\n"+ )+ walked = walk_file("test_m.py", "python", source).functions+ assert [fn.name for fn in walked] == ["run", "run"]++ seen = walked_functions(walked, "python")+ assert [fn.start_line for fn in seen] == [2, 5]+++def test_the_walked_list_is_document_order_and_empty_for_sql():+ """The walker returns siblings last-first; markers report top-down."""+ source = b"def a():\n pass\ndef b():\n pass\ndef c():\n pass\n"+ walked = walk_file("m.py", "python", source).functions+ # The premise: unsorted, the walker hands these back reversed.+ assert [fn.start_line for fn in walked] == [5, 3, 1]++ assert [fn.start_line for fn in walked_functions(walked, "python")] == [1, 3, 5]+ # SQL routines are text-counted; they never reach a method biomarker.+ assert walked_functions(walked, "sql") == ()