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
- func Allow(context.Context, core.BeforeToolCallContext) core.BeforeToolCallDecision
- func AssistantWithTools(reason core.StopReason, blocks ...core.ContentBlock) core.AssistantMessage
- func Attending(name string, m *Meeting, mode core.ExecutionMode) core.Tool
- func BlockIf(cond func(core.BeforeToolCallContext) bool, terminate bool) core.BeforeToolCall
- func Child(name string) core.Tool
- func EchoTool(name string, calls *atomic.Int32) core.Tool
- func Executions(evs []core.Event) (starts, ends, results map[string]int)
- func Named(name string, reach ...core.Tool) core.Tool
- func Noop(context.Context, json.RawMessage) (json.RawMessage, error)
- func NoopAfter(context.Context, core.AfterToolCallContext) core.AfterToolCallDecision
- func Returning(name string, res core.ToolResult) core.Tool
- func TestModel() *core.Model
- func Tool(name string, run func(ctx context.Context, in json.RawMessage) core.ToolResult) core.Tool
- func ToolUse(t *testing.T, id, name, args string) core.ToolUseBlock
- func Uses(names ...string) []core.ToolUseBlock
- func Voter(name string) core.Tool
- func Wrapper(name string, body func(ctx context.Context) core.ToolResult, ...) core.Tool
- type EventLog
- type GuardLog
- type Meeting
- type Scripted
Constants ¶
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
func Allow(context.Context, core.BeforeToolCallContext) core.BeforeToolCallDecision
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 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 Executions ¶ added in v0.10.0
Executions counts, per call id, the start, end and result events.
func Noop ¶ added in v0.10.0
func Noop(context.Context, json.RawMessage) (json.RawMessage, error)
Noop is a handler that does nothing.
func NoopAfter ¶ added in v0.10.0
func NoopAfter(context.Context, core.AfterToolCallContext) core.AfterToolCallDecision
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 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.
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.
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
func (g *GuardLog) Guard(_ context.Context, in core.BeforeToolCallContext) core.BeforeToolCallDecision
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
Meet is a meeting of n attendees, each waiting up to wait for the others.
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.