scriptenv

package
v0.0.0-...-ac8c494 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2026 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Overview

Package scriptenv is the shared environment of the testscript (.txtar) golden suite (issue #26 §5): the determinism environment every script runs under, the custom command set (daemon, clock, waitfor, capture, exitcode, cmpjson, cmpshape, mask), and the in-process daemon the inproc lane talks to.

Two lanes run through one Params: the inproc lane constructs the daemon inside the test process on a clock.Fake — the `messq` commands a script writes re-exec the test binary via testscript.RunMain and speak real HTTP over the socket — and the subproc lane (added with the quickstart/dev_mode scripts) runs a real `messq serve` where the process boundary is the thing under test.

This package is imported by tests only; nothing in the production tree links it. Its dependency on rogpeppe/go-internal is PLAN.md §13's test-only row.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Shapes

func Shapes() map[string]any

Shapes is the cmpshape registry: shape name → prototype value of the wire type. Only importable types appear; a command's private view type joins when its owning package exports a prototype or the shape moves next to it.

Types

type Daemon

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

Daemon is the inproc lane's daemon: the same construction pipeline `messq serve` runs (store.Open → api.New → writer engine with the waiter registry as its event sink → expiry sweeper), built inside the test process on a clock.Fake and listening on a unix socket under $WORK.

Scripts drive it through the REAL CLI: `messq <args…>` re-execs the test binary (testscript.RunMain) and talks HTTP over the socket, so every script exercises the same client/transport/API path production uses. The fake clock belongs to the test process; `clock advance` moves it between script lines.

func StartDaemon

func StartDaemon(workDir string, clk *clock.Fake) (*Daemon, error)

StartDaemon builds and starts the inproc daemon under workDir. It returns only once /readyz answers — the same readiness rule `messq serve`'s systemd unit relies on — so a script line that follows `daemon start` never races startup.

func (*Daemon) Addr

func (d *Daemon) Addr() string

Addr returns the daemon address in --addr form.

func (*Daemon) Clock

func (d *Daemon) Clock() *clock.Fake

Clock exposes the lane's fake clock for `clock advance`/`clock set`.

func (*Daemon) DataDir

func (d *Daemon) DataDir() string

DataDir returns the daemon's data directory (under $WORK).

func (*Daemon) Quiesce

func (d *Daemon) Quiesce() error

Quiesce returns once everything issued before it has finished: a healthz round-trip through the real client gives a happens-after edge for the sweeper ticks `clock advance` fired. When delivery commands (#13/#14) land, this gains the writer-queue drain those scripts need; the scripts that exist today need no more than this barrier.

func (*Daemon) SocketPath

func (d *Daemon) SocketPath() string

SocketPath returns the bare socket path.

func (*Daemon) Stop

func (d *Daemon) Stop(graceful bool)

Stop tears the daemon down. Graceful=false is `daemon kill`: no shutdown grace, the socket file left behind exactly as a SIGKILLed serve would.

type State

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

state is the per-script state custom commands share: the fake clock, the inproc daemon (once `daemon start` ran), the script directory (-update needs it), and the update flag.

func (*State) Close

func (st *State) Close()

Close tears the script's daemon down. Registered with e.Defer, so it runs even when the script fails.

type Suite

type Suite struct {
	// Dir is the directory holding the .txtar scripts (testscript.Params.Dir).
	Dir string
	// Update mirrors the repo-wide -update convention: goldens rewrite instead of
	// failing on drift. cmpshape assertions are NEVER rewritten — see [shapecheck].
	Update bool
	// FakeClockStart pins the inproc lane's fake clock. Zero means the suite
	// default, so every script starts from the same instant.
	FakeClockStart time.Time
}

Suite configures one testscript run. Tests build it, hand it to Params, and never touch the per-script state themselves.

func (*Suite) Params

func (s *Suite) Params() testscript.Params

Params returns the testscript.Params for this suite: the command registry, the determinism setup, and the -update wiring.

Jump to

Keyboard shortcuts

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