From 08301ccd06e804001464602dd969e9cc1463e169 Mon Sep 17 00:00:00 2001 From: Satvik Shrivas <44926681+theSatvik@users.noreply.github.com> Date: Thu, 3 Sep 2026 02:07:26 +0530 Subject: [PATCH] fix(watch): preserve pending semantic update flag --- graphify/watch.py | 13 ------------- tests/test_watch.py | 26 ++++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/graphify/watch.py b/graphify/watch.py index fbcbbc011..847ab20d7 100644 --- a/graphify/watch.py +++ b/graphify/watch.py @@ -1846,11 +1846,6 @@ def _failed(f: str) -> bool: except Exception: pass - # clear stale needs_update flag if present - flag = out / "needs_update" - if flag.exists(): - flag.unlink() - if same_graph: print("[graphify watch] No code-graph changes detected (--no-cluster); outputs left untouched.") else: @@ -1894,9 +1889,6 @@ def _failed(f: str) -> bool: ) except Exception: pass - flag = out / "needs_update" - if flag.exists(): - flag.unlink() html_action = _reconcile_graph_html(out, existing_graph_data) if html_action == "rendered": print( @@ -2086,11 +2078,6 @@ def _failed(f: str) -> bool: except Exception as cf_err: print(f"[graphify watch] callflow HTML update skipped: {cf_err}") - # clear stale needs_update flag if present - flag = out / "needs_update" - if flag.exists(): - flag.unlink() - if not no_change: print(f"[graphify watch] Rebuilt: {G.number_of_nodes()} nodes, " f"{G.number_of_edges()} edges, {len(communities)} communities") diff --git a/tests/test_watch.py b/tests/test_watch.py index a189446b6..6f9dfac63 100644 --- a/tests/test_watch.py +++ b/tests/test_watch.py @@ -163,6 +163,32 @@ def test_check_update_does_not_clear_flag(tmp_path): assert flag.exists() +@pytest.mark.parametrize( + ("no_cluster", "change_topology"), + [(True, False), (False, False), (False, True)], + ids=["no-cluster", "unchanged-topology", "clustered-rebuild"], +) +def test_code_rebuild_preserves_semantic_update_flag( + tmp_path, no_cluster, change_topology +): + """An AST-only rebuild cannot clear pending semantic work (#3294).""" + source = tmp_path / "app.py" + source.write_text("def before(): pass\n", encoding="utf-8") + assert _rebuild_code( + tmp_path, no_cluster=no_cluster, acquire_lock=False + ) is True + + flag = tmp_path / "graphify-out" / "needs_update" + flag.write_text("docs/PRD.md\n", encoding="utf-8") + if change_topology: + source.write_text("def after(): pass\n", encoding="utf-8") + + assert _rebuild_code( + tmp_path, no_cluster=no_cluster, acquire_lock=False + ) is True + assert flag.read_text(encoding="utf-8") == "docs/PRD.md\n" + + def test_watch_raises_without_watchdog(tmp_path, monkeypatch): import builtins real_import = builtins.__import__