Testing
Test policies, prove denied actions never run, and debug decisions.
Test authorization at three levels:
| Level | What it proves | Tooling |
|---|---|---|
| Policy tests | Rules produce the expected allow, deny and approval outcomes | reqlo policies test |
| Integration tests | Your code enforces decisions: denied actions don't run | Your test framework with a sandbox key or mock |
| Failure tests | Timeouts, outages and errors never execute actions | Fault injection |
The most important test in any integration: a denied action does not execute.
Sandbox and credentials
Every project has a sandbox environment with the same engine as production.
- Isolated: sandbox agents, policies, delegations, approvals and decisions are separate from other projects and environments. For a clean slate, create a new project.
- Same semantics: decisions are evaluated exactly as they will be in production.
- Synthetic data only: never send real customer records, names or identifiers.
Keep your sandbox key out of the repository:
# .env.local (gitignored)
REQLO_API_KEY=rq_test_...Policy tests
Test files live in reqlo/tests and list cases. reqlo policies test evaluates them against your local policy
files with the same engine as the API, offline, so it is safe in every pull request. Each case is a full request plus
the expected decision, and optionally the reason code.
cases:
- name: deploy main to staging
agent: { id: agt_ci_deployer, tags: [ci] }
subject: { id: usr_55, kind: user }
action: deployments.create
resource: { type: environment, id: env_staging, attributes: { environment_type: staging } }
context: { repository_id: repo_api, branch: main }
expect: allow
- name: never read production secrets
agent: { id: agt_ci_deployer, tags: [ci] }
action: secrets.read
resource: { type: secret, id: sec_db_prod, attributes: { environment_type: production } }
expect: deny
reason_code: policy_deniedGive each case the agent's tags, because tag rules match on them.
Guidelines
- Use obviously fake IDs (
usr_55,cus_2031) and example domains (example.com). - Cover every rule: at least one case it allows or denies, and one just outside its boundary.
- Include a case with each optional attribute missing, to catch missing-attribute gaps.
- Keep tests next to the policies they test and review them together.
Allow and deny tests
Policy tests prove rules are right. Integration tests prove your code obeys them.
import { describe, expect, it, vi } from "vitest";
describe("tickets.reply tool", () => {
it("sends when allowed", async () => {
reqloMock.next({ decision: "allow", allowed: true, reason_code: "policy_allowed" });
const send = vi.spyOn(email, "send");
await replyTool({ ticketId: "tkt_1", text: "Hi" }, ctx);
expect(send).toHaveBeenCalledOnce();
});
it("does not send when denied", async () => {
reqloMock.next({ decision: "deny", allowed: false, reason_code: "policy_denied" });
const send = vi.spyOn(email, "send");
const result = await replyTool({ ticketId: "tkt_2", text: "Hi" }, ctx);
expect(send).not.toHaveBeenCalled();
expect(result).toEqual({ error: "This action isn't allowed." });
});
it("does not send when approval is required", async () => {
reqloMock.next({ decision: "approval_required", allowed: false, reason_code: "approval_required", approval: { id: "apr_1", status: "pending" } });
const send = vi.spyOn(email, "send");
await replyTool({ ticketId: "tkt_3", text: "Hi" }, ctx);
expect(send).not.toHaveBeenCalled();
});
});reqloMock can be a small fake that points the SDK's baseUrl at a local server returning queued responses. Also
run a few tests against the real sandbox to catch schema mismatches.
Delegation cases
For each delegated workflow, test:
| Case | Expected |
|---|---|
| Valid delegation covering the action | allow |
No delegation_id when the rule requires one | deny, delegation_required |
| Delegation for a different agent or subject | deny, delegation_invalid |
| Action not in the delegation | deny, delegation_scope_exceeded |
| Expired delegation | deny, delegation_expired |
| Revoked delegation | deny, delegation_revoked |
| Subject lacks the permission themselves | deny (delegation never widens access) |
Create sandbox delegations with short expiries (for example, one minute) to test expiry without waiting.
Approval cases
| Case | Expected |
|---|---|
Request matching a require_approval rule | approval_required with a pending approval |
| Redeem before resolution | deny, approval_pending |
| Approve, redeem with identical request | allow, approval_redeemed |
| Redeem a second time | deny, approval_consumed |
| Approve, redeem with a changed attribute | deny, approval_mismatch |
| Reject, then redeem | deny, approval_rejected |
| Let it expire, then redeem | deny, approval_expired |
| Approver not on the channel | 403 approver_not_allowed |
Also test that your code doesn't execute the action at any point before a successful redemption.
Fault injection
Simulate each failure and assert the action doesn't run:
| Fault | How to simulate |
|---|---|
| Timeout | Set the SDK timeoutMs to 1, or point baseUrl at a server that never responds |
| Connection refused | Point baseUrl at a closed port |
| 500 / 503 | Mock server returns 5xx |
| 429 | Mock server returns 429 with Retry-After |
| Revoked key | Use a revoked sandbox key |
| Invalid request | Send an unregistered action |
it("does not execute when ReQlo times out", async () => {
const reqlo = new Reqlo({ apiKey: "rq_test_fake", baseUrl: "http://127.0.0.1:9", timeoutMs: 50, maxRetries: 0 });
const send = vi.spyOn(email, "send");
await expect(replyToolWith(reqlo, args, ctx)).rejects.toThrow();
expect(send).not.toHaveBeenCalled();
});Run these in CI. A regression here is a security bug.
Debugging
- Error or decision? HTTP errors have an
error.code(see Errors). Denials are 200 responses with areason_code(see reason codes). - Check the project. Most
agent_unknownandaction_unknownproblems are a key from one project used with agents or actions registered in another. Each project's key only sees its own environment. - Open the decision. In Observability, select the check to see its reason code, matched rules and policy version.
- Reproduce locally. Copy the request into a case in
reqlo/testsand runreqlo policies testto see the decision and matched rules without calling ReQlo. - Check attributes. Missing or mistyped attributes are the most common cause of unexpected denies.
When asking for help, share the request_id and decision_id, never keys or real personal data.
Something wrong or unclear? Report an issue with this page.