test(8249): hook contract tests run the hooks instead of searching their source
- test_write_path_trigger:
- the sync, reuse and rule dedup channels: two string searches become one
run of the hook twice in a session, checking each class of id comes back
on its own parameter;
- "stays a GET": one request to the prior-art route, with no body;
- the route/hook argument contract: the hook runs with every ledger it
keeps already holding something, and every key it sends must be read by
the route (read from the route's AST);
- the "names the shapes" string search goes: two runtime tests already check
the Write and the Edit cases.
- test_rule_moment_signal_hooks: the body the route must read is the body the
hook actually sent.
- test_task_claims: session start is run and must send source and session_id;
session end is run and releases on logout but not on /clear.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -218,14 +218,19 @@ def test_session_end_removes_the_sessions_moment_files_and_no_others(sandbox):
|
||||
assert sorted(p.name for p in ledger.iterdir()) == ["s2.acts"]
|
||||
|
||||
|
||||
def test_the_hook_and_the_route_agree_on_the_body():
|
||||
"""A contract across the shell/Python seam: a renamed field fails silently."""
|
||||
src = (HOOKS / "grimoire_record_opened.sh").read_text()
|
||||
def test_the_hook_and_the_route_agree_on_the_body(sandbox):
|
||||
"""A contract across the shell/Python seam: a renamed field fails silently.
|
||||
The body is what the hook actually sends; the route must read every field
|
||||
of it, and the service must answer with the `context` the hook prints."""
|
||||
tmp, env = sandbox
|
||||
_run("grimoire_record_opened.sh",
|
||||
{"session_id": "s1", "tool_name": "mcp__grimoire__get_rule",
|
||||
"tool_input": {"rule_id": 11}}, env,
|
||||
FAKE_CURL_REPLY=json.dumps({"moments": [], "context": ""}))
|
||||
sent = json.loads((tmp / "curl.body").read_text())
|
||||
route = inspect.getsource(plugin_routes.rule_opened)
|
||||
assert "/api/plugin/rule-opened" in src
|
||||
for field in ("rule_id", "session_id", "acts"):
|
||||
assert f'"{field}"' in src and f'"{field}"' in route
|
||||
assert "'.context'" in src
|
||||
for field in sent:
|
||||
assert f'"{field}"' in route, f"the route ignores {field}"
|
||||
assert '"context"' in inspect.getsource(judgments_svc.opened_after)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user