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

@@ -31,45 +31,6 @@ use tracing::Level;
use tracing_subscriber::fmt::format::FmtSpan;
use tracing_test::internal::MockWriter;
#[tokio::test]
async fn returns_fallback_plugins_when_remote_disabled_for_codex_auth() {
let codex_home = tempdir().expect("tempdir should succeed");
write_file(
&codex_home.path().join(CONFIG_TOML_FILE),
r#"[features]
plugins = true
remote_plugin = false
"#,
);
let curated_root = curated_plugins_repo_path(codex_home.path());
write_openai_curated_marketplace(&curated_root, &["sample", "slack", "openai-developers"]);
let plugins = load_plugins_config(codex_home.path(), codex_home.path()).await;
let plugins_manager = test_plugins_manager_with_options(
codex_home.path().to_path_buf(),
Some(Product::Codex),
Some(AuthMode::Chatgpt),
);
let auth = CodexAuth::create_dummy_chatgpt_auth_for_testing();
let discoverable_plugins = list_discoverable_plugins(
&plugins_manager,
discovery_input(plugins, &[], &[], &[]),
Some(&auth),
)
.await;
assert_eq!(
discoverable_plugins
.into_iter()
.map(|plugin| plugin.id)
.collect::<Vec<_>>(),
vec![
"openai-developers@openai-curated".to_string(),
"slack@openai-curated".to_string(),
]
);
}
#[tokio::test]
async fn returns_api_curated_fallback_plugins_for_direct_provider_auth() {
let codex_home = tempdir().expect("tempdir should succeed");
@@ -106,7 +67,7 @@ async fn returns_api_curated_fallback_plugins_for_direct_provider_auth() {
async fn returns_microsoft_fallback_plugins() {
let codex_home = tempdir().expect("tempdir should succeed");
let curated_root = curated_plugins_repo_path(codex_home.path());
write_openai_curated_marketplace(
write_openai_api_curated_marketplace(
&curated_root,
&["teams", "sharepoint", "outlook-email", "outlook-calendar"],
);
@@ -116,7 +77,7 @@ async fn returns_microsoft_fallback_plugins() {
let plugins_manager = test_plugins_manager_with_options(
codex_home.path().to_path_buf(),
Some(Product::Codex),
Some(AuthMode::Chatgpt),
Some(AuthMode::ApiKey),
);
let discoverable_plugins = list_discoverable_plugins(
&plugins_manager,
@@ -131,9 +92,9 @@ async fn returns_microsoft_fallback_plugins() {
.map(|plugin| plugin.id)
.collect::<Vec<_>>(),
vec![
"outlook-calendar@openai-curated".to_string(),
"outlook-email@openai-curated".to_string(),
"sharepoint@openai-curated".to_string(),
"outlook-calendar@openai-api-curated".to_string(),
"outlook-email@openai-api-curated".to_string(),
"sharepoint@openai-api-curated".to_string(),
]
);
}
@@ -178,9 +139,9 @@ source = {bundled_marketplace_root:?}
let plugins_manager = test_plugins_manager_with_options(
codex_home.path().to_path_buf(),
Some(Product::Codex),
Some(AuthMode::Chatgpt),
Some(AuthMode::Headers),
);
let auth = CodexAuth::create_dummy_chatgpt_auth_for_testing();
let auth = CodexAuth::Headers(codex_login::AuthHeaders::new(http::HeaderMap::new()));
let discoverable_plugins = list_discoverable_plugins(
&plugins_manager,
discovery_input(plugins, &[], &[], &[]),
@@ -262,13 +223,13 @@ source = {marketplace_root:?}
),
);
let plugins = load_plugins_config(codex_home.path(), codex_home.path()).await;
let auth_manager = test_auth_manager(Some(AuthMode::Chatgpt));
let auth_manager = test_auth_manager(Some(AuthMode::ApiKey));
let plugins_manager = test_plugins_manager_with_auth_manager(
codex_home.path().to_path_buf(),
Some(Product::Codex),
Arc::clone(&auth_manager),
);
let chatgpt_projection = list_discoverable_plugins(
let header_projection = list_discoverable_plugins(
&plugins_manager,
discovery_input(plugins.clone(), &[plugin_id.as_str()], &[], &[]),
/*auth*/ None,
@@ -282,10 +243,11 @@ source = {marketplace_root:?}
"Plugin that includes skills, MCP servers, and app connectors".to_string(),
),
has_skills: true,
mcp_server_names: Vec::new(),
app_connector_ids: vec!["connector_sample".to_string()],
// App routes required ChatGPT auth, so direct MCP servers are always advertised.
mcp_server_names: vec!["sample-docs".to_string()],
app_connector_ids: Vec::new(),
};
assert_eq!(chatgpt_projection, vec![expected.clone()]);
assert_eq!(header_projection, vec![expected.clone()]);
set_test_auth_mode(&auth_manager, Some(AuthMode::ApiKey)).await;
let api_key_projection = list_discoverable_plugins(
@@ -294,30 +256,23 @@ source = {marketplace_root:?}
/*auth*/ None,
)
.await;
assert_eq!(
api_key_projection,
vec![ToolSuggestDiscoverablePlugin {
mcp_server_names: vec!["sample-docs".to_string()],
app_connector_ids: Vec::new(),
..expected
}]
);
assert_eq!(api_key_projection, vec![expected]);
}
#[tokio::test]
async fn reprojects_cached_skill_availability_for_current_config() {
let codex_home = tempdir().expect("tempdir should succeed");
let curated_root = curated_plugins_repo_path(codex_home.path());
write_openai_curated_marketplace(&curated_root, &["slack"]);
write_openai_api_curated_marketplace(&curated_root, &["slack"]);
let plugins = load_plugins_config(codex_home.path(), codex_home.path()).await;
let plugins_manager = test_plugins_manager_with_options(
codex_home.path().to_path_buf(),
Some(Product::Codex),
Some(AuthMode::Chatgpt),
Some(AuthMode::ApiKey),
);
let expected = ToolSuggestDiscoverablePlugin {
id: "slack@openai-curated".to_string(),
id: "slack@openai-api-curated".to_string(),
remote_plugin_id: None,
name: "slack".to_string(),
description: Some(
@@ -325,7 +280,7 @@ async fn reprojects_cached_skill_availability_for_current_config() {
),
has_skills: true,
mcp_server_names: vec!["sample-docs".to_string()],
app_connector_ids: vec!["connector_calendar".to_string()],
app_connector_ids: Vec::new(),
};
let initial = list_discoverable_plugins(
&plugins_manager,
@@ -362,7 +317,7 @@ enabled = false
async fn does_not_advertise_skills_when_skill_loading_fails() {
let codex_home = tempdir().expect("tempdir should succeed");
let curated_root = curated_plugins_repo_path(codex_home.path());
write_openai_curated_marketplace(&curated_root, &["slack"]);
write_openai_api_curated_marketplace(&curated_root, &["slack"]);
write_file(
&curated_root.join("plugins/slack/skills/SKILL.md"),
"---\nname: bad",
@@ -372,7 +327,7 @@ async fn does_not_advertise_skills_when_skill_loading_fails() {
let plugins_manager = test_plugins_manager_with_options(
codex_home.path().to_path_buf(),
Some(Product::Codex),
Some(AuthMode::Chatgpt),
Some(AuthMode::ApiKey),
);
let discoverable_plugins = list_discoverable_plugins(
&plugins_manager,
@@ -384,7 +339,7 @@ async fn does_not_advertise_skills_when_skill_loading_fails() {
assert_eq!(
discoverable_plugins,
vec![ToolSuggestDiscoverablePlugin {
id: "slack@openai-curated".to_string(),
id: "slack@openai-api-curated".to_string(),
remote_plugin_id: None,
name: "slack".to_string(),
description: Some(
@@ -392,7 +347,7 @@ async fn does_not_advertise_skills_when_skill_loading_fails() {
),
has_skills: false,
mcp_server_names: vec!["sample-docs".to_string()],
app_connector_ids: vec!["connector_calendar".to_string()],
app_connector_ids: Vec::new(),
}]
);
}
@@ -401,7 +356,7 @@ async fn does_not_advertise_skills_when_skill_loading_fails() {
async fn clear_cache_invalidates_cached_tool_suggest_metadata() {
let codex_home = tempdir().expect("tempdir should succeed");
let curated_root = curated_plugins_repo_path(codex_home.path());
write_openai_curated_marketplace(&curated_root, &["slack"]);
write_openai_api_curated_marketplace(&curated_root, &["slack"]);
let plugin_manifest = curated_root.join("plugins/slack/.codex-plugin/plugin.json");
write_file(
&plugin_manifest,
@@ -415,17 +370,17 @@ async fn clear_cache_invalidates_cached_tool_suggest_metadata() {
let plugins_manager = test_plugins_manager_with_options(
codex_home.path().to_path_buf(),
Some(Product::Codex),
Some(AuthMode::Chatgpt),
Some(AuthMode::ApiKey),
);
let input = discovery_input(plugins, &[], &[], &[]);
let expected_cached = vec![ToolSuggestDiscoverablePlugin {
id: "slack@openai-curated".to_string(),
id: "slack@openai-api-curated".to_string(),
remote_plugin_id: None,
name: "slack".to_string(),
description: Some("Before reload".to_string()),
has_skills: true,
mcp_server_names: vec!["sample-docs".to_string()],
app_connector_ids: vec!["connector_calendar".to_string()],
app_connector_ids: Vec::new(),
}];
let initial = list_discoverable_plugins(&plugins_manager, input.clone(), /*auth*/ None).await;
assert_eq!(initial, expected_cached);
@@ -456,7 +411,7 @@ async fn clear_cache_invalidates_cached_tool_suggest_metadata() {
async fn ignores_missing_marketplace_plugin() {
let codex_home = tempdir().expect("tempdir should succeed");
let curated_root = curated_plugins_repo_path(codex_home.path());
write_openai_curated_marketplace(&curated_root, &["installed", "slack"]);
write_openai_api_curated_marketplace(&curated_root, &["installed", "slack"]);
let marketplace_name = OPENAI_BUNDLED_MARKETPLACE_NAME;
let marketplace_root = codex_home
.path()
@@ -491,7 +446,7 @@ source = "/tmp/{marketplace_name}"
let plugins_manager = test_plugins_manager_with_options(
codex_home.path().to_path_buf(),
Some(Product::Codex),
Some(AuthMode::Chatgpt),
Some(AuthMode::ApiKey),
);
let discoverable_plugins = list_discoverable_plugins(
&plugins_manager,
@@ -501,14 +456,14 @@ source = "/tmp/{marketplace_name}"
.await;
assert_eq!(discoverable_plugins.len(), 1);
assert_eq!(discoverable_plugins[0].id, "slack@openai-curated");
assert_eq!(discoverable_plugins[0].id, "slack@openai-api-curated");
}
#[tokio::test]
async fn normalizes_description() {
let codex_home = tempdir().expect("tempdir should succeed");
let curated_root = curated_plugins_repo_path(codex_home.path());
write_openai_curated_marketplace(&curated_root, &["installed", "slack"]);
write_openai_api_curated_marketplace(&curated_root, &["installed", "slack"]);
write_file(
&curated_root.join("plugins/slack/.codex-plugin/plugin.json"),
r#"{
@@ -522,7 +477,7 @@ async fn normalizes_description() {
let plugins_manager = test_plugins_manager_with_options(
codex_home.path().to_path_buf(),
Some(Product::Codex),
Some(AuthMode::Chatgpt),
Some(AuthMode::ApiKey),
);
let discoverable_plugins = list_discoverable_plugins(
&plugins_manager,
@@ -534,13 +489,13 @@ async fn normalizes_description() {
assert_eq!(
discoverable_plugins,
vec![ToolSuggestDiscoverablePlugin {
id: "slack@openai-curated".to_string(),
id: "slack@openai-api-curated".to_string(),
remote_plugin_id: None,
name: "slack".to_string(),
description: Some("Plugin with extra spacing".to_string()),
has_skills: true,
mcp_server_names: vec!["sample-docs".to_string()],
app_connector_ids: vec!["connector_calendar".to_string()],
app_connector_ids: Vec::new(),
}]
);
}
@@ -569,9 +524,9 @@ async fn omits_not_available_curated_plugins() {
let codex_home = tempdir().expect("tempdir should succeed");
let curated_root = curated_plugins_repo_path(codex_home.path());
write_file(
&curated_root.join(".agents/plugins/marketplace.json"),
&curated_root.join(".agents/plugins/api_marketplace.json"),
r#"{
"name": "openai-curated",
"name": "openai-api-curated",
"plugins": [
{
"name": "installed",
@@ -610,7 +565,7 @@ async fn omits_not_available_curated_plugins() {
let plugins_manager = test_plugins_manager_with_options(
codex_home.path().to_path_buf(),
Some(Product::Codex),
Some(AuthMode::Chatgpt),
Some(AuthMode::ApiKey),
);
let discoverable_plugins = list_discoverable_plugins(
&plugins_manager,
@@ -624,7 +579,7 @@ async fn omits_not_available_curated_plugins() {
.into_iter()
.map(|plugin| plugin.id)
.collect::<Vec<_>>(),
vec!["slack@openai-curated".to_string()]
vec!["slack@openai-api-curated".to_string()]
);
}
@@ -632,7 +587,7 @@ async fn omits_not_available_curated_plugins() {
async fn discovery_warns_once_per_invalid_manifest() {
let codex_home = tempdir().expect("tempdir should succeed");
let curated_root = curated_plugins_repo_path(codex_home.path());
write_openai_curated_marketplace(&curated_root, &["slack", "gmail", "openai-developers"]);
write_openai_api_curated_marketplace(&curated_root, &["slack", "gmail", "openai-developers"]);
install_marketplace_plugin(codex_home.path(), curated_root.as_path(), "slack").await;
let too_long_prompt = "x".repeat(513);
@@ -655,7 +610,7 @@ async fn discovery_warns_once_per_invalid_manifest() {
let plugins_manager = test_plugins_manager_with_options(
codex_home.path().to_path_buf(),
Some(Product::Codex),
Some(AuthMode::Chatgpt),
Some(AuthMode::ApiKey),
);
let buffer: &'static std::sync::Mutex<Vec<u8>> =
Box::leak(Box::new(std::sync::Mutex::new(Vec::new())));
@@ -680,7 +635,7 @@ async fn discovery_warns_once_per_invalid_manifest() {
.iter()
.map(|plugin| plugin.id.as_str())
.collect::<Vec<_>>(),
vec!["gmail@openai-curated", "openai-developers@openai-curated"]
vec!["gmail@openai-api-curated", "openai-developers@openai-api-curated"]
);
let logs = String::from_utf8(buffer.lock().expect("buffer lock").clone())
@@ -864,9 +819,14 @@ async fn install_marketplace_plugin(codex_home: &Path, marketplace_root: &Path,
&config.config_layer_stack,
PluginInstallRequest {
plugin_name: plugin_name.to_string(),
marketplace_path: AbsolutePathBuf::try_from(
marketplace_root.join(".agents/plugins/marketplace.json"),
)
marketplace_path: AbsolutePathBuf::try_from({
let api_manifest = marketplace_root.join(".agents/plugins/api_marketplace.json");
if api_manifest.is_file() {
api_manifest
} else {
marketplace_root.join(".agents/plugins/marketplace.json")
}
})
.expect("marketplace path"),
},
)