runner

package
v0.27.0 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: AGPL-3.0 Imports: 22 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 runner executes deterministic sailwright E2E scenarios. Scenarios are YAML data; the runner maps their steps to an Executor, either the CLI directly or the sailwright-gateway over MCP. The runner knows what to test and what to expect; the gateway only decides how commands may run.

Index

Constants

View Source
const (
	EnvExecutor         = "SAILWRIGHT_E2E_EXECUTOR"
	EnvBinary           = "SAILWRIGHT_E2E_BIN"
	EnvTarget           = "SAILWRIGHT_E2E_TARGET"
	EnvAllowHostChanges = "SAILWRIGHT_E2E_ALLOW_HOST_CHANGES"
	EnvOutDir           = "SAILWRIGHT_E2E_OUT"
	EnvIncludeUnstable  = "SAILWRIGHT_E2E_INCLUDE_UNSTABLE"
)

Environment variables understood by the E2E module.

View Source
const (
	ExecutorDirect  = "direct"
	ExecutorGateway = "gateway"
)

Executor names.

View Source
const (
	StatusPassed  = "passed"
	StatusFailed  = "failed"
	StatusSkipped = "skipped"
)

Step statuses.

View Source
const (
	OpBuild          = "build"
	OpCreate         = "create"
	OpStart          = "start"
	OpStop           = "stop"
	OpDestroy        = "destroy"
	OpProvision      = "provision"
	OpPull           = "pull"
	OpProvisionLocal = "provision_local"
	OpList           = "list"
	OpCLI            = "cli"
)

Operations understood by every executor.

View Source
const (
	// RequireTarget needs SAILWRIGHT_E2E_TARGET.
	RequireTarget = "target"
	// RequireHostChanges needs host approval (gateway) or SAILWRIGHT_E2E_ALLOW_HOST_CHANGES=1 (direct).
	RequireHostChanges = "host-changes"
)

Requirements a scenario can declare.

Variables

View Source
var ErrStepNotSupported = errors.New("step not supported by this executor")

ErrStepNotSupported is returned when an executor cannot run an operation.

Functions

func DirectArgv

func DirectArgv(req StepRequest) ([]string, error)

DirectArgv maps a step to sailwright argv. The gateway applies its own grammar to the equivalent tool call, so both executors run the same command.

func Markdown

func Markdown(report Report) string

Markdown renders a human-readable report.

func ParseRecap

func ParseRecap(output string) (map[string]int, bool)

ParseRecap sums the counters of every host line in the last Ansible PLAY RECAP.

func PlanMatrix

func PlanMatrix(ctx context.Context, scenario Scenario, executor Executor, opts MatrixOptions) ([]TargetPlan, []ListedTarget, error)

PlanMatrix decides which matrix targets run on this host. It also returns targets of the scenario's covers command that the matrix does not contain.

func UnknownEnv

func UnknownEnv(environ []string, scenarios []Scenario) []string

UnknownEnv returns SAILWRIGHT_E2E_* variables from environ that neither the runner nor any scenario uses, which usually means a typo such as SAILWRIGHT_E2E_TARGETS.

func WriteReports

func WriteReports(dir string, report Report) error

WriteReports writes <dir>/<scenario>.json and <scenario>.md.

Types

type Config

type Config struct {
	Executor         string
	Binary           string
	Target           *Target
	AllowHostChanges bool
	OutDir           string
	IncludeUnstable  bool
	// Gateway is the discovered gateway endpoint (gateway executor only), see
	// internal/gateway/client for the discovery rules.
	Gateway client.Endpoint
}

Config selects and configures the executor.

func ConfigFromEnv

func ConfigFromEnv(getenv func(string) string) (Config, error)

ConfigFromEnv reads the E2E configuration from the environment.

type DirectExecutor

type DirectExecutor struct {
	Binary string
	// AllowHostChanges enables provision_local and other host-modifying steps.
	AllowHostChanges bool
	// Stream receives live output (optional).
	Stream io.Writer
}

DirectExecutor runs the sailwright binary itself. It is meant for disposable CI runners and for a human on the host; agents use the gateway executor.

func (*DirectExecutor) Describe

Describe implements Executor.

func (*DirectExecutor) HostChangesAllowed

func (d *DirectExecutor) HostChangesAllowed(context.Context) (bool, string)

HostChangesAllowed implements Executor.

func (*DirectExecutor) List

func (d *DirectExecutor) List(ctx context.Context, command string) ([]ListedTarget, error)

List implements Executor.

func (*DirectExecutor) Name

func (d *DirectExecutor) Name() string

Name implements Executor.

func (*DirectExecutor) Run

func (d *DirectExecutor) Run(ctx context.Context, req StepRequest) (Result, error)

Run implements Executor.

type Environment

type Environment struct {
	Executor     string `json:"executor"`
	HostOS       string `json:"host_os"`
	HostArch     string `json:"host_arch"`
	BinarySHA256 string `json:"binary_sha256,omitempty"`
	Gateway      string `json:"gateway,omitempty"`
}

Environment describes where the scenario ran.

type Executor

type Executor interface {
	Name() string
	Describe(ctx context.Context) (Environment, error)
	Run(ctx context.Context, req StepRequest) (Result, error)
	List(ctx context.Context, command string) ([]ListedTarget, error)
	// HostChangesAllowed reports whether host-modifying steps can run at all.
	HostChangesAllowed(ctx context.Context) (bool, string)
}

Executor runs scenario steps.

func NewExecutor

func NewExecutor(ctx context.Context, cfg Config, stream io.Writer) (Executor, func() error, error)

NewExecutor creates and connects the configured executor.

type Expect

type Expect struct {
	ExitCode       *int              `yaml:"exit_code"`
	OutputRegex    string            `yaml:"output_regex"`
	OutputNotRegex string            `yaml:"output_not_regex"`
	Recap          map[string]int    `yaml:"recap"`
	State          *StateExpectation `yaml:"state"`
	MaxDuration    string            `yaml:"max_duration"`
	// contains filtered or unexported fields
}

Expect describes what a step must produce. Without exit_code, 0 is expected.

type GatewayExecutor

type GatewayExecutor struct {
	Endpoint     client.Endpoint
	PollInterval time.Duration
	// Stream receives live job output (optional).
	Stream io.Writer
	// contains filtered or unexported fields
}

GatewayExecutor runs steps through sailwright-gateway over MCP. Every step passes the gateway policy: safe steps run directly, everything else waits for host approval.

func (*GatewayExecutor) Close

func (g *GatewayExecutor) Close() error

Close closes the MCP session.

func (*GatewayExecutor) Connect

func (g *GatewayExecutor) Connect(ctx context.Context) error

Connect opens the MCP session.

func (*GatewayExecutor) Describe

func (g *GatewayExecutor) Describe(ctx context.Context) (Environment, error)

Describe implements Executor.

func (*GatewayExecutor) HostChangesAllowed

func (g *GatewayExecutor) HostChangesAllowed(ctx context.Context) (bool, string)

HostChangesAllowed implements Executor.

func (*GatewayExecutor) List

func (g *GatewayExecutor) List(ctx context.Context, command string) ([]ListedTarget, error)

List implements Executor.

func (*GatewayExecutor) Name

func (g *GatewayExecutor) Name() string

Name implements Executor.

func (*GatewayExecutor) Run

func (g *GatewayExecutor) Run(ctx context.Context, req StepRequest) (Result, error)

Run implements Executor.

type ListedTarget

type ListedTarget struct {
	OS     string            `json:"os"`
	Type   string            `json:"type"`
	Arch   string            `json:"arch"`
	Engine string            `json:"engine"`
	Fields map[string]string `json:"fields"`
}

ListedTarget is one entry of `<command> list --json`.

func FindTarget

func FindTarget(targets []ListedTarget, target Target) (ListedTarget, bool)

FindTarget returns the listed entry for a scenario target.

type MatrixOptions

type MatrixOptions struct {
	// Filter runs only matrix targets that match it (SAILWRIGHT_E2E_TARGET).
	Filter *Target
	// IncludeUnstable also runs targets the CLI marks unstable, such as emulated
	// architectures (SAILWRIGHT_E2E_INCLUDE_UNSTABLE=1).
	IncludeUnstable bool
}

MatrixOptions narrow a matrix run.

type PrefixWriter

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

PrefixWriter prefixes every line written to it, so live command output stands out from the test log. Partial lines are held until they are complete.

func NewPrefixWriter

func NewPrefixWriter(next io.Writer, prefix string) *PrefixWriter

NewPrefixWriter returns a PrefixWriter writing to next.

func (*PrefixWriter) Write

func (w *PrefixWriter) Write(p []byte) (int, error)

Write implements io.Writer.

type Report

type Report struct {
	// ID names the report files: the scenario, plus the target for matrix runs.
	ID          string        `json:"id"`
	Scenario    string        `json:"scenario"`
	Description string        `json:"description,omitempty"`
	Target      Target        `json:"target"`
	Environment Environment   `json:"environment"`
	Started     time.Time     `json:"started"`
	Duration    time.Duration `json:"duration_ns"`
	Passed      bool          `json:"passed"`
	Steps       []StepReport  `json:"steps"`
}

Report is the outcome of one scenario.

func Run

func Run(ctx context.Context, scenario Scenario, executor Executor, opts RunOptions) Report

Run executes a scenario. After the first failed step the remaining steps are skipped, but `always` steps still run, unless a preflight step failed: then the scenario has not changed anything and nothing runs after the preflight.

func (Report) Failures

func (r Report) Failures() []StepReport

Failures returns the failed steps.

type Result

type Result struct {
	Argv     []string
	ExitCode int
	Output   string
	Note     string
}

Result is what an executor reports for one operation.

type RunOptions

type RunOptions struct {
	Target Target
	// Matrix marks a run of one target of a matrix scenario; reports get the
	// target in their name.
	Matrix bool
	Getenv func(string) string
	Logf   func(format string, args ...any)
	Now    func() time.Time
}

RunOptions configure a scenario run.

type Scenario

type Scenario struct {
	Name        string   `yaml:"name"`
	Description string   `yaml:"description"`
	Requires    []string `yaml:"requires"`
	// HostOS limits the scenario to one host OS: linux, darwin or windows.
	HostOS string `yaml:"host_os"`
	// Targets turns the scenario into a matrix: the steps run once per target.
	Targets []string `yaml:"targets"`
	// Covers names a list command whose targets must all appear in Targets, so new
	// VM options cannot silently go untested.
	Covers string `yaml:"covers"`
	// Preflight steps check that the host is fit for the scenario before it changes
	// anything. If one fails, the steps and the always steps are skipped, so cleanup
	// never touches state the scenario did not create, such as an existing VM.
	Preflight []Step `yaml:"preflight"`
	Steps     []Step `yaml:"steps"`
	Always    []Step `yaml:"always"`

	File string `yaml:"-"`
	// contains filtered or unexported fields
}

Scenario is one deterministic test case.

func LoadScenario

func LoadScenario(path string) (Scenario, error)

LoadScenario reads and validates one scenario file. Unknown fields are errors.

func LoadScenarios

func LoadScenarios(dir string) ([]Scenario, error)

LoadScenarios reads every *.yaml file in dir, sorted by name.

func (Scenario) EnvReferences

func (s Scenario) EnvReferences() []string

EnvReferences returns the environment variables a scenario reads through when_env, unless_env or ${SAILWRIGHT_E2E_*} references in step parameters.

func (Scenario) Matrix

func (s Scenario) Matrix() []Target

Matrix returns the parsed targets matrix (empty for single-target scenarios).

func (Scenario) Needs

func (s Scenario) Needs(requirement string) bool

Needs reports whether the scenario declares a requirement.

type StateExpectation

type StateExpectation struct {
	Command string `yaml:"command"`
	Field   string `yaml:"field"`
	Regex   string `yaml:"regex"`
	// contains filtered or unexported fields
}

StateExpectation checks a field of `<command> list --json` for the scenario target.

type Step

type Step struct {
	Name      string         `yaml:"name"`
	Op        string         `yaml:"op"`
	With      map[string]any `yaml:"with"`
	Expect    Expect         `yaml:"expect"`
	WhenEnv   string         `yaml:"when_env"`
	UnlessEnv string         `yaml:"unless_env"`
	Only      string         `yaml:"only"`
	// WhenListed runs the step only if the target appears in `<command> list`,
	// e.g. build is skipped for targets that use a public image.
	WhenListed string `yaml:"when_listed"`
	// CancelAfter cancels the step's command after this duration, the way a user
	// cancels a gateway job. The step passes when the command was still running then;
	// expect.state is checked afterwards, the exit code is not.
	CancelAfter string `yaml:"cancel_after"`
	// contains filtered or unexported fields
}

Step is one operation plus its expectations.

func (Step) Args

func (st Step) Args(getenv func(string) string) []string

Args returns the cli args with ${SAILWRIGHT_E2E_*} references expanded.

func (Step) Bool

func (st Step) Bool(key string) bool

Bool returns a boolean parameter.

func (Step) Enabled

func (st Step) Enabled(executor string, getenv func(string) string) (bool, string)

Enabled reports whether the step runs for this executor and environment.

func (Step) Int

func (st Step) Int(key string) (int, bool)

Int returns an integer parameter and whether it was set.

func (Step) String

func (st Step) String(key string, getenv func(string) string) string

String returns a string parameter with ${SAILWRIGHT_E2E_*} references expanded.

type StepReport

type StepReport struct {
	Name       string        `json:"name"`
	Op         string        `json:"op"`
	Preflight  bool          `json:"preflight,omitempty"`
	Always     bool          `json:"always,omitempty"`
	Status     string        `json:"status"`
	Argv       []string      `json:"argv,omitempty"`
	ExitCode   *int          `json:"exit_code,omitempty"`
	Duration   time.Duration `json:"duration_ns"`
	Reason     string        `json:"reason,omitempty"`
	OutputTail string        `json:"output_tail,omitempty"`
}

StepReport is the outcome of one step.

type StepRequest

type StepRequest struct {
	Step   Step
	Target Target
	Getenv func(string) string
	Logf   func(format string, args ...any)
}

StepRequest is one operation for an executor.

type Target

type Target struct {
	OS   string `json:"os"`
	Type string `json:"type,omitempty"`
	Arch string `json:"arch,omitempty"`
	// Engine selects the virtualization engine for build and pull when a host offers
	// several for the same OS/type/arch (e.g. Hyper-V and VirtualBox on Windows).
	Engine string `json:"engine,omitempty"`
}

Target identifies the VM a scenario works on.

func ParseTarget

func ParseTarget(value string) (Target, error)

ParseTarget parses "os[/type][/arch][/engine]", e.g. "ubuntu/server/amd64", "windows11//arm64" or "windows11//amd64/hyperv".

func (Target) Slug

func (t Target) Slug() string

Slug renders the target for file and subtest names, e.g. ubuntu-server-amd64.

func (Target) String

func (t Target) String() string

String renders the target as os/type/arch[/engine].

type TargetPlan

type TargetPlan struct {
	Target Target
	Skip   string
}

TargetPlan is one matrix entry and why it is skipped, if it is.

Jump to

Keyboard shortcuts

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