test(8249): prompt filter, shared rule ledger and reply-shape guards run the hooks
CI & Build / Python lint (push) Successful in 2s
CI & Build / Plugin hooks (push) Successful in 13s
CI & Build / TypeScript typecheck (push) Successful in 32s
CI & Build / Python tests (push) Successful in 2m19s
CI & Build / integration (push) Successful in 2m33s
CI & Build / Build & push image (push) Successful in 18s

- test_prompt_boundary_filter: the prompt hook runs on a client-written turn
  and sends nothing, and on a typed one and asks; was "the filter call sits
  above the curl line" in the source.
- test_rule_usage_wiring: the write arm runs and is told it named rule 33,
  then the tool arm in the same session must send 33 as already named; was
  three string searches of each script for the ledger's path.
- test_reply_shape_turn: the hook half of the shape-ledger contract is the
  runtime test already there; the remaining test checks the route half from
  the route's AST.
- test_contract_around_the_change: its write-gate guard was a copy of
  test_hook_never_returns_a_permission_decision, which now checks the same
  two things.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-01 17:37:24 -05:00
co-authored by Claude Opus 5.5
parent 0681534257
commit ea30e0bd75
4 changed files with 54 additions and 40 deletions
+28 -10
View File
@@ -670,21 +670,39 @@ async def test_a_long_command_is_bounded_before_it_reaches_the_ranker():
assert sent.startswith("git tag v1"), "the head of the command is the signal"
def test_the_two_pre_tool_arms_share_one_session_rule_ledger():
def test_the_two_pre_tool_arms_share_one_session_rule_ledger(tmp_path):
"""The integration point most worth guarding.
Two ledgers would mean a rule named by the write arm gets re-offered by the
tool arm — and the hint that fires most often is exactly the one that must
not repeat itself. Asserted on the FILENAME both scripts build, because
that is the shared thing; a copy of the path in each is how they drift.
tool arm, and the hint that fires most often is exactly the one that must
not repeat itself. So the write arm runs and is told it named rule 33; the
tool arm, next in the same session, must send rule 33 as already named.
"""
prior = Path("plugin/hooks/grimoire_prior_art.sh").read_text()
tool = Path("plugin/hooks/grimoire_tool_rules.sh").read_text()
import json
import os
import subprocess
for src, name in ((prior, "grimoire_prior_art.sh"), (tool, "grimoire_tool_rules.sh")):
assert '"${TMPDIR:-/tmp}/grimoire-priorart"' in src, f"{name}: state dir moved"
assert '.rules.ids' in src, f"{name}: rules ledger filename moved"
assert "exclude_rule_ids" in src, f"{name}: does not send the exclusion"
from tests.helpers import http_sink, need_tools
need_tools("bash", "curl", "awk")
hooks = Path("plugin/hooks")
replies = {"/api/plugin/prior-art": b'{"context":"> rule 33","note_ids":[],"rule_ids":[33]}',
"/api/plugin/tool-rules": b'{"context":"","rule_ids":[]}'}
with http_sink(by_path=replies) as (port, seen):
env = {"PATH": os.environ["PATH"], "GRIMOIRE_URL": f"http://127.0.0.1:{port}",
"GRIMOIRE_TOKEN": "t", "TMPDIR": str(tmp_path), "HOME": str(tmp_path)}
for script, event in (
("grimoire_prior_art.sh", {"tool_name": "Write", "tool_input": {
"file_path": str(tmp_path / "a.py"), "content": "def debounce(fn):\n return fn"}}),
("grimoire_tool_rules.sh", {"tool_name": "Bash", "tool_input": {"command": "git push"}}),
):
out = subprocess.run(["bash", str(hooks / script)],
input=json.dumps({"session_id": "s-shared", "cwd": str(tmp_path),
**event}),
capture_output=True, text=True, env=env, timeout=30)
assert out.returncode == 0, out.stderr
tool_ask = [e for e in seen if e["_path"] == "/api/plugin/tool-rules"]
assert tool_ask and tool_ask[0]["exclude_rule_ids"] == ["33"]
def test_the_tool_arm_is_registered_on_bash():