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: share desktop loopback guard across control tests
Steven Enamakelf821862737fb
diff --git a/crates/openhuman-core/src/desktop/control/ops.rs b/crates/openhuman-core/src/desktop/control/ops.rsindex c63b3c303e..cca28ed09a 100644--- a/crates/openhuman-core/src/desktop/control/ops.rs+++ b/crates/openhuman-core/src/desktop/control/ops.rs@@ -43,6 +43,34 @@ fn approval_bypass_decision(config: &Config, tool: &dyn tinytools::Tool) -> boolstatic STATE_LOCK: Mutex<()> = Mutex::new(());static LOOPBACK_LISTENER: AtomicBool = AtomicBool::new(false);+#[cfg(test)]+static TEST_LOOPBACK_LOCK: Mutex<()> = Mutex::new(());++/// Serializes tests that temporarily make the process-wide listener local.+#[cfg(test)]+pub(super) struct TestLoopbackGuard {+ previous: bool,+ _lock: std::sync::MutexGuard<'static, ()>,+}++#[cfg(test)]+pub(super) fn test_loopback_guard() -> TestLoopbackGuard {+ let lock = TEST_LOOPBACK_LOCK+ .lock()+ .unwrap_or_else(std::sync::PoisonError::into_inner);+ TestLoopbackGuard {+ previous: LOOPBACK_LISTENER.swap(true, Ordering::AcqRel),+ _lock: lock,+ }+}++#[cfg(test)]+impl Drop for TestLoopbackGuard {+ fn drop(&mut self) {+ set_listener_is_loopback(self.previous);+ }+}+/// The HTTP host reports its actual bound address before serving requests.pub(crate) fn set_listener_is_loopback(value: bool) {LOOPBACK_LISTENER.store(value, Ordering::Release);diff --git a/crates/openhuman-core/src/desktop/control/ops_tests.rs b/crates/openhuman-core/src/desktop/control/ops_tests.rsindex b5bd712348..f9c1f454c8 100644--- a/crates/openhuman-core/src/desktop/control/ops_tests.rs+++ b/crates/openhuman-core/src/desktop/control/ops_tests.rs@@ -1,34 +1,5 @@use super::*;-#[cfg(any(target_os = "macos", target_os = "windows"))]-static TEST_LOOPBACK_LOCK: Mutex<()> = Mutex::new(());--#[cfg(any(target_os = "macos", target_os = "windows"))]-struct LoopbackTestGuard {- previous: bool,- _lock: std::sync::MutexGuard<'static, ()>,-}--#[cfg(any(target_os = "macos", target_os = "windows"))]-impl LoopbackTestGuard {- fn enable() -> Self {- let lock = TEST_LOOPBACK_LOCK- .lock()- .unwrap_or_else(std::sync::PoisonError::into_inner);- Self {- previous: LOOPBACK_LISTENER.swap(true, Ordering::AcqRel),- _lock: lock,- }- }-}--#[cfg(any(target_os = "macos", target_os = "windows"))]-impl Drop for LoopbackTestGuard {- fn drop(&mut self) {- set_listener_is_loopback(self.previous);- }-}-#[test]fn disabled_by_default_and_persists() {let dir = tempfile::tempdir().unwrap();@@ -97,7 +68,7 @@ async fn disabled_status_reports_local_setting_without_contacting_module() {async fn enabled_status_reports_module_permissions_and_errors() {use tinydesktop_bus::{DesktopError, DesktopResponse};- let _loopback = LoopbackTestGuard::enable();+ let _loopback = test_loopback_guard();let dir = tempfile::tempdir().unwrap();let mut config = Config::default();config.workspace_dir = dir.path().to_path_buf();@@ -153,7 +124,7 @@ async fn disabling_desktop_persists_even_if_state_was_enabled() {async fn probe_requires_accessibility_and_snapshot_before_listing_apps() {use tinydesktop_bus::{DesktopError, DesktopResponse};- let _loopback = LoopbackTestGuard::enable();+ let _loopback = test_loopback_guard();let dir = tempfile::tempdir().unwrap();let mut config = Config::default();config.workspace_dir = dir.path().to_path_buf();