Help us shape the future of Go! Take the 2026 Go Developer Survey

wefttest

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 11, 2026 License: MIT Imports: 13 Imported by: 8

Documentation

Overview

Package wefttest provides a scriptable weft.Model, in the spirit of httptest: write the agent's dialogue as a sequence of scripted model steps and test agents offline, deterministically, with no network.

Index

Constants

This section is empty.

Variables

View Source
var ErrScriptExhausted = errors.New("wefttest: model script exhausted (agent made more model calls than the script provides)")

ErrScriptExhausted is the stream error a Model yields when the agent makes more model calls than the script provides — almost always a test bug worth failing loudly.

Functions

func Golden

func Golden(t testing.TB, path string, got []byte)

Golden compares got against the committed golden file at path. With -update it writes got (creating parent directories); otherwise a mismatch fails the test with a line diff, and a missing file fails with a hint to regenerate. Note the flag goes after the package list (`go test ./... -update`): placed before it, the go tool routes it to the wrong package's binary.

func TestManifest(t *testing.T) {
	b, err := weft.Manifest(newAgent())
	if err != nil { t.Fatal(err) }
	wefttest.Golden(t, "weft.json", b)
}

Types

type Call

type Call struct {
	Name string
	Args string // raw JSON; "{}" when empty
	ID   string // optional; "call_N" within the turn when empty
}

Call describes one scripted tool invocation.

type Model

type Model struct {
	// contains filtered or unexported fields
}

Model is a scripted weft.Model. It plays one Turn per Stream call, in order, and records every ModelRequest it received for assertions.

func Script

func Script(turns ...Turn) *Model

Script returns a Model that plays the turns in order.

func (*Model) Info

func (*Model) Info() weft.ModelInfo

Info identifies the scripted model, so RunStart.Model and manifests carry a non-zero value in tests.

func (*Model) Requests

func (m *Model) Requests() []weft.ModelRequest

Requests returns every ModelRequest the agent sent, in order — assert on system prompts, transcript shape, and the tool catalog the model saw.

func (*Model) Stream

Stream implements weft.Model.

type Turn

type Turn struct {
	// contains filtered or unexported fields
}

Turn is the script for one model call, built by Say, ToolCalls, or Fail.

func Fail

func Fail(err error) Turn

Fail scripts a model failure: the stream errors immediately with err.

func MaxTokens

func MaxTokens(text string) Turn

MaxTokens scripts a step that hit the output-token limit: the text so far, then a max_tokens finish. The run records it on RunResult.StopReason (and the StepRecord) rather than failing; truncated tool-call arguments decode as error results the model recovers from.

func Say

func Say(text string) Turn

Say scripts a completed assistant reply: one text delta, then a normal stop. Usage is fixed at 10 input / 5 output tokens per scripted step, so usage accounting is assertable.

func Think

func Think(text string, then Turn) Turn

Think prefixes then with a scripted reasoning delta: Think("plan", ToolCalls(...)) is a step that reasons and then requests tools. The reasoning carries no signature; signed blocks are scripted with raw model events.

func ToolCalls

func ToolCalls(calls ...Call) Turn

ToolCalls scripts a step that requests tool calls. Call IDs are assigned "call_1", "call_2", ... within the turn unless set explicitly.

Directories

Path Synopsis
Package conformance is the provider adapter contract as an executable table.
Package conformance is the provider adapter contract as an executable table.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL