testmocks

package
v0.331.0 Latest Latest
Warning

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

Go to latest
Published: May 21, 2026 License: AGPL-3.0 Imports: 18 Imported by: 0

Documentation

Overview

Package testmocks centralises the shared mock harness used across PromptZero's test surfaces — flipper-agent tests, end-to-end REPL tests, workflow tests. Callers get ready-to-use backends without having to know which package owns the underlying mock (pty for flipper, fake port for marauder, httptest.Server for the Anthropic SDK).

Every constructor registers cleanup hooks with the supplied testing.T, so tests don't need to defer Close themselves. Linux-only because the underlying flipper mock uses Linux pty syscalls.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewMockAnthropic

func NewMockAnthropic(t *testing.T, script []AnthropicScript) *anthropic.Client

NewMockAnthropic starts an httptest.Server that replays the supplied script against /v1/messages streaming requests, and returns an anthropic.Client wired to it via WithBaseURL. Each /v1/messages POST consumes the next script entry; requests past the end of the script yield a canned "end of script" text response so tests that overshoot fail loudly rather than hang.

func NewMockFlipper

func NewMockFlipper(t *testing.T, opts ...MockFlipperOption) *flipper.Flipper

NewMockFlipper spins up the pty-backed Flipper mock and returns a connected *flipper.Flipper ready for assertions. Handshake + capability detection both complete before return; on failure t.Fatalf is called.

func NewMockMarauder

func NewMockMarauder(t *testing.T, opts ...MockMarauderOption) *marauder.Marauder

NewMockMarauder returns a *marauder.Marauder wired to an in-memory fake serial port. Canned responses are registered through options; commands that lack a handler still receive a bare echo + prompt so Exec doesn't hang waiting on silence.

Types

type AnthropicScript

type AnthropicScript struct {
	// Text is the plain-text body the fake model "generates" for this
	// turn. Ignored when Tool is set.
	Text string
	// Tool, when non-empty, instructs the mock to return a tool_use
	// block naming this tool with the supplied input arguments.
	Tool string
	// ToolID uniquely identifies the tool_use block (matches the id the
	// caller threads back as a tool_result). Defaults to "mock-<n>" when
	// empty.
	ToolID string
	// ToolInput is marshalled to JSON and placed in the tool_use block's
	// input field. nil is emitted as an empty object.
	ToolInput any
	// StopReason defaults to "end_turn" for text and "tool_use" for
	// tool entries. Override for edge-case coverage.
	StopReason string
}

AnthropicScript is one scripted model response consumed by a single streamOnce invocation. Text is emitted as a text block; when Tool is set, a tool_use block is emitted instead. Only one of Text or Tool should be non-zero per script entry — entries with both populated prioritise Tool.

type MockFlipperOption

type MockFlipperOption func(*mockFlipperConfig)

MockFlipperOption tunes NewMockFlipper at construction time.

func WithFlipperBanner

func WithFlipperBanner(s string) MockFlipperOption

WithFlipperBanner overrides the one-shot welcome banner emitted when the Flipper mock's slave fd is first read.

func WithFlipperHandler

func WithFlipperHandler(cmd string, h flippermock.Handler) MockFlipperOption

WithFlipperHandler registers a response handler for a Flipper CLI verb (the first whitespace-separated word of the command line). Overrides any handler the pty mock ships with by default.

type MockMarauderOption

type MockMarauderOption func(*fakeMarauderPort)

MockMarauderOption tunes NewMockMarauder at construction time.

func WithMarauderResponse

func WithMarauderResponse(cmd, body string) MockMarauderOption

WithMarauderResponse preloads a canned response body for the given command string (echoed back as "#<cmd>\n<body>\n> "). The body may span multiple lines and should not include the trailing prompt.

Jump to

Keyboard shortcuts

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