Skip to content

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

test(tinyflows): cover handed context isolation for adapters

Steven Enamakel0785cad25d53
diff --git a/crates/openhuman-core/src/flows/tinyflows/tinyflows_capabilities_tests.rs b/crates/openhuman-core/src/flows/tinyflows/tinyflows_capabilities_tests.rs
index d5a6f71185..954bc675bb 100644
--- a/crates/openhuman-core/src/flows/tinyflows/tinyflows_capabilities_tests.rs
+++ b/crates/openhuman-core/src/flows/tinyflows/tinyflows_capabilities_tests.rs
@@ -506,3 +506,48 @@ fn route_custom_entry_lookup_falls_back_when_no_entry_exists() {
must still resolve through the fallback (which reports \"unknown agent_ref\")"
);
}
+
+// ── Handed context ───────────────────────────────────────────────────────
+
+/// An adapter acts for the context its run was started with, never for the
+/// scope of whichever task happens to poll it: two runs under two contexts do
+/// not cross, even when a third context is ambient.
+#[tokio::test]
+async fn adapters_act_for_the_context_they_were_handed_not_the_ambient_one() {
+ use crate::core::runtime::{context::CoreContext, ComponentSet, DispatchCtx, DomainSet};
+
+ let tmp = TempDir::new().unwrap();
+ let config = test_config(&tmp);
+ let security = Arc::new(SecurityPolicy::from_config(
+ &config.autonomy,
+ &config.workspace_dir,
+ &config.action_dir,
+ ));
+ let sandbox_off = ComponentSet {
+ sandbox: false,
+ ..ComponentSet::default()
+ };
+ let handed_off = DispatchCtx::new(CoreContext::for_test_with_components(sandbox_off));
+ let handed_on = DispatchCtx::new(CoreContext::for_test_with_components(
+ ComponentSet::default(),
+ ));
+ let ambient = CoreContext::for_test(DomainSet::full(), None);
+
+ let build = |ctx: &DispatchCtx| OpenHumanCode {
+ ctx: ctx.clone(),
+ config: Arc::new(config.clone()),
+ security: security.clone(),
+ approval: Default::default(),
+ };
+ let (off, on) = (build(&handed_off), build(&handed_on));
+
+ CoreContext::scope(ambient, async {
+ assert!(!off.ctx.components().sandbox, "the run's own switch wins");
+ assert!(on.ctx.components().sandbox, "two runs do not cross");
+ assert!(
+ DispatchCtx::ambient().components().sandbox,
+ "the ambient scope is a third, unrelated context"
+ );
+ })
+ .await;
+}