aion/testing

Pure Gleam workflow test harness.

aion/testing is the recommended way to test workflow author code. It runs under gleam test with no engine, beamr, store, external services, or Rust NIFs. Test code initialises a process-scoped TestEnv; the test-only Erlang module test/aion_flow_ffi.erl occupies the same production FFI namespace so workflow code and @external declarations are byte-identical in tests and production.

Types

Process-scoped test environment handle.

The runtime state is held by the test FFI double under the current Erlang process. The handle keeps test APIs explicit and prevents unrelated tests from sharing state when gleeunit runs them concurrently in separate processes.

pub opaque type TestEnv

Values

pub fn advance(
  env: TestEnv,
  by: duration.Duration,
) -> Result(TestEnv, error.EngineError)

Advance the simulated test clock by a canonical duration.

pub fn assert_replay(
  env: TestEnv,
  workflow: fn() -> Result(value, workflow_error),
) -> Result(value, replay.ReplayError(workflow_error))

Assert that a workflow emits the same observation sequence on a second run.

This mirrors AD’s production non-determinism detection in a lightweight test harness: if replay emits different observable commands, the helper returns a clear ReplayError diagnostic instead of requiring a live engine.

pub fn clear_observations(
  env: TestEnv,
) -> Result(TestEnv, error.EngineError)

Clear the observation sequence for the current process.

pub fn current_time_milliseconds(
  env: TestEnv,
) -> Result(Int, error.EngineError)

Return the current simulated clock value in milliseconds.

pub fn mock_activity(
  env: TestEnv,
  activity_value: activity.Activity(input, output),
  handler: fn(input) -> Result(output, error.ActivityError),
) -> Result(TestEnv, error.EngineError)

Register a typed activity mock for the current test process.

pub fn new() -> Result(TestEnv, error.EngineError)

Build a fresh TestEnv for the current test process.

The simulated clock, activity mock registry, child/query/signal fixtures, and observation capture are reset for the current process only.

pub fn observations(
  env: TestEnv,
) -> Result(String, error.EngineError)

Capture the current observation sequence emitted by the test FFI double.

pub fn process_key(env: TestEnv) -> String

Return the process key assigned by the test FFI double.

pub fn run(
  workflow: fn(TestEnv) -> value,
) -> Result(value, error.EngineError)

Run a workflow thunk under a fresh process-scoped test environment.

Search Document