Help us shape the future of Go! Take the 2026 Go Developer Survey

commandmock

package
v0.39.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	SessionEnvironmentVariable = "WAZA_COMMAND_MOCK_SESSION"
)

Variables

This section is empty.

Functions

func CloseRuntime

func CloseRuntime() error

CloseRuntime removes the temporary shim registry after the Copilot runtime has stopped.

func Invoke

func Invoke(root, sessionID, name string, args []string, cwd string) (invocationResult, error)

Invoke chooses the first matching response for the task session. The cwd fallback supports callers without an explicit session ID.

func InvokeContext added in v0.39.0

func InvokeContext(ctx context.Context, root, sessionID, name string, args []string, cwd string) (invocationResult, error)

func MatchResponse added in v0.39.0

func MatchResponse(response models.CommandMockResponse, args []string, cwd, workspace string) (bool, error)

MatchResponse checks invocation arguments, environment, and working directory using the native command-mock matcher semantics.

func ResponseOutput added in v0.39.0

func ResponseOutput(response models.CommandMockResponse, baseDir string) ([]byte, error)

ResponseOutput returns fixture bytes, string stdout, or JSON-encoded stdout using the native command-mock output semantics.

func RunCommand

func RunCommand(root, name string, args []string) (int, error)

RunCommand is the entry point for the private executable shims.

func RunCommandContext added in v0.39.0

func RunCommandContext(ctx context.Context, root, name string, args []string) (int, error)

RunCommandContext returns cancellation separately from an ordinary nonzero exit so callers can avoid diagnostic writes after canceling a backpressured host.

func RunNativeCommand added in v0.39.0

func RunNativeCommand(ctx context.Context, root, sessionID, name string, args []string, cwd string, options NativeDispatchOptions) (exitCode int, resultErr error)

RunNativeCommand is an opt-in shim entry point. With no private configuration it uses RunCommand unchanged; configured mocks never fall through to the host. Nil writers use the actual process streams.

func RuntimeEnvironment

func RuntimeEnvironment() ([]string, error)

RuntimeEnvironment returns an environment for the Copilot child process that puts the command-mock shims before, but does not replace, the host PATH.

Types

type NativeDispatch added in v0.39.0

type NativeDispatch func(context.Context, NativeDispatchRequest, func(NativeOutput) error, func() error) (int, error)

NativeDispatch must call emit and then receipt synchronously, at most once. It owns cancellable I/O; this hook does not install process-signal handlers. Receipt failure after emission must never cause retry, re-emission or rollback.

type NativeDispatchOptions added in v0.39.0

type NativeDispatchOptions struct {
	Dispatch NativeDispatch
	Stdout   io.Writer
	Stderr   io.Writer
}

type NativeDispatchRequest added in v0.39.0

type NativeDispatchRequest struct {
	StateDir      string
	Workspace     string
	CWD           string
	Name          string
	Args          []string
	Mock          json.RawMessage
	Configuration json.RawMessage
}

NativeDispatchRequest carries the selected stored mock and opaque preparation result. Neither value is interpreted as a fault schema by commandmock.

type NativeOutput added in v0.39.0

type NativeOutput struct {
	Stdout        []byte
	Stderr        string
	ExitCode      int
	ResponseIndex int
}

type NativePrepare added in v0.39.0

type NativePrepare func(context.Context, NativePrepareRequest) (json.RawMessage, error)

type NativePrepareRequest added in v0.39.0

type NativePrepareRequest struct {
	StateDir  string
	Workspace string
	Mock      json.RawMessage
}

NativePrepareRequest contains the typed, serialized baseline mock before normalization, not the retained raw source or a public schema extension. Serialization's omitempty tags lose explicit empty slices and zero values. Callers requiring source presence must retain it separately in a closure or private envelope. Preparation owns any additional private state.

type Session

type Session struct {
	// contains filtered or unexported fields
}

Session owns the temporary configuration and invocation history for a task.

func NewNativeSession added in v0.39.0

func NewNativeSession(ctx context.Context, workspace string, mocks []models.CommandMockConfig, baseDir string, prepare NativePrepare) (_ *Session, resultErr error)

NewNativeSession optionally prepares opaque task-private configuration after the task directory exists, but before baseline responses are materialized. A nil preparation preserves NewSession's legacy configuration and behavior.

func NewSession

func NewSession(workspace string, mocks []models.CommandMockConfig, baseDir string) (*Session, error)

NewSession validates and materializes task-scoped mock config outside the workspace so fixtures and credentials are not captured in workspace snapshots.

func (*Session) Close

func (s *Session) Close() ([]models.CommandInvocation, error)

Close removes task-private configuration and verifies exact call counts.

func (*Session) ID

func (s *Session) ID() string

ID returns the opaque task identifier passed to command-mock shims.

func (*Session) Invocations

func (s *Session) Invocations() []models.CommandInvocation

Invocations returns sanitized invocation records in chronological order. Legacy records reflect selection, not stream delivery. Close checks private native capture integrity; this legacy accessor cannot report capture errors but omits corrupt or unmatched native receipts.

Jump to

Keyboard shortcuts

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