transcript

package
v0.1.0-beta Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2026 License: MIT Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package transcript records real HTTP exchanges against a live lab and replays them offline.

The audit must not depend on a live backend: labs cost quota, rate-limit, and drift. The usual answer is a hand-written httptest handler, and this repo is full of them. They have one failure mode -- the fake and the real backend disagree and nobody notices, so the eval grades an imitation. A recorded transcript is the same fake with its provenance attached: it came off the real thing, and re-recording is how you find out it changed.

Two properties earn the package its place:

  • Exchanges key on the AUTH CLASS as well as the path. Anonymous and authenticated requests to one URL are different observations, and on Neon they are the difference between a refusal and every row in a table.
  • An unrecorded request is reported, never quietly answered. A missing recording that returns 404 looks exactly like a real negative result.

Credentials are never stored. Recording keeps the class ("anon"/"authed"), which is all replay needs and all a committed file should ever hold.

Index

Constants

View Source
const (
	Anon   = "anon"
	Authed = "authed"
)

Auth classes. These are the only two observations that matter to a posture scan: what a stranger sees, and what any account sees.

Variables

This section is empty.

Functions

This section is empty.

Types

type Exchange

type Exchange struct {
	Method      string `json:"method"`
	Path        string `json:"path"` // path plus raw query
	Auth        string `json:"auth"` // Anon or Authed -- never a credential
	Status      int    `json:"status"`
	ContentType string `json:"content_type,omitempty"`
	Body        string `json:"body"`
	// RequestBody is what was SENT, and it exists so a recording can be checked
	// against the code that replays it.
	//
	// Replay does not key on it -- a probe should not have to send byte-identical
	// JSON to be answered -- but without it nothing can ask whether the
	// recording still answers the question the scanner asks. It did not, once:
	// the Neon write probe stopped naming a column, five tables changed from
	// 400 PGRST204 to 403/42501, and the committed transcript went on serving
	// the old answers while every offline eval passed.
	//
	// Empty for requests that carry no body, which is most of them.
	RequestBody string `json:"request_body,omitempty"`
}

An Exchange is one recorded request/response pair.

type Request

type Request struct {
	Method string
	Path   string
	Auth   string
	Body   string
}

A Request describes one exchange to record.

type Transcript

type Transcript struct {
	Exchanges []Exchange `json:"exchanges"`
}

A Transcript is an ordered set of exchanges. Order is normalised on save so re-recording an unchanged backend produces an unchanged file.

func Load

func Load(path string) (*Transcript, error)

Load reads a transcript from disk.

func New

func New() *Transcript

New returns an empty transcript.

func Record

func Record(ctx context.Context, base, token string, reqs []Request) (*Transcript, error)

Record performs each request against base and captures the responses.

token is used only to populate the Authorization header for Authed requests. It is never written to the transcript.

func (*Transcript) Add

func (t *Transcript) Add(method, path, auth string, status int, contentType, body string)

Add appends an exchange.

func (*Transcript) AddWithRequest

func (t *Transcript) AddWithRequest(method, path, auth, requestBody string,
	status int, contentType, body string)

AddWithRequest records an exchange and what was sent to provoke it.

func (*Transcript) Save

func (t *Transcript) Save(path string) error

Save writes the transcript with exchanges in a stable order.

func (*Transcript) Server

func (t *Transcript) Server(onUnrecorded func(string)) *httptest.Server

Server replays the transcript. onUnrecorded is called with a description of any request the transcript does not cover; it is not optional, because silently answering an unknown request is the failure this package exists to prevent.

Jump to

Keyboard shortcuts

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