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:
@@ -1,7 +1,6 @@
|
||||
"""Structural tests for the platforms blueprint —
|
||||
registration and the route-to-service contract. What the writes do is in
|
||||
tests/test_integration_platforms.py."""
|
||||
import inspect
|
||||
"""Structural tests for the platforms blueprint: every endpoint is routed.
|
||||
That each service takes its caller is in tests/test_service_user_id_contract.py,
|
||||
and what the writes do is in tests/test_integration_platforms.py."""
|
||||
|
||||
|
||||
def test_platforms_blueprint_registered_in_app():
|
||||
@@ -17,12 +16,3 @@ def test_platforms_blueprint_registered_in_app():
|
||||
("/api/projects/<int:project_id>/platforms", "PUT"),
|
||||
):
|
||||
assert (rule, method) in rules, f"{method} {rule} is not routed"
|
||||
|
||||
|
||||
def test_writes_to_the_catalog_and_to_a_project_take_the_caller():
|
||||
"""The catalog's admin gate and the project's write gate both live in the
|
||||
service, so every write must be handed the caller to check."""
|
||||
from grimoire.services import platforms as svc
|
||||
for name in ("create_platform", "update_platform", "set_project_platforms",
|
||||
"project_platforms"):
|
||||
assert "user_id" in inspect.signature(getattr(svc, name)).parameters
|
||||
|
||||
@@ -73,19 +73,6 @@ def test_project_scoping_reaches_every_caller():
|
||||
assert "project_id" in inspect.getsource(routes.list_snippets_route)
|
||||
|
||||
|
||||
def test_location_lookup_reaches_every_caller():
|
||||
"""The reverse lookup — "what already lives here?" — has to be askable from
|
||||
both surfaces, or an agent and a human get different answers about the same
|
||||
file."""
|
||||
from grimoire.mcp.tools import snippets as tools
|
||||
from grimoire.routes import snippets as routes
|
||||
from grimoire.services import snippets as svc
|
||||
for key in ("repo", "path", "symbol"):
|
||||
assert key in inspect.signature(svc.list_snippets).parameters
|
||||
assert key in inspect.signature(tools.list_snippets).parameters
|
||||
assert f'request.args.get("{key}"' in inspect.getsource(routes)
|
||||
|
||||
|
||||
def test_update_field_map_matches_service_kwargs():
|
||||
"""Every field the PATCH route forwards must be a real update_snippet kwarg
|
||||
(interface-contract parity)."""
|
||||
|
||||
@@ -29,6 +29,19 @@ NEEDS_NO_CALLER = {
|
||||
"invalidate_for_push": "a forge push touches every snippet at that location",
|
||||
},
|
||||
"design_systems": {},
|
||||
"family": {
|
||||
"next_version": "numbers a canon version inside a write that has checked the caller",
|
||||
},
|
||||
"family_adoption": {
|
||||
"family_reference_ids": "the coverage refresh's mechanical read for a project",
|
||||
"family_reach_ids": "retrieval's reach for a project it has already scoped",
|
||||
},
|
||||
"platforms": {
|
||||
"list_platforms": "the catalog is global and the same for everyone",
|
||||
"resolve_slugs": "a lookup in the global catalog",
|
||||
"record_detected": "the coverage refresh records what it detected",
|
||||
"detect_for_project": "the coverage refresh's own call",
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -151,7 +151,7 @@ def test_location_clause_renders_a_jsonpath_containment():
|
||||
|
||||
# --- surface plumbing ---------------------------------------------------------
|
||||
|
||||
def test_agent_and_service_surfaces_take_the_same_location_params():
|
||||
def test_every_door_takes_the_same_location_params():
|
||||
from grimoire.mcp.tools.snippets import list_snippets as mcp_list
|
||||
from grimoire.services.snippets import list_snippets as svc_list
|
||||
|
||||
@@ -160,6 +160,11 @@ def test_agent_and_service_surfaces_take_the_same_location_params():
|
||||
for key in LOCATION_KEYS:
|
||||
assert key in params, f"{fn.__qualname__} is missing {key}"
|
||||
assert params[key].default == "", f"{fn.__qualname__}.{key} default drifted"
|
||||
# The web door reads the same keys from the query string, so an agent and
|
||||
# a human asking "what already lives here?" get the same answer.
|
||||
from grimoire.routes import snippets as routes
|
||||
for key in LOCATION_KEYS:
|
||||
assert f'request.args.get("{key}"' in inspect.getsource(routes), f"the route ignores {key}"
|
||||
|
||||
|
||||
def test_route_forwards_the_location_args_by_name():
|
||||
|
||||
@@ -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