runner

package
v0.20.3 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package runner discovers rehearse scenario files, executes their step blocks through the block-executor registry, and renders the run report (REQ: scenario-discovery, REQ: scenario-shape, REQ: run-report).

Index

Constants

View Source
const (
	StatusPass    = "pass"
	StatusFail    = "fail"
	StatusSkipped = "skipped"
	StatusNoSteps = "no-steps"
)

Scenario statuses (REQ: scenario-shape, REQ: run-report).

View Source
const StepStatusSkipped = "skipped-after-failure"

StepStatusSkipped marks steps after the first failing step (REQ: scenario-shape).

Variables

View Source
var (

	// ExecCommandFn is the test seam for git invocations: it runs name with
	// args in dir and returns stdout. Exported so CLI-layer tests can control
	// git provenance output without touching the filesystem.
	// Feature: cli/rehearse/evidence (REQ: report-provenance)
	ExecCommandFn = execCommandOutput
)

Test seams — package-level vars wrapping external functions. Production code calls these vars; tests replace them via t.Cleanup.

View Source
var NowFn = func() time.Time { return time.Now() }

NowFn is the test seam for time.Now. The CLI calls this to capture the run start time before dispatching to Run, so tests can control started_at. Feature: cli/rehearse/evidence (REQ: report-provenance)

Functions

func CountFailed

func CountFailed(reports []ScenarioReport) int

CountFailed returns how many scenarios failed (drives exit code 1, REQ: run-report).

func Discover

func Discover(paths []string, cwd string) ([]string, error)

Discover resolves the run's scenario files (REQ: scenario-discovery). Each path may be a file, a directory (scanned recursively for *.md, excluding README.md), or a glob. With no paths, it defaults to every scenario under spec/features/**/_tests/ of the SpecScore repo enclosing cwd. Explicit paths need no specscore.yaml (standalone mode). Zero discovered scenarios is a config error (exit 2), not an empty pass.

func GitProvenance

func GitProvenance(dir string) (sha string, dirty bool)

GitProvenance collects HEAD SHA and dirty flag from the working tree at dir. Outside a git work tree (or when git is unavailable) it returns empty SHA and dirty=false — provenance is honest, never invented. Feature: cli/rehearse/evidence (REQ: report-provenance)

func RenderHuman

func RenderHuman(w io.Writer, reports []ScenarioReport)

RenderHuman writes the human report: one line per scenario — status, file path, Verifies AC ids, duration — plus a totals line (REQ: run-report). Failing scenarios additionally get their failure detail and captured step output as indented diagnostic lines (REQ: bash-block).

func WriteReport

func WriteReport(path string, runnerVersion string, startedAt time.Time, reports []ScenarioReport, dir string) error

WriteReport persists the run report envelope to path, creating parent directories as needed. The scenarios' file paths are made repo-root-relative when dir is inside a git work tree (the stdout report keeps its paths as-is).

Feature: cli/rehearse/evidence (REQ: report-out, REQ: report-provenance)

Types

type Bag

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

Bag is one scenario run's context bag (REQ: context-bag): an ordered map of string variables. Steps feed it via their StepResult captures; consumption is per block class — bash/sql/dtql get {{name}} textual interpolation before dispatch, hurl-derived blocks receive the ordered Snapshot through StepCtx.Vars and hand it to Hurl as --variable flags.

func NewBag

func NewBag() *Bag

NewBag returns an empty context bag.

func (*Bag) Interpolate

func (b *Bag) Interpolate(text string) (string, error)

Interpolate textually replaces every {{name}} placeholder with the bag's value for name. An unknown variable is an error naming it — the step fails instead of running with a literal placeholder (REQ: context-bag).

func (*Bag) Map

func (b *Bag) Map() map[string]string

Map returns a copy of the bag's final state for the JSON report (REQ: run-report). Never nil.

func (*Bag) Merge

func (b *Bag) Merge(captures []blocks.Capture)

Merge folds a step's captures into the bag: new names append in capture order, existing names update in place (first-insertion order is kept).

func (*Bag) Snapshot

func (b *Bag) Snapshot() []blocks.Capture

Snapshot returns the bag as ordered name/value pairs — the shape hurl-derived executors turn into `--variable name=value` flags.

type RunReport

type RunReport struct {
	RunnerVersion string           `json:"runner_version"`
	GitSHA        string           `json:"git_sha"`
	GitDirty      bool             `json:"git_dirty"`
	StartedAt     string           `json:"started_at"`
	Scenarios     []ScenarioReport `json:"scenarios"`
}

RunReport is the persisted report envelope written by --report-out. It carries run provenance alongside the scenario results. Feature: cli/rehearse/evidence (REQ: report-provenance)

type ScenarioReport

type ScenarioReport struct {
	File       string            `json:"file"`
	Status     string            `json:"status"`
	Verifies   []string          `json:"verifies"`
	DurationMS int64             `json:"duration_ms"`
	Bag        map[string]string `json:"bag"`
	Steps      []StepReport      `json:"steps"`
	// Detail carries scenario-level failure detail (e.g. a parse error).
	Detail string `json:"detail,omitempty"`
	// FilterStatus is "match" or "skip" when --filter is active; omitted otherwise.
	// Feature: cli/rehearse/run-filter (REQ: filter-output-labels)
	FilterStatus string `json:"filter_status,omitempty"`
	// Expect is "fail" when the scenario declared `**Expect:** fail`; omitted for
	// the default. A reported "pass" with Expect=="fail" is a correctly-failing
	// negative scenario. Feature: cli/rehearse/expected-fail (REQ: expect-in-report)
	Expect string `json:"expect,omitempty"`
	// Case is the `### When …` branch label when this report is one case of a
	// nested scenario suite; omitted for a flat scenario. Feature:
	// cli/rehearse/nested-suites.
	Case string `json:"case,omitempty"`
}

ScenarioReport is one scenario's outcome in the JSON report (REQ: run-report).

func Run

func Run(reg blocks.Registry, files []string) []ScenarioReport

Run executes the scenario files in order and returns one report per scenario. Failures never abort the run; they are reported per scenario.

type StepReport

type StepReport struct {
	Kind   string `json:"kind"`
	Status string `json:"status"`
	Detail string `json:"detail,omitempty"`
	Output string `json:"output,omitempty"`
}

StepReport is one executed (or skipped) step in the JSON report (REQ: run-report).

Jump to

Keyboard shortcuts

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