Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

test(flows): cover workflow builder edge cases

M3gA-Mind19114e14fd03
diff --git a/crates/openhuman-core/src/agent/orchestration/tools/spawn_subagent_proposal_tests.rs b/crates/openhuman-core/src/agent/orchestration/tools/spawn_subagent_proposal_tests.rs
new file mode 100644
index 0000000000..4a62dfa1f5
--- /dev/null
+++ b/crates/openhuman-core/src/agent/orchestration/tools/spawn_subagent_proposal_tests.rs
@@ -0,0 +1,127 @@
+use super::*;
+use crate::flows::builder_tools::tests_support::{edit_workflow_tool, propose_workflow_tool};
+use serde_json::Value;
+use std::sync::Arc;
+use tinytools::Tool;
+
+/// Four steps whose configs differ only by value, so a config landing on a
+/// neighbouring node (an index shift anywhere between the tool and the stored
+/// proposal) is visible.
+fn four_step_graph() -> Value {
+ json!({
+ "nodes": [
+ { "id": "t", "kind": "trigger", "name": "Manual" },
+ { "id": "fetch", "kind": "agent", "name": "Fetch", "config": { "prompt": "fetch step" } },
+ { "id": "rank", "kind": "agent", "name": "Rank", "config": { "prompt": "rank step" } },
+ { "id": "report", "kind": "agent", "name": "Report", "config": { "prompt": "report step" } }
+ ],
+ "edges": [
+ { "from_node": "t", "to_node": "fetch" },
+ { "from_node": "fetch", "to_node": "rank" },
+ { "from_node": "rank", "to_node": "report" }
+ ]
+ })
+}
+
+fn test_config(workspace: &std::path::Path) -> Arc<crate::config::Config> {
+ let config = crate::config::Config {
+ workspace_dir: workspace.join("workspace"),
+ action_dir: workspace.join("workspace"),
+ config_path: workspace.join("config.toml"),
+ ..crate::config::Config::default()
+ };
+ std::fs::create_dir_all(&config.workspace_dir).unwrap();
+ Arc::new(config)
+}
+
+/// Persist `tool_output` as the child's last tool result and return the
+/// proposal the parent thread stored for it.
+fn persisted_proposal(workspace: &std::path::Path, task_id: &str, tool_output: String) -> Value {
+ use crate::threads::store::CreateConversationThread;
+ let ctx = DispatchCtx::ambient();
+ conversations::ensure_thread(
+ &ctx,
+ workspace.to_path_buf(),
+ CreateConversationThread {
+ id: "thread-parent".into(),
+ title: "Main chat".into(),
+ created_at: chrono::Utc::now().to_rfc3339(),
+ parent_thread_id: None,
+ labels: None,
+ personality_id: None,
+ working_dir: None,
+ },
+ )
+ .expect("thread created");
+ attach_workflow_proposal(
+ &ctx,
+ workspace,
+ Some("thread-parent"),
+ task_id,
+ "workflow_builder",
+ &[TranscriptMessage::tool(&tool_output)],
+ "proposal ready".to_string(),
+ );
+ conversations::get_messages(&ctx, workspace.to_path_buf(), "thread-parent")
+ .expect("messages")
+ .into_iter()
+ .find(|message| message.id == format!("workflow-proposal:{task_id}"))
+ .expect("proposal message persisted")
+ .extra_metadata["proposal"]
+ .clone()
+}
+
+fn assert_prompts(proposal: &Value, expected: &[(&str, &str)]) {
+ let nodes = proposal["graph"]["nodes"].as_array().expect("proposal nodes");
+ assert_eq!(nodes.len(), 4, "{proposal}");
+ for (id, prompt) in expected {
+ let node = nodes
+ .iter()
+ .find(|node| node["id"] == *id)
+ .unwrap_or_else(|| panic!("node `{id}` missing from {proposal}"));
+ assert_eq!(
+ node["config"]["prompt"], *prompt,
+ "node `{id}` carries another step's config: {proposal}"
+ );
+ }
+}
+
+#[tokio::test]
+async fn proposed_and_edited_steps_keep_their_own_config_in_the_stored_proposal() {
+ let _module = crate::integrations::composio::module_client::module_guard().await;
+ let temp = tempfile::tempdir().expect("tempdir");
+ let config = test_config(temp.path());
+
+ let proposed = propose_workflow_tool(config.clone())
+ .execute(json!({ "name": "Four steps", "graph": four_step_graph() }))
+ .await
+ .unwrap();
+ assert!(!proposed.is_error, "{}", proposed.output());
+ let stored = persisted_proposal(temp.path(), "propose-1", proposed.output());
+ assert_prompts(
+ &stored,
+ &[
+ ("fetch", "fetch step"),
+ ("rank", "rank step"),
+ ("report", "report step"),
+ ],
+ );
+
+ let edited = edit_workflow_tool(config)
+ .execute(json!({
+ "graph": stored["graph"],
+ "ops": [ { "op": "update_node_config", "id": "rank", "config": { "prompt": "rank edited" } } ]
+ }))
+ .await
+ .unwrap();
+ assert!(!edited.is_error, "{}", edited.output());
+ let stored = persisted_proposal(temp.path(), "edit-1", edited.output());
+ assert_prompts(
+ &stored,
+ &[
+ ("fetch", "fetch step"),
+ ("rank", "rank edited"),
+ ("report", "report step"),
+ ],
+ );
+}
diff --git a/crates/openhuman-core/src/agent/orchestration/tools/spawn_subagent_surface.rs b/crates/openhuman-core/src/agent/orchestration/tools/spawn_subagent_surface.rs
index 105dfdc043..7e94aaaa12 100644
--- a/crates/openhuman-core/src/agent/orchestration/tools/spawn_subagent_surface.rs
+++ b/crates/openhuman-core/src/agent/orchestration/tools/spawn_subagent_surface.rs
@@ -576,3 +576,7 @@ mod tests;
#[cfg(test)]
#[path = "spawn_subagent_tests.rs"]
mod surface_tests;
+
+#[cfg(all(test, feature = "flows"))]
+#[path = "spawn_subagent_proposal_tests.rs"]
+mod proposal_tests;
diff --git a/crates/openhuman-core/src/agent_registry/agents/orchestrator/prompt_tests_session_routing_tests.rs b/crates/openhuman-core/src/agent_registry/agents/orchestrator/prompt_tests_session_routing_tests.rs
index 3eef1fc395..f02f9a1191 100644
--- a/crates/openhuman-core/src/agent_registry/agents/orchestrator/prompt_tests_session_routing_tests.rs
+++ b/crates/openhuman-core/src/agent_registry/agents/orchestrator/prompt_tests_session_routing_tests.rs
@@ -217,3 +217,19 @@ fn the_composio_connect_row_is_dropped_when_composio_is_off() {
assert!(!off.contains("composio_connect"), "{off}");
assert!(off.contains("keep") && off.contains("tail"));
}
+
+/// The rendered prompt (not just the source file) keeps the async-wait rule
+/// and the proposal turn boundary: a model told neither sleeps or re-spawns
+/// to wait for a sub-agent, or keeps building after delivering a proposal.
+#[test]
+fn rendered_prompt_keeps_the_no_wait_rule_and_the_proposal_turn_boundary() {
+ let body = build(&ctx_with(&[])).unwrap();
+ assert!(
+ body.contains("never sleep, poll or re-spawn to wait for it"),
+ "the rendered orchestrator prompt lost the no-sleep/no-poll/no-respawn rule"
+ );
+ assert!(
+ body.contains("A delivered workflow proposal ends that turn"),
+ "the rendered orchestrator prompt lost the proposal turn boundary"
+ );
+}
diff --git a/crates/openhuman-core/src/flows/builder_tools_draft_id_tests.rs b/crates/openhuman-core/src/flows/builder_tools_draft_id_tests.rs
index be6138be45..23f4f622bf 100644
--- a/crates/openhuman-core/src/flows/builder_tools_draft_id_tests.rs
+++ b/crates/openhuman-core/src/flows/builder_tools_draft_id_tests.rs
@@ -170,6 +170,69 @@ async fn validate_workflow_by_draft_id_checks_the_draft_graph() {
assert_eq!(parsed["structurally_valid"], true);
}
+/// A draft whose graph differs from every other handle in the call: a dangling
+/// edge makes it structurally invalid, so a tool that reads the draft reports
+/// the invalid graph while one that reads the flow or inline graph passes.
+fn invalid_draft(config: &Arc<Config>, flow_id: Option<String>) -> String {
+ ops::flows_draft_create(
+ config,
+ flow_id,
+ "Broken draft".to_string(),
+ json!({
+ "nodes": [ { "id": "t", "kind": "trigger", "name": "Manual" } ],
+ "edges": [ { "from_node": "t", "to_node": "ghost" } ]
+ }),
+ tinyflows_bus::catalog::DraftOrigin::Chat,
+ )
+ .unwrap()
+ .value
+ .id
+}
+
+#[tokio::test]
+async fn dry_run_workflow_by_draft_id_runs_the_draft_not_the_saved_flow() {
+ let tmp = TempDir::new().unwrap();
+ let config = test_config(&tmp);
+ let flow = ops::flows_create(&config, "Runnable".to_string(), valid_graph(), false)
+ .await
+ .unwrap()
+ .value;
+ let draft_id = invalid_draft(&config, Some(flow.id.clone()));
+
+ let tool = dry_run_workflow_tool(config.clone());
+ let result = tool
+ .execute(json!({ "draft_id": draft_id, "flow_id": flow.id }))
+ .await
+ .unwrap();
+ // The saved flow dry-runs `ok` (see the flow_id test above); only the
+ // draft's dangling edge can produce this rejection.
+ assert!(result.is_error, "{}", result.output());
+ assert!(
+ result.output().contains("Cannot dry-run an invalid graph"),
+ "{}",
+ result.output()
+ );
+}
+
+#[tokio::test]
+async fn validate_workflow_prefers_draft_id_over_an_inline_graph() {
+ let _module = crate::integrations::composio::module_client::module_guard().await;
+ let tmp = TempDir::new().unwrap();
+ let config = test_config(&tmp);
+ let draft_id = invalid_draft(&config, None);
+
+ let tool = validate_workflow_tool(config.clone());
+ let result = tool
+ .execute(json!({ "draft_id": draft_id, "graph": valid_graph() }))
+ .await
+ .unwrap();
+ assert!(!result.is_error, "{}", result.output());
+ let parsed: Value = serde_json::from_str(&result.output()).unwrap();
+ // The inline graph is valid; `ok: false` means the draft was checked.
+ assert_eq!(parsed["ok"], false, "{parsed}");
+ assert_eq!(parsed["structurally_valid"], false, "{parsed}");
+}
+
#[tokio::test]
async fn save_workflow_by_draft_id_persists_the_draft_graph_onto_the_flow() {
let tmp = TempDir::new().unwrap();
diff --git a/crates/openhuman-core/src/flows/builder_tools_support.rs b/crates/openhuman-core/src/flows/builder_tools_support.rs
index fe62faf96f..6aeaf37ed6 100644
--- a/crates/openhuman-core/src/flows/builder_tools_support.rs
+++ b/crates/openhuman-core/src/flows/builder_tools_support.rs
@@ -9,6 +9,10 @@ fn tool(config: Arc<Config>, name: &str) -> BusCopilotTool {
BusCopilotTool::from_name(config, name)
}
+pub(crate) fn propose_workflow_tool(config: Arc<Config>) -> BusCopilotTool {
+ tool(config, "propose_workflow")
+}
+
pub(crate) fn edit_workflow_tool(config: Arc<Config>) -> BusCopilotTool {
tool(config, "edit_workflow")
}
diff --git a/crates/openhuman-core/src/security/approval/gate_core_flow_tests.rs b/crates/openhuman-core/src/security/approval/gate_core_flow_tests.rs
index c81653e776..8d84101952 100644
--- a/crates/openhuman-core/src/security/approval/gate_core_flow_tests.rs
+++ b/crates/openhuman-core/src/security/approval/gate_core_flow_tests.rs
@@ -216,6 +216,89 @@ async fn auto_approve_tool_skips_prompt() {
);
}
+/// "Always allow" on a parked `create_workflow` round-trips: the decided row is
+/// persisted to `autonomy.auto_approve` (what `approval::rpc::approval_decide`
+/// does for `ApproveAlwaysForTool`; the RPC itself reads the process-wide gate,
+/// which tests must not install), and the next `create_workflow` is allowed
+/// without a second prompt.
+#[tokio::test]
+async fn approve_always_for_create_workflow_persists_and_skips_the_next_prompt() {
+ let (gate, dir) = test_gate();
+ let gate = Arc::new(gate);
+ let _env = EnvVarGuard::workspace_async(dir.path()).await;
+ crate::security::live_policy::install(
+ Arc::new(crate::security::SecurityPolicy::default()),
+ dir.path().to_path_buf(),
+ dir.path().to_path_buf(),
+ );
+
+ let intercept = |gate: Arc<ApprovalGate>| {
+ tokio::spawn(async move {
+ turn_origin::with_origin(
+ web_origin(),
+ gate.intercept(
+ &ApprovalTurnContext::chat(chat_ctx()),
+ "create_workflow",
+ "create a workflow",
+ serde_json::json!({}),
+ ),
+ )
+ .await
+ })
+ };
+
+ let first = intercept(gate.clone());
+ let pending = loop {
+ if let Some(p) = gate
+ .list_pending()
+ .unwrap()
+ .into_iter()
+ .find(|p| p.tool_name == "create_workflow")
+ {
+ break p;
+ }
+ tokio::time::sleep(Duration::from_millis(10)).await;
+ };
+ let row = gate
+ .decide(&pending.request_id, ApprovalDecision::ApproveAlwaysForTool)
+ .unwrap()
+ .expect("the parked create_workflow row is decided");
+ assert!(matches!(first.await.unwrap(), GateOutcome::Allow));
+ crate::config::ops::add_auto_approve_tool(
+ &crate::core::runtime::DispatchCtx::process_default(),
+ &row.tool_name,
+ )
+ .await
+ .expect("persist the Always-allow choice");
+
+ let saved = crate::config::ops::load_config_with_timeout().await.unwrap();
+ assert!(
+ saved
+ .autonomy
+ .auto_approve
+ .iter()
+ .any(|tool| tool == "create_workflow"),
+ "Always allow must persist create_workflow to autonomy.auto_approve"
+ );
+
+ let second = tokio::time::timeout(Duration::from_secs(5), intercept(gate.clone()))
+ .await
+ .expect("the second create_workflow must not park for approval")
+ .unwrap();
+ assert!(matches!(second, GateOutcome::Allow));
+ assert!(
+ gate.list_pending().unwrap().is_empty(),
+ "the second create_workflow must not re-prompt"
+ );
+
+ // Leave no allowlisted create_workflow behind for sibling gate tests.
+ crate::security::live_policy::install(
+ Arc::new(crate::security::SecurityPolicy::default()),
+ dir.path().to_path_buf(),
+ dir.path().to_path_buf(),
+ );
+}
+
/// With `auto_approve_all: true`, a WebChat-origin call resolves to
/// `Allow` immediately — no pending row is created and the chat context
/// is never consulted, proving the short-circuit fires above the park.
diff --git a/crates/openhuman-core/src/skills/bundled/flow_authoring_tests.rs b/crates/openhuman-core/src/skills/bundled/flow_authoring_tests.rs
index a6f5e925b8..b4d80c0915 100644
--- a/crates/openhuman-core/src/skills/bundled/flow_authoring_tests.rs
+++ b/crates/openhuman-core/src/skills/bundled/flow_authoring_tests.rs
@@ -105,3 +105,77 @@ fn tiny_skills_rejects_unsafe_resource_paths_without_writing_outside_scope() {
assert!(!workspace.path().join(".openhuman/outside.txt").exists());
assert!(snapshot_for(&snapshot_key(workspace.path(), &gate), 1).is_none());
}
+
+/// While the local legacy flow import is incomplete, workflow access is paused
+/// (`ensure_flow_scope_ready`), so the builtin must stay hidden; once the
+/// import finishes, the next prewarm must surface it.
+#[tokio::test]
+// The guard serializes the process-wide storage slot for this async test.
+#[allow(clippy::await_holding_lock)]
+async fn builtin_is_hidden_until_the_legacy_flow_import_completes() {
+ use crate::core::runtime::{ComponentSet, ContextOverlay, CoreContext};
+ use crate::storage::Scope;
+
+ let workspace = tempfile::tempdir().expect("workspace");
+ let legacy = Path::new(env!("CARGO_MANIFEST_DIR"))
+ .join("src/storage/import/fixtures/tinyflows/workspace/flows");
+ fn copy_tree(from: &Path, to: &Path) {
+ std::fs::create_dir_all(to).unwrap();
+ for entry in std::fs::read_dir(from).unwrap() {
+ let entry = entry.unwrap();
+ let target = to.join(entry.file_name());
+ if entry.path().is_dir() {
+ copy_tree(&entry.path(), &target);
+ } else {
+ std::fs::copy(entry.path(), target).unwrap();
+ }
+ }
+ }
+ copy_tree(&legacy, &workspace.path().join("flows"));
+ let mut config = Config::default();
+ config.workspace_dir = workspace.path().to_path_buf();
+ let backend = crate::storage::test_support::sqlite_backend().expect("sqlite backend");
+ let _storage =
+ crate::storage::test_support::install_backend_for_test(Arc::clone(&backend.backend));
+ let context = CoreContext::for_test_with_components(ComponentSet::all()).derive_with(
+ ContextOverlay::new(
+ config.clone(),
+ DomainSet::full(),
+ crate::tools::toolpacks::ToolGroups::none(),
+ )
+ .without_user_skill_roots(),
+ );
+
+ CoreContext::scope(context, async {
+ let ctx = DispatchCtx::ambient();
+ let visible = |ctx: &DispatchCtx| {
+ crate::skills::load_workflow_metadata_for(ctx, &config)
+ .iter()
+ .any(|skill| skill.id() == FLOW_SKILL_ID)
+ };
+
+ prewarm(&ctx, &config, None).await;
+ assert!(
+ !visible(&ctx),
+ "flow-authoring must stay hidden while the legacy flow import is incomplete"
+ );
+
+ let imported = crate::storage::import::tinyflows::import_flows(
+ &backend.backend,
+ &Scope::local(),
+ &config,
+ )
+ .expect("legacy flow import");
+ assert!(
+ matches!(imported, crate::storage::import::Outcome::Imported { .. }),
+ "{imported:?}"
+ );
+
+ prewarm(&ctx, &config, None).await;
+ assert!(
+ visible(&ctx),
+ "flow-authoring must appear once the legacy flow import has completed"
+ );
+ })
+ .await;
+}