mirror of
https://github.com/openai/codex.git
synced 2026-11-17 22:10:37 +00:00
Reject conflicting remote endpoints for resume and fork (#62065)
Extend the remote endpoint conflict check to `codex resume` and `codex fork` so conflicting root and subcommand `--remote` values report a command-specific error before authentication token lookup. Add regression coverage for both commands with conflicting endpoints and an unset authentication token environment variable. GitOrigin-RevId: 7fb7bc3f05d8d17d740b0d82c7cd9b327426c1fb
This commit is contained in:
@@ -1093,12 +1093,18 @@ async fn dispatch_cli(
|
||||
Some(Subcommand::Agents(options)) => Some(options),
|
||||
_ => None,
|
||||
};
|
||||
if let Some(options) = agents_options
|
||||
let session_remote = match &subcommand {
|
||||
Some(Subcommand::Agents(options)) => Some(("agents", &options.remote)),
|
||||
Some(Subcommand::Resume(options)) => Some(("resume", &options.remote)),
|
||||
Some(Subcommand::Fork(options)) => Some(("fork", &options.remote)),
|
||||
_ => None,
|
||||
};
|
||||
if let Some((command, options)) = session_remote
|
||||
&& let Some(root_endpoint) = &remote.remote
|
||||
&& let Some(agents_endpoint) = &options.remote.remote
|
||||
&& root_endpoint != agents_endpoint
|
||||
&& let Some(command_endpoint) = &options.remote
|
||||
&& root_endpoint != command_endpoint
|
||||
{
|
||||
anyhow::bail!("`codex agents` received conflicting remote server endpoints");
|
||||
anyhow::bail!("`codex {command}` received conflicting remote server endpoints");
|
||||
}
|
||||
let root_remote = agents_options
|
||||
.and_then(|options| options.remote.remote.clone())
|
||||
|
||||
@@ -652,6 +652,36 @@ fn remote_exec_rejects_conflicting_endpoints() -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tui_session_commands_reject_conflicting_remotes_before_token_lookup() -> Result<()> {
|
||||
const MISSING_TOKEN: &str = "CODEX_TEST_MISSING_TUI_REMOTE_TOKEN";
|
||||
for command in ["resume", "fork"] {
|
||||
let output = std::process::Command::new(codex_utils_cargo_bin::cargo_bin("codex")?)
|
||||
.env_remove(MISSING_TOKEN)
|
||||
.args([
|
||||
"--remote",
|
||||
"wss://a.example:443",
|
||||
"--remote-auth-token-env",
|
||||
MISSING_TOKEN,
|
||||
command,
|
||||
"--remote",
|
||||
"wss://b.example:443",
|
||||
THREAD_ID,
|
||||
])
|
||||
.output()?;
|
||||
let stderr = String::from_utf8(output.stderr)?;
|
||||
assert!(!output.status.success());
|
||||
assert!(
|
||||
stderr.contains(&format!(
|
||||
"`codex {command}` received conflicting remote server endpoints"
|
||||
)),
|
||||
"{command}: {stderr}"
|
||||
);
|
||||
assert!(!stderr.contains(MISSING_TOKEN), "{command}: {stderr}");
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn remote_session_commands_validate_config() -> Result<()> {
|
||||
let cases: &[(&[&str], &str, &str)] = &[
|
||||
|
||||
Reference in New Issue
Block a user