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(user_agents): add coverage for user agent handling
Steven Enamakel10931b282ae2
diff --git a/crates/openhuman-core/src/user_agents/host_tests.rs b/crates/openhuman-core/src/user_agents/host_tests.rsindex aeff78d688..7aafc04558 100644--- a/crates/openhuman-core/src/user_agents/host_tests.rs+++ b/crates/openhuman-core/src/user_agents/host_tests.rs@@ -261,3 +261,55 @@ fn a_provisioned_config_needs_no_agent_slot() {assert!(host.provisioned_config(&b).is_ok());assert!(host.provisioned_config(&agent("nobody")).is_err());}++#[tokio::test]+async fn an_open_agent_is_gated_by_its_own_policy_not_the_operators() {+ let tmp = tempfile::tempdir().unwrap();+ let host = host(&tmp, 4, 60);+ let id = agent("alice");+ host.provision(&id).unwrap();+ let state = host.open(&id).unwrap();+ assert_eq!(state.context().profile(), Some(id.as_str()));++ let own = state.context().agent_policy().expect("the profile carries a policy");+ assert!(own.enabled, "the forced autonomy policy is on");+ assert!(own.workspace_only);+ let effective = CoreContext::scope(Arc::clone(state.context()), async {+ crate::security::live_policy::effective()+ })+ .await+ .expect("a policy is in effect");+ assert!(+ Arc::ptr_eq(&effective, &own),+ "inside the profile's scope the gate answers with its policy"+ );+}++#[tokio::test]+async fn an_agent_with_a_live_turn_is_not_evicted() {+ let tmp = tempfile::tempdir().unwrap();+ let host = host(&tmp, 1, 0);+ let (a, b) = (agent("a"), agent("b"));+ host.provision(&a).unwrap();+ host.provision(&b).unwrap();+ // The request that started the turn has answered and let go of the+ // state; the turn keeps running on a context derived from the agent's.+ let context = Arc::clone(host.open(&a).unwrap().context());+ let (release, released) = tokio::sync::oneshot::channel::<()>();+ let turn = tokio::spawn(CoreContext::scope_with_turn_origin(context, None, async {+ let _ = released.await;+ }));+ tokio::task::yield_now().await;++ host.evict_idle();+ assert!(host.is_open(&a), "a live turn keeps its agent open");+ let err = host.open(&b).unwrap_err();+ assert!(err.contains("slots are in use"), "{err}");+ assert!(host.deprovision(&a).unwrap_err().contains("in use"));++ release.send(()).unwrap();+ turn.await.unwrap();+ host.evict_idle();+ assert!(!host.is_open(&a), "evicted once the turn ended");+ host.open(&b).unwrap();+}