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 ¶
- func FormatDivergenceMessage(seq uint64, expectedKind, actualKind string, ...) string
- type Option
- type Result
- func (r Result[R]) AssertCompleted(t *testing.T) R
- func (r Result[R]) AssertIterationsAtMost(t *testing.T, n int)
- func (r Result[R]) AssertOutcome(t *testing.T, want string)
- func (r Result[R]) AssertSpendUnder(t *testing.T, limit budget.Spend)
- func (r Result[R]) AssertState(t *testing.T, pred func(json.RawMessage) bool)
- type StateResult
- type Trajectory
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 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 ¶
AssertCompleted asserts that the loop completed successfully and returns the result. Calls t.Fatal on failure.
func (Result[R]) AssertIterationsAtMost ¶
AssertIterationsAtMost asserts that the loop ran at most n iterations.
func (Result[R]) AssertOutcome ¶
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 ¶
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 ¶
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 ¶
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.