Skip to content

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

test(storage): cover config resolution from explicit dispatch context

Steven Enamakel13c89096ec9d
diff --git a/crates/openhuman-core/src/flows/bus/owner_tests.rs b/crates/openhuman-core/src/flows/bus/owner_tests.rs
index e42664ec4e..c1baec0f9d 100644
--- a/crates/openhuman-core/src/flows/bus/owner_tests.rs
+++ b/crates/openhuman-core/src/flows/bus/owner_tests.rs
@@ -65,3 +65,37 @@ async fn a_cached_owner_is_dropped_once_its_scope_loses_the_flow() {
assert_eq!(resolve(&config, "owner-test-revalidate").await, Ok(None));
assert!(!OWNERS.lock().unwrap().contains_key("owner-test-revalidate"));
}
+
+/// The handling config follows the explicit context: an agent's context yields
+/// its own config with no task scope anywhere, and an unbound one the
+/// registered config.
+#[tokio::test]
+async fn the_scope_config_follows_the_explicit_context() {
+ use crate::core::runtime::{ContextOverlay, CoreContext, DispatchCtx, DomainSet};
+ let registered = std::sync::Arc::new(Config {
+ workspace_dir: std::path::PathBuf::from("/tmp/flows-owner-registered"),
+ ..Config::default()
+ });
+ let agent_config = Config {
+ workspace_dir: std::path::PathBuf::from("/tmp/flows-owner-agent"),
+ ..Config::default()
+ };
+ let agent = DispatchCtx::new(
+ CoreContext::for_test(DomainSet::full(), None).derive_with(
+ ContextOverlay::new(agent_config, DomainSet::full(), Default::default())
+ .session_agent("flows-owner-agent"),
+ ),
+ );
+ let unbound = config_for_scope(&DispatchCtx::unbound(), &registered);
+ let own = tokio::spawn(async move {
+ tokio::task::yield_now().await;
+ config_for_scope(&agent, &std::sync::Arc::new(Config::default()))
+ })
+ .await
+ .unwrap();
+ assert_eq!(
+ own.workspace_dir,
+ std::path::Path::new("/tmp/flows-owner-agent")
+ );
+ assert!(std::sync::Arc::ptr_eq(&unbound, &registered));
+}
diff --git a/crates/openhuman-core/src/mcp/host_tests.rs b/crates/openhuman-core/src/mcp/host_tests.rs
index 134fce8bae..2a36a573d8 100644
--- a/crates/openhuman-core/src/mcp/host_tests.rs
+++ b/crates/openhuman-core/src/mcp/host_tests.rs
@@ -122,3 +122,43 @@ fn oauth_redirect_port_parser_accepts_only_explicit_url_ports() {
assert_eq!(explicit_port("http://127.0.0.1/rpc"), None);
assert_eq!(explicit_port("not a URL"), None);
}
+
+/// The config comes from the dispatch context passed in, not from the calling
+/// task's scope: two agents resolved concurrently, across awaits and on spawned
+/// tasks, each get their own, and an unbound context gets neither.
+#[tokio::test]
+async fn ambient_config_follows_the_explicit_context() {
+ use crate::core::runtime::{ContextOverlay, CoreContext, DispatchCtx, DomainSet};
+ let agent = |name: &str| {
+ let config = Config {
+ workspace_dir: std::path::PathBuf::from(format!("/tmp/mcp-host-{name}")),
+ ..Config::default()
+ };
+ DispatchCtx::new(CoreContext::for_test(DomainSet::full(), None).derive_with(
+ ContextOverlay::new(config, DomainSet::full(), Default::default()).session_agent(name),
+ ))
+ };
+ let (alice, bob) = (agent("alice"), agent("bob"));
+ let resolve = |ctx: DispatchCtx| {
+ tokio::spawn(async move {
+ tokio::task::yield_now().await;
+ ambient_config(&ctx).map(|config| config.workspace_dir)
+ })
+ };
+ let (a, b) = tokio::join!(resolve(alice), resolve(bob));
+ assert_eq!(
+ a.unwrap().as_deref(),
+ Some(std::path::Path::new("/tmp/mcp-host-alice"))
+ );
+ assert_eq!(
+ b.unwrap().as_deref(),
+ Some(std::path::Path::new("/tmp/mcp-host-bob"))
+ );
+ assert_eq!(
+ ambient_config(&DispatchCtx::unbound()).map(|config| config.workspace_dir),
+ DEFAULT_CONFIG
+ .get()
+ .map(|config| config.workspace_dir.clone()),
+ "an unbound context falls back to the process default, never a scope"
+ );
+}
diff --git a/crates/openhuman-core/src/modules/storage_host.rs b/crates/openhuman-core/src/modules/storage_host.rs
index 3c1ac0b362..622d120643 100644
--- a/crates/openhuman-core/src/modules/storage_host.rs
+++ b/crates/openhuman-core/src/modules/storage_host.rs
@@ -649,3 +649,7 @@ mod endpoint;
#[cfg(test)]
#[path = "storage_host_tests.rs"]
mod tests;
+
+#[cfg(test)]
+#[path = "storage_host_ctx_tests.rs"]
+mod ctx_tests;
diff --git a/crates/openhuman-core/src/modules/storage_host_ctx_tests.rs b/crates/openhuman-core/src/modules/storage_host_ctx_tests.rs
new file mode 100644
index 0000000000..19ba69372a
--- /dev/null
+++ b/crates/openhuman-core/src/modules/storage_host_ctx_tests.rs
@@ -0,0 +1,38 @@
+//! The scope a module's host call serves follows the dispatch context passed
+//! in, not the calling task's scope.
+
+use super::*;
+use crate::core::runtime::{ContextOverlay, CoreContext, DispatchCtx, DomainSet};
+
+fn profile(name: &str) -> DispatchCtx {
+ DispatchCtx::new(
+ CoreContext::for_test(DomainSet::full(), None).derive_with(
+ ContextOverlay::new(
+ crate::config::Config::default(),
+ DomainSet::kernel(),
+ Default::default(),
+ )
+ .profile(name),
+ ),
+ )
+}
+
+#[tokio::test]
+async fn a_module_scope_is_the_explicit_contexts_profile_across_tasks() {
+ let (alice, bob) = (profile("scope-alice"), profile("scope-bob"));
+ let resolve = |ctx: DispatchCtx| {
+ tokio::spawn(async move {
+ tokio::task::yield_now().await;
+ current_module_scope(&ctx, "tinymcp").map(|scope| scope.as_str().to_owned())
+ })
+ };
+ let (a, b) = tokio::join!(resolve(alice.clone()), resolve(bob));
+ let (a, b) = (a.unwrap().unwrap(), b.unwrap().unwrap());
+ assert!(a.contains("scope-alice") && !a.contains("scope-bob"), "{a}");
+ assert!(b.contains("scope-bob") && !b.contains("scope-alice"), "{b}");
+ assert_eq!(
+ current_module_scope(&alice, "tinymcp").unwrap().as_str(),
+ a,
+ "the same context resolves the same scope"
+ );
+}