Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion graphify/analyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
Expand Down
15 changes: 14 additions & 1 deletion tests/test_analyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 ──────────────────────────────────────────────────


Expand Down
Loading