Skip to content

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

test(security): cover explicit context policy precedence

Steven Enamakel8cd60966a3aa
diff --git a/crates/openhuman-core/src/security/live_policy_tests.rs b/crates/openhuman-core/src/security/live_policy_tests.rs
index b0cdc75dd8..e738e3ce1d 100644
--- a/crates/openhuman-core/src/security/live_policy_tests.rs
+++ b/crates/openhuman-core/src/security/live_policy_tests.rs
@@ -237,3 +237,27 @@ async fn effective_falls_back_to_the_process_policy_for_an_agent_without_one() {
fn effective() -> Option<Arc<SecurityPolicy>> {
effective_in(&crate::core::runtime::DispatchCtx::ambient())
}
+
+#[tokio::test]
+async fn an_explicit_context_policy_wins_over_the_ambient_one() {
+ let workspace = std::env::temp_dir().join("openhuman_effective_policy_test");
+ let process = Arc::new(SecurityPolicy::default());
+ let _guard = install_scoped(Arc::clone(&process), workspace.clone(), workspace);
+ let explicit = Arc::new(SecurityPolicy {
+ autonomy: AutonomyLevel::ReadOnly,
+ ..SecurityPolicy::default()
+ });
+ let ambient = Arc::new(SecurityPolicy {
+ autonomy: AutonomyLevel::Full,
+ ..SecurityPolicy::default()
+ });
+ let explicit_ctx =
+ crate::core::runtime::DispatchCtx::new(agent_context(Some(Arc::clone(&explicit))));
+
+ let seen = crate::core::runtime::CoreContext::scope(agent_context(Some(ambient)), async {
+ effective_in(&explicit_ctx)
+ })
+ .await;
+
+ assert!(Arc::ptr_eq(&seen.expect("explicit policy"), &explicit));
+}