Skip to content

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

test: migrate approval gate tests to ApprovalTurnContext

Steven Enamakel6a9fbd48a4c7
diff --git a/tests/raw_coverage/tool_registry_approval_raw_coverage_e2e.rs b/tests/raw_coverage/tool_registry_approval_raw_coverage_e2e.rs
index 15fa119029..b8a2b87c35 100644
--- a/tests/raw_coverage/tool_registry_approval_raw_coverage_e2e.rs
+++ b/tests/raw_coverage/tool_registry_approval_raw_coverage_e2e.rs
@@ -22,7 +22,7 @@ use openhuman_core::core::auth::{init_rpc_token, CORE_TOKEN_ENV_VAR};
use openhuman_core::mcp::registry::connections;
use openhuman_core::mcp::registry::types::{CommandKind, InstalledServer, Transport};
use openhuman_core::security::approval::gate::{
- ApprovalChatContext, ApprovalGate, APPROVAL_CHAT_CONTEXT,
+ ApprovalChatContext, ApprovalGate, ApprovalTurnContext,
};
use openhuman_core::security::approval::{
all_approval_controller_schemas, all_approval_registered_controllers, ExecutionOutcome,
@@ -692,17 +692,16 @@ async fn approval_rpc_decision_paths_persist_always_allow_and_recent_audit() {
client_id: "approval-raw-client".to_string(),
request_id: None,
},
- APPROVAL_CHAT_CONTEXT.scope(
- ApprovalChatContext {
+ async move {
+ let turn = ApprovalTurnContext::chat(ApprovalChatContext {
thread_id: "approval-raw-thread".to_string(),
client_id: "approval-raw-client".to_string(),
// No turn in scope in this fixture; the field is documented as
// carried only when the caller has one (`gate.rs:91-95`).
request_id: None,
- },
- async move {
+ });
gate_for_task
- .intercept_audited(
+ .intercept_audited(&turn,
"tools.composio_execute",
"tools.composio_execute(action=execute, 123 bytes)",
json!({
@@ -713,7 +712,6 @@ async fn approval_rpc_decision_paths_persist_always_allow_and_recent_audit() {
)
.await
},
- ),
)
.await
});
@@ -909,21 +907,17 @@ async fn approval_rpc_decision_paths_persist_always_allow_and_recent_audit() {
config.workspace_dir.clone(),
config.workspace_dir.clone(),
);
- let live_policy_auto_approved = APPROVAL_CHAT_CONTEXT
- .scope(
- ApprovalChatContext {
+ let live_policy_auto_approved = gate.intercept_audited(&ApprovalTurnContext::chat(ApprovalChatContext {
thread_id: "approval-live-policy-thread".to_string(),
client_id: "approval-live-policy-client".to_string(),
// No turn in scope in this fixture; the field is documented as
// carried only when the caller has one (`gate.rs:91-95`).
request_id: None,
- },
- gate.intercept_audited(
+ }),
"tools.live_policy_allowed",
"tools.live_policy_allowed(action=coverage)",
json!({ "action": "coverage" }),
- ),
- )
+ )
.await;
assert!(matches!(live_policy_auto_approved.0, GateOutcome::Allow));
assert_eq!(live_policy_auto_approved.1, None);
@@ -939,24 +933,22 @@ async fn approval_rpc_decision_paths_persist_always_allow_and_recent_audit() {
client_id: "approval-deny-client".to_string(),
request_id: None,
},
- APPROVAL_CHAT_CONTEXT.scope(
- ApprovalChatContext {
+ async move {
+ let turn = ApprovalTurnContext::chat(ApprovalChatContext {
thread_id: "approval-deny-thread".to_string(),
client_id: "approval-deny-client".to_string(),
// No turn in scope in this fixture; the field is documented as
// carried only when the caller has one (`gate.rs:91-95`).
request_id: None,
- },
- async move {
+ });
gate_for_deny_task
- .intercept_audited(
+ .intercept_audited(&turn,
"tools.web_search",
"tools.web_search(query=deny)",
json!({ "query": "deny" }),
)
.await
},
- ),
)
.await
});
@@ -1065,20 +1057,17 @@ async fn approval_rpc_decision_paths_persist_always_allow_and_recent_audit() {
client_id: "approval-persist-failure-client".to_string(),
request_id: None,
},
- APPROVAL_CHAT_CONTEXT.scope(
- ApprovalChatContext {
+ gate.intercept_audited(&ApprovalTurnContext::chat(ApprovalChatContext {
thread_id: "approval-persist-failure-thread".to_string(),
client_id: "approval-persist-failure-client".to_string(),
// No turn in scope in this fixture; the field is documented as
// carried only when the caller has one (`gate.rs:91-95`).
request_id: None,
- },
- gate.intercept_audited(
+ }),
"tools.persistence_failure",
"tools.persistence_failure(action=coverage)",
json!({ "action": "coverage" }),
),
- ),
)
.await;
match persist_failure.0 {
diff --git a/tests/raw_coverage/worker_b_raw_coverage_e2e.rs b/tests/raw_coverage/worker_b_raw_coverage_e2e.rs
index 5c4d3a3965..19259fbcb2 100644
--- a/tests/raw_coverage/worker_b_raw_coverage_e2e.rs
+++ b/tests/raw_coverage/worker_b_raw_coverage_e2e.rs
@@ -25,7 +25,7 @@ use openhuman_core::agent::turn_origin::{self, AgentTurnOrigin};
use openhuman_core::config::Config;
use openhuman_core::core::auth::{init_rpc_token, CORE_TOKEN_ENV_VAR};
use openhuman_core::security::approval::gate::{
- ApprovalChatContext, ApprovalGate, APPROVAL_CHAT_CONTEXT,
+ ApprovalChatContext, ApprovalGate, ApprovalTurnContext,
};
use openhuman_core::security::approval::types::{ExecutionOutcome, GateOutcome};
use openhuman_core::security::credentials::{
@@ -609,24 +609,22 @@ async fn approval_gate_rpc_decision_resumes_parked_tool_and_records_execution()
client_id: "worker-b-client".to_string(),
request_id: None,
},
- APPROVAL_CHAT_CONTEXT.scope(
- ApprovalChatContext {
+ async move {
+ let turn = ApprovalTurnContext::chat(ApprovalChatContext {
thread_id: "worker-b-thread".to_string(),
client_id: "worker-b-client".to_string(),
// No turn in scope in this fixture; the field is documented as
// carried only when the caller has one (`gate.rs:91-95`).
request_id: None,
- },
- async move {
+ });
gate_for_task
- .intercept_audited(
+ .intercept_audited(&turn,
"tools.web_search",
"search the web for coverage",
json!({ "query": "<redacted>", "max_results": 3 }),
)
.await
},
- ),
)
.await
});