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
chore: add test module for command exit failure middleware
Steven Enamakel7d4b420e9005
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.rsnew file mode 100644index 0000000000..6bffb71ec4--- /dev/null+++ b/crates/openhuman-core/src/agent/tinyagents/middleware_command_exit_failure_tests.rs@@ -0,0 +1,180 @@+use super::*;++use super::super::repeated_failure::recovery_policy;++/// The tengo DeepSWE task: `git log --oneline | head` exits 141 (SIGPIPE when+/// `head` closes the pipe), and one commit subject is `Update objects.md (#401)`.+fn sigpipe_git_log_report() -> String {+ tinytools::render_command_failure(+ Some(141),+ "ef59933 bench-baseline\n3cad0da calculate compiled size (#456)\n2edd39e Update objects.md (#401)",+ "",+ )+}++fn run_shell(+ mw: &RepeatedToolFailureMiddleware,+ id: &str,+ command: &str,+ mut result: TaToolResult,+) -> impl std::future::Future<Output = ()> + '_ {+ let mut call = TaToolCall::new(id, "shell", json!({ "command": command }));+ let id = id.to_owned();+ async move {+ mw.before_tool(&mut ctx(), &(), &mut call).await.unwrap();+ mw.after_tool(&mut ctx(), &(), &invocation(&id, "shell"), &mut result)+ .await+ .unwrap();+ }+}++#[test]+fn a_command_exit_report_is_program_output_not_a_failure_class() {+ assert_eq!(recovery_policy("shell", &sigpipe_git_log_report(), false), None);+ for stdout in [+ "HTTP/1.1 403 Forbidden",+ "test_login ... Unauthorized",+ "pytest: 3 tests timed out",+ "error: Permission denied (os error 13)",+ ] {+ let report = tinytools::render_command_failure(Some(1), stdout, "");+ assert_eq!(recovery_policy("shell", &report, false), None, "{stdout}");+ }+ // A missing program is still reported with its exit code and hint, which+ // steers the model; it no longer ends the run on the first missing tool.+ let missing = tinytools::render_command_failure(Some(127), "", "bash: jq: command not found");+ assert_eq!(recovery_policy("shell", &missing, false), None);+ let signalled = tinytools::render_command_failure(None, "partial", "");+ assert_eq!(recovery_policy("shell", &signalled, false), None);+}++#[test]+fn tool_layer_shell_failures_are_still_classified() {+ // Worded by the shell tool itself, not a finished command's report.+ assert_eq!(+ recovery_policy("shell", "Command timed out after 60s and was killed", false),+ Some(("uncertain_side_effect", 1))+ );+ assert_eq!(+ recovery_policy("gmail_send", "401 Unauthorized", false),+ Some(("authentication", 0))+ );+}++#[tokio::test]+async fn a_sigpipe_with_401_in_its_output_does_not_halt_the_run() {+ 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());+ run_shell(+ &mw,+ "log-1",+ "git log --oneline | head",+ failing_result("shell", &sigpipe_git_log_report()),+ )+ .await;+ assert_eq!(drain_pause_count(&handle), 0);+ assert!(slot.lock().unwrap().is_none());+}++/// An edit-and-rerun loop reruns the same test command many times. Output+/// that mentions a timeout used to route it to the recoverable ladder, whose+/// identical-repeat count survives successes and halted the run at 8.+#[tokio::test]+async fn rerunning_a_failing_test_between_edits_never_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 report = tinytools::render_command_failure(+ Some(1),+ "FAILED tests/test_consumer.py::test_priority - TimeoutError: timed out",+ "",+ );+ for round in 0..12 {+ run_shell(+ &mw,+ &format!("test-{round}"),+ "python -m pytest tests/test_consumer.py",+ failing_result("shell", &report),+ )+ .await;+ run_shell(+ &mw,+ &format!("edit-{round}"),+ "sed -i 's/a/b/' kombu/consumer.py",+ tool_result("shell", ""),+ )+ .await;+ }+ assert_eq!(drain_pause_count(&handle), 0);+ assert!(slot.lock().unwrap().is_none());+}++/// The same failing command repeated with nothing in between is still a loop,+/// and the generic no-progress ladder still ends it.+#[tokio::test]+async fn an_identical_failing_command_repeated_unchanged_still_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 report = tinytools::render_command_failure(Some(2), "", "make: *** No rule to make target");+ for id in ["make-1", "make-2", "make-3", "make-4"] {+ run_shell(&mw, id, "make build", failing_result("shell", &report)).await;+ }+ assert_eq!(drain_pause_count(&handle), 1);+}++const MODULE_FAULT: &str = "Failed to resolve command runtime: module 'tinyruntime' could not be loaded \+ from the installer bundle: module `ubuntu-22.04-x86_64` refused: module directory is owned by \+ another user. This is terminal for the running process; restart the app to try again";++#[test]+fn a_faulted_module_is_unavailable_not_transient() {+ assert_eq!(+ recovery_policy("web_search_tool", MODULE_FAULT, false),+ Some(("unavailable", 1))+ );+}++#[test]+fn the_module_fault_marker_matches_the_producer_wording() {+ assert!(MODULE_FAULT.contains(crate::tools::status::MODULE_FAULT_MARKER));+}++#[tokio::test]+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 call = TaToolCall::new("search-1", "web_search_tool", json!({ "query": "one" }));+ mw.before_tool(&mut ctx(), &(), &mut call).await.unwrap();+ let mut result = failing_result("web_search_tool", MODULE_FAULT);+ mw.after_tool(+ &mut ctx(),+ &(),+ &invocation("search-1", "web_search_tool"),+ &mut result,+ )+ .await+ .unwrap();+ assert_eq!(drain_pause_count(&handle), 0);+ let nudges = drain_nudge_messages(&mw);+ assert_eq!(nudges.len(), 1, "{nudges:?}");+ assert!(nudges[0].contains("`web_search_tool`"), "{}", nudges[0]);+ 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();+ let mut result = failing_result("web_search_tool", MODULE_FAULT);+ mw.after_tool(+ &mut ctx(),+ &(),+ &invocation("search-2", "web_search_tool"),+ &mut result,+ )+ .await+ .unwrap();+ assert_eq!(drain_pause_count(&handle), 1);+ let summary = slot.lock().unwrap().clone().unwrap();+ assert!(summary.contains("unavailable"), "{summary}");+}