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

cassette

package
v0.2.61 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package cassette records and replays broker responses deterministically.

Recording is explicit opt-in; replay is the default and never falls back to the live network. Both paths run the identical broker admission, credential, and checkpoint checks — the cassette only substitutes for the network round trip, returning the already-filtered safe response that recording captured. A cassette never persists raw request or response bytes: it stores only the filtered safe response, keyed by a match digest that normalizes the host-injected idempotency key, request id, and timestamps without weakening the action, resource, origin, or response-policy binding. Recording fails closed if any secret-shaped value survives into what would be stored.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cassette

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

Cassette is a deterministic record/replay store.

func Load

func Load(data []byte, providerVersion string) (*Cassette, error)

Load restores recorded entries for replay.

func New

func New(mode Mode, providerVersion string) *Cassette

New builds a cassette in the given mode bound to a concrete provider version.

func (*Cassette) Marshal

func (c *Cassette) Marshal() ([]byte, error)

Marshal serializes the cassette deterministically for a byte-stable on-disk form and reviewable diffs.

func (*Cassette) Mode

func (c *Cassette) Mode() Mode

Mode reports the cassette mode.

func (*Cassette) Record

func (c *Cassette) Record(key Key, status uint32, safeHeaders map[string]string, response *providerv0.ExecuteRequestResponse) error

Record stores a live filtered response. It fails closed if any secret-shaped value survived filtering, so a cassette can never become an exfiltration surface.

func (*Cassette) Replay

Replay returns the next recorded response for the key. It never falls back to the network: an unknown key or a response-policy mismatch is a hard error.

type Entry

type Entry struct {
	Sequence        int               `json:"sequence"`
	Method          string            `json:"method"`
	MatchDigest     string            `json:"match_digest"`
	PolicyDigest    string            `json:"policy_digest"`
	ProviderVersion string            `json:"provider_version"`
	Status          uint32            `json:"status"`
	SafeHeaders     map[string]string `json:"safe_headers,omitempty"`
	Response        json.RawMessage   `json:"response"`
}

Entry is one recorded exchange. It holds only safe, filtered material.

type Key

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

Key identifies one logical request independent of host-injected volatile fields. Method, descriptor, path, query, body, origin, and response policy are bound; the idempotency key, request id, and timestamps are not.

func NewKey

func NewKey(planned *providerv0.PlannedRequest, origin *providerv0.AdmittedOrigin) Key

NewKey builds a match key from the admitted planned request and origin.

type Mode

type Mode int

Mode selects record or replay. The zero value is replay, so a misconfigured cassette never accidentally reaches the network.

const (
	// ModeReplay returns recorded responses and never dials the network.
	ModeReplay Mode = iota
	// ModeRecord stores live filtered responses.
	ModeRecord
)

Jump to

Keyboard shortcuts

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