Documentation
¶
Overview ¶
Package scenario provides types and functions for loading and validating cli-replay scenario files.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CallBounds ¶
CallBounds specifies the allowed invocation range for a step. When nil on a Step, EffectiveCalls() returns {Min: 1, Max: 1}.
func (*CallBounds) Validate ¶
func (cb *CallBounds) Validate() error
Validate checks that the call bounds are valid.
type GroupRange ¶
type GroupRange struct {
Start int // Inclusive flat index of first group child
End int // Exclusive flat index (Start + len(group.Steps))
Name string // Group name (resolved, never empty)
TopIndex int // Index of the group in the top-level Steps array
}
GroupRange describes the flat-index extent of a single step group.
type Meta ¶
type Meta struct {
Name string `yaml:"name"`
Description string `yaml:"description,omitempty"`
Vars map[string]string `yaml:"vars,omitempty"`
Security *Security `yaml:"security,omitempty"`
Session *Session `yaml:"session,omitempty"`
}
Meta contains scenario metadata including identification and template variables.
type Response ¶
type Response struct {
Exit int `yaml:"exit"`
Stdout string `yaml:"stdout,omitempty"`
Stderr string `yaml:"stderr,omitempty"`
StdoutFile string `yaml:"stdout_file,omitempty"`
StderrFile string `yaml:"stderr_file,omitempty"`
Delay string `yaml:"delay,omitempty"`
Capture map[string]string `yaml:"capture,omitempty"`
}
Response defines the output for a matched command.
type Scenario ¶
type Scenario struct {
Meta Meta `yaml:"meta"`
Steps []StepElement `yaml:"steps"`
}
Scenario represents a complete test definition loaded from a YAML file.
func Load ¶
Load parses a scenario from the given reader with strict field validation. Unknown fields in the YAML will cause an error.
func (*Scenario) FlatSteps ¶
FlatSteps returns all leaf steps expanded inline. Groups are replaced by their child steps in order. The result preserves contiguous flat indices.
func (*Scenario) GroupRanges ¶
func (s *Scenario) GroupRanges() []GroupRange
GroupRanges returns the flat-index ranges for all groups in the scenario.
type Security ¶
type Security struct {
AllowedCommands []string `yaml:"allowed_commands,omitempty"`
DenyEnvVars []string `yaml:"deny_env_vars,omitempty"`
}
Security defines constraints on which commands may be intercepted.
type Session ¶
type Session struct {
TTL string `yaml:"ttl,omitempty"`
}
Session defines session lifecycle configuration.
type Step ¶
type Step struct {
Match Match `yaml:"match"`
Respond Response `yaml:"respond"`
Calls *CallBounds `yaml:"calls,omitempty"`
When string `yaml:"when,omitempty"`
}
Step represents a single command-response pair within a scenario.
func (*Step) EffectiveCalls ¶
func (s *Step) EffectiveCalls() CallBounds
EffectiveCalls returns the call bounds for this step, applying defaults when the Calls field is nil (backward compatible: exactly one call).
type StepElement ¶
type StepElement struct {
Step *Step `yaml:"-"` // Set when YAML has match/respond (leaf step)
Group *StepGroup `yaml:"-"` // Set when YAML has group key
}
StepElement is a union type — exactly one of Step or Group is non-nil. It represents either a leaf step or a group container in the steps array.
func (StepElement) MarshalYAML ¶
func (se StepElement) MarshalYAML() (interface{}, error)
MarshalYAML implements custom YAML marshaling for StepElement. It serializes the underlying Step or group wrapper so that fields tagged yaml:"-" are emitted correctly.
func (*StepElement) UnmarshalYAML ¶
func (se *StepElement) UnmarshalYAML(value *yaml.Node) error
UnmarshalYAML implements custom YAML unmarshaling for StepElement. It inspects the mapping keys to determine whether the node represents a leaf step (has "match") or a group (has "group"), then dispatches to the appropriate type.
func (*StepElement) Validate ¶
func (se *StepElement) Validate() error
Validate checks that exactly one of Step or Group is set and validates it.
type StepGroup ¶
type StepGroup struct {
Mode string `yaml:"mode"`
Name string `yaml:"name,omitempty"`
Steps []StepElement `yaml:"steps"`
}
StepGroup defines a group of steps with unordered matching semantics.
func (*StepGroup) UnmarshalYAML ¶
UnmarshalYAML implements custom YAML unmarshaling for StepGroup. It decodes the group's mode, name, and steps fields.