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(refactoring): add split_file call edges in a fixed order (#2991)
Raghav Chamadiyaa75488734532
diff --git a/packages/core/src/repowise/core/analysis/health/refactoring/split_file.py b/packages/core/src/repowise/core/analysis/health/refactoring/split_file.pyindex b551bae2a..17bca9893 100644--- a/packages/core/src/repowise/core/analysis/health/refactoring/split_file.py+++ b/packages/core/src/repowise/core/analysis/health/refactoring/split_file.py@@ -251,7 +251,8 @@ def _module_label(labfor m in membersfor lab in foreign_of.get(m, set())- if _label_identifier(lab).lower() not in _PRECOMPILED_HEADER_STEMS+ # "tpl, resources" is a two-area community label, not a module name.+ if "," not in lab and _label_identifier(lab).lower() not in _PRECOMPILED_HEADER_STEMS)if not labels:return ""@@ -544,7 +545,7 @@ def _weighted_graph(# Signals are added strongest first (see module docstring).edges = _EdgeWeights(spine)- for a, b in signals.local_pairs:+ for a, b in sorted(signals.local_pairs):edges.add(a, b, _DIRECT_CALL_WEIGHT)cochange_edges = _add_cochange_edges(edges, commits_of)_add_shared_helper_edges(edges, signals.callers_of)diff --git a/tests/unit/health/test_refactoring_split_file.py b/tests/unit/health/test_refactoring_split_file.pyindex a2e700fe9..5a7a1aad7 100644--- a/tests/unit/health/test_refactoring_split_file.py+++ b/tests/unit/health/test_refactoring_split_file.py@@ -25,8 +25,11 @@ from repowise.core.analysis.health.refactoring import ()from repowise.core.analysis.health.refactoring.split_file import (SplitFileDetector,+ _CallSignals,_dominant_token,+ _module_label,_shim_required,+ _weighted_graph,)from repowise.core.ingestion.git_indexer.function_blame import BlameIndex@@ -576,3 +579,19 @@ def test_overloads_are_listed_once_in_the_residual():out = _detect(g, _CPP, language="cpp")assert len(out) == 1assert out[0].plan["residual"] == {"symbols": ["Trim"]}+++def test_direct_call_edges_are_added_in_sorted_order():+ # A set of pairs iterates in hash order, and the community partitioner reads+ # edges in insertion order, so the order must not follow the hash seed.+ signals = _CallSignals()+ for pair in [("z", "a"), ("m", "a"), ("c", "a"), ("q", "a"), ("x", "a")]:+ signals.add_local_call(*pair)+ wg, _ = _weighted_graph(["a", "c", "m", "q", "x", "z"], set(), signals, {})+ assert list(wg.adj["a"]) == ["c", "m", "q", "x", "z"]+++def test_a_two_area_community_label_never_names_a_group():+ foreign_of = {"a": {"tpl, resources"}, "b": {"tpl, resources", "path/to/layout.go"}}+ assert _module_label(foreign_of, ["a"], set()) == ""+ assert _module_label(foreign_of, ["a", "b"], set()) == "layout"