Skip to content

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

fix(tests): release env lock before waiting for TTL expiry in approval gate tests

Steven Enamakel10464b7a735e
diff --git a/src/openhuman/security/approval/gate_tests.rs b/src/openhuman/security/approval/gate_tests.rs
index ecbc118f2d..98f7b0a0e0 100644
--- a/src/openhuman/security/approval/gate_tests.rs
+++ b/src/openhuman/security/approval/gate_tests.rs
@@ -54,7 +54,7 @@ fn test_gate_with_ttl(ttl: Duration) -> (ApprovalGate, TempDir) {
}
/// A gate for the tests that let a park expire, plus the env lock they
-/// have to hold while it does.
+/// hold until the pending row captures its effective TTL.
///
/// [`ApprovalGate::effective_ttl`] reads `OPENHUMAN_APPROVAL_TTL_SECS` at
/// park time, not at construction, and this whole suite is a debug build,
@@ -64,8 +64,10 @@ fn test_gate_with_ttl(ttl: Duration) -> (ApprovalGate, TempDir) {
/// their `42`, and a row that was supposed to die in two seconds outlives
/// the test that is waiting for it instead.
///
-/// The guard is returned rather than dropped here: holding it only while
-/// the gate is built would leave the window open for the park itself.
+/// Callers drop the returned guard after observing the pending row. Holding
+/// it only while the gate is built would leave the window open for the park's
+/// initial `effective_ttl` read, while holding it through expiry serializes
+/// these tests unnecessarily.
/// `test_gate_with_ttl` must not take the lock, because the
/// `effective_ttl_*` tests call it while already holding it.
struct ExpiryEnvGuard {
diff --git a/src/openhuman/security/approval/gate_tests_part_03_tests.rs b/src/openhuman/security/approval/gate_tests_part_03_tests.rs
index 0589e94e05..34f5b8d85c 100644
--- a/src/openhuman/security/approval/gate_tests_part_03_tests.rs
+++ b/src/openhuman/security/approval/gate_tests_part_03_tests.rs
@@ -165,8 +165,11 @@ async fn intercept_with_external_channel_origin_persists_and_ttl_denies() {
tokio::time::sleep(Duration::from_millis(10)).await;
}
+ // The TTL was captured when the row was inserted; release the process-wide
+ // environment lock before waiting so expiry tests can run concurrently.
+ drop(env);
// Without a routable channel approval surface, the parked future
- // TTL-denies (2s — matches the test_gate fixture).
+ // TTL-denies after `EXPIRY_TEST_TTL`.
let outcome = handle.await.unwrap();
match outcome {
GateOutcome::Deny { reason } => assert!(reason.contains("timed out")),
@@ -383,7 +386,7 @@ async fn flow_tool_trust_auto_allows_before_parking() {
//
// The second half of this test *does* wait a park out, so it needs the
// short window even though it never inspects the "timed out" reason.
- let (gate, _dir, _env) = expiry_gate();
+ let (gate, _dir, env) = expiry_gate();
store::insert_flow_trust(&gate.config, "flow-trusted", "composio").unwrap();
let outcome = turn_origin::with_origin(
@@ -424,7 +427,10 @@ async fn flow_tool_trust_auto_allows_before_parking() {
let mut tries = 0;
while gate.list_pending().unwrap().is_empty() {
tries += 1;
- assert!(tries < 50, "audit row never appeared for untrusted flow tool");
+ assert!(
+ tries < 50,
+ "audit row never appeared for untrusted flow tool"
+ );
tokio::time::sleep(Duration::from_millis(10)).await;
}
drop(env);