mirror of
https://github.com/openai/codex.git
synced 2026-12-03 00:41:03 +00:00
Report workload identity authentication in codex doctor (#65142)
## Why `codex doctor` could report missing credentials when workload identity was selected and no local credentials were stored. ## What changed Use the auth manager's workload identity selection to report authentication as successful and show how to check it with `codex login status`. ## Testing Add a regression test that checks the terminal and redacted JSON reports for workload identity with no stored credentials. GitOrigin-RevId: cf385cf2cb71cc8aed95427ef83524bab4582702
This commit is contained in:
@@ -92,6 +92,9 @@ mod updates;
|
||||
#[cfg(target_os = "windows")]
|
||||
mod windows_dev_drive;
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "doctor/auth_tests.rs"]
|
||||
mod auth_tests;
|
||||
#[cfg(test)]
|
||||
#[path = "doctor/desktop_tests.rs"]
|
||||
mod desktop_tests;
|
||||
@@ -445,7 +448,7 @@ async fn build_report(
|
||||
},
|
||||
async {
|
||||
run_sync_check("auth", progress.clone(), || match &auth_manager_result {
|
||||
Ok(_) => auth_check(config),
|
||||
Ok(manager) => auth_check(config, manager.is_workload_identity_selected()),
|
||||
Err(error) => DoctorCheck::new(
|
||||
"auth.load",
|
||||
"auth",
|
||||
@@ -1227,7 +1230,7 @@ fn config_toml_details(config: &Config, details: &mut Vec<String>) {
|
||||
}
|
||||
}
|
||||
|
||||
fn auth_check(config: &Config) -> DoctorCheck {
|
||||
fn auth_check(config: &Config, workload_identity_authenticated: bool) -> DoctorCheck {
|
||||
let mut details = Vec::new();
|
||||
let auth_path = config.codex_home.join("auth.json");
|
||||
details.push(format!(
|
||||
@@ -1260,6 +1263,17 @@ fn auth_check(config: &Config) -> DoctorCheck {
|
||||
return check;
|
||||
}
|
||||
|
||||
if workload_identity_authenticated {
|
||||
return DoctorCheck::new(
|
||||
"auth.credentials",
|
||||
"auth",
|
||||
CheckStatus::Ok,
|
||||
"authenticated using workload identity",
|
||||
)
|
||||
.details(details)
|
||||
.detail("Run codex login status to check the current login.");
|
||||
}
|
||||
|
||||
match load_auth_dot_json(
|
||||
&config.codex_home,
|
||||
config.cli_auth_credentials_store_mode,
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
#![cfg(test)]
|
||||
|
||||
use codex_core::config::ConfigBuilder;
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
use super::HumanOutputOptions;
|
||||
use super::auth_check;
|
||||
use super::redacted_json_report;
|
||||
use super::render_human_report;
|
||||
use super::report_from_checks;
|
||||
|
||||
#[tokio::test]
|
||||
async fn auth_check_reports_authenticated_workload_identity_without_stored_credentials() {
|
||||
let home = tempfile::tempdir().expect("create Codex home");
|
||||
let config = ConfigBuilder::default()
|
||||
.codex_home(home.path().to_path_buf())
|
||||
.build()
|
||||
.await
|
||||
.expect("load doctor config");
|
||||
|
||||
let mut check = auth_check(&config, /*workload_identity_authenticated*/ true);
|
||||
// Stabilize the host-specific details for the terminal snapshot.
|
||||
check
|
||||
.details
|
||||
.retain(|detail| !detail.starts_with("auth env vars present: "));
|
||||
if let Some(auth_file) = check
|
||||
.details
|
||||
.iter_mut()
|
||||
.find(|detail| detail.starts_with("auth file: "))
|
||||
{
|
||||
*auth_file = "auth file: /codex-home/auth.json".to_string();
|
||||
}
|
||||
|
||||
let mut report = report_from_checks(vec![check]);
|
||||
report.codex_version = "1.2.3".to_string();
|
||||
let rendered = render_human_report(
|
||||
&report,
|
||||
HumanOutputOptions {
|
||||
show_details: true,
|
||||
show_all: false,
|
||||
ascii: false,
|
||||
color_enabled: false,
|
||||
},
|
||||
);
|
||||
insta::assert_snapshot!(rendered, @r"
|
||||
Codex Doctor v1.2.3
|
||||
|
||||
Configuration
|
||||
✓ auth authenticated using workload identity
|
||||
auth storage mode File
|
||||
auth.json path (file backend/fallback) /codex-home/auth.json
|
||||
· Run codex login status to check the current login.
|
||||
|
||||
─────────────────────────────────────────────────────────────
|
||||
1 ok · 0 warn · 0 fail ok
|
||||
|
||||
--summary compact output --all expand truncated lists
|
||||
--json redacted report
|
||||
");
|
||||
|
||||
let report = serde_json::to_value(redacted_json_report(&report)).expect("serialize report");
|
||||
let check = &report["checks"]["auth.credentials"];
|
||||
|
||||
assert_eq!(check["status"], "ok");
|
||||
assert_eq!(check["summary"], "authenticated using workload identity");
|
||||
}
|
||||
Reference in New Issue
Block a user