---
title: Test weft agents
description: 'Which test to write first for a weft agent: a scripted model for behaviour, record and replay for real model output, a Studio run saved as a test, and the conformance suite for adapters, all offline under WEFT_MODEL_REQUESTS=deny.'
url: https://weftgo.dev/docs/testing/
type: concept
sources:
  - weft/README.md:1039-1064 (Testing, in reach order)
  - weft/AGENTS.md:637-654 (test offline, replay, conformance, fuzz, the deny switch)
  - weft/wefttest/doc.go (package wefttest)
  - weft/core/wefttest/model.go:1-3 (in the spirit of httptest)
  - weft/docs/adr/0017-testing-conventions.md (two replay questions, two answers)
  - weft/docs/adr/0013-adapter-contract.md (the suite is the adapter contract)
  - weft/studio/savetest.go:17-56 (save as test)
---

# Test weft agents

Start with a scripted model. [`wefttest.Script`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/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`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2#Model) seam, so nothing in the loop knows it is under test.

## 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](https://weftgo.dev/docs/testing/scripted-models/) |
| Did this output change? | `wefttest.Golden` | never | [Golden files](https://weftgo.dev/docs/testing/record-replay/#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](https://weftgo.dev/docs/testing/record-replay/) |
| 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](https://weftgo.dev/docs/testing/studio-runs-as-tests/) |
| Does my adapter speak the provider's wire format? | `wefttest/conformance` | only with `-tags live` | [Prove a provider adapter with the conformance suite](https://weftgo.dev/docs/testing/conformance/) |

The two replay layers answer different questions. Application replay records [model events](https://weftgo.dev/docs/concepts/models/) 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

Run tests with the [kill switch](https://weftgo.dev/docs/reference/glossary/#kill-switch) set:

```sh
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](https://weftgo.dev/docs/testing/scripted-models/#never-reach-the-network) has the rules.

## In this section

- [Test an agent with a scripted model](https://weftgo.dev/docs/testing/scripted-models/): 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](https://weftgo.dev/docs/testing/record-replay/): 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](https://weftgo.dev/docs/testing/studio-runs-as-tests/): the generated replay test, steered and compacted steps, `weft export --wefttest`.
- [Prove a provider adapter with the conformance suite](https://weftgo.dev/docs/testing/conformance/): the cases, `Caps`, the fixture servers, live runs and `make fuzz`.

Every example on these pages is a test in [`docs-site/examples/testing`](https://github.com/weftgo/weftgo.dev/tree/main/docs-site/examples/testing) that runs under `WEFT_MODEL_REQUESTS=deny`.
