fixturecapture

package
v0.3.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Overview

Package fixturecapture records bounded, anonymized terminal output for adapter fixtures. It deliberately has no input, shell-script, environment, provider, or credential API.

Index

Constants

View Source
const (
	// SchemaVersion is incremented when the persisted JSON contract changes.
	SchemaVersion = 1

	DefaultMaxBytes = 256 * 1024
	HardMaxBytes    = 4 * 1024 * 1024
	DefaultTimeout  = 20 * time.Second
	MaximumTimeout  = 5 * time.Minute
)

Variables

View Source
var (
	ErrSensitiveContent = errors.New("fixture contains sensitive content")
	ErrUnsupported      = errors.New("fixture capture is unsupported on this platform")
)

Functions

func HelperMain

func HelperMain(arguments []string, diagnostics io.Writer) (handled bool, exitCode int)

HelperMain handles only the private tmux launch protocol. Public commands must call it before flag parsing. Diagnostics intentionally contain no argv, paths, environment values, or captured output.

func Marshal

func Marshal(fixture Fixture, anonymizer *Anonymizer) ([]byte, error)

Marshal validates and serializes one fixture with a trailing newline. The returned slice never aliases fixture storage.

func Validate

func Validate(fixture Fixture, anonymizer *Anonymizer) error

Validate checks the schema, all memory bounds, and that the persisted chunk stream is already in canonical anonymized form.

func WriteFile

func WriteFile(path string, fixture Fixture, anonymizer *Anonymizer) error

WriteFile atomically publishes a validated fixture. New directories are private and the final file is always mode 0600 on Unix.

Types

type Anonymizer

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

Anonymizer centralizes the only transformation permitted before fixture persistence. Credential-shaped content is rejected; identity-bearing email addresses and home-directory prefixes are replaced with stable markers.

func NewAnonymizer

func NewAnonymizer(homePaths []string) (*Anonymizer, error)

NewAnonymizer defensively copies explicit home-directory prefixes. It is exported so tests and offline fixture validators do not depend on host data.

func NewDefaultAnonymizer

func NewDefaultAnonymizer() (*Anonymizer, error)

NewDefaultAnonymizer includes the current user's home path without exposing it in the resulting value or artifact.

func (*Anonymizer) Anonymize

func (anonymizer *Anonymizer) Anonymize(input []byte) ([]byte, error)

Anonymize returns independent storage safe for a fixture, or fails closed when a token, JWT, authorization value, API key, URL credential, or another credential-shaped value is observed. It never returns partially sanitized bytes together with an error.

type Backend

type Backend string

Backend identifies the local terminal transport used for the observation.

const (
	BackendPTY  Backend = "pty"
	BackendTmux Backend = "tmux"
)

type Chunk

type Chunk struct {
	Sequence int    `json:"sequence"`
	Data     string `json:"data"`
}

Chunk is one bounded piece of already anonymized terminal output.

type Fixture

type Fixture struct {
	SchemaVersion int     `json:"schema_version"`
	Tool          string  `json:"tool"`
	Adapter       string  `json:"adapter"`
	Backend       Backend `json:"backend"`
	Outcome       Outcome `json:"outcome"`
	ExitCode      *int    `json:"exit_code,omitempty"`
	Truncated     bool    `json:"truncated,omitempty"`
	Chunks        []Chunk `json:"chunks"`
}

Fixture is the complete versioned on-disk contract. It intentionally omits argv, cwd, environment variables, raw input, timestamps, and user identity.

func Capture

func Capture(ctx context.Context, options Options) (Fixture, error)

Capture starts exactly one output-only CLI in a PTY or an isolated private tmux server. It never forwards caller input and never accepts or records an environment map. Timeout and output-limit outcomes still return a fixture.

func Decode

func Decode(input []byte, anonymizer *Anonymizer) (Fixture, error)

Decode accepts exactly one strict JSON value. Unknown fields are rejected so argv, environment, manual input, or other unsafe ad-hoc fields cannot hide in a nominally valid fixture.

func ReadFile

func ReadFile(path string, anonymizer *Anonymizer) (Fixture, error)

ReadFile performs a bounded read and strict dry validation.

type Options

type Options struct {
	Tool       string
	Adapter    string
	Backend    Backend
	Command    []string
	Cwd        string
	TmuxPath   string
	HelperPath string
	Timeout    time.Duration
	MaxBytes   int
	Anonymizer *Anonymizer
}

Options configures an output-only PTY capture. Command is exact argv and the harness never wraps it in an implicit shell. A caller can still explicitly choose a shell executable, so argv remains security-sensitive. There is intentionally no environment or stdin field. The child receives a small internal allowlist of non-secret process environment variables plus disposable private HOME, TMPDIR, and XDG roots; it never inherits the caller's configuration directories.

type Outcome

type Outcome string

Outcome describes why an otherwise successful output-only capture ended. A timeout and an output limit are expected capture outcomes, not claims about the tool that was observed.

const (
	OutcomeExited      Outcome = "exited"
	OutcomeTimedOut    Outcome = "timed_out"
	OutcomeOutputLimit Outcome = "output_limit"
)

Jump to

Keyboard shortcuts

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