Skip to content

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

test(voice): cover socket context isolation

Steven Enamakel3a8123e7d9ff
diff --git a/crates/openhuman-core/src/voice/live/ws_tests.rs b/crates/openhuman-core/src/voice/live/ws_tests.rs
index 8013e1929d..a25b5a5fbc 100644
--- a/crates/openhuman-core/src/voice/live/ws_tests.rs
+++ b/crates/openhuman-core/src/voice/live/ws_tests.rs
@@ -179,12 +179,18 @@ mod socket {
/// Serves `handle_live_voice_ws` on a loopback port with `config`.
async fn serve(config: Config) -> String {
+ serve_with(config, crate::core::runtime::DispatchCtx::unbound()).await
+ }
+
+ /// [`serve`] under an explicit context, handed to the handler.
+ async fn serve_with(config: Config, ctx: crate::core::runtime::DispatchCtx) -> String {
let config = Arc::new(config);
let app = axum::Router::new().route(
"/ws",
axum::routing::get(move |ws: axum::extract::WebSocketUpgrade| {
let config = config.clone();
- async move { ws.on_upgrade(move |socket| handle_live_voice_ws(socket, crate::core::runtime::DispatchCtx::unbound(), config)) }
+ let ctx = ctx.clone();
+ async move { ws.on_upgrade(move |socket| handle_live_voice_ws(socket, ctx, config)) }
}),
);
let listener = tokio::net::TcpListener::bind("127.0.0.1:0").await.unwrap();
@@ -219,6 +225,30 @@ mod socket {
(dir, config)
}
+ #[tokio::test]
+ async fn the_socket_runs_under_the_handed_context_not_the_task_one() {
+ // The upgraded socket is spawned off the request, so the context it
+ // runs under is the one handed in; a different context scoped on the
+ // accepting task must not leak into it.
+ let (dir, config) = config();
+ let handed = crate::core::runtime::CoreContext::for_test_with_config(
+ crate::core::runtime::DomainSet::full(),
+ config.clone(),
+ );
+ let other = crate::core::runtime::CoreContext::for_test(
+ crate::core::runtime::DomainSet::full(),
+ None,
+ );
+ let url = crate::core::runtime::CoreContext::scope(
+ other,
+ serve_with(config, crate::core::runtime::DispatchCtx::new(handed)),
+ )
+ .await;
+ let out = frames(&url, Some(WsMessage::Text(r#"{"type":"stop"}"#.into()))).await;
+ assert_eq!(out[0]["code"], "invalid_request");
+ drop(dir);
+ }
+
#[tokio::test]
async fn a_bad_first_frame_is_answered_with_an_error() {
let (_dir, config) = config();
diff --git a/crates/openhuman-rpc/src/server/http/events_tests.rs b/crates/openhuman-rpc/src/server/http/events_tests.rs
index eb2d830110..5306f9eb89 100644
--- a/crates/openhuman-rpc/src/server/http/events_tests.rs
+++ b/crates/openhuman-rpc/src/server/http/events_tests.rs
@@ -104,7 +104,8 @@ async fn events_stream_forwards_only_the_bound_client() {
let token = crate::core_host::core::event_bind_tokens::issue("stream-client", None)
.expect("bind token")
.token;
- let response = events_handler(HeaderMap::new(), None, query("stream-client", Some(&token))).await;
+ let response =
+ events_handler(HeaderMap::new(), None, query("stream-client", Some(&token))).await;
assert_eq!(response.status(), StatusCode::OK);
let mut body = response.into_body().into_data_stream();