ironflow_engine/config/workflow.rs
1//! Configuration for workflow (sub-workflow) steps.
2
3use serde::{Deserialize, Serialize};
4use serde_json::Value;
5
6/// Configuration for invoking a registered workflow as a sub-step.
7///
8/// The engine will look up the handler by [`workflow_name`](WorkflowStepConfig::workflow_name)
9/// and execute it as a child run with its own steps and lifecycle.
10///
11/// # Examples
12///
13/// ```
14/// use ironflow_engine::config::WorkflowStepConfig;
15/// use serde_json::json;
16///
17/// let config = WorkflowStepConfig::new("build", json!({"branch": "main"}));
18/// assert_eq!(config.workflow_name, "build");
19/// ```
20#[derive(Debug, Clone, Serialize, Deserialize)]
21pub struct WorkflowStepConfig {
22 /// Name of the registered workflow handler to invoke.
23 pub workflow_name: String,
24 /// Payload to pass to the child workflow run.
25 pub payload: Value,
26}
27
28impl WorkflowStepConfig {
29 /// Create a new workflow step config.
30 ///
31 /// # Examples
32 ///
33 /// ```
34 /// use ironflow_engine::config::WorkflowStepConfig;
35 /// use serde_json::json;
36 ///
37 /// let config = WorkflowStepConfig::new("deploy", json!({}));
38 /// assert_eq!(config.workflow_name, "deploy");
39 /// ```
40 pub fn new(workflow_name: &str, payload: Value) -> Self {
41 Self {
42 workflow_name: workflow_name.to_string(),
43 payload,
44 }
45 }
46}
47
48#[cfg(test)]
49mod tests {
50 use super::*;
51 use serde_json::json;
52
53 #[test]
54 fn new_sets_fields() {
55 let config = WorkflowStepConfig::new("build", json!({"key": "val"}));
56 assert_eq!(config.workflow_name, "build");
57 assert_eq!(config.payload["key"], "val");
58 }
59
60 #[test]
61 fn serde_roundtrip() {
62 let config = WorkflowStepConfig::new("deploy", json!({"env": "prod"}));
63 let json = serde_json::to_string(&config).unwrap();
64 let back: WorkflowStepConfig = serde_json::from_str(&json).unwrap();
65 assert_eq!(back.workflow_name, "deploy");
66 assert_eq!(back.payload["env"], "prod");
67 }
68}