Format OAuth refresh consistency changes

This commit is contained in:
fawney19
2026-04-28 09:54:35 +08:00
parent 29fc0be121
commit 3f1abb6906
3 changed files with 18 additions and 10 deletions

View File

@@ -990,10 +990,12 @@ impl AppState {
let _ = self let _ = self
.invalidate_local_oauth_refresh_entry(&current_transport.key.id) .invalidate_local_oauth_refresh_entry(&current_transport.key.id)
.await; .await;
return Err(provider_transport::LocalOAuthRefreshError::InvalidResponse { return Err(
provider_type: "gateway", provider_transport::LocalOAuthRefreshError::InvalidResponse {
message: format!("local oauth refresh persistence failed: {err:?}"), provider_type: "gateway",
}); message: format!("local oauth refresh persistence failed: {err:?}"),
},
);
} }
self.oauth_refresh self.oauth_refresh
.store_cached_entry(current_transport.key.id.trim(), refreshed_entry.clone()) .store_cached_entry(current_transport.key.id.trim(), refreshed_entry.clone())

View File

@@ -5057,8 +5057,10 @@ async fn gateway_concurrent_manual_oauth_refresh_uses_rotated_refresh_token_afte
provider_node.tunnel_mode = false; provider_node.tunnel_mode = false;
provider_node.tunnel_connected = false; provider_node.tunnel_connected = false;
provider_node.proxy_url = Some("http://proxy-provider.example:8080".to_string()); provider_node.proxy_url = Some("http://proxy-provider.example:8080".to_string());
let proxy_node_repository = let proxy_node_repository = Arc::new(InMemoryProxyNodeRepository::seed(vec![
Arc::new(InMemoryProxyNodeRepository::seed(vec![key_node, provider_node])); key_node,
provider_node,
]));
let oauth_refresh = let oauth_refresh =
crate::provider_transport::LocalOAuthRefreshCoordinator::with_adapters_for_tests(vec![ crate::provider_transport::LocalOAuthRefreshCoordinator::with_adapters_for_tests(vec![
@@ -5150,8 +5152,8 @@ async fn gateway_concurrent_manual_oauth_refresh_uses_rotated_refresh_token_afte
} }
#[tokio::test] #[tokio::test]
async fn gateway_manual_oauth_refresh_prefers_fresher_transport_auth_config_over_stale_runtime_cache() async fn gateway_manual_oauth_refresh_prefers_fresher_transport_auth_config_over_stale_runtime_cache(
{ ) {
let refresh_request_bodies = Arc::new(Mutex::new(Vec::<String>::new())); let refresh_request_bodies = Arc::new(Mutex::new(Vec::<String>::new()));
let refresh_request_bodies_clone = Arc::clone(&refresh_request_bodies); let refresh_request_bodies_clone = Arc::clone(&refresh_request_bodies);
let execution_runtime = Router::new().route( let execution_runtime = Router::new().route(
@@ -5312,7 +5314,10 @@ async fn gateway_manual_oauth_refresh_prefers_fresher_transport_auth_config_over
.await .await
.expect("initial refresh should succeed") .expect("initial refresh should succeed")
.expect("initial refresh should return cached entry"); .expect("initial refresh should return cached entry");
assert_eq!(cached_entry.auth_header_value, "Bearer cached-codex-access-token"); assert_eq!(
cached_entry.auth_header_value,
"Bearer cached-codex-access-token"
);
let mut updated_key = provider_catalog_repository let mut updated_key = provider_catalog_repository
.list_keys_by_ids(&["key-codex-oauth-stale-cache".to_string()]) .list_keys_by_ids(&["key-codex-oauth-stale-cache".to_string()])

View File

@@ -278,7 +278,8 @@ impl LocalOAuthRefreshAdapter for GenericOAuthRefreshAdapter {
else { else {
return Ok(None); return Ok(None);
}; };
let cached_auth_config = entry.and_then(|cached| Self::auth_config_from_entry(transport, cached)); let cached_auth_config =
entry.and_then(|cached| Self::auth_config_from_entry(transport, cached));
let transport_auth_config = Self::auth_config_from_transport(transport); let transport_auth_config = Self::auth_config_from_transport(transport);
let base_auth_config = self.base_auth_config(transport, entry); let base_auth_config = self.base_auth_config(transport, entry);
let base_auth_config_source = match ( let base_auth_config_source = match (