agenttest

package
v0.4.0-rc.18 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package agenttest provides helpers for testing agents built on agentsdk. It lives in its own package so the testing dependency it pulls in never reaches an agent's production binary — agents import it only from _test.go.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func UseDB

func UseDB(t *testing.T, a *agentsdk.Agent)

UseDB brings the database configured by NewDBEnv to a clean, fully-migrated state.

It resets the schema — goose down to 0, then up — applying db/migrations. Go migrations run with the agent attached, exactly as in production. Call it after constructing the agent and before using agent.DB():

env := agenttest.NewDBEnv(t)
a := newAgent()
agenttest.UseDB(t, a)
// a.DB() now points at a freshly migrated test schema

Types

type Env

type Env struct {
	// Airlock is the mock Airlock server. Inspect Airlock.Requests() to
	// assert on the calls a handler made.
	Airlock *agentsdk.MockAirlock
	// URL is the mock Airlock's base URL (also set as AIRLOCK_API_URL).
	URL string
}

Env is a test environment for an agent: a mock Airlock server plus the AIRLOCK_* environment variables wired to point at it.

func NewDBEnv

func NewDBEnv(t *testing.T) *Env

NewDBEnv starts a test environment with a PostgreSQL database. It uses the database supplied by Airlock in TEST_DB_URL when available. Otherwise it starts a throwaway pgvector container and skips the test when Docker is not available. Call it before constructing the agent so dependencies may cache agent.DB() safely.

func NewEnv

func NewEnv(t *testing.T) *Env

NewEnv starts a mock Airlock and sets the environment variables agentsdk.New requires (AIRLOCK_API_URL, AIRLOCK_AGENT_ID, AIRLOCK_AGENT_TOKEN) to point at it. Call it before constructing the agent. The mock server and the env vars are torn down automatically when the test ends.

When Airlock provisions a test database in TEST_DB_URL, NewEnv also sets AIRLOCK_DB_URL before the caller builds the agent. DB-backed tests should use NewDBEnv, which additionally provisions a local database when needed.

Jump to

Keyboard shortcuts

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