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(mcp): remove obsolete module client cleanup tests
Steven Enamakel36b8f8d1159e
diff --git a/crates/openhuman-core/src/mcp/module_client/cleanup_tests.rs b/crates/openhuman-core/src/mcp/module_client/cleanup_tests.rsindex 1d889cf314..b46ee0682a 100644--- a/crates/openhuman-core/src/mcp/module_client/cleanup_tests.rs+++ b/crates/openhuman-core/src/mcp/module_client/cleanup_tests.rs@@ -234,221 +234,3 @@ async fn a_removed_agent_context_cannot_reopen_its_evicted_client() {}).await;}--#[tokio::test(flavor = "multi_thread", worker_threads = 2)]-async fn a_removed_context_waiting_for_the_client_cache_cannot_reopen_it() {- use crate::core::runtime::{ContextOverlay, CoreContext, DomainSet};- use crate::tools::toolpacks::ToolGroups;-- let workspace = tempfile::tempdir().expect("workspace");- let scoped_dir = workspace.path().join("agents").join("agent");- let mut config = Config::default();- config.workspace_dir = workspace.path().to_path_buf();- config.modules.enabled = true;- let scope = Arc::new(crate::security::approval::ApprovalScope::default());- let mut overrides = crate::agent::host_overrides::HostOverrides::default();- overrides.approval_scope = Some(Arc::clone(&scope));- let context = CoreContext::for_test(DomainSet::full(), Some(workspace.path().to_path_buf()))- .derive_with(- ContextOverlay::new(config.clone(), DomainSet::kernel(), ToolGroups::none())- .session_agent("agent")- .host_overrides(Arc::new(overrides)),- );-- let clients = CLIENTS.get_or_init(|| Mutex::new(HashMap::new()));- let clients_lock = clients.lock().unwrap();- let (checked, checked_rx) = tokio::sync::oneshot::channel();- *AFTER_CONTEXT_CHECK- .get_or_init(|| Mutex::new(None))- .lock()- .unwrap() = Some((scoped_dir.clone(), checked));- let request = tokio::spawn(CoreContext::scope(context, async move {- McpConfiguredClient::for_config(&config)- }));-- tokio::time::timeout(Duration::from_secs(10), checked_rx)- .await- .expect("request passed the initial context check")- .unwrap();- scope.close("agent_removed");- drop(clients_lock);-- let admitted = request.await.unwrap().is_ok();- if admitted {- clients.lock().unwrap().remove(&scoped_dir);- }- assert!(!admitted, "removed context must not create a cached client");- assert!(!clients.lock().unwrap().contains_key(&scoped_dir));-}--#[tokio::test]-async fn delayed_agent_close_cannot_evict_a_replacement_cache_entry() {- let workspace = tempfile::tempdir().expect("workspace");- let mut config = Config::default();- config.workspace_dir = workspace.path().to_path_buf();- config.modules.enabled = true;-- let old_port = FakePort::default();- let old_closed = Arc::clone(&old_port.closed);- let old = McpConfiguredClient::install_test_port(&config, Box::new(old_port))- .expect("install old client");- old.call::<bool>(&configured("server"), "ConnectedOverview", ())- .await- .unwrap();- let cleanup_ran = Arc::new(std::sync::atomic::AtomicBool::new(false));- let callback_flag = Arc::clone(&cleanup_ran);- let reservation = McpConfiguredClient::reservation_with_action(- workspace.path(),- Arc::new(move || {- callback_flag.store(true, std::sync::atomic::Ordering::SeqCst);- true- }),- );- let captured = McpConfiguredClient::retire_cached_client(workspace.path())- .expect("retirement captures the exact old client");-- let replacement_port = FakePort::default();- let replacement_closed = Arc::clone(&replacement_port.closed);- let replacement = Arc::new(McpConfiguredClient::with_port(- workspace.path().to_string_lossy().into_owned(),- Box::new(replacement_port),- ));- CLIENTS- .get()- .expect("old client initialized the cache")- .lock()- .unwrap()- .insert(workspace.path().to_path_buf(), Arc::clone(&replacement));-- assert!(- !McpConfiguredClient::close_retired_client(- workspace.path().to_path_buf(),- captured,- Arc::clone(&reservation),- )- .await,- "a stale close completion cannot claim the replacement entry"- );- assert!(!cleanup_ran.load(std::sync::atomic::Ordering::SeqCst));- assert_eq!(old_closed.lock().unwrap().len(), 1);- assert!(replacement_closed.lock().unwrap().is_empty());- let current = CLIENTS- .get()- .unwrap()- .lock()- .unwrap()- .get(workspace.path())- .cloned()- .expect("replacement remains cached");- assert!(Arc::ptr_eq(¤t, &replacement));- CLEANUP_RESERVATIONS- .get()- .unwrap()- .lock()- .unwrap()- .remove(workspace.path());-}--#[tokio::test]-async fn failed_cleanup_actions_retain_and_retry_cached_and_orphaned_paths() {- use std::sync::atomic::{AtomicUsize, Ordering};-- let workspace = tempfile::tempdir().expect("workspace");- let agent_dir = workspace.path().join("agents").join("alpha");- std::fs::create_dir_all(&agent_dir).unwrap();- std::fs::write(agent_dir.join("state.json"), "retained until cleanup").unwrap();- let mut config = Config::default();- config.workspace_dir = agent_dir.clone();- config.modules.enabled = true;- let client = McpConfiguredClient::install_test_port(&config, Box::new(FakePort::default()))- .expect("install client");- client- .call::<bool>(&configured("alpha"), "ConnectedOverview", ())- .await- .unwrap();-- let attempts = Arc::new(AtomicUsize::new(0));- let callback_attempts = Arc::clone(&attempts);- let home = agent_dir.clone();- let action: CleanupAction = Arc::new(move || {- if callback_attempts.fetch_add(1, Ordering::SeqCst) == 0 {- return false;- }- std::fs::remove_dir_all(&home).is_ok() || !home.exists()- });- let reservation = McpConfiguredClient::reservation_with_action(&agent_dir, action);- let captured = McpConfiguredClient::retire_cached_client(&agent_dir).unwrap();- assert!(- !McpConfiguredClient::close_retired_client(agent_dir.clone(), captured, reservation,).await- );- assert!(agent_dir.join("state.json").exists());- assert!(McpConfiguredClient::agent_close_pending(&agent_dir));- assert!(matches!(- McpConfiguredClient::for_config(&config),- Err(ModuleCallError::Unavailable)- ));- assert!(McpConfiguredClient::close_agent_data_dir(&agent_dir).await);- assert!(!agent_dir.exists());- assert!(McpConfiguredClient::for_config(&config).is_ok());-- let orphan_dir = workspace.path().join("agents").join("orphan");- std::fs::create_dir_all(&orphan_dir).unwrap();- let orphan_attempts = Arc::new(AtomicUsize::new(0));- let callback_attempts = Arc::clone(&orphan_attempts);- let orphan_home = orphan_dir.clone();- let reservation = McpConfiguredClient::reservation_with_action(- &orphan_dir,- Arc::new(move || {- if callback_attempts.fetch_add(1, Ordering::SeqCst) == 0 {- return false;- }- std::fs::remove_dir_all(&orphan_home).is_ok() || !orphan_home.exists()- }),- );- assert!(!McpConfiguredClient::finish_cleanup(- &orphan_dir,- None,- reservation,- ));- assert!(McpConfiguredClient::agent_close_pending(&orphan_dir));- assert!(orphan_dir.exists());- McpConfiguredClient::retry_orphaned_cleanups();- assert!(!McpConfiguredClient::agent_close_pending(&orphan_dir));- assert!(!orphan_dir.exists());-}--#[test]-fn cleanup_callback_can_access_the_client_cache() {- let workspace = tempfile::tempdir().expect("workspace");- let mut config = Config::default();- config.workspace_dir = workspace.path().to_path_buf();- config.modules.enabled = true;- McpConfiguredClient::install_test_port(&config, Box::new(FakePort::default()))- .expect("install closed client");- let cache_available = Arc::new(AtomicBool::new(false));- let callback_flag = Arc::clone(&cache_available);- McpConfiguredClient::schedule_agent_close_and_cleanup(- workspace.path(),- Arc::new(move || {- // Permit transient contention from other parallel tests, while- // detecting a cache lock held by the cleanup call itself.- let deadline = std::time::Instant::now() + Duration::from_secs(10);- let available = loop {- if CLIENTS.get().unwrap().try_lock().is_ok() {- break true;- }- if std::time::Instant::now() >= deadline {- break false;- }- std::thread::yield_now();- };- callback_flag.store(available, Ordering::SeqCst);- true- }),- );- assert!(- cache_available.load(Ordering::SeqCst),- "cleanup callbacks must not hold the global client cache lock"- );- assert!(!McpConfiguredClient::agent_close_pending(workspace.path()));-}