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: exercise desktop connection branches on Linux coverage
Steven Enamakeld160d9902d6e
diff --git a/crates/openhuman-core/src/desktop/control/ops.rs b/crates/openhuman-core/src/desktop/control/ops.rsindex cca28ed09a..b77a8037d3 100644--- a/crates/openhuman-core/src/desktop/control/ops.rs+++ b/crates/openhuman-core/src/desktop/control/ops.rs@@ -186,10 +186,17 @@ fn permission(data: &serde_json::Value, field: &str) -> String {}pub async fn status(config: &Config) -> DesktopStatus {- status_with(config, || crate::modules::desktop::permissions(config)).await+ status_with(config, supported(), || {+ crate::modules::desktop::permissions(config)+ })+ .await}-async fn status_with<F, Fut>(config: &Config, permissions: F) -> DesktopStatus+async fn status_with<F, Fut>(+ config: &Config,+ platform_supported: bool,+ permissions: F,+) -> DesktopStatuswhereF: FnOnce() -> Fut,Fut: std::future::Future<Output = Result<tinydesktop_bus::DesktopResponse, String>>,@@ -197,7 +204,7 @@ wherelet local_enabled = enabled(config);let (module_state, mut reason) = crate::modules::desktop::state(config);let mut result = DesktopStatus {- supported: supported(),+ supported: platform_supported,enabled: local_enabled,approvals_enabled: config.desktop.approvals_enabled,platform: std::env::consts::OS,@@ -230,7 +237,7 @@ where}pub async fn probe(config: &Config) -> DesktopProbe {- probe_with(config, |member| async move {+ probe_with(config, supported(), |member| async move {match member {names::methods::PERMISSIONS => crate::modules::desktop::permissions(config).await,names::methods::SNAPSHOT => {@@ -253,12 +260,12 @@ pub async fn probe(config: &Config) -> DesktopProbe {.await}-async fn probe_with<F, Fut>(config: &Config, mut call: F) -> DesktopProbe+async fn probe_with<F, Fut>(config: &Config, platform_supported: bool, mut call: F) -> DesktopProbewhereF: FnMut(&'static str) -> Fut,Fut: std::future::Future<Output = Result<tinydesktop_bus::DesktopResponse, String>>,{- if !supported() || !enabled(config) {+ if !platform_supported || !enabled(config) {return DesktopProbe {ok: false,app_count: None,diff --git a/crates/openhuman-core/src/desktop/control/ops_tests.rs b/crates/openhuman-core/src/desktop/control/ops_tests.rsindex f9c1f454c8..c4110083fd 100644--- a/crates/openhuman-core/src/desktop/control/ops_tests.rs+++ b/crates/openhuman-core/src/desktop/control/ops_tests.rs@@ -35,7 +35,7 @@ async fn disabled_probe_never_calls_the_module() {let dir = tempfile::tempdir().unwrap();let mut config = Config::default();config.workspace_dir = dir.path().to_path_buf();- let result = probe_with(&config, |_| async {+ let result = probe_with(&config, true, |_| async {panic!("disabled probe reached module")}).await;@@ -52,7 +52,7 @@ async fn disabled_status_reports_local_setting_without_contacting_module() {let dir = tempfile::tempdir().unwrap();let mut config = Config::default();config.workspace_dir = dir.path().to_path_buf();- let result = status_with(&config, || async {+ let result = status_with(&config, true, || async {panic!("disabled status reached module")}).await;@@ -61,20 +61,40 @@ async fn disabled_status_reports_local_setting_without_contacting_module() {assert_eq!(result.accessibility, "unknown");assert_eq!(result.screen_recording, "unknown");assert_eq!(result.platform, std::env::consts::OS);++ let unsupported = status_with(&config, false, || async {+ panic!("unsupported status reached module")+ })+ .await;+ assert!(!unsupported.supported);+ assert!(unsupported+ .reason+ .as_deref()+ .unwrap()+ .contains("loopback core listener"));+}++#[cfg(target_os = "linux")]+#[tokio::test]+async fn enable_request_fails_closed_on_unsupported_platform_without_persisting() {+ let dir = tempfile::tempdir().unwrap();+ let mut config = Config::default();+ config.workspace_dir = dir.path().to_path_buf();+ let error = set_enabled(&config, true).await.unwrap_err();+ assert!(error.contains("macOS or Windows"));+ assert!(!enabled(&config));}-#[cfg(any(target_os = "macos", target_os = "windows"))]#[tokio::test]async fn enabled_status_reports_module_permissions_and_errors() {use tinydesktop_bus::{DesktopError, DesktopResponse};- let _loopback = test_loopback_guard();let dir = tempfile::tempdir().unwrap();let mut config = Config::default();config.workspace_dir = dir.path().to_path_buf();save(&config, true).unwrap();- let permitted = status_with(&config, || async {+ let permitted = status_with(&config, true, || async {Ok(DesktopResponse::ok("permissions",serde_json::json!({@@ -88,7 +108,7 @@ async fn enabled_status_reports_module_permissions_and_errors() {assert_eq!(permitted.accessibility, "granted");assert_eq!(permitted.screen_recording, "not_required");- let refused = status_with(&config, || async {+ let refused = status_with(&config, true, || async {Ok(DesktopResponse::err("permissions",DesktopError::new("PERM_DENIED", "Grant Accessibility"),@@ -98,7 +118,7 @@ async fn enabled_status_reports_module_permissions_and_errors() {assert_eq!(refused.reason.as_deref(), Some("Grant Accessibility"));assert_eq!(refused.accessibility, "unknown");- let unavailable = status_with(&config, || async {+ let unavailable = status_with(&config, true, || async {Err("module could not start".to_owned())}).await;@@ -119,18 +139,16 @@ async fn disabling_desktop_persists_even_if_state_was_enabled() {assert!(!enabled(&config));}-#[cfg(any(target_os = "macos", target_os = "windows"))]#[tokio::test]async fn probe_requires_accessibility_and_snapshot_before_listing_apps() {use tinydesktop_bus::{DesktopError, DesktopResponse};- let _loopback = test_loopback_guard();let dir = tempfile::tempdir().unwrap();let mut config = Config::default();config.workspace_dir = dir.path().to_path_buf();save(&config, true).unwrap();- let denied = probe_with(&config, |member| async move {+ let denied = probe_with(&config, true, |member| async move {assert_eq!(member, names::methods::PERMISSIONS);Ok(DesktopResponse::ok(member,@@ -146,7 +164,7 @@ async fn probe_requires_accessibility_and_snapshot_before_listing_apps() {Some("Accessibility permission is not granted to the core process"));- let failed = probe_with(&config, |member| async move {+ let failed = probe_with(&config, true, |member| async move {match member {names::methods::PERMISSIONS => Ok(DesktopResponse::ok(member,@@ -165,7 +183,7 @@ async fn probe_requires_accessibility_and_snapshot_before_listing_apps() {assert!(!failed.ok);assert_eq!(failed.reason.as_deref(), Some("Screen Recording required"));- let success = probe_with(&config, |member| async move {+ let success = probe_with(&config, true, |member| async move {Ok(DesktopResponse::ok(member,match member {@@ -185,7 +203,7 @@ async fn probe_requires_accessibility_and_snapshot_before_listing_apps() {assert_eq!(success.app_count, Some(2));assert!(success.reason.is_none());- let transport_error = probe_with(&config, |member| async move {+ let transport_error = probe_with(&config, true, |member| async move {match member {names::methods::PERMISSIONS => Ok(DesktopResponse::ok(member,@@ -207,7 +225,7 @@ async fn probe_requires_accessibility_and_snapshot_before_listing_apps() {Some("app list bus disconnected"));- let module_error = probe_with(&config, |member| async move {+ let module_error = probe_with(&config, true, |member| async move {match member {names::methods::PERMISSIONS => Ok(DesktopResponse::ok(member,diff --git a/crates/openhuman-core/src/desktop/control/schemas_tests.rs b/crates/openhuman-core/src/desktop/control/schemas_tests.rsindex d95a3fee92..4c23ee971e 100644--- a/crates/openhuman-core/src/desktop/control/schemas_tests.rs+++ b/crates/openhuman-core/src/desktop/control/schemas_tests.rs@@ -1,4 +1,6 @@use super::*;+use crate::core::runtime::context::CoreContext;+use crate::core::runtime::DomainSet;fn controller(name: &str) -> RegisteredController {all_registered_controllers()@@ -52,3 +54,36 @@ async fn malformed_controller_inputs_fail_before_loading_config_or_acting() {"approve must be a boolean");}++#[tokio::test]+async fn controllers_use_scoped_config_for_disabled_desktop_and_reject_unknown_confirmation() {+ let _loopback = super::super::ops::test_loopback_guard();+ let dir = tempfile::tempdir().unwrap();+ let mut config = crate::config::Config::default();+ config.workspace_dir = dir.path().to_path_buf();+ let context = CoreContext::for_test_with_config(DomainSet::full(), config);++ CoreContext::scope(context, async {+ let status = (controller("status").handler)(Map::new()).await.unwrap();+ assert_eq!(status["enabled"], false);++ let probe = (controller("probe").handler)(Map::new()).await.unwrap();+ assert_eq!(probe["ok"], false);+ assert!(probe["reason"].as_str().unwrap().contains("disabled"));++ let mut params = Map::new();+ params.insert("enabled".to_owned(), Value::Bool(false));+ let disabled = (controller("set_enabled").handler)(params).await.unwrap();+ assert_eq!(disabled["enabled"], false);++ let mut params = Map::new();+ params.insert(+ "confirmation_id".to_owned(),+ Value::String("missing".to_owned()),+ );+ params.insert("approve".to_owned(), Value::Bool(true));+ let error = (controller("confirm").handler)(params).await.unwrap_err();+ assert!(error.contains("missing or expired"));+ })+ .await;+}