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
- Variables
- func DirectArgv(req StepRequest) ([]string, error)
- func Markdown(report Report) string
- func ParseRecap(output string) (map[string]int, bool)
- func PlanMatrix(ctx context.Context, scenario Scenario, executor Executor, opts MatrixOptions) ([]TargetPlan, []ListedTarget, error)
- func UnknownEnv(environ []string, scenarios []Scenario) []string
- func WriteReports(dir string, report Report) error
- type Config
- type DirectExecutor
- func (d *DirectExecutor) Describe(context.Context) (Environment, error)
- func (d *DirectExecutor) HostChangesAllowed(context.Context) (bool, string)
- func (d *DirectExecutor) List(ctx context.Context, command string) ([]ListedTarget, error)
- func (d *DirectExecutor) Name() string
- func (d *DirectExecutor) Run(ctx context.Context, req StepRequest) (Result, error)
- type Environment
- type Executor
- type Expect
- type GatewayExecutor
- func (g *GatewayExecutor) Close() error
- func (g *GatewayExecutor) Connect(ctx context.Context) error
- func (g *GatewayExecutor) Describe(ctx context.Context) (Environment, error)
- func (g *GatewayExecutor) HostChangesAllowed(ctx context.Context) (bool, string)
- func (g *GatewayExecutor) List(ctx context.Context, command string) ([]ListedTarget, error)
- func (g *GatewayExecutor) Name() string
- func (g *GatewayExecutor) Run(ctx context.Context, req StepRequest) (Result, error)
- type ListedTarget
- type MatrixOptions
- type PrefixWriter
- type Report
- type Result
- type RunOptions
- type Scenario
- type StateExpectation
- type Step
- type StepReport
- type StepRequest
- type Target
- type TargetPlan
Constants ¶
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.
const ( ExecutorDirect = "direct" ExecutorGateway = "gateway" )
Executor names.
const ( StatusPassed = "passed" StatusFailed = "failed" StatusSkipped = "skipped" )
Step statuses.
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.
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 ¶
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 ParseRecap ¶
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 ¶
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 ¶
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.
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 ¶
func (d *DirectExecutor) Describe(context.Context) (Environment, error)
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) 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.
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) 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.
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.
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 ¶
LoadScenario reads and validates one scenario file. Unknown fields are errors.
func LoadScenarios ¶
LoadScenarios reads every *.yaml file in dir, sorted by name.
func (Scenario) EnvReferences ¶
EnvReferences returns the environment variables a scenario reads through when_env, unless_env or ${SAILWRIGHT_E2E_*} references in step parameters.
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.
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 ¶
ParseTarget parses "os[/type][/arch][/engine]", e.g. "ubuntu/server/amd64", "windows11//arm64" or "windows11//amd64/hyperv".
type TargetPlan ¶
TargetPlan is one matrix entry and why it is skipped, if it is.