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): save the walk cache after a parallel health pass (#3389)
Raghav Chamadiyabe53f6bd86a7
diff --git a/packages/core/src/repowise/core/analysis/health/engine.py b/packages/core/src/repowise/core/analysis/health/engine.pyindex 8dc2633fa..d5fd6a408 100644--- a/packages/core/src/repowise/core/analysis/health/engine.py+++ b/packages/core/src/repowise/core/analysis/health/engine.py@@ -949,7 +949,6 @@ class HealthAnalyzer:)with timed(timings, "analysis.health.walk"):walked = self._walk_files(self._target_files(changed_set), run.vocab, on_step)- self._save_walk_cache()return self._score(run,walked,@@ -1077,6 +1076,7 @@ class HealthAnalyzer:# evaluate).if on_step:on_step(pf.file_info.path)+ self._save_walk_cache()return walkedasync def _walk_files_async(@@ -1100,7 +1100,9 @@ class HealthAnalyzer:on_step(pf.file_info.path)return pf, fcx- return list(await asyncio.gather(*[_one(pf) for pf in targets]))+ walked = list(await asyncio.gather(*[_one(pf) for pf in targets]))+ self._save_walk_cache()+ return walkeddef _score(self,diff --git a/tests/unit/health/test_walk_cache.py b/tests/unit/health/test_walk_cache.pyindex 653ce20b4..f76209bab 100644--- a/tests/unit/health/test_walk_cache.py+++ b/tests/unit/health/test_walk_cache.py@@ -11,6 +11,8 @@ from __future__ import annotationsfrom pathlib import Pathfrom types import SimpleNamespace+import pytest+from repowise.core.analysis.health.asserts.lexicon import AssertVocabularyfrom repowise.core.analysis.health.complexity import walk_filefrom repowise.core.analysis.health.engine import HEALTH_ANALYZER_VERSION, HealthAnalyzer@@ -99,7 +101,14 @@ def test_only_used_entries_are_written_back(tmp_path: Path) -> None:assert third.get(gone) is None-def test_the_analyzer_walks_once_and_serves_the_second_pass_from_the_cache(tmp_path: Path, monkeypatch) -> None:[email protected]("parallel", [False, True], ids=["analyze", "analyze_async"])+def test_the_analyzer_walks_once_and_serves_the_second_pass_from_the_cache(+ tmp_path: Path, monkeypatch, parallel: bool+) -> None:+ # Both paths persist the cache: the parallel one serves ``init`` on large+ # repos, and a walk it never saved is paid again on the next pass.+ import asyncio+import networkx as nxfrom repowise.core.analysis.health import engine as engine_mod@@ -127,8 +136,11 @@ def test_the_analyzer_walks_once_and_serves_the_second_pass_from_the_cache(tmp_prepo_root=tmp_path,)- first = analyzer().analyze(None)- second = analyzer().analyze(None)+ def run():+ return asyncio.run(analyzer().analyze_async(None)) if parallel else analyzer().analyze(None)++ first = run()+ second = run()assert len(calls) == 1assert [m.score for m in first.metrics] == [m.score for m in second.metrics]assert [(f.biomarker_type, f.function_name) for f in first.findings] == [