Skip to content

Commit 54575d3

Browse files
fix(graph): count cross-community edges symmetrically
1 parent 853230f commit 54575d3

2 files changed

Lines changed: 25 additions & 4 deletions

File tree

engraphis/core/graph_scene.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1475,10 +1475,11 @@ def _community_summaries(graph: dict, community_ids: set[str],
14751475
tc = node_community.get(edge["target"])
14761476
if sc and sc == tc:
14771477
edge_by_community[sc].append(edge)
1478-
elif sc:
1479-
cross_by_community[sc].append(edge)
1480-
elif tc:
1481-
cross_by_community[tc].append(edge)
1478+
else:
1479+
if sc:
1480+
cross_by_community[sc].append(edge)
1481+
if tc:
1482+
cross_by_community[tc].append(edge)
14821483
result = []
14831484
for community_id in community_ids:
14841485
member_ids = set(graph["community_members"][community_id])

tests/test_graph_explorer_v2.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,26 @@ def test_complete_scene_keeps_every_memory_and_raw_connector_deterministically()
532532
assert community["external_strength"] == pytest.approx(expected_external)
533533

534534

535+
def test_community_summaries_count_cross_edges_for_both_endpoint_systems():
536+
graph = {
537+
"edges": [{"source": "a", "target": "b", "strength": 2.5}],
538+
"community_members": {"A": ["a"], "B": ["b"]},
539+
"community_anchors": {"A": "a", "B": "b"},
540+
"nodes": {
541+
"a": {"label": "A", "gravity_mass": 1.0, "scene_rank": 1.0},
542+
"b": {"label": "B", "gravity_mass": 1.0, "scene_rank": 1.0},
543+
},
544+
}
545+
546+
summaries = graph_scene_module._community_summaries(
547+
graph, {"A", "B"}, {"a", "b"}
548+
)
549+
550+
assert {item["id"]: item["external_strength"] for item in summaries} == {
551+
"A": 2.5, "B": 2.5,
552+
}
553+
554+
535555
def test_complete_scene_keeps_every_enabled_code_memory_connector():
536556
entities = [{
537557
"id": "code:symbol", "canonical_id": "code:symbol",

0 commit comments

Comments
 (0)