Skip to content

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

test(profiles): cover host-only admission and profile reopen

Steven Enamakeldd674380a95f
diff --git a/crates/openhuman-embed/src/profiles/host_tests.rs b/crates/openhuman-embed/src/profiles/host_tests.rs
index 8807b87b35..c412a8e77b 100644
--- a/crates/openhuman-embed/src/profiles/host_tests.rs
+++ b/crates/openhuman-embed/src/profiles/host_tests.rs
@@ -66,3 +66,22 @@ fn profiles_keep_a_nonempty_readonly_permission_map_without_operator_grants() {
.values()
.all(|level| level == "readonly"));
}
+
+
+#[test]
+fn host_only_admission_does_not_authorize_supervised_mutation_or_unknown_channels() {
+ let config = SaasConfig::new("/srv/openhuman");
+ let options = ProfileHostOptions {
+ scope: Some(ToolScopeSpec::HostOnly),
+ permission: Some(Arc::new(crate::permission::PermissionHook::new(|_| {
+ Box::pin(async { crate::seams::ToolHookDecision::Proceed })
+ }))),
+ channels: HashMap::from([("telegram".into(), PermissionLevel::Execute)]),
+ ..Default::default()
+ };
+ let capabilities = options.finish(&config).unwrap();
+ assert!(capabilities.admits("custom_host_mutation"));
+ assert!(!capabilities.authorizes_approval("custom_host_mutation"));
+ assert_eq!(capabilities.channel_permission("telegram"), PermissionLevel::Execute);
+ assert_eq!(capabilities.channel_permission("unknown_channel"), PermissionLevel::ReadOnly);
+}
diff --git a/crates/openhuman-embed/tests/profile_host_capabilities.rs b/crates/openhuman-embed/tests/profile_host_capabilities.rs
index b12a881f99..0ee0ddc2f4 100644
--- a/crates/openhuman-embed/tests/profile_host_capabilities.rs
+++ b/crates/openhuman-embed/tests/profile_host_capabilities.rs
@@ -8,7 +8,7 @@ use std::time::Duration;
use common::{
chat_completion, chat_requests, runtime_without_master_key, tool_call_completion, tool_names,
- tool_results, PointedTransport,
+ PointedTransport,
};
use openhuman_embed::memory::api::conformance::ReferenceEngine;
use openhuman_embed::memory::api::{LearningKind, MemoryEngine, MemoryMeta, StoreItem};
@@ -89,13 +89,16 @@ struct CallTools;
impl Respond for CallTools {
fn respond(&self, request: &Request) -> ResponseTemplate {
let body: Value = serde_json::from_slice(&request.body).unwrap();
- let completion = if common::last_user_message(&body).contains("deny callback request") && tool_results(request).is_empty() {
+ let messages = body["messages"].as_array().unwrap();
+ let last_user = messages.iter().rposition(|message| message["role"] == "user").unwrap();
+ let has_tool_results = messages[last_user + 1..].iter().any(|message| message["role"] == "tool");
+ let completion = if common::last_user_message(&body).contains("deny callback request") && !has_tool_results {
tool_call_completion("tenant_probe", r#"{"deny":true}"#)
} else if common::last_user_message(&body).contains("unsafe fixture request") {
let mut completion = tool_call_completion("shell", "{}");
completion["choices"][0]["message"]["tool_calls"] = json!(["shell", "delegate", "http_request", "run_workflow"].iter().enumerate().map(|(i, name)| json!({"id":format!("unsafe_{i}"),"type":"function","function":{"name":name,"arguments":"{}"}})).collect::<Vec<_>>());
completion
- } else if !tool_results(request).is_empty()
+ } else if has_tool_results
|| !tool_names(request)
.iter()
.any(|name| name == "tenant_probe")
@@ -386,6 +389,36 @@ async fn scenario() {
.scope(closed_hook.before_tool_decision(&hook_context))
.await
.is_deny());
+ // Closing really releases the old lease; reopening must install the same
+ // immutable belt and engine on a fresh profile context, without pinning it.
+ drop(alice_profile);
+ let old_alice = handles.remove(0);
+ let alice_id = old_alice.id().clone();
+ drop(old_alice);
+ tokio::time::timeout(Duration::from_secs(30), async {
+ loop {
+ match runtime.release(&alice_id).await {
+ Ok(released) => { assert!(released); break; }
+ Err(_) => tokio::time::sleep(Duration::from_millis(20)).await,
+ }
+ }
+ }).await.expect("completed turns leave the profile releasable");
+ let reopened = runtime.open("alice").await.unwrap();
+ assert!(reopened.threads().await.unwrap().iter().any(|thread| thread.id == "t1"));
+ reopened.chat("t1", "alice: call tenant_probe after reopening").await.unwrap();
+ let mut events = reopened.events();
+ assert!(reopened.relay_inbound(RelayMessage::new("telegram", "chat", "sender", "message", "alice: call tenant_probe after reopening")).await.unwrap().accepted);
+ tokio::time::timeout(Duration::from_secs(30), async {
+ while events.recv().await.unwrap().event != "channel_outbound" {}
+ }).await.unwrap();
+ assert_eq!(&calls.lock().unwrap()[4..], ["tenant_probe:alice", "tenant_probe:alice"]);
+ let reopened_sessions = sessions.lock().unwrap();
+ assert_eq!(&reopened_sessions[reopened_sessions.len() - 2..], [("alice".into(), Some("t1".into())), ("alice".into(), Some("channel:telegram/sender/chat".into()))]);
+ drop(reopened_sessions);
+ handles.insert(0, reopened);
+ let alice_profile = handles[0].scope(async { openhuman_core::profiles::current().unwrap() }).await;
+ let alice_hook = handles[0].context().host_overrides().unwrap().tool_hooks().into_iter().find(|hook| hook.name() == "profile.can_use_tool").unwrap();
+ assert!(matches!(handles[0].scope(alice_hook.before_tool_decision(&hook_context)).await, ToolHookDecision::Proceed));
let requests = chat_requests(&inference).await;
assert!(requests
.iter()