The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
test: thread DispatchCtx through controller handler calls
Steven Enamakel44b842ef907d
diff --git a/tests/cost_report_e2e.rs b/tests/cost_report_e2e.rsindex eae53aba51..738ce0e383 100644--- a/tests/cost_report_e2e.rs+++ b/tests/cost_report_e2e.rs@@ -6,6 +6,7 @@//! and the config is found through `OPENHUMAN_WORKSPACE`, so the phases below//! must share one process and run in order.+use openhuman::core::runtime::DispatchCtx;use std::sync::Arc;use chrono::{Datelike, Duration, Utc};@@ -82,6 +83,7 @@ async fn cost_reports_group_the_ledger_and_a_refuse_budget_stops_the_call() {// cost_report grouped by model.let report = invoke_method(+ DispatchCtx::process_default(),default_state(),"openhuman.cost_report",json!({ "days": 1, "groupBy": ["model"] }),@@ -107,6 +109,7 @@ async fn cost_reports_group_the_ledger_and_a_refuse_budget_stops_the_call() {// A filter narrows the report; a misspelt one is refused.let filtered = invoke_method(+ DispatchCtx::process_default(),default_state(),"openhuman.cost_report",json!({ "days": 1, "filter": { "model": "m-b" } }),@@ -115,6 +118,7 @@ async fn cost_reports_group_the_ledger_and_a_refuse_budget_stops_the_call() {.expect("filtered cost_report");assert_eq!(peel(&filtered)["totals"]["calls"], 1);invoke_method(+ DispatchCtx::process_default(),default_state(),"openhuman.cost_report",json!({ "days": 1, "filter": { "modle": "m-b" } }),@@ -124,6 +128,7 @@ async fn cost_reports_group_the_ledger_and_a_refuse_budget_stops_the_call() {// cost_cache_report: overall hit ratio and the cold call.let cache = invoke_method(+ DispatchCtx::process_default(),default_state(),"openhuman.cost_cache_report",json!({ "days": 1 }),diff --git a/tests/raw_coverage/composio_raw_coverage_e2e.rs b/tests/raw_coverage/composio_raw_coverage_e2e.rsindex be6d60c0e6..ce4c92606d 100644--- a/tests/raw_coverage/composio_raw_coverage_e2e.rs+++ b/tests/raw_coverage/composio_raw_coverage_e2e.rs@@ -3,6 +3,7 @@//! These tests avoid live Composio/backend calls and exercise public helper//! surfaces that feed the JSON-RPC and agent-tool paths.+use openhuman::core::runtime::DispatchCtx;use std::sync::{Arc, OnceLock};use serde_json::{json, Value};@@ -469,5 +470,5 @@ fn composio_controller<'a>(async fn composio_call(controller: &RegisteredController, params: Value) -> Result<Value, String> {let params = params.as_object().cloned().unwrap_or_default();- (controller.handler)(params).await+ (controller.handler)(DispatchCtx::process_default(), params).await}diff --git a/tests/raw_coverage/dispatch_param_validation_e2e.rs b/tests/raw_coverage/dispatch_param_validation_e2e.rsindex cb4ea09d13..88f1593a7e 100644--- a/tests/raw_coverage/dispatch_param_validation_e2e.rs+++ b/tests/raw_coverage/dispatch_param_validation_e2e.rs@@ -17,6 +17,7 @@//! is easy to write a test that looks like it covers the dispatch path and does//! not. These tests pin the observable behaviour on both sides of that line.+use openhuman::core::runtime::DispatchCtx;use serde_json::{json, Map};use openhuman_core::core::all::{@@ -44,7 +45,7 @@ async fn missing_required_param_is_refused_with_the_schema_comment() {.expect("`id` input").comment;- let err = dispatch(state(), "openhuman.run_ledger_get", json!({}))+ let err = dispatch(DispatchCtx::process_default(), state(), "openhuman.run_ledger_get", json!({})).await.expect_err("`id` is required");@@ -62,6 +63,7 @@ async fn missing_required_param_is_refused_with_the_schema_comment() {#[tokio::test]async fn unknown_param_is_refused_by_the_gate_alone() {let err = dispatch(+ DispatchCtx::process_default(),state(),"openhuman.memory_engines_list",json!({ "nonsense_param": 1 }),@@ -77,6 +79,7 @@ async fn unknown_param_is_refused_by_the_gate_alone() {#[tokio::test]async fn mistyped_param_is_refused_with_the_declared_type() {let err = dispatch(+ DispatchCtx::process_default(),state(),"openhuman.session_import_run",json!({ "dry_run": "yes" }),@@ -97,7 +100,7 @@ async fn mistyped_param_is_refused_with_the_declared_type() {/// directory call controllers.#[tokio::test]async fn handler_refusal_differs_from_the_dispatcher_refusal_for_an_absent_param() {- let dispatched = dispatch(state(), "openhuman.memory_recall", json!({}))+ let dispatched = dispatch(DispatchCtx::process_default(), state(), "openhuman.memory_recall", json!({})).await.expect_err("`question` is required");assert!(@@ -110,7 +113,7 @@ async fn handler_refusal_differs_from_the_dispatcher_refusal_for_an_absent_param.iter().find(|controller| rpc_method_name(&controller.schema) == "openhuman.memory_recall").expect("memory_recall is registered unconditionally");- let direct = (controller.handler)(Map::new())+ let direct = (controller.handler)(DispatchCtx::process_default(), Map::new()).await.expect_err("the handler refuses too");@@ -132,6 +135,7 @@ async fn handler_refusal_differs_from_the_dispatcher_refusal_for_an_absent_param#[tokio::test]async fn explicit_null_passes_the_gate_and_the_handler_refuses_instead() {let err = dispatch(+ DispatchCtx::process_default(),state(),"openhuman.memory_recall",json!({ "question": null }),@@ -156,6 +160,7 @@ async fn explicit_null_passes_the_gate_and_the_handler_refuses_instead() {#[tokio::test]async fn out_of_range_integer_is_refused_with_the_bound_named() {let err = dispatch(+ DispatchCtx::process_default(),state(),"openhuman.config_update_autonomy_settings",json!({ "max_actions_per_hour": 4_294_967_296u64 }),@@ -169,6 +174,7 @@ async fn out_of_range_integer_is_refused_with_the_bound_named() {);let err = dispatch(+ DispatchCtx::process_default(),state(),"openhuman.config_update_autonomy_settings",json!({ "max_actions_per_hour": 0 }),diff --git a/tests/raw_coverage/inference_local_controllers_rpc_raw_coverage_e2e.rs b/tests/raw_coverage/inference_local_controllers_rpc_raw_coverage_e2e.rsindex 6979811458..f58f4abefa 100644--- a/tests/raw_coverage/inference_local_controllers_rpc_raw_coverage_e2e.rs+++ b/tests/raw_coverage/inference_local_controllers_rpc_raw_coverage_e2e.rs@@ -45,6 +45,7 @@//! serialization mechanism, the same reasoning as `tests/agent_harness_e2e.rs:8-12`.#![allow(clippy::await_holding_lock)]+use openhuman::core::runtime::DispatchCtx;use crate::env_guard::EnvVarGuard;use std::path::{Path, PathBuf};use std::sync::{OnceLock};@@ -94,7 +95,7 @@ fn controller<'a>(async fn call(controller: &RegisteredController, params: Value) -> Result<Value, String> {let params = params.as_object().cloned().unwrap_or_default();- (controller.handler)(params).await+ (controller.handler)(DispatchCtx::process_default(), params).await}/// A config rooted in `tmp/.openhuman`, matching what `OPENHUMAN_WORKSPACE`diff --git a/tests/raw_coverage/tool_registry_approval_raw_coverage_e2e.rs b/tests/raw_coverage/tool_registry_approval_raw_coverage_e2e.rsindex 5ec61e75a4..c00e2d97a4 100644--- a/tests/raw_coverage/tool_registry_approval_raw_coverage_e2e.rs+++ b/tests/raw_coverage/tool_registry_approval_raw_coverage_e2e.rs@@ -5,6 +5,7 @@//! direct public API calls cover persistence/redaction/provider branches that//! are otherwise only indirectly reachable from the controllers.+use openhuman::core::runtime::DispatchCtx;use crate::env_guard::EnvVarGuard;use crate::rpc_harness::{error_message, payload};use std::path::Path;@@ -549,7 +550,7 @@ async fn approval_schema_handlers_validate_params_and_surface_empty_gate_state().find(|controller| controller.schema.function == "list_pending").expect("list pending controller").handler;- let list_value = list_handler(Map::new()).await.expect("list pending value");+ let list_value = list_handler(DispatchCtx::process_default(), Map::new()).await.expect("list pending value");assert!(list_value.get("result").or(Some(&list_value))@@ -563,27 +564,27 @@ async fn approval_schema_handlers_validate_params_and_surface_empty_gate_state().handler;let mut invalid_limit = Map::new();invalid_limit.insert("limit".to_string(), json!("ten"));- assert!(recent_handler(invalid_limit)+ assert!(recent_handler(DispatchCtx::process_default(), invalid_limit).await.expect_err("string limit").contains("expected unsigned integer"));for invalid in [json!(true), json!([]), json!({ "limit": 10 })] {let mut invalid_limit = Map::new();invalid_limit.insert("limit".to_string(), invalid);- assert!(recent_handler(invalid_limit)+ assert!(recent_handler(DispatchCtx::process_default(), invalid_limit).await.expect_err("non-numeric limit").contains("expected unsigned integer"));}let mut negative_limit = Map::new();negative_limit.insert("limit".to_string(), json!(-1));- assert!(recent_handler(negative_limit)+ assert!(recent_handler(DispatchCtx::process_default(), negative_limit).await.expect_err("negative limit").contains("expected unsigned integer"));let mut null_limit = Map::new();null_limit.insert("limit".to_string(), Value::Null);- let recent_value = recent_handler(null_limit)+ let recent_value = recent_handler(DispatchCtx::process_default(), null_limit).await.expect("null limit should use default");assert!(recent_value@@ -597,14 +598,14 @@ async fn approval_schema_handlers_validate_params_and_surface_empty_gate_state().find(|controller| controller.schema.function == "decide").expect("decide controller").handler;- assert!(decide_handler(Map::new())+ assert!(decide_handler(DispatchCtx::process_default(), Map::new()).await.expect_err("missing request id").contains("missing required param 'request_id'"));let mut numeric_request = Map::new();numeric_request.insert("request_id".to_string(), json!(42));numeric_request.insert("decision".to_string(), json!("deny"));- assert!(decide_handler(numeric_request)+ assert!(decide_handler(DispatchCtx::process_default(), numeric_request).await.expect_err("numeric request id").contains("expected string"));@@ -617,7 +618,7 @@ async fn approval_schema_handlers_validate_params_and_surface_empty_gate_state()let mut invalid_request = Map::new();invalid_request.insert("request_id".to_string(), invalid);invalid_request.insert("decision".to_string(), json!("deny"));- assert!(decide_handler(invalid_request)+ assert!(decide_handler(DispatchCtx::process_default(), invalid_request).await.expect_err("non-string request id").contains("expected string"));@@ -625,14 +626,14 @@ async fn approval_schema_handlers_validate_params_and_surface_empty_gate_state()let mut numeric_decision = Map::new();numeric_decision.insert("request_id".to_string(), json!("missing"));numeric_decision.insert("decision".to_string(), json!(42));- assert!(decide_handler(numeric_decision)+ assert!(decide_handler(DispatchCtx::process_default(), numeric_decision).await.expect_err("numeric decision").contains("expected string"));let mut invalid_decision = Map::new();invalid_decision.insert("request_id".to_string(), json!("missing"));invalid_decision.insert("decision".to_string(), json!("maybe"));- assert!(decide_handler(invalid_decision)+ assert!(decide_handler(DispatchCtx::process_default(), invalid_decision).await.expect_err("invalid decision").contains("approve_once|approve_always_for_tool|approve_always_for_flow|deny"));@@ -642,27 +643,27 @@ async fn approval_schema_handlers_validate_params_and_surface_empty_gate_state().find(|controller| controller.schema.function == "preauthorize_flow").expect("preauthorize flow controller").handler;- assert!(preauthorize_handler(Map::new())+ assert!(preauthorize_handler(DispatchCtx::process_default(), Map::new()).await.expect_err("missing flow id").contains("missing required param 'flow_id'"));let mut missing_tools = Map::new();missing_tools.insert("flow_id".to_string(), json!("flow-1"));- assert!(preauthorize_handler(missing_tools)+ assert!(preauthorize_handler(DispatchCtx::process_default(), missing_tools).await.expect_err("missing tool names").contains("missing required param 'tool_names'"));let mut non_array_tools = Map::new();non_array_tools.insert("flow_id".to_string(), json!("flow-1"));non_array_tools.insert("tool_names".to_string(), json!("slack_post"));- assert!(preauthorize_handler(non_array_tools)+ assert!(preauthorize_handler(DispatchCtx::process_default(), non_array_tools).await.expect_err("non-array tool names").contains("expected array of strings"));let mut mixed_tools = Map::new();mixed_tools.insert("flow_id".to_string(), json!("flow-1"));mixed_tools.insert("tool_names".to_string(), json!(["ok", 42]));- assert!(preauthorize_handler(mixed_tools)+ assert!(preauthorize_handler(DispatchCtx::process_default(), mixed_tools).await.expect_err("non-string tool name entry").contains("expected string"));