Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

test(desktop): cover tool argument and continuation failures

Steven Enamakela9ea02a0730c
diff --git a/crates/openhuman-core/src/desktop/control/tools_tests.rs b/crates/openhuman-core/src/desktop/control/tools_tests.rs
index 183a02a707..aae748d3d2 100644
--- a/crates/openhuman-core/src/desktop/control/tools_tests.rs
+++ b/crates/openhuman-core/src/desktop/control/tools_tests.rs
@@ -1,4 +1,19 @@
use super::*;
+use tinydesktop_bus::DesktopError;
+
+#[test]
+fn desktop_arguments_reject_missing_or_blank_required_values() {
+ assert_eq!(
+ required(&json!({"app":" TextEdit "}), "app").unwrap(),
+ "TextEdit"
+ );
+ for args in [json!({}), json!({"app":" "}), json!({"app":42})] {
+ assert!(required(&args, "app")
+ .unwrap_err()
+ .to_string()
+ .contains("missing required parameter: app"));
+ }
+}
#[tokio::test]
async fn deferred_tool_is_discoverable_but_fails_closed_when_disabled() {
@@ -24,6 +39,22 @@ fn launch_tool_cannot_accept_process_arguments_or_environment() {
assert!(schema["properties"].get("cdp_port").is_none());
}
+#[test]
+fn raw_ref_action_requires_a_snapshot_ref_and_declares_a_write_effect() {
+ let tool = DesktopTool::new(Arc::new(Config::default()), DesktopToolKind::Act);
+ let schema = tool.parameters_schema();
+ assert_eq!(tool.name(), "desktop_act");
+ assert_eq!(tool.permission_level(), PermissionLevel::Write);
+ assert!(tool.external_effect());
+ assert_eq!(schema["required"], json!(["operation", "ref_id"]));
+ assert_eq!(
+ schema["properties"]["operation"]["enum"],
+ json!(["click", "focus", "type", "check", "uncheck", "expand", "collapse"])
+ );
+ assert!(schema["properties"].get("args").is_none());
+ assert!(schema["properties"].get("env").is_none());
+}
+
#[test]
fn goal_and_continuation_have_distinct_required_inputs() {
let config = Arc::new(Config::default());
@@ -90,6 +121,25 @@ async fn approvals_on_returns_pending_without_self_approval() {
assert_eq!(result.data.unwrap()["confirmation_id"], "once");
}
+#[tokio::test]
+async fn a_missing_confirmation_handle_never_triggers_an_action() {
+ let malformed = DesktopResponse::ok("run-goal", json!({"stop":"confirmation_required"}));
+ let error = advance_goal_confirmations(malformed, false, |_id, _approve| async {
+ panic!("a missing handle must not reach the desktop module")
+ })
+ .await
+ .unwrap_err();
+ assert!(error.contains("without a continuation handle"));
+
+ let failure = DesktopResponse::err("run-goal", DesktopError::new("PERM_DENIED", "denied"));
+ let returned = advance_goal_confirmations(failure.clone(), false, |_id, _approve| async {
+ panic!("a failed goal must not be continued")
+ })
+ .await
+ .unwrap();
+ assert_eq!(returned, failure);
+}
+
#[tokio::test]
async fn continuation_ceiling_returns_cancelled_result_with_all_executed_turns() {
let calls = Arc::new(std::sync::atomic::AtomicUsize::new(0));
@@ -135,3 +185,48 @@ async fn continuation_ceiling_returns_cancelled_result_with_all_executed_turns()
assert_eq!(data["turns"].as_array().unwrap().len(), 8);
assert_eq!(data["metrics"]["calls"], 8);
}
+
+#[tokio::test]
+async fn continuation_ceiling_reports_uncertain_cancellation_delivery() {
+ let initial = DesktopResponse::ok(
+ "run-goal",
+ json!({"stop":"confirmation_required", "confirmation_id":"once", "turns":[]}),
+ );
+ let result = advance_goal_confirmations(initial, false, |_id, approve| async move {
+ if approve {
+ Ok(DesktopResponse::ok(
+ "run-goal",
+ json!({"stop":"confirmation_required", "confirmation_id":"once", "turns":[null]}),
+ ))
+ } else {
+ Err("connection lost".to_owned())
+ }
+ })
+ .await;
+ let error = result.unwrap_err();
+ assert!(error.contains("continuation limit"));
+ assert!(error.contains("cancellation delivery is uncertain: connection lost"));
+}
+
+#[tokio::test]
+async fn continuation_ceiling_rejects_a_module_that_refuses_cancellation() {
+ let initial = DesktopResponse::ok(
+ "run-goal",
+ json!({"stop":"confirmation_required", "confirmation_id":"once"}),
+ );
+ let result = advance_goal_confirmations(initial, false, |_id, approve| async move {
+ if approve {
+ Ok(DesktopResponse::ok(
+ "run-goal",
+ json!({"stop":"confirmation_required", "confirmation_id":"once"}),
+ ))
+ } else {
+ Ok(DesktopResponse::err(
+ "run-goal",
+ DesktopError::new("CANCEL_FAILED", "not cancelled"),
+ ))
+ }
+ })
+ .await;
+ assert!(result.unwrap_err().contains("module refused cancellation"));
+}