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): remove embedder tool hooks middleware tests
Steven Enamakel8579ec9bf166
diff --git a/crates/openhuman-core/src/agent/tinyagents/middleware_memory_and_hooks_tests.rs b/crates/openhuman-core/src/agent/tinyagents/middleware_memory_and_hooks_tests.rsdeleted file mode 100644index 39bfa5e303..0000000000--- a/crates/openhuman-core/src/agent/tinyagents/middleware_memory_and_hooks_tests.rs+++ /dev/null@@ -1,184 +0,0 @@-use super::*;-use crate::agent::tinyagents::middleware::embedder_hooks::EmbedderToolHooksMiddleware;--#[tokio::test]-async fn embedder_tool_hooks_post_use_replays_the_normalized_pre_call_arguments() {- let pre = std::sync::Arc::new(std::sync::Mutex::new(Vec::new()));- let post = std::sync::Arc::new(std::sync::Mutex::new(Vec::new()));- let mw = embedder_hook_mw(pre.clone(), post.clone(), false);-- let mut call = TaToolCall {- id: "call-1".into(),- name: "lookup".into(),- arguments: json!({"id": 42}),- invalid: None,- };- mw.before_tool(&mut ctx(), &(), &mut call).await.unwrap();-- let mut result = TaToolResult::success("found");- mw.after_tool(- &mut ctx(),- &(),- &invocation("call-1", "lookup"),- &mut result,- )- .await- .unwrap();-- assert_eq!(pre.lock().unwrap().len(), 1, "one pre-use notification");- let post = post.lock().unwrap();- assert_eq!(post.len(), 1, "one post-use notification");- let (tool, arguments, success, duration) = &post[0];- assert_eq!(tool, "lookup");- assert_eq!(- *arguments,- json!({"id": 42}),- "post-use context must preserve the normalized pre-call arguments, not Null"- );- assert_eq!(*success, Some(true));- assert_eq!(- *duration, None,- "canonical ToolResult carries no elapsed field"- );-}--#[tokio::test]-async fn embedder_tool_hooks_veto_denies_the_call_and_skips_post_use() {- let pre = std::sync::Arc::new(std::sync::Mutex::new(Vec::new()));- let post = std::sync::Arc::new(std::sync::Mutex::new(Vec::new()));- let mw = embedder_hook_mw(pre.clone(), post.clone(), true);-- let mut call = TaToolCall {- id: "call-2".into(),- name: "rm".into(),- arguments: json!({"path": "/"}),- invalid: None,- };- let error = mw- .before_tool(&mut ctx(), &(), &mut call)- .await- .unwrap_err();- assert!(- error.to_string().contains("vetoed"),- "veto must surface as a tool error: {error}"- );- // The call was vetoed — no post-use event, and no cache entry leaks.- assert_eq!(pre.lock().unwrap().len(), 1, "pre-use hook still observed");- assert!(- post.lock().unwrap().is_empty(),- "no post-use for a vetoed call"- );- assert!(- mw.arguments_by_call_id.lock().unwrap().is_empty(),- "a vetoed call must not leave a cached argument entry"- );-}--#[tokio::test]-async fn embedder_tool_hooks_post_use_without_pre_call_falls_back_to_null() {- let pre = std::sync::Arc::new(std::sync::Mutex::new(Vec::new()));- let post = std::sync::Arc::new(std::sync::Mutex::new(Vec::new()));- let mw = embedder_hook_mw(pre.clone(), post.clone(), false);-- // A result with no matching `before_tool` (defensive path) must not panic- // and falls back to `Null`, the pre-fix behaviour.- let mut result = TaToolResult::success("found");- mw.after_tool(- &mut ctx(),- &(),- &invocation("orphan", "lookup"),- &mut result,- )- .await- .unwrap();- let post = post.lock().unwrap();- assert_eq!(post.len(), 1);- assert_eq!(post[0].1, serde_json::Value::Null);- assert_eq!(post[0].2, Some(true));-}--fn nested_call(name: &str) -> TaToolCall {- TaToolCall {- id: "parent/1".into(),- name: name.into(),- arguments: json!({"path": "/"}),- invalid: None,- }-}--/// A hook whose pre-tool decision is fixed, to exercise every arm.-struct FixedDecisionHook(tinyagents_hooks::tool::ToolHookDecision);--#[async_trait]-impl tinyagents_hooks::tool::ToolHook for FixedDecisionHook {- fn name(&self) -> &str {- "fixed"- }- async fn before_tool(- &self,- _context: &tinyagents_hooks::tool::ToolHookContext,- ) -> anyhow::Result<()> {- Ok(())- }- async fn after_tool(- &self,- _context: &tinyagents_hooks::tool::ToolHookContext,- ) -> anyhow::Result<()> {- Ok(())- }- async fn before_tool_decision(- &self,- _context: &tinyagents_hooks::tool::ToolHookContext,- ) -> tinyagents_hooks::tool::ToolHookDecision {- self.0.clone()- }-}--#[tokio::test]-async fn embedder_tool_hooks_nested_call_is_admitted_when_hooks_proceed() {- let pre = std::sync::Arc::new(std::sync::Mutex::new(Vec::new()));- let post = std::sync::Arc::new(std::sync::Mutex::new(Vec::new()));- let mw = embedder_hook_mw(pre.clone(), post, false);- mw.check_nested_tool(&ctx(), &(), &nested_call("lookup"))- .await- .unwrap();- assert_eq!(- pre.lock().unwrap().len(),- 1,- "hook consulted for nested call"- );- assert!(- mw.arguments_by_call_id.lock().unwrap().is_empty(),- "a nested check caches nothing"- );-}--#[tokio::test]-async fn embedder_tool_hooks_nested_call_honours_a_veto() {- let pre = std::sync::Arc::new(std::sync::Mutex::new(Vec::new()));- let post = std::sync::Arc::new(std::sync::Mutex::new(Vec::new()));- let mw = embedder_hook_mw(pre, post, true);- let error = mw- .check_nested_tool(&ctx(), &(), &nested_call("rm"))- .await- .unwrap_err();- assert!(error.to_string().contains("vetoed"), "{error}");-}--#[tokio::test]-async fn embedder_tool_hooks_nested_call_refuses_ask_and_rewrite() {- use tinyagents_hooks::tool::ToolHookDecision;- for decision in [- ToolHookDecision::Ask("confirm".into()),- ToolHookDecision::ProceedWith(json!({"path": "."})),- ] {- let mw = EmbedderToolHooksMiddleware::new(vec![std::sync::Arc::new(FixedDecisionHook(- decision,- ))]);- let error = mw- .check_nested_tool(&ctx(), &(), &nested_call("write"))- .await- .unwrap_err();- assert!(error.to_string().contains("refused nested call"), "{error}");- }-}diff --git a/crates/openhuman-core/src/agent/tinyagents/middleware_tests.rs b/crates/openhuman-core/src/agent/tinyagents/middleware_tests.rsindex b020cdd406..c2456e794f 100644--- a/crates/openhuman-core/src/agent/tinyagents/middleware_tests.rs+++ b/crates/openhuman-core/src/agent/tinyagents/middleware_tests.rs@@ -3,7 +3,6 @@ use super::repeated_failure::{is_body_level_failure, user_actionable_escalation}use super::tool_output::{COMPACTION_EXEMPT_TOOLS, SAMPLING_TOOLS, is_compaction_exempt, is_truncation_exempt,};-use crate::agent::tinyagents::middleware::embedder_hooks::EmbedderToolHooksMiddleware;use crate::agent::tinyagents::middleware::repeated_failure::RepeatedToolFailureMiddleware;use crate::agent::tinyagents::middleware::tool_outcome_capture::ToolOutcomeCaptureMiddleware;use crate::agent::tinyagents::middleware::tool_output::ToolOutputMiddleware;@@ -338,65 +337,6 @@ fn body_failure_result(name: &str, extra: serde_json::Value) -> TaToolResult {tool_result(name, &serde_json::to_string_pretty(&body).unwrap())}-// ── EmbedderToolHooksMiddleware ──────────────────────────────────────────--/// One recorded post-tool notification: tool name, args, success flag, duration.-type PostToolRecord = (String, serde_json::Value, Option<bool>, Option<u64>);--/// Records lifecycle notifications for a test hook, optionally vetoing every-/// pre-tool call so the veto path can be exercised.-struct RecordingToolHook {- name: &'static str,- pre: std::sync::Arc<std::sync::Mutex<Vec<(String, serde_json::Value)>>>,- post: std::sync::Arc<std::sync::Mutex<Vec<PostToolRecord>>>,- veto: bool,-}--#[async_trait]-impl tinyagents_hooks::tool::ToolHook for RecordingToolHook {- fn name(&self) -> &str {- self.name- }- async fn before_tool(- &self,- context: &tinyagents_hooks::tool::ToolHookContext,- ) -> anyhow::Result<()> {- self.pre- .lock()- .unwrap()- .push((context.tool_name.clone(), context.arguments.clone()));- if self.veto {- anyhow::bail!("vetoed by test hook");- }- Ok(())- }- async fn after_tool(- &self,- context: &tinyagents_hooks::tool::ToolHookContext,- ) -> anyhow::Result<()> {- self.post.lock().unwrap().push((- context.tool_name.clone(),- context.arguments.clone(),- context.success,- context.duration_ms,- ));- Ok(())- }-}--fn embedder_hook_mw(- pre: std::sync::Arc<std::sync::Mutex<Vec<(String, serde_json::Value)>>>,- post: std::sync::Arc<std::sync::Mutex<Vec<PostToolRecord>>>,- veto: bool,-) -> EmbedderToolHooksMiddleware {- EmbedderToolHooksMiddleware::new(vec![std::sync::Arc::new(RecordingToolHook {- name: "recording",- pre,- post,- veto,- })])-}-#[path = "middleware_approval_guard_tests.rs"]mod approval_guard_tests;#[path = "middleware_classified_failure_fetch_tests.rs"]@@ -416,8 +356,6 @@ mod memory_budget_tests;#[path = "middleware_stop_cause_tests.rs"]mod stop_cause_tests;-#[path = "middleware_memory_and_hooks_tests.rs"]-mod memory_and_hooks_tests;#[path = "middleware_tool_output_artifact_tests.rs"]mod tool_output_artifact_tests;#[path = "middleware_tool_output_tests.rs"]