Files
codex/codex-rs/code-mode-host/src/transport_tests.rs
Channing Conger 0dfa778dae 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
2026-07-24 02:40:11 +00:00

54 lines
1.5 KiB
Rust

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"));
}