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(overview): read community_info() as a dict so the clusters section renders (#4463)

uzumakienes4adaed7dc631
diff --git a/packages/core/src/repowise/core/generation/context/assembler.py b/packages/core/src/repowise/core/generation/context/assembler.py
index a2f389de3..5483ff762 100644
--- a/packages/core/src/repowise/core/generation/context/assembler.py
+++ b/packages/core/src/repowise/core/generation/context/assembler.py
@@ -874,13 +874,14 @@ class ContextAssembler:
execution_flows_list: list[dict] = []
if graph_builder is not None:
try:
- for ci in graph_builder.community_info():
+ # ``community_info()`` maps community id to ``CommunityInfo``.
+ for info in graph_builder.community_info().values():
communities_list.append(
{
- "id": ci.id,
- "label": ci.label,
- "size": ci.size,
- "cohesion": round(ci.cohesion, 2),
+ "id": info.community_id,
+ "label": info.label,
+ "size": info.size,
+ "cohesion": round(info.cohesion, 2),
}
)
# Id, not label: two same-size communities can carry the same
diff --git a/tests/unit/generation/test_overview_execution_flows.py b/tests/unit/generation/test_overview_execution_flows.py
index 71d9ca327..324ffec1f 100644
--- a/tests/unit/generation/test_overview_execution_flows.py
+++ b/tests/unit/generation/test_overview_execution_flows.py
@@ -16,6 +16,7 @@ import networkx as nx
import pytest
from structlog.testing import capture_logs
+from repowise.core.analysis.communities import CommunityInfo
from repowise.core.analysis.execution_flows import ExecutionFlow, ExecutionFlowReport
from repowise.core.generation.context_assembler import ContextAssembler
@@ -79,6 +80,41 @@ def test_overview_context_carries_traced_flows(sample_config, sample_repo_struct
assert first["trace_length"] == 3
+def test_overview_context_carries_communities(sample_config, sample_repo_structure):
+ """``community_info()`` is a dict keyed by community id, not a list."""
+
+ class _CommunityBuilder(_Builder):
+ def community_info(self):
+ return {
+ 3: CommunityInfo(
+ community_id=3,
+ label="cli",
+ members=["a.py"],
+ size=1,
+ cohesion=0.5,
+ dominant_language="python",
+ ),
+ 7: CommunityInfo(
+ community_id=7,
+ label="core",
+ members=["b.py", "c.py"],
+ size=2,
+ cohesion=0.12345,
+ dominant_language="python",
+ ),
+ }
+
+ assembler = ContextAssembler(sample_config)
+ ctx = assembler.assemble_repo_overview(
+ sample_repo_structure, {}, [], {}, graph_builder=_CommunityBuilder([])
+ )
+
+ assert ctx.communities == [
+ {"id": 7, "label": "core", "size": 2, "cohesion": 0.12},
+ {"id": 3, "label": "cli", "size": 1, "cohesion": 0.5},
+ ]
+
+
def test_overview_context_ranks_flows_by_score(sample_config, sample_repo_structure):
"""The template renders the first five, so the order is the selection."""
assembler = ContextAssembler(sample_config)