import { b as Cmd, c as Sub, M as Machine, B as BuiltinSub } from '../core-sEWVgnpI.js'; import { R as Runtime } from '../runtime-types-f231H8Gq.js'; import '@standard-schema/spec'; /** * Shared options shape for every test assertion below. Mirrors the * second argument of `replay(machine, opts)` — `msgs` is the sequence to * fold over (may be empty for init-only assertions), `ctx` is the * substrate-required ctx value, `loaded` is the optional pre-`init` * snapshot (omit / pass `null` for fresh boot). */ interface ReplayOpts { readonly msgs: readonly M[]; readonly ctx: Ctx; readonly loaded?: S | null; } /** * Assert the final state after replaying `opts.msgs` equals `expected`. * Replaces the boilerplate: * * const { state } = replay(machine, opts); * expect(state).toEqual(expected); * * Uses `toEqual` (deep structural). For type-narrowing assertions that * branch on `state._tag` afterwards, fall back to plain `replay` — * `expectFinalState` is the "exact match" tool. */ declare function expectFinalState(machine: Machine, opts: NoInfer>, expected: NoInfer): void; /** * Assert that `cmd` appears at least once in the cmds array produced by * replaying `opts.msgs`. Uses `toContainEqual` (deep structural). Order * and surrounding cmds are not asserted — use `expectCmdSequence` for * exact ordered match. * * Replaces: * * const { cmds } = replay(machine, opts); * expect(cmds).toContainEqual(cmd); */ declare function expectCmdEmitted(machine: Machine, opts: NoInfer>, cmd: NoInfer): void; /** * Assert the exact ordered sequence of cmds emitted by replaying * `opts.msgs`. Uses `toEqual` against the full cmds array — extra cmds * fail the assertion, missing cmds fail the assertion, wrong order * fails the assertion. * * Replaces: * * const { cmds } = replay(machine, opts); * expect(cmds).toEqual(expected); */ declare function expectCmdSequence(machine: Machine, opts: NoInfer>, expected: NoInfer): void; /** * Assert the exact set of subs desired at the final state after * replaying `opts.msgs`. Uses `toEqual` against the full subs array. * * Replaces: * * const { subs } = replay(machine, opts); * expect(subs).toEqual(expected); */ declare function expectActiveSubs(machine: Machine, opts: NoInfer>, expected: NoInfer): void; /** * Single-msg step helper — feeds `loaded → msg → next state + cmds emitted by * that msg`. Returns a readonly tuple in the shape consumers used before the * substrate (`[state, cmds]`), so existing tests that destructure with * `[next, cmds]` can swap `reduce(state, msg)` for `step(machine, state, msg, * ctx)` without changing the assertion code. * * Calls the update cell directly, without init or subscription derivation. * The returned Cmds belong only to this message. * * Use when consumers want to walk a machine one msg at a time and assert per * step. For one-shot "final state after N msgs" assertions, prefer * `expectFinalState`. */ declare function step(machine: Machine, loaded: NoInfer, msg: NoInfer, _ctx: NoInfer): readonly [S, readonly C[]]; /** * Replay options shape used by every bound method. `ctx` is captured by * `bindMachine`; the per-call opts only need `msgs` and an optional * `loaded` snapshot. (Compare `ReplayOpts` in `./assertions.ts`, which * still takes `ctx` because the free helpers cannot capture it.) */ interface BoundOpts { readonly msgs: readonly M[]; readonly loaded?: S | null; } /** * The bound testing surface. Every method is 2-arg max — `ctx` and * `machine` are captured by `bindMachine`. * * `NoInfer<...>` on `expected` / `cmd` arguments mirrors the discipline * the free helpers use (see `./assertions.ts`): inference flows purely * FROM the machine, so a `[]`-shaped expected does not drag `C` down to * `never` and reject the machine. */ interface BoundMachine { /** * Single-msg step — feeds `loaded → msg → [next state, cmds emitted by * that msg]`. Mirrors the free `step(machine, loaded, msg, ctx)`. */ step(loaded: S, msg: M): readonly [S, readonly C[]]; /** * Assert the final state after replaying `opts.msgs` deep-equals * `expected`. Mirrors the free `expectFinalState(machine, opts, expected)`. */ expectFinalState(opts: BoundOpts, expected: NoInfer): void; /** * Assert `cmd` appears at least once in the emitted cmd list. Order is * not asserted. Mirrors the free `expectCmdEmitted(machine, opts, cmd)`. */ expectCmdEmitted(opts: BoundOpts, cmd: NoInfer): void; /** * Assert the exact ordered sequence of cmds emitted by replaying * `opts.msgs`. Mirrors the free `expectCmdSequence(machine, opts, expected)`. */ expectCmdSequence(opts: BoundOpts, expected: readonly NoInfer[]): void; /** * Assert the exact set of subs desired at the final state. Mirrors the * free `expectActiveSubs(machine, opts, expected)`. */ expectActiveSubs(opts: BoundOpts, expected: readonly NoInfer>[]): void; /** * Bound `replay` — returns `{ state, cmds, subs }` for the given opts. * Use for the "narrow-then-assert" pattern where the test inspects a * specific field after `state._tag === "..."` discrimination. */ replay(opts: BoundOpts): { state: S; cmds: readonly C[]; subs: readonly (U | BuiltinSub)[]; }; } /** * Bind a machine + ctx into a small bag of 2-arg helpers. Each method * delegates to `step` or `replay(machine, { ...opts, ctx })` and pipes the result * through a single `expect(...)` matcher (or returns the raw tuple, for * `step` and `replay`). * * Use one bind per `describe` block (or per file) when many assertions * share the same machine + ctx. For one-off cross-machine calls, stick * with the free helpers from `./assertions.ts`. */ declare function bindMachine(machine: Machine, ctx: Ctx): BoundMachine; /** * Assert that replaying `opts.msgs` is a pure function of the Msg log: the * final state and every emitted Cmd come out the same under two different * global wall-clocks and RNG seeds. * * `init` and `update` never receive a clock, so a cell that reads * `Date.now()` or `Math.random()` reaches for the global one, and a replay of * the same log on another day or another host lands somewhere else. Two * back-to-back replays under one clock would hide that; this helper stubs * two distinct ambients and compares. Time belongs in the Msg (an `at` * field), where it is identical across replays. * * Subs are not compared: they are derived from the final state, so a state * that matches yields the same Subs. */ declare function expectReplayDeterministic(machine: Machine, opts: NoInfer>): void; /** * Construct an inert `Runtime` value. Use at ctx sites that require * a Runtime reference but where the test never invokes `interpret` (so * the runtime is never dereferenced in practice). * * @param opts.initialState Optional value returned by `getState()`. Omit * when the test never calls `getState()` on the no-op runtime — most * tests only need the type-level slot filled. */ declare function noopRuntime(opts?: { initialState?: S; }): Runtime; /** A factory-constructed phase: `S` narrowed to the arm whose discriminator equals `K`. */ type StateOf = Extract; /** A factory-constructed phase with the `_tag` discriminator removed — the "fields the caller cares about" half. */ type RequiredFields = Omit; /** * Defaults shape passed to `stateFactory`. Mapped type over the discriminant * set: every phase MUST have an entry, and that entry MUST match the phase's * required fields minus the `_tag` discriminator. */ type StateFactoryDefaults = { readonly [K in S["_tag"]]: RequiredFields>; }; /** * The API returned by `stateFactory`. One method per phase; calling it with * no args returns the default snapshot, calling it with a partial overrides * object merges those overrides in (with undefineds stripped — see * stripUndefined below). */ type StateFactoryAPI = { readonly [K in S["_tag"]]: (overrides?: Partial>>) => StateOf; }; /** * Build a typed phase-constructor API from per-phase defaults. The defaults * object MUST have one entry per `S["_tag"]` discriminant; the returned API * has one method per phase. Each method merges the defaults with optional * overrides (undefineds stripped), then stamps the `_tag` discriminator. * * @example * ```ts * import { stateFactory } from "@demlik/tea/testing"; * * type S = { _tag: "a"; n: number } | { _tag: "b"; s: string }; * const f = stateFactory({ a: { n: 0 }, b: { s: "" } }); * f.a(); // { _tag: "a", n: 0 } * f.a({ n: 42 }); // { _tag: "a", n: 42 } * f.b({ s: "hi" }); // { _tag: "b", s: "hi" } * ``` */ declare function stateFactory(defaults: StateFactoryDefaults): StateFactoryAPI; export { type BoundMachine, type ReplayOpts, type StateFactoryAPI, type StateFactoryDefaults, bindMachine, expectActiveSubs, expectCmdEmitted, expectCmdSequence, expectFinalState, expectReplayDeterministic, noopRuntime, stateFactory, step };