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 and each Send, Steer, Respond, Cancel, SetModel 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 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) 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) Request() agentapi.OpenRequest
- func (c *Conversation) Respond(ctx context.Context, id string, answer agentapi.Answer) error
- func (c *Conversation) Responds() []Response
- func (c *Conversation) Send(ctx context.Context, prompt string) 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) 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) Steer(ctx context.Context, prompt string) error
- func (c *Conversation) Steers() []string
- func (c *Conversation) SubagentCancels() []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) 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) SetCheckError(err 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) Shutdown(context.Context) error
- func (p *Provider) ShutdownCalls() int
- func (p *Provider) WaitOpened(timeout time.Duration) *Conversation
- type Response
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
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) 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) 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) 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) 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) 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.
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) 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) SetCheckError ¶
SetCheckError makes Check fail with err (nil restores success).
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) ShutdownCalls ¶
ShutdownCalls reports how often Shutdown ran.
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.