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(communities): never name a community after a third-party module (#2502)
Raghav Chamadiya321987646256
diff --git a/packages/core/src/repowise/core/analysis/communities.py b/packages/core/src/repowise/core/analysis/communities.pyindex 1875684d9..353555af2 100644--- a/packages/core/src/repowise/core/analysis/communities.py+++ b/packages/core/src/repowise/core/analysis/communities.py@@ -21,6 +21,7 @@ import networkx as nximport structlogfrom repowise.core.analysis.kg_curation import GENERIC_ORG_SEGMENTS, dominant_segments+from repowise.core.ids import is_externalfrom repowise.core.ingestion.models import FILE_DEPENDENCY_EDGE_TYPES, SYMBOL_USE_EDGE_TYPESfrom repowise.core.support_paths import is_example_pathfrom repowise.core.test_paths import is_test_related_path@@ -640,11 +641,19 @@ def detect_file_communities(# Labels and conductance come from the production members: tests were kept# out of the partition so they would not shape a community, and they must# not name it either. The non-core catch-all is labelled from what it has.+ #+ # External and framework nodes are stored as files, so they reach the+ # partition, but they must not name a community either. They have no+ # directory, so a big community with no dominant segment fell through to+ # the filename-stem strategy, where eight `external:rich.*` imports share+ # the stem `external:rich` and won: this repo's largest community was+ # labelled after a third-party library that every view hides.label_members: dict[int, list[str]] = {}for cid, members in community_members.items():sorted_members = sorted(members)prod_members = [m for m in sorted_members if not non_core[m]]- label_members[cid] = prod_members or sorted_members+ owned = [m for m in prod_members if not is_external(m)]+ label_members[cid] = owned or prod_members or sorted_memberscommunities_info[cid] = CommunityInfo(community_id=cid,label=_heuristic_label(label_members[cid], cid, extra_generic),diff --git a/tests/unit/analysis/test_community_labels.py b/tests/unit/analysis/test_community_labels.pyindex 7998f79b2..6bf039fb2 100644--- a/tests/unit/analysis/test_community_labels.py+++ b/tests/unit/analysis/test_community_labels.py@@ -117,6 +117,19 @@ class TestDetectFileCommunitiesLabels:assert "ingestion" in joined and "web" in joined+class TestExternalNodesNeverName:+ def test_third_party_stem_does_not_label_a_community(self):+ # One production file per folder (no dominant segment, no keyword),+ # all importing four `external:rich.*` nodes. Those share the stem+ # "external:rich", so the stem fallback used to pick it.+ prod = [f"pkg/area{i}/f{i}.py" for i in range(12)]+ rich = [f"external:rich.{m}" for m in ("console", "panel", "table", "text")]+ edges = list(itertools.pairwise(prod)) + [(p, r) for p in prod for r in rich]+ assignment, info, _ = detect_file_communities(_graph(prod + rich, edges))+ ci = info[assignment["pkg/area0/f0.py"]]+ assert not ci.label.startswith("external:")++class TestRootFirstLabels:def test_sub_label_follows_path_order(self):# Frequency picks "ingestion" (in every path) as primary and "engine"