Skip to content

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

test(mcp): scope context check hook to the expected data dir

Steven Enamakeld576f48478c9
diff --git a/crates/openhuman-core/src/mcp/module_client.rs b/crates/openhuman-core/src/mcp/module_client.rs
index 3e4346751e..ed11949d89 100644
--- a/crates/openhuman-core/src/mcp/module_client.rs
+++ b/crates/openhuman-core/src/mcp/module_client.rs
@@ -48,8 +48,8 @@ static SHUTDOWN_REGISTERED: AtomicBool = AtomicBool::new(false);
static SHUTTING_DOWN: AtomicBool = AtomicBool::new(false);
#[cfg(test)]
-static AFTER_CONTEXT_CHECK: OnceLock<Mutex<Option<tokio::sync::oneshot::Sender<()>>>> =
- OnceLock::new();
+static AFTER_CONTEXT_CHECK:
+ OnceLock<Mutex<Option<(PathBuf, tokio::sync::oneshot::Sender<()>)>>> = OnceLock::new();
#[derive(Clone)]
struct OpenObject {
@@ -262,17 +262,22 @@ impl McpConfiguredClient {
ModuleClient::report_unavailable(MODULE);
return Err(ModuleCallError::Unavailable);
}
+ let data_dir = crate::core::runtime::agent_scope_dir(config);
#[cfg(test)]
- if let Some(sender) = AFTER_CONTEXT_CHECK
- .get_or_init(|| Mutex::new(None))
- .lock()
- .unwrap_or_else(std::sync::PoisonError::into_inner)
- .take()
{
- let _ = sender.send(());
+ let mut hook = AFTER_CONTEXT_CHECK
+ .get_or_init(|| Mutex::new(None))
+ .lock()
+ .unwrap_or_else(std::sync::PoisonError::into_inner);
+ if hook
+ .as_ref()
+ .is_some_and(|(expected, _)| expected == &data_dir)
+ {
+ if let Some((_, sender)) = hook.take() {
+ let _ = sender.send(());
+ }
+ }
}
-
- let data_dir = crate::core::runtime::agent_scope_dir(config);
if current_agent_context_is_removed() || Self::cleanup_pending(&data_dir) {
return Err(ModuleCallError::Unavailable);
}
diff --git a/crates/openhuman-core/src/mcp/module_client_tests.rs b/crates/openhuman-core/src/mcp/module_client_tests.rs
index 7454ed7fdf..11fda1af93 100644
--- a/crates/openhuman-core/src/mcp/module_client_tests.rs
+++ b/crates/openhuman-core/src/mcp/module_client_tests.rs
@@ -450,7 +450,6 @@ async fn agent_cleanup_closes_only_the_cached_agent_and_keeps_siblings_open() {
#[tokio::test]
async fn failed_agent_close_stays_retired_and_can_be_retried() {
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;
@@ -644,6 +643,7 @@ async fn a_removed_context_waiting_for_the_client_cache_cannot_reopen_it() {
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;
@@ -663,12 +663,12 @@ async fn a_removed_context_waiting_for_the_client_cache_cannot_reopen_it() {
*AFTER_CONTEXT_CHECK
.get_or_init(|| Mutex::new(None))
.lock()
- .unwrap() = Some(checked);
+ .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(1), checked_rx)
+ tokio::time::timeout(Duration::from_secs(10), checked_rx)
.await
.expect("request passed the initial context check")
.unwrap();