Skip to content

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

chore: files changed crates/openhuman-core/src/core/runtime/agent_scope_tests.rs,crates/openhuman-co

Steven Enamakeld3ad70611a42
diff --git a/crates/openhuman-core/src/core/runtime/agent_scope_tests.rs b/crates/openhuman-core/src/core/runtime/agent_scope_tests.rs
index 63b3b683d2..9fc17b7744 100644
--- a/crates/openhuman-core/src/core/runtime/agent_scope_tests.rs
+++ b/crates/openhuman-core/src/core/runtime/agent_scope_tests.rs
@@ -43,6 +43,13 @@ fn every_agent_context_owns_its_slots() {
#[test]
fn autonomy_tier_source_and_ceiling_survive_derived_contexts() {
let parent = root("/tmp/autonomy-source-parent");
+ let live_child = parent.derive_with(overlay("/tmp/autonomy-source-live-child"));
+ assert_eq!(
+ live_child.autonomy_tier_source(),
+ crate::core::runtime::AutonomyTierSource::LiveConfig,
+ "an overlay without a source override inherits the live parent binding"
+ );
+
let fixed = parent.derive_with(
overlay("/tmp/autonomy-source-fixed")
.captured_autonomy_tier()
diff --git a/crates/openhuman-core/src/flows/tinyflows/caps/ops_tier_live_config_tests.rs b/crates/openhuman-core/src/flows/tinyflows/caps/ops_tier_live_config_tests.rs
index b561357000..9de224ff90 100644
--- a/crates/openhuman-core/src/flows/tinyflows/caps/ops_tier_live_config_tests.rs
+++ b/crates/openhuman-core/src/flows/tinyflows/caps/ops_tier_live_config_tests.rs
@@ -40,7 +40,21 @@ async fn one_live_capability_observes_full_readonly_full_updates() {
let dir = tempfile::tempdir().unwrap();
let mut config = persisted_tier_config(dir.path(), true, AutonomyLevel::Full);
save_tier_config(&config).await;
- let ctx = live_tier_context(&config);
+ let mut decoy = persisted_tier_config(
+ &dir.path().join("decoy-profile"),
+ true,
+ AutonomyLevel::ReadOnly,
+ );
+ save_tier_config(&decoy).await;
+ decoy.autonomy.level = AutonomyLevel::ReadOnly;
+ let origin = crate::agent::turn_origin::AgentTurnOrigin::TrustedAutomation {
+ job_id: "issue48-flow-run".to_string(),
+ source: crate::agent::turn_origin::TrustedAutomationSource::Workflow {
+ require_approval: true,
+ },
+ };
+ let ctx = live_tier_context(&config).with_turn_origin(origin.clone());
+ assert_eq!(ctx.turn_origin(), Some(origin.clone()));
let mut baseline =
SecurityPolicy::from_config(&config.autonomy, &config.workspace_dir, &config.action_dir);
baseline.trusted_roots.push(crate::security::TrustedRoot {
@@ -60,6 +74,11 @@ async fn one_live_capability_observes_full_readonly_full_updates() {
.unwrap(),
GateDecision::Allow
);
+ assert_eq!(
+ ctx.turn_origin(),
+ Some(origin.clone()),
+ "refreshing the policy must retain the dispatch's workflow origin"
+ );
config.autonomy.level = AutonomyLevel::ReadOnly;
save_tier_config(&config).await;
assert!(
@@ -77,6 +96,7 @@ async fn one_live_capability_observes_full_readonly_full_updates() {
GateDecision::Allow,
"a config-derived tier must be allowed to upgrade again"
);
+ assert_eq!(ctx.turn_origin(), Some(origin));
}
#[tokio::test]
@@ -288,7 +308,7 @@ async fn native_adapter_uses_live_upgrade_for_filesystem_write() {
use crate::security::{AutonomyLevel, SecurityPolicy};
let dir = tempfile::tempdir().unwrap();
- let mut captured = persisted_tier_config(dir.path(), true, AutonomyLevel::ReadOnly);
+ let captured = persisted_tier_config(dir.path(), true, AutonomyLevel::ReadOnly);
save_tier_config(&captured).await;
let mut live = captured.clone();
live.autonomy.level = AutonomyLevel::Full;
@@ -318,6 +338,57 @@ async fn native_adapter_uses_live_upgrade_for_filesystem_write() {
);
}
+#[tokio::test]
+async fn native_adapter_downgrade_blocks_a_write_on_the_same_capability() {
+ use crate::security::{AutonomyLevel, SecurityPolicy};
+
+ let dir = tempfile::tempdir().unwrap();
+ let mut captured = persisted_tier_config(dir.path(), true, AutonomyLevel::Full);
+ save_tier_config(&captured).await;
+ let ctx = live_tier_context(&captured);
+ let tools = OpenHumanTools {
+ ctx,
+ config: Arc::new(captured.clone()),
+ security: Arc::new(SecurityPolicy::from_config(
+ &captured.autonomy,
+ &captured.workspace_dir,
+ &captured.action_dir,
+ )),
+ approval: Default::default(),
+ };
+
+ tools
+ .invoke(
+ "oh:file_write",
+ json!({ "path": "tier-downgrade.txt", "content": "before" }),
+ None,
+ )
+ .await
+ .expect("Full permits the initial write");
+ let path = captured.action_dir.join("tier-downgrade.txt");
+ assert_eq!(std::fs::read_to_string(&path).unwrap(), "before");
+
+ captured.autonomy.level = AutonomyLevel::ReadOnly;
+ save_tier_config(&captured).await;
+ let error = tools
+ .invoke(
+ "oh:file_write",
+ json!({ "path": "tier-downgrade.txt", "content": "after" }),
+ None,
+ )
+ .await
+ .expect_err("the same long-lived capability must observe ReadOnly");
+ assert!(matches!(
+ error,
+ EngineError::Capability(ref message) if message.contains(POLICY_BLOCKED_MARKER)
+ ));
+ assert_eq!(
+ std::fs::read_to_string(path).unwrap(),
+ "before",
+ "the denied call must not modify the existing file"
+ );
+}
+
#[tokio::test]
async fn http_adapter_passes_its_live_upgrade_to_the_http_gate_without_egress() {
use crate::security::{AutonomyLevel, SecurityPolicy};
@@ -355,9 +426,9 @@ async fn http_adapter_passes_its_live_upgrade_to_the_http_gate_without_egress()
EngineError::Capability(message) => message,
other => panic!("expected capability error, got {other:?}"),
};
- assert!(
- !message.contains("autonomy is read-only"),
- "downstream NetGate used the stale ReadOnly policy: {message}"
+ assert_eq!(
+ message, "Invalid URL",
+ "the refreshed policy must pass the inner NetGate and reach URL validation"
);
}
diff --git a/crates/openhuman-embed/src/agent/build_tests.rs b/crates/openhuman-embed/src/agent/build_tests.rs
index 76bace8723..25ac34aba8 100644
--- a/crates/openhuman-embed/src/agent/build_tests.rs
+++ b/crates/openhuman-embed/src/agent/build_tests.rs
@@ -24,6 +24,52 @@ fn agent_ids_must_be_plain_names() {
assert!(validate_agent_id("../escape").is_err());
}
+#[tokio::test]
+async fn config_fn_final_autonomy_is_captured_on_the_built_agent_context() {
+ use openhuman_core::config::Config;
+ use openhuman_core::core::runtime::AutonomyTierSource;
+ use openhuman_core::security::AutonomyLevel;
+
+ let dir = tempfile::tempdir().unwrap();
+ let mut config = Config::default();
+ config.config_path = dir.path().join("config.toml");
+ config.workspace_dir = dir.path().join("workspace");
+ config.action_dir = dir.path().join("action");
+ config.autonomy.enabled = true;
+ config.autonomy.level = AutonomyLevel::ReadOnly;
+ config.save().await.unwrap();
+
+ let runtime = crate::runtime::RuntimeBuilder::new()
+ .config(config)
+ .services(openhuman_core::core::runtime::ServiceSet::none())
+ .build()
+ .await
+ .expect("runtime with a file-backed ReadOnly config");
+ let agent = runtime
+ .agent(
+ crate::AgentSpec::new("config-fn-tier")
+ .config(|effective| {
+ effective.autonomy.enabled = true;
+ effective.autonomy.level = AutonomyLevel::Full;
+ }),
+ )
+ .expect("AgentSpec config_fn builds");
+
+ assert_eq!(agent.inner.config.autonomy.level, AutonomyLevel::Full);
+ assert_eq!(
+ agent.inner.ctx.autonomy_tier_source(),
+ AutonomyTierSource::Captured
+ );
+ assert_eq!(
+ agent.inner.ctx.agent_policy().unwrap().autonomy,
+ AutonomyLevel::Full,
+ "the final config_fn tier is what the captured policy carries"
+ );
+
+ drop(agent);
+ drop(runtime);
+}
+
#[test]
fn an_agent_without_sub_agents_resolves_through_the_process_catalogue() {
let catalogue = process_catalogue();