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(desktop): follow Rust test layout
Steven Enamakel14ae14998bde
diff --git a/crates/openhuman-core/src/agent/tinyagents/middleware_approval_guard_tests.rs b/crates/openhuman-core/src/agent/tinyagents/middleware_approval_guard_tests.rsnew file mode 100644index 0000000000..35577245c8--- /dev/null+++ b/crates/openhuman-core/src/agent/tinyagents/middleware_approval_guard_tests.rs@@ -0,0 +1,100 @@+use super::*;++// ── ApprovalSecurityMiddleware ──────────────────────────────────────────++#[test]+fn approval_external_effect_resolution_walks_the_tool_sets() {+ let tools: Arc<Vec<Box<dyn Tool>>> = Arc::new(vec![+ Box::new(FakeTool {+ name: "send_email",+ cap: None,+ external: true,+ }),+ Box::new(FakeTool {+ name: "read_file",+ cap: None,+ external: false,+ }),+ ]);+ let mw = ApprovalSecurityMiddleware::new(vec![tools]);+ assert!(mw.has_external_effect("send_email", &json!({})));+ assert!(!mw.has_external_effect("read_file", &json!({})));+ // Unknown tool defaults to no external effect (nothing to gate).+ assert!(!mw.has_external_effect("missing", &json!({})));+}++#[test]+fn desktop_external_effect_keeps_metadata_but_skips_approval_when_disabled() {+ std::thread::Builder::new()+ .stack_size(16 * 1024 * 1024)+ .spawn(|| {+ tokio::runtime::Builder::new_current_thread()+ .enable_all()+ .build()+ .unwrap()+ .block_on(desktop_external_effect_inner());+ })+ .unwrap()+ .join()+ .unwrap();+}++async fn desktop_external_effect_inner() {+ let _guard = crate::config::TEST_ENV_LOCK.lock().unwrap();+ let previous = std::env::var_os("OPENHUMAN_WORKSPACE");+ let temp = tempfile::tempdir().unwrap();+ std::fs::write(+ temp.path().join("config.toml"),+ "[desktop]\napprovals_enabled = false\n",+ )+ .unwrap();+ unsafe {+ std::env::set_var("OPENHUMAN_WORKSPACE", temp.path());+ }+ let tools: Arc<Vec<Box<dyn Tool>>> = Arc::new(vec![+ Box::new(crate::desktop::control::tools::DesktopTool::new(+ Arc::new(crate::config::Config::default()),+ crate::desktop::control::tools::DesktopToolKind::Goal,+ )),+ Box::new(FakeTool {+ name: "send_email",+ cap: None,+ external: true,+ }),+ ]);+ let middleware = ApprovalSecurityMiddleware::new(vec![tools]);+ assert!(middleware.has_external_effect("desktop_goal", &json!({})));+ assert!(+ !middleware+ .requires_approval("desktop_goal", &json!({}))+ .await+ );+ assert!(middleware.requires_approval("send_email", &json!({})).await);+ match previous {+ Some(value) => unsafe { std::env::set_var("OPENHUMAN_WORKSPACE", value) },+ None => unsafe { std::env::remove_var("OPENHUMAN_WORKSPACE") },+ }+}++#[test]+fn approval_identity_scopes_composio_dispatcher_grants_to_one_action() {+ assert_eq!(+ approval_tool_name(+ "composio_execute",+ &json!({ "tool": " GMAIL_SEND_EMAIL " })+ ),+ "composio_execute:GMAIL_SEND_EMAIL"+ );+ assert_eq!(+ approval_tool_name("composio_execute", &json!({ "tool": "GMAIL_DELETE_EMAIL" })),+ "composio_execute:GMAIL_DELETE_EMAIL"+ );+ assert_eq!(+ approval_tool_name("composio_execute", &json!({})),+ "composio_execute:<invalid-action>"+ );+ assert_eq!(+ approval_tool_name("send_email", &json!({ "tool": "ignored" })),+ "send_email"+ );+}diff --git a/crates/openhuman-core/src/agent/tinyagents/middleware_loop_guard_tests.rs b/crates/openhuman-core/src/agent/tinyagents/middleware_loop_guard_tests.rsindex fedaedc158..685b8249f5 100644--- a/crates/openhuman-core/src/agent/tinyagents/middleware_loop_guard_tests.rs+++ b/crates/openhuman-core/src/agent/tinyagents/middleware_loop_guard_tests.rs@@ -593,105 +593,6 @@ async fn successful_repeat_tracker_resets_failed_and_exempt_batches() {);}-// ── ApprovalSecurityMiddleware ──────────────────────────────────────────--#[test]-fn approval_external_effect_resolution_walks_the_tool_sets() {- let tools: Arc<Vec<Box<dyn Tool>>> = Arc::new(vec![- Box::new(FakeTool {- name: "send_email",- cap: None,- external: true,- }),- Box::new(FakeTool {- name: "read_file",- cap: None,- external: false,- }),- ]);- let mw = ApprovalSecurityMiddleware::new(vec![tools]);- assert!(mw.has_external_effect("send_email", &json!({})));- assert!(!mw.has_external_effect("read_file", &json!({})));- // Unknown tool defaults to no external effect (nothing to gate).- assert!(!mw.has_external_effect("missing", &json!({})));-}--#[test]-fn desktop_external_effect_keeps_metadata_but_skips_approval_when_disabled() {- std::thread::Builder::new()- .stack_size(16 * 1024 * 1024)- .spawn(|| {- tokio::runtime::Builder::new_current_thread()- .enable_all()- .build()- .unwrap()- .block_on(desktop_external_effect_inner());- })- .unwrap()- .join()- .unwrap();-}--async fn desktop_external_effect_inner() {- let _guard = crate::config::TEST_ENV_LOCK.lock().unwrap();- let previous = std::env::var_os("OPENHUMAN_WORKSPACE");- let temp = tempfile::tempdir().unwrap();- std::fs::write(- temp.path().join("config.toml"),- "[desktop]\napprovals_enabled = false\n",- )- .unwrap();- unsafe {- std::env::set_var("OPENHUMAN_WORKSPACE", temp.path());- }- let tools: Arc<Vec<Box<dyn Tool>>> = Arc::new(vec![- Box::new(crate::desktop::control::tools::DesktopTool::new(- Arc::new(crate::config::Config::default()),- crate::desktop::control::tools::DesktopToolKind::Goal,- )),- Box::new(FakeTool {- name: "send_email",- cap: None,- external: true,- }),- ]);- let middleware = ApprovalSecurityMiddleware::new(vec![tools]);- assert!(middleware.has_external_effect("desktop_goal", &json!({})));- assert!(- !middleware- .requires_approval("desktop_goal", &json!({}))- .await- );- assert!(middleware.requires_approval("send_email", &json!({})).await);- match previous {- Some(value) => unsafe { std::env::set_var("OPENHUMAN_WORKSPACE", value) },- None => unsafe { std::env::remove_var("OPENHUMAN_WORKSPACE") },- }-}--#[test]-fn approval_identity_scopes_composio_dispatcher_grants_to_one_action() {- assert_eq!(- approval_tool_name(- "composio_execute",- &json!({ "tool": " GMAIL_SEND_EMAIL " })- ),- "composio_execute:GMAIL_SEND_EMAIL"- );- assert_eq!(- approval_tool_name("composio_execute", &json!({ "tool": "GMAIL_DELETE_EMAIL" })),- "composio_execute:GMAIL_DELETE_EMAIL"- );- assert_eq!(- approval_tool_name("composio_execute", &json!({})),- "composio_execute:<invalid-action>"- );- assert_eq!(- approval_tool_name("send_email", &json!({ "tool": "ignored" })),- "send_email"- );-}-#[tokio::test]async fn memory_write_without_index_read_gets_a_corrective_note() {let mw = MemoryProtocolMiddleware::new();diff --git a/crates/openhuman-core/src/agent/tinyagents/middleware_tests.rs b/crates/openhuman-core/src/agent/tinyagents/middleware_tests.rsindex 04292b6619..71c8aa8aa4 100644--- a/crates/openhuman-core/src/agent/tinyagents/middleware_tests.rs+++ b/crates/openhuman-core/src/agent/tinyagents/middleware_tests.rs@@ -478,6 +478,8 @@ fn embedder_hook_mw(})])}+#[path = "middleware_approval_guard_tests.rs"]+mod approval_guard_tests;#[path = "middleware_loop_guard_tests.rs"]mod loop_guard_tests;#[path = "middleware_repeat_progress_tests.rs"]diff --git a/crates/openhuman-core/src/config/schema/desktop.rs b/crates/openhuman-core/src/config/schema/desktop.rsindex af9e0f534e..ff95803c71 100644--- a/crates/openhuman-core/src/config/schema/desktop.rs+++ b/crates/openhuman-core/src/config/schema/desktop.rs@@ -14,13 +14,5 @@ pub struct DesktopConfig {}#[cfg(test)]-mod tests {- use super::*;-- #[test]- fn approvals_are_off_by_default_and_can_be_opted_in() {- assert!(!DesktopConfig::default().approvals_enabled);- let enabled: DesktopConfig = toml::from_str("approvals_enabled = true").unwrap();- assert!(enabled.approvals_enabled);- }-}+#[path = "desktop_tests.rs"]+mod tests;diff --git a/crates/openhuman-core/src/config/schema/desktop_tests.rs b/crates/openhuman-core/src/config/schema/desktop_tests.rsnew file mode 100644index 0000000000..3363c6bc28--- /dev/null+++ b/crates/openhuman-core/src/config/schema/desktop_tests.rs@@ -0,0 +1,8 @@+use super::*;++#[test]+fn approvals_are_off_by_default_and_can_be_opted_in() {+ assert!(!DesktopConfig::default().approvals_enabled);+ let enabled: DesktopConfig = toml::from_str("approvals_enabled = true").unwrap();+ assert!(enabled.approvals_enabled);+}diff --git a/crates/openhuman-core/src/desktop/control/confirmation.rs b/crates/openhuman-core/src/desktop/control/confirmation.rsindex 75dfabcac2..9e2aa89bdf 100644--- a/crates/openhuman-core/src/desktop/control/confirmation.rs+++ b/crates/openhuman-core/src/desktop/control/confirmation.rs@@ -211,53 +211,5 @@ pub(super) fn take_approved(id: &str) -> Result<(String, String), String> {}#[cfg(test)]-mod tests {- use super::*;-- #[tokio::test]- async fn confirmation_requires_trusted_one_use_decision_for_same_goal() {- super::super::ops::set_listener_is_loopback(true);- let id = uuid::Uuid::new_v4().to_string();- record(- "TextEdit",- "make a note",- &json!({- "stop":"confirmation_required", "confirmation_id":id,- "pending":{"operation":"CLICK", "reason":"May save a file",- "target":{"ref_id":"@s1:e2", "name":"Save", "role":"button"}}- }),- );- assert!(take_approved(&id).is_err());- let listed = pending();- let item = listed- .iter()- .find(|item| item.confirmation_id == id)- .unwrap();- assert_eq!(item.operation, "CLICK");- assert_eq!(item.target_name.as_deref(), Some("Save"));- assert_eq!(item.action_summary, "CLICK button 'Save' in TextEdit");- let config = Config::default();- let approved = confirm(&config, &id, true).await.unwrap();- assert_eq!(approved["approve"], true);- assert_eq!(- take_approved(&id).unwrap(),- ("TextEdit".to_owned(), "make a note".to_owned())- );- assert!(take_approved(&id).is_err());- }-- #[test]- fn unnamed_target_cannot_be_approved() {- super::super::ops::set_listener_is_loopback(true);- let id = uuid::Uuid::new_v4().to_string();- record(- "TextEdit",- "test",- &json!({- "stop":"confirmation_required", "confirmation_id":id,- "pending":{"operation":"CLICK", "target":{"ref_id":"@s1:e2", "role":"button"}}- }),- );- assert!(!pending().iter().any(|item| item.confirmation_id == id));- }-}+#[path = "confirmation_tests.rs"]+mod tests;diff --git a/crates/openhuman-core/src/desktop/control/confirmation_tests.rs b/crates/openhuman-core/src/desktop/control/confirmation_tests.rsnew file mode 100644index 0000000000..21b2f03e60--- /dev/null+++ b/crates/openhuman-core/src/desktop/control/confirmation_tests.rs@@ -0,0 +1,48 @@+use super::*;++#[tokio::test]+async fn confirmation_requires_trusted_one_use_decision_for_same_goal() {+ super::super::ops::set_listener_is_loopback(true);+ let id = uuid::Uuid::new_v4().to_string();+ record(+ "TextEdit",+ "make a note",+ &json!({+ "stop":"confirmation_required", "confirmation_id":id,+ "pending":{"operation":"CLICK", "reason":"May save a file",+ "target":{"ref_id":"@s1:e2", "name":"Save", "role":"button"}}+ }),+ );+ assert!(take_approved(&id).is_err());+ let listed = pending();+ let item = listed+ .iter()+ .find(|item| item.confirmation_id == id)+ .unwrap();+ assert_eq!(item.operation, "CLICK");+ assert_eq!(item.target_name.as_deref(), Some("Save"));+ assert_eq!(item.action_summary, "CLICK button 'Save' in TextEdit");+ let config = Config::default();+ let approved = confirm(&config, &id, true).await.unwrap();+ assert_eq!(approved["approve"], true);+ assert_eq!(+ take_approved(&id).unwrap(),+ ("TextEdit".to_owned(), "make a note".to_owned())+ );+ assert!(take_approved(&id).is_err());+}++#[test]+fn unnamed_target_cannot_be_approved() {+ super::super::ops::set_listener_is_loopback(true);+ let id = uuid::Uuid::new_v4().to_string();+ record(+ "TextEdit",+ "test",+ &json!({+ "stop":"confirmation_required", "confirmation_id":id,+ "pending":{"operation":"CLICK", "target":{"ref_id":"@s1:e2", "role":"button"}}+ }),+ );+ assert!(!pending().iter().any(|item| item.confirmation_id == id));+}diff --git a/crates/openhuman-core/src/desktop/control/ops.rs b/crates/openhuman-core/src/desktop/control/ops.rsindex d9c35598a8..56f032882d 100644--- a/crates/openhuman-core/src/desktop/control/ops.rs+++ b/crates/openhuman-core/src/desktop/control/ops.rs@@ -272,39 +272,5 @@ pub async fn probe(config: &Config) -> DesktopProbe {}#[cfg(test)]-mod tests {- use super::*;-- #[test]- fn disabled_by_default_and_persists() {- let dir = tempfile::tempdir().unwrap();- let mut config = Config::default();- config.workspace_dir = dir.path().to_path_buf();- assert!(!enabled(&config));- save(&config, true).unwrap();- assert!(enabled(&config));- save(&config, false).unwrap();- assert!(!enabled(&config));- }-- #[test]- fn permission_states_are_normalized() {- let data = serde_json::json!({"accessibility":{"state":"granted"},- "screen_recording":{"state":"weird"}});- assert_eq!(permission(&data, "accessibility"), "granted");- assert_eq!(permission(&data, "screen_recording"), "unknown");- }-- #[test]- fn approval_bypass_requires_a_registered_desktop_tool_and_disabled_setting() {- use super::super::tools::{DesktopTool, DesktopToolKind};- let mut config = Config::default();- let goal = DesktopTool::new(std::sync::Arc::new(config.clone()), DesktopToolKind::Goal);- let raw_action =- DesktopTool::new(std::sync::Arc::new(config.clone()), DesktopToolKind::Act);- assert!(approval_bypass_decision(&config, &goal));- assert!(!approval_bypass_decision(&config, &raw_action));- config.desktop.approvals_enabled = true;- assert!(!approval_bypass_decision(&config, &goal));- }-}+#[path = "ops_tests.rs"]+mod tests;diff --git a/crates/openhuman-core/src/desktop/control/ops_tests.rs b/crates/openhuman-core/src/desktop/control/ops_tests.rsnew file mode 100644index 0000000000..36f8858776--- /dev/null+++ b/crates/openhuman-core/src/desktop/control/ops_tests.rs@@ -0,0 +1,33 @@+use super::*;++#[test]+fn disabled_by_default_and_persists() {+ let dir = tempfile::tempdir().unwrap();+ let mut config = Config::default();+ config.workspace_dir = dir.path().to_path_buf();+ assert!(!enabled(&config));+ save(&config, true).unwrap();+ assert!(enabled(&config));+ save(&config, false).unwrap();+ assert!(!enabled(&config));+}++#[test]+fn permission_states_are_normalized() {+ let data = serde_json::json!({"accessibility":{"state":"granted"},+ "screen_recording":{"state":"weird"}});+ assert_eq!(permission(&data, "accessibility"), "granted");+ assert_eq!(permission(&data, "screen_recording"), "unknown");+}++#[test]+fn approval_bypass_requires_a_registered_desktop_tool_and_disabled_setting() {+ use super::super::tools::{DesktopTool, DesktopToolKind};+ let mut config = Config::default();+ let goal = DesktopTool::new(std::sync::Arc::new(config.clone()), DesktopToolKind::Goal);+ let raw_action = DesktopTool::new(std::sync::Arc::new(config.clone()), DesktopToolKind::Act);+ assert!(approval_bypass_decision(&config, &goal));+ assert!(!approval_bypass_decision(&config, &raw_action));+ config.desktop.approvals_enabled = true;+ assert!(!approval_bypass_decision(&config, &goal));+}diff --git a/crates/openhuman-core/src/desktop/control/tools.rs b/crates/openhuman-core/src/desktop/control/tools.rsindex 77f5a788ff..ec51023f64 100644--- a/crates/openhuman-core/src/desktop/control/tools.rs+++ b/crates/openhuman-core/src/desktop/control/tools.rs@@ -397,142 +397,5 @@ impl Tool for DesktopTool {}#[cfg(test)]-mod tests {- use super::*;-- #[tokio::test]- async fn deferred_tool_is_discoverable_but_fails_closed_when_disabled() {- let dir = tempfile::tempdir().unwrap();- let mut config = Config::default();- config.workspace_dir = dir.path().to_path_buf();- let tool = DesktopTool::new(Arc::new(config), DesktopToolKind::Apps);- assert_eq!(tool.exposure(), ToolExposure::Deferred);- let result = tool.execute(json!({})).await.unwrap();- assert!(result.output().contains("disabled in Connections"));- }-- #[test]- fn launch_tool_cannot_accept_process_arguments_or_environment() {- let tool = DesktopTool::new(Arc::new(Config::default()), DesktopToolKind::Launch);- let schema = tool.parameters_schema();- assert_eq!(tool.exposure(), ToolExposure::Deferred);- assert_eq!(tool.permission_level(), PermissionLevel::Write);- assert!(tool.external_effect());- assert_eq!(schema["required"], json!(["app"]));- assert!(schema["properties"].get("args").is_none());- assert!(schema["properties"].get("env").is_none());- assert!(schema["properties"].get("cdp_port").is_none());- }-- #[test]- fn goal_and_continuation_have_distinct_required_inputs() {- let config = Arc::new(Config::default());- let goal = DesktopTool::new(config.clone(), DesktopToolKind::Goal);- let continuation = DesktopTool::new(config, DesktopToolKind::ContinueGoal);- assert_eq!(goal.parameters_schema()["required"], json!(["app", "goal"]));- assert!(goal.parameters_schema()["properties"]- .get("confirmation_id")- .is_none());- assert_eq!(- continuation.parameters_schema()["required"],- json!(["confirmation_id"])- );- assert!(continuation.parameters_schema()["properties"]- .get("approve")- .is_none());- assert!(super::super::confirmation::take_approved("unknown").is_err());- }-- #[tokio::test]- async fn approvals_off_continues_one_use_handle_and_reports_module_result() {- assert!(!Config::default().desktop.approvals_enabled);- let called = Arc::new(std::sync::atomic::AtomicUsize::new(0));- let observed = Arc::clone(&called);- let initial = DesktopResponse::ok(- "run-goal",- json!({- "stop":"confirmation_required", "confirmation_id":"once"- }),- );- let result = advance_goal_confirmations(initial, false, move |id, approve| {- let observed = Arc::clone(&observed);- async move {- assert_eq!(id, "once");- assert!(approve);- observed.fetch_add(1, std::sync::atomic::Ordering::SeqCst);- Ok(DesktopResponse::ok(- "run-goal",- json!({- "stop":"stale_target", "turns":[], "metrics":{"calls":1}- }),- ))- }- })- .await- .unwrap();- assert_eq!(called.load(std::sync::atomic::Ordering::SeqCst), 1);- assert_eq!(result.data.unwrap()["stop"], "stale_target");- }-- #[tokio::test]- async fn approvals_on_returns_pending_without_self_approval() {- let initial = DesktopResponse::ok(- "run-goal",- json!({- "stop":"confirmation_required", "confirmation_id":"once"- }),- );- let result = advance_goal_confirmations(initial, true, |_id, _approve| async {- panic!("manual approval mode must never auto-continue")- })- .await- .unwrap();- assert_eq!(result.data.unwrap()["confirmation_id"], "once");- }-- #[tokio::test]- async fn continuation_ceiling_returns_cancelled_result_with_all_executed_turns() {- let calls = Arc::new(std::sync::atomic::AtomicUsize::new(0));- let seen = Arc::clone(&calls);- let initial = DesktopResponse::ok(- "run-goal",- json!({- "stop":"confirmation_required", "confirmation_id":"id-0", "turns":[]- }),- );- let result = advance_goal_confirmations(initial, false, move |id, approve| {- let seen = Arc::clone(&seen);- async move {- let index = seen.fetch_add(1, std::sync::atomic::Ordering::SeqCst);- assert_eq!(id, format!("id-{index}"));- if approve {- Ok(DesktopResponse::ok(- "run-goal",- json!({- "stop":"confirmation_required",- "confirmation_id":format!("id-{}", index + 1),- "turns":vec![Value::Null; index + 1],- "metrics":{"calls":index + 1}- }),- ))- } else {- assert_eq!(index, 8);- Ok(DesktopResponse::ok(- "run-goal",- json!({- "stop":"cancelled", "turns":vec![Value::Null; 8],- "metrics":{"calls":8}- }),- ))- }- }- })- .await- .unwrap();- assert_eq!(calls.load(std::sync::atomic::Ordering::SeqCst), 9);- let data = result.data.unwrap();- assert_eq!(data["stop"], "cancelled");- assert_eq!(data["turns"].as_array().unwrap().len(), 8);- assert_eq!(data["metrics"]["calls"], 8);- }-}+#[path = "tools_tests.rs"]+mod tests;diff --git a/crates/openhuman-core/src/desktop/control/tools_tests.rs b/crates/openhuman-core/src/desktop/control/tools_tests.rsnew file mode 100644index 0000000000..68264e2496--- /dev/null+++ b/crates/openhuman-core/src/desktop/control/tools_tests.rs@@ -0,0 +1,137 @@+use super::*;++#[tokio::test]+async fn deferred_tool_is_discoverable_but_fails_closed_when_disabled() {+ let dir = tempfile::tempdir().unwrap();+ let mut config = Config::default();+ config.workspace_dir = dir.path().to_path_buf();+ let tool = DesktopTool::new(Arc::new(config), DesktopToolKind::Apps);+ assert_eq!(tool.exposure(), ToolExposure::Deferred);+ let result = tool.execute(json!({})).await.unwrap();+ assert!(result.output().contains("disabled in Connections"));+}++#[test]+fn launch_tool_cannot_accept_process_arguments_or_environment() {+ let tool = DesktopTool::new(Arc::new(Config::default()), DesktopToolKind::Launch);+ let schema = tool.parameters_schema();+ assert_eq!(tool.exposure(), ToolExposure::Deferred);+ assert_eq!(tool.permission_level(), PermissionLevel::Write);+ assert!(tool.external_effect());+ assert_eq!(schema["required"], json!(["app"]));+ assert!(schema["properties"].get("args").is_none());+ assert!(schema["properties"].get("env").is_none());+ assert!(schema["properties"].get("cdp_port").is_none());+}++#[test]+fn goal_and_continuation_have_distinct_required_inputs() {+ let config = Arc::new(Config::default());+ let goal = DesktopTool::new(config.clone(), DesktopToolKind::Goal);+ let continuation = DesktopTool::new(config, DesktopToolKind::ContinueGoal);+ assert_eq!(goal.parameters_schema()["required"], json!(["app", "goal"]));+ assert!(goal.parameters_schema()["properties"]+ .get("confirmation_id")+ .is_none());+ assert_eq!(+ continuation.parameters_schema()["required"],+ json!(["confirmation_id"])+ );+ assert!(continuation.parameters_schema()["properties"]+ .get("approve")+ .is_none());+ assert!(super::super::confirmation::take_approved("unknown").is_err());+}++#[tokio::test]+async fn approvals_off_continues_one_use_handle_and_reports_module_result() {+ assert!(!Config::default().desktop.approvals_enabled);+ let called = Arc::new(std::sync::atomic::AtomicUsize::new(0));+ let observed = Arc::clone(&called);+ let initial = DesktopResponse::ok(+ "run-goal",+ json!({+ "stop":"confirmation_required", "confirmation_id":"once"+ }),+ );+ let result = advance_goal_confirmations(initial, false, move |id, approve| {+ let observed = Arc::clone(&observed);+ async move {+ assert_eq!(id, "once");+ assert!(approve);+ observed.fetch_add(1, std::sync::atomic::Ordering::SeqCst);+ Ok(DesktopResponse::ok(+ "run-goal",+ json!({+ "stop":"stale_target", "turns":[], "metrics":{"calls":1}+ }),+ ))+ }+ })+ .await+ .unwrap();+ assert_eq!(called.load(std::sync::atomic::Ordering::SeqCst), 1);+ assert_eq!(result.data.unwrap()["stop"], "stale_target");+}++#[tokio::test]+async fn approvals_on_returns_pending_without_self_approval() {+ let initial = DesktopResponse::ok(+ "run-goal",+ json!({+ "stop":"confirmation_required", "confirmation_id":"once"+ }),+ );+ let result = advance_goal_confirmations(initial, true, |_id, _approve| async {+ panic!("manual approval mode must never auto-continue")+ })+ .await+ .unwrap();+ assert_eq!(result.data.unwrap()["confirmation_id"], "once");+}++#[tokio::test]+async fn continuation_ceiling_returns_cancelled_result_with_all_executed_turns() {+ let calls = Arc::new(std::sync::atomic::AtomicUsize::new(0));+ let seen = Arc::clone(&calls);+ let initial = DesktopResponse::ok(+ "run-goal",+ json!({+ "stop":"confirmation_required", "confirmation_id":"id-0", "turns":[]+ }),+ );+ let result = advance_goal_confirmations(initial, false, move |id, approve| {+ let seen = Arc::clone(&seen);+ async move {+ let index = seen.fetch_add(1, std::sync::atomic::Ordering::SeqCst);+ assert_eq!(id, format!("id-{index}"));+ if approve {+ Ok(DesktopResponse::ok(+ "run-goal",+ json!({+ "stop":"confirmation_required",+ "confirmation_id":format!("id-{}", index + 1),+ "turns":vec![Value::Null; index + 1],+ "metrics":{"calls":index + 1}+ }),+ ))+ } else {+ assert_eq!(index, 8);+ Ok(DesktopResponse::ok(+ "run-goal",+ json!({+ "stop":"cancelled", "turns":vec![Value::Null; 8],+ "metrics":{"calls":8}+ }),+ ))+ }+ }+ })+ .await+ .unwrap();+ assert_eq!(calls.load(std::sync::atomic::Ordering::SeqCst), 9);+ let data = result.data.unwrap();+ assert_eq!(data["stop"], "cancelled");+ assert_eq!(data["turns"].as_array().unwrap().len(), 8);+ assert_eq!(data["metrics"]["calls"], 8);+}