aion/testing/mock

Typed activity and child-workflow mock registries for aion/testing.

Tests register activity mocks against an Activity(i, o) value so the handler is statically checked against the same input and output types that workflow.run will use, and child doubles against the input/output/error codecs that workflow.spawn_and_wait will use. The test-only FFI double stores a type-erased wrapper in process-scoped state and intercepts activity dispatch and child spawn by name.

Values

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

Register a typed activity mock for the current process.

A handler whose input or output type does not match the supplied activity will fail at gleam build, before the workflow test can run.

pub fn child(
  env: env,
  name: String,
  child_input_codec: codec.Codec(input),
  child_output_codec: codec.Codec(output),
  child_error_codec: codec.Codec(workflow_error),
  handler: fn(input) -> Result(output, workflow_error),
) -> Result(env, error.EngineError)

Register a typed child-workflow double for the current test process.

workflow.spawn_and_wait(name, ...) calls with the same name execute handler synchronously and record its typed result as the child terminal: Ok is decoded by the parent’s output codec and a typed Error surfaces as error.ChildWorkflowFailed. Registering the child module’s real execute function as the handler runs the full child workflow body — including its own activity dispatches against this process’s activity mocks — inside the parent test.

Search Document