Files
codex/codex-rs/app-server/tests/suite/v2/environment_add.rs
Adam Perry @ OpenAI dbd2df27d1 test: migrate TestAppServer callers to builder (#31451)
## Why

Keep the TestAppServer builder API change reviewable by moving the
repository-wide caller migration into a mechanical follow-up.

## What

- replace TestAppServer constructor callsites with equivalent builder
chains
- preserve each caller's automatic-environment, args, program, env,
managed-config, plugin-startup, and JSON-logging behavior
- make no TestAppServer implementation changes

## Validation

- cargo check -p codex-app-server --tests

## Cleanup stack

1. [#31425 test: add TestAppServer
builder](https://github.com/openai/codex/pull/31425)
2. [#31451 test: migrate TestAppServer callers to
builder](https://github.com/openai/codex/pull/31451)
3. [#31452 test: remove TestAppServer
constructors](https://github.com/openai/codex/pull/31452)
2026-07-08 00:15:49 +00:00

57 lines
1.9 KiB
Rust

use std::time::Duration;
use anyhow::Result;
use app_test_support::TestAppServer;
use app_test_support::to_response;
use codex_app_server_protocol::EnvironmentAddResponse;
use codex_app_server_protocol::JSONRPCResponse;
use codex_app_server_protocol::RequestId;
use serde_json::json;
use tempfile::TempDir;
use tokio::io::AsyncReadExt;
use tokio::net::TcpListener;
use tokio::time::timeout;
const RPC_TIMEOUT: Duration = Duration::from_secs(10);
const CONNECTION_CLOSE_TIMEOUT: Duration = Duration::from_secs(5);
#[tokio::test]
async fn environment_add_applies_connect_timeout() -> Result<()> {
let listener = TcpListener::bind("127.0.0.1:0").await?;
let exec_server_url = format!("ws://{}", listener.local_addr()?);
let stalled_server = tokio::spawn(async move {
let (mut socket, _) = listener.accept().await?;
let mut request = Vec::new();
socket.read_to_end(&mut request).await?;
anyhow::ensure!(!request.is_empty(), "expected a WebSocket handshake");
Ok::<_, anyhow::Error>(())
});
let codex_home = TempDir::new()?;
let mut app_server = TestAppServer::builder()
.with_codex_home(codex_home.path())
.without_auto_env()
.build()
.await?;
timeout(RPC_TIMEOUT, app_server.initialize()).await??;
let request_id = app_server
.send_raw_request(
"environment/add",
Some(json!({
"environmentId": "remote-a",
"execServerUrl": exec_server_url,
"connectTimeoutMs": 1_000,
})),
)
.await?;
let response: JSONRPCResponse = timeout(
RPC_TIMEOUT,
app_server.read_stream_until_response_message(RequestId::Integer(request_id)),
)
.await??;
let _: EnvironmentAddResponse = to_response(response)?;
timeout(CONNECTION_CLOSE_TIMEOUT, stalled_server).await???;
Ok(())
}