acpmock

package
v0.3.0-beta.29 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ProviderName     = "acpmock"
	ProviderClaude   = "claude"
	ProviderOpenClaw = "openclaw"
	ProviderHermes   = "hermes"
)

Provider identities supported by provider-aware fixture scenarios.

View Source
const FixtureVersion = 2

Variables

This section is empty.

Functions

func BuildCommand

func BuildCommand(
	driverPath string,
	fixturePath string,
	fixtureAgent string,
	diagnosticsPath string,
	effectiveProvider ...string,
) string

BuildCommand renders the test-only ACP driver command string stored in AGENT.md.

func DefaultDriverPath

func DefaultDriverPath() (string, error)

DefaultDriverPath resolves or builds the test-only ACP mock driver binary.

func ProviderConfig

func ProviderConfig(command ...string) compozyconfig.ProviderConfig

ProviderConfig returns the local auth-free provider config for ACP mock agents.

func ProviderConfigForIdentity

func ProviderConfigForIdentity(provider string, command ...string) (compozyconfig.ProviderConfig, error)

ProviderConfigForIdentity returns an ACP mock config under one typed native provider identity.

func RequireDriver

func RequireDriver(t testing.TB) string

RequireDriver resolves the ACP mock driver binary or fails the current test.

Types

type AgentFixture

type AgentFixture struct {
	Name            string   `json:"name"`
	Provider        string   `json:"provider"`
	Model           string   `json:"model,omitempty"`
	ReasoningEffort string   `json:"reasoning_effort,omitempty"`
	Permissions     string   `json:"permissions,omitempty"`
	Tools           []string `json:"tools,omitempty"`
	Prompt          string   `json:"prompt,omitempty"`
	LoadSession     *bool    `json:"load_session,omitempty"`
	// ForkSession advertises the unstable ACP session/fork capability; the driver answers
	// session/fork with a clone id after sending clone-id updates first (OpenCode shape).
	ForkSession bool `json:"fork_session,omitempty"`
	// ForkError makes session/fork fail with this message.
	ForkError string `json:"fork_error,omitempty"`
	// LoadMissing makes session/load fail with ACP resource-not-found for any id.
	LoadMissing   bool                         `json:"load_missing,omitempty"`
	ConfigOptions []SessionConfigOptionFixture `json:"config_options,omitempty"`
	Turns         []TurnFixture                `json:"turns"`
}

AgentFixture describes one named ACP mock agent inside a fixture file.

func (AgentFixture) RejectsConfigValue

func (a AgentFixture) RejectsConfigValue(configID string, value string) bool

RejectsConfigValue reports whether the fixture scripts a set_config_option failure.

func (AgentFixture) SelectTurn

func (a AgentFixture) SelectTurn(prompt string, meta ...acp.PromptMeta) (TurnFixture, error)

SelectTurn returns the first turn that matches stable prompt fields.

func (AgentFixture) SupportsLoadSession

func (a AgentFixture) SupportsLoadSession() bool

SupportsLoadSession reports the fixture's advertised ACP session/load capability.

func (AgentFixture) Validate

func (a AgentFixture) Validate(path string) error

Validate ensures the agent fixture is usable.

type DiagnosticsRecord

type DiagnosticsRecord struct {
	CompozySessionID  string             `json:"compozy_session_id,omitempty"`
	AgentName         string             `json:"agent_name"`
	Provider          string             `json:"provider,omitempty"`
	SessionID         string             `json:"session_id"`
	ProtocolMethod    string             `json:"protocol_method,omitempty"`
	ConfigOptionID    string             `json:"config_option_id,omitempty"`
	ConfigOptionValue string             `json:"config_option_value,omitempty"`
	LifecycleEvent    string             `json:"lifecycle_event,omitempty"`
	MCPServers        []acpsdk.McpServer `json:"mcp_servers,omitempty"`

	PromptIndex int               `json:"prompt_index"`
	Prompt      string            `json:"prompt"`
	PromptMeta  acp.PromptMeta    `json:"prompt_meta"`
	TurnName    string            `json:"turn_name,omitempty"`
	Match       TurnMatch         `json:"match"`
	Steps       []DiagnosticsStep `json:"steps"`
}

DiagnosticsRecord captures one protocol, lifecycle, or prompt event emitted by the ACP mock driver.

func DiagnosticsForCompozySession

func DiagnosticsForCompozySession(records []DiagnosticsRecord, compozySessionID string) []DiagnosticsRecord

DiagnosticsForCompozySession returns records owned by one daemon session in append order.

func DiagnosticsForProvider

func DiagnosticsForProvider(records []DiagnosticsRecord, provider string) []DiagnosticsRecord

DiagnosticsForProvider returns structured records for one canonical provider identity.

func PromptDiagnostics

func PromptDiagnostics(records []DiagnosticsRecord) []DiagnosticsRecord

PromptDiagnostics returns diagnostics emitted for prompt execution turns only.

func ProtocolDiagnostics

func ProtocolDiagnostics(records []DiagnosticsRecord) []DiagnosticsRecord

ProtocolDiagnostics returns diagnostics emitted when the driver receives ACP protocol methods.

func ReadDiagnostics

func ReadDiagnostics(path string) (records []DiagnosticsRecord, err error)

ReadDiagnostics decodes newline-delimited diagnostics written by the mock driver.

type DiagnosticsStep

type DiagnosticsStep struct {
	Kind         StepKind            `json:"kind"`
	Text         string              `json:"text,omitempty"`
	ToolCallID   string              `json:"tool_call_id,omitempty"`
	Decision     string              `json:"decision,omitempty"`
	Command      string              `json:"command,omitempty"`
	Args         []string            `json:"args,omitempty"`
	ExitCode     *int                `json:"exit_code,omitempty"`
	Output       string              `json:"output,omitempty"`
	Error        string              `json:"error,omitempty"`
	DriverAction DriverControlAction `json:"driver_action,omitempty"`
}

DiagnosticsStep captures one executed fixture step with any observed runtime outputs.

type DriverControlAction

type DriverControlAction string

DriverControlAction identifies one supported driver fault injection action.

const (
	DriverControlDisconnect       DriverControlAction = "disconnect"
	DriverControlWriteRawJSONRPC  DriverControlAction = "write_raw_jsonrpc"
	DriverControlBlockUntilCancel DriverControlAction = "block_until_cancel"
	DriverControlDelay            DriverControlAction = "delay"
	// DriverControlHoldIgnoringCancel keeps the turn open for delay_ms while ignoring
	// prompt cancellation, so stop ladders must escalate past the cooperative phase.
	DriverControlHoldIgnoringCancel DriverControlAction = "hold_ignoring_cancel"
	// DriverControlFailPrompt answers the matched session/prompt with a JSON-RPC error
	// carrying error_message, the shape a provider rate limit or auth lapse reaches the
	// daemon in after the session was accepted.
	DriverControlFailPrompt DriverControlAction = "fail_prompt"
)

type DriverControlStep

type DriverControlStep struct {
	Action     DriverControlAction `json:"action"`
	RawJSONRPC string              `json:"raw_jsonrpc,omitempty"`
	Async      bool                `json:"async,omitempty"`
	DelayMS    int                 `json:"delay_ms,omitempty"`
	// ErrorMessage is the JSON-RPC error message fail_prompt answers session/prompt with.
	ErrorMessage string `json:"error_message,omitempty"`
	// ErrorCode is the optional JSON-RPC error code for fail_prompt (default -32603).
	ErrorCode int `json:"error_code,omitempty"`
}

DriverControlStep injects driver-level protocol or lifecycle faults.

func (DriverControlStep) Validate

func (d DriverControlStep) Validate(path string) error

Validate ensures the driver-control payload is internally consistent.

type Fixture

type Fixture struct {
	Version int            `json:"version"`
	Agents  []AgentFixture `json:"agents"`
}

Fixture describes one deterministic multi-agent ACP mock scenario.

func LoadFixture

func LoadFixture(path string) (Fixture, error)

LoadFixture parses and validates one fixture file.

func ParseFixture

func ParseFixture(data []byte) (Fixture, error)

ParseFixture decodes and validates fixture JSON.

func (Fixture) Agent

func (f Fixture) Agent(name string) (AgentFixture, error)

Agent returns one named fixture agent.

func (Fixture) Validate

func (f Fixture) Validate() error

Validate ensures the fixture can drive deterministic ACP scenarios.

type RegisterOptions

type RegisterOptions struct {
	FixturePath     string
	FixtureAgent    string
	AgentName       string
	ProviderName    string
	DriverPath      string
	DiagnosticsPath string
	Tools           []string
}

RegisterOptions describes one temporary fixture-backed AGENT.md registration.

type Registration

type Registration struct {
	AgentName       string
	FixtureAgent    string
	FixturePath     string
	DriverPath      string
	DiagnosticsPath string
	AgentDefPath    string
	Command         string
	Provider        string
	Model           string
	Permissions     string
}

Registration captures one temporary mock-agent definition written into Compozy home.

func Register

func Register(homePaths compozyconfig.HomePaths, opts RegisterOptions) (Registration, error)

Register writes one temporary fixture-backed AGENT.md file into the supplied Compozy home.

type SessionConfigOptionFixture

type SessionConfigOptionFixture struct {
	ID       string                            `json:"id"`
	Name     string                            `json:"name"`
	Category string                            `json:"category,omitempty"`
	Current  string                            `json:"current"`
	Values   []SessionConfigOptionValueFixture `json:"values"`
}

SessionConfigOptionFixture describes one deterministic ACP session config select option.

func (SessionConfigOptionFixture) Validate

func (o SessionConfigOptionFixture) Validate(path string) error

Validate ensures one session config option is deterministic and selectable.

type SessionConfigOptionValueFixture

type SessionConfigOptionValueFixture struct {
	Value string `json:"value"`
	Label string `json:"label,omitempty"`
	// RejectSet makes session/set_config_option to this advertised value fail, which
	// scripts a start that ACP accepted (session/new returned) and then failed.
	RejectSet bool `json:"reject_set,omitempty"`
}

SessionConfigOptionValueFixture describes one selectable ACP config option value.

type Step

type Step struct {
	Kind StepKind `json:"kind"`

	Text   string   `json:"text,omitempty"`
	Chunks []string `json:"chunks,omitempty"`
	// BurstCount repeats Text without delivery pacing to exercise transport pressure.
	BurstCount int `json:"burst_count,omitempty"`

	ToolCallID  string          `json:"tool_call_id,omitempty"`
	Title       string          `json:"title,omitempty"`
	ToolKind    string          `json:"tool_kind,omitempty"`
	Path        string          `json:"path,omitempty"`
	Status      string          `json:"status,omitempty"`
	ContentText string          `json:"content_text,omitempty"`
	RawInput    json.RawMessage `json:"raw_input,omitempty"`
	RawOutput   json.RawMessage `json:"raw_output,omitempty"`

	ExpectDecision string `json:"expect_decision,omitempty"`
	EmitDecision   bool   `json:"emit_decision,omitempty"`
	EmitText       string `json:"emit_text,omitempty"`

	Command              string             `json:"command,omitempty"`
	Args                 []string           `json:"args,omitempty"`
	Cwd                  string             `json:"cwd,omitempty"`
	ExpectExitCode       *int               `json:"expect_exit_code,omitempty"`
	ExpectOutputContains string             `json:"expect_output_contains,omitempty"`
	ExpectErrorContains  string             `json:"expect_error_contains,omitempty"`
	EmitOutput           bool               `json:"emit_output,omitempty"`
	DriverControl        *DriverControlStep `json:"driver_control,omitempty"`
}

Step describes one deterministic ACP action emitted or executed by the driver.

func (Step) Validate

func (s Step) Validate(path string) error

Validate ensures the step kind and payload are internally consistent.

type StepKind

type StepKind string
const (
	StepKindAssistant     StepKind = "assistant"
	StepKindThought       StepKind = "thought"
	StepKindToolCall      StepKind = "tool_call"
	StepKindPermission    StepKind = "permission"
	StepKindCommand       StepKind = "command_exec"
	StepKindDriverControl StepKind = "driver_control"
)

type TurnFixture

type TurnFixture struct {
	UsageUpdates []UsageUpdate `json:"usage_updates,omitempty"`
	Name         string        `json:"name,omitempty"`
	Match        TurnMatch     `json:"match"`
	Steps        []Step        `json:"steps"`
	StopReason   string        `json:"stop_reason,omitempty"`
	Usage        *TurnUsage    `json:"usage,omitempty"`
}

TurnFixture describes one deterministic prompt turn for an agent.

func (TurnFixture) Validate

func (t TurnFixture) Validate(path string) error

Validate ensures the turn fixture is usable.

type TurnMatch

type TurnMatch struct {
	TurnSource string `json:"turn_source,omitempty"`
	UserText   string `json:"user_text,omitempty"`
	// UserTextContains matches a substring after the same canonical whitespace normalization as UserText.
	UserTextContains string `json:"user_text_contains,omitempty"`
	// RawUserTextContains matches a substring before prompt augmentation is stripped.
	RawUserTextContains string `json:"raw_user_text_contains,omitempty"`

	Goal  *TurnMatchGoal  `json:"goal,omitempty"`
	Judge *TurnMatchJudge `json:"judge,omitempty"`
}

TurnMatch routes a prompt to a turn fixture using stable prompt fields.

func (TurnMatch) Normalize

func (m TurnMatch) Normalize() TurnMatch

Normalize returns a trimmed copy of the turn matcher.

func (TurnMatch) Validate

func (m TurnMatch) Validate(path string) error

Validate ensures the turn match contains at least one supported stable selector.

type TurnMatchGoal

type TurnMatchGoal struct {
	Kind          string `json:"kind,omitempty"`
	RunID         string `json:"run_id,omitempty"`
	NodeID        string `json:"node_id,omitempty"`
	Generation    int64  `json:"generation,omitempty"`
	ItemIndex     *int   `json:"item_index,omitempty"`
	Turn          *int   `json:"turn,omitempty"`
	PromptAttempt *int   `json:"prompt_attempt,omitempty"`
	PromptID      string `json:"prompt_id,omitempty"`
}

TurnMatchGoal captures exact Goal prompt metadata fields.

func (TurnMatchGoal) IsZero

func (m TurnMatchGoal) IsZero() bool

IsZero reports whether the matcher selects no Goal fields.

func (TurnMatchGoal) Normalize

func (m TurnMatchGoal) Normalize() TurnMatchGoal

Normalize returns an isolated, trimmed Goal matcher.

func (TurnMatchGoal) Validate

func (m TurnMatchGoal) Validate(_ string) error

Validate ensures at least one exact Goal selector is present.

type TurnMatchJudge

type TurnMatchJudge struct {
	Role          string `json:"role,omitempty"`
	Attempt       int    `json:"attempt,omitempty"`
	CorrelationID string `json:"correlation_id,omitempty"`
	GateID        string `json:"gate_id,omitempty"`
	CriterionID   string `json:"criterion_id,omitempty"`
}

TurnMatchJudge captures exact daemon-owned judge prompt metadata fields.

func (TurnMatchJudge) IsZero

func (m TurnMatchJudge) IsZero() bool

IsZero reports whether the matcher selects no judge fields.

func (TurnMatchJudge) Normalize

func (m TurnMatchJudge) Normalize() TurnMatchJudge

Normalize returns a trimmed judge matcher.

func (TurnMatchJudge) Validate

func (m TurnMatchJudge) Validate(_ string) error

Validate ensures at least one exact judge selector is present.

type TurnUsage

type TurnUsage struct {
	CacheReadTokens  *int `json:"cache_read_tokens,omitempty"`
	CacheWriteTokens *int `json:"cache_write_tokens,omitempty"`
	InputTokens      int  `json:"input_tokens"`
	OutputTokens     int  `json:"output_tokens"`
	TotalTokens      *int `json:"total_tokens,omitempty"`
}

func (TurnUsage) Validate

func (u TurnUsage) Validate(path string) error

Validate rejects impossible aggregate token counts.

type UsageUpdate

type UsageUpdate struct {
	Used int            `json:"used"`
	Size int            `json:"size"`
	Meta map[string]any `json:"meta,omitempty"`
}

TurnUsage scripts deterministic aggregate token usage for one ACP prompt response.

Directories

Path Synopsis
cmd
acpmock-driver command

Jump to

Keyboard shortcuts

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