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
+16
View File
@@ -131,6 +131,22 @@ def test_a_checkpoint_past_the_session_cap_is_reported_as_let_through(tmp_path):
assert [(s["gate"], s["outcome"]) for s in _stops(seen)] == [("checkpoint", "let_through")]
def test_a_checkpoint_holds_a_rule_once_and_books_it_as_surfaced_either_way(tmp_path):
"""The per-rule cap, end to end: the second command on the same rule goes
ahead. And the rule is on the session's rules ledger after the stop,
because what the server surfaced happened whichever way the hook rendered
it; bookkeeping inside one branch is how two arms' ledgers came to disagree."""
with http_sink(by_path=_checkpoint_replies(rule_id=9)) as (port, seen):
first = _run(TOOL_RULES, tmp_path, port,
_bash_event(call="toolu_a", command="git commit -m x", cwd=str(tmp_path)))
second = _run(TOOL_RULES, tmp_path, port,
_bash_event(call="toolu_b", command="git commit -m y", cwd=str(tmp_path)))
assert _denied(first)
assert not second or not _denied(second)
ledger = tmp_path / "tmp" / "grimoire-priorart" / "s-gate.rules.ids"
assert ledger.read_text().split("\t")[0].strip() == "9"
# ── the project fence ────────────────────────────────────────────────────
HOME_URL = "https://forge.example/team/home.git"