Skip to content

Test weft agents

View as Markdown

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.

QuestionTestNetworkPage
Does my agent call the right tool, recover from a failure, stop when it should?wefttest.ScriptneverTest an agent with a scripted model
Did this output change?wefttest.GoldenneverGolden files
What does my agent do with what a real model said?wefttest.Record once, wefttest.Replay in CIonce, when you recordRecord a real conversation once, replay it forever
Does the run I just watched in Studio still pass?Save as test, or weft export --wefttestneverTurn a Studio run into a test
Does my adapter speak the provider’s wire format?wefttest/conformanceonly with -tags liveProve 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.

Run tests with the kill switch set:

Terminal window
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.

Every example on these pages is a test in docs-site/examples/testing that runs under WEFT_MODEL_REQUESTS=deny.