testscenario

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: AGPL-3.0 Imports: 8 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 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

View Source
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
)
View Source
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

View Source
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")
)
View Source
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

type CleanupFunc func(context.Context) error

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.

func (*Phase) Fail

func (phase *Phase) Fail(reason string) error

Fail publishes the phase's only failed settlement with a bounded reason.

func (*Phase) Succeed

func (phase *Phase) Succeed(payload any) error

Succeed publishes the phase's only successful settlement.

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

func (trace *Trace) Events() []testrun.Event

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

func (trace *Trace) Finish() error

Finish retires cleanup owners in reverse order and publishes one terminal verdict.

func (*Trace) Finished

func (trace *Trace) Finished() bool

Finished reports whether the terminal boundary has been published or attempted.

func (*Trace) MarkFunctionalSuccess

func (trace *Trace) MarkFunctionalSuccess() error

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

func (trace *Trace) StartPhase(milestone testrun.Milestone, payload any) (*Phase, error)

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.

Jump to

Keyboard shortcuts

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