Test weft agents
Start with a scripted model. wefttest.Script plays the model turns you write, so a test runs your real agent, its tools and its middleware offline, with no key and the same result every time. Move up only when a question needs more: record a real model once and replay it when you need what a model really said, save a Studio run as a test when the run you want already happened, and run the conformance suite when you write a provider adapter.
wefttest is to agents what net/http/httptest is to handlers: a test double at the weft.Model seam, so nothing in the loop knows it is under test.
Which test answers which question
Section titled “Which test answers which question”| Question | Test | Network | Page |
|---|---|---|---|
| Does my agent call the right tool, recover from a failure, stop when it should? | wefttest.Script | never | Test an agent with a scripted model |
| Did this output change? | wefttest.Golden | never | Golden files |
| What does my agent do with what a real model said? | wefttest.Record once, wefttest.Replay in CI | once, when you record | Record a real conversation once, replay it forever |
| Does the run I just watched in Studio still pass? | Save as test, or weft export --wefttest | never | Turn a Studio run into a test |
| Does my adapter speak the provider’s wire format? | wefttest/conformance | only with -tags live | Prove a provider adapter with the conformance suite |
The two replay layers answer different questions. Application replay records model events at the Model seam, so a fixture replays the same whichever adapter recorded it. Adapter conformance records the provider’s wire bytes, because an adapter bug lives between the bytes and the events. Neither replaces the other.
Keep every suite offline
Section titled “Keep every suite offline”Run tests with the kill switch set:
WEFT_MODEL_REQUESTS=deny go test ./...Every first-party adapter then refuses to call its provider with a client it built from credentials, so an accidental live call fails the test. wefttest models ignore the switch, and a client you inject with an adapter’s Client(c) option stays reachable, so scripted, replayed and httptest-backed tests all keep working. Never reach the network has the rules.
In this section
Section titled “In this section”- Test an agent with a scripted model: script tool calls, text, failures and usage; inspect the requests the model saw; check middleware forwards
Info. - Record a real conversation once, replay it forever: the recording switch, the fixture file, what a request is matched on, and what a miss looks like.
- Turn a Studio run into a test: the generated replay test, steered and compacted steps,
weft export --wefttest. - Prove a provider adapter with the conformance suite: the cases,
Caps, the fixture servers, live runs andmake fuzz.
Every example on these pages is a test in docs-site/examples/testing that runs under WEFT_MODEL_REQUESTS=deny.