From d83e375a344dccebcca1ea181cc62c73fd3b3f38 Mon Sep 17 00:00:00 2001 From: hanmo1 Date: Sat, 11 Jul 2026 01:11:15 +0800 Subject: [PATCH] fix(analyze): exclude rationale nodes from gap questions --- graphify/analyze.py | 5 ++++- tests/test_analyze.py | 15 ++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/graphify/analyze.py b/graphify/analyze.py index 0d4bbe4c9..e47dce4f1 100644 --- a/graphify/analyze.py +++ b/graphify/analyze.py @@ -504,7 +504,10 @@ def suggest_questions( # 4. Isolated or weakly-connected nodes → exploration questions isolated = [ n for n in G.nodes() - if G.degree(n) <= 1 and not _is_file_node(G, n) and not _is_concept_node(G, n) + if G.degree(n) <= 1 + and not _is_file_node(G, n) + and not _is_concept_node(G, n) + and G.nodes[n].get("file_type") != "rationale" ] if isolated: labels = [G.nodes[n].get("label", n) for n in isolated[:3]] diff --git a/tests/test_analyze.py b/tests/test_analyze.py index ecf1555d3..7bff432cf 100644 --- a/tests/test_analyze.py +++ b/tests/test_analyze.py @@ -5,7 +5,7 @@ from pathlib import Path from graphify.build import build_from_json from graphify.cluster import cluster -from graphify.analyze import god_nodes, surprising_connections, _is_concept_node, graph_diff, _surprise_score, _file_category, _is_json_key_node, find_import_cycles +from graphify.analyze import god_nodes, surprising_connections, _is_concept_node, graph_diff, _surprise_score, _file_category, _is_json_key_node, find_import_cycles, suggest_questions from graphify.extract import _make_id FIXTURES = Path(__file__).parent / "fixtures" @@ -603,6 +603,19 @@ def test_god_nodes_filter_is_case_insensitive(): assert variant not in labels, f"`{variant}` should be filtered as JSON-key noise" +def test_suggest_questions_excludes_rationale_nodes_from_isolated_count(): + G = nx.Graph() + G.add_node("service", label="Service", file_type="code", source_file="service.py") + G.add_node("reason", label="Explains service", file_type="rationale", source_file="service.py") + + questions = suggest_questions(G, communities={}, community_labels={}, top_n=10) + isolated = next(question for question in questions if question["type"] == "isolated_nodes") + + assert isolated["why"].startswith("1 weakly-connected node") + assert "`Service`" in isolated["question"] + assert "Explains service" not in isolated["question"] + + # ── find_import_cycles tests ──────────────────────────────────────────────────