From efa296e817ced3c9dddc6ad078a12ef39f1d7449 Mon Sep 17 00:00:00 2001 From: Deepanshu Pal <40927968+DeepanshuPal@users.noreply.github.com> Date: Sun, 4 Oct 2026 02:02:25 +0530 Subject: [PATCH] test(hook-guard): cover custom GRAPHIFY_OUT reminder text (#4040) Regression tests for #4040: read, stale-read and search reminders name the effective graph.json under a custom GRAPHIFY_OUT, and the default output dir stays byte-identical. Co-Authored-By: Claude (cherry picked from commit 31cb3bb1c0587454f9f2c6dedbcdc75ae4511bbb) --- tests/test_hook_guard.py | 46 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/tests/test_hook_guard.py b/tests/test_hook_guard.py index c719c8fcb..e75d4e9d0 100644 --- a/tests/test_hook_guard.py +++ b/tests/test_hook_guard.py @@ -311,3 +311,49 @@ def test_read_nudge_em_dash_survives_utf8(tmp_path): text = r.stdout.decode("utf-8") # raises if not valid UTF-8 payload = json.loads(text) assert "—" in payload["hookSpecificOutput"]["additionalContext"] # em dash preserved + + +# --------------------------------------------------------------------------- # +# #4040: reminders name the effective graph.json when GRAPHIFY_OUT is customized +# --------------------------------------------------------------------------- # +def _ctx(out): + return json.loads(out)["hookSpecificOutput"]["additionalContext"] + + +def test_custom_out_read_nudge_names_effective_graph(tmp_path, monkeypatch): + out = _invoke("read", {"tool_name": "Read", "tool_input": {"file_path": "src/app.py"}}, + tmp_path, monkeypatch, out_name="artifacts/graphify") + assert "artifacts/graphify/graph.json" in _ctx(out) + assert "graphify-out/" not in _ctx(out) + + +def test_custom_out_stale_nudge_names_effective_graph(tmp_path, monkeypatch): + target = tmp_path / "src" / "app.py" + target.parent.mkdir(parents=True) + target.write_text("x = 1\n", encoding="utf-8") + g = tmp_path / "artifacts" / "graphify" / "graph.json" + g.parent.mkdir(parents=True) + g.write_text("{}", encoding="utf-8") + os.utime(g, (1, 1)) + out = _invoke("read", {"tool_name": "Read", "tool_input": {"file_path": str(target)}}, + tmp_path, monkeypatch, graph=False, out_name="artifacts/graphify") + assert "STALE" in _ctx(out) + assert "artifacts/graphify/graph.json" in _ctx(out) + assert "graphify-out/" not in _ctx(out) + + +def test_custom_out_search_nudge_names_effective_graph(tmp_path, monkeypatch): + out = _invoke("search", {"tool_name": "Bash", "tool_input": {"command": "grep -rn x ."}}, + tmp_path, monkeypatch, out_name="artifacts/graphify") + assert "artifacts/graphify/graph.json" in _ctx(out) + assert "graphify-out/" not in _ctx(out) + + +@pytest.mark.parametrize("kind,payload,const", [ + ("read", {"tool_name": "Read", "tool_input": {"file_path": "src/app.py"}}, "_READ_NUDGE"), + ("search", {"tool_name": "Bash", "tool_input": {"command": "grep -rn x ."}}, "_SEARCH_NUDGE"), +]) +def test_default_out_nudge_is_byte_identical(kind, payload, const, tmp_path, monkeypatch): + from graphify import cli + out = _invoke(kind, payload, tmp_path, monkeypatch) + assert out == getattr(cli, const)