From 076e6b7c06d0018a027ecc37249d82518999f639 Mon Sep 17 00:00:00 2001 From: Safi Date: Wed, 20 May 2026 18:27:53 +0100 Subject: [PATCH] fix cluster-only crash when graphify-out/ absent, add regression test (#934) Co-Authored-By: Claude Sonnet 4.6 --- graphify/__main__.py | 1 + tests/test_cli_export.py | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/graphify/__main__.py b/graphify/__main__.py index 3765a81..9ca7839 100644 --- a/graphify/__main__.py +++ b/graphify/__main__.py @@ -1808,6 +1808,7 @@ def main() -> None: gods = god_nodes(G) surprises = surprising_connections(G, communities) out = watch_path / "graphify-out" + out.mkdir(parents=True, exist_ok=True) labels_path = out / ".graphify_labels.json" if labels_path.exists(): try: diff --git a/tests/test_cli_export.py b/tests/test_cli_export.py index 07412f1..87b9833 100644 --- a/tests/test_cli_export.py +++ b/tests/test_cli_export.py @@ -263,3 +263,26 @@ def test_update_no_cluster_writes_raw_graph(tmp_path): data = json.loads(graph_path.read_text(encoding="utf-8")) assert "nodes" in data and "links" in data assert all("community" not in node for node in data["nodes"]) + + +# Regression test for #934 - cluster-only crashes when graphify-out/ doesn't exist + +def test_cluster_only_creates_output_dir_when_missing(tmp_path): + """cluster-only must not crash with FileNotFoundError when graphify-out/ is absent (#934).""" + # Build graph.json somewhere other than the default graphify-out/ location + # so we can point --graph at it while graphify-out/ doesn't exist yet. + graph_src = tmp_path / "backup" / "graph.json" + graph_src.parent.mkdir() + + out_dir = _make_graph(tmp_path) + graph_json = out_dir / "graph.json" + # Simulate user archiving the output dir before re-clustering + import shutil + shutil.copy(graph_json, graph_src) + shutil.rmtree(out_dir) + + assert not (tmp_path / "graphify-out").exists() + + r = _run(["cluster-only", ".", "--graph", str(graph_src), "--no-viz"], tmp_path) + assert r.returncode == 0, r.stderr + assert (tmp_path / "graphify-out" / "GRAPH_REPORT.md").exists()