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:
@@ -530,3 +530,21 @@ def forge_tarball(files: dict[str, bytes], top: str = "widget") -> bytes:
|
||||
info.size = len(data)
|
||||
tar.addfile(info, io.BytesIO(data))
|
||||
return buf.getvalue()
|
||||
|
||||
|
||||
def route_query_args(*fns) -> set[str]:
|
||||
"""Every query-string key the given route functions read with
|
||||
`request.args.get("…")`, from their AST. A hook test runs the hook, takes
|
||||
the keys it actually sent, and checks the route reads each one."""
|
||||
import ast
|
||||
import inspect
|
||||
import textwrap
|
||||
|
||||
keys = set()
|
||||
for fn in fns:
|
||||
for node in ast.walk(ast.parse(textwrap.dedent(inspect.getsource(fn)))):
|
||||
if (isinstance(node, ast.Call) and isinstance(node.func, ast.Attribute)
|
||||
and node.func.attr == "get" and ast.unparse(node.func.value) == "request.args"
|
||||
and node.args and isinstance(node.args[0], ast.Constant)):
|
||||
keys.add(node.args[0].value)
|
||||
return keys
|
||||
|
||||
Reference in New Issue
Block a user