test(8249): moment and checkpoint hook guards run the hooks

- test_moment_delivery: the route/hook name check runs the hook with the
  rule, opened and shape ledgers filled and checks every key it sends is read
  by the route; "leaves Grimoire's own tools alone" runs it with a listed
  Grimoire tool and sees no ask.
- test_gate_stop_hooks: the action hook run twice on one checkpoint rule
  holds once, and books the rule on the session ledger after the stop. This
  replaces two line-window checks in test_pre_act_checkpoint.
- The write hook never stopping a write: the two string guards (one per test
  file) are one, which now also forbids the shared deny helper, the call the
  old permissionDecision check could not see.
- route_query_args (tests/helpers.py) reads the query keys a route takes from
  its AST, shared by both route/hook contract tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-01 17:29:56 -05:00
co-authored by Claude Opus 5.5
parent 4321b05387
commit e92f129d4f
5 changed files with 81 additions and 100 deletions
-56
View File
@@ -49,7 +49,6 @@ ROOT = Path(__file__).resolve().parents[1]
HOOKS = ROOT / "plugin" / "hooks"
DEFS = HOOKS / "grimoire_defs.sh"
ACTION_HOOK = HOOKS / "grimoire_tool_rules.sh"
WRITE_HOOK = HOOKS / "grimoire_prior_art.sh"
WHERE = "this Bash call"
TRIGGER = "about to assert in a commit message what CI said"
@@ -255,60 +254,5 @@ def test_the_deny_envelope_is_valid_json_carrying_the_reason():
# ── The boundary that is a recorded decision ──────────────────────────────
def test_only_the_action_hook_can_hold_an_act():
"""THE GUARD ON THE RECORDED DECISION, and the reason it is here rather
than left to memory.
`grimoire_prior_art.sh` runs before every Write and Edit and has never been
able to stop one. That is a standing decision — a recall aid may not stand
in the way of the work — and `test_hook_never_returns_a_permission_
decision` in test_write_path_trigger.py holds the other half of it.
This milestone has a live argument for extending the checkpoint to writes:
three of its seven misses were file edits and none of them are reachable
from the command side. That argument is exactly why this assertion exists.
A feature with a good reason to spread is the kind that spreads without
anyone deciding to, and the decision here is the operator's to revisit.
"""
assert "grimoire_json_deny" in ACTION_HOOK.read_text()
write_code = [
ln for ln in WRITE_HOOK.read_text().splitlines()
if not ln.lstrip().startswith("#")
]
assert not any("grimoire_json_deny" in ln for ln in write_code)
assert not any("permissionDecision" in ln for ln in write_code)
def test_the_action_hook_caps_every_hold_it_emits():
"""Structural, and able to fail: the deny and the ledger call
must appear together. A deny emitted outside the guard is a session that
can be held by the same rule on every command, which is the one outcome
both guards exist to prevent."""
text = ACTION_HOOK.read_text()
code = [ln for ln in text.splitlines() if not ln.lstrip().startswith("#")]
denies = [i for i, ln in enumerate(code) if "grimoire_json_deny" in ln]
assert denies, "the action arm no longer emits a hold at all"
for i in denies:
window = "\n".join(code[max(0, i - 6):i])
assert "grimoire_checkpoint_allowed" in window, (
"a hold is emitted without passing the per-rule and per-session "
"guards first"
)
def test_the_action_hook_records_what_was_surfaced_whichever_way_it_renders():
"""The ledger append sits BEFORE the checkpoint branch. What the server
chose to surface happened whichever way this hook then renders it, and
doing the bookkeeping inside one branch is how the two arms' ledgers came
to disagree once already."""
code = [
ln for ln in ACTION_HOOK.read_text().splitlines()
if not ln.lstrip().startswith("#")
]
append = next(i for i, ln in enumerate(code) if "grimoire_rules_append" in ln)
deny = next(i for i, ln in enumerate(code) if "grimoire_json_deny" in ln)
assert append < deny
def test_the_action_hook_is_still_shell_valid():
subprocess.run(["bash", "-n", str(ACTION_HOOK)], check=True)