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(cost): cover explicit context winning over ambient agent scope
Steven Enamakelff3927d88e2a
diff --git a/crates/openhuman-core/src/platform/cost/scope_tests.rs b/crates/openhuman-core/src/platform/cost/scope_tests.rsindex c37a077f34..a896cf8362 100644--- a/crates/openhuman-core/src/platform/cost/scope_tests.rs+++ b/crates/openhuman-core/src/platform/cost/scope_tests.rs@@ -92,3 +92,31 @@ fn outside_any_turn_and_without_a_provider_the_scope_is_empty() {let scope = UsageScope::in_ctx(&DispatchCtx::ambient(), Some(""), None);assert!(scope.is_empty(), "{scope:?}");}++#[tokio::test]+async fn the_explicit_context_names_the_session_agent_not_the_ambient_one() {+ let root = crate::core::runtime::CoreContext::for_test(crate::core::runtime::DomainSet::full(), None);+ let alice = crate::core::runtime::agent_scope::test_agent_context(&root, "alice");+ let bob = crate::core::runtime::agent_scope::test_agent_context(&root, "bob");+ let alice_ctx = DispatchCtx::new(alice.clone());+ let bob_ctx = DispatchCtx::new(bob.clone());++ // Concurrent tasks, each ambient under the other tenant, across an await+ // and into a spawned task: the explicit context decides.+ let a = tokio::spawn(crate::core::runtime::CoreContext::scope(bob, {+ let ctx = alice_ctx.clone();+ async move {+ tokio::task::yield_now().await;+ UsageScope::in_ctx(&ctx, Some("p"), None)+ }+ }));+ let b = tokio::spawn(crate::core::runtime::CoreContext::scope(alice, {+ let ctx = bob_ctx.clone();+ async move {+ tokio::task::yield_now().await;+ UsageScope::in_ctx(&ctx, Some("p"), None)+ }+ }));+ assert_eq!(a.await.unwrap().session_agent.as_deref(), Some("alice"));+ assert_eq!(b.await.unwrap().session_agent.as_deref(), Some("bob"));+}