Documentation
¶
Overview ¶
Package agenttest provides a scriptable agent.Agent for tests of the run manager and the HTTP API. A Script plays the CLI: it reads client inputs and emits events.
Index ¶
- Constants
- func Echo(ctx context.Context, s *Session) error
- func Hook(ctx context.Context, s *Session) error
- func Permission(ctx context.Context, s *Session) error
- func Streaming(ctx context.Context, s *Session) error
- func WriteExecutable(t testing.TB, path, content string)
- type Agent
- func (*Agent) AuthStatus(context.Context) (agent.AuthStatus, error)
- func (*Agent) Info() agent.Info
- func (*Agent) Interactive(context.Context, agent.IO, agent.InteractiveCommand) error
- func (a *Agent) LastRequest() agent.Request
- func (*Agent) Name() string
- func (*Agent) ProviderSections() map[agent.Section]reflect.Type
- func (a *Agent) Start(ctx context.Context, req agent.Request, onEvent agent.EventFunc) (agent.Conversation, error)
- func (*Agent) Validate(req *agent.Request) error
- func (*Agent) Version(context.Context) (string, error)
- type ControlFields
- type Input
- type ResultFields
- type Script
- type Session
- func (s *Session) AgentTurn(text string) error
- func (s *Session) Answer(answer agent.PermissionAnswer) error
- func (s *Session) Ask(id, kind string) error
- func (s *Session) AskControl(id, subtype string) error
- func (s *Session) CloseInput() error
- func (s *Session) Control(_ context.Context, request json.RawMessage) (json.RawMessage, error)
- func (s *Session) Emit(eventType, raw string) error
- func (s *Session) Finish(text string, isError bool) error
- func (s *Session) FinishWithUsage(text string, isError bool, tokens *agent.Tokens) error
- func (s *Session) Interrupt() error
- func (s *Session) NativeSessionID() string
- func (s *Session) Next(ctx context.Context) (Input, bool)
- func (s *Session) Observe(raw string, observation agent.Observation) error
- func (s *Session) Partial(text string) error
- func (s *Session) Respond(id string, response json.RawMessage, errMessage string) error
- func (s *Session) Send(text string) error
- func (s *Session) StartTurn() error
- func (s *Session) Wait() error
Constants ¶
const ( InputMessage = "message" InputInterrupt = "interrupt" InputAnswer = "answer" InputRespond = "respond" InputClose = "close" )
Input kinds delivered to a Script.
Variables ¶
This section is empty.
Functions ¶
func Permission ¶
Permission asks for "Write" once per message and reports the decision as the result.
func WriteExecutable ¶ added in v0.2.1
WriteExecutable writes a script that a test then runs as a fake CLI.
It holds syscall.ForkLock while the file is open for writing. Without it, a parallel test can fork in that moment; the child keeps the write descriptor until it calls exec, and running the script fails on Linux with "text file busy" (ETXTBSY).
Types ¶
type Agent ¶
type Agent struct {
Script Script
Started chan agent.Request
// StartErr makes Start fail.
StartErr error
// contains filtered or unexported fields
}
Agent is a fake agent. Started receives every request when non-nil.
func (*Agent) AuthStatus ¶
AuthStatus implements agent.Agent.
func (*Agent) Interactive ¶
Interactive implements agent.Agent.
func (*Agent) LastRequest ¶
LastRequest returns the most recent request passed to Start.
func (*Agent) ProviderSections ¶
ProviderSections implements agent.SectionDescriber.
func (*Agent) Start ¶
func (a *Agent) Start(ctx context.Context, req agent.Request, onEvent agent.EventFunc) (agent.Conversation, error)
Start implements agent.Agent.
type ControlFields ¶
type ControlFields struct {
Subtype string `json:"subtype"`
}
ControlFields are the fake agent's fields of a control request's provider section.
type Input ¶
type Input struct {
Kind string
Text string
Answer agent.PermissionAnswer
// Respond fields.
ID string
Response json.RawMessage
Error string
}
Input is one client action. The initial prompt arrives as the first InputMessage.
type ResultFields ¶
type ResultFields struct {
Reason string `json:"reason"`
}
ResultFields are the fake agent's fields of a turn result's provider section.
type Session ¶
Session is the fake conversation; Scripts use Next and the emit helpers.
func (*Session) AgentTurn ¶
AgentTurn emits the terminal event of a turn the agent started on its own.
func (*Session) Answer ¶
func (s *Session) Answer(answer agent.PermissionAnswer) error
Answer implements agent.Conversation.
func (*Session) AskControl ¶
AskControl emits a generic control request.
func (*Session) CloseInput ¶
CloseInput implements agent.Conversation.
func (*Session) Control ¶
func (s *Session) Control(_ context.Context, request json.RawMessage) (json.RawMessage, error)
Control implements agent.Conversation: it answers {"echo": request}; subtype "fail" is rejected.
func (*Session) FinishWithUsage ¶
FinishWithUsage emits a terminal event with explicit token counts (nil: unreported).
func (*Session) NativeSessionID ¶
NativeSessionID implements agent.NativeSession.
func (*Session) Observe ¶
func (s *Session) Observe(raw string, observation agent.Observation) error
Observe emits a native event carrying optional structured lifecycle data.