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

@@ -16,10 +16,7 @@ use codex_extension_api::ExtensionRegistryBuilder;
use codex_features::Feature;
use codex_login::CodexAuth;
use codex_mcp::CODEX_APPS_MCP_SERVER_NAME;
use codex_model_provider_info::AMAZON_BEDROCK_PROVIDER_ID;
use codex_model_provider_info::OPENAI_PROVIDER_ID;
use codex_plugin::PluginId;
use codex_protocol::auth::AuthMode;
use codex_protocol::config_types::CollaborationMode;
use codex_protocol::config_types::ModeKind;
use codex_protocol::config_types::Settings;
@@ -30,7 +27,6 @@ use codex_protocol::protocol::EventMsg;
#[cfg(unix)]
use codex_protocol::protocol::ThreadSettingsOverrides;
use codex_protocol::user_input::UserInput;
use codex_skills_extension::HostSkillsLoadInput;
use codex_skills_extension::SkillsExtensionConfig;
use codex_skills_extension::install;
use core_test_support::apps_test_server::AppsTestServer;
@@ -273,7 +269,7 @@ async fn build_apps_enabled_plugin_test_codex(
) -> Result<TestCodex> {
let mut builder = test_codex()
.with_home(codex_home)
.with_auth(CodexAuth::create_dummy_chatgpt_auth_for_testing())
.with_auth(CodexAuth::from_api_key("Test API Key"))
.with_config(move |config| {
config
.features
@@ -373,7 +369,7 @@ async fn persisted_remote_plugin_command_attribution_flows_through_turn_context(
let chatgpt_base_url = server.uri();
let mut builder = builder
.with_home(Arc::clone(&codex_home))
.with_auth(CodexAuth::create_dummy_chatgpt_auth_for_testing())
.with_catalog_discovery_api_key()
.with_model("gpt-5.2")
.with_config(move |config| config.chatgpt_base_url = chatgpt_base_url);
let test_codex = builder.build_with_auto_env(&server).await?;
@@ -451,7 +447,7 @@ async fn thread_disabled_plugins_filter_skills_and_tools_without_changing_shared
let mut builder = test_codex()
.with_home(home)
.with_extensions(skills_extensions())
.with_auth(CodexAuth::create_dummy_chatgpt_auth_for_testing())
.with_auth(CodexAuth::from_api_key("Test API Key"))
.with_config(move |config| {
config.features.enable(Feature::Apps).unwrap();
config.chatgpt_base_url = apps.chatgpt_base_url;
@@ -861,7 +857,7 @@ enabled = true
let mut builder = test_codex()
.with_home(codex_home)
.with_extensions(skills_extensions())
.with_auth(CodexAuth::create_dummy_chatgpt_auth_for_testing())
.with_auth(CodexAuth::from_api_key("Test API Key"))
.with_config(move |config| {
config.chatgpt_base_url = chatgpt_base_url;
config.apps_mcp_product_sku = product_sku;
@@ -1052,257 +1048,6 @@ async fn agent_plugin_root_mcp_stdio_tool_round_trip_expands_reserved_paths_and_
Ok(())
}
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn curated_plugin_skills_follow_auth_switch() -> Result<()> {
const CHATGPT_CURATED_PLUGIN_SKILL: &str = "chatgpt-plugin:chatgpt-skill";
const API_CURATED_PLUGIN_SKILL: &str = "api-plugin:api-skill";
const CURATED_PLUGIN_SKILLS: &[&str] =
&[CHATGPT_CURATED_PLUGIN_SKILL, API_CURATED_PLUGIN_SKILL];
#[derive(Clone, Copy)]
enum TargetAuth {
Chatgpt,
ApiKey,
BedrockApiKey,
NoCodexAuth,
}
#[derive(Clone, Copy)]
struct Fixture {
name: &'static str,
target_auth: TargetAuth,
target_model_provider_id: &'static str,
expected_target_loaded_plugin_skills: &'static [&'static str],
expected_target_skill_description: &'static str,
}
const FIXTURES: &[Fixture] = &[
Fixture {
name: "ChatGPT",
target_auth: TargetAuth::Chatgpt,
target_model_provider_id: OPENAI_PROVIDER_ID,
expected_target_loaded_plugin_skills: &[CHATGPT_CURATED_PLUGIN_SKILL],
expected_target_skill_description: "chatgpt description",
},
Fixture {
name: "ChatGPT with a custom provider",
target_auth: TargetAuth::Chatgpt,
target_model_provider_id: "ollama",
expected_target_loaded_plugin_skills: &[CHATGPT_CURATED_PLUGIN_SKILL],
expected_target_skill_description: "chatgpt description",
},
Fixture {
name: "API key",
target_auth: TargetAuth::ApiKey,
target_model_provider_id: OPENAI_PROVIDER_ID,
expected_target_loaded_plugin_skills: &[API_CURATED_PLUGIN_SKILL],
expected_target_skill_description: "api description before",
},
Fixture {
name: "Bedrock API key",
target_auth: TargetAuth::BedrockApiKey,
target_model_provider_id: AMAZON_BEDROCK_PROVIDER_ID,
expected_target_loaded_plugin_skills: &[API_CURATED_PLUGIN_SKILL],
expected_target_skill_description: "api description before",
},
Fixture {
name: "ambient Bedrock",
target_auth: TargetAuth::NoCodexAuth,
target_model_provider_id: AMAZON_BEDROCK_PROVIDER_ID,
expected_target_loaded_plugin_skills: &[API_CURATED_PLUGIN_SKILL],
expected_target_skill_description: "api description before",
},
Fixture {
name: "unauthenticated OpenAI",
target_auth: TargetAuth::NoCodexAuth,
target_model_provider_id: OPENAI_PROVIDER_ID,
expected_target_loaded_plugin_skills: &[API_CURATED_PLUGIN_SKILL],
expected_target_skill_description: "api description before",
},
Fixture {
name: "unauthenticated custom provider",
target_auth: TargetAuth::NoCodexAuth,
target_model_provider_id: "ollama",
expected_target_loaded_plugin_skills: &[API_CURATED_PLUGIN_SKILL],
expected_target_skill_description: "api description before",
},
];
async fn loaded_plugin_skills_for_config(test_codex: &TestCodex, config: &Config) -> String {
let plugins_input = config.plugins_config_input();
let plugins_manager = test_codex.thread_manager.plugins_manager();
let plugin_outcome = plugins_manager.plugins_for_config(&plugins_input).await;
let skills_input = HostSkillsLoadInput::new(
config.cwd.clone(),
plugin_outcome.effective_plugin_skill_roots(),
config.config_layer_stack.clone(),
)
.with_plugin_skill_snapshots(
plugins_manager.plugin_skill_snapshots_for_config(&plugins_input),
);
let skills_snapshot = test_codex
.thread_manager
.skills_service()
.snapshot_for_config(&skills_input, /*repository*/ None)
.await;
skills_snapshot
.outcome()
.skills
.iter()
.filter_map(|skill| {
let plugin_id = skill.plugin_id.as_deref()?;
let plugin_name = plugin_id
.split_once('@')
.map_or(plugin_id, |(plugin_name, _)| plugin_name);
Some(format!(
"{plugin_name}:{}\n{}",
skill.name, skill.description
))
})
.collect::<Vec<_>>()
.join("\n")
}
skip_if_no_network!(Ok(()));
let assert_loaded_plugin_skills =
|fixture_name: &str, phase: &str, skills: &str, expected: &[&str]| {
let loaded_plugin_skills = CURATED_PLUGIN_SKILLS
.iter()
.copied()
.filter(|plugin_skill| skills.contains(plugin_skill))
.collect::<Vec<_>>();
assert_eq!(
loaded_plugin_skills.as_slice(),
expected,
"unexpected curated plugin skills for {fixture_name} during {phase}: {skills:?}"
);
};
for fixture in FIXTURES {
let server = start_mock_server().await;
let codex_home = Arc::new(TempDir::new()?);
std::fs::write(
codex_home.path().join("config.toml"),
r#"[features]
plugins = true
remote_plugin = false
[plugins."chatgpt-plugin@openai-curated"]
enabled = true
[plugins."api-plugin@openai-api-curated"]
enabled = true
"#,
)?;
for (marketplace_name, plugin_name, skill_name, description) in [
(
"openai-curated",
"chatgpt-plugin",
"chatgpt-skill",
"chatgpt description",
),
(
"openai-api-curated",
"api-plugin",
"api-skill",
"api description before",
),
] {
let plugin_root = codex_home
.path()
.join("plugins/cache")
.join(marketplace_name)
.join(plugin_name)
.join("local");
std::fs::create_dir_all(plugin_root.join(".codex-plugin"))?;
std::fs::write(
plugin_root.join(".codex-plugin/plugin.json"),
format!(r#"{{"name":"{plugin_name}","description":"{plugin_name}"}}"#),
)?;
let skill_dir = plugin_root.join("skills").join(skill_name);
std::fs::create_dir_all(&skill_dir)?;
std::fs::write(
skill_dir.join("SKILL.md"),
format!("---\ndescription: {description}\n---\n\n# body\n"),
)?;
}
let mut builder = test_codex()
.with_home(Arc::clone(&codex_home))
.with_extensions(skills_extensions())
.with_auth(CodexAuth::create_dummy_chatgpt_auth_for_testing());
let test_codex = builder.build_with_auto_env(&server).await?;
let initial_skills = loaded_plugin_skills_for_config(&test_codex, &test_codex.config).await;
assert_loaded_plugin_skills(
fixture.name,
"initial ChatGPT config",
&initial_skills,
&[CHATGPT_CURATED_PLUGIN_SKILL],
);
assert!(initial_skills.contains("chatgpt description"));
std::fs::write(
codex_home.path().join(
"plugins/cache/openai-api-curated/api-plugin/local/skills/api-skill/SKILL.md",
),
"---\ndescription: api description after\n---\n\n# body\n",
)?;
let expected_auth_mode = match fixture.target_auth {
TargetAuth::Chatgpt => Some(AuthMode::Chatgpt),
TargetAuth::ApiKey => {
codex_login::login_with_api_key(
codex_home.path(),
"test-api-key",
codex_login::AuthCredentialsStoreMode::File,
codex_login::AuthKeyringBackendKind::default(),
)?;
test_codex.thread_manager.auth_manager().reload().await;
Some(AuthMode::ApiKey)
}
TargetAuth::BedrockApiKey => {
codex_login::login_with_bedrock_api_key(
codex_home.path(),
"test-bedrock-api-key",
"us-east-1",
codex_login::AuthCredentialsStoreMode::File,
codex_login::AuthKeyringBackendKind::default(),
)?;
test_codex.thread_manager.auth_manager().reload().await;
Some(AuthMode::BedrockApiKey)
}
TargetAuth::NoCodexAuth => {
test_codex.thread_manager.auth_manager().logout().await?;
None
}
};
assert_eq!(
test_codex.thread_manager.auth_manager().get_api_auth_mode(),
expected_auth_mode
);
test_codex.thread_manager.skills_service().clear_cache();
let mut target_config = test_codex.config.clone();
target_config.model_provider_id = fixture.target_model_provider_id.to_string();
let target_skills = loaded_plugin_skills_for_config(&test_codex, &target_config).await;
assert_loaded_plugin_skills(
fixture.name,
"target config",
&target_skills,
fixture.expected_target_loaded_plugin_skills,
);
assert!(
target_skills.contains(fixture.expected_target_skill_description),
"expected {:?} in current skills: {skills:?}",
fixture.expected_target_skill_description,
skills = target_skills
);
assert!(!target_skills.contains("api description after"));
}
Ok(())
}
#[test_case(true; "apps enabled")]
#[test_case(false; "apps disabled without direct MCP fallback")]
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
@@ -1349,7 +1094,7 @@ async fn curated_agent_plugin_app_routing_reaches_turns(apps_enabled: bool) -> R
)?;
let mut builder = test_codex()
.with_home(codex_home)
.with_auth(CodexAuth::create_dummy_chatgpt_auth_for_testing())
.with_auth(CodexAuth::from_api_key("Test API Key"))
.with_config(move |config| {
config
.features