mirror of
https://github.com/safishamsi/graphify.git
synced 2026-10-14 16:09:26 +00:00
The read/search nudge was re-injected on every qualifying Read/Glob/Grep/Bash call with no dedup or session cap (issue #3435 measured ~8,348 injections, ~651k tokens, for 339 graphify calls), and an agent that just ran `graphify query` was still nudged on its very next read. `_nudge_allowed` now gates all three soft-nudge sites with a per-session + per-agent counter (first nudge always fires; later ones suppressed while the query stamp is fresh; hard cap via GRAPHIFY_HOOK_NUDGE_CAP, default 5), with 24h GC and fail-open preserved. Subagents get independent budgets. The strict deny path is unchanged. Landed from PR #3443 (squashed). The README strict-mode note is omitted here because that prose moved to docs.graphify.com in the README trim. Co-Authored-By: Andre Brait <andrebrait@gmail.com> Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
454 lines
19 KiB
Python
454 lines
19 KiB
Python
"""Rigorous edge-case coverage for the `graphify hook-guard` subcommand (#522).
|
|
|
|
Covers the shell-agnostic PreToolUse/BeforeTool guard that replaced the inline
|
|
bash hooks: the search/read detection matrix, the gemini BeforeTool contract,
|
|
fail-open behavior, output-dir overrides, subcommand dispatch, exit codes, and
|
|
UTF-8 (em dash) byte fidelity. Detection is exercised by calling _run_hook_guard
|
|
directly (hermetic, fast); dispatch/exit/encoding go through a real subprocess.
|
|
"""
|
|
import io
|
|
import json
|
|
import os
|
|
import subprocess
|
|
import sys
|
|
|
|
import pytest
|
|
|
|
from graphify import __main__ as m
|
|
|
|
|
|
# --------------------------------------------------------------------------- #
|
|
# Direct-call harness: hermetic w.r.t. the ambient GRAPHIFY_OUT env.
|
|
# --------------------------------------------------------------------------- #
|
|
def _invoke(kind, payload, tmp_path, monkeypatch, *, graph=True, out_name="graphify-out"):
|
|
monkeypatch.setattr("graphify.paths.GRAPHIFY_OUT", out_name)
|
|
monkeypatch.setattr("graphify.paths.GRAPHIFY_OUT_NAME", out_name)
|
|
monkeypatch.chdir(tmp_path)
|
|
if graph:
|
|
(tmp_path / out_name).mkdir(parents=True, exist_ok=True)
|
|
(tmp_path / out_name / "graph.json").write_text("{}", encoding="utf-8")
|
|
|
|
if isinstance(payload, (bytes, bytearray)):
|
|
data = bytes(payload)
|
|
elif payload is None:
|
|
data = b""
|
|
else:
|
|
data = json.dumps(payload).encode("utf-8")
|
|
|
|
class _Stdin:
|
|
def __init__(self, b):
|
|
self.buffer = io.BytesIO(b)
|
|
|
|
monkeypatch.setattr(sys, "stdin", _Stdin(data))
|
|
buf = io.StringIO()
|
|
monkeypatch.setattr(sys, "stdout", buf)
|
|
m._run_hook_guard(kind)
|
|
return buf.getvalue()
|
|
|
|
|
|
# --------------------------------------------------------------------------- #
|
|
# search: commands that MUST nudge (mirror the old *grep*/token globs)
|
|
# --------------------------------------------------------------------------- #
|
|
@pytest.mark.parametrize("command", [
|
|
"grep -rn foo .",
|
|
"egrep pattern file", # contains 'grep'
|
|
"fgrep lit file", # contains 'grep'
|
|
"ls -la | grep foo", # piped
|
|
"ripgrep thing",
|
|
"rg pattern src/",
|
|
"find . -name '*.py'",
|
|
"fd bar",
|
|
"ack needle",
|
|
"ag needle",
|
|
])
|
|
def test_search_nudges(command, tmp_path, monkeypatch):
|
|
out = _invoke("search", {"tool_input": {"command": command}}, tmp_path, monkeypatch)
|
|
assert "graphify query" in out, f"{command!r} should nudge"
|
|
assert json.loads(out)["hookSpecificOutput"]["hookEventName"] == "PreToolUse"
|
|
|
|
|
|
# --------------------------------------------------------------------------- #
|
|
# search: commands / inputs that MUST stay silent
|
|
# --------------------------------------------------------------------------- #
|
|
@pytest.mark.parametrize("command", [
|
|
"", # empty
|
|
# pgrep searches PROCESSES, not file content - the old substring scan
|
|
# nudged on it only because the string contains 'grep' (#3121); the graph
|
|
# has nothing to offer a process lookup.
|
|
"pgrep -f server",
|
|
"ls -la",
|
|
"git status",
|
|
"cat README.md",
|
|
"python app.py",
|
|
"cd findings && ls", # 'find' without a trailing space is not a match
|
|
"manage db migrate", # 'ag' mid-word, no 'ag ' token
|
|
"echo hello",
|
|
])
|
|
def test_search_silent(command, tmp_path, monkeypatch):
|
|
out = _invoke("search", {"tool_input": {"command": command}}, tmp_path, monkeypatch)
|
|
assert out.strip() == "", f"{command!r} should be silent"
|
|
|
|
|
|
def test_search_silent_without_graph(tmp_path, monkeypatch):
|
|
out = _invoke("search", {"tool_input": {"command": "grep x"}}, tmp_path, monkeypatch, graph=False)
|
|
assert out.strip() == ""
|
|
|
|
|
|
def test_search_missing_command_key(tmp_path, monkeypatch):
|
|
out = _invoke("search", {"tool_input": {}}, tmp_path, monkeypatch)
|
|
assert out.strip() == ""
|
|
|
|
|
|
def test_search_non_string_command_is_silent(tmp_path, monkeypatch):
|
|
out = _invoke("search", {"tool_input": {"command": 123}}, tmp_path, monkeypatch)
|
|
assert out.strip() == ""
|
|
|
|
|
|
def test_search_top_level_command_without_tool_input(tmp_path, monkeypatch):
|
|
# Some hosts pass the tool payload flat (no "tool_input" wrapper).
|
|
out = _invoke("search", {"command": "grep x"}, tmp_path, monkeypatch)
|
|
assert "graphify query" in out
|
|
|
|
|
|
def test_search_non_dict_tool_input_is_silent(tmp_path, monkeypatch):
|
|
out = _invoke("search", {"tool_input": "grep foo"}, tmp_path, monkeypatch)
|
|
assert out.strip() == ""
|
|
|
|
|
|
# --------------------------------------------------------------------------- #
|
|
# read: file targets that MUST nudge
|
|
# --------------------------------------------------------------------------- #
|
|
@pytest.mark.parametrize("tool_input", [
|
|
{"file_path": "src/app.py"},
|
|
{"file_path": "pkg/mod.ts"},
|
|
{"file_path": "src/App.vue"},
|
|
{"file_path": "src/Hero.astro"},
|
|
{"file_path": "src/Card.svelte"},
|
|
{"file_path": "SRC/APP.PY"}, # uppercase extension
|
|
{"file_path": "src/a.test.tsx"}, # multi-dot -> .tsx
|
|
{"file_path": "lib/foo.min.js"}, # multi-dot -> .js
|
|
{"file_path": "scripts/deploy.ps1"}, # #4271: PowerShell sources nudge too
|
|
{"file_path": "scripts/Module.psm1"}, # #4271
|
|
{"file_path": "scripts/Module.psd1"}, # #4271
|
|
{"file_path": "scripts/DEPLOY.PS1"}, # #4271: uppercase extension
|
|
{"file_path": r"src\components\app.py"}, # windows backslashes
|
|
{"pattern": "**/*.py", "path": "src"}, # glob pattern
|
|
{"pattern": "**/*.astro"},
|
|
])
|
|
def test_read_nudges(tool_input, tmp_path, monkeypatch):
|
|
out = _invoke("read", {"tool_input": tool_input}, tmp_path, monkeypatch)
|
|
assert "graphify query" in out, f"{tool_input!r} should nudge"
|
|
|
|
|
|
# --------------------------------------------------------------------------- #
|
|
# read: targets that MUST stay silent
|
|
# --------------------------------------------------------------------------- #
|
|
@pytest.mark.parametrize("tool_input", [
|
|
{"file_path": "package.json"}, # .json must not match .js
|
|
{"file_path": "tsconfig.json"},
|
|
{"file_path": "data.geojson"},
|
|
{"file_path": "uv.lock"},
|
|
{"file_path": "logo.png"},
|
|
{"file_path": "data.bin"},
|
|
{"file_path": ".gitignore"},
|
|
{"file_path": "Makefile"}, # no extension
|
|
{"file_path": "my.ts/file"}, # extension on a directory segment
|
|
{"file_path": "graphify-out/GRAPH_REPORT.md"}, # the graph's own output
|
|
{"file_path": ""},
|
|
{}, # nothing at all
|
|
])
|
|
def test_read_silent(tool_input, tmp_path, monkeypatch):
|
|
out = _invoke("read", {"tool_input": tool_input}, tmp_path, monkeypatch)
|
|
assert out.strip() == "", f"{tool_input!r} should be silent"
|
|
|
|
|
|
def test_read_silent_without_graph(tmp_path, monkeypatch):
|
|
out = _invoke("read", {"tool_input": {"file_path": "src/app.py"}}, tmp_path, monkeypatch, graph=False)
|
|
assert out.strip() == ""
|
|
|
|
|
|
def test_read_non_dict_tool_input_is_silent(tmp_path, monkeypatch):
|
|
out = _invoke("read", {"tool_input": ["src/app.py"]}, tmp_path, monkeypatch)
|
|
assert out.strip() == ""
|
|
|
|
|
|
def test_read_respects_custom_output_dir_name(tmp_path, monkeypatch):
|
|
# A source file living under a CUSTOM output dir name must be suppressed too,
|
|
# not just the literal 'graphify-out/'.
|
|
out = _invoke("read", {"tool_input": {"file_path": "build-out/report.py"}},
|
|
tmp_path, monkeypatch, graph=True, out_name="build-out")
|
|
assert out.strip() == ""
|
|
|
|
|
|
def test_read_nudges_source_outside_custom_output_dir(tmp_path, monkeypatch):
|
|
out = _invoke("read", {"tool_input": {"file_path": "src/app.py"}},
|
|
tmp_path, monkeypatch, graph=True, out_name="build-out")
|
|
assert "graphify query" in out
|
|
|
|
|
|
@pytest.mark.parametrize("file_path", [
|
|
"tools/graphify/notes.md",
|
|
"tools/graphify/helper.py",
|
|
".codex/skills/graphify/SKILL.md",
|
|
r"tools\graphify\helper.py",
|
|
])
|
|
def test_read_nudges_when_nested_out_name_matches_directory(file_path, tmp_path, monkeypatch):
|
|
# #3959: when GRAPHIFY_OUT is a nested path whose last segment is a common name
|
|
# (e.g. artifacts/graphify), paths containing graphify/ outside the output directory
|
|
# must still be nudged and not falsely suppressed.
|
|
out = _invoke("read", {"tool_input": {"file_path": file_path}},
|
|
tmp_path, monkeypatch, graph=True, out_name="artifacts/graphify")
|
|
assert "graphify query" in out, f"{file_path} should nudge"
|
|
|
|
|
|
@pytest.mark.parametrize("tool_input", [
|
|
{"file_path": "artifacts/graphify/GRAPH_REPORT.md"},
|
|
{"file_path": "artifacts/graphify/report.py"},
|
|
{"pattern": "artifacts/graphify/**/*.py"},
|
|
{"pattern": "*.py", "path": "artifacts/graphify"},
|
|
{"pattern": "graphify/*.py", "path": "artifacts"},
|
|
])
|
|
def test_read_nested_output_dir_silences_own_output(tool_input, tmp_path, monkeypatch):
|
|
# #3959: files and globs inside the nested output dir must remain silent.
|
|
out = _invoke("read", {"tool_input": tool_input},
|
|
tmp_path, monkeypatch, graph=True, out_name="artifacts/graphify")
|
|
assert out.strip() == "", f"{tool_input!r} should be silent"
|
|
|
|
|
|
|
|
# --------------------------------------------------------------------------- #
|
|
# fail-open: malformed / empty stdin never crashes or blocks
|
|
# --------------------------------------------------------------------------- #
|
|
@pytest.mark.parametrize("kind", ["search", "read"])
|
|
@pytest.mark.parametrize("raw", [b"not json at all", b"", b"[1,2,3]", b"\xff\xfe\x00bad"])
|
|
def test_fail_open_on_bad_stdin(kind, raw, tmp_path, monkeypatch):
|
|
out = _invoke(kind, raw, tmp_path, monkeypatch)
|
|
assert out.strip() == ""
|
|
|
|
|
|
def test_search_out_path_error_is_swallowed(tmp_path, monkeypatch):
|
|
# If the graph-existence check itself throws, the guard stays silent (never
|
|
# blocks the tool).
|
|
def _boom(*a, **k):
|
|
raise OSError("boom")
|
|
monkeypatch.setattr("graphify.paths.out_path", _boom)
|
|
out = _invoke("search", {"tool_input": {"command": "grep x"}}, tmp_path, monkeypatch)
|
|
assert out.strip() == ""
|
|
|
|
|
|
# --------------------------------------------------------------------------- #
|
|
# soft nudge bounds (#3435): fresh query stamp suppresses, per-session cap
|
|
# --------------------------------------------------------------------------- #
|
|
def _read_payload(sid="s1", agent=None):
|
|
p = {"session_id": sid, "tool_name": "Read", "tool_input": {"file_path": "src/app.py"}}
|
|
if agent:
|
|
p["agent_id"] = agent
|
|
return p
|
|
|
|
|
|
def _search_payload(sid="s1"):
|
|
return {"session_id": sid, "tool_input": {"command": "grep -rn foo ."}}
|
|
|
|
|
|
def _fresh_stamp(tmp_path):
|
|
stamp = tmp_path / "graphify-out" / "cache" / "last_query_stamp"
|
|
stamp.parent.mkdir(parents=True, exist_ok=True)
|
|
stamp.write_text("x", encoding="utf-8")
|
|
|
|
|
|
def test_fresh_query_stamp_silences_nudges_after_the_first(tmp_path, monkeypatch):
|
|
_fresh_stamp(tmp_path)
|
|
# The stamp is project-wide and cannot tell which agent queried, so each
|
|
# agent still gets its first nudge; later ones are silenced.
|
|
assert "MANDATORY" in _invoke("read", _read_payload(), tmp_path, monkeypatch)
|
|
assert _invoke("read", _read_payload(), tmp_path, monkeypatch) == ""
|
|
assert _invoke("search", _search_payload(), tmp_path, monkeypatch) == ""
|
|
|
|
|
|
def test_fresh_query_stamp_silences_nudges_without_session_id(tmp_path, monkeypatch):
|
|
_fresh_stamp(tmp_path)
|
|
payload = {"tool_name": "Read", "tool_input": {"file_path": "src/app.py"}}
|
|
assert _invoke("read", payload, tmp_path, monkeypatch) == ""
|
|
|
|
|
|
def test_subagents_get_their_own_nudge_budget(tmp_path, monkeypatch):
|
|
# Claude Code subagents share the parent's session_id and differ by agent_id.
|
|
monkeypatch.setenv("GRAPHIFY_HOOK_NUDGE_CAP", "1")
|
|
sid = "s" * 64 # long ids must not truncate distinct agents into one key
|
|
assert "MANDATORY" in _invoke("read", _read_payload(sid), tmp_path, monkeypatch)
|
|
assert _invoke("read", _read_payload(sid), tmp_path, monkeypatch) == ""
|
|
assert "MANDATORY" in _invoke("read", _read_payload(sid, "agent-a"), tmp_path, monkeypatch)
|
|
assert _invoke("read", _read_payload(sid, "agent-a"), tmp_path, monkeypatch) == ""
|
|
assert "MANDATORY" in _invoke("read", _read_payload(sid, "agent-b"), tmp_path, monkeypatch)
|
|
|
|
|
|
def test_subagent_first_nudge_survives_parent_query(tmp_path, monkeypatch):
|
|
assert "MANDATORY" in _invoke("read", _read_payload(), tmp_path, monkeypatch)
|
|
_fresh_stamp(tmp_path) # parent queried
|
|
assert _invoke("read", _read_payload(), tmp_path, monkeypatch) == ""
|
|
assert "MANDATORY" in _invoke("read", _read_payload(agent="agent-a"), tmp_path, monkeypatch)
|
|
|
|
|
|
def test_nudges_capped_per_session(tmp_path, monkeypatch):
|
|
monkeypatch.setenv("GRAPHIFY_HOOK_NUDGE_CAP", "3")
|
|
outs = [_invoke("read", _read_payload("cap"), tmp_path, monkeypatch) for _ in range(3)]
|
|
assert all("MANDATORY" in o for o in outs)
|
|
assert _invoke("read", _read_payload("cap"), tmp_path, monkeypatch) == ""
|
|
assert _invoke("search", _search_payload("cap"), tmp_path, monkeypatch) == ""
|
|
# Another session has its own budget.
|
|
assert "MANDATORY" in _invoke("read", _read_payload("other"), tmp_path, monkeypatch)
|
|
|
|
|
|
def test_read_and_search_nudges_share_the_session_budget(tmp_path, monkeypatch):
|
|
monkeypatch.setenv("GRAPHIFY_HOOK_NUDGE_CAP", "2")
|
|
assert "MANDATORY" in _invoke("search", _search_payload("mix"), tmp_path, monkeypatch)
|
|
assert "MANDATORY" in _invoke("read", _read_payload("mix"), tmp_path, monkeypatch)
|
|
assert _invoke("search", _search_payload("mix"), tmp_path, monkeypatch) == ""
|
|
|
|
|
|
def test_nudge_cap_default_is_five(tmp_path, monkeypatch):
|
|
monkeypatch.delenv("GRAPHIFY_HOOK_NUDGE_CAP", raising=False)
|
|
outs = [_invoke("read", _read_payload("d"), tmp_path, monkeypatch) for _ in range(6)]
|
|
assert [bool(o) for o in outs] == [True] * 5 + [False]
|
|
|
|
|
|
@pytest.mark.parametrize("value", ["0", "-1", "not-a-number"])
|
|
def test_nudge_cap_disabled(value, tmp_path, monkeypatch):
|
|
monkeypatch.setenv("GRAPHIFY_HOOK_NUDGE_CAP", value)
|
|
outs = [_invoke("read", _read_payload("nocap"), tmp_path, monkeypatch) for _ in range(8)]
|
|
assert all("MANDATORY" in o for o in outs)
|
|
|
|
|
|
def test_nudges_without_session_id_are_not_counted(tmp_path, monkeypatch):
|
|
monkeypatch.setenv("GRAPHIFY_HOOK_NUDGE_CAP", "1")
|
|
payload = {"tool_name": "Read", "tool_input": {"file_path": "src/app.py"}}
|
|
outs = [_invoke("read", payload, tmp_path, monkeypatch) for _ in range(3)]
|
|
assert all("MANDATORY" in o for o in outs)
|
|
|
|
|
|
# --------------------------------------------------------------------------- #
|
|
# gemini: BeforeTool contract (always allow; nudge only when a graph exists)
|
|
# --------------------------------------------------------------------------- #
|
|
def test_gemini_allow_with_nudge(tmp_path, monkeypatch):
|
|
out = _invoke("gemini", None, tmp_path, monkeypatch, graph=True)
|
|
payload = json.loads(out)
|
|
assert payload["decision"] == "allow"
|
|
assert "graphify query" in payload["additionalContext"]
|
|
|
|
|
|
def test_gemini_allow_without_graph(tmp_path, monkeypatch):
|
|
out = _invoke("gemini", None, tmp_path, monkeypatch, graph=False)
|
|
payload = json.loads(out)
|
|
assert payload == {"decision": "allow"}
|
|
|
|
|
|
def test_gemini_always_allows_even_when_check_throws(tmp_path, monkeypatch):
|
|
def _boom(*a, **k):
|
|
raise OSError("boom")
|
|
monkeypatch.setattr("graphify.paths.out_path", _boom)
|
|
out = _invoke("gemini", None, tmp_path, monkeypatch, graph=True)
|
|
assert json.loads(out) == {"decision": "allow"}
|
|
|
|
|
|
# --------------------------------------------------------------------------- #
|
|
# subcommand dispatch, exit codes, and UTF-8 fidelity (real subprocess)
|
|
# --------------------------------------------------------------------------- #
|
|
def _env():
|
|
e = dict(os.environ)
|
|
e.pop("GRAPHIFY_OUT", None)
|
|
return e
|
|
|
|
|
|
def _cli(args, tmp_path, stdin=""):
|
|
return subprocess.run(
|
|
[sys.executable, "-m", "graphify", *args],
|
|
input=stdin, capture_output=True, text=True, cwd=tmp_path, env=_env(),
|
|
)
|
|
|
|
|
|
def test_dispatch_missing_mode_exits_zero_silent(tmp_path):
|
|
r = _cli(["hook-guard"], tmp_path, stdin="{}")
|
|
assert r.returncode == 0
|
|
assert r.stdout.strip() == ""
|
|
|
|
|
|
def test_dispatch_unknown_mode_exits_zero_silent(tmp_path):
|
|
r = _cli(["hook-guard", "bogus"], tmp_path, stdin="{}")
|
|
assert r.returncode == 0
|
|
assert r.stdout.strip() == ""
|
|
|
|
|
|
@pytest.mark.parametrize("args,stdin", [
|
|
(["hook-guard", "search"], '{"tool_input":{"command":"grep x"}}'),
|
|
(["hook-guard", "read"], '{"tool_input":{"file_path":"a.py"}}'),
|
|
(["hook-guard", "gemini"], ""),
|
|
])
|
|
def test_dispatch_always_exits_zero(args, stdin, tmp_path):
|
|
# even with a graph present (nudge path), exit code must be 0 (never blocks)
|
|
(tmp_path / "graphify-out").mkdir()
|
|
(tmp_path / "graphify-out" / "graph.json").write_text("{}", encoding="utf-8")
|
|
r = _cli(args, tmp_path, stdin=stdin)
|
|
assert r.returncode == 0
|
|
|
|
|
|
def test_read_nudge_em_dash_survives_utf8(tmp_path):
|
|
# The read nudge contains an em dash; the emitted bytes must be valid UTF-8
|
|
# and parse back cleanly (guards the ensure_ascii=False + stdout reconfigure).
|
|
(tmp_path / "graphify-out").mkdir()
|
|
(tmp_path / "graphify-out" / "graph.json").write_text("{}", encoding="utf-8")
|
|
r = subprocess.run(
|
|
[sys.executable, "-m", "graphify", "hook-guard", "read"],
|
|
input=b'{"tool_input":{"file_path":"src/app.py"}}',
|
|
capture_output=True, cwd=tmp_path, env=_env(),
|
|
)
|
|
assert r.returncode == 0
|
|
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)
|