test(8249): signature and source-text batch, the hook tests run the hook
- The caller-scoping property now covers services/family, family_adoption and platforms, with the seven reads that need no caller named and why. The hand-written platform list goes. - The snippet location keys: one test checks every door (service, MCP tool, web route) takes them; the route-only copy goes. - The write-path hook: the payload-shape and skip-list tests searched the shell script for strings. They now run the hook against a local listener and check what it sends: the code from each of the four payload field names, and nothing for a note, JSON or SVG while a YAML file and a .py are still asked about. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1014,13 +1014,19 @@ def test_hook_is_executable_and_shell_valid():
|
||||
subprocess.run(["bash", "-n", str(HOOK)], check=True)
|
||||
|
||||
|
||||
def test_hook_reads_both_write_and_edit_payload_shapes():
|
||||
@pytest.mark.parametrize("tool,field", [
|
||||
("Write", "content"), ("Write", "file_content"),
|
||||
("Edit", "new_string"), ("Edit", "new_str"),
|
||||
])
|
||||
def test_hook_reads_every_write_and_edit_payload_shape(tmp_path, tool, field):
|
||||
"""Write and Edit name the payload differently, and the names have changed
|
||||
across Claude Code versions — read whichever is present."""
|
||||
src = HOOK.read_text()
|
||||
for field in ("content", "file_content", "new_string", "new_str"):
|
||||
assert f".tool_input.{field}" in src
|
||||
assert ".tool_input.file_path" in src
|
||||
across Claude Code versions: the code is sent whichever one is present."""
|
||||
code = "def debounce(fn):\n return fn\n"
|
||||
seen = _run_hook_against_sink(tmp_path, {
|
||||
"session_id": f"s-shape-{field}", "cwd": str(tmp_path), "tool_name": tool,
|
||||
"tool_input": {"file_path": str(tmp_path / "b.py"), field: code},
|
||||
})
|
||||
assert seen.get("code") == [code]
|
||||
|
||||
|
||||
def test_hook_stays_a_get_so_a_read_scoped_key_works():
|
||||
@@ -1046,19 +1052,18 @@ def test_hook_exits_silently_when_unconfigured():
|
||||
assert out.stdout.strip() == ""
|
||||
|
||||
|
||||
def test_hook_skips_prose_and_data_files():
|
||||
"""No round-trip for a markdown edit — the server would return nothing
|
||||
anyway. The list lives in the shared library and the hook asks it."""
|
||||
lib = (PLUGIN / "hooks" / "grimoire_defs.sh").read_text()
|
||||
skip = re.search(r"grimoire_skip_path\(\) \{\n case \"\$1\" in\n(.*?)esac", lib, re.S)
|
||||
assert skip, "expected an extension skip list in grimoire_defs.sh"
|
||||
for ext in ("*.md", "*.json", "*.lock", "*.png"):
|
||||
assert ext in skip.group(1)
|
||||
# Config formats are deliberately NOT skipped — a workflow file is reusable.
|
||||
assert "*.yml" not in skip.group(1)
|
||||
src = HOOK.read_text()
|
||||
assert 'grimoire_skip_path "$file_path" && exit 0' in src
|
||||
assert '/grimoire_defs.sh"' in src # sourced, not copied
|
||||
@pytest.mark.parametrize("name,asks", [
|
||||
("README.md", False), ("data.json", False), ("logo.svg", False),
|
||||
("deploy.yml", True), ("b.py", True),
|
||||
])
|
||||
def test_hook_asks_about_code_and_never_about_prose_or_data(tmp_path, name, asks):
|
||||
"""Prior art is about code. A note or a data file sends nothing; a YAML
|
||||
workflow is code that gets copied between projects, so it is asked about."""
|
||||
seen = _run_hook_against_sink(tmp_path, {
|
||||
"session_id": f"s-skip-{name}", "cwd": str(tmp_path), "tool_name": "Write",
|
||||
"tool_input": {"file_path": str(tmp_path / name), "content": "x: 1\n"},
|
||||
})
|
||||
assert bool(seen) is asks
|
||||
|
||||
|
||||
def test_hook_keeps_sync_and_reuse_dedup_apart():
|
||||
|
||||
Reference in New Issue
Block a user