Skip to content

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

test(security): split approval gate tests into focused modules

Steven Enamakelb99223cd3036
diff --git a/crates/openhuman-core/src/security/approval/gate_agent_tests.rs b/crates/openhuman-core/src/security/approval/gate_agent_tests.rs
index 8011eca914..3bd57c0f6a 100644
--- a/crates/openhuman-core/src/security/approval/gate_agent_tests.rs
+++ b/crates/openhuman-core/src/security/approval/gate_agent_tests.rs
@@ -30,15 +30,12 @@ async fn gated_call(
ctx,
turn_origin::with_origin(
origin,
- APPROVAL_CHAT_CONTEXT.scope(
- chat_ctx(),
- gate.intercept_audited_bounded(
+ gate.intercept_audited_bounded(&ApprovalTurnContext::chat(chat_ctx()),
tool,
"run it",
serde_json::json!({}),
Some(Duration::from_millis(100)),
),
- ),
),
)
.await
@@ -170,10 +167,11 @@ fn park(
ctx,
turn_origin::with_origin(
web_origin(),
- APPROVAL_CHAT_CONTEXT.scope(chat_ctx(), async move {
- gate.intercept_audited("shell", "run it", serde_json::json!({}))
+ async move {
+ let turn = ApprovalTurnContext::chat(chat_ctx());
+ gate.intercept_audited(&turn, "shell", "run it", serde_json::json!({}))
.await
- }),
+ },
),
))
}
@@ -311,10 +309,11 @@ async fn an_agent_cannot_decide_a_request_the_process_parked() {
let g = Arc::clone(&gate);
let process = tokio::spawn(turn_origin::with_origin(
web_origin(),
- APPROVAL_CHAT_CONTEXT.scope(chat_ctx(), async move {
- g.intercept_audited("shell", "run it", serde_json::json!({}))
+ async move {
+ let turn = ApprovalTurnContext::chat(chat_ctx());
+ g.intercept_audited(&turn, "shell", "run it", serde_json::json!({}))
.await
- }),
+ },
));
let request_id = loop {
if let Some(request_id) = gate.pending_for_agent_thread(None, "t-test") {
diff --git a/crates/openhuman-core/src/security/approval/gate_core_flow_tests.rs b/crates/openhuman-core/src/security/approval/gate_core_flow_tests.rs
index 60f232d3a0..1a33d9e820 100644
--- a/crates/openhuman-core/src/security/approval/gate_core_flow_tests.rs
+++ b/crates/openhuman-core/src/security/approval/gate_core_flow_tests.rs
@@ -33,10 +33,7 @@ async fn approve_once_returns_allow() {
let handle = tokio::spawn(async move {
turn_origin::with_origin(
web_origin(),
- APPROVAL_CHAT_CONTEXT.scope(
- chat_ctx(),
- g.intercept("composio", "send slack", serde_json::json!({})),
- ),
+ g.intercept(&ApprovalTurnContext::chat(chat_ctx()), "composio", "send slack", serde_json::json!({})),
)
.await
});
@@ -69,10 +66,7 @@ async fn deny_returns_deny_with_reason() {
let handle = tokio::spawn(async move {
turn_origin::with_origin(
web_origin(),
- APPROVAL_CHAT_CONTEXT.scope(
- chat_ctx(),
- g.intercept("pushover", "send push", serde_json::json!({})),
- ),
+ g.intercept(&ApprovalTurnContext::chat(chat_ctx()), "pushover", "send push", serde_json::json!({})),
)
.await
});
@@ -103,10 +97,7 @@ async fn aborting_older_chat_waiter_preserves_newer_thread_route() {
let old_handle = tokio::spawn(async move {
turn_origin::with_origin(
web_origin(),
- APPROVAL_CHAT_CONTEXT.scope(
- chat_ctx(),
- old_gate.intercept("composio", "old action", serde_json::json!({})),
- ),
+ old_gate.intercept(&ApprovalTurnContext::chat(chat_ctx()), "composio", "old action", serde_json::json!({})),
)
.await
});
@@ -125,10 +116,7 @@ async fn aborting_older_chat_waiter_preserves_newer_thread_route() {
let new_handle = tokio::spawn(async move {
turn_origin::with_origin(
web_origin(),
- APPROVAL_CHAT_CONTEXT.scope(
- chat_ctx(),
- new_gate.intercept("composio", "new action", serde_json::json!({})),
- ),
+ new_gate.intercept(&ApprovalTurnContext::chat(chat_ctx()), "composio", "new action", serde_json::json!({})),
)
.await
});
@@ -193,11 +181,7 @@ async fn auto_approve_tool_skips_prompt() {
// without persisting a pending row. The shortcut runs regardless of
// origin (it's the user's persisted "Always allow" allowlist), so we
// do not need to scope an origin for this case.
- let outcome = APPROVAL_CHAT_CONTEXT
- .scope(
- chat_ctx(),
- gate.intercept(tool, "noop", serde_json::json!({})),
- )
+ let outcome = gate.intercept(&ApprovalTurnContext::chat(chat_ctx()), tool, "noop", serde_json::json!({}))
.await;
assert!(matches!(outcome, GateOutcome::Allow));
assert!(
@@ -261,10 +245,7 @@ async fn auto_approve_all_off_still_parks() {
let handle = tokio::spawn(async move {
turn_origin::with_origin(
web_origin(),
- APPROVAL_CHAT_CONTEXT.scope(
- chat_ctx(),
- g.intercept("openhuman_test_aaa_off", "noop", serde_json::json!({})),
- ),
+ g.intercept(&ApprovalTurnContext::chat(chat_ctx()), "openhuman_test_aaa_off", "noop", serde_json::json!({})),
)
.await
});
@@ -434,10 +415,7 @@ async fn timeout_returns_deny() {
let handle = tokio::spawn(async move {
turn_origin::with_origin(
web_origin(),
- APPROVAL_CHAT_CONTEXT.scope(
- chat_ctx(),
- g.intercept("composio", "timed out", serde_json::json!({})),
- ),
+ g.intercept(&ApprovalTurnContext::chat(chat_ctx()), "composio", "timed out", serde_json::json!({})),
)
.await
});
@@ -472,14 +450,11 @@ async fn cancel_flow_run_parks_for_approval_when_a_gate_is_present() {
let handle = tokio::spawn(async move {
turn_origin::with_origin(
web_origin(),
- APPROVAL_CHAT_CONTEXT.scope(
- chat_ctx(),
- g.intercept(
+ g.intercept(&ApprovalTurnContext::chat(chat_ctx()),
"cancel_flow_run",
"cancel run r-1 of flow f-1",
serde_json::json!({ "flow_id": "f-1", "run_id": "r-1" }),
),
- ),
)
.await
});
diff --git a/crates/openhuman-core/src/security/approval/gate_forced_tests.rs b/crates/openhuman-core/src/security/approval/gate_forced_tests.rs
index c0f32e828e..5858cf0622 100644
--- a/crates/openhuman-core/src/security/approval/gate_forced_tests.rs
+++ b/crates/openhuman-core/src/security/approval/gate_forced_tests.rs
@@ -9,14 +9,11 @@ async fn forced_approval_parks_with_autonomy_disabled_and_releases_exact_request
let handle = tokio::spawn(async move {
turn_origin::with_origin(
web_origin(),
- APPROVAL_CHAT_CONTEXT.scope(
- chat_ctx(),
- worker.intercept_forced(
+ worker.intercept_forced(
"browser",
"Click Submit on checkout",
serde_json::json!({"action": "click", "target": "Submit"}),
),
- ),
)
.await
});
@@ -43,11 +40,7 @@ async fn forced_approval_parks_with_autonomy_disabled_and_releases_exact_request
#[tokio::test]
async fn forced_approval_denies_without_routable_web_chat_origin() {
let (gate, _dir) = test_gate();
- let outcome = APPROVAL_CHAT_CONTEXT
- .scope(
- chat_ctx(),
- gate.intercept_forced("browser", "click", serde_json::json!({})),
- )
+ let outcome = gate.intercept_forced("browser", "click", serde_json::json!({}))
.await;
assert!(matches!(outcome, GateOutcome::Deny { .. }));
assert!(gate.list_pending().unwrap().is_empty());
@@ -74,10 +67,7 @@ async fn forced_approval_ignores_auto_approval_and_rejects_persistent_grants() {
let handle = tokio::spawn(async move {
turn_origin::with_origin(
web_origin(),
- APPROVAL_CHAT_CONTEXT.scope(
- chat_ctx(),
- worker.intercept_forced("browser_forced_test", "click", serde_json::json!({})),
- ),
+ worker.intercept_forced("browser_forced_test", "click", serde_json::json!({})),
)
.await
});
diff --git a/crates/openhuman-core/src/security/approval/gate_origin_intercept_tests.rs b/crates/openhuman-core/src/security/approval/gate_origin_intercept_tests.rs
index e4b78f6a5d..8e7913f442 100644
--- a/crates/openhuman-core/src/security/approval/gate_origin_intercept_tests.rs
+++ b/crates/openhuman-core/src/security/approval/gate_origin_intercept_tests.rs
@@ -172,10 +172,7 @@ async fn intercept_audited_returns_request_id_only_when_allowed_and_persisted()
// turn whose origin labels it as web-routable.
turn_origin::with_origin(
web_origin(),
- APPROVAL_CHAT_CONTEXT.scope(
- chat_ctx(),
- g.intercept_audited("composio", "send slack", serde_json::json!({})),
- ),
+ g.intercept_audited(&ApprovalTurnContext::chat(chat_ctx()), "composio", "send slack", serde_json::json!({})),
)
.await
});
@@ -210,10 +207,7 @@ async fn intercept_audited_id_is_none_for_denied_some_for_approved() {
let denied = tokio::spawn(async move {
turn_origin::with_origin(
web_origin(),
- APPROVAL_CHAT_CONTEXT.scope(
- chat_ctx(),
- g.intercept_audited("composio", "send slack", serde_json::json!({})),
- ),
+ g.intercept_audited(&ApprovalTurnContext::chat(chat_ctx()), "composio", "send slack", serde_json::json!({})),
)
.await
});
@@ -234,10 +228,7 @@ async fn intercept_audited_id_is_none_for_denied_some_for_approved() {
let first = tokio::spawn(async move {
turn_origin::with_origin(
web_origin(),
- APPROVAL_CHAT_CONTEXT.scope(
- chat_ctx(),
- g.intercept_audited("pushover", "first send", serde_json::json!({})),
- ),
+ g.intercept_audited(&ApprovalTurnContext::chat(chat_ctx()), "pushover", "first send", serde_json::json!({})),
)
.await
});
@@ -280,13 +271,10 @@ async fn flow_origin_park_populates_source_context_with_flow_and_run_id() {
let handle = tokio::spawn(async move {
turn_origin::with_origin(
flow_origin("flow-1", true),
- APPROVAL_FLOW_RUN_CONTEXT.scope(
- FlowRunContext {
+ g.intercept_audited(&ApprovalTurnContext::default().with_flow_run(FlowRunContext {
flow_id: "flow-1".to_string(),
run_id: "run-1".to_string(),
- },
- g.intercept_audited("composio", "post to slack", serde_json::json!({})),
- ),
+ }), "composio", "post to slack", serde_json::json!({})),
)
.await
});
@@ -331,10 +319,7 @@ async fn chat_origin_park_has_no_source_context() {
let handle = tokio::spawn(async move {
turn_origin::with_origin(
web_origin(),
- APPROVAL_CHAT_CONTEXT.scope(
- chat_ctx(),
- g.intercept_audited("composio", "send slack", serde_json::json!({})),
- ),
+ g.intercept_audited(&ApprovalTurnContext::chat(chat_ctx()), "composio", "send slack", serde_json::json!({})),
)
.await
});
@@ -371,13 +356,10 @@ async fn flow_tool_trust_auto_allows_before_parking() {
let outcome = turn_origin::with_origin(
flow_origin("flow-trusted", true),
- APPROVAL_FLOW_RUN_CONTEXT.scope(
- FlowRunContext {
+ gate.intercept(&ApprovalTurnContext::default().with_flow_run(FlowRunContext {
flow_id: "flow-trusted".to_string(),
run_id: "run-1".to_string(),
- },
- gate.intercept("composio", "post to slack", serde_json::json!({})),
- ),
+ }), "composio", "post to slack", serde_json::json!({})),
)
.await;
@@ -394,13 +376,10 @@ async fn flow_tool_trust_auto_allows_before_parking() {
let handle = tokio::spawn(async move {
turn_origin::with_origin(
flow_origin("flow-trusted", true),
- APPROVAL_FLOW_RUN_CONTEXT.scope(
- FlowRunContext {
+ g.intercept(&ApprovalTurnContext::default().with_flow_run(FlowRunContext {
flow_id: "flow-trusted".to_string(),
run_id: "run-1".to_string(),
- },
- g.intercept("pushover", "send push", serde_json::json!({})),
- ),
+ }), "pushover", "send push", serde_json::json!({})),
)
.await
});
@@ -439,13 +418,10 @@ async fn decide_approve_always_for_flow_then_insert_flow_trust_composes_to_auto_
let handle = tokio::spawn(async move {
turn_origin::with_origin(
flow_origin("flow-2", true),
- APPROVAL_FLOW_RUN_CONTEXT.scope(
- FlowRunContext {
+ g.intercept_audited(&ApprovalTurnContext::default().with_flow_run(FlowRunContext {
flow_id: "flow-2".to_string(),
run_id: "run-2".to_string(),
- },
- g.intercept_audited("composio", "post to slack", serde_json::json!({})),
- ),
+ }), "composio", "post to slack", serde_json::json!({})),
)
.await
});
@@ -499,13 +475,10 @@ async fn flow_origin_park_publishes_flow_approval_request_and_notification() {
let handle = tokio::spawn(async move {
turn_origin::with_origin(
flow_origin("flow-9", true),
- APPROVAL_FLOW_RUN_CONTEXT.scope(
- FlowRunContext {
+ g.intercept_audited(&ApprovalTurnContext::default().with_flow_run(FlowRunContext {
flow_id: "flow-9".to_string(),
run_id: "run-9".to_string(),
- },
- g.intercept_audited("composio", "post to slack", serde_json::json!({})),
- ),
+ }), "composio", "post to slack", serde_json::json!({})),
)
.await
});
diff --git a/crates/openhuman-core/src/security/approval/gate_subagent_tests.rs b/crates/openhuman-core/src/security/approval/gate_subagent_tests.rs
index 88325715a8..503ef95457 100644
--- a/crates/openhuman-core/src/security/approval/gate_subagent_tests.rs
+++ b/crates/openhuman-core/src/security/approval/gate_subagent_tests.rs
@@ -137,8 +137,7 @@ async fn an_inline_chat_park_is_not_detached_and_keeps_the_full_window() {
let handle = tokio::spawn(async move {
turn_origin::with_origin(
web_origin(),
- APPROVAL_CHAT_CONTEXT
- .scope(chat_ctx(), g.intercept(tool, "run", serde_json::json!({}))),
+ g.intercept(&ApprovalTurnContext::chat(chat_ctx()), tool, "run", serde_json::json!({})),
)
.await
});
@@ -176,16 +175,13 @@ async fn an_inline_subagent_park_uses_the_short_window_without_being_detached()
let handle = tokio::spawn(async move {
turn_origin::with_origin(
web_origin(),
- APPROVAL_CHAT_CONTEXT.scope(
- chat_ctx(),
- tinyagents_harness::context::with_run_depth(
+ tinyagents_harness::context::with_run_depth(
tinyagents_harness::context::RunDepth {
depth: 1,
max_depth: crate::agent::tinyagents::budget::MAX_SPAWN_DEPTH,
},
- g.intercept("skill_registry_install", "install", serde_json::json!({})),
+ g.intercept(&ApprovalTurnContext::chat(chat_ctx()), "skill_registry_install", "install", serde_json::json!({})),
),
- ),
)
.await
});
diff --git a/crates/openhuman-core/src/security/approval/gate_tenant_tests.rs b/crates/openhuman-core/src/security/approval/gate_tenant_tests.rs
index d238561e30..c0b6fcbd8f 100644
--- a/crates/openhuman-core/src/security/approval/gate_tenant_tests.rs
+++ b/crates/openhuman-core/src/security/approval/gate_tenant_tests.rs
@@ -56,10 +56,11 @@ fn park_as(
ctx,
turn_origin::with_origin(
web_origin(),
- APPROVAL_CHAT_CONTEXT.scope(chat_ctx(), async move {
- gate.intercept_audited("shell", "run it", serde_json::json!({}))
+ async move {
+ let turn = ApprovalTurnContext::chat(chat_ctx());
+ gate.intercept_audited(&turn, "shell", "run it", serde_json::json!({}))
.await
- }),
+ },
),
))
}
diff --git a/crates/openhuman-core/src/security/approval/gate_triage_tests.rs b/crates/openhuman-core/src/security/approval/gate_triage_tests.rs
index 9f0a405acb..6973cdf06c 100644
--- a/crates/openhuman-core/src/security/approval/gate_triage_tests.rs
+++ b/crates/openhuman-core/src/security/approval/gate_triage_tests.rs
@@ -239,14 +239,11 @@ async fn a_parked_approval_is_recoverable_from_its_thread_for_replay() {
let handle = tokio::spawn(async move {
turn_origin::with_origin(
origin,
- APPROVAL_CHAT_CONTEXT.scope(
- ctx,
- g.intercept(
+ g.intercept(&ApprovalTurnContext::chat(ctx),
"create_workflow",
"create a workflow",
serde_json::json!({ "name": "nightly" }),
),
- ),
)
.await
});
@@ -300,15 +297,12 @@ async fn intercept_audited_for_call_threads_tool_call_id_onto_the_pending_row_an
let handle = tokio::spawn(async move {
turn_origin::with_origin(
web_origin(),
- APPROVAL_CHAT_CONTEXT.scope(
- chat_ctx(),
- g.intercept_audited_for_call(
+ g.intercept_audited_for_call(&ApprovalTurnContext::chat(chat_ctx()),
"composio",
"send slack",
serde_json::json!({}),
Some("call-abc"),
),
- ),
)
.await
});
@@ -343,15 +337,12 @@ async fn timeout_publishes_approval_decided_with_expired_resolution() {
let handle = tokio::spawn(async move {
turn_origin::with_origin(
web_origin(),
- APPROVAL_CHAT_CONTEXT.scope(
- chat_ctx(),
- g.intercept_audited_for_call(
+ g.intercept_audited_for_call(&ApprovalTurnContext::chat(chat_ctx()),
"composio",
"timed out",
serde_json::json!({}),
Some("call-expire"),
),
- ),
)
.await
});
diff --git a/crates/openhuman-core/src/security/approval/gate_ttl_and_triage_tests.rs b/crates/openhuman-core/src/security/approval/gate_ttl_and_triage_tests.rs
index 3fd9f9f469..713cd3f458 100644
--- a/crates/openhuman-core/src/security/approval/gate_ttl_and_triage_tests.rs
+++ b/crates/openhuman-core/src/security/approval/gate_ttl_and_triage_tests.rs
@@ -24,7 +24,7 @@ async fn pending_for_thread_tracks_request_under_chat_context_and_clears() {
let handle = tokio::spawn(async move {
turn_origin::with_origin(
origin,
- APPROVAL_CHAT_CONTEXT.scope(ctx, g.intercept("shell", "run ls", serde_json::json!({}))),
+ g.intercept(&ApprovalTurnContext::chat(ctx), "shell", "run ls", serde_json::json!({})),
)
.await
});
@@ -125,10 +125,7 @@ async fn waiter_future_dropped_mid_park_evicts_waiter_clears_routing_and_denies_
// than just a `Pin<&mut _>` reference.
let mut fut = Box::pin(turn_origin::with_origin(
web_origin(),
- APPROVAL_CHAT_CONTEXT.scope(
- chat_ctx(),
- g.intercept("shell", "run rm", serde_json::json!({})),
- ),
+ g.intercept(&ApprovalTurnContext::chat(chat_ctx()), "shell", "run rm", serde_json::json!({})),
));
// Poll it just long enough to register the waiter, persist the pending
@@ -205,15 +202,12 @@ async fn intercept_audited_bounded_abandons_park_and_leaves_row_pending() {
let handle = tokio::spawn(async move {
turn_origin::with_origin(
origin,
- APPROVAL_CHAT_CONTEXT.scope(
- ctx,
- g.intercept_audited_bounded(
+ g.intercept_audited_bounded(&ApprovalTurnContext::chat(ctx),
"shell",
"run ls",
serde_json::json!({}),
Some(Duration::from_millis(100)),
),
- ),
)
.await
});
@@ -374,13 +368,7 @@ async fn copilot_streaming_park_persists_the_clamped_expiry() {
let handle = tokio::spawn(async move {
turn_origin::with_origin(
web_origin(),
- APPROVAL_CHAT_CONTEXT.scope(
- chat_ctx(),
- APPROVAL_COPILOT_STREAM_CONTEXT.scope(
- (),
- g.intercept("composio", "send slack", serde_json::json!({})),
- ),
- ),
+ g.intercept(&ApprovalTurnContext::chat(chat_ctx()).with_copilot_stream(), "composio", "send slack", serde_json::json!({})),
)
.await
});