agenttest

package
v0.6.0-rc.1 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package agenttest provides agent environments, platform mocks, and caller contexts for tests of agents built on agentsdk.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithCaller

func WithCaller(ctx context.Context, user agentsdk.User, access agentsdk.Access) context.Context

WithCaller returns a context for an authenticated user with the given access. Identity does not determine access, so tests can model any valid combination.

func WithUser

func WithUser(ctx context.Context, user agentsdk.User) context.Context

WithUser returns a context for an authenticated user. It implies AccessUser.

Types

type Env

type Env struct {
	Agent *agentsdk.Agent
	// Airlock records calls made through the platform API.
	Airlock *MockAirlock
	// URL is the mock Airlock base URL.
	URL string
}

Env is a fully constructed test agent with its mock Airlock server.

func New

func New(t *testing.T, factory func() *agentsdk.Agent) *Env

New invokes factory first while runtime environment is cleared, then provisions a mock Airlock and test database and starts the agent. Start opens the database, validates migrations with an up, down-to-zero, up cycle from the enclosing Go module, synchronizes declarations, and runs named OnStart hooks before New returns. TEST_DB_URL is used when explicitly supplied; otherwise New starts a throwaway pgvector container. The factory may wire Agent.DB()'s late-bound handle, but database operations are unavailable until Start. `go tool air build` supplies one shared throwaway database to its serial package tests.

type MockAirlock

type MockAirlock struct {
	Server *httptest.Server

	// LLMResponse is the NDJSON response returned by the model endpoint.
	LLMResponse []byte
	// contains filtered or unexported fields
}

MockAirlock is an in-process Airlock API used by agent tests.

func NewMockAirlock

func NewMockAirlock() (*MockAirlock, string)

NewMockAirlock creates a mock Airlock server and returns its base URL.

func (*MockAirlock) Close

func (m *MockAirlock) Close()

Close shuts down the mock server.

func (*MockAirlock) Requests

func (m *MockAirlock) Requests() []MockRequest

Requests returns all recorded requests.

func (*MockAirlock) RequestsByPath

func (m *MockAirlock) RequestsByPath(prefix string) []MockRequest

RequestsByPath returns requests matching the path prefix.

func (*MockAirlock) Reset

func (m *MockAirlock) Reset()

Reset clears all recorded requests.

func (*MockAirlock) SetConnectorCommandResponse added in v0.6.0

func (m *MockAirlock) SetConnectorCommandResponse(name string, output any) error

SetConnectorCommandResponse configures the typed JSON output returned for a connector command name.

type MockRequest

type MockRequest struct {
	Method string
	Path   string
	Body   []byte
}

MockRequest records a request made to the mock Airlock server.

Jump to

Keyboard shortcuts

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