mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Add WebSocket transport to the code-mode host (#35078)
## What changed - Add a `--listen` option that accepts `stdio`, `stdio://`, or a `ws://IP:PORT` endpoint, while retaining stdio as the default. - Serve the existing length-prefixed protocol in binary WebSocket messages, with isolated connections, shared host limits, and a `/readyz` endpoint. - Reject browser-origin handshakes and contain malformed frames to the affected connection. ## Testing - Cover listen URL parsing and complete-frame encoding and decoding. - Exercise readiness, cell execution, tool callbacks, large frames, concurrent connections, malformed frames, and origin rejection through the WebSocket listener. GitOrigin-RevId: 01c8be4c6256b8ce4a3a0002440dcb3294e5f887
This commit is contained in:
1 parent
f47f28cd0d
commit
0dfa778dae
11 files changed
+946
-24
No files matched your search
@@ -0,0 +1,53 @@
|
||||
use std::net::SocketAddr;
|
||||
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
use super::ListenTransport;
|
||||
use super::parse_listen_url;
|
||||
|
||||
#[test]
|
||||
fn parse_listen_url_accepts_stdio_transports() {
|
||||
assert_eq!(
|
||||
parse_listen_url("stdio").expect("stdio listen URL should parse"),
|
||||
ListenTransport::Stdio
|
||||
);
|
||||
assert_eq!(
|
||||
parse_listen_url("stdio://").expect("stdio URL should parse"),
|
||||
ListenTransport::Stdio
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_listen_url_accepts_websocket_addresses() {
|
||||
assert_eq!(
|
||||
parse_listen_url("ws://127.0.0.1:0").expect("websocket listen URL should parse"),
|
||||
ListenTransport::WebSocket(
|
||||
"127.0.0.1:0"
|
||||
.parse::<SocketAddr>()
|
||||
.expect("valid socket address")
|
||||
)
|
||||
);
|
||||
assert_eq!(
|
||||
parse_listen_url("ws://[::1]:9000").expect("IPv6 websocket listen URL should parse"),
|
||||
ListenTransport::WebSocket(
|
||||
"[::1]:9000"
|
||||
.parse::<SocketAddr>()
|
||||
.expect("valid IPv6 socket address")
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_listen_url_rejects_invalid_transports() {
|
||||
let invalid_address = parse_listen_url("ws://localhost:9000")
|
||||
.expect_err("websocket listener requires an IP address");
|
||||
assert!(
|
||||
invalid_address
|
||||
.to_string()
|
||||
.contains("expected `ws://IP:PORT`")
|
||||
);
|
||||
|
||||
let unsupported =
|
||||
parse_listen_url("http://127.0.0.1:9000").expect_err("HTTP is not a listen transport");
|
||||
assert!(unsupported.to_string().contains("unsupported --listen URL"));
|
||||
}
|
||||
Reference in new issue
Block a user