agenttest

package
v0.8.0-beta.1 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2026 License: MIT Imports: 5 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 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

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) 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) 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) 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) Send

func (c *Conversation) Send(ctx context.Context, prompt string) 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) 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) Steer

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

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) 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) 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) SetCheckError

func (p *Provider) SetCheckError(err error)

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

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) Shutdown

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

func (*Provider) ShutdownCalls

func (p *Provider) ShutdownCalls() int

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.

type Response

type Response struct {
	InteractionID string
	Answer        agentapi.Answer
}

Response is one recorded Respond call.

Jump to

Keyboard shortcuts

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