testutil

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertFiles

func AssertFiles(t *testing.T, root string, expectations []FileExpectation)

AssertFiles verifies file expectations against the workspace.

func RegisterScriptedProvider

func RegisterScriptedProvider(provider *ScriptedProvider, providerName string)

RegisterScriptedProvider is a test helper that registers a ScriptedProvider as an APIClient with a matching ProviderConfig, and returns cleanup functions. The providerName is used for both the ProviderConfig name and the Model.Provider field.

func UniqueAPI

func UniqueAPI(prefix string) string

Types

type FileExpectation

type FileExpectation struct {
	Path     string // relative to workspace root
	Contains string // substring that must appear in file content
	Equals   string // exact match (if non-empty, overrides Contains)
	Absent   bool   // file must NOT exist
}

FileExpectation defines expected file state after a scenario.

type ScriptEntry

type ScriptEntry struct {
	Text       string
	ToolCalls  []ToolCallSpec
	StopReason ai.StopReason
	Error      string
}

ScriptEntry defines one provider response in a scripted conversation. If ToolCalls is set, the response will contain tool call content blocks. If Text is set, it will contain a text content block.

type ScriptedProvider

type ScriptedProvider struct {
	CallLog []ScriptedProviderCall

	// Gates allows blocking specific provider calls until signaled.
	// Key is the 0-based call index. The provider will wait on the channel
	// before returning the response for that call.
	Gates map[int]chan struct{}
	// contains filtered or unexported fields
}

ScriptedProvider is a deterministic fake AI provider that replays a pre-defined sequence of responses. Each call to Stream/StreamSimple returns the next entry in the script. If calls exceed the script length, the last entry is repeated.

Implements ai.APIClient.

func NewScriptedProvider

func NewScriptedProvider(clientType string, script []ScriptEntry) *ScriptedProvider

NewScriptedProvider creates a fake provider with the given client type and script.

func (*ScriptedProvider) Calls

func (p *ScriptedProvider) Calls() int

Calls returns the number of provider calls made.

func (*ScriptedProvider) ClientType

func (p *ScriptedProvider) ClientType() string

func (*ScriptedProvider) Stream

func (*ScriptedProvider) StreamSimple

func (p *ScriptedProvider) StreamSimple(ctx context.Context, _ ai.ProviderEndpoint, model ai.Model, llmCtx ai.Context, opts ai.SimpleStreamOptions) *ai.EventStream

type ScriptedProviderCall

type ScriptedProviderCall struct {
	Messages     []ai.Message
	Tools        []ai.Tool
	SystemPrompt string
}

ScriptedProviderCall records what the provider received.

type ToolCallSpec

type ToolCallSpec struct {
	ID        string
	Name      string
	Arguments map[string]any
}

ToolCallSpec defines a tool call within a scripted provider response.

type WorkspaceSnapshot

type WorkspaceSnapshot struct {
	Files map[string]string // relative path -> content
}

WorkspaceSnapshot captures all files in a directory tree.

func SnapshotWorkspace

func SnapshotWorkspace(root string) (*WorkspaceSnapshot, error)

SnapshotWorkspace captures the current state of a workspace.

func (*WorkspaceSnapshot) Diff

func (s *WorkspaceSnapshot) Diff(other *WorkspaceSnapshot) string

Diff returns the changes between two snapshots.

Jump to

Keyboard shortcuts

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