WIP fase 2b-2: rimosso login ChatGPT/OAuth/device code, agent/workload identity, backend-client; resta solo chiave API (test non tutti verdi)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
andrea.difonzo
2026-11-10 06:00:44 +01:00
parent 82347a58ed
commit 231e8cd136
661 changed files with 4924 additions and 64817 deletions

View File

@@ -17,7 +17,6 @@ use codex_history::RolloutLine;
use codex_login::AuthKeyringBackendKind;
use codex_login::AuthManager;
use codex_login::CodexAuth;
use codex_login::auth::AgentIdentityAuthPolicy;
use codex_login::auth::BedrockApiKeyAuth;
use codex_login::default_client::originator;
use codex_model_provider_info::AMAZON_BEDROCK_PROVIDER_ID;
@@ -793,7 +792,7 @@ async fn response_item_ids_are_sent_for_all_remote_v2_compaction_requests() -> a
)
.await;
let test = test_codex()
.with_auth(CodexAuth::create_dummy_chatgpt_auth_for_testing())
.with_auth(CodexAuth::from_api_key("Test API Key"))
.build(&server)
.await?;
@@ -1831,7 +1830,6 @@ async fn send_request_with_provider(provider: ModelProviderInfo) {
"unused-api-key",
))),
),
AgentIdentityAuthPolicy::JwtOnly,
thread_id,
uuid_v7_item_id_generator_for_test(),
SessionSource::Exec,
@@ -1849,7 +1847,6 @@ async fn send_request_with_provider(provider: ModelProviderInfo) {
/*output_token_replay_enabled*/ false,
/*attestation_provider*/ None,
config.http_client_factory(),
config.workspace_routing_context(),
Vec::new(),
);
let responses_metadata = test_turn_responses_metadata(&client, thread_id);
@@ -1936,7 +1933,7 @@ async fn includes_base_instructions_override_in_request() {
}
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn chatgpt_auth_sends_correct_request() {
async fn stored_auth_sends_correct_request() {
skip_if_no_network!();
// Mock server
@@ -1981,17 +1978,14 @@ async fn chatgpt_auth_sends_correct_request() {
.header("authorization")
.expect("authorization header");
let request_originator = request.header("originator").expect("originator header");
let request_chatgpt_account_id = request
.header("chatgpt-account-id")
.expect("chatgpt-account-id header");
let request_body = request.body_json();
let model = request_body["model"]
.as_str()
.expect("missing request model");
assert_eq!(
request.header(X_CODEX_ROUTING_HINT_HEADER),
Some(format!("model={model}"))
);
// ChatGPT-only routing and account headers are never sent.
assert!(!model.is_empty());
assert_eq!(request.header(X_CODEX_ROUTING_HINT_HEADER), None);
assert_eq!(request.header("chatgpt-account-id"), None);
let request_session_id = request.header("session-id").expect("session-id header");
let request_thread_id = request.header("thread-id").expect("thread-id header");
@@ -2004,8 +1998,7 @@ async fn chatgpt_auth_sends_correct_request() {
assert_eq!(request_thread_id, thread_id_string.as_str());
assert_eq!(request_originator, originator().value);
assert_eq!(request_authorization, "Bearer Access Token");
assert_eq!(request_chatgpt_account_id, "account_id");
assert_eq!(request_authorization, "Bearer Test API Key");
assert_codex_client_metadata(
&request_body,
installation_id.as_str(),
@@ -2066,9 +2059,7 @@ async fn prefers_apikey_when_config_prefers_apikey_even_with_chatgpt_tokens() {
let auth = CodexAuth::from_auth_storage(
codex_home.path(),
AuthCredentialsStoreMode::File,
/*chatgpt_base_url*/ None,
AuthKeyringBackendKind::default(),
&codex_login::test_support::transport_default_auth_route_config(),
)
.await
.expect("Failed to load CodexAuth")
@@ -2187,63 +2178,6 @@ async fn includes_user_instructions_message_in_request() {
);
}
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn includes_apps_guidance_as_developer_message_for_chatgpt_auth() {
skip_if_no_network!();
let server = MockServer::start().await;
let apps_server = AppsTestServer::mount(&server)
.await
.expect("mount apps MCP mock");
let apps_base_url = apps_server.chatgpt_base_url.clone();
let resp_mock = mount_sse_once(
&server,
sse(vec![ev_response_created("resp1"), ev_completed("resp1")]),
)
.await;
let mut builder = test_codex()
.with_auth(create_dummy_codex_auth())
.with_config(move |config| {
config
.features
.enable(Feature::Apps)
.expect("test config should allow feature update");
config.chatgpt_base_url = apps_base_url;
});
let codex = builder
.build(&server)
.await
.expect("create new conversation")
.codex;
codex
.start_or_steer_turn(TurnInputRequest::user_input(vec![UserInput::Text {
text: "hello".into(),
text_elements: Vec::new(),
}]))
.await
.unwrap();
wait_for_event(&codex, |ev| matches!(ev, EventMsg::TurnComplete(_))).await;
let request = resp_mock.single_request();
let apps_snippet =
"Apps (Connectors) can be explicitly triggered in user messages in the format";
assert!(
message_input_text_contains(&request, "developer", apps_snippet),
"expected apps guidance in a developer message, got {:?}",
request.body_json()["input"]
);
assert!(
!message_input_text_contains(&request, "user", apps_snippet),
"did not expect apps guidance in user messages, got {:?}",
request.body_json()["input"]
);
}
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn omits_apps_guidance_for_api_key_auth_even_when_feature_enabled() {
skip_if_no_network!();
@@ -2794,7 +2728,7 @@ async fn sequential_cutoff_is_omitted_for_non_openai_provider() -> anyhow::Resul
)
.await;
let TestCodex { codex, .. } = test_codex()
.with_auth(CodexAuth::create_dummy_chatgpt_auth_for_testing())
.with_auth(CodexAuth::from_api_key("Test API Key"))
.with_config(|config| {
config.model_provider.name = "mock".to_string();
let _ = config
@@ -3337,7 +3271,6 @@ async fn azure_responses_request_does_not_store_and_preserves_prefixed_item_ids(
let client = ModelClient::new(
codex_model_provider::create_model_provider(provider.clone(), /*auth_manager*/ None),
AgentIdentityAuthPolicy::JwtOnly,
thread_id,
uuid_v7_item_id_generator_for_test(),
SessionSource::Exec,
@@ -3352,7 +3285,6 @@ async fn azure_responses_request_does_not_store_and_preserves_prefixed_item_ids(
/*output_token_replay_enabled*/ false,
/*attestation_provider*/ None,
config.http_client_factory(),
config.workspace_routing_context(),
Vec::new(),
);
let responses_metadata = test_turn_responses_metadata(&client, thread_id);
@@ -4284,7 +4216,7 @@ async fn env_var_overrides_loaded_auth() {
}
fn create_dummy_codex_auth() -> CodexAuth {
CodexAuth::create_dummy_chatgpt_auth_for_testing()
CodexAuth::from_api_key("Test API Key")
}
/// Scenario: