testkit

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: Apache-2.0 Imports: 9 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 testkit holds the Agent-free test doubles the root package's and the runner package's tests use, exported so a test in a package ABOVE the root (such as tools_test) can script a provider the same way. It imports core and schema only; a helper that constructed an Agent would import the root, and the root's own internal tests could not then import it.

Index

Constants

View Source
const TestAPI core.API = "test-api"

TestAPI is the wire API every scripted provider registers under.

Variables

This section is empty.

Functions

func Allow added in v0.10.0

Allow is a Guard that allows every call.

func AssistantWithTools

func AssistantWithTools(reason core.StopReason, blocks ...core.ContentBlock) core.AssistantMessage

AssistantWithTools is an assistant message carrying the given blocks.

func Attending added in v0.10.0

func Attending(name string, m *Meeting, mode core.ExecutionMode) core.Tool

Attending is a tool whose handler attends m.

func BlockIf added in v0.10.0

func BlockIf(cond func(core.BeforeToolCallContext) bool, terminate bool) core.BeforeToolCall

BlockIf is a Guard that blocks the calls cond picks.

func Child added in v0.10.0

func Child(name string) core.Tool

Child is a tool that answers with its own name and arguments.

func EchoTool

func EchoTool(name string, calls *atomic.Int32) core.Tool

EchoTool is a tool that answers {"echoed":true} and counts its calls.

func Executions added in v0.10.0

func Executions(evs []core.Event) (starts, ends, results map[string]int)

Executions counts, per call id, the start, end and result events.

func Named added in v0.10.0

func Named(name string, reach ...core.Tool) core.Tool

Named is a bare tool with a handler.

func Noop added in v0.10.0

Noop is a handler that does nothing.

func NoopAfter added in v0.10.0

NoopAfter is an after-interceptor with no opinion.

func Returning added in v0.10.0

func Returning(name string, res core.ToolResult) core.Tool

Returning is a tool that answers res.

func TestModel

func TestModel() *core.Model

TestModel is a resolved model on TestAPI.

func Tool added in v0.10.0

func Tool(name string, run func(ctx context.Context, in json.RawMessage) core.ToolResult) core.Tool

Tool is a tool taking an optional string "v" that runs run.

func ToolUse

func ToolUse(t *testing.T, id, name, args string) core.ToolUseBlock

ToolUse builds a tool_use block from raw argument bytes.

func Uses added in v0.10.0

func Uses(names ...string) []core.ToolUseBlock

Uses is one tool_use block per name, all with the id "same" and no input: a group of nested calls whose ids the caller does not choose.

func Voter added in v0.10.0

func Voter(name string) core.Tool

Voter is a tool whose result votes to end the run.

func Wrapper added in v0.10.0

func Wrapper(name string, body func(ctx context.Context) core.ToolResult, children ...core.Tool) core.Tool

Wrapper is a tool that reaches children and runs body.

Types

type EventLog added in v0.10.0

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

EventLog is a sink that keeps what it receives.

func (*EventLog) Add added in v0.10.0

func (l *EventLog) Add(e core.Event)

Add is the sink: it records e.

func (*EventLog) All added in v0.10.0

func (l *EventLog) All() []core.Event

All is a copy of what the sink received, in order.

type GuardLog added in v0.10.0

type GuardLog struct {

	// Decide answers each call; nil allows it.
	Decide func(core.BeforeToolCallContext) core.BeforeToolCallDecision
	// contains filtered or unexported fields
}

GuardLog is a Guard that records what it sees and answers with Decide.

func (*GuardLog) Calls added in v0.10.0

func (g *GuardLog) Calls() []core.BeforeToolCallContext

Calls is a copy of what the guard saw, in order.

func (*GuardLog) Guard added in v0.10.0

Guard is the core.BeforeToolCall of the log.

type Meeting added in v0.10.0

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

Meeting measures how many handlers run at once. Each attendee waits up to wait for all n to be inside together, so a parallel group meets at once and a sequential one never does.

func Meet added in v0.10.0

func Meet(n int32, wait time.Duration) *Meeting

Meet is a meeting of n attendees, each waiting up to wait for the others.

func (*Meeting) Attend added in v0.10.0

func (m *Meeting) Attend()

Attend enters the meeting, waits for the others, and leaves.

func (*Meeting) Peak added in v0.10.0

func (m *Meeting) Peak() int32

Peak is the most attendees that were inside at once.

type Scripted

type Scripted struct {
	Turns []core.AssistantMessage

	// Seen records the message list each turn was asked to complete, so a
	// test can assert what the loop actually sent and when.
	Seen []core.Messages
	// Systems records the assembled system prompt per turn.
	Systems [][]core.ContentBlock
	// contains filtered or unexported fields
}

Scripted is a provider that replays a predetermined sequence of assistant messages, one per turn, and answers "done" once the script is exhausted. It is the executable double the loop is tested against; provider/faux is the shipped, supported form of the same idea.

func (*Scripted) SentAt

func (s *Scripted) SentAt(turn int) core.Messages

SentAt returns the messages the provider was asked to complete on turn.

func (*Scripted) Stream

func (s *Scripted) Stream(ctx context.Context, req core.Request) (<-chan core.StreamEvent, error)

Stream implements core.ProviderClient.

func (*Scripted) TurnsRun

func (s *Scripted) TurnsRun() int

TurnsRun reports how many requests the double has answered.

Jump to

Keyboard shortcuts

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