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:
@@ -22,7 +22,6 @@ codex-config = { workspace = true }
|
||||
codex-connectors = { workspace = true }
|
||||
codex-core-plugin-common = { workspace = true }
|
||||
codex-exec-server = { workspace = true }
|
||||
codex-features = { workspace = true }
|
||||
codex-git-utils = { workspace = true }
|
||||
codex-hooks = { workspace = true }
|
||||
codex-http-client = { workspace = true }
|
||||
@@ -32,7 +31,6 @@ codex-model-provider = { workspace = true }
|
||||
codex-otel = { workspace = true }
|
||||
codex-plugin = { workspace = true }
|
||||
codex-protocol = { workspace = true }
|
||||
codex-runtime-agent-instance = { workspace = true }
|
||||
codex-shell-command = { workspace = true }
|
||||
codex-skills = { workspace = true }
|
||||
codex-tools = { workspace = true }
|
||||
|
||||
@@ -6,8 +6,10 @@ use codex_protocol::auth::AuthMode;
|
||||
use std::collections::HashMap;
|
||||
use std::collections::HashSet;
|
||||
|
||||
pub fn apps_route_available(auth_mode: Option<AuthMode>) -> bool {
|
||||
auth_mode.is_some_and(AuthMode::uses_codex_backend)
|
||||
/// aKode never authenticates to ChatGPT, so account-backed services (remote plugin
|
||||
/// catalogs and app routes) are never available for any credential.
|
||||
pub fn apps_route_available(_auth_mode: Option<AuthMode>) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
pub(crate) fn plugin_supports_apps(format: PluginManifestFormat, plugin_id: &PluginId) -> bool {
|
||||
|
||||
@@ -18,12 +18,6 @@ fn mcp_servers(mcp_servers: impl IntoIterator<Item = (&'static str, i32)>) -> Ha
|
||||
.collect::<HashMap<_, _>>()
|
||||
}
|
||||
|
||||
fn sorted_app_names(apps: &[AppDeclaration]) -> Vec<String> {
|
||||
let mut names = apps.iter().map(|app| app.name.clone()).collect::<Vec<_>>();
|
||||
names.sort();
|
||||
names
|
||||
}
|
||||
|
||||
fn sorted_mcp_server_names(mcp_servers: &HashMap<String, i32>) -> Vec<String> {
|
||||
let mut names = mcp_servers.keys().cloned().collect::<Vec<_>>();
|
||||
names.sort();
|
||||
@@ -31,11 +25,16 @@ fn sorted_mcp_server_names(mcp_servers: &HashMap<String, i32>) -> Vec<String> {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn apps_route_available_tracks_auth_mode() {
|
||||
assert!(apps_route_available(Some(AuthMode::Chatgpt)));
|
||||
assert!(apps_route_available(Some(AuthMode::AgentIdentity)));
|
||||
assert!(!apps_route_available(Some(AuthMode::ApiKey)));
|
||||
assert!(!apps_route_available(/*auth_mode*/ None));
|
||||
fn apps_route_is_never_available() {
|
||||
for auth_mode in [
|
||||
Some(AuthMode::ApiKey),
|
||||
Some(AuthMode::Headers),
|
||||
Some(AuthMode::BedrockApiKey),
|
||||
Some(AuthMode::BedrockAccessKeys),
|
||||
None,
|
||||
] {
|
||||
assert!(!apps_route_available(auth_mode));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -43,6 +42,21 @@ fn app_mcp_routing_clears_apps_when_apps_route_is_unavailable() {
|
||||
let mut apps = vec![app("linear")];
|
||||
let mut mcp_servers = mcp_servers([("linear", 1), ("docs", 2)]);
|
||||
|
||||
for (auth_mode, plugin_active) in [
|
||||
(Some(AuthMode::ApiKey), true),
|
||||
(Some(AuthMode::Headers), true),
|
||||
(Some(AuthMode::Headers), false),
|
||||
(None, true),
|
||||
] {
|
||||
let mut apps = apps.clone();
|
||||
let mut mcp_servers = mcp_servers.clone();
|
||||
apply_app_mcp_routing_policy(&mut apps, &mut mcp_servers, auth_mode, plugin_active);
|
||||
assert!(apps.is_empty());
|
||||
assert_eq!(
|
||||
sorted_mcp_server_names(&mcp_servers),
|
||||
vec!["docs".to_string(), "linear".to_string()]
|
||||
);
|
||||
}
|
||||
apply_app_mcp_routing_policy(
|
||||
&mut apps,
|
||||
&mut mcp_servers,
|
||||
@@ -56,44 +70,3 @@ fn app_mcp_routing_clears_apps_when_apps_route_is_unavailable() {
|
||||
vec!["docs".to_string(), "linear".to_string()]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn app_mcp_routing_preserves_apps_and_removes_conflicting_mcp_with_apps_route() {
|
||||
let mut apps = vec![app("linear"), app("notion")];
|
||||
let mut mcp_servers = mcp_servers([("linear", 1), ("docs", 2), ("notion", 3)]);
|
||||
|
||||
apply_app_mcp_routing_policy(
|
||||
&mut apps,
|
||||
&mut mcp_servers,
|
||||
Some(AuthMode::Chatgpt),
|
||||
/*plugin_active*/ true,
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
sorted_app_names(&apps),
|
||||
vec!["linear".to_string(), "notion".to_string()]
|
||||
);
|
||||
assert_eq!(
|
||||
sorted_mcp_server_names(&mcp_servers),
|
||||
vec!["docs".to_string()]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn app_mcp_routing_preserves_mcp_conflicts_when_plugin_is_inactive() {
|
||||
let mut apps = vec![app("linear")];
|
||||
let mut mcp_servers = mcp_servers([("linear", 1), ("docs", 2)]);
|
||||
|
||||
apply_app_mcp_routing_policy(
|
||||
&mut apps,
|
||||
&mut mcp_servers,
|
||||
Some(AuthMode::Chatgpt),
|
||||
/*plugin_active*/ false,
|
||||
);
|
||||
|
||||
assert_eq!(sorted_app_names(&apps), vec!["linear".to_string()]);
|
||||
assert_eq!(
|
||||
sorted_mcp_server_names(&mcp_servers),
|
||||
vec!["docs".to_string(), "linear".to_string()]
|
||||
);
|
||||
}
|
||||
|
||||
@@ -78,7 +78,10 @@ impl PluginsManager {
|
||||
}
|
||||
|
||||
let use_remote_global_catalog =
|
||||
input.plugins.remote_plugin_enabled && auth.is_some_and(CodexAuth::uses_codex_backend);
|
||||
input.plugins.remote_plugin_enabled
|
||||
&& auth.is_some_and(|auth| {
|
||||
crate::app_mcp_routing::apps_route_available(Some(auth.auth_mode()))
|
||||
});
|
||||
let marketplaces = self
|
||||
.list_marketplaces_for_config(
|
||||
&input.plugins,
|
||||
|
||||
@@ -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"),
|
||||
},
|
||||
)
|
||||
|
||||
@@ -102,7 +102,6 @@ use codex_config::types::ToolSuggestDisabledTool;
|
||||
use codex_config::types::ToolSuggestDiscoverableType;
|
||||
use codex_connectors::ConnectorSnapshot;
|
||||
use codex_connectors::PluginConnectorSource;
|
||||
use codex_features::RuntimeAuthMode;
|
||||
use codex_hooks::plugin_hook_declarations;
|
||||
use codex_http_client::ClientRouteClass;
|
||||
use codex_http_client::HttpClientFactory;
|
||||
@@ -119,7 +118,6 @@ use codex_plugin::prompt_safe_plugin_description;
|
||||
use codex_protocol::auth::AuthMode;
|
||||
use codex_protocol::protocol::HookEventName;
|
||||
use codex_protocol::protocol::Product;
|
||||
use codex_runtime_agent_instance::RuntimeAuthSlot;
|
||||
use codex_skills::SkillMetadata;
|
||||
use codex_skills::SkillRootLoader;
|
||||
use codex_skills::SkillRootSnapshots;
|
||||
@@ -168,8 +166,6 @@ pub struct PluginsConfigInput {
|
||||
pub product_sku: Option<String>,
|
||||
http_client_factory: HttpClientFactory,
|
||||
remote_http_clients: Arc<OnceLock<Arc<dyn HttpClientSelector>>>,
|
||||
runtime_http_clients: Arc<OnceLock<Arc<dyn HttpClientSelector>>>,
|
||||
runtime_auth_mode: Option<RuntimeAuthMode>,
|
||||
}
|
||||
|
||||
impl PluginsConfigInput {
|
||||
@@ -195,37 +191,13 @@ impl PluginsConfigInput {
|
||||
http_client_factory,
|
||||
product_sku,
|
||||
remote_http_clients: Arc::new(OnceLock::new()),
|
||||
runtime_http_clients: Arc::new(OnceLock::new()),
|
||||
runtime_auth_mode: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn with_runtime_auth_mode(mut self, mode: Option<RuntimeAuthMode>) -> Self {
|
||||
self.runtime_auth_mode = mode;
|
||||
self
|
||||
}
|
||||
|
||||
/// Shares lazy route-aware connection pools across this input and its clones.
|
||||
/// Runtime mode strips sensitive headers on cross-origin redirects.
|
||||
pub fn remote_plugin_service_config(
|
||||
&self,
|
||||
runtime_auth: Option<(RuntimeAuthSlot, RuntimeAuthMode)>,
|
||||
) -> RemotePluginServiceConfig {
|
||||
let runtime_auth = runtime_auth.filter(|_| {
|
||||
codex_http_client::classify_openai_api_url(&self.chatgpt_base_url)
|
||||
!= codex_http_client::OpenAiDestination::Other
|
||||
});
|
||||
let (http_clients, factory) = if runtime_auth.is_some() {
|
||||
(
|
||||
&self.runtime_http_clients,
|
||||
self.http_client_factory
|
||||
.clone()
|
||||
.with_sensitive_header_protection(),
|
||||
)
|
||||
} else {
|
||||
(&self.remote_http_clients, self.http_client_factory.clone())
|
||||
};
|
||||
let http_clients = http_clients.get_or_init(|| {
|
||||
pub fn remote_plugin_service_config(&self) -> RemotePluginServiceConfig {
|
||||
let factory = self.http_client_factory.clone();
|
||||
let http_clients = self.remote_http_clients.get_or_init(|| {
|
||||
Arc::new(
|
||||
RouteAwareClientPool::with_chatgpt_cloudflare_cookies_without_request_logging(
|
||||
factory,
|
||||
@@ -240,7 +212,6 @@ impl PluginsConfigInput {
|
||||
.clone()
|
||||
.unwrap_or_else(|| CODEX_PRODUCT_SKU.to_string()),
|
||||
http_clients: Arc::clone(http_clients),
|
||||
runtime_auth,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -264,9 +235,6 @@ pub struct RecommendedPluginCandidatesInput<'a> {
|
||||
#[derive(Clone, PartialEq, Eq)]
|
||||
struct FeaturedPluginIdsCacheKey {
|
||||
chatgpt_base_url: String,
|
||||
account_id: Option<String>,
|
||||
chatgpt_user_id: Option<String>,
|
||||
is_workspace_account: bool,
|
||||
}
|
||||
|
||||
#[derive(Clone, Hash, PartialEq, Eq)]
|
||||
@@ -284,18 +252,12 @@ struct CachedFeaturedPluginIds {
|
||||
#[derive(Clone, PartialEq, Eq)]
|
||||
pub(crate) struct RemoteInstalledPluginsAuthIdentity {
|
||||
auth_mode: Option<AuthMode>,
|
||||
account_id: Option<String>,
|
||||
chatgpt_user_id: Option<String>,
|
||||
is_workspace_account: Option<bool>,
|
||||
}
|
||||
|
||||
impl RemoteInstalledPluginsAuthIdentity {
|
||||
pub(crate) fn from_auth(auth: Option<&CodexAuth>) -> Self {
|
||||
Self {
|
||||
auth_mode: auth.map(CodexAuth::api_auth_mode),
|
||||
account_id: auth.and_then(CodexAuth::get_account_id),
|
||||
chatgpt_user_id: auth.and_then(CodexAuth::get_chatgpt_user_id),
|
||||
is_workspace_account: auth.map(CodexAuth::is_workspace_account),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -374,13 +336,7 @@ struct RemoteCatalogCacheRefreshRequest {
|
||||
|
||||
impl RemoteCatalogCacheRefreshRequest {
|
||||
fn has_same_cache_identity(&self, other: &Self) -> bool {
|
||||
self.service_config == other.service_config
|
||||
&& self.auth.as_ref().and_then(CodexAuth::get_account_id)
|
||||
== other.auth.as_ref().and_then(CodexAuth::get_account_id)
|
||||
&& self.auth.as_ref().and_then(CodexAuth::get_chatgpt_user_id)
|
||||
== other.auth.as_ref().and_then(CodexAuth::get_chatgpt_user_id)
|
||||
&& self.auth.as_ref().map(CodexAuth::is_workspace_account)
|
||||
== other.auth.as_ref().map(CodexAuth::is_workspace_account)
|
||||
self.service_config == other.service_config && self.auth == other.auth
|
||||
}
|
||||
}
|
||||
|
||||
@@ -437,15 +393,9 @@ struct ConfiguredMarketplaceUpgradeState {
|
||||
in_flight: bool,
|
||||
}
|
||||
|
||||
fn featured_plugin_ids_cache_key(
|
||||
config: &PluginsConfigInput,
|
||||
auth: Option<&CodexAuth>,
|
||||
) -> FeaturedPluginIdsCacheKey {
|
||||
fn featured_plugin_ids_cache_key(config: &PluginsConfigInput) -> FeaturedPluginIdsCacheKey {
|
||||
FeaturedPluginIdsCacheKey {
|
||||
chatgpt_base_url: config.chatgpt_base_url.clone(),
|
||||
account_id: auth.and_then(CodexAuth::get_account_id),
|
||||
chatgpt_user_id: auth.and_then(CodexAuth::get_chatgpt_user_id),
|
||||
is_workspace_account: auth.is_some_and(CodexAuth::is_workspace_account),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -592,7 +542,6 @@ pub struct PluginsManager {
|
||||
remote_catalog_cache_refresh_state: RwLock<RemoteCatalogCacheRefreshState>,
|
||||
restriction_product: Option<Product>,
|
||||
auth_manager: Arc<AuthManager>,
|
||||
runtime_auth: RuntimeAuthSlot,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
@@ -692,7 +641,7 @@ impl PluginLoadCacheKey {
|
||||
}
|
||||
|
||||
fn target_curated_marketplace(auth_mode: Option<AuthMode>) -> TargetCuratedMarketplace {
|
||||
if auth_mode.is_some_and(AuthMode::uses_codex_backend) {
|
||||
if crate::app_mcp_routing::apps_route_available(auth_mode) {
|
||||
TargetCuratedMarketplace::OpenAiWithRemote
|
||||
} else {
|
||||
TargetCuratedMarketplace::OpenAiApi
|
||||
@@ -700,37 +649,24 @@ fn target_curated_marketplace(auth_mode: Option<AuthMode>) -> TargetCuratedMarke
|
||||
}
|
||||
|
||||
impl PluginsManager {
|
||||
/// Build remote service state from the request's effective mode and this harness's runtime.
|
||||
/// Build remote service state from the request's effective configuration.
|
||||
pub fn remote_plugin_service_config(
|
||||
&self,
|
||||
config: &PluginsConfigInput,
|
||||
) -> RemotePluginServiceConfig {
|
||||
config.remote_plugin_service_config(
|
||||
config
|
||||
.runtime_auth_mode
|
||||
.map(|mode| (Arc::clone(&self.runtime_auth), mode)),
|
||||
)
|
||||
config.remote_plugin_service_config()
|
||||
}
|
||||
|
||||
pub fn auth_manager(&self) -> Arc<AuthManager> {
|
||||
Arc::clone(&self.auth_manager)
|
||||
}
|
||||
|
||||
pub fn runtime_auth_slot(&self) -> RuntimeAuthSlot {
|
||||
Arc::clone(&self.runtime_auth)
|
||||
}
|
||||
|
||||
/// Reuse host configuration without sharing another actor's remote caches or credentials.
|
||||
pub fn for_auth_context(
|
||||
&self,
|
||||
auth_manager: Arc<AuthManager>,
|
||||
runtime_auth: RuntimeAuthSlot,
|
||||
) -> Self {
|
||||
pub fn for_auth_context(&self, auth_manager: Arc<AuthManager>) -> Self {
|
||||
Self::new_with_options(
|
||||
self.codex_home.clone(),
|
||||
self.restriction_product,
|
||||
auth_manager,
|
||||
runtime_auth,
|
||||
Arc::clone(&self.skill_root_loader),
|
||||
)
|
||||
}
|
||||
@@ -744,7 +680,6 @@ impl PluginsManager {
|
||||
codex_home,
|
||||
Some(Product::Codex),
|
||||
auth_manager,
|
||||
RuntimeAuthSlot::default(),
|
||||
skill_root_loader,
|
||||
)
|
||||
}
|
||||
@@ -753,7 +688,6 @@ impl PluginsManager {
|
||||
codex_home: PathBuf,
|
||||
restriction_product: Option<Product>,
|
||||
auth_manager: Arc<AuthManager>,
|
||||
runtime_auth: RuntimeAuthSlot,
|
||||
skill_root_loader: Arc<dyn SkillRootLoader<PluginSkillRoot>>,
|
||||
) -> Self {
|
||||
// Product restrictions are enforced at marketplace admission time for a given CODEX_HOME:
|
||||
@@ -797,7 +731,6 @@ impl PluginsManager {
|
||||
),
|
||||
restriction_product,
|
||||
auth_manager,
|
||||
runtime_auth,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -806,7 +739,7 @@ impl PluginsManager {
|
||||
}
|
||||
|
||||
fn remote_global_catalog_active(&self, config: &PluginsConfigInput) -> bool {
|
||||
config.remote_plugin_enabled && self.auth_mode().is_some_and(AuthMode::uses_codex_backend)
|
||||
config.remote_plugin_enabled && crate::app_mcp_routing::apps_route_available(self.auth_mode())
|
||||
}
|
||||
|
||||
fn restriction_product_matches(&self, products: Option<&[Product]>) -> bool {
|
||||
@@ -1333,15 +1266,11 @@ impl PluginsManager {
|
||||
if !config.plugins_enabled || !config.remote_plugin_enabled {
|
||||
return Vec::new();
|
||||
}
|
||||
let Some(auth) = auth.filter(|auth| auth.uses_codex_backend()) else {
|
||||
let Some(auth) = auth.filter(|auth| {
|
||||
crate::app_mcp_routing::apps_route_available(Some(auth.auth_mode()))
|
||||
}) else {
|
||||
return Vec::new();
|
||||
};
|
||||
let Some(account_id) = auth.get_account_id() else {
|
||||
return Vec::new();
|
||||
};
|
||||
if account_id.is_empty() {
|
||||
return Vec::new();
|
||||
}
|
||||
|
||||
crate::remote::cached_global_remote_discoverable_plugins(
|
||||
self.codex_home.as_path(),
|
||||
@@ -1961,7 +1890,7 @@ impl PluginsManager {
|
||||
return Ok(Vec::new());
|
||||
}
|
||||
|
||||
let cache_key = featured_plugin_ids_cache_key(config, auth);
|
||||
let cache_key = featured_plugin_ids_cache_key(config);
|
||||
if let Some(featured_plugin_ids) = self.cached_featured_plugin_ids(&cache_key) {
|
||||
return Ok(featured_plugin_ids);
|
||||
}
|
||||
@@ -1990,7 +1919,9 @@ impl PluginsManager {
|
||||
) -> RecommendedPluginsMode {
|
||||
if !config.plugins_enabled
|
||||
|| !config.remote_plugin_enabled
|
||||
|| !auth.is_some_and(CodexAuth::uses_codex_backend)
|
||||
|| !auth.is_some_and(|auth| {
|
||||
crate::app_mcp_routing::apps_route_available(Some(auth.auth_mode()))
|
||||
})
|
||||
{
|
||||
return RecommendedPluginsMode::Legacy;
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -8,10 +8,8 @@ mod skills;
|
||||
|
||||
#[tokio::test]
|
||||
async fn curated_git_policy_controls_catalog_install_and_cached_activation() {
|
||||
for (name, auth) in [
|
||||
(OPENAI_CURATED_MARKETPLACE_NAME, AuthMode::Chatgpt),
|
||||
(OPENAI_API_CURATED_MARKETPLACE_NAME, AuthMode::ApiKey),
|
||||
] {
|
||||
// The ChatGPT curated catalog required ChatGPT auth; only the API catalog remains.
|
||||
for (name, auth) in [(OPENAI_API_CURATED_MARKETPLACE_NAME, AuthMode::ApiKey)] {
|
||||
let home = TempDir::new().unwrap();
|
||||
let root = curated_plugins_repo_path(home.path());
|
||||
write_openai_curated_marketplace(&root, &["sample"]);
|
||||
@@ -91,24 +89,3 @@ host_pattern = '^github[.]com$'
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn blocking_curated_git_does_not_block_remote_installed_plugins() {
|
||||
let home = TempDir::new().unwrap();
|
||||
write_cached_plugin(home.path(), REMOTE_GLOBAL_MARKETPLACE_NAME, "linear");
|
||||
let manager = test_plugins_manager_with_options(
|
||||
home.path().to_path_buf(),
|
||||
Some(Product::Codex),
|
||||
Some(AuthMode::Chatgpt),
|
||||
);
|
||||
manager.write_remote_installed_plugins_cache(vec![remote_installed_plugin("linear")]);
|
||||
let mut config = plugins_config_input_with_requirements(
|
||||
home.path(),
|
||||
"",
|
||||
"[marketplaces]\nrestrict_to_allowed_sources = true\n",
|
||||
);
|
||||
config.remote_plugin_enabled = true;
|
||||
assert_eq!(
|
||||
loaded_plugin_names(&manager, &config).await,
|
||||
vec!["linear@openai-curated-remote".to_string()]
|
||||
);
|
||||
}
|
||||
|
||||
@@ -26,9 +26,8 @@ use tempfile::TempDir;
|
||||
|
||||
#[tokio::test]
|
||||
async fn curated_git_requirements_control_plugin_skills() -> Result<()> {
|
||||
// The ChatGPT curated catalog required ChatGPT auth; the API catalog is the only curated one.
|
||||
for (name, allow_curated) in [
|
||||
("openai-curated", true),
|
||||
("openai-curated", false),
|
||||
("openai-api-curated", true),
|
||||
("openai-api-curated", false),
|
||||
("openai-bundled", false),
|
||||
@@ -95,11 +94,7 @@ async fn curated_git_requirements_control_plugin_skills() -> Result<()> {
|
||||
HttpClientFactory::new(OutboundProxyPolicy::ReqwestDefault),
|
||||
/*product_sku*/ None,
|
||||
);
|
||||
let auth = if name == "openai-curated" {
|
||||
CodexAuth::create_dummy_chatgpt_auth_for_testing()
|
||||
} else {
|
||||
CodexAuth::from_api_key("test-api-key")
|
||||
};
|
||||
let auth = CodexAuth::from_api_key("test-api-key");
|
||||
let skills = test_skill_root_loader();
|
||||
let manager = PluginsManager::new(
|
||||
home.path().to_path_buf(),
|
||||
|
||||
@@ -20,14 +20,12 @@ fn repeated_service_configs_and_early_clones_share_one_lazy_pool() {
|
||||
);
|
||||
let clone = input.clone();
|
||||
assert!(input.remote_http_clients.get().is_none());
|
||||
let first = input.remote_plugin_service_config(/*runtime_auth*/ None);
|
||||
let first = input.remote_plugin_service_config();
|
||||
let reuse: Vec<_> = (0..220)
|
||||
.map(|_| {
|
||||
Arc::ptr_eq(
|
||||
&first.http_clients,
|
||||
&clone
|
||||
.remote_plugin_service_config(/*runtime_auth*/ None)
|
||||
.http_clients,
|
||||
&clone.remote_plugin_service_config().http_clients,
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
@@ -46,9 +44,7 @@ fn repeated_service_configs_and_early_clones_share_one_lazy_pool() {
|
||||
reuse,
|
||||
Arc::ptr_eq(
|
||||
&first.http_clients,
|
||||
&new_input
|
||||
.remote_plugin_service_config(/*runtime_auth*/ None)
|
||||
.http_clients,
|
||||
&new_input.remote_plugin_service_config().http_clients,
|
||||
),
|
||||
),
|
||||
(vec![true; 220], false)
|
||||
|
||||
@@ -13,7 +13,6 @@ use codex_app_server_protocol::PluginInstallPolicySource;
|
||||
use codex_app_server_protocol::PluginInterface;
|
||||
use codex_app_server_protocol::ScheduledTaskSummary;
|
||||
use codex_app_server_protocol::SkillInterface;
|
||||
use codex_features::RuntimeAuthMode;
|
||||
use codex_http_client::ClientRouteClass;
|
||||
use codex_http_client::HttpClientFactory;
|
||||
use codex_http_client::RouteAwareClientPool;
|
||||
@@ -25,7 +24,6 @@ use codex_plugin::PluginCapabilitySummary;
|
||||
use codex_plugin::PluginId;
|
||||
use codex_plugin::app_connector_ids_from_declarations;
|
||||
use codex_plugin::prompt_safe_plugin_description;
|
||||
use codex_runtime_agent_instance::RuntimeAuthSlot;
|
||||
use http::StatusCode;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
@@ -123,7 +121,6 @@ pub struct RemotePluginServiceConfig {
|
||||
pub chatgpt_base_url: String,
|
||||
pub(crate) product_sku: String,
|
||||
pub(crate) http_clients: Arc<dyn HttpClientSelector>,
|
||||
pub(crate) runtime_auth: Option<(RuntimeAuthSlot, RuntimeAuthMode)>,
|
||||
}
|
||||
|
||||
impl RemotePluginServiceConfig {
|
||||
@@ -152,7 +149,6 @@ impl RemotePluginServiceConfig {
|
||||
chatgpt_base_url,
|
||||
product_sku: product_sku.unwrap_or_else(|| CODEX_PRODUCT_SKU.to_string()),
|
||||
http_clients,
|
||||
runtime_auth: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -161,13 +157,6 @@ impl PartialEq for RemotePluginServiceConfig {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.chatgpt_base_url == other.chatgpt_base_url
|
||||
&& self.product_sku == other.product_sku
|
||||
&& match (&self.runtime_auth, &other.runtime_auth) {
|
||||
(Some((left, left_mode)), Some((right, right_mode))) => {
|
||||
Arc::ptr_eq(left, right) && left_mode == right_mode
|
||||
}
|
||||
(None, None) => true,
|
||||
_ => false,
|
||||
}
|
||||
&& self.http_clients.outbound_proxy_policy()
|
||||
== other.http_clients.outbound_proxy_policy()
|
||||
}
|
||||
@@ -1933,7 +1922,7 @@ fn ensure_chatgpt_auth(auth: Option<&CodexAuth>) -> Result<&CodexAuth, RemotePlu
|
||||
let Some(auth) = auth else {
|
||||
return Err(RemotePluginCatalogError::AuthRequired);
|
||||
};
|
||||
if !auth.uses_codex_backend() {
|
||||
if !crate::app_mcp_routing::apps_route_available(Some(auth.auth_mode())) {
|
||||
return Err(RemotePluginCatalogError::UnsupportedAuthMode);
|
||||
}
|
||||
Ok(auth)
|
||||
|
||||
@@ -5,6 +5,7 @@ use super::RemotePluginServiceConfig;
|
||||
use chrono::DateTime;
|
||||
use chrono::Utc;
|
||||
use codex_login::CodexAuth;
|
||||
use codex_protocol::auth::AuthMode;
|
||||
use serde::Deserialize;
|
||||
use serde::Deserializer;
|
||||
use serde::Serialize;
|
||||
@@ -32,9 +33,7 @@ const REMOTE_PLUGIN_CATALOG_DISK_CACHE_TTL: Duration = Duration::from_secs(60 *
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||
struct RemotePluginCatalogCacheKey {
|
||||
chatgpt_base_url: String,
|
||||
account_id: Option<String>,
|
||||
chatgpt_user_id: Option<String>,
|
||||
is_workspace_account: bool,
|
||||
auth_mode: AuthMode,
|
||||
// Global catalogs predate scoped cache keys and must keep their existing filenames.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
scope: Option<RemotePluginScope>,
|
||||
@@ -49,24 +48,17 @@ impl RemotePluginCatalogCacheKey {
|
||||
scope: RemotePluginScope,
|
||||
collection: Option<&str>,
|
||||
) -> Option<Self> {
|
||||
let cache_key = Self {
|
||||
chatgpt_base_url: config.chatgpt_base_url.clone(),
|
||||
account_id: auth.get_account_id(),
|
||||
chatgpt_user_id: auth.get_chatgpt_user_id(),
|
||||
is_workspace_account: auth.is_workspace_account(),
|
||||
scope: (scope != RemotePluginScope::Global).then_some(scope),
|
||||
collection: collection.map(str::to_owned),
|
||||
};
|
||||
// Preserve global catalog caching for existing header-auth clients, but never share
|
||||
// user or workspace catalogs when the auth mode cannot identify their owner.
|
||||
if !matches!(scope, RemotePluginScope::Global)
|
||||
&& cache_key.account_id.is_none()
|
||||
&& cache_key.chatgpt_user_id.is_none()
|
||||
{
|
||||
// Credentials never identify an account owner, so only the global catalog may be
|
||||
// cached; user and workspace catalogs are never shared.
|
||||
if !matches!(scope, RemotePluginScope::Global) {
|
||||
return None;
|
||||
}
|
||||
|
||||
Some(cache_key)
|
||||
Some(Self {
|
||||
chatgpt_base_url: config.chatgpt_base_url.clone(),
|
||||
auth_mode: auth.auth_mode(),
|
||||
scope: None,
|
||||
collection: collection.map(str::to_owned),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
use super::*;
|
||||
use chrono::TimeDelta;
|
||||
use codex_login::AuthHeaders;
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
#[test]
|
||||
fn catalog_cache_freshness_honors_ttl() {
|
||||
@@ -22,9 +21,7 @@ fn catalog_cache_paths_are_isolated_by_scope_and_collection() {
|
||||
let codex_home = Path::new("/tmp/codex-home");
|
||||
let cache_key_for_scope = |scope| RemotePluginCatalogCacheKey {
|
||||
chatgpt_base_url: "https://chatgpt.com/backend-api".to_string(),
|
||||
account_id: Some("account-id".to_string()),
|
||||
chatgpt_user_id: Some("user-id".to_string()),
|
||||
is_workspace_account: true,
|
||||
auth_mode: codex_protocol::auth::AuthMode::Headers,
|
||||
scope: (scope != RemotePluginScope::Global).then_some(scope),
|
||||
collection: None,
|
||||
};
|
||||
@@ -45,55 +42,6 @@ fn catalog_cache_paths_are_isolated_by_scope_and_collection() {
|
||||
assert!(!paths.contains(&cache_path(codex_home, &collection_key)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn global_catalog_cache_reuses_legacy_cache_file() {
|
||||
let codex_home = tempfile::tempdir().expect("create codex home");
|
||||
let config = RemotePluginServiceConfig::new(
|
||||
"https://chatgpt.com/backend-api".to_string(),
|
||||
crate::test_support::test_http_client_factory(),
|
||||
/*product_sku*/ None,
|
||||
);
|
||||
let auth = CodexAuth::Headers(AuthHeaders::new(http::HeaderMap::new()));
|
||||
let legacy_cache_path = codex_home
|
||||
.path()
|
||||
.join(REMOTE_PLUGIN_CATALOG_DISK_CACHE_DIR)
|
||||
.join("f22564d6f8ca89f6.json");
|
||||
let legacy_cache = serde_json::json!({
|
||||
"schema_version": REMOTE_PLUGIN_CATALOG_DISK_CACHE_SCHEMA_VERSION,
|
||||
"plugins": [],
|
||||
});
|
||||
codex_utils_path::write_atomically(&legacy_cache_path, &legacy_cache.to_string())
|
||||
.expect("write legacy cache");
|
||||
|
||||
let cached = load_cached_directory_plugins::<RemotePluginDirectoryItem>(
|
||||
codex_home.path(),
|
||||
&config,
|
||||
&auth,
|
||||
RemotePluginScope::Global,
|
||||
/*collection*/ None,
|
||||
RemotePluginCatalogCacheMode::PreferCache,
|
||||
)
|
||||
.expect("load legacy global cache");
|
||||
assert!(cached.plugins.is_empty());
|
||||
assert_eq!(cached.freshness, RemotePluginCatalogCacheFreshness::Stale);
|
||||
|
||||
write_cached_directory_plugins(
|
||||
codex_home.path(),
|
||||
&config,
|
||||
&auth,
|
||||
RemotePluginScope::Global,
|
||||
/*collection*/ None,
|
||||
&[],
|
||||
);
|
||||
assert!(has_cached_directory_plugins(
|
||||
codex_home.path(),
|
||||
&config,
|
||||
&auth,
|
||||
RemotePluginScope::Global,
|
||||
RemotePluginCatalogCacheMode::PreferFreshCache,
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn freshness_probe_defers_plugin_validation_until_full_read() {
|
||||
let codex_home = tempfile::tempdir().expect("create codex home");
|
||||
@@ -204,9 +152,7 @@ fn header_auth_does_not_cache_private_catalogs_without_a_stable_identity() {
|
||||
for scope in [RemotePluginScope::User, RemotePluginScope::Workspace] {
|
||||
let insecure_cache_key = RemotePluginCatalogCacheKey {
|
||||
chatgpt_base_url: config.chatgpt_base_url.clone(),
|
||||
account_id: None,
|
||||
chatgpt_user_id: None,
|
||||
is_workspace_account: false,
|
||||
auth_mode: codex_protocol::auth::AuthMode::Headers,
|
||||
scope: Some(scope),
|
||||
collection: None,
|
||||
};
|
||||
|
||||
@@ -1,135 +0,0 @@
|
||||
//! Metadata publication must preserve derived caches until runtime inputs change.
|
||||
|
||||
use super::*;
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
#[tokio::test]
|
||||
async fn display_refresh_preserves_loaded_skills_and_tool_suggestions() {
|
||||
let codex_home = TempDir::new().unwrap();
|
||||
let marketplace_root = codex_home
|
||||
.path()
|
||||
.join("plugins/cache/openai-curated-remote");
|
||||
write_plugin(&marketplace_root, "sample/local", "sample");
|
||||
let plugin_root = marketplace_root.join("sample/local");
|
||||
write_file(
|
||||
&codex_home.path().join(CONFIG_TOML_FILE),
|
||||
r#"[features]
|
||||
plugins = true
|
||||
remote_plugin = true
|
||||
|
||||
[plugins."sample@openai-curated-remote"]
|
||||
enabled = true
|
||||
"#,
|
||||
);
|
||||
let config = load_config(codex_home.path(), codex_home.path()).await;
|
||||
let manager = test_plugins_manager_with_options(
|
||||
codex_home.path().to_path_buf(),
|
||||
Some(Product::Codex),
|
||||
Some(AuthMode::Chatgpt),
|
||||
);
|
||||
let mut remote = remote_installed_plugin("sample");
|
||||
remote.interface = Some(
|
||||
serde_json::from_value(serde_json::json!({
|
||||
"capabilities": [], "screenshots": [], "screenshotUrls": [],
|
||||
"logoUrl": "https://files.openai.com/logo.png?sig=old"
|
||||
}))
|
||||
.unwrap(),
|
||||
);
|
||||
assert!(manager.write_remote_installed_plugins_cache(vec![remote.clone()]));
|
||||
|
||||
let loaded = manager.plugins_for_config(&config).await;
|
||||
let snapshots = manager.plugin_skill_snapshots_for_config(&config).unwrap();
|
||||
let roots = loaded.effective_plugin_skill_roots();
|
||||
assert_eq!(roots.len(), 1);
|
||||
assert_eq!(snapshots.get(&roots[0]).unwrap().skills.len(), 1);
|
||||
let loaded_generation = manager.loaded_plugins_cache_generation();
|
||||
let plugin = ConfiguredMarketplacePlugin {
|
||||
id: "sample@openai-curated-remote".to_string(),
|
||||
name: "sample".to_string(),
|
||||
local_version: None,
|
||||
installed_version: None,
|
||||
source: MarketplacePluginSource::Local {
|
||||
path: plugin_root.abs(),
|
||||
},
|
||||
policy: MarketplacePluginPolicy {
|
||||
installation: MarketplacePluginInstallPolicy::Available,
|
||||
authentication: MarketplacePluginAuthPolicy::OnUse,
|
||||
products: None,
|
||||
},
|
||||
interface: None,
|
||||
keywords: Vec::new(),
|
||||
manifest_fallback: None,
|
||||
installed: true,
|
||||
enabled: true,
|
||||
};
|
||||
let suggestions = manager
|
||||
.tool_suggest_metadata_cache
|
||||
.metadata_for_plugin(
|
||||
REMOTE_GLOBAL_MARKETPLACE_NAME,
|
||||
&plugin,
|
||||
manager.restriction_product,
|
||||
manager.skill_root_loader.as_ref(),
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
assert!(
|
||||
suggestions
|
||||
.project(&SkillConfigRules::default(), manager.auth_mode())
|
||||
.has_skills
|
||||
);
|
||||
|
||||
let interface = remote.interface.as_mut().unwrap();
|
||||
interface.logo_url = Some("https://files.openai.com/logo.png?sig=new".to_string());
|
||||
interface.display_name = Some("Updated display name".to_string());
|
||||
interface.capabilities = vec!["Updated store badge".to_string()];
|
||||
assert!(!manager.write_remote_installed_plugins_cache(vec![remote.clone()]));
|
||||
assert_eq!(
|
||||
manager
|
||||
.remote_installed_plugins_cache
|
||||
.read()
|
||||
.unwrap()
|
||||
.plugins,
|
||||
Some(vec![remote.clone()])
|
||||
);
|
||||
assert_eq!(manager.loaded_plugins_cache_generation(), loaded_generation);
|
||||
assert_eq!(
|
||||
manager.plugin_skill_snapshots_for_config(&config),
|
||||
Some(snapshots.clone())
|
||||
);
|
||||
assert_eq!(manager.plugins_for_config(&config).await, loaded);
|
||||
let refreshed_suggestions = manager
|
||||
.tool_suggest_metadata_cache
|
||||
.metadata_for_plugin(
|
||||
REMOTE_GLOBAL_MARKETPLACE_NAME,
|
||||
&plugin,
|
||||
manager.restriction_product,
|
||||
manager.skill_root_loader.as_ref(),
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
assert!(Arc::ptr_eq(&suggestions, &refreshed_suggestions));
|
||||
|
||||
remote.version = Some("2.0.0".to_string());
|
||||
assert!(manager.write_remote_installed_plugins_cache(vec![remote]));
|
||||
assert_eq!(
|
||||
manager.loaded_plugins_cache_generation(),
|
||||
loaded_generation + 1
|
||||
);
|
||||
assert_eq!(manager.plugin_skill_snapshots_for_config(&config), None);
|
||||
manager.plugins_for_config(&config).await;
|
||||
assert_ne!(
|
||||
manager.plugin_skill_snapshots_for_config(&config),
|
||||
Some(snapshots)
|
||||
);
|
||||
let changed_suggestions = manager
|
||||
.tool_suggest_metadata_cache
|
||||
.metadata_for_plugin(
|
||||
REMOTE_GLOBAL_MARKETPLACE_NAME,
|
||||
&plugin,
|
||||
manager.restriction_product,
|
||||
manager.skill_root_loader.as_ref(),
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
assert!(!Arc::ptr_eq(&suggestions, &changed_suggestions));
|
||||
}
|
||||
@@ -27,7 +27,6 @@ use codex_login::test_support::auth_manager_from_optional_auth;
|
||||
use codex_protocol::auth::AuthMode;
|
||||
use codex_protocol::protocol::Product;
|
||||
use codex_protocol::protocol::SkillScope;
|
||||
use codex_runtime_agent_instance::RuntimeAuthSlot;
|
||||
use codex_skills::LoadedSkillRoot;
|
||||
use codex_skills::LoadedSkills;
|
||||
use codex_skills::SkillError;
|
||||
@@ -75,7 +74,6 @@ pub(crate) fn test_plugins_manager_with_options(
|
||||
codex_home,
|
||||
restriction_product,
|
||||
test_auth_manager(auth_mode),
|
||||
RuntimeAuthSlot::default(),
|
||||
test_skill_root_loader(),
|
||||
)
|
||||
}
|
||||
@@ -89,7 +87,6 @@ pub(crate) fn test_plugins_manager_with_auth_manager(
|
||||
codex_home,
|
||||
restriction_product,
|
||||
auth_manager,
|
||||
RuntimeAuthSlot::default(),
|
||||
test_skill_root_loader(),
|
||||
)
|
||||
}
|
||||
@@ -116,13 +113,6 @@ pub(crate) async fn set_test_auth(auth_manager: &AuthManager, auth: Option<Codex
|
||||
fn test_codex_auth(auth_mode: Option<AuthMode>) -> Option<CodexAuth> {
|
||||
auth_mode.map(|auth_mode| match auth_mode {
|
||||
AuthMode::ApiKey => CodexAuth::from_api_key("test-api-key"),
|
||||
AuthMode::Chatgpt => CodexAuth::create_dummy_chatgpt_auth_for_testing(),
|
||||
AuthMode::ChatgptAuthTokens => CodexAuth::from_external_chatgpt_tokens(
|
||||
"header.e30.test",
|
||||
"test-account",
|
||||
/*chatgpt_plan_type*/ None,
|
||||
)
|
||||
.expect("test ChatGPT tokens should parse"),
|
||||
AuthMode::Headers => CodexAuth::Headers(AuthHeaders::new(http::HeaderMap::new())),
|
||||
AuthMode::BedrockApiKey => CodexAuth::BedrockApiKey(BedrockApiKeyAuth {
|
||||
api_key: "test-api-key".to_string(),
|
||||
@@ -133,9 +123,6 @@ fn test_codex_auth(auth_mode: Option<AuthMode>) -> Option<CodexAuth> {
|
||||
secret_access_key: "test-secret-access-key".to_string(),
|
||||
session_token: None,
|
||||
}),
|
||||
AuthMode::AgentIdentity | AuthMode::PersonalAccessToken => {
|
||||
panic!("test auth mode requires a purpose-built CodexAuth")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user