mirror of
https://github.com/openai/codex.git
synced 2026-11-23 23:10:47 +00:00
[codex] close remaining WIF readiness gaps [ci changed_files]
This commit is contained in:
@@ -25,6 +25,7 @@ tokio = { workspace = true, features = ["fs", "rt", "sync", "time"] }
|
||||
tracing = { workspace = true }
|
||||
|
||||
[dev-dependencies]
|
||||
codex-app-server-protocol = { workspace = true }
|
||||
pretty_assertions = { workspace = true }
|
||||
tempfile = { workspace = true }
|
||||
tokio = { workspace = true, features = ["macros", "rt", "test-util", "time"] }
|
||||
|
||||
@@ -494,7 +494,8 @@ where
|
||||
Ok(auth) => auth,
|
||||
Err(error) => {
|
||||
tracing::error!(error = %error, "Failed to resolve auth while refreshing cloud config bundle");
|
||||
return false;
|
||||
emit_load_metric("refresh", "error", /*bundle*/ None);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
let Some(auth) = auth else {
|
||||
|
||||
@@ -8,6 +8,7 @@ use crate::cache::CloudConfigBundleCache;
|
||||
use crate::metrics::bundle_shape_tag;
|
||||
use base64::Engine;
|
||||
use base64::engine::general_purpose::URL_SAFE_NO_PAD;
|
||||
use codex_app_server_protocol::AuthMode;
|
||||
use codex_backend_client::ConfigBundleResponse;
|
||||
use codex_backend_client::DeliveredTomlFragment;
|
||||
use codex_config::AbsolutePathBuf;
|
||||
@@ -17,6 +18,10 @@ use codex_config::CloudRequirementsFragment;
|
||||
use codex_config::CloudRequirementsTomlBundle;
|
||||
use codex_config::types::AuthCredentialsStoreMode;
|
||||
use codex_login::AuthKeyringBackendKind;
|
||||
use codex_login::auth::ExternalAuth;
|
||||
use codex_login::auth::ExternalAuthFuture;
|
||||
use codex_login::auth::ExternalAuthRefreshContext;
|
||||
use codex_login::auth::ExternalAuthTokens;
|
||||
use pretty_assertions::assert_eq;
|
||||
use serde_json::json;
|
||||
use std::collections::VecDeque;
|
||||
@@ -238,6 +243,29 @@ impl BundleClient for PendingBundleClient {
|
||||
}
|
||||
}
|
||||
|
||||
struct FailingRequiredExternalAuth;
|
||||
|
||||
impl ExternalAuth for FailingRequiredExternalAuth {
|
||||
fn auth_mode(&self) -> AuthMode {
|
||||
AuthMode::Chatgpt
|
||||
}
|
||||
|
||||
fn requires_successful_resolution(&self) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn resolve(&self) -> ExternalAuthFuture<'_, Option<ExternalAuthTokens>> {
|
||||
Box::pin(async { Err(std::io::Error::other("transient WIF failure")) })
|
||||
}
|
||||
|
||||
fn refresh(
|
||||
&self,
|
||||
_context: ExternalAuthRefreshContext,
|
||||
) -> ExternalAuthFuture<'_, ExternalAuthTokens> {
|
||||
Box::pin(async { Err(std::io::Error::other("transient WIF failure")) })
|
||||
}
|
||||
}
|
||||
|
||||
struct SequenceBundleClient {
|
||||
responses: tokio::sync::Mutex<VecDeque<Result<CloudConfigBundle, BundleRequestError>>>,
|
||||
request_count: AtomicUsize,
|
||||
@@ -962,6 +990,32 @@ async fn refresh_from_remote_updates_cached_bundle() {
|
||||
assert_eq!(signed_payload.bundle, replacement_bundle);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn refresh_continues_after_required_external_auth_resolution_error() {
|
||||
let codex_home = tempdir().expect("tempdir");
|
||||
let auth_manager = Arc::new(
|
||||
AuthManager::new(
|
||||
codex_home.path().to_path_buf(),
|
||||
/*enable_codex_api_key_env*/ false,
|
||||
AuthCredentialsStoreMode::File,
|
||||
/*chatgpt_base_url*/ None,
|
||||
AuthKeyringBackendKind::default(),
|
||||
)
|
||||
.await,
|
||||
);
|
||||
auth_manager.set_external_auth(Arc::new(FailingRequiredExternalAuth));
|
||||
let fetcher = Arc::new(StaticBundleClient::new(test_bundle()));
|
||||
let service = CloudConfigBundleService::new(
|
||||
auth_manager,
|
||||
fetcher.clone(),
|
||||
codex_home.path().to_path_buf(),
|
||||
CLOUD_CONFIG_BUNDLE_TIMEOUT,
|
||||
);
|
||||
|
||||
assert!(service.refresh_cache_once().await);
|
||||
assert_eq!(fetcher.request_count.load(Ordering::SeqCst), 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bundle_response_conversion_preserves_fragment_order() {
|
||||
let response = ConfigBundleResponse {
|
||||
|
||||
Reference in New Issue
Block a user