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(decisions): keep conventional ADR dirs ahead of loose name matches at the cap (#2586)
Raghav Chamadiyaa35094979cbe
diff --git a/packages/core/src/repowise/core/analysis/decisions/adr.py b/packages/core/src/repowise/core/analysis/decisions/adr.pyindex b7d782fea..4135b6938 100644--- a/packages/core/src/repowise/core/analysis/decisions/adr.py+++ b/packages/core/src/repowise/core/analysis/decisions/adr.py@@ -77,11 +77,16 @@ def find_adr_files(repo_path: Path) -> list[Path]:bucket = _adr_bucket(fname, in_adr_dir, conventional, loose)if bucket is None:continue+ # A full loose bucket can never reach the output, so skip it.+ if bucket is loose and len(loose) >= _MAX_ADR_FILES:+ continueif ignore.match_file(f"{rel_dir}/{fname}" if rel_dir else fname):continuebucket.append(dirpath / fname)- if len(conventional) + len(loose) >= _MAX_ADR_FILES:+ # Only a full conventional bucket ends the walk: loose matches seen+ # early must not crowd out an ADR dir the walk has not reached yet.+ if len(conventional) >= _MAX_ADR_FILES:break# No dedup pass: walk_repo yields each directory once, and each filediff --git a/tests/unit/analysis/test_decision_sources.py b/tests/unit/analysis/test_decision_sources.pyindex 3a60cba88..702012ce2 100644--- a/tests/unit/analysis/test_decision_sources.py+++ b/tests/unit/analysis/test_decision_sources.py@@ -98,6 +98,27 @@ async def test_discover_adrs_maps_superseded_status_from_frontmatter(tmp_path):+def test_conventional_adrs_win_the_cap_over_earlier_loose_matches(tmp_path, monkeypatch):+ """Loose name matches walked first must not fill the cap before an ADR dir."""+ from repowise.core.analysis.decisions import adr++ monkeypatch.setattr(adr, "_MAX_ADR_FILES", 3)+ for i in range(3):+ (tmp_path / f"adr-note-{i}.md").write_text("# note\n", encoding="utf-8")+ adr_dir = tmp_path / "docs" / "adr"+ adr_dir.mkdir(parents=True)+ for i in range(3):+ (adr_dir / f"000{i}-choice.md").write_text("# choice\n", encoding="utf-8")++ found = adr.find_adr_files(tmp_path)++ assert sorted(p.relative_to(tmp_path).as_posix() for p in found) == [+ "docs/adr/0000-choice.md",+ "docs/adr/0001-choice.md",+ "docs/adr/0002-choice.md",+ ]++class TestAdrDiscoveryHonorsIgnoreFiles:"""A path git cannot see must not become a decision record.