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(agent): fold the adapter timeout tests into existing fixtures
M3gA-Minda54bb27f0254
diff --git a/crates/openhuman-core/src/agent/tinyagents/tools.rs b/crates/openhuman-core/src/agent/tinyagents/tools.rsindex 1223eb7d41..4f2102f4a0 100644--- a/crates/openhuman-core/src/agent/tinyagents/tools.rs+++ b/crates/openhuman-core/src/agent/tinyagents/tools.rs@@ -173,10 +173,8 @@ impl Tool for CanonicalSharedToolAdapter {self.resolved_tool().and_then(Tool::family)}- /// Forwarded so the harness bounds each call by the wrapped tool's own- /// policy. Without it the trait default reported `Inherit` for every- /// registered tool, so `shell` (Unbounded unless `timeout_secs`) and the- /// tools sized to a human wait were all killed at the inherited 120s.+ /// Forwarded so each call gets the wrapped tool's own deadline; the trait+ /// default capped every tool, `shell` included, at the inherited 120s.fn timeout_policy(&self, arguments: &serde_json::Value) -> tinytools::ToolTimeout {self.resolved_tool().map_or(tinytools::ToolTimeout::Inherit, |tool| {diff --git a/crates/openhuman-core/src/agent/tinyagents/tools_canonical_tests.rs b/crates/openhuman-core/src/agent/tinyagents/tools_canonical_tests.rsindex 7a29baf710..d714bd549a 100644--- a/crates/openhuman-core/src/agent/tinyagents/tools_canonical_tests.rs+++ b/crates/openhuman-core/src/agent/tinyagents/tools_canonical_tests.rs@@ -26,6 +26,15 @@ impl Tool for RecordingTool {ToolPolicy::read_only().requiring_approval()}+ /// Like `ShellTool`: unbounded unless the call passes `timeout_secs`.+ fn timeout_policy(&self, args: &serde_json::Value) -> tinytools::ToolTimeout {+ args["timeout_secs"]+ .as_u64()+ .map_or(tinytools::ToolTimeout::Unbounded, |secs| {+ tinytools::ToolTimeout::Millis(secs * 1000)+ })+ }+async fn execute(&self, args: serde_json::Value) -> anyhow::Result<ToolResult> {self.execute_with_context(args, ToolCallOptions::default(), None).await@@ -240,6 +249,10 @@ async fn canonical_adapter_fails_closed_when_the_registered_tool_is_gone() {.expect("reported failure");assert!(result.is_error);assert_eq!(result.output(), "unknown tool 'missing'");+ assert_eq!(+ adapter.timeout_policy(&serde_json::json!({"timeout_secs": 300})),+ tinytools::ToolTimeout::Inherit+ );}#[tokio::test]@@ -343,69 +356,30 @@ fn session_deferred_adapter_reports_deferred_but_never_surfaces_a_hidden_tool()assert_eq!(forced("deferred"), tinytools::ToolExposure::Deferred);}-/// Mirrors `ShellTool::timeout_policy`: unbounded unless the call passes-/// `timeout_secs`. Its default `policy()` reports an `Inherit` runtime, so a-/// policy derived from `policy()` alone would lose both answers.-struct ArgTimedTool;--#[async_trait]-impl Tool for ArgTimedTool {- fn name(&self) -> &str {- "arg_timed"- }-- fn description(&self) -> &str {- "Times itself from its arguments."- }-- fn parameters_schema(&self) -> serde_json::Value {- serde_json::json!({"type": "object"})- }-- fn timeout_policy(&self, args: &serde_json::Value) -> tinytools::ToolTimeout {- match args.get("timeout_secs").and_then(serde_json::Value::as_u64) {- None | Some(0) => tinytools::ToolTimeout::Unbounded,- Some(secs) => tinytools::ToolTimeout::Millis(secs * 1000),- }- }-- async fn execute(&self, _args: serde_json::Value) -> anyhow::Result<ToolResult> {- Ok(ToolResult::default())- }-}-/// The harness bounds a call by the *registered* tool's `timeout_policy`, and-/// every OpenHuman tool is registered through this adapter. Without forwarding,-/// a shell call was killed at the inherited 120s even with `timeout_secs=3493`-/// (#7712).+/// every OpenHuman tool is registered through this adapter (#7712).#[test]fn adapter_forwards_the_wrapped_tools_timeout_policy() {- let set: Arc<Vec<Box<dyn Tool>>> = Arc::new(vec![Box::new(ArgTimedTool)]);- let adapter =- CanonicalSharedToolAdapter::for_name(vec![set], "arg_timed").expect("registered tool");-+ use tinytools::ToolTimeout::{Inherit, Millis, Unbounded};+ let set: Arc<Vec<Box<dyn Tool>>> = Arc::new(vec![+ Box::new(RecordingTool {+ saw_context: AtomicBool::new(false),+ }),+ Box::new(ExposedTool("plain", tinytools::ToolExposure::Direct)),+ ]);+ let policy = |name: &str, args: serde_json::Value| {+ CanonicalSharedToolAdapter::for_name(vec![set.clone()], name)+ .expect("registered")+ .timeout_policy(&args)+ };+ assert_eq!(policy("recording", serde_json::json!({})), Unbounded);assert_eq!(- adapter.timeout_policy(&serde_json::json!({})),- tinytools::ToolTimeout::Unbounded+ policy("recording", serde_json::json!({"timeout_secs": 300})),+ Millis(300_000));+ // A tool without its own policy still inherits the configured timeout.assert_eq!(- adapter.timeout_policy(&serde_json::json!({"timeout_secs": 300})),- tinytools::ToolTimeout::Millis(300_000)- );-}--#[test]-fn adapter_for_a_missing_tool_inherits_the_default_timeout() {- let adapter = CanonicalSharedToolAdapter {- sets: Vec::new(),- name: "missing".to_string(),- description: "missing".to_string(),- parameters_schema: serde_json::json!({"type": "object"}),- early_exit: None,- force_deferred: false,- };- assert_eq!(- adapter.timeout_policy(&serde_json::json!({"timeout_secs": 300})),- tinytools::ToolTimeout::Inherit+ policy("plain", serde_json::json!({"timeout_secs": 300})),+ Inherit);}