Skip to content

@bendyline/molen-kernel/testing ​

Molen headless deterministic simulation kernel (no DOM, no three.js).

ts
import { /* … */ } from '@bendyline/molen-kernel/testing';

Classes ​

ReplayPlayer ​

Scrubs a deterministic replay: seek to any tick by restoring the nearest cached keyframe and re-stepping forward. Keyframes are cached at keyframeInterval so checkpoint-safe seeking is O(interval). Scripts with untracked closures seek from the beginning — see docs-src/guide/scripting.md ("State that survives save/load and replay"). Used for replay scrubbing and machinima.

Constructors ​

Constructor ​
ts
new ReplayPlayer(
   build, 
   commands, 
   opts
): ReplayPlayer;
Parameters ​
build ​

WorldBuilder

commands ​

Command[]

opts ​
keyframeInterval? ​

number

totalTicks ​

number

Returns ​

ReplayPlayer

Properties ​

length ​
ts
readonly length: number;

Methods ​

seek() ​
ts
seek(tick): World;

Return a world at the given tick (clamped to [0, length]).

Parameters ​
tick ​

number

Returns ​

World

Interfaces ​

AssertContext ​

Properties ​

events ​
ts
events: object[];

All events emitted over the run, with the tick they occurred on.

event ​
ts
event: EngineEvent;
tick ​
ts
tick: number;

AssertionResult ​

Properties ​

message ​
ts
message: string;
op ​
ts
op: string;
pass ​
ts
pass: boolean;
target ​
ts
target: string;

Echo of the assertion's selector or event for reporting.


ComponentDiff ​

Properties ​

after? ​
ts
optional after?: JsonObject;
before? ​
ts
optional before?: JsonObject;
component ​
ts
component: string;
entity ​
ts
entity: string;
kind ​
ts
kind: "added" | "removed" | "changed";

DivergenceReport ​

Properties ​

diff ​
ts
diff: ComponentDiff[];
tick ​
ts
tick: number;

HeadlessResult ​

Properties ​

events ​
ts
events: RecordedEvent[];
finalHash ​
ts
finalHash: string;
ticks ​
ts
ticks: number;
world ​
ts
world: World;

ParsedSelector ​

Properties ​

predicates ​
ts
predicates: Predicate[];
valuePath ​
ts
valuePath: (string | number)[];

Trailing value path tokens, e.g. ["health", "hp"] or ["transform", "pos", 1].


RecordedEvent ​

Properties ​

event ​
ts
event: EngineEvent;
tick ​
ts
tick: number;

ReplayResult ​

Properties ​

actualHash ​
ts
actualHash: string;
expectedHash? ​
ts
optional expectedHash?: string;
firstDivergentTick? ​
ts
optional firstDivergentTick?: number;

Set when the result is being compared against a reference run that diverged.

ok ​
ts
ok: boolean;
ticks ​
ts
ticks: number;

SelectMatch ​

Properties ​

components ​
ts
components: ComponentMap;
id ​
ts
id: string;
value? ​
ts
optional value?: JsonValue;

The resolved value at the selector's value path, if one was given.

Type Aliases ​

WorldBuilder ​

ts
type WorldBuilder = () => World;

A factory that returns a fully-configured world (entities + systems + command handlers).

Returns ​

World

Functions ​

diffKeyframes() ​

ts
function diffKeyframes(a, b): ComponentDiff[];

Component-level diff between two keyframes (a = before, b = after).

Parameters ​

a ​

Keyframe

b ​

Keyframe

Returns ​

ComponentDiff[]


firstDivergentTick() ​

ts
function firstDivergentTick(
   buildA, 
   buildB, 
   ticks, 
   commandsA?, 
   commandsB?
): DivergenceReport | null;

Step two worlds in lockstep and report the first tick at which their state hashes diverge, with a component-level diff at that tick. Returns null if they agree for all ticks. Used both for determinism tests (same builder twice) and to localize replay divergence.

Parameters ​

buildA ​

WorldBuilder

buildB ​

WorldBuilder

ticks ​

number

commandsA? ​

Command[]

commandsB? ​

Command[]

Returns ​

DivergenceReport | null


formatAssertionResults() ​

ts
function formatAssertionResults(results): string;

Format assertion results as an agent-facing block.

Parameters ​

results ​

AssertionResult[]

Returns ​

string


parseSelector() ​

ts
function parseSelector(selector): ParsedSelector;

Parameters ​

selector ​

string

Returns ​

ParsedSelector


perTickHashes() ​

ts
function perTickHashes(
   build, 
   commands, 
   ticks
): string[];

Per-tick state hashes for ticks steps (index i = hash after tick i).

Parameters ​

build ​

WorldBuilder

commands ​

Command[]

ticks ​

number

Returns ​

string[]


runAssertions() ​

ts
function runAssertions(
   world, 
   doc, 
   ctx?
): AssertionResult[];

Evaluate an assertion document against the final world state and recorded events.

Parameters ​

world ​

World

doc ​

AssertionDoc

ctx? ​

AssertContext

Returns ​

AssertionResult[]


runHeadless() ​

ts
function runHeadless(build, opts): HeadlessResult;

Run a built world for ticks, submitting recorded commands and capturing every emitted event with the tick it occurred on. The backbone of molen sim run and the MCP run_simulation tool.

Parameters ​

build ​

WorldBuilder

opts ​
commands? ​

Command[]

onTick? ​

(world) => void

ticks ​

number

Returns ​

HeadlessResult


runReplay() ​

ts
function runReplay(
   build, 
   commands, 
   ticks, 
   expectedHash?
): ReplayResult;

Submit a recorded command stream and run ticks. Commands are queued at their recorded tickExecuted, so replay is faithful regardless of original late-command rewriting.

Parameters ​

build ​

WorldBuilder

commands ​

Command[]

ticks ​

number

expectedHash? ​

string

Returns ​

ReplayResult


select() ​

ts
function select(world, selector): SelectMatch[];

Evaluate a selector against the world; returns matching entities (+ resolved value path).

Parameters ​

world ​

World

selector ​

string

Returns ​

SelectMatch[]

References ​

buildWorld ​

Re-exports buildWorld


createWorldFromScene ​

Re-exports createWorldFromScene


resolveEntityComponents ​

Re-exports resolveEntityComponents


resolvePrefab ​

Re-exports resolvePrefab


stateHash ​

Re-exports stateHash


World ​

Re-exports World


WorldSetup ​

Re-exports WorldSetup

37 guides · 36 schema formats · 41 API entry points · 10 samples. API, CLI and schema pages are generated from the shipped build.