Expand description
In-memory test harness for workflow handlers.
TestEngine runs a real Engine against a real
InMemoryStore: the run, the steps,
the FSM transitions and the persistence are the production ones. Only the
outside world is swapped out – shell commands, HTTP requests, agent
invocations, approval gates and human inputs are answered from closures instead of
spawning processes, opening sockets or waiting for a human.
What it does not start: no HTTP server, no background worker, no Postgres.
A run executes inline, in the calling task, and finishes before
run returns.
§Examples
use ironflow_engine::prelude::*;
use ironflow_engine::testing::{ApprovalOutcome, MockShellOutput, TestEngine};
use ironflow_store::models::RunStatus;
use serde_json::json;
let result = TestEngine::new()
.with_handler(Deploy)
.with_mock_shell(|_cfg| Ok(MockShellOutput::ok(r#"{"version":"1.2.3"}"#)))
.with_mock_approval(ApprovalOutcome::Approved)
.run(json!({"env": "prod"}))
.await?;
assert_eq!(result.status(), RunStatus::Completed);
assert_eq!(result.step("deploy").step_output().stdout(), r#"{"version":"1.2.3"}"#);§What the harness covers
| Step | How it is mocked |
|---|---|
ctx.shell | TestEngine::with_mock_shell |
ctx.http | TestEngine::with_mock_http |
ctx.agent | TestEngine::with_mock_agent or TestEngine::with_recorded_agent |
ctx.approval | TestEngine::with_mock_approval, or TestEngine::resume |
ctx.human_input | TestEngine::with_mock_human_input, or TestEngine::resume after writing the answer on the step |
ctx.parallel, ctx.workflow, on_error | the mocks above apply to the steps inside them |
§Limitations
- Custom operations (
ctx.operation) are not intercepted. Mock one by passing a test-doubleOperationto the handler. ctx.delayis not intercepted: a non-zero delay still suspends the run withRunStatus::Sleeping.ctx.decisionneeds a realDecisionProvider, wired withTestEngine::with_decision_provider.
Re-exports§
pub use crate::executor::ApprovalOutcome;pub use crate::executor::HumanInputOutcome;
Structs§
- Missing
Agent Provider - The provider a
TestEngineuses when no agent backend was configured. - Mock
Agent Provider - An
AgentProviderbacked by a closure. - Mock
Http Response - Canned response of a mocked HTTP step.
- Mock
Interceptor - A
StepInterceptorbuilt from closures. - Mock
Shell Output - Canned result of a mocked shell step.
- Test
Engine - Runs a
WorkflowHandleragainst an in-memory store with mocked steps. - Test
Result - Outcome of a
TestEnginerun. - Test
Step - One persisted step, with assertion-friendly accessors.
Type Aliases§
- Agent
Mock - Closure answering an agent invocation from its config.
- Http
Mock - Closure answering an HTTP step from its config.
- Human
Input Mock - Closure answering a human input step from its name and config.
- Shell
Mock - Closure answering a shell step from its config.