Skip to content

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

test(approval): split gate tests into focused modules

Steven Enamakel495b0ae83f2b
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 fdc8198a73..2f582e395e 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
@@ -212,7 +212,7 @@ async fn auto_approve_all_resolves_allow() {
let outcome = turn_origin::with_origin(
web_origin(),
- gate.intercept(&Default::default(), "noop", "openhuman_test_aaa_webchat", serde_json::json!({})),
+ gate.intercept(&ApprovalTurnContext::default(), "openhuman_test_aaa_webchat", "noop", serde_json::json!({})),
)
.await;
@@ -291,7 +291,7 @@ async fn auto_approve_all_does_not_override_unknown() {
// No `with_origin` scope at all — mirrors an unlabelled call site,
// which `turn_origin::current()` maps to `AgentTurnOrigin::Unknown`.
let outcome = gate
- .intercept(&Default::default(), "noop", "openhuman_test_aaa_unknown", serde_json::json!({}))
+ .intercept(&ApprovalTurnContext::default(), "openhuman_test_aaa_unknown", "noop", serde_json::json!({}))
.await;
match outcome {
@@ -333,7 +333,7 @@ async fn auto_approve_all_overrides_require_approval_workflow() {
};
let outcome = turn_origin::with_origin(
origin,
- gate.intercept(&Default::default(), "noop", "openhuman_test_aaa_workflow", serde_json::json!({})),
+ gate.intercept(&ApprovalTurnContext::default(), "openhuman_test_aaa_workflow", "noop", serde_json::json!({})),
)
.await;
@@ -389,10 +389,9 @@ async fn auto_approve_all_allows_a_remote_triage_dispatch_without_an_audit_row()
let outcome = turn_origin::with_origin(
remote_trigger_origin(&envelope),
- gate.intercept(
- &Default::default(),
- "escalate to orchestrator",
+ gate.intercept(&ApprovalTurnContext::default(),
"triage.escalate",
+ "escalate to orchestrator",
serde_json::json!({}),
),
)
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 450cd066a8..cae2db4f05 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
@@ -11,7 +11,7 @@ async fn intercept_with_trusted_background_origin_allows_without_prompt() {
};
let outcome = turn_origin::with_origin(
origin,
- gate.intercept(&Default::default(), "run ls", "shell", serde_json::json!({})),
+ gate.intercept(&ApprovalTurnContext::default(), "shell", "run ls", serde_json::json!({})),
)
.await;
assert!(matches!(outcome, GateOutcome::Allow));
@@ -26,7 +26,7 @@ async fn intercept_with_cli_origin_allows_without_prompt() {
let (gate, _dir) = test_gate();
let outcome = turn_origin::with_origin(
AgentTurnOrigin::Cli,
- gate.intercept(&Default::default(), "run ls", "shell", serde_json::json!({})),
+ gate.intercept(&ApprovalTurnContext::default(), "shell", "run ls", serde_json::json!({})),
)
.await;
assert!(matches!(outcome, GateOutcome::Allow));
@@ -43,7 +43,7 @@ async fn intercept_with_direct_chat_origin_allows_without_prompt() {
let (gate, _dir) = test_gate();
let outcome = turn_origin::with_origin(
AgentTurnOrigin::DirectChat,
- gate.intercept(&Default::default(), "run ls", "shell", serde_json::json!({})),
+ gate.intercept(&ApprovalTurnContext::default(), "shell", "run ls", serde_json::json!({})),
)
.await;
assert!(
@@ -78,7 +78,7 @@ async fn cron_add_on_a_turnless_spawn_resolves_to_a_real_origin_not_unknown_deni
// `Unknown`, and the scheduling tool is refused as "no origin label".
let g = gate.clone();
let denied = tokio::spawn(async move {
- g.intercept(&Default::default(), "schedule a job", "cron_add", serde_json::json!({}))
+ g.intercept(&ApprovalTurnContext::default(), "cron_add", "schedule a job", serde_json::json!({}))
.await
})
.await
@@ -96,7 +96,7 @@ async fn cron_add_on_a_turnless_spawn_resolves_to_a_real_origin_not_unknown_deni
// Master-chat gate) instead of being denied as unlabelled.
let g = gate.clone();
let allowed = tokio::spawn(turn_origin::with_origin(AgentTurnOrigin::Cli, async move {
- g.intercept(&Default::default(), "schedule a job", "cron_add", serde_json::json!({}))
+ g.intercept(&ApprovalTurnContext::default(), "cron_add", "schedule a job", serde_json::json!({}))
.await
}))
.await
@@ -128,7 +128,7 @@ async fn intercept_with_external_channel_origin_persists_and_ttl_denies() {
let handle = tokio::spawn(async move {
turn_origin::with_origin(
origin,
- g.intercept(&Default::default(), "run ls", "shell", serde_json::json!({})),
+ g.intercept(&ApprovalTurnContext::default(), "shell", "run ls", serde_json::json!({})),
)
.await
});
@@ -262,7 +262,7 @@ async fn intercept_audited_id_is_none_for_denied_some_for_approved() {
async fn flow_origin_park_populates_source_context_with_flow_and_run_id() {
// A `require_approval: true` flow still parks (same shape as before
// this change) but the persisted row must now carry the flow/run
- // correlation the turn's `flow_run` supplies —
+ // correlation the `APPROVAL_FLOW_RUN_CONTEXT` task-local supplies —
// the origin alone only carries `flow_id`, not `run_id`.
let (gate, _dir) = test_gate();
let gate = Arc::new(gate);
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 e6f4ef1979..8d80890b9b 100644
--- a/crates/openhuman-core/src/security/approval/gate_subagent_tests.rs
+++ b/crates/openhuman-core/src/security/approval/gate_subagent_tests.rs
@@ -76,12 +76,12 @@ async fn an_async_subagent_park_reaches_the_parent_thread_detached_with_a_short_
let before = chrono::Utc::now();
let g = gate.clone();
- // Origin propagated, the chat approval context not — the state
+ // Origin propagated, APPROVAL_CHAT_CONTEXT not — the state
// `spawn_async_subagent` leaves its detached child in.
let handle = tokio::spawn(async move {
turn_origin::with_origin(
async_subagent_origin("thread-parent"),
- g.intercept(&Default::default(), "generate an image", tool, serde_json::json!({})),
+ g.intercept(&ApprovalTurnContext::default(), tool, "generate an image", serde_json::json!({})),
)
.await
});
@@ -207,10 +207,9 @@ async fn an_expired_park_tells_the_model_nobody_answered() {
let handle = tokio::spawn(async move {
turn_origin::with_origin(
async_subagent_origin("thread-expiry"),
- g.intercept(
- &Default::default(),
- "generate a clip",
+ g.intercept(&ApprovalTurnContext::default(),
"media_generate_video",
+ "generate a clip",
serde_json::json!({}),
),
)
@@ -250,7 +249,7 @@ async fn every_detached_park_on_a_thread_stays_recoverable() {
handles.push(tokio::spawn(async move {
turn_origin::with_origin(
async_subagent_origin("thread-multi"),
- g.intercept(&Default::default(), "generate media", tool, serde_json::json!({})),
+ g.intercept(&ApprovalTurnContext::default(), tool, "generate media", 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 1cf5203592..10e69d9da1 100644
--- a/crates/openhuman-core/src/security/approval/gate_triage_tests.rs
+++ b/crates/openhuman-core/src/security/approval/gate_triage_tests.rs
@@ -53,13 +53,11 @@ async fn a_remote_triage_escalation_parks_with_an_audit_row_rather_than_an_unkno
// `Box::pin` + a short timeout drives the future into the park without
// waiting out the TTL; nothing decides it, so it must still be pending.
- let turn = ApprovalTurnContext::default();
let mut fut = Box::pin(turn_origin::with_origin(
remote_trigger_origin(&envelope),
- gate.intercept(
- &turn,
- "escalate to orchestrator",
+ gate.intercept(&ApprovalTurnContext::default(),
"triage.escalate",
+ "escalate to orchestrator",
serde_json::json!({}),
),
));
@@ -91,10 +89,9 @@ async fn a_local_triage_escalation_is_allowed_without_a_prompt() {
let (gate, _dir) = test_gate();
let outcome = turn_origin::with_origin(
local_trigger_origin(),
- gate.intercept(
- &Default::default(),
- "escalate to orchestrator",
+ gate.intercept(&ApprovalTurnContext::default(),
"triage.escalate",
+ "escalate to orchestrator",
serde_json::json!({}),
),
)
@@ -118,7 +115,7 @@ async fn intercept_with_unknown_origin_denies() {
// tools from unlabelled call sites.
let (gate, _dir) = test_gate();
let outcome = gate
- .intercept(&Default::default(), "run ls", "shell", serde_json::json!({}))
+ .intercept(&ApprovalTurnContext::default(), "shell", "run ls", serde_json::json!({}))
.await;
match outcome {
GateOutcome::Deny { reason } => assert!(reason.contains("origin label")),
@@ -137,7 +134,7 @@ async fn intercept_with_trusted_cron_origin_denies_external_effect() {
};
let outcome = turn_origin::with_origin(
origin,
- gate.intercept(&Default::default(), "run ls", "shell", serde_json::json!({})),
+ gate.intercept(&ApprovalTurnContext::default(), "shell", "run ls", serde_json::json!({})),
)
.await;
assert!(matches!(outcome, GateOutcome::Deny { .. }));
@@ -160,7 +157,7 @@ async fn intercept_with_workflow_origin_trust_root_allows_without_prompt() {
};
let outcome = turn_origin::with_origin(
origin,
- gate.intercept(&Default::default(), "post to slack", "composio", serde_json::json!({})),
+ gate.intercept(&ApprovalTurnContext::default(), "composio", "post to slack", serde_json::json!({})),
)
.await;
assert!(matches!(outcome, GateOutcome::Allow));
@@ -190,7 +187,7 @@ async fn intercept_with_workflow_require_approval_persists_and_ttl_denies() {
let handle = tokio::spawn(async move {
turn_origin::with_origin(
origin,
- g.intercept(&Default::default(), "post to slack", "composio", serde_json::json!({})),
+ g.intercept(&ApprovalTurnContext::default(), "composio", "post to slack", serde_json::json!({})),
)
.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 01a56c6310..fb7eea0899 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
@@ -50,7 +50,7 @@ async fn pending_for_thread_tracks_request_under_chat_context_and_clears() {
/// Regression for #5499: an async-delegated sub-agent carries the `WebChat`
/// origin across the `tokio::spawn` boundary (`spawn_async_subagent` calls
-/// `turn_origin::propagate`) but NOT the chat approval context.
+/// `turn_origin::propagate`) but NOT the `APPROVAL_CHAT_CONTEXT` task-local.
/// Before the origin-routing fallback the gate parked with `thread_id:
/// None`, the web-channel surface dropped the `ApprovalRequested` event
/// ("thread/client absent — NOT surfacing"), and the park silently
@@ -64,7 +64,7 @@ async fn webchat_origin_routes_park_when_approval_chat_context_absent() {
let (gate, _dir) = test_gate();
let gate = Arc::new(gate);
- // WebChat origin scoped, but NO chat approval context — exactly the
+ // WebChat origin scoped, but NO `APPROVAL_CHAT_CONTEXT` — exactly the
// async sub-agent spawn state (origin propagated, approval context not).
let g = gate.clone();
let origin = AgentTurnOrigin::WebChat {
@@ -75,7 +75,7 @@ async fn webchat_origin_routes_park_when_approval_chat_context_absent() {
let handle = tokio::spawn(async move {
turn_origin::with_origin(
origin,
- g.intercept(&Default::default(), "schedule daily reminder", "cron_add", serde_json::json!({})),
+ g.intercept(&ApprovalTurnContext::default(), "cron_add", "schedule daily reminder", serde_json::json!({})),
)
.await
});
@@ -93,7 +93,7 @@ async fn webchat_origin_routes_park_when_approval_chat_context_absent() {
assert!(
tries < 50,
"park must be routable via the WebChat origin's thread when \
- the chat approval context is absent (#5499)"
+ APPROVAL_CHAT_CONTEXT is absent (#5499)"
);
tokio::time::sleep(Duration::from_millis(10)).await;
};
@@ -123,10 +123,9 @@ async fn waiter_future_dropped_mid_park_evicts_waiter_clears_routing_and_denies_
// `Box::pin` (not `tokio::pin!`) so `drop(fut)` below drops the *future
// itself* — and thus the `WaiterGuard` saved in its async state — rather
// than just a `Pin<&mut _>` reference.
- let turn = ApprovalTurnContext::chat(chat_ctx());
let mut fut = Box::pin(turn_origin::with_origin(
web_origin(),
- g.intercept(&turn, "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
@@ -349,8 +348,8 @@ mod resolve_park_ttl_tests {
/// persists the clamped TTL when the copilot-streaming context is scoped.
/// Builds a gate with the full `DEFAULT_APPROVAL_TTL` boot TTL (unlike
/// `test_gate()` before this suite stopped hard-coding a 2s window, which
-/// would make this assertion vacuous), sets
-/// the copilot flag alongside the chat context + WebChat
+/// would make this assertion vacuous), scopes
+/// `APPROVAL_COPILOT_STREAM_CONTEXT` alongside the chat context + WebChat
/// origin the way `flows::ops::flows_build` does in production, and
/// inspects the persisted `expires_at` on the pending row.
#[tokio::test]