chattest

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: MIT Imports: 13 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package chattest provides a scripted Client for testing users of chat.Client, plus a stream contract checker.

Index

Constants

View Source
const SampleImageURL = "https://raw.githubusercontent.com/github/explore/main/topics/go/go.png"

SampleImageURL is a public image (the Go logo) for testing URL media input. Whether a provider can fetch it is up to the provider: some sites reject them via robots.txt or access rules, so verify every provider when changing it.

Variables

This section is empty.

Functions

func CheckMediaInput

func CheckMediaInput(t *testing.T, client chat.Client)

CheckMediaInput tests media input against a real model: a URL image and an inline PDF go in with the user message, then a tool result returns another PDF. Both answers are logged and checked.

func CheckStream

func CheckStream(events []chat.Event) error

CheckStream checks that an event sequence honors the chat.Client stream contract, for provider contract tests.

func EnvKey

func EnvKey(t testing.TB, envVar, yamlKey string) string

EnvKey reads a key for integration tests: first the environment variable envVar, then yamlKey in an env.yaml found in the current or a parent directory. It skips the test when neither exists. env.yaml is a local file ignored by git.

func LookupKey

func LookupKey(envVar, yamlKey string) string

LookupKey finds a key with the same rules as EnvKey, returning an empty string when not found.

func Record

func Record(events iter.Seq[chat.Event]) []chat.Event

Record consumes an event sequence and returns all events. The Message in an event is a live object, so only the events themselves are kept; the final message comes from the terminal event's Message.

func TextPDF

func TextPDF(line string) []byte

TextPDF builds a minimal PDF with a single line of text; line must be ASCII.

Types

type Client

type Client struct {
	Model   chat.ModelInfo
	Scripts []Script
	// contains filtered or unexported fields
}

Client is a chat.Client that runs scripts in order and records the requests it receives.

func NewClient

func NewClient(scripts ...Script) *Client

NewClient creates a Client that runs scripts in order. Once the scripts run out, later calls produce an empty reply.

func (*Client) Info

func (c *Client) Info() chat.ModelInfo

func (*Client) Requests

func (c *Client) Requests() []chat.Request

Requests returns a copy of the requests received so far.

func (*Client) Stream

func (c *Client) Stream(ctx context.Context, req chat.Request) iter.Seq[chat.Event]

type Script

type Script func(ctx context.Context, b *chat.Builder)

Script describes what one model call produces. If the script returns without a terminal event, Done is emitted.

func CallTools

func CallTools(calls ...chat.ToolCall) Script

CallTools produces tool calls and finishes with tool_use.

func Fail

func Fail(err error) Script

Fail produces a failing terminal event.

func Gate

func Gate(started chan<- struct{}, release <-chan struct{}, next Script) Script

Gate notifies started before running next, then waits for release or for ctx to end; when ctx ends it fails as canceled.

func Say

func Say(text string) Script

Say produces some text and finishes normally.

func SayAndCall

func SayAndCall(text string, calls ...chat.ToolCall) Script

SayAndCall produces text followed by tool calls.

Jump to

Keyboard shortcuts

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