looptest

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package looptest provides go test helpers for replaying .loopfix fixtures against loop definitions and asserting outcomes, spend, iterations, and state.

Usage:

result := looptest.Replay(t, def, "testdata/myloop.loopfix")
result.AssertCompleted(t)
result.AssertSpendUnder(t, budget.Spend{Tokens: 1000})

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatDivergenceMessage

func FormatDivergenceMessage(seq uint64, expectedKind, actualKind string, expectedPayload, actualPayload json.RawMessage) string

formatDivergenceMessage formats a human-readable divergence failure message. This is used by golden tests to verify the divergence message format.

Types

type Option

type Option func(*replayConfig)

Option configures Replay behavior.

type Result

type Result[R any] struct {
	Outcome    outcome.Outcome[R]
	Spend      budget.Spend
	Iterations int
	Trajectory Trajectory
	// contains filtered or unexported fields
}

Result is the output of Replay. Contains the outcome, spend, iteration count, and the raw event trajectory.

func Replay

func Replay[S, R any](t *testing.T, def loop.Definition[S, R], path string, opts ...Option) Result[R]

Replay replays the fixture at path against def and returns a Result. It loads recorded model/tool responses from the fixture and plays them back against the current definition. If the transition produces different actions than what was recorded, a divergence error is reported immediately.

func (Result[R]) AssertCompleted

func (r Result[R]) AssertCompleted(t *testing.T) R

AssertCompleted asserts that the loop completed successfully and returns the result. Calls t.Fatal on failure.

func (Result[R]) AssertIterationsAtMost

func (r Result[R]) AssertIterationsAtMost(t *testing.T, n int)

AssertIterationsAtMost asserts that the loop ran at most n iterations.

func (Result[R]) AssertOutcome

func (r Result[R]) AssertOutcome(t *testing.T, want string)

AssertOutcome asserts that the loop's outcome matches the expected Kind string. Valid Kind values: "Completed", "BudgetExceeded", "Stuck", "Interrupted", "PolicyDenied", "Failed".

func (Result[R]) AssertSpendUnder

func (r Result[R]) AssertSpendUnder(t *testing.T, limit budget.Spend)

AssertSpendUnder asserts that the total spend is below the given limits. Zero values in limit mean "unlimited" (no check for that dimension).

func (Result[R]) AssertState

func (r Result[R]) AssertState(t *testing.T, pred func(json.RawMessage) bool)

AssertState asserts that a predicate holds on the final loop state. S must match the state type of the definition used in Replay.

type StateResult

type StateResult[S, R any] struct {
	Result[R]
	FinalState S
}

StateResult[S,R] is a type-safe version of Result that allows asserting on the concrete state type S via a typed predicate.

func ReplayTyped

func ReplayTyped[S, R any](t *testing.T, def loop.Definition[S, R], path string, opts ...Option) StateResult[S, R]

ReplayTyped replays a fixture and returns a StateResult with the typed final state. Use this when you need to assert on the concrete state type S.

func (StateResult[S, R]) AssertState

func (r StateResult[S, R]) AssertState(t *testing.T, pred func(S) bool)

AssertState asserts that a predicate holds on the typed final state.

type Trajectory

type Trajectory = []event.Envelope

Trajectory is the raw event log from a replay.

Jump to

Keyboard shortcuts

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