Documentation
¶
Overview ¶
Package agenttoolstest is an in-memory fake of the parts of sandboxd the aerolvm CLI and MCP server use: v1 sandboxes (create, get, list by name, start, destroy, ports), the toolbox file and exec endpoints, the exec WebSocket, and sessions. Tests in agenttools, agentmcp and cmd/aerolvm share it so the three layers are checked against the same wire behaviour. It never imports server packages.
Index ¶
- Constants
- func Interpret(cmd string, in io.Reader, out func(byte, []byte), killed <-chan struct{}) (int, string)
- type Exec
- type ExecStart
- type Sandbox
- type Server
- func (s *Server) AddSandbox(sb models.Sandbox) *Sandbox
- func (s *Server) AddSession(sandboxID string, session models.Session)
- func (s *Server) AppendSessionLog(sandboxID, sessionID string, b []byte)
- func (s *Server) Count() int
- func (s *Server) File(id, path string) ([]byte, bool)
- func (s *Server) Observe(fn func(*Server))
- func (s *Server) PutFile(id, path string, data []byte)
- func (s *Server) Remove(id string)
- func (s *Server) Sandbox(id string) (models.Sandbox, bool)
- func (s *Server) SetStatus(id string, status models.SandboxStatus)
- type Session
Constants ¶
const DropStream = "\x00drop"
DropStream, returned as the signal from an Exec, makes the fake close the exec stream without an exit message, like a connection lost mid-command.
const Token = "test-token"
Token is the bearer token the fake accepts.
Variables ¶
This section is empty.
Functions ¶
func Interpret ¶
func Interpret(cmd string, in io.Reader, out func(byte, []byte), killed <-chan struct{}) (int, string)
Interpret is the built-in command language:
echo TEXT stdout TEXT + newline, exit 0 stderr TEXT stderr TEXT + newline, exit 0 exit N exit N cat copy stdin to stdout until EOF yes N N bytes of "y\n" on stdout sleep run until killed, then report signal "killed" signal NAME exit by signal NAME anything else stdout "ran: CMD" + newline
Types ¶
type Exec ¶
type Exec func(cmd string, in io.Reader, out func(stream byte, b []byte), killed <-chan struct{}) (code int, signal string)
Exec is a scripted command. It writes output with out(stream, bytes) (stream 1 = stdout, 2 = stderr), reads stdin from in (closed at EOF), and returns the exit code and signal. killed is closed when the client sends KILL or the stream drops.
type ExecStart ¶ added in v0.6.6
type ExecStart struct {
Command string `json:"command"`
Env map[string]string `json:"env"`
TTY bool `json:"tty"`
Cols int `json:"cols"`
Rows int `json:"rows"`
}
ExecStart is the first frame of a streaming exec.
type Server ¶
type Server struct {
*httptest.Server
// IgnoreNameFilter makes GET /sandboxes ignore ?name=, like a server
// that predates name lookup (CEO review CF5).
IgnoreNameFilter bool
// IgnoreLimit makes GET /sandboxes return every row even when the
// caller sent ?limit=, like a daemon that predates single-node paging.
IgnoreLimit bool
// BadFileInfo makes GET /toolbox/files/info return a body that is
// not the info JSON, so callers exercise their decode failure path.
BadFileInfo bool
// HangAttach accepts the session websocket and then waits for the
// client to go away, so a follower can be detached instead of
// observing an immediate exit.
HangAttach bool
// AttachReady is closed once a hanging attach has the websocket.
// Tests wait on it before cancelling the client.
AttachReady chan struct{}
// AttachExitSignal is sent on the attach exit message. Empty means
// the command exited by code alone.
AttachExitSignal string
// DropAfterCreate drops the connection this many times right after a
// create succeeds, so the client never sees the reply (lost reply, D5).
DropAfterCreate int
// ToolboxFeatures is what GET /toolbox/version lists. Nil lists every
// feature the CLI and the Go SDK check for; set an empty slice to play
// an agent too old to list any.
ToolboxFeatures []string
// ExecFunc overrides the built-in command interpreter.
ExecFunc Exec
// ExecStartError makes a streamed exec answer its start message with
// this error frame, as toolboxd does for a command it can't start.
ExecStartError string
// BufferedPad adds this many bytes of padding to buffered exec stdout.
BufferedPad int
// FailStart makes POST /start fail with 500.
FailStart bool
// FailDestroy makes DELETE /sandboxes/{id} fail with 500 after the
// sandbox was found, so callers can tell a destroy error from a miss.
FailDestroy bool
// FailToolbox makes every toolbox route fail with 500.
FailToolbox bool
// FailSessions makes session create/get/delete fail with 500.
FailSessions bool
// FailExpose makes POST /ports/{port} fail with 500.
FailExpose bool
// DropAttach upgrades the session websocket and closes it before an
// exit message, so Wait returns an error instead of a code.
DropAttach bool
// FailAttach makes the session websocket handshake fail with 500.
FailAttach bool
// OnAttach runs, without the lock held, once a session attach has its
// websocket and before DropAttach drops it: a test stops or destroys
// the sandbox there to see what the client makes of the dropped stream.
OnAttach func(sandboxID, sessionID string)
// LiveAttach makes a session attach interactive, like a shell: it
// replays the log, then runs the exec function on the session's
// command with the client's stdin. A client "close" or a dropped
// connection detaches without an exit message, as toolboxd does.
LiveAttach bool
// ConflictAlways makes every create fail with 409 without creating
// anything (a conflict on something other than the name).
ConflictAlways bool
// FailCreates makes the next N creates fail with 500.
FailCreates int
// CreateDelay holds each create this long, to widen races in tests.
CreateDelay time.Duration
Requests []string
CreatePosts int
CreatedIDs []string
StreamDials int
Signals []string
Resizes []string
LastExecStart ExecStart
ExecCommands []string
SessionCreates []models.CreateSessionRequest
Detaches int
BufferedExecs int
LastCreate models.CreateSandboxRequest
StartCalls int
DestroyCalls int
ListQueries []string
UploadedBodies int
// contains filtered or unexported fields
}
Server is the fake sandboxd. Fields after mu are guarded by it; read them through Snapshot-style helpers or after the client calls return.
func (*Server) AddSandbox ¶
AddSandbox registers a sandbox. A zero ID gets a generated one.
func (*Server) AddSession ¶ added in v0.6.6
AddSession registers a session in a fake sandbox, as one started by another client (an SSH login, an earlier `aerolvm shell`) would be.
func (*Server) AppendSessionLog ¶
AppendSessionLog adds output to a fake session's log.