Documentation
¶
Overview ¶
Package testscenario owns lifecycle evidence and cleanup verdicts for native integration and process E2E scenarios. Protocol-specific tests retain their own milestones; this package owns the ordering rules every scenario shares.
Index ¶
- Constants
- Variables
- type CleanupContext
- type CleanupFunc
- type FailureContext
- type Phase
- type TerminalContext
- type Trace
- func (trace *Trace) AddCleanup(name string, cleanup CleanupFunc) error
- func (trace *Trace) Events() []testrun.Event
- func (trace *Trace) Finish() error
- func (trace *Trace) Finished() bool
- func (trace *Trace) MarkFunctionalSuccess() error
- func (trace *Trace) Record(milestone testrun.Milestone, outcome testrun.Outcome, payload any) error
- func (trace *Trace) RequireCleanup(t testContext, name string, cleanup CleanupFunc)
- func (trace *Trace) RequireRecord(t testContext, milestone testrun.Milestone, outcome testrun.Outcome, ...)
- func (trace *Trace) RequireSuccess(t testContext)
- func (trace *Trace) StartPhase(milestone testrun.Milestone, payload any) (*Phase, error)
Constants ¶
const ( // MaximumCleanupOwners bounds both retained ownership state and the number of // caller-controlled callbacks that a terminal transition can attempt. MaximumCleanupOwners = 32 // MaximumCleanupOwnerNameBytes bounds retained labels and failure diagnostics. MaximumCleanupOwnerNameBytes = 128 // CleanupOwnerTimeout bounds one uncooperative owner, while // ScenarioCleanupTimeout bounds the sum of leases allocated across one // reverse-order cleanup transition. CleanupOwnerTimeout = 15 * time.Second ScenarioCleanupTimeout = 60 * time.Second )
const ( // MaximumFailureReasonBytes keeps machine-consumed failure decisions bounded. MaximumFailureReasonBytes = 128 // MaximumPhasesPerScenario prevents a faulty fixture from retaining an // unbounded number of settlement authorities. MaximumPhasesPerScenario = 128 // MaximumScenarioEvidenceEvents reserves enough recorder capacity for every // phase settlement plus the cleanup and terminal records owned by Finish. MaximumScenarioEvidenceEvents = 512 // InterruptedFailureReason closes a phase whose caller never published a result. InterruptedFailureReason = "scenario_interrupted" )
Variables ¶
var ( // ErrCleanupTimeout identifies an owner that did not honor its cleanup lease. ErrCleanupTimeout = errors.New("test scenario cleanup timed out") // ErrCleanupPanic isolates a caller cleanup panic from the terminal owner. ErrCleanupPanic = errors.New("test scenario cleanup panicked") )
var ( // ErrInvalid rejects malformed ownership or lifecycle operations. ErrInvalid = errors.New("test scenario lifecycle is invalid") // ErrRetired prevents mutation after the functional seal or terminal owner takes control. ErrRetired = errors.New("test scenario lifecycle is retired") // ErrIncomplete means the functional oracle was never authoritatively marked successful. ErrIncomplete = errors.New("test scenario did not reach its verified success boundary") // ErrPhaseActive prevents success while a started milestone lacks an outcome. ErrPhaseActive = errors.New("test scenario phase is still active") // ErrPhaseSettled prevents a second, contradictory outcome for one started milestone. ErrPhaseSettled = errors.New("test scenario phase is already settled") // ErrFailureReason rejects unbounded or non-semantic failure prose. ErrFailureReason = errors.New("test scenario failure reason is invalid") // ErrCapacity rejects lifecycle growth that would make terminal evidence or // callback latency unbounded. ErrCapacity = errors.New("test scenario lifecycle capacity exceeded") )
Functions ¶
This section is empty.
Types ¶
type CleanupContext ¶
type CleanupContext struct {
FailureCount int `json:"failure_count"`
}
CleanupContext makes aggregate cleanup failure count machine-readable.
type CleanupFunc ¶
CleanupFunc receives a framework-owned lease. The lifecycle also enforces the lease mechanically, so a callback that ignores cancellation cannot block the remaining cleanup owners or terminal evidence.
type FailureContext ¶
type FailureContext struct {
Reason string `json:"reason"`
}
FailureContext carries a stable decision token rather than unbounded error prose.
type Phase ¶
type Phase struct {
// contains filtered or unexported fields
}
Phase pairs one started milestone with exactly one success or bounded semantic failure. It deliberately carries no protocol data beyond the milestone itself.
type TerminalContext ¶
type TerminalContext struct {
FunctionalOutcome testrun.Outcome `json:"functional_outcome"`
CleanupOutcome testrun.Outcome `json:"cleanup_outcome"`
PriorEvidenceOutcome testrun.Outcome `json:"prior_evidence_outcome"`
PriorDeliveryOutcome testrun.Outcome `json:"prior_delivery_outcome"`
LastMilestone testrun.Milestone `json:"last_milestone"`
}
TerminalContext separates functional and cleanup verdicts for diagnosis.
type Trace ¶
type Trace struct {
// contains filtered or unexported fields
}
Trace is the single verdict owner for a scenario. Its mutex linearizes event publication against Finish so no milestone can appear after the terminal event.
func New ¶
func New( operation testrun.Operation, component testrun.Component, sink testrun.EventSink, ) (*Trace, error)
New starts one correlated scenario and immediately publishes its started event.
func Start ¶
func Start( t lifecycleTestContext, operation testrun.Operation, component testrun.Component, sink testrun.EventSink, ) *Trace
Start installs terminal ownership before surfacing a started-event error. A sink may persist an event and then fail, so callers must never have to remember this ordering at each integration or E2E entry point.
func (*Trace) AddCleanup ¶
func (trace *Trace) AddCleanup(name string, cleanup CleanupFunc) error
AddCleanup transfers cleanup verdict ownership to the scenario.
func (*Trace) Events ¶
Events returns the authoritative bounded journal. External delivery is best effort and separately reported; lifecycle correctness is decided from this pull-only snapshot.
func (*Trace) Finish ¶
Finish retires cleanup owners in reverse order and publishes one terminal verdict.
func (*Trace) Finished ¶
Finished reports whether the terminal boundary has been published or attempted.
func (*Trace) MarkFunctionalSuccess ¶
MarkFunctionalSuccess seals the functional oracle only after every phase succeeds. A successful seal rejects all later evidence, cleanup registration, and phase settlement so Finish observes the exact state that was authoritatively verified.
func (*Trace) Record ¶
func (trace *Trace) Record( milestone testrun.Milestone, outcome testrun.Outcome, payload any, ) error
Record emits an already-decided protocol-specific point observation. Started outcomes require StartPhase so the lifecycle owner can enforce one settlement. Lifecycle and cleanup milestones remain reserved for this owner.
func (*Trace) RequireCleanup ¶
func (trace *Trace) RequireCleanup(t testContext, name string, cleanup CleanupFunc)
RequireCleanup binds AddCleanup failure to the calling test verdict.
func (*Trace) RequireRecord ¶
func (trace *Trace) RequireRecord( t testContext, milestone testrun.Milestone, outcome testrun.Outcome, payload any, )
RequireRecord binds Record failure to the calling test verdict.
func (*Trace) RequireSuccess ¶
func (trace *Trace) RequireSuccess(t testContext)
RequireSuccess seals the functional oracle, runs every cleanup owner, and makes functional, cleanup, and evidence-publication failures one test verdict.
func (*Trace) StartPhase ¶
StartPhase publishes started and returns its sole settlement authority. The phase remains registered when a sink returns an error because the write may already be externally visible; Finish will then publish a matching failure.