Skip to main content

Module testing

Module testing 

Source
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

StepHow it is mocked
ctx.shellTestEngine::with_mock_shell
ctx.httpTestEngine::with_mock_http
ctx.agentTestEngine::with_mock_agent or TestEngine::with_recorded_agent
ctx.approvalTestEngine::with_mock_approval, or TestEngine::resume
ctx.human_inputTestEngine::with_mock_human_input, or TestEngine::resume after writing the answer on the step
ctx.parallel, ctx.workflow, on_errorthe mocks above apply to the steps inside them

§Limitations

Re-exports§

pub use crate::executor::ApprovalOutcome;
pub use crate::executor::HumanInputOutcome;

Structs§

MissingAgentProvider
The provider a TestEngine uses when no agent backend was configured.
MockAgentProvider
An AgentProvider backed by a closure.
MockHttpResponse
Canned response of a mocked HTTP step.
MockInterceptor
A StepInterceptor built from closures.
MockShellOutput
Canned result of a mocked shell step.
TestEngine
Runs a WorkflowHandler against an in-memory store with mocked steps.
TestResult
Outcome of a TestEngine run.
TestStep
One persisted step, with assertion-friendly accessors.

Type Aliases§

AgentMock
Closure answering an agent invocation from its config.
HttpMock
Closure answering an HTTP step from its config.
HumanInputMock
Closure answering a human input step from its name and config.
ShellMock
Closure answering a shell step from its config.