How to Test FACET Authorization Before Tool Access
An agent should not receive a tool and only then discover whether it was allowed to use it.
Authorization belongs before execution, but putting a policy in front of a tool is only half the work. The other half is proving that the policy keeps making the same decision when inputs, roles, modes, and contract versions change. I want that proof to look like ordinary executable tests—not a screenshot from an admin panel and not a prompt that asks the model to behave.
FACET already has the right boundary for this. Its @test blocks can supply fixed variables and runtime inputs, intercept interface calls with mocks, and assert against canonical output, telemetry, and the execution artifact. That makes a policy test a small deterministic experiment: given this contract and this operation, which decision must the guard produce?
Start with a decision matrix
Before writing syntax, I write the cases as a table:
| Case | Identity or mode | Operation | Expected result |
|---|---|---|---|
| Read public record | support agent | records.read |
allow |
| Read restricted record | support agent | records.read |
deny |
| Update record | support agent | records.update |
deny |
| Update record | supervisor | records.update |
allow |
| Unknown effect | any identity | undeclared operation | fail closed |
This table is more useful than a single happy-path test because authorization defects live at boundaries. A rule can allow the intended call and still be unsafe because a neighboring identity, scope, or effect inherits permission accidentally.
The matrix also separates two different questions. A model evaluation asks whether the agent chose a good action. A policy test asks whether the runtime would permit a specific action. The first is probabilistic. The second should be deterministic.
Encode the boundary in @test
A simplified contract can keep the operation typed and place tests beside the policy it protects:
@interface Records
@method read
effect: "read"
@method update
effect: "write"
@policy
default: "deny"
allow:
- id: "support-read"
capability: "records.read"
when: $role == "support"
- id: "supervisor-update"
capability: "records.update"
when: $role == "supervisor"
@test "support-can-read"
vars:
role: "support"
mock:
Records.read: { id: "42", status: "open" }
assert:
- execution.guard.decision == "allow"
- execution.guard.rule_id == "support-read"
@test "support-cannot-update"
vars:
role: "support"
mock:
Records.update: { ok: true }
assert:
- execution.guard.decision == "deny"
The exact contract shape depends on the host profile and implementation, so this is an architectural example rather than a replacement for the normative grammar. The important pattern is stable: fixed identity, fixed operation, fixed mocked boundary, explicit decision assertion.
FACET’s testing model allows assertions over canonical, telemetry, and—when exposed—execution. Policy tests should prefer the execution artifact because authorization is a runtime decision. Canonical output can show what was compiled; it cannot by itself prove what the guard permitted.
Test refusal as a first-class result
I do not treat denial as a failed test. If the contract says the support role cannot update a record, a deterministic denial is the successful result.
That distinction matters in agent systems because retry logic often treats every non-success as temporary. A denied operation must not become an invitation to rephrase the request, switch tools, or search for an equivalent side effect. The policy test should preserve the terminal meaning of refusal.
FACET assigns explicit failures to policy and guard outcomes. In the documented Pure Mode test path, policy or guard denial and undecidable authorization use F454 and F455 where applicable. A regression suite can therefore assert more than “something failed.” It can distinguish:
- an expected policy denial;
- an undecidable authorization state;
- forbidden I/O in Pure Mode (
F801); - a missing deterministic cache dependency (
F803); - a malformed contract that never reached authorization.
Stable failure identity is what lets orchestration react safely. Denial may terminate the branch. An undecidable result may escalate to a human. A malformed contract should block deployment. Collapsing all three into a generic exception destroys that routing information.
Use pairs, not isolated examples
Every consequential allow case should have a nearby deny case that changes one dimension only:
support + records.read -> allow
support + records.update -> deny
Then add a second pair for identity:
support + records.update -> deny
supervisor + records.update -> allow
These pairs make policy drift visible. If a future refactor broadens an effect class, changes a default, or alters rule precedence, the matrix shows which boundary moved.
This is narrower than the general FACET CI contract gate. CI answers whether the contract compiles and its deterministic tests pass. The authorization matrix defines what those tests should prove for guarded tools. It also complements FACET policy as executable authorization: policy becomes engineering only when its decisions can be reproduced and compared.
Keep the model out of the test
The test should not call a provider. Fixed mocks are not a compromise here; they are the point. The policy boundary must not depend on whether a model happens to emit a particular tool call today.
A separate model evaluation can test whether the agent selects the right operation under realistic instructions. The authorization suite tests the invariant underneath it: even if the model proposes the wrong operation, the guard still produces the declared decision.
That gives me two independent signals:
- behavior quality: what the model proposed;
- execution authority: what the runtime allowed.
Mixing them creates ambiguous failures. Separating them makes each layer easier to debug and harder to overclaim.
The limit of this method
An authorization matrix does not prove that external credentials are configured correctly, that a downstream API honors its own permissions, or that every business rule is represented. It proves the decisions expressed by the tested FACET contract and implementation revision.
That boundary should be recorded. Pin the compiler revision, keep the contract hash, and preserve the execution artifact when the implementation exposes it. If the compiler or specification changes, rerun the matrix and review decision deltas as contract changes—not as incidental test noise.
I do not want policy to be prose that everyone agrees with until the first dangerous call. I want it to be an executable table of permitted and forbidden transitions. The agent may remain probabilistic. Its authority does not have to be.