Skip to content

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

test(embed): update hook decision calls for run context

Steven Enamakel24065534d80d
diff --git a/crates/openhuman-embed/tests/profile_host_capabilities.rs b/crates/openhuman-embed/tests/profile_host_capabilities.rs
index 4a54edec4d..666a0d65e7 100644
--- a/crates/openhuman-embed/tests/profile_host_capabilities.rs
+++ b/crates/openhuman-embed/tests/profile_host_capabilities.rs
@@ -13,7 +13,9 @@ use common::{
use openhuman_embed::memory::api::conformance::ReferenceEngine;
use openhuman_embed::memory::api::{LearningKind, MemoryEngine, MemoryMeta, StoreItem};
use openhuman_embed::profiles::ProfileCredentialKind;
-use openhuman_embed::seams::ToolHookDecision;
+use openhuman_embed::seams::{
+ OpenHumanRunContext, ToolHookContext, ToolHookDecision, ToolHookEvent,
+};
use openhuman_embed::{
HostTurnTools, PermissionLevel, ProfileRuntime, RelayMessage, SaasConfig, Tool, ToolResult,
ToolScopeSpec,
@@ -375,7 +377,21 @@ async fn scenario() {
assert_eq!(calls.lock().unwrap().len(), executions_before_denied_turn);
// Persistent hooks fail closed if reused under a different profile or
// after the owning lease is fenced, before the host callback is consulted.
- let hook_context = serde_json::from_value(json!({"event":"PreToolUse", "call_id":"fixture", "tool_name":"tenant_probe", "arguments":{}, "success":null, "duration_ms":null})).unwrap();
+ let alice_run = OpenHumanRunContext::new().with_core(Some(handles[0].context().clone()));
+ let bob_run = OpenHumanRunContext::new().with_core(Some(handles[1].context().clone()));
+ let hook_context = |tool_name: &str| ToolHookContext {
+ event: ToolHookEvent::PreToolUse,
+ call_id: "fixture".to_owned(),
+ tool_name: tool_name.to_owned(),
+ arguments: json!({}),
+ success: None,
+ duration_ms: None,
+ output: None,
+ error: None,
+ session_id: Some("t1".to_owned()),
+ agent_id: None,
+ cwd: None,
+ };
let alice_hook = handles[0]
.context()
.host_overrides()
@@ -384,14 +400,13 @@ async fn scenario() {
.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::default()
- ));
+ assert!(handles[0]
+ .scope(alice_hook.before_tool_decision(&alice_run, &hook_context("tenant_probe")))
+ .await
+ .permission
+ .is_none());
assert!(handles[1]
- .scope(alice_hook.before_tool_decision(&hook_context))
+ .scope(alice_hook.before_tool_decision(&bob_run, &hook_context("tenant_probe")))
.await
.is_deny());
for name in [
@@ -404,11 +419,9 @@ async fn scenario() {
"delegate_to",
"install_workflow_from_url",
] {
- let mut denied = hook_context.clone();
- denied.tool_name = name.to_owned();
assert!(
handles[0]
- .scope(alice_hook.before_tool_decision(&denied))
+ .scope(alice_hook.before_tool_decision(&alice_run, &hook_context(name)))
.await
.is_deny(),
"{name} must be refused even with a proceeding host callback"
@@ -434,7 +447,7 @@ async fn scenario() {
.await;
let closed_hook = no_callback.hook(handles[0].id(), alice_profile.lease_fence().clone());
assert!(handles[0]
- .scope(closed_hook.before_tool_decision(&hook_context))
+ .scope(closed_hook.before_tool_decision(&alice_run, &hook_context("tenant_probe")))
.await
.is_deny());
// Closing really releases the old lease; reopening must install the same
@@ -525,12 +538,12 @@ async fn scenario() {
.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::default()
- ));
+ let reopened_run = OpenHumanRunContext::new().with_core(Some(handles[0].context().clone()));
+ assert!(handles[0]
+ .scope(alice_hook.before_tool_decision(&reopened_run, &hook_context("tenant_probe")))
+ .await
+ .permission
+ .is_none());
let requests = chat_requests(&inference).await;
assert!(requests
.iter()
@@ -668,7 +681,7 @@ async fn scenario() {
"a latched profile must not resolve the shared engine"
);
assert!(handles[0]
- .scope(alice_hook.before_tool_decision(&hook_context))
+ .scope(alice_hook.before_tool_decision(&reopened_run, &hook_context("tenant_probe")))
.await
.is_deny());
runtime.shutdown().await;