agenttest

package
v0.10.4 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package agenttest provides a scriptable agentapi.Provider for tests of the web service. Tests drive events explicitly and decide how the model catalog, the command list and each Send, RunCommand, Steer, Respond, Cancel, SetModel, Title, SetTitle or Diff call behave; every call is recorded so a test can prove what the service did (and did not) ask the provider to do.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CommandRun

type CommandRun struct {
	Name string
	Args agentapi.Prompt
}

CommandRun is one recorded RunCommand call.

type Conversation

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

Conversation is a fake agentapi.Conversation.

func (*Conversation) Cancel

func (c *Conversation) Cancel(ctx context.Context) error

func (*Conversation) CancelSubagent

func (c *Conversation) CancelSubagent(ctx context.Context, agentID string) error

func (*Conversation) Cancels

func (c *Conversation) Cancels() int

Cancels reports how often Cancel ran.

func (*Conversation) Close

func (c *Conversation) Close(context.Context) error

func (*Conversation) Closes

func (c *Conversation) Closes() int

Closes reports how often Close ran.

func (*Conversation) CommandRuns

func (c *Conversation) CommandRuns() []CommandRun

CommandRuns returns every RunCommand call, oldest first.

func (*Conversation) Commands

func (c *Conversation) Commands(context.Context) ([]agentapi.Command, error)

func (*Conversation) Diff

func (*Conversation) Emit

func (c *Conversation) Emit(ev agentapi.Event)

Emit delivers ev to the service's sink exactly as an adapter would.

func (*Conversation) EmitDelta

func (c *Conversation) EmitDelta(itemID string, kind agentapi.ItemKind, text string)

EmitDelta appends streamed text to an item.

func (*Conversation) EmitInteraction

func (c *Conversation) EmitInteraction(ix agentapi.Interaction)

EmitInteraction upserts a permission request or question.

func (*Conversation) EmitItem

func (c *Conversation) EmitItem(item agentapi.Item)

EmitItem upserts a transcript item.

func (*Conversation) EmitSubagent

func (c *Conversation) EmitSubagent(sa agentapi.Subagent)

EmitSubagent upserts a subagent record.

func (*Conversation) EmitTitle

func (c *Conversation) EmitTitle(title string)

EmitTitle reports a provider-generated title.

func (*Conversation) EmitTurn

func (c *Conversation) EmitTurn(state agentapi.TurnState, errText string)

EmitTurn reports a turn transition.

func (*Conversation) Exit

func (c *Conversation) Exit(reason string)

Exit simulates the provider runtime exiting: the conversation becomes unusable and EventExit is delivered with reason.

func (*Conversation) History

func (*Conversation) ID

func (c *Conversation) ID() string

func (*Conversation) ModelSets

func (c *Conversation) ModelSets() []string

ModelSets returns every model passed to SetModel, oldest first.

func (*Conversation) ModelSettings

func (c *Conversation) ModelSettings() []agentapi.OpenRequest

ModelSettings returns the complete selections passed to SetModel.

func (*Conversation) PromptSubagent

func (c *Conversation) PromptSubagent(ctx context.Context, agentID, text string) error

func (*Conversation) Prompts

func (c *Conversation) Prompts() []agentapi.Prompt

Prompts returns every prompt passed to Send, with its references.

func (*Conversation) Request

func (c *Conversation) Request() agentapi.OpenRequest

Request returns the OpenRequest that produced the conversation.

func (*Conversation) Respond

func (c *Conversation) Respond(ctx context.Context, id string, answer agentapi.Answer) error

func (*Conversation) Responds

func (c *Conversation) Responds() []Response

Responds returns every Respond call, oldest first.

func (*Conversation) RunCommand

func (c *Conversation) RunCommand(ctx context.Context, name string, args agentapi.Prompt) error

RunCommand behaves like Send: the send hook decides the outcome, called with "/name arguments".

func (*Conversation) Send

func (c *Conversation) Send(ctx context.Context, prompt agentapi.Prompt) error

func (*Conversation) Sends

func (c *Conversation) Sends() []string

Sends returns every prompt passed to Send, oldest first.

func (*Conversation) SetCancelError

func (c *Conversation) SetCancelError(err error)

SetCancelError makes Cancel return err.

func (*Conversation) SetCancelHook

func (c *Conversation) SetCancelHook(hook func(ctx context.Context) error)

SetCancelHook decides how Cancel behaves, as SetSendHook does for Send.

func (*Conversation) SetCancelSubagentHook

func (c *Conversation) SetCancelSubagentHook(hook func(context.Context, string) error)

SetCancelSubagentHook decides how CancelSubagent behaves.

func (*Conversation) SetDiff

func (c *Conversation) SetDiff(files []agentapi.FileDiff, err error)

SetDiff sets what Diff returns.

func (*Conversation) SetModel

func (c *Conversation) SetModel(_ context.Context, model, effort, contextSize string) error

func (*Conversation) SetModelError

func (c *Conversation) SetModelError(err error)

SetModelError makes SetModel fail with err (nil restores success).

func (*Conversation) SetPromptSubagentHook

func (c *Conversation) SetPromptSubagentHook(hook func(ctx context.Context, agentID, text string) error)

SetPromptSubagentHook decides how PromptSubagent behaves, as SetSendHook does for Send. The fake reports no subagent status on its own.

func (*Conversation) SetRespondHook

func (c *Conversation) SetRespondHook(hook func(ctx context.Context, id string, answer agentapi.Answer) error)

SetRespondHook decides how Respond behaves.

func (*Conversation) SetSendHook

func (c *Conversation) SetSendHook(hook func(ctx context.Context, prompt string) error)

SetSendHook decides how Send behaves: return nil to accept, an error to reject, or block until the test releases it.

func (*Conversation) SetSteerHook

func (c *Conversation) SetSteerHook(hook func(ctx context.Context, prompt string) error)

SetSteerHook decides how Steer behaves, as SetSendHook does for Send.

func (*Conversation) SetTitle

func (c *Conversation) SetTitle(_ context.Context, title string) error

func (*Conversation) SetTitleError

func (c *Conversation) SetTitleError(err error)

SetTitleError makes SetTitle fail with err (nil restores success).

func (*Conversation) Steer

func (c *Conversation) Steer(ctx context.Context, prompt agentapi.Prompt) error

func (*Conversation) SteerPrompts added in v0.10.1

func (c *Conversation) SteerPrompts() []agentapi.Prompt

SteerPrompts returns every prompt passed to Steer, with its references.

func (*Conversation) Steers

func (c *Conversation) Steers() []string

Steers returns every prompt passed to Steer, oldest first.

func (*Conversation) SubagentCancels

func (c *Conversation) SubagentCancels() []string

SubagentCancels returns the exact agent IDs passed to CancelSubagent.

func (*Conversation) SubagentPrompts

func (c *Conversation) SubagentPrompts() []SubagentPrompt

SubagentPrompts returns every PromptSubagent call, oldest first.

func (*Conversation) Titles

func (c *Conversation) Titles() []string

Titles returns every title passed to SetTitle, oldest first.

type Provider

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

Provider is a fake agentapi.Provider. The zero value is not usable; call NewProvider.

func NewProvider

func NewProvider(name string, caps agentapi.Capabilities) *Provider

NewProvider returns a fake provider with the given name and capabilities.

func (*Provider) AddConversation

func (p *Provider) AddConversation(id string, items []agentapi.Item, subagents ...agentapi.Subagent)

AddConversation registers an existing provider conversation that Open may reopen by exact ID; History returns items and subagents.

func (*Provider) Capabilities

func (p *Provider) Capabilities() agentapi.Capabilities

func (*Provider) Check

func (p *Provider) Check(context.Context) error

func (*Provider) Conversations

func (p *Provider) Conversations() []*Conversation

Conversations returns every conversation opened, oldest first.

func (*Provider) DisplayName

func (p *Provider) DisplayName() string

func (*Provider) ForgetConversation

func (p *Provider) ForgetConversation(id string)

ForgetConversation removes a conversation so reopening it reports agentapi.ErrConversationNotFound.

func (*Provider) InUse

func (p *Provider) InUse(ctx context.Context, ids []string) ([]string, error)

func (*Provider) InUseChecks

func (p *Provider) InUseChecks() [][]string

InUseChecks returns the IDs of every InUse call, oldest first.

func (*Provider) Last

func (p *Provider) Last() *Conversation

Last returns the most recently opened conversation, or nil.

func (*Provider) Models

func (p *Provider) Models(context.Context) ([]agentapi.Model, error)

func (*Provider) ModelsCalls

func (p *Provider) ModelsCalls() int

ModelsCalls reports how often Models ran.

func (*Provider) Name

func (p *Provider) Name() string

func (*Provider) Open

func (*Provider) Opens

func (p *Provider) Opens() []agentapi.OpenRequest

Opens returns every Open request received, oldest first.

func (*Provider) Previous

func (p *Provider) Previous(_ context.Context, workdir string) ([]agentapi.PreviousConversation, error)

func (*Provider) PreviousDirs

func (p *Provider) PreviousDirs() []string

PreviousDirs returns the directory of every Previous call, oldest first.

func (*Provider) Quota

func (p *Provider) Quota(context.Context) ([]agentapi.Quota, error)

func (*Provider) QuotaCalls

func (p *Provider) QuotaCalls() int

QuotaCalls reports how often Quota ran.

func (*Provider) ReadHistory

func (p *Provider) ReadHistory(ctx context.Context, req agentapi.ReadRequest) (agentapi.History, error)

ReadHistory returns the record of a known conversation, or agentapi.ErrConversationNotFound; SetReadHook replaces that. Every call is recorded.

func (*Provider) Reads

func (p *Provider) Reads() []agentapi.ReadRequest

Reads returns every ReadHistory request, oldest first.

func (*Provider) SetCheckError

func (p *Provider) SetCheckError(err error)

SetCheckError makes Check fail with err (nil restores success).

func (*Provider) SetCommands

func (p *Provider) SetCommands(commands []agentapi.Command, err error)

SetCommands decides what every conversation's Commands returns.

func (*Provider) SetHistory

func (p *Provider) SetHistory(id string, h agentapi.History)

SetHistory registers an existing provider conversation with its complete record, Model and Truncated included.

func (*Provider) SetHistoryUsage

func (p *Provider) SetHistoryUsage(id string, usage agentapi.Usage)

SetHistoryUsage makes History of the registered conversation id report usage.

func (*Provider) SetInUse

func (p *Provider) SetInUse(ids []string, err error)

SetInUse decides which conversations InUse reports as held by another client (those among the asked IDs), or the error it fails with.

func (*Provider) SetInUseHook

func (p *Provider) SetInUseHook(hook func(context.Context, []string) ([]string, error))

func (*Provider) SetModels

func (p *Provider) SetModels(models []agentapi.Model, err error)

SetModels decides what Models returns.

func (*Provider) SetOpenError

func (p *Provider) SetOpenError(err error)

SetOpenError makes every Open fail with err (nil restores success).

func (*Provider) SetOpenSetModelError

func (p *Provider) SetOpenSetModelError(err error)

SetOpenSetModelError makes SetModel fail with err on conversations opened afterwards (nil restores success).

func (*Provider) SetPrevious

func (p *Provider) SetPrevious(list []agentapi.PreviousConversation, err error)

SetPrevious decides what Previous returns for any directory.

func (*Provider) SetQuota

func (p *Provider) SetQuota(quotas []agentapi.Quota, err error)

SetQuota decides what Quota returns. The service reads quotas only from a provider created with the usage capability.

func (*Provider) SetReadHook

func (p *Provider) SetReadHook(hook func(ctx context.Context, req agentapi.ReadRequest) (agentapi.History, error))

SetReadHook decides how ReadHistory behaves: return a record or an error, or block until the test releases it.

func (*Provider) SetTitleHook

func (p *Provider) SetTitleHook(hook func(ctx context.Context, req agentapi.TitleRequest) (string, error))

SetTitleHook decides how Title behaves. Without a hook Title fails. The service asks for titles only from a provider created with the titles capability.

func (*Provider) Shutdown

func (p *Provider) Shutdown(context.Context) error

func (*Provider) ShutdownCalls

func (p *Provider) ShutdownCalls() int

ShutdownCalls reports how often Shutdown ran.

func (*Provider) Title

func (p *Provider) Title(ctx context.Context, req agentapi.TitleRequest) (string, error)

func (*Provider) TitleRequests

func (p *Provider) TitleRequests() []agentapi.TitleRequest

TitleRequests returns every Title call, oldest first.

func (*Provider) WaitOpened

func (p *Provider) WaitOpened(timeout time.Duration) *Conversation

WaitOpened returns the next conversation opened after the call, or nil when timeout elapses first.

type Response

type Response struct {
	InteractionID string
	Answer        agentapi.Answer
}

Response is one recorded Respond call.

type SubagentPrompt

type SubagentPrompt struct {
	AgentID string
	Text    string
}

SubagentPrompt is one recorded PromptSubagent call.

Jump to

Keyboard shortcuts

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