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 ¶
- type CommandRun
- type Conversation
- func (c *Conversation) Cancel(ctx context.Context) error
- func (c *Conversation) CancelSubagent(ctx context.Context, agentID string) error
- func (c *Conversation) Cancels() int
- func (c *Conversation) Close(context.Context) error
- func (c *Conversation) Closes() int
- func (c *Conversation) CommandRuns() []CommandRun
- func (c *Conversation) Commands(context.Context) ([]agentapi.Command, error)
- func (c *Conversation) Diff(context.Context) ([]agentapi.FileDiff, error)
- func (c *Conversation) Emit(ev agentapi.Event)
- func (c *Conversation) EmitDelta(itemID string, kind agentapi.ItemKind, text string)
- func (c *Conversation) EmitInteraction(ix agentapi.Interaction)
- func (c *Conversation) EmitItem(item agentapi.Item)
- func (c *Conversation) EmitSubagent(sa agentapi.Subagent)
- func (c *Conversation) EmitTitle(title string)
- func (c *Conversation) EmitTurn(state agentapi.TurnState, errText string)
- func (c *Conversation) Exit(reason string)
- func (c *Conversation) History(context.Context) (agentapi.History, error)
- func (c *Conversation) ID() string
- func (c *Conversation) ModelSets() []string
- func (c *Conversation) ModelSettings() []agentapi.OpenRequest
- func (c *Conversation) PromptSubagent(ctx context.Context, agentID, text string) error
- func (c *Conversation) Prompts() []agentapi.Prompt
- func (c *Conversation) Request() agentapi.OpenRequest
- func (c *Conversation) Respond(ctx context.Context, id string, answer agentapi.Answer) error
- func (c *Conversation) Responds() []Response
- func (c *Conversation) RunCommand(ctx context.Context, name string, args agentapi.Prompt) error
- func (c *Conversation) Send(ctx context.Context, prompt agentapi.Prompt) error
- func (c *Conversation) Sends() []string
- func (c *Conversation) SetCancelError(err error)
- func (c *Conversation) SetCancelHook(hook func(ctx context.Context) error)
- func (c *Conversation) SetCancelSubagentHook(hook func(context.Context, string) error)
- func (c *Conversation) SetDiff(files []agentapi.FileDiff, err error)
- func (c *Conversation) SetModel(_ context.Context, model, effort, contextSize string) error
- func (c *Conversation) SetModelError(err error)
- func (c *Conversation) SetPromptSubagentHook(hook func(ctx context.Context, agentID, text string) error)
- func (c *Conversation) SetRespondHook(hook func(ctx context.Context, id string, answer agentapi.Answer) error)
- func (c *Conversation) SetSendHook(hook func(ctx context.Context, prompt string) error)
- func (c *Conversation) SetSteerHook(hook func(ctx context.Context, prompt string) error)
- func (c *Conversation) SetTitle(_ context.Context, title string) error
- func (c *Conversation) SetTitleError(err error)
- func (c *Conversation) Steer(ctx context.Context, prompt string) error
- func (c *Conversation) Steers() []string
- func (c *Conversation) SubagentCancels() []string
- func (c *Conversation) SubagentPrompts() []SubagentPrompt
- func (c *Conversation) Titles() []string
- type Provider
- func (p *Provider) AddConversation(id string, items []agentapi.Item, subagents ...agentapi.Subagent)
- func (p *Provider) Capabilities() agentapi.Capabilities
- func (p *Provider) Check(context.Context) error
- func (p *Provider) Conversations() []*Conversation
- func (p *Provider) DisplayName() string
- func (p *Provider) ForgetConversation(id string)
- func (p *Provider) InUse(ctx context.Context, ids []string) ([]string, error)
- func (p *Provider) InUseChecks() [][]string
- func (p *Provider) Last() *Conversation
- func (p *Provider) Models(context.Context) ([]agentapi.Model, error)
- func (p *Provider) ModelsCalls() int
- func (p *Provider) Name() string
- func (p *Provider) Open(_ context.Context, req agentapi.OpenRequest) (agentapi.Conversation, error)
- func (p *Provider) Opens() []agentapi.OpenRequest
- func (p *Provider) Previous(_ context.Context, workdir string) ([]agentapi.PreviousConversation, error)
- func (p *Provider) PreviousDirs() []string
- func (p *Provider) Quota(context.Context) ([]agentapi.Quota, error)
- func (p *Provider) QuotaCalls() int
- func (p *Provider) ReadHistory(ctx context.Context, req agentapi.ReadRequest) (agentapi.History, error)
- func (p *Provider) Reads() []agentapi.ReadRequest
- func (p *Provider) SetCheckError(err error)
- func (p *Provider) SetCommands(commands []agentapi.Command, err error)
- func (p *Provider) SetHistory(id string, h agentapi.History)
- func (p *Provider) SetHistoryUsage(id string, usage agentapi.Usage)
- func (p *Provider) SetInUse(ids []string, err error)
- func (p *Provider) SetInUseHook(hook func(context.Context, []string) ([]string, error))
- func (p *Provider) SetModels(models []agentapi.Model, err error)
- func (p *Provider) SetOpenError(err error)
- func (p *Provider) SetOpenSetModelError(err error)
- func (p *Provider) SetPrevious(list []agentapi.PreviousConversation, err error)
- func (p *Provider) SetQuota(quotas []agentapi.Quota, err error)
- func (p *Provider) SetReadHook(...)
- func (p *Provider) SetTitleHook(hook func(ctx context.Context, req agentapi.TitleRequest) (string, error))
- func (p *Provider) Shutdown(context.Context) error
- func (p *Provider) ShutdownCalls() int
- func (p *Provider) Title(ctx context.Context, req agentapi.TitleRequest) (string, error)
- func (p *Provider) TitleRequests() []agentapi.TitleRequest
- func (p *Provider) WaitOpened(timeout time.Duration) *Conversation
- type Response
- type SubagentPrompt
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CommandRun ¶
CommandRun is one recorded RunCommand call.
type Conversation ¶
type Conversation struct {
// contains filtered or unexported fields
}
Conversation is a fake agentapi.Conversation.
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) 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) 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) 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) Responds ¶
func (c *Conversation) Responds() []Response
Responds returns every Respond call, oldest first.
func (*Conversation) RunCommand ¶
RunCommand behaves like Send: the send hook decides the outcome, called with "/name arguments".
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) 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) Conversations ¶
func (p *Provider) Conversations() []*Conversation
Conversations returns every conversation opened, oldest first.
func (*Provider) DisplayName ¶
func (*Provider) ForgetConversation ¶
ForgetConversation removes a conversation so reopening it reports agentapi.ErrConversationNotFound.
func (*Provider) InUseChecks ¶
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) ModelsCalls ¶
ModelsCalls reports how often Models ran.
func (*Provider) Open ¶
func (p *Provider) Open(_ context.Context, req agentapi.OpenRequest) (agentapi.Conversation, error)
func (*Provider) Opens ¶
func (p *Provider) Opens() []agentapi.OpenRequest
Opens returns every Open request received, oldest first.
func (*Provider) PreviousDirs ¶
PreviousDirs returns the directory of every Previous call, oldest first.
func (*Provider) QuotaCalls ¶
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 ¶
SetCheckError makes Check fail with err (nil restores success).
func (*Provider) SetCommands ¶
SetCommands decides what every conversation's Commands returns.
func (*Provider) SetHistory ¶
SetHistory registers an existing provider conversation with its complete record, Model and Truncated included.
func (*Provider) SetHistoryUsage ¶
SetHistoryUsage makes History of the registered conversation id report usage.
func (*Provider) SetInUse ¶
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 (*Provider) SetOpenError ¶
SetOpenError makes every Open fail with err (nil restores success).
func (*Provider) SetOpenSetModelError ¶
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 ¶
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) ShutdownCalls ¶
ShutdownCalls reports how often Shutdown ran.
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 SubagentPrompt ¶
SubagentPrompt is one recorded PromptSubagent call.