diff --git a/codex-rs/cli/src/login.rs b/codex-rs/cli/src/login.rs index 4291e06820..5f56eb1c4d 100644 --- a/codex-rs/cli/src/login.rs +++ b/codex-rs/cli/src/login.rs @@ -47,7 +47,7 @@ pub async fn run_login_with_api_key( pub async fn run_login_status(cli_config_overrides: CliConfigOverrides) -> ! { let config = load_config_or_exit(cli_config_overrides); - match load_auth(&config.codex_home, true) { + match load_auth(&config.codex_home) { Ok(Some(auth)) => match auth.mode { AuthMode::ApiKey => { if let Some(api_key) = auth.api_key.as_deref() { diff --git a/codex-rs/core/src/codex_wrapper.rs b/codex-rs/core/src/codex_wrapper.rs index eeb4a7b470..1e26a9ebed 100644 --- a/codex-rs/core/src/codex_wrapper.rs +++ b/codex-rs/core/src/codex_wrapper.rs @@ -26,7 +26,7 @@ pub struct CodexConversation { /// that callers can surface the information to the UI. pub async fn init_codex(config: Config) -> anyhow::Result { let ctrl_c = notify_on_sigint(); - let auth = load_auth(&config.codex_home, true)?; + let auth = load_auth(&config.codex_home)?; let CodexSpawnOk { codex, init_id, diff --git a/codex-rs/login/src/lib.rs b/codex-rs/login/src/lib.rs index a52e105628..0157c77555 100644 --- a/codex-rs/login/src/lib.rs +++ b/codex-rs/login/src/lib.rs @@ -145,7 +145,11 @@ impl CodexAuth { } // Loads the available auth information from the auth.json or OPENAI_API_KEY environment variable. -pub fn load_auth(codex_home: &Path, include_env_var: bool) -> std::io::Result> { +pub fn load_auth(codex_home: &Path) -> std::io::Result> { + _load_auth(codex_home, true) +} + +fn _load_auth(codex_home: &Path, include_env_var: bool) -> std::io::Result> { let auth_file = get_auth_file(codex_home); let auth_dot_json = try_read_auth_json(&auth_file).ok(); @@ -421,7 +425,7 @@ mod tests { fn writes_api_key_and_loads_auth() { let dir = tempdir().unwrap(); login_with_api_key(dir.path(), "sk-test-key").unwrap(); - let auth = load_auth(dir.path(), false).unwrap().unwrap(); + let auth = _load_auth(dir.path(), false).unwrap().unwrap(); assert_eq!(auth.mode, AuthMode::ApiKey); assert_eq!(auth.api_key.as_deref(), Some("sk-test-key")); } @@ -434,7 +438,7 @@ mod tests { let env_var = std::env::var(OPENAI_API_KEY_ENV_VAR); if let Ok(env_var) = env_var { - let auth = load_auth(dir.path(), true).unwrap().unwrap(); + let auth = _load_auth(dir.path(), true).unwrap().unwrap(); assert_eq!(auth.mode, AuthMode::ApiKey); assert_eq!(auth.api_key, Some(env_var)); } @@ -493,7 +497,7 @@ mod tests { mode, auth_dot_json, auth_file, - } = load_auth(dir.path(), false).unwrap().unwrap(); + } = _load_auth(dir.path(), false).unwrap().unwrap(); assert_eq!(None, api_key); assert_eq!(AuthMode::ChatGPT, mode); assert_eq!(dir.path().join("auth.json"), auth_file); @@ -558,7 +562,7 @@ mod tests { ) .unwrap(); - let auth = load_auth(dir.path(), false).unwrap().unwrap(); + let auth = _load_auth(dir.path(), false).unwrap().unwrap(); assert_eq!(auth.mode, AuthMode::ApiKey); assert_eq!(auth.api_key, Some("sk-test-key".to_string()));