Skip to content

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

test(json-rpc): cover copilot run_flow tool invocation end to end

Steven Enamakel4bbc4e2fb3ab
diff --git a/tests/json_rpc_e2e.rs b/tests/json_rpc_e2e.rs
index 9ade01e7bd..47412c5b74 100644
--- a/tests/json_rpc_e2e.rs
+++ b/tests/json_rpc_e2e.rs
@@ -11341,6 +11341,9 @@ encrypt = false
# content, so compaction must stay off for the arc to be observable in-test.
[context]
compaction_enabled = false
+
+[autonomy]
+auto_approve = ["run_flow"]
"#
);
fn write_config_file(config_dir: &Path, cfg: &str) {
@@ -11470,6 +11473,19 @@ async fn json_rpc_flows_full_arc_discover_build_create_run_inner() {
let user_scoped_dir = openhuman_home.join("users").join("e2e-user");
write_flows_tier_config(&user_scoped_dir, &mock_origin);
+ // This test runs as its own exact-filtered JSON-RPC E2E process. Install
+ // only the approval needed for the real run_flow tool call below, so the
+ // streaming builder exposes that tool without parking the deterministic
+ // test completion for a human decision.
+ let mut approval_config = openhuman_core::config::Config::default();
+ approval_config.workspace_dir = openhuman_home.join("workspace");
+ approval_config.config_path = openhuman_home.join("config.toml");
+ approval_config.autonomy.auto_approve.push("run_flow".to_string());
+ openhuman_core::security::approval::ApprovalGate::init_global(
+ approval_config,
+ format!("session-{}", uuid::Uuid::new_v4()),
+ );
+
let (rpc_addr, rpc_join) = serve_on_ephemeral(build_core_http_router(false)).await;
let rpc_base = format!("http://{rpc_addr}");
tokio::time::sleep(Duration::from_millis(100)).await;
@@ -11727,6 +11743,140 @@ async fn json_rpc_flows_full_arc_discover_build_create_run_inner() {
"drafter prompt must reference the planner's structured plan (graph data passing)"
);
+ // ── 4. Copilot run_flow goes through InvokeTool → RunFlow over TinyBus ──
+ // The trigger-only flow finishes without a model call, keeping this proof
+ // focused on the detached-run callback rather than flow-node execution.
+ let callback_flow = post_json_rpc(
+ &rpc_base,
+ 71_030,
+ "openhuman.flows_create",
+ json!({
+ "name": "Copilot RunFlow callback probe",
+ "graph": {
+ "nodes": [{"id":"trigger","kind":"trigger","name":"Manual"}],
+ "edges": []
+ }
+ }),
+ )
+ .await;
+ let callback_flow_id = peel_logs_envelope(assert_no_jsonrpc_error(
+ &callback_flow,
+ "flows_create for Copilot RunFlow callback",
+ ))
+ .get("id")
+ .and_then(Value::as_str)
+ .expect("saved callback flow id")
+ .to_string();
+ let callback_graph = json!({
+ "nodes": [{"id":"trigger","kind":"trigger","name":"Manual"}],
+ "edges": []
+ });
+
+ fn tool_result_with_marker(requests: &[Value], marker: &str) -> Option<String> {
+ requests
+ .iter()
+ .filter_map(|request| request.pointer("/body/messages").and_then(Value::as_array))
+ .flatten()
+ .filter(|message| message.get("role").and_then(Value::as_str) == Some("tool"))
+ .filter_map(|message| message.get("content").and_then(Value::as_str))
+ .find(|content| content.contains(marker))
+ .map(str::to_string)
+ }
+
+ clear_forced_chat_completions();
+ with_chat_completion_requests(|requests| requests.clear());
+ push_forced_chat_completion_when(
+ "run_flow",
+ forced_tool_call_completion(
+ "run_flow",
+ json!({ "flow_id": "missing-copilot-flow" }),
+ ),
+ );
+ push_forced_chat_completion_when(
+ "Could not start flow",
+ forced_text_completion("That flow is not saved, so I could not run it."),
+ );
+ let missing_run = post_json_rpc(
+ &rpc_base,
+ 71_031,
+ "openhuman.flows_build",
+ json!({
+ "mode": "revise",
+ "flow_id": "missing-copilot-flow",
+ "graph": callback_graph,
+ "instruction": "The user confirmed a test run; attempt the saved flow now.",
+ "thread_id": "e2e-copilot-runflow-missing",
+ "request_id": "req-copilot-runflow-missing"
+ }),
+ )
+ .await;
+ assert_no_jsonrpc_error(&missing_run, "Copilot run_flow missing-flow path");
+ let missing_requests = with_chat_completion_requests(|requests| requests.clone());
+ assert!(
+ missing_requests.iter().any(|request| {
+ request
+ .pointer("/body/tools")
+ .and_then(Value::as_array)
+ .is_some_and(|tools| {
+ tools.iter().any(|tool| {
+ tool.pointer("/function/name").and_then(Value::as_str)
+ == Some("run_flow")
+ })
+ })
+ }),
+ "streaming Copilot builder must expose the real run_flow tool"
+ );
+ let missing_tool_result = tool_result_with_marker(&missing_requests, "Could not start flow")
+ .expect("module tool result reports the missing saved flow");
+ assert!(
+ missing_tool_result.contains("missing-copilot-flow"),
+ "missing flow result should identify the rejected id: {missing_tool_result}"
+ );
+
+ clear_forced_chat_completions();
+ with_chat_completion_requests(|requests| requests.clear());
+ push_forced_chat_completion_when(
+ "run_flow",
+ forced_tool_call_completion(
+ "run_flow",
+ json!({ "flow_id": callback_flow_id }),
+ ),
+ );
+ push_forced_chat_completion_when(
+ "workflow_run_started",
+ forced_text_completion("The confirmed test run started."),
+ );
+ let started_run = post_json_rpc(
+ &rpc_base,
+ 71_032,
+ "openhuman.flows_build",
+ json!({
+ "mode": "revise",
+ "flow_id": callback_flow_id,
+ "graph": callback_graph,
+ "instruction": "The user confirmed a test run; run this saved flow now.",
+ "thread_id": "e2e-copilot-runflow-saved",
+ "request_id": "req-copilot-runflow-saved"
+ }),
+ )
+ .await;
+ assert_no_jsonrpc_error(&started_run, "Copilot run_flow saved-flow path");
+ let started_requests = with_chat_completion_requests(|requests| requests.clone());
+ let started_tool_result = tool_result_with_marker(&started_requests, "workflow_run_started")
+ .expect("module tool result reports a detached run");
+ let started_payload: Value =
+ serde_json::from_str(&started_tool_result).expect("run_flow result is JSON");
+ assert_eq!(started_payload["type"], "workflow_run_started");
+ assert_eq!(started_payload["flow_id"], callback_flow_id);
+ assert_eq!(started_payload["status"], "running");
+ assert_eq!(started_payload["detached"], true);
+ assert!(
+ started_payload["run_id"]
+ .as_str()
+ .is_some_and(|run_id| !run_id.is_empty()),
+ "detached tool result must contain its run id: {started_payload}"
+ );
+
// Hygiene: never let a leftover scripted completion bleed into another test
// sharing this process (the FIFO is a process-global static).
clear_forced_chat_completions();