agenttest

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: Apache-2.0 Imports: 18 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package agenttest is the conformance kit for agent modules: an in-memory Host and a suite every module must pass.

Index

Constants

View Source
const FailEnv = "FAKE_CLOUD_FAIL"

FailEnv is the variable RunCloud sets in a run's RunOptions.Env to make the stand-in driver fail like the vendor's: "signed-out", "not-eligible", "repo-mismatch" (a send), or "bad-record" (one unreadable record in a listing). The programs given to RunCloud must honour it.

View Source
const LineageSuffix = ".hopsesh.json"

LineageSuffix is the core's lineage manifest name beside a session's main file; agents must ignore such files.

Variables

This section is empty.

Functions

func Run

func Run(t *testing.T, m agent.Module, newHost func(t *testing.T) *FakeHost)

Run checks a module against the contract. newHost returns a machine with the module's test sessions on it (at least one), the agent's binary present and its roots resolved from the Spec's defaults.

func RunCloud added in v0.4.0

func RunCloud(t *testing.T, m agent.Module, programs Programs)

RunCloud checks a module's clouds against the contract, with programs standing in for its drivers (they answer the binaries' version arguments too). Every module with Spec.Clouds runs it; a module that declares clouds as data only passes the Spec checks. For each cloud and each capability the module implements, it starts a session (or uses a seeded one, or the first listed), lists it, follows up, fetches and archives it, then checks that the vendor's refusals map onto ErrSignedOut, ErrNotEligible and ErrRepoUnsupported and that a listing survives an unreadable record. A module that adopts what its driver writes reports nothing before the driver ran; a module that reads links reads back its own; a module that tests its cloud refuses a login the cloud cannot use. Throughout, the drivers run only through the confined Host, with no credential in an argument or a variable.

func RunCloudWith added in v0.4.0

func RunCloudWith(t *testing.T, m agent.Module, programs Programs, o CloudOptions)

RunCloudWith is RunCloud with options.

Types

type CloudOptions added in v0.4.0

type CloudOptions struct {
	// Seed adds a session to the programs' cloud, as if the user had started it there, and
	// returns its id; RunCloud then passes it in CloudQuery.Known. For a module without
	// CloudSender.
	Seed func(cloud string) agent.SessionID
	// Request is the hand-off RunCloud sends, for a driver that starts from a real checkout
	// (claude --cloud clones the current branch of Dir's repository); nil: a made-up one.
	Request func(c agent.Cloud) agent.SendRequest
	// Step runs a terminal step (a SendCloud's Sent.Run) the way the user's terminal would,
	// answering what the driver asks as the user would, and returns what it printed. For
	// a module whose SendCloud returns one; RunCloud adds FailEnv to the command's Env when
	// it plays a failure.
	Step func(c agent.Command) agent.StepOutput
	// Work plays the cloud's agent on the session SendCloud started, before RunCloud fetches
	// it: a cloud that has nothing to bring until its agent worked (a patch) needs it; nil
	// fetches the session as it was sent.
	Work func(cloud string, id agent.SessionID)
}

CloudOptions adapt RunCloud to a cloud whose CLI can neither start a session from hopsesh nor list them on its own (Claude Code's teleport needs to be told which).

type FakeHost

type FakeHost struct {

	// Programs answer Exec.Run by binary name (argv[0] after resolution is the fake path
	// "/bin/<name>").
	Programs map[string]func(argv []string, o agent.RunOptions) agent.Result
	// LocksHeld and PIDs simulate lock files and processes; LockHolders and PIDNames say
	// which process holds a lock and what it is (a terminated process releases its locks).
	LocksHeld   map[string]bool
	PIDs        map[int]bool
	LockHolders map[string][]int
	PIDNames    map[int]string
	// PIDCommands are processes' command lines (ProcCommands); nil leaves it unsupported.
	PIDCommands map[int]string
	// Writes records every write, in order.
	Writes []string
	// contains filtered or unexported fields
}

FakeHost is an in-memory POSIX machine.

func NewFakeHost

func NewFakeHost(home string) *FakeHost

NewFakeHost returns an empty machine with the given home folder.

func (*FakeHost) AddBinary

func (h *FakeHost) AddBinary(name, versionLine string)

AddBinary makes a binary present with a version line.

func (*FakeHost) AddBinaryAt added in v0.5.0

func (h *FakeHost) AddBinaryAt(name, p, versionLine string)

AddBinaryAt makes a binary present at an absolute path with a version line.

func (*FakeHost) Exec

func (h *FakeHost) Exec() agent.Exec

func (*FakeHost) FS

func (h *FakeHost) FS() agent.FS

func (*FakeHost) Facts

func (h *FakeHost) Facts() agent.Facts

func (*FakeHost) Get

func (h *FakeHost) Get(p string) ([]byte, bool)

Get returns a file's content.

func (*FakeHost) Load

func (h *FakeHost) Load(dir, dest string) error

Load copies a folder from disk (test data) to dest, keeping relative paths.

func (*FakeHost) Locks

func (h *FakeHost) Locks() agent.Locks

func (*FakeHost) Log

func (h *FakeHost) Log() *slog.Logger

func (*FakeHost) Path

func (h *FakeHost) Path() agent.Path

func (*FakeHost) Paths

func (h *FakeHost) Paths() []string

Paths lists every file, sorted.

func (*FakeHost) Procs

func (h *FakeHost) Procs() agent.Procs

func (*FakeHost) Put

func (h *FakeHost) Put(p string, data []byte, mtime time.Time)

Put creates a file (and its folders) with a modification time.

func (*FakeHost) SetEnv

func (h *FakeHost) SetEnv(k, v string)

SetEnv sets a variable the module's Spec declares.

type Programs added in v0.4.0

type Programs = map[string]func(argv []string, o agent.RunOptions) agent.Result

Programs answer a module's binaries in a FakeHost (FakeHost.Programs).

Jump to

Keyboard shortcuts

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