Skip to content

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

test(plan_review): cover socket scope resolution after task handoff

Steven Enamakel9485f3925f19
diff --git a/crates/openhuman-core/src/plan_review/gate_tests.rs b/crates/openhuman-core/src/plan_review/gate_tests.rs
index 3ca8617149..aafa4156e5 100644
--- a/crates/openhuman-core/src/plan_review/gate_tests.rs
+++ b/crates/openhuman-core/src/plan_review/gate_tests.rs
@@ -280,6 +280,31 @@ fn socket_review_scope_comes_from_server_context_and_fails_closed_in_saas() {
assert!(socket_scope_from_context(Err(crate::core::runtime::tenant::NoTenant), true).is_none());
}
+#[tokio::test]
+async fn socket_scope_uses_explicit_dispatch_context_after_task_handoff() {
+ use crate::core::runtime::{ContextOverlay, CoreContext, DispatchCtx, DomainSet};
+
+ let root = CoreContext::for_test(DomainSet::full(), None);
+ let active = root.derive_with(
+ ContextOverlay::new(
+ crate::config::Config::default(),
+ DomainSet::full(),
+ crate::tools::toolpacks::ToolGroups::none(),
+ )
+ .profile("active-profile"),
+ );
+ let dispatch = DispatchCtx::new(active);
+ let gate = PlanReviewGate::new(Duration::from_secs(1));
+
+ // Socket.IO spawns its async connect callback. The task-local context is
+ // absent there; the request's explicit DispatchCtx remains the authority.
+ let scope = tokio::spawn(async move { gate.socket_scope_for_dispatch(&dispatch) })
+ .await
+ .expect("spawned callback completes")
+ .expect("request context binds socket scope");
+ assert_eq!(scope.0.profile.as_deref(), Some("active-profile"));
+}
+
#[test]
fn local_socket_review_scope_preserves_the_active_profile() {
let active_profile = Tenant {
diff --git a/crates/openhuman-rpc/src/server/socketio_tests.rs b/crates/openhuman-rpc/src/server/socketio_tests.rs
index 89edef389e..38d4124934 100644
--- a/crates/openhuman-rpc/src/server/socketio_tests.rs
+++ b/crates/openhuman-rpc/src/server/socketio_tests.rs
@@ -1,8 +1,28 @@
use super::{
channel_connection_update_payload, event_alias, origin_is_allowed_with_extra,
- publish_companion_state_changed, subscribe_companion_state_changed, ThreadSubscribePayload,
+ publish_companion_state_changed, socket_tenant_from_request_extensions,
+ subscribe_companion_state_changed, ThreadSubscribePayload,
};
+#[tokio::test]
+async fn socket_connect_reads_dispatch_context_from_request_extensions_after_spawn() {
+ let dispatch = crate::core_host::core::runtime::DispatchCtx::process_default();
+ let expected = crate::core_host::agent::plan_review::gate::global()
+ .socket_scope_for_dispatch(&dispatch);
+ let mut extensions = axum::http::Extensions::new();
+ extensions.insert(dispatch);
+
+ // Mirrors socketioxide's async connect handler boundary: request parts
+ // retain Axum extensions, while the callback itself runs in a new task.
+ let actual = tokio::spawn(async move {
+ socket_tenant_from_request_extensions(&extensions).map(|tenant| tenant.0)
+ })
+ .await
+ .expect("spawned connect callback completes");
+
+ assert_eq!(actual, expected);
+}
+
#[test]
fn thread_subscribe_cannot_choose_a_profile_for_review_replay() {
let payload = serde_json::from_value::<ThreadSubscribePayload>(serde_json::json!({