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(agent): cover bare origin scope isolation
Steven Enamakel6522a6c60a16
diff --git a/crates/openhuman-core/src/agent/turn_origin_tests.rs b/crates/openhuman-core/src/agent/turn_origin_tests.rsindex 99b37a9488..70ab8f7c96 100644--- a/crates/openhuman-core/src/agent/turn_origin_tests.rs+++ b/crates/openhuman-core/src/agent/turn_origin_tests.rs@@ -325,23 +325,63 @@ async fn current_returns_inner_origin_on_nested_scope() {/// must see the same label, so there is no second copy to drift.#[tokio::test]async fn origin_is_carried_by_the_scoped_core_context_only() {- assert!(crate::core::runtime::CoreContext::scoped().is_none());- let (via_module, via_context, scoped_during) =- with_origin(AgentTurnOrigin::DirectChat, async {+ assert!(crate::core::runtime::CoreContext::scoped_for_turn().is_none());+ let (via_module, via_context, carried) = with_origin(AgentTurnOrigin::DirectChat, async {+ (+ current(),+ crate::core::runtime::CoreContext::current_turn_origin(),+ crate::core::runtime::CoreContext::scoped_for_turn().is_some(),+ )+ })+ .await;+ assert!(matches!(via_module, Some(AgentTurnOrigin::DirectChat)));+ assert!(matches!(via_context, Some(AgentTurnOrigin::DirectChat)));+ assert!(+ carried,+ "with_origin must scope a context, bare if none was booted"+ );+ assert!(crate::core::runtime::CoreContext::scoped_for_turn().is_none());+}++#[derive(Default)]+struct StateProbe;++/// Regression: with no core booted, `with_origin` carries its origin on a bare+/// context. That context must be invisible to every other reader: a state slot+/// read inside the scope is the same slot read outside it (a plan-mode switch+/// set before a turn is seen by the tool the turn runs), and `current` /+/// `scoped` answer as they do when nothing is scoped.+#[tokio::test]+async fn a_bare_origin_scope_is_invisible_to_every_other_reader() {+ use crate::core::runtime::{current_slot, CoreContext};++ let outside_slot = current_slot::<StateProbe>();+ let outside_current = CoreContext::current();+ let (inside_slot, inside_current, inside_scoped, origin) =+ with_origin(AgentTurnOrigin::Cli, async {(+ current_slot::<StateProbe>(),+ CoreContext::current(),+ CoreContext::scoped(),current(),- crate::core::runtime::CoreContext::current_turn_origin(),- crate::core::runtime::CoreContext::scoped().is_some(),)}).await;- assert!(matches!(via_module, Some(AgentTurnOrigin::DirectChat)));- assert!(matches!(via_context, Some(AgentTurnOrigin::DirectChat)));+assert!(- scoped_during,- "with_origin must scope a context, bare if none was booted"+ std::sync::Arc::ptr_eq(&outside_slot, &inside_slot),+ "a bare context must not give the turn a state slot of its own");- assert!(crate::core::runtime::CoreContext::scoped().is_none());+ match (&outside_current, &inside_current) {+ (None, None) => {}+ (Some(a), Some(b)) => assert!(std::sync::Arc::ptr_eq(a, b)),+ _ => panic!("`current` changed inside the scope"),+ }+ // No booted core => nothing scoped for anyone but the origin readers.+ if outside_current.is_none() {+ assert!(inside_scoped.is_none());+ }+ assert!(matches!(origin, Some(AgentTurnOrigin::Cli)));}/// The label survives await points that move the turn between worker threads.