acptest

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package acptest drives ACP in tests as an editor does: a session client and agent, a server on a real HTTP listener, and a client on a WebSocket that reads the frames in order and answers the agent's requests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Error

func Error(t *testing.T, resp map[string]any) map[string]any

Error is the error object of a response; a response with none fails the test.

func Listen

func Listen(t *testing.T, srv *server.Server) string

Listen serves srv on a test HTTP listener and returns the ws:// URL of its /acp.

func Message

func Message(t *testing.T, resp map[string]any) string

Message is the message of an error response; a response with no error fails the test.

func Result

func Result(t *testing.T, resp map[string]any) map[string]any

Result is the result object of a response; an error response fails the test.

func Server

func Server(r *Runtime, wire server.ProtocolWireStore) *server.Server

Server is an anonymous ACP server for r, with its wire state in wire (nil: in memory).

func SessionID

func SessionID(t *testing.T, resp map[string]any) string

SessionID is the sessionId a session/new response returned.

func StopReason

func StopReason(resp map[string]any) string

StopReason is the stopReason a prompt's response ends with; "" when it is an error.

func Updates

func Updates(frames []map[string]any) []map[string]any

Updates are the session/update payloads among frames, in order.

Types

type Client

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

Client is an ACP client on one WebSocket.

func Connect

func Connect(t *testing.T, url, initialize string) *Client

Connect dials url and says hello with the initialize params.

func Dial

func Dial(t *testing.T, url string, header http.Header) *Client

Dial connects to url with header and says nothing.

func Open

func Open(t *testing.T, r *Runtime) *Client

Open is a connection to a new anonymous ACP server for r that said hello.

func (*Client) Call

func (c *Client) Call(method, params string) map[string]any

Call sends method with params and returns its response.

func (*Client) Close

func (c *Client) Close()

Close closes the socket, as an editor that quits does.

func (*Client) Frame

func (c *Client) Frame() map[string]any

Frame is the next frame the agent sends.

func (*Client) NewSession

func (c *Client) NewSession(cwd string) string

NewSession makes a session in cwd and returns its id.

func (*Client) Prompt

func (c *Client) Prompt(sid, blocks string) int

Prompt sends blocks (a JSON array of content blocks) to session sid and returns the request id.

func (*Client) Request

func (c *Client) Request(method, params string) int

Request sends method with params and returns its id.

func (*Client) Say

func (c *Client) Say(sid, text string) (map[string]any, []map[string]any)

Say sends text to session sid and returns how the turn ended and the frames before.

func (*Client) Send

func (c *Client) Send(body string)

Send writes one frame.

func (*Client) Until

func (c *Client) Until(id int, answer func(req map[string]any) any) (map[string]any, []map[string]any)

Until reads frames until the response to id, answering each request the agent makes with answer, and returns that response and the frames before it. A request with no answer fails the test.

func (*Client) Use

func (c *Client) Use(t *testing.T) *Client

Use makes the client's failures fail t.

type Runtime

type Runtime struct {
	Client    session.Client
	Agent     tacklr.AgentOptions
	Workspace bool
}

Runtime is the session client and agent an ACP request runs against. Workspace says the sessions have a workspace, so clients may bind to it.

func NewRuntime

func NewRuntime(t *testing.T, model tacklr.Model, spec tacklr.AgentOptions) *Runtime

NewRuntime runs spec on the live Temporal stack, with no workspace. A nil spec.Model takes model, else a model that sends nothing; the window and system prompt get test defaults.

func NewWorkspaceRuntime

func NewWorkspaceRuntime(t *testing.T, model tacklr.Model, spec tacklr.AgentOptions, ws workspace.Config) *Runtime

NewWorkspaceRuntime is NewRuntime with ws as the agent's workspace.

Jump to

Keyboard shortcuts

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