experiment

package
v6.2.2 Latest Latest
Warning

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

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

Documentation

Overview

Package experiment implements `experiment get`, `apply` and `run`.

Experiment designs pass through as documents rather than generated structs: decoding a file into typed Go values and encoding it again would drop fields the spec does not know yet and rewrite zero values, silently changing files kept in Git. The generated client still types every path, parameter and the smaller request bodies.

Index

Constants

This section is empty.

Variables

View Source
var ErrIncomplete = fmt.Errorf("incomplete dump")

ErrIncomplete makes the command exit non-zero after everything that could be fetched has been written, so that a pipeline does not mistake a partial dump for a full one.

View Source
var ErrTimedOut = errors.New("timed out")

ErrTimedOut is returned when --timeout cancelled the run.

View Source
var ErrUnexpected = errors.New("the run did not end as expected")

ErrUnexpected marks a run that did not end as expected, by --expect-state and --expect-reason or by completing, which --expectation-retries runs again.

View Source
var Interactive = func() bool { return term.IsTerminal(int(os.Stdin.Fd())) }

Interactive reports whether questions can be asked. Tests replace it.

View Source
var PollInterval = 5 * time.Second

PollInterval is how often --wait asks for the state of a run. Tests shorten it.

View Source
var StartCheckDelay = 2 * time.Second

StartCheckDelay is how long --no-wait gives a run before first looking at it. The platform accepts a run and may cancel it moments later, when its validation finds another experiment running; unchecked, a pipeline would pass on a run that never ran.

View Source
var StartCheckTimeout = 15 * time.Second

StartCheckTimeout bounds the whole check, requests and the client's back-off included: --no-wait promises not to wait for the run, so a slow platform only earns a warning.

Functions

func Apply

func Apply(ctx context.Context, c *platform.Client, o ApplyOptions) error

func ApplyTemplate

func ApplyTemplate(ctx context.Context, c *platform.Client, key string, o TemplateOptions) error

ApplyTemplate creates an experiment from a template, or updates the one with key.

func Delete

func Delete(ctx context.Context, c *platform.Client, key string) error

Delete removes an experiment.

func Dump

func Get

func Init

Init walks through creating an experiment from a template: which template, its placeholders, the team and environment. It creates the experiment and writes it to a file, ready for `run -f` and for Git.

func ResolveFiles

func ResolveFiles(paths []string, recursive bool) ([]string, error)

ResolveFiles expands directories into their YAML files, recursively on request.

func ResolvePlaceholders

ResolvePlaceholders reads the placeholders file, a map of key to value or the platform's list of {key, value}, and applies -p values on top, so that a pipeline can keep shared values in a file and override one per stage.

func Run

func WriteGitHubSummary

func WriteGitHubSummary(runs []*RunResult) error

WriteGitHubSummary appends a Markdown summary of the runs to the job summary when the CLI runs in GitHub Actions, which names the file in GITHUB_STEP_SUMMARY.

func WriteReport

func WriteReport(file string, runs []*RunResult) error

WriteReport writes the runs as JUnit XML, which CI systems show as test results, or as JSON, chosen by the file's extension.

Types

type ApplyOptions

type ApplyOptions struct {
	Key       string
	Files     []string
	Recursive bool
}

type Document

type Document = *output.Document

func Fetch

func Fetch(ctx context.Context, c *platform.Client, key string) (Document, error)

type DumpOptions

type DumpOptions struct {
	Directory string
	Type      string
	Teams     []string
}

type GetOptions

type GetOptions struct {
	Key, File, Type string
}

type InitOptions

type InitOptions struct {
	Template    string
	Team        string
	Environment string
	File        string
}

type RunOptions

type RunOptions struct {
	Key           string
	Files         []string
	Recursive     bool
	Yes, Wait     bool
	AllowParallel bool
	Retries       int
	RetryInterval int
	// Parallel is how many runs go at once; 0 or 1 runs them one after another.
	Parallel int
	// BusyRetries tries a run again, BusyRetryInterval apart, when another experiment is
	// running and running in parallel is not allowed, instead of asking or failing.
	BusyRetries       int
	BusyRetryInterval time.Duration
	// ExpectationRetries runs an experiment again, ExpectationRetryInterval apart, when
	// its run did not end as expected.
	ExpectationRetries       int
	ExpectationRetryInterval time.Duration
	WaitOptions
	// Report is a file to write a JUnit (or, for .json, JSON) report of the runs to.
	Report string

	TemplateOptions
}

type RunResult

type RunResult struct {
	ID         int64     `json:"id"`
	Key        string    `json:"key"`
	Name       string    `json:"name"`
	State      string    `json:"state"`
	Reason     string    `json:"reason,omitempty"`
	Started    time.Time `json:"started"`
	Ended      time.Time `json:"ended"`
	UILocation string    `json:"uiLocation,omitempty"`
	// APILocation is where the platform's API serves the run, as run-experiment's
	// executionUrl output names it.
	APILocation string `json:"apiLocation,omitempty"`
	Steps       []Step `json:"steps"`
}

RunResult is a finished (or abandoned) experiment run, as reports describe it.

func (RunResult) Duration

func (r RunResult) Duration() time.Duration

type Step

type Step struct {
	Name    string    `json:"name"`
	State   string    `json:"state"`
	Reason  string    `json:"reason,omitempty"`
	Started time.Time `json:"started"`
	Ended   time.Time `json:"ended"`
}

func (Step) Duration

func (s Step) Duration() time.Duration

type TemplateOptions

type TemplateOptions struct {
	Template          string
	Team              string
	Environment       string
	ExternalID        string
	Placeholder       *jsyaml.Map
	PlaceholdersFile  string
	Variable          *jsyaml.Map
	ResetProperties   bool
	ExecutionVariable *jsyaml.Map
}

type WaitOptions

type WaitOptions struct {
	// Timeout cancels the run once it has taken this long; zero waits indefinitely.
	Timeout time.Duration
	// KeepRunningOnInterrupt leaves the run going when the CLI is interrupted, as the
	// TypeScript CLI did. By default it is cancelled: an aborted pipeline should not
	// leave an attack running on its own.
	KeepRunningOnInterrupt bool
	// ShowSteps prints each step's state as it changes.
	ShowSteps bool
	// Prefix starts each line about the run, telling runs apart when several go at once.
	Prefix string
	// ExpectState passes the run once it reaches this state, which need not be an end
	// such as RUNNING, and fails it when it ends in another. A run that ended passes a
	// state it went through without a poll seeing it. Empty expects COMPLETED.
	ExpectState string
	// ExpectReason also requires the run's reason to be exactly this.
	ExpectReason string
	// Steps asks the platform for the steps of the run, which reports need.
	Steps bool
}

WaitOptions shape what `run --wait` does besides waiting.

Jump to

Keyboard shortcuts

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