Lightweight coding agent that runs in your terminal
Rust
Clarify API key login and status messages (#55407)
Felipe Coury1ccc0d64e80f
diff --git a/codex-rs/cli/src/login.rs b/codex-rs/cli/src/login.rsindex 1d6421b060..b6836c33ef 100644--- a/codex-rs/cli/src/login.rs+++ b/codex-rs/cli/src/login.rs@@ -46,6 +46,7 @@ const API_KEY_LOGIN_DISABLED_MESSAGE: &str =const ACCESS_TOKEN_LOGIN_DISABLED_MESSAGE: &str ="Access token login is disabled. Use API key login instead.";const LOGIN_SUCCESS_MESSAGE: &str = "Successfully logged in";+const API_KEY_AUTHENTICATION_NOTICE: &str = "Authentication is checked when you send a request.";const DEFAULT_LOGIN_LOG_FILTER: &str ="codex_cli=info,codex_core=info,codex_login=info,codex_otel::auth_storage=warn";@@ -228,7 +229,7 @@ pub async fn run_login_with_api_key(config.auth_keyring_backend_kind(),) {Ok(_) => {- eprintln!("{LOGIN_SUCCESS_MESSAGE}");+ eprintln!("API key saved. {API_KEY_AUTHENTICATION_NOTICE}");std::process::exit(0);}Err(e) => {@@ -468,7 +469,8 @@ pub async fn run_login_status(cli_config_overrides: CliConfigOverrides) -> ! {Ok(Some(auth)) => match auth.auth_mode() {AuthMode::ApiKey => match auth.get_token() {Ok(api_key) => {- eprintln!("Logged in using an API key - {}", safe_format_key(&api_key));+ eprintln!("API key configured - {}", safe_format_key(&api_key));+ eprintln!("{API_KEY_AUTHENTICATION_NOTICE}");std::process::exit(0);}Err(e) => {diff --git a/codex-rs/cli/tests/login.rs b/codex-rs/cli/tests/login.rsindex 810ecadaed..00f4af1365 100644--- a/codex-rs/cli/tests/login.rs+++ b/codex-rs/cli/tests/login.rs@@ -52,22 +52,38 @@ fn login_with_api_key_reads_stdin_and_writes_auth_json() -> Result<()> {write_file_auth_config(codex_home.path())?;let mut cmd = codex_command(codex_home.path())?;- cmd.args([- "-c",- "forced_login_method=\"api\"",- "login",- "--with-api-key",- ])- .write_stdin("sk-test\n")- .assert()- .success()- .stderr(contains("Successfully logged in"));+ let login = cmd+ .args([+ "-c",+ "forced_login_method=\"api\"",+ "login",+ "--with-api-key",+ ])+ .write_stdin("sk-test\n")+ .assert()+ .success();+ insta::assert_snapshot!(String::from_utf8_lossy(&login.get_output().stderr), @r"+ Reading API key from stdin...+ API key saved. Authentication is checked when you send a request.+ ");let auth = read_auth_json(codex_home.path())?;assert_eq!(auth["OPENAI_API_KEY"], "sk-test");assert!(auth.get("tokens").is_none());assert!(auth.get("agent_identity").is_none());+ let status = codex_command(codex_home.path())?+ .env_remove(CODEX_ACCESS_TOKEN_ENV_VAR)+ .env_remove(OPENAI_FEDERATION_RULE_ID_ENV_VAR)+ .env_remove(OPENAI_IDENTITY_TOKEN_FILE_ENV_VAR)+ .args(["login", "status"])+ .assert()+ .success();+ insta::assert_snapshot!(String::from_utf8_lossy(&status.get_output().stderr), @r"+ API key configured - ***+ Authentication is checked when you send a request.+ ");+Ok(())}