mirror of
https://github.com/openai/codex.git
synced 2026-11-16 22:00:36 +00:00
Support remote app servers in codex exec (#61707)
## What changed Allow `codex exec --remote <ADDR>` to run a noninteractive turn using an existing app server's configuration and credentials. Support starting a new thread or resuming one by UUID, with human-readable or JSON output and optional bearer-token authentication through `--remote-auth-token-env`. Accept remote options before or after `exec`, and reject conflicting endpoints. Reject unsupported agent configuration overrides and active threads, and report an error if the server disconnects before the turn completes. ## Testing Extend CLI integration coverage for remote execution and resume using server authentication, JSON completion events, human-readable thread IDs, and conflicting endpoints. Add a snapshot for `--remote` help text. GitOrigin-RevId: d4c3b16fb80eb6e8c523aff92110eaa878cbd3ee
This commit is contained in:
@@ -303,7 +303,7 @@ async fn remote_session_commands_with_workload_identity_use_server_auth() -> Res
|
||||
.respond_with(responses::sse_response(
|
||||
create_final_assistant_message_sse_response("queued message consumed")?,
|
||||
))
|
||||
.expect(2)
|
||||
.expect(4)
|
||||
.mount_as_scoped(&model)
|
||||
.await;
|
||||
MockResponsesConfig::new(&model.uri())
|
||||
@@ -417,6 +417,60 @@ async fn remote_session_commands_with_workload_identity_use_server_auth() -> Res
|
||||
let metadata: Value = serde_json::from_str(request.headers["x-codex-turn-metadata"].to_str()?)?;
|
||||
assert_eq!(metadata["turn_trigger"], "queue");
|
||||
|
||||
let exec_home = TempDir::new()?;
|
||||
for args in [
|
||||
vec!["exec", "--remote", &endpoint, "--json", "new task"],
|
||||
vec![
|
||||
"exec",
|
||||
"resume",
|
||||
"--remote",
|
||||
&endpoint,
|
||||
&thread_id,
|
||||
"continue task",
|
||||
],
|
||||
] {
|
||||
let output = Command::new(&codex)
|
||||
.env("CODEX_HOME", exec_home.path())
|
||||
.env_remove("CODEX_QUEUE_SERVER_API_KEY")
|
||||
.current_dir(exec_home.path())
|
||||
.args(args)
|
||||
.output()
|
||||
.await?;
|
||||
assert!(
|
||||
output.status.success(),
|
||||
"{}",
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
);
|
||||
let stdout = String::from_utf8(output.stdout)?;
|
||||
assert!(stdout.contains("queued message consumed"));
|
||||
if stdout.starts_with('{') {
|
||||
let events = stdout
|
||||
.lines()
|
||||
.map(serde_json::from_str::<Value>)
|
||||
.collect::<serde_json::Result<Vec<_>>>()?;
|
||||
assert_ne!(events[0]["thread_id"], thread_id);
|
||||
assert!(events.iter().any(|event| event["type"] == "turn.completed"));
|
||||
} else {
|
||||
let stderr = String::from_utf8(output.stderr)?;
|
||||
let header = stderr
|
||||
.lines()
|
||||
.find(|line| line.starts_with("thread id: "))
|
||||
.context("missing remote exec header")?
|
||||
.replace(&thread_id, "[thread-id]");
|
||||
insta::assert_snapshot!(header, @"thread id: [thread-id]");
|
||||
}
|
||||
}
|
||||
let shared: ThreadReadResponse = app
|
||||
.request_typed(ClientRequest::ThreadRead {
|
||||
request_id: RequestId::Integer(20),
|
||||
params: ThreadReadParams {
|
||||
thread_id: thread_id.clone(),
|
||||
include_turns: true,
|
||||
},
|
||||
})
|
||||
.await?;
|
||||
assert_eq!(shared.thread.turns.len(), 2);
|
||||
|
||||
let name = "remote-session-lifecycle";
|
||||
let _: ThreadSetNameResponse = app
|
||||
.request_typed(ClientRequest::ThreadSetName {
|
||||
@@ -541,7 +595,7 @@ async fn remote_session_commands_with_workload_identity_use_server_auth() -> Res
|
||||
.await?;
|
||||
let requests = model_requests.received_requests().await;
|
||||
assert!(
|
||||
requests[1].body_json::<Value>()?["input"]
|
||||
requests[3].body_json::<Value>()?["input"]
|
||||
.to_string()
|
||||
.contains(cold_message)
|
||||
);
|
||||
@@ -578,6 +632,26 @@ async fn remote_session_commands_with_workload_identity_use_server_auth() -> Res
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn remote_exec_rejects_conflicting_endpoints() -> Result<()> {
|
||||
for command in [vec!["exec"], vec!["exec", "resume"]] {
|
||||
let output = std::process::Command::new(codex_utils_cargo_bin::cargo_bin("codex")?)
|
||||
.env_remove("CODEX_TEST_REMOTE_TOKEN")
|
||||
.args([
|
||||
"--remote",
|
||||
"wss://a.example:443",
|
||||
"--remote-auth-token-env",
|
||||
"CODEX_TEST_REMOTE_TOKEN",
|
||||
])
|
||||
.args(command)
|
||||
.args(["--remote", "wss://b.example:443"])
|
||||
.output()?;
|
||||
assert!(!output.status.success());
|
||||
assert!(String::from_utf8(output.stderr)?.contains("conflicting remote server endpoints"));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn remote_session_commands_validate_config() -> Result<()> {
|
||||
let cases: &[(&[&str], &str, &str)] = &[
|
||||
|
||||
Reference in New Issue
Block a user