Agent Test Fixtures
About 40 min
Goal
By the end of this lesson, you can build deterministic agent-trajectory fixtures and explain which controller behaviors they protect when the implementation or external services change.
Turn agent behavior into known cases
Agent systems can appear difficult to test because model outputs vary and tools may depend on external services. The solution is not to give up on deterministic tests. Instead, test the harness with fixtures: fixed inputs, fixed model proposals, fixed tool outcomes, and expected controller behavior.
A fixture is a known scenario. For example, one fixture may describe a successful order lookup. Another may describe an expired approval, a duplicate side-effect delivery, or a child task that exceeds its budget. The harness runs against these fixed events and should produce the expected transitions and metrics.
Fixtures are especially useful for boundaries the model does not own. Permission checks, state transitions, retry classification, idempotency handling, memory policy, queue recovery, and release rules should be deterministic. A live model is not required to prove that an unauthorized refund is rejected.
{"case_id":"expired-approval","role":"support","action":"refund","approval_expired":true,"expected":"deny"}
Make fixtures recomputable
Good fixtures contain enough information to reproduce the decision. A tool failure fixture should say which attempt failed, what error class occurred, and what operation ID was used. A retry test that only says 'something went wrong' cannot verify precise recovery behavior.
Negative fixtures are as important as passing fixtures. A test suite should intentionally include stale approvals, unauthorized tools, malformed child results, duplicate messages, and continued execution after a stop condition. The test should fail if the harness incorrectly accepts those cases.
Do not encode the answer only in a trusted boolean inside the fixture. If a fixture says authorized:false, a strong validator should recompute authorization from role and policy rather than trusting that label. This prevents the test data from accidentally grading itself.
Use small failures to protect refactors
Fixtures also protect refactoring. You may replace a queue implementation or reorganize controller classes while expecting the same externally visible behavior. If the fixtures still pass, the refactor preserved the tested contract.
Keep fixture scope understandable. One giant scenario with thirty intertwined failures is hard to debug. Prefer small cases that isolate one boundary, plus a few end-to-end integration fixtures that test interactions between boundaries.
Later, simulation will vary inputs across many runs. Fixtures come first because they establish exact known cases. They answer 'does this specific safety and recovery rule work?' before simulation asks 'how often does the system remain reliable across a range of conditions?'
Predict
Run the local Lab
Run:
python labs/notebooks/level-12/l12-09-test-fixtures.py
The Lab runs a passing fixture (ok) and a failing fixture (unauthorized). Each fixture also stores a derived authorized field, which the validator ignores.
- Run it unchanged. The
unauthorizedline ends withvalid=False (rule: reader may not execute refund_order): that is the rule that rejects the failure. - Before editing, predict whether changing the stored field can make the unauthorized fixture pass.
- In the
unauthorizedfixture, change only"authorized":Falseto"authorized":Trueand rerun. - The line now reads
stored authorized=True recomputed authorized=False valid=False. The validator still rejects the fixture, because it recomputes permission from the rawroleandactiondata.
Loading lab…
Quick Check
Explain it back
Describe three fixtures for the same side-effecting tool: one success, one retry-safe timeout, and one unauthorized attempt. State what the validator should recompute in each case.
Check your explanation
A strong answer mentions:
- Success fixture: a permitted side effect completes once; recompute final state and number of applied operations from raw events.
- Timeout fixture: the first response is lost; recompute that the stable operation ID prevents duplicate effects after recovery.
- Unauthorized fixture: policy rejects the proposal; recompute that no tool side effect occurred and the terminal reason records denial.
Key Takeaways
- Deterministic fixtures make harness behavior repeatable.
- Test controller boundaries without requiring a live model.
- Include negative cases for important failures.
- Recompute critical derived facts from raw evidence.
- Use small focused fixtures plus a few integration scenarios.
Next Lesson
Next, L12.10 — Simulation-Based Evaluation expands exact fixtures into controlled families of delays, failures, and user behavior.
References
- Liu et al., AgentBench.
Completion is stored locally on this device.