Documentation
¶
Overview ¶
Package testrun carries correlation identity across test runners and their child processes. It is intentionally independent of any process or network fixture so those owners can evolve without changing the trace contract.
Index ¶
- Constants
- Variables
- func IsDeliveryFailure(err error) bool
- func ValidateEvent(event Event) error
- func ValidateIdentity(identity Identity) error
- func ValidateMilestone(milestone Milestone) error
- type Component
- type EnvironmentLookup
- type Event
- type EventSink
- type Identity
- type JSONLineSink
- type ListenerReadyContext
- type Milestone
- type Operation
- type Outcome
- type PreparedEvent
- type Recorder
- func (recorder *Recorder) Events() []Event
- func (recorder *Recorder) PrepareEvent(milestone Milestone, outcome Outcome, payload any) (PreparedEvent, error)
- func (recorder *Recorder) Record(milestone Milestone, outcome Outcome, payload any) error
- func (recorder *Recorder) RecordEncoded(milestone Milestone, outcome Outcome, payload json.RawMessage) error
- func (recorder *Recorder) RecordPrepared(prepared PreparedEvent) error
- type Run
Constants ¶
const ( EventSchemaVersion = "windshare.test-event/v1" MaximumEventDocumentBytes = 1 << 20 MaximumRecordedEvents = 1024 // Sink and writer calls cross caller-controlled boundaries. Separate limits // let the outer recorder retire a wedged sink after an inner adapter has had // enough time to report its own bounded delivery failure. EventSinkCallTimeout = 2 * time.Second EventAdapterCallTimeout = time.Second EventWriterCallTimeout = time.Second EventPayloadCallTimeout = time.Second ListenerReadyMilestone = "listener_ready" )
const ( RunIDEnvironment = "WINDSHARE_TEST_RUN_ID" OperationIDEnvironment = "WINDSHARE_TEST_OPERATION_ID" ScenarioEnvironment = "WINDSHARE_TEST_SCENARIO" )
Variables ¶
var ( ErrEventDeliveryTimeout = errors.New("test event delivery timed out") ErrEventDeliveryPanic = errors.New("test event delivery panicked") ErrEventJournalFull = errors.New("test event journal is full") ErrEventPayloadTimeout = errors.New("test event payload encoding timed out") ErrEventPayloadPanic = errors.New("test event payload encoding panicked") )
Functions ¶
func IsDeliveryFailure ¶
IsDeliveryFailure distinguishes external adapter health from preparation or authoritative-journal failures without evaluating caller error methods.
func ValidateEvent ¶
func ValidateIdentity ¶
ValidateIdentity applies the same portable correlation contract used when an Operation is constructed. Protocol boundaries use this projection so event validation cannot silently accept identities that child propagation rejects.
func ValidateMilestone ¶
ValidateMilestone lets higher-level lifecycle owners commit semantic state before publication without duplicating the recorder's portable wire rules.
Types ¶
type Component ¶
type Component string
Component and Milestone prevent recorder call sites from swapping two otherwise indistinguishable strings in the six-field trace contract.
type EnvironmentLookup ¶
EnvironmentLookup matches os.LookupEnv while keeping environment resolution deterministic in tests and embedders.
type Event ¶
type Event struct {
SchemaVersion string `json:"schema_version"`
Identity
Component string `json:"component"`
Milestone string `json:"milestone"`
Outcome string `json:"outcome"`
Payload json.RawMessage `json:"payload,omitempty"`
}
Event is the canonical structured record shared by in-process scenarios and owned child processes. Payload is optional semantic JSON context, never a replacement for one of the six stable correlation and decision fields. Its object order and numeric spelling are deliberately not a cross-runtime byte contract.
type EventSink ¶
EventSink is defined at the recorder's consumption boundary so transports can be injected without making testrun depend on a process or network fixture.
func EventSinkFunc ¶
EventSinkFunc adapts a callback behind a persistent delivery boundary. The function spelling preserves concise injection call sites while preventing repeated direct calls from accumulating one wedged goroutine per attempt.
type Identity ¶
type Identity struct {
RunID string `json:"run_id"`
OperationID string `json:"operation_id"`
Scenario string `json:"scenario"`
}
Identity is the transport-neutral projection of an Operation. Process ownership may carry the same identity, but it does not own its semantics.
type JSONLineSink ¶
type JSONLineSink struct {
// contains filtered or unexported fields
}
JSONLineSink writes one complete canonical event per line. Sharing one sink per destination makes concurrent recorders atomic without relying on stderr prose or testing.T logging prefixes.
func NewJSONLineSink ¶
func NewJSONLineSink(writer io.Writer) (*JSONLineSink, error)
func (*JSONLineSink) WriteEvent ¶
func (sink *JSONLineSink) WriteEvent(event Event) error
type ListenerReadyContext ¶
type ListenerReadyContext struct {
Address string `json:"address"`
}
ListenerReadyContext is shared by process fixtures and listener-owning children so the published address remains a typed protocol field.
type Operation ¶
type Operation struct {
// contains filtered or unexported fields
}
Operation identifies one scenario within a run. Its fields are immutable so correlation cannot drift after child environments or events are created.
func NewOperation ¶
NewOperation validates a correlation tuple read from a trusted protocol boundary such as a child environment or a test fixture.
func OperationFromEnvironment ¶
func OperationFromEnvironment(lookup EnvironmentLookup) (Operation, bool, error)
OperationFromEnvironment reads an all-or-nothing child correlation tuple. A partially propagated tuple is an orchestration failure, not an invitation to invent a second identity inside the child.
func (Operation) ChildEnvironment ¶
ChildEnvironment returns a copy with one authoritative value for each correlation variable. Case-insensitive replacement prevents Windows from retaining a second spelling that a cross-platform child might interpret.
func (Operation) EventIdentity ¶
EventIdentity projects correlation without exposing mutable operation state.
type Outcome ¶
type Outcome string
Outcome is deliberately closed so trace consumers never have to infer success semantics from free-form log prose.
type PreparedEvent ¶
type PreparedEvent struct {
// contains filtered or unexported fields
}
PreparedEvent is a fully validated immutable event that cannot be forged outside this package. Separating preparation lets lifecycle owners mutate phase state only after caller marshal hooks have completed safely.
type Recorder ¶
type Recorder struct {
// contains filtered or unexported fields
}
Recorder binds immutable operation identity and component context once. This prevents protocol operation IDs from being substituted into observability envelopes at individual call sites.
func NewRecorder ¶
func (*Recorder) Events ¶
Events returns the recorder-owned authoritative journal. Delivery adapters may fail or time out, but a consumer can always pull the bounded event history without invoking external code from a lifecycle-critical path.
func (*Recorder) PrepareEvent ¶
func (recorder *Recorder) PrepareEvent( milestone Milestone, outcome Outcome, payload any, ) (PreparedEvent, error)
PrepareEvent invokes the recorder's persistent caller-payload boundary. Once a payload hook fails, panics, or times out, later preparations fail immediately without creating another caller goroutine.
func (*Recorder) RecordEncoded ¶
func (recorder *Recorder) RecordEncoded( milestone Milestone, outcome Outcome, payload json.RawMessage, ) error
RecordEncoded publishes already-encoded semantic JSON without invoking a caller marshaler. Lifecycle frameworks use this path for their closed payload model so a retired caller-payload boundary cannot suppress cleanup or terminal evidence.
func (*Recorder) RecordPrepared ¶
func (recorder *Recorder) RecordPrepared(prepared PreparedEvent) error
RecordPrepared commits an event only after every caller-controlled preparation hook and deterministic validation step has completed.
type Run ¶
type Run struct {
// contains filtered or unexported fields
}
Run identifies one package-suite invocation, including every child scenario launched by that invocation.
func PackageRun ¶
PackageRun resolves the runner-provided identity once. Direct go test invocations receive a process-local fallback, while malformed explicit input fails closed instead of producing uncorrelatable logs.