Skip to content

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

test(security): cover agent-first policy resolution (#7032)

oxoxDeve1d0a5e0b91d
diff --git a/crates/openhuman-core/src/security/live_policy_tests.rs b/crates/openhuman-core/src/security/live_policy_tests.rs
index b4cb45fd81..436cc9edbd 100644
--- a/crates/openhuman-core/src/security/live_policy_tests.rs
+++ b/crates/openhuman-core/src/security/live_policy_tests.rs
@@ -178,3 +178,57 @@ fn set_action_dir_swaps_root_and_bumps_generation() {
"reload after set_action_dir must keep the swapped root"
);
}
+
+fn agent_context(policy: Option<Arc<SecurityPolicy>>) -> Arc<crate::core::runtime::CoreContext> {
+ use crate::core::runtime::{ContextOverlay, CoreContext, DomainSet};
+ let parent = CoreContext::for_test(DomainSet::full(), Some(std::env::temp_dir()));
+ let mut config = crate::config::Config::default();
+ config.workspace_dir = std::env::temp_dir().join("openhuman_effective_policy_test");
+ let mut overlay = ContextOverlay::new(
+ config,
+ DomainSet::kernel(),
+ crate::tools::toolpacks::ToolGroups::none(),
+ )
+ .session_agent("effective-agent");
+ overlay.agent_policy = policy;
+ parent.derive_with(overlay)
+}
+
+#[tokio::test]
+async fn effective_prefers_the_agent_policy_over_the_process_policy() {
+ let workspace = std::env::temp_dir().join("openhuman_effective_policy_test");
+ let process = Arc::new(SecurityPolicy {
+ auto_approve_all: true,
+ autonomy: AutonomyLevel::Full,
+ ..SecurityPolicy::default()
+ });
+ let _guard = install_scoped(Arc::clone(&process), workspace.clone(), workspace);
+ let agent = Arc::new(SecurityPolicy {
+ auto_approve_all: false,
+ autonomy: AutonomyLevel::ReadOnly,
+ auto_approve: vec!["agent_only_tool".into()],
+ ..SecurityPolicy::default()
+ });
+
+ let seen =
+ crate::core::runtime::CoreContext::scope(agent_context(Some(Arc::clone(&agent))), async {
+ effective().expect("agent policy")
+ })
+ .await;
+ assert!(Arc::ptr_eq(&seen, &agent));
+ assert!(!seen.auto_approve_all);
+ assert_eq!(seen.autonomy, AutonomyLevel::ReadOnly);
+
+ assert!(Arc::ptr_eq(&effective().expect("process policy"), &process));
+}
+
+#[tokio::test]
+async fn effective_falls_back_to_the_process_policy_for_an_agent_without_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 seen =
+ crate::core::runtime::CoreContext::scope(agent_context(None), async { effective() }).await;
+ assert!(Arc::ptr_eq(&seen.expect("process policy"), &process));
+}