Why
Permission changes should fail CI when they open or close access by accident. The testing kit builds an in-memory instance from a small fixture, asksexplain() about every case, and reports failures with the reason and the near misses. Nothing is written to the audit log.
A policy suite
expect of allow, deny or escalate, and an optional code (a decision code). arguments are checked against allowedArgPatterns. report.failed holds { name, expected, got }, where got is the full explain result. formatPolicyReport(report) turns it into text.
A delegating agent must hold what it delegates. Agents are created under a seeded owner, so the suite needs no users.
Test instance
createTestAuth(config?) returns a normal TheAuth on sqlite :memory:, plus:
Any config you pass (hooks, policy, audit) is applied. Pass
runHooks in the explain option of runPolicySuite to include beforeAuthorize dry runs.
Assertions and matchers
explain() and throw with the reason and near misses when the expectation fails. The matchers accept an AuthorizeResult or an ExplainResult.
CLI
PASS or FAIL line per case, with the explain reason and near miss hints for failures. The exit code is 1 when any case fails or the file is invalid, otherwise 0. --json prints { total, passed, failed }.
Without --config the suite runs on a fresh in-memory instance. With --config (an ES module whose default export is a TheAuth instance or a config object) it runs on that. When the suite declares no agents, each case.agent is treated as an existing agent id on that instance. YAML is not supported.