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(tinyagents): share failing-tool helper across middleware tests
Steven Enamakel3be843af4cee
diff --git a/crates/openhuman-core/src/agent/tinyagents/middleware_classified_failure_fetch_tests.rs b/crates/openhuman-core/src/agent/tinyagents/middleware_classified_failure_fetch_tests.rsindex 9335349bdb..5d1a392680 100644--- a/crates/openhuman-core/src/agent/tinyagents/middleware_classified_failure_fetch_tests.rs+++ b/crates/openhuman-core/src/agent/tinyagents/middleware_classified_failure_fetch_tests.rs@@ -13,7 +13,7 @@ const FETCH_503: &str = "HTTP 503 Service Unavailable from example.test; the ser/// Run one failing `tool` call with `url` and `error` through the breaker.async fn fail_call(mw: &RepeatedToolFailureMiddleware,- context: &mut RunContext<OpenHumanRunContext>,+ context: &mut RunContext<crate::agent::tinyagents::host::OpenHumanRunContext>,id: &str,tool: &str,arguments: serde_json::Value,diff --git a/crates/openhuman-core/src/agent/tinyagents/middleware_classified_failure_tests.rs b/crates/openhuman-core/src/agent/tinyagents/middleware_classified_failure_tests.rsindex 77088b8d23..56b6a8e88a 100644--- a/crates/openhuman-core/src/agent/tinyagents/middleware_classified_failure_tests.rs+++ b/crates/openhuman-core/src/agent/tinyagents/middleware_classified_failure_tests.rs@@ -1,6 +1,22 @@use super::*;use crate::agent::tinyagents::middleware::repeated_failure::RepeatedToolFailureMiddleware;+async fn run_failing_tool(+ mw: &RepeatedToolFailureMiddleware,+ context: &mut RunContext<crate::agent::tinyagents::host::OpenHumanRunContext>,+ id: &str,+ tool: &str,+ arguments: serde_json::Value,+ error: &str,+) {+ let mut call = TaToolCall::new(id, tool, arguments);+ mw.before_tool(context, &(), &mut call).await.unwrap();+ let mut result = failing_result(tool, error);+ mw.after_tool(context, &(), &invocation(id, tool), &mut result)+ .await+ .unwrap();+}+#[tokio::test]async fn varied_queries_against_one_forbidden_endpoint_stop_on_first_failure() {let handle = SteeringHandle::allow_all();@@ -231,20 +247,15 @@ async fn shell_timeout_nudges_once_then_halts_on_second() {let slot = std::sync::Arc::new(std::sync::Mutex::new(None));let mw = RepeatedToolFailureMiddleware::new(handle.clone(), 3, slot.clone());let mut context = ctx();- let mut run = |id: &'static str, command: &'static str| {- let mw = &mw;- let context = &mut context;- async move {- let mut call = TaToolCall::new(id, "shell", serde_json::json!({ "command": command }));- mw.before_tool(context, &(), &mut call).await.unwrap();- let mut result = failing_result("shell", "Command timed out after 60s and was killed");- mw.after_tool(context, &(), &invocation(id, "shell"), &mut result)- .await- .unwrap();- }- };-- run("sh-1", "for d in a.io b.io c.io; do whois $d; done").await;+ run_failing_tool(+ &mw,+ &mut context,+ "sh-1",+ "shell",+ serde_json::json!({ "command": "for d in a.io b.io c.io; do whois $d; done" }),+ "Command timed out after 60s and was killed",+ )+ .await;assert_eq!(drain_pause_count(&handle), 0, "first timeout must not halt");assert!(slot.lock().unwrap().is_none());let nudges = drain_nudge_messages(&mw, &mut context).await;@@ -252,7 +263,15 @@ async fn shell_timeout_nudges_once_then_halts_on_second() {assert!(nudges[0].contains("timed out"), "{nudges:?}");assert!(nudges[0].contains("smaller, bounded"), "{nudges:?}");- run("sh-2", "whois a.io").await;+ run_failing_tool(+ &mw,+ &mut context,+ "sh-2",+ "shell",+ serde_json::json!({ "command": "whois a.io" }),+ "Command timed out after 60s and was killed",+ )+ .await;assert_eq!(drain_pause_count(&handle), 1, "second timeout halts");let summary = slot.lock().unwrap().clone().unwrap();assert!(summary.contains("uncertain_side_effect"), "{summary}");@@ -273,29 +292,15 @@ async fn a_refused_integration_steers_the_model_off_it_instead_of_ending_the_runlet mw = RepeatedToolFailureMiddleware::new(handle.clone(), 3, slot.clone());let refused = "Web search failed: search ExecuteTool failed: ai.tinyhumans.tinybus.Error.Failed: provider request failed: provider returned HTTP 401";let mut context = ctx();- let mut run = |id: &'static str, query: &'static str| {- let mw = &mw;- let context = &mut context;- async move {- let mut call = TaToolCall::new(- id,- "web_search_tool",- serde_json::json!({ "query": query, "max_results": 10 }),- );- mw.before_tool(context, &(), &mut call).await.unwrap();- let mut result = failing_result("web_search_tool", refused);- mw.after_tool(- context,- &(),- &invocation(id, "web_search_tool"),- &mut result,- )- .await- .unwrap();- }- };-- run("ws-1", "regex chess move generator").await;+ run_failing_tool(+ &mw,+ &mut context,+ "ws-1",+ "web_search_tool",+ serde_json::json!({ "query": "regex chess move generator", "max_results": 10 }),+ refused,+ )+ .await;assert_eq!(drain_pause_count(&handle),0,@@ -315,7 +320,15 @@ async fn a_refused_integration_steers_the_model_off_it_instead_of_ending_the_run);// The model insists on the same operation: now the ledger stops it.- run("ws-2", "regex chess move generator").await;+ run_failing_tool(+ &mw,+ &mut context,+ "ws-2",+ "web_search_tool",+ serde_json::json!({ "query": "regex chess move generator", "max_results": 10 }),+ refused,+ )+ .await;assert_eq!(drain_pause_count(&handle),1,@@ -707,7 +720,7 @@ async fn a_success_clears_the_invalid_arguments_count_and_a_rejection_is_nudged("the success restarted the count: three more rejections stay inside the budget");assert!(slot.lock().unwrap().is_none());- reject(&mw, "r-7").await;+ reject(&mw, &mut context, "r-7").await;assert_eq!(drain_pause_count(&handle),1,diff --git a/crates/openhuman-core/src/agent/tinyagents/middleware_command_exit_failure_tests.rs b/crates/openhuman-core/src/agent/tinyagents/middleware_command_exit_failure_tests.rsindex e6ca8a67c8..7c29e36a5d 100644--- a/crates/openhuman-core/src/agent/tinyagents/middleware_command_exit_failure_tests.rs+++ b/crates/openhuman-core/src/agent/tinyagents/middleware_command_exit_failure_tests.rs@@ -15,7 +15,7 @@ fn sigpipe_git_log_report() -> String {async fn run_shell(mw: &RepeatedToolFailureMiddleware,- context: &mut RunContext<OpenHumanRunContext>,+ context: &mut RunContext<crate::agent::tinyagents::host::OpenHumanRunContext>,id: &str,command: &str,mut result: TaToolResult,@@ -171,11 +171,12 @@ async fn a_faulted_module_tool_is_steered_away_once_then_halts() {let handle = SteeringHandle::allow_all();let slot = std::sync::Arc::new(std::sync::Mutex::new(None));let mw = RepeatedToolFailureMiddleware::new(handle.clone(), 3, slot.clone());+ let mut context = ctx();let mut call = TaToolCall::new("search-1", "web_search_tool", json!({ "query": "one" }));- mw.before_tool(&mut ctx(), &(), &mut call).await.unwrap();+ mw.before_tool(&mut context, &(), &mut call).await.unwrap();let mut result = failing_result("web_search_tool", MODULE_FAULT);mw.after_tool(- &mut ctx(),+ &mut context,&(),&invocation("search-1", "web_search_tool"),&mut result,@@ -189,10 +190,10 @@ async fn a_faulted_module_tool_is_steered_away_once_then_halts() {assert!(nudges[0].contains("Do not call"), "{}", nudges[0]);let mut call = TaToolCall::new("search-2", "web_search_tool", json!({ "query": "two" }));- mw.before_tool(&mut ctx(), &(), &mut call).await.unwrap();+ mw.before_tool(&mut context, &(), &mut call).await.unwrap();let mut result = failing_result("web_search_tool", MODULE_FAULT);mw.after_tool(- &mut ctx(),+ &mut context,&(),&invocation("search-2", "web_search_tool"),&mut result,diff --git a/crates/openhuman-core/src/agent/tinyagents/middleware_failure_effect_tests.rs b/crates/openhuman-core/src/agent/tinyagents/middleware_failure_effect_tests.rsindex 8a27d2e14b..1cda9d219d 100644--- a/crates/openhuman-core/src/agent/tinyagents/middleware_failure_effect_tests.rs+++ b/crates/openhuman-core/src/agent/tinyagents/middleware_failure_effect_tests.rs@@ -23,7 +23,7 @@ fn harness_timeout(tool: &str) -> String {async fn run_call(mw: &RepeatedToolFailureMiddleware,- context: &mut RunContext<OpenHumanRunContext>,+ context: &mut RunContext<crate::agent::tinyagents::host::OpenHumanRunContext>,id: &str,tool: &str,args: serde_json::Value,