Documentation
¶
Overview ¶
Package agenttest is the conformance kit for agent modules: an in-memory Host and a suite every module must pass.
Index ¶
- Constants
- func Run(t *testing.T, m agent.Module, newHost func(t *testing.T) *FakeHost)
- func RunCloud(t *testing.T, m agent.Module, programs Programs)
- func RunCloudWith(t *testing.T, m agent.Module, programs Programs, o CloudOptions)
- type CloudOptions
- type FakeHost
- func (h *FakeHost) AddBinary(name, versionLine string)
- func (h *FakeHost) Exec() agent.Exec
- func (h *FakeHost) FS() agent.FS
- func (h *FakeHost) Facts() agent.Facts
- func (h *FakeHost) Get(p string) ([]byte, bool)
- func (h *FakeHost) Load(dir, dest string) error
- func (h *FakeHost) Locks() agent.Locks
- func (h *FakeHost) Log() *slog.Logger
- func (h *FakeHost) Path() agent.Path
- func (h *FakeHost) Paths() []string
- func (h *FakeHost) Procs() agent.Procs
- func (h *FakeHost) Put(p string, data []byte, mtime time.Time)
- func (h *FakeHost) SetEnv(k, v string)
- type Programs
Constants ¶
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.
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 ¶
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
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
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
// Writes records every write, in order.
Writes []string
// contains filtered or unexported fields
}
FakeHost is an in-memory POSIX machine.
func NewFakeHost ¶
NewFakeHost returns an empty machine with the given home folder.