Add configurable default plugin activation policy (#52220)

## What changed

Support `plugins._default.enabled` with explicit per-plugin `enabled` overrides. Omission preserves existing source and account enablement; configuration cannot activate a plugin disabled at its source. Plugin settings such as remembered tool approvals inherit the default unless `enabled` is explicitly set.

Apply the policy to plugin skills, MCP servers, Apps, and hooks, including selected executor roots and runtime configuration refreshes. Preserve the latest plugin policy when adding MCP dependencies and rebuild hooks when concurrent configuration updates replace their inputs.

Report effective enablement in `plugin/list`, `plugin/installed`, `plugin/read`, and `plugin/share/list`. Remote installation still installs disabled packages, but skips MCP and Apps authentication setup without writing an enablement override.

## Testing

Add regression coverage for default inheritance and explicit overrides, source-disabled plugins, policy refreshes during active turns, disabled or malformed selected plugin roots, and remote installation authentication behavior.

GitOrigin-RevId: 83b70c5b47fc95474fec292f248683f1f887221e
This commit is contained in:
stevenlee-oai
2026-10-08 18:42:58 +00:00
committed by copyberry
parent 79773e8826
commit 89d68bc8d2
49 changed files with 2134 additions and 240 deletions
@@ -2,6 +2,7 @@
use codex_config::DEFAULT_MCP_SERVER_ENVIRONMENT_ID;
use codex_config::HookHandlerConfig;
use codex_config::types::PluginsConfigToml;
use codex_exec_server::ExecutorCapabilityDiscoverySnapshot;
use codex_mcp::CODEX_APPS_MCP_SERVER_NAME;
use codex_mcp::MCP_TOOL_CODEX_APPS_META_KEY;
@@ -28,11 +29,15 @@ use crate::manifest::parse_plugin_manifest_uri;
/// hooks from the bundled cleanup allowlist and the remote Browser plugin.
pub fn executor_plugin_hook_sources<'a>(
snapshot: &ExecutorCapabilityDiscoverySnapshot,
plugins_config: &PluginsConfigToml,
lookup_enabled_tool: impl Fn(&str, &str) -> Option<&'a ToolInfo>,
) -> Vec<ExecutorPluginHookSource> {
let mut sources = Vec::new();
for entry in snapshot.roots() {
if !plugins_config.allows_plugin(&entry.selected_root.id) {
continue;
}
let Ok(plugin_id) = PluginId::parse(&entry.selected_root.id) else {
continue;
};
@@ -130,7 +130,8 @@ fn discovers_allowlisted_executor_plugin_hook_sources() {
manifest,
);
let sources = executor_plugin_hook_sources(&snapshot, |_, _| None);
let sources =
executor_plugin_hook_sources(&snapshot, &PluginsConfigToml::default(), |_, _| None);
let mut interrupt_source = expected_source(/*index*/ 1);
interrupt_source.hooks.interrupt = std::mem::take(&mut interrupt_source.hooks.stop);
let mut stop_and_interrupt_source = expected_source(/*index*/ 2);
@@ -144,6 +145,22 @@ fn discovers_allowlisted_executor_plugin_hook_sources() {
stop_and_interrupt_source,
]
);
for (config, expected) in [
(
"[_default]\nenabled = false\n[\"computer-use@other-marketplace\"]\nenabled = true",
Vec::new(),
),
(
"[_default]\nenabled = false\n[\"computer-use@openai-bundled\"]\nenabled = true",
sources,
),
] {
let config = toml::from_str(config).expect("plugin policy");
assert_eq!(
executor_plugin_hook_sources(&snapshot, &config, |_, _| None),
expected
);
}
}
#[test]
@@ -165,7 +182,7 @@ fn discovers_unified_computer_use_cleanup_hooks() {
*server = "cua_repl".to_string();
assert_eq!(
executor_plugin_hook_sources(&snapshot, |_, _| None),
executor_plugin_hook_sources(&snapshot, &PluginsConfigToml::default(), |_, _| None),
vec![expected]
);
}
@@ -202,7 +219,7 @@ fn filters_mixed_handlers_without_rewriting_allowed_groups() {
);
assert_eq!(
executor_plugin_hook_sources(&snapshot, |_, _| None),
executor_plugin_hook_sources(&snapshot, &PluginsConfigToml::default(), |_, _| None),
vec![expected]
);
}
@@ -234,7 +251,7 @@ fn preserves_allowlisted_executor_plugin_hook_options() {
expected.hooks.interrupt = expected.hooks.stop.clone();
assert_eq!(
executor_plugin_hook_sources(&snapshot, |_, _| None),
executor_plugin_hook_sources(&snapshot, &PluginsConfigToml::default(), |_, _| None),
vec![expected]
);
}
@@ -378,11 +395,15 @@ fn resolves_apps_hook_metadata_from_the_registered_connector() {
}))
.expect("listed tool")
});
let actual = executor_plugin_hook_sources(&snapshot, |server, tool| {
tool_info
.as_ref()
.filter(|info| info.server_name == server && info.tool.name == tool)
});
let actual = executor_plugin_hook_sources(
&snapshot,
&PluginsConfigToml::default(),
|server, tool| {
tool_info
.as_ref()
.filter(|info| info.server_name == server && info.tool.name == tool)
},
);
let expected = if admitted {
vec![expected.clone()]
} else {
@@ -454,7 +475,7 @@ fn ignores_unallowlisted_executor_plugin_hooks() {
);
assert_eq!(
executor_plugin_hook_sources(&snapshot, |_, _| None),
executor_plugin_hook_sources(&snapshot, &PluginsConfigToml::default(), |_, _| None),
Vec::<ExecutorPluginHookSource>::new(),
"{name}"
);
@@ -474,7 +495,7 @@ fn ignores_file_backed_executor_plugin_hooks() {
);
assert_eq!(
executor_plugin_hook_sources(&file_backed, |_, _| None),
executor_plugin_hook_sources(&file_backed, &PluginsConfigToml::default(), |_, _| None),
Vec::<ExecutorPluginHookSource>::new()
);
}
+19 -16
View File
@@ -30,6 +30,7 @@ use codex_config::types::McpServerConfig;
use codex_config::types::McpServerTransportConfig;
use codex_config::types::PluginConfig;
use codex_config::types::PluginMcpServerConfig;
use codex_config::types::PluginsConfigToml;
use codex_connectors::parse_plugin_app_config;
use codex_connectors::parse_plugin_app_config_value;
use codex_mcp::parse_agent_plugin_mcp_config;
@@ -54,6 +55,7 @@ use codex_utils_plugins::PluginSkillRoot;
use codex_utils_plugins::SkillDiscoveryMode;
use codex_utils_plugins::find_plugin_manifest_path;
use codex_utils_plugins::migrated_command_skills_root;
use serde::Deserialize;
use serde_json::Value as JsonValue;
use std::collections::HashMap;
use std::collections::HashSet;
@@ -131,8 +133,11 @@ pub(crate) fn log_plugin_load_errors(plugins: &[LoadedPlugin<McpServerConfig>])
/// Load configured plugins without applying auth-dependent runtime policies.
#[instrument(level = "trace", skip_all)]
// Keep validated policy with the existing snapshot inputs instead of reparsing layers.
#[allow(clippy::too_many_arguments)]
pub(crate) async fn load_plugins_from_layer_stack(
config_layer_stack: &ConfigLayerStack,
plugin_policy: &codex_config::types::PluginsConfigToml,
remote_installed_plugins_snapshot: RemoteInstalledPluginsSnapshot,
store: &PluginStore,
plugin_skill_snapshots: Option<&SkillRootSnapshots<PluginSkillRoot>>,
@@ -147,6 +152,7 @@ pub(crate) async fn load_plugins_from_layer_stack(
} = remote_installed_plugins_snapshot;
load_plugins_from_layer_stack_with_scope(
config_layer_stack,
plugin_policy,
extra_plugins,
store,
remote_global_catalog_active,
@@ -163,17 +169,22 @@ pub(crate) async fn load_plugins_from_layer_stack(
async fn load_plugins_from_layer_stack_with_scope(
config_layer_stack: &ConfigLayerStack,
plugin_policy: &codex_config::types::PluginsConfigToml,
extra_plugins: HashMap<String, PluginConfig>,
store: &PluginStore,
remote_global_catalog_active: bool,
scope: PluginLoadScope<'_>,
) -> Vec<LoadedPlugin<McpServerConfig>> {
let configured_plugins = merge_configured_plugins_with_remote_installed(
let mut configured_plugins = merge_configured_plugins_with_remote_installed(
configured_plugins_from_stack(config_layer_stack, store.codex_home().as_path()),
extra_plugins,
store,
remote_global_catalog_active,
);
for (plugin_id, plugin) in &mut configured_plugins {
plugin.enabled =
Some(plugin.enabled.unwrap_or(true) && plugin_policy.allows_plugin(plugin_id));
}
let mut configured_plugins: Vec<_> = configured_plugins.into_iter().collect();
configured_plugins.sort_unstable_by(|(a, _), (b, _)| a.cmp(b));
@@ -202,6 +213,7 @@ async fn load_plugins_from_layer_stack_with_scope(
/// Load hooks from enabled plugins without loading their skills, MCP servers, or apps.
pub async fn load_plugin_hooks_from_layer_stack(
config_layer_stack: &ConfigLayerStack,
plugin_policy: &codex_config::types::PluginsConfigToml,
extra_plugins: HashMap<String, PluginConfig>,
store: &PluginStore,
target_curated_marketplace: TargetCuratedMarketplace,
@@ -209,6 +221,7 @@ pub async fn load_plugin_hooks_from_layer_stack(
) -> PluginHookLoadOutcome {
let mut plugins = load_plugins_from_layer_stack_with_scope(
config_layer_stack,
plugin_policy,
extra_plugins,
store,
remote_global_catalog_active,
@@ -365,7 +378,7 @@ pub fn remote_installed_plugins_to_config(
Some((
plugin_id.as_key(),
PluginConfig {
enabled: plugin.enabled,
enabled: Some(plugin.enabled),
mcp_servers: HashMap::new(),
},
))
@@ -736,8 +749,8 @@ fn configured_plugins_from_config_value(
let Some(plugins_value) = user_config.get("plugins") else {
return HashMap::new();
};
match plugins_value.clone().try_into() {
Ok(plugins) => plugins,
match PluginsConfigToml::deserialize(plugins_value.clone()) {
Ok(plugins) => plugins.plugins,
Err(err) => {
warn!("invalid plugins config: {err}");
HashMap::new()
@@ -846,7 +859,7 @@ async fn load_plugin(
plugin_namespace: None,
manifest_description: None,
root,
enabled: plugin.enabled,
enabled: plugin.enabled.unwrap_or(true),
skill_roots: Vec::new(),
skill_discovery_mode: SkillDiscoveryMode::Recursive,
disabled_skill_paths: HashSet::new(),
@@ -858,7 +871,7 @@ async fn load_plugin(
error: None,
};
if !plugin.enabled {
if !loaded_plugin.enabled {
return loaded_plugin;
}
@@ -1421,16 +1434,6 @@ pub async fn load_configured_plugin_mcp_servers(
load_plugin_mcp_servers_with_policy(plugin_root, auth_mode, plugin_policy).await
}
/// Resolves effective per-plugin MCP policies without validating opaque selected-root IDs.
pub fn configured_plugin_mcp_server_policies(
config_layer_stack: &ConfigLayerStack,
) -> HashMap<String, HashMap<String, PluginMcpServerConfig>> {
configured_plugins_from_config_value(&config_layer_stack.effective_config())
.into_iter()
.map(|(plugin_id, plugin)| (plugin_id, plugin.mcp_servers))
.collect()
}
/// Applies user policy without widening the selected plugin's declared restrictions.
pub fn apply_configured_plugin_mcp_server_policies(
policies: &HashMap<String, PluginMcpServerConfig>,
+96 -7
View File
@@ -7,6 +7,7 @@ use codex_config::ConfigLayerEntry;
use codex_config::ConfigLayerSource;
use codex_config::ConfigRequirements;
use codex_config::ConfigRequirementsToml;
use codex_config::config_toml::ConfigToml;
use codex_plugin::PluginId;
use codex_utils_plugins::AGENT_PLUGIN_SCHEMA_URI;
use pretty_assertions::assert_eq;
@@ -278,6 +279,11 @@ async fn installed_agent_plugin_uses_isolated_data_root_for_stdio_mcp() {
let plugins = load_plugins_from_layer_stack(
&stack,
&stack
.effective_config()
.try_into::<codex_config::config_toml::ConfigToml>()
.unwrap()
.plugins,
RemoteInstalledPluginsSnapshot::default(),
&store,
/*plugin_skill_snapshots*/ None,
@@ -370,29 +376,30 @@ fn configured_plugins_from_stack_merges_enabled_effective_layers() {
(
"base".to_string(),
PluginConfig {
enabled: true,
enabled: Some(true),
mcp_servers: HashMap::new(),
},
),
(
"profile".to_string(),
PluginConfig {
enabled: true,
enabled: Some(true),
mcp_servers: project_mcp_servers.clone(),
},
),
(
"system".to_string(),
PluginConfig {
enabled: true,
enabled: Some(true),
mcp_servers: HashMap::new(),
},
),
])
);
let config: ConfigToml = stack.effective_config().try_into().expect("plugin config");
assert_eq!(
configured_plugin_mcp_server_policies(&stack).get("profile"),
Some(&project_mcp_servers)
config.plugins.plugins["profile"].mcp_servers,
project_mcp_servers
);
}
@@ -420,8 +427,8 @@ async fn legacy_ema_policy_disables_installed_and_selected_plugin_servers() {
ConfigRequirementsToml::default(),
)
.expect("legacy policy stack");
let policies = configured_plugin_mcp_server_policies(&stack);
let policy = policies.get("plugin@market").expect("plugin policy");
let config: ConfigToml = stack.effective_config().try_into().expect("plugin config");
let policy = &config.plugins.plugins["plugin@market"].mcp_servers;
let installed = load_plugin_mcp_servers_with_policy(
&plugin_root,
/*auth_mode*/ None,
@@ -536,6 +543,11 @@ enabled = true
let full = load_plugins_from_layer_stack(
&stack,
&stack
.effective_config()
.try_into::<codex_config::config_toml::ConfigToml>()
.unwrap()
.plugins,
RemoteInstalledPluginsSnapshot::default(),
&store,
/*plugin_skill_snapshots*/ None,
@@ -546,6 +558,11 @@ enabled = true
.await;
let hooks_only = load_plugins_from_layer_stack_with_scope(
&stack,
&stack
.effective_config()
.try_into::<codex_config::config_toml::ConfigToml>()
.unwrap()
.plugins,
HashMap::new(),
&store,
/*remote_global_catalog_active*/ false,
@@ -587,6 +604,78 @@ enabled = true
assert!(hooks_only_valid.skill_roots.is_empty());
assert!(hooks_only_valid.mcp_servers.is_empty());
assert!(hooks_only_valid.apps.is_empty());
for (policy, active, extra_plugins) in [
(
"[plugins._default]\nenabled = false\n[plugins.\"valid@test\"]\nenabled = true",
true,
// Typed policy must also veto enabled entries from the original source map.
configured_plugins_from_stack(&stack, temp_dir.path()),
),
(
"[plugins.\"valid@test\".mcp_servers.example]\nenabled = true",
true,
HashMap::new(),
),
(
"[plugins._default]\nenabled = false\n[plugins.\"valid@test\".mcp_servers.example]\ndefault_tools_approval_mode = 'approve'",
false,
HashMap::new(),
),
] {
let stack = ConfigLayerStack::default()
.with_user_config(
&user_config_path(&temp_dir, "inherited.toml"),
toml::from_str(policy).expect("plugin policy"),
)
.expect("valid inherited config");
let policy = stack
.effective_config()
.try_into::<ConfigToml>()
.expect("plugin config")
.plugins;
let plugins = load_plugins_from_layer_stack(
&stack,
&policy,
RemoteInstalledPluginsSnapshot::default(),
&store,
/*plugin_skill_snapshots*/ None,
Some(Product::Codex),
/*remote_global_catalog_active*/ false,
test_skill_root_loader().as_ref(),
)
.await;
let plugin = &plugins[0];
assert_eq!(
(
plugin.is_active(),
!plugin.skill_roots.is_empty(),
!plugin.mcp_servers.is_empty(),
!plugin.apps.is_empty()
),
(active, active, active, active),
);
let hooks = load_plugin_hooks_from_layer_stack(
&stack,
&policy,
extra_plugins,
&store,
TargetCuratedMarketplace::OpenAi,
/*remote_global_catalog_active*/ false,
)
.await;
assert_eq!(
hooks,
PluginHookLoadOutcome {
hook_sources: if active {
hooks_only_valid.hook_sources.clone()
} else {
Vec::new()
},
hook_load_warnings: Vec::new(),
},
);
}
}
#[test]
+14 -1
View File
@@ -95,6 +95,7 @@ use codex_config::clear_user_plugin;
use codex_config::set_user_plugin_enabled;
use codex_config::skill_config_rules_from_stack;
use codex_config::types::PluginConfig;
use codex_config::types::PluginsConfigToml;
use codex_config::types::ToolSuggestDisabledTool;
use codex_config::types::ToolSuggestDiscoverableType;
use codex_connectors::ConnectorSnapshot;
@@ -157,6 +158,7 @@ type EffectivePluginsChangedCallback = Arc<dyn Fn(EffectivePluginsChange) + Send
#[derive(Debug, Clone)]
pub struct PluginsConfigInput {
pub config_layer_stack: ConfigLayerStack,
pub plugins: PluginsConfigToml,
pub model_provider_id: String,
pub plugins_enabled: bool,
pub remote_plugin_enabled: bool,
@@ -167,8 +169,11 @@ pub struct PluginsConfigInput {
}
impl PluginsConfigInput {
// Require validated policy at construction; a default followed by a setter could fail open.
#[allow(clippy::too_many_arguments)]
pub fn new(
config_layer_stack: ConfigLayerStack,
plugins: PluginsConfigToml,
model_provider_id: String,
plugins_enabled: bool,
remote_plugin_enabled: bool,
@@ -178,6 +183,7 @@ impl PluginsConfigInput {
) -> Self {
Self {
config_layer_stack,
plugins,
model_provider_id,
plugins_enabled,
remote_plugin_enabled,
@@ -633,6 +639,7 @@ impl LoadedPluginsCache {
#[derive(Clone, PartialEq, Eq)]
struct PluginLoadCacheKey {
configured_plugins: HashMap<String, PluginConfig>,
plugin_policy: PluginsConfigToml,
skill_config_rules: SkillConfigRules,
remote_global_catalog_active: bool,
auth_identity: Option<RemoteInstalledPluginsAuthIdentity>,
@@ -650,6 +657,7 @@ impl PluginLoadCacheKey {
&config.config_layer_stack,
codex_home,
),
plugin_policy: config.plugins.clone(),
skill_config_rules: skill_config_rules_from_stack(&config.config_layer_stack),
remote_global_catalog_active,
// Local curated loads are auth-independent; only remote snapshots vary by account.
@@ -882,6 +890,7 @@ impl PluginsManager {
let load_started = Instant::now();
let plugins = load_plugins_from_layer_stack(
&config.config_layer_stack,
&config.plugins,
self.remote_installed_plugins_snapshot(),
&self.store,
Some(&plugin_skill_snapshots),
@@ -1003,6 +1012,7 @@ impl PluginsManager {
let target_curated_marketplace = target_curated_marketplace(self.auth_mode());
load_plugin_hooks_from_layer_stack(
config_layer_stack,
&config.plugins,
self.remote_installed_plugin_configs(),
&self.store,
target_curated_marketplace,
@@ -3577,7 +3587,10 @@ impl PluginsManager {
.collect::<HashSet<_>>();
let enabled = configured_plugins
.into_iter()
.filter_map(|(plugin_key, plugin)| plugin.enabled.then_some(plugin_key))
.filter_map(|(plugin_key, plugin)| {
(plugin.enabled.unwrap_or(true) && config.plugins.allows_plugin(&plugin_key))
.then_some(plugin_key)
})
.collect::<HashSet<_>>();
ConfiguredPluginStates { installed, enabled }
}
+125 -1
View File
@@ -122,6 +122,9 @@ fn plugins_config_input_with_requirements(
) -> PluginsConfigInput {
PluginsConfigInput::new(
config_layer_stack_with_requirements(codex_home, user_config, requirements),
toml::from_str::<codex_config::config_toml::ConfigToml>(user_config)
.unwrap()
.plugins,
String::new(),
/*plugins_enabled*/ true,
/*remote_plugin_enabled*/ false,
@@ -163,6 +166,7 @@ fn curated_repo_sync_stays_deferred_for_remote_chatgpt_catalog() {
let tmp = TempDir::new().unwrap();
let config = PluginsConfigInput::new(
unrestricted_config_layer_stack(),
Default::default(),
"openai".to_string(),
/*plugins_enabled*/ true,
/*remote_plugin_enabled*/ true,
@@ -2987,6 +2991,11 @@ async fn plugin_cache_reuses_effective_configurations() {
let config = |session_config| {
PluginsConfigInput::new(
stack(session_config),
stack(session_config)
.effective_config()
.try_into::<codex_config::config_toml::ConfigToml>()
.unwrap()
.plugins,
String::new(),
/*plugins_enabled*/ true,
/*remote_plugin_enabled*/ false,
@@ -3037,6 +3046,113 @@ enabled = false"#,
);
}
#[tokio::test]
async fn plugin_defaults_resolve_remote_enablement_and_separate_cache_entries() {
let codex_home = TempDir::new().unwrap();
let cache_root = codex_home
.path()
.join("plugins/cache/openai-curated-remote");
for name in ["sample", "other"] {
write_plugin(&cache_root, &format!("{name}/local"), name);
write_file(
&cache_root.join(format!("{name}/local/.app.json")),
&format!(r#"{{"apps":{{"{name}":{{"id":"connector_{name}"}}}}}}"#),
);
}
let config_path = codex_home.path().join(CONFIG_TOML_FILE);
let manager = test_plugins_manager_with_options(
codex_home.path().to_path_buf(),
Some(Product::Codex),
Some(AuthMode::Chatgpt),
);
manager.write_remote_installed_plugins_cache(vec![
remote_installed_plugin("sample"),
remote_installed_plugin("other"),
]);
let assert_active_plugins = |loaded: &PluginLoadOutcome, expected_names: Vec<&str>| {
assert_eq!(
loaded
.capability_summaries()
.iter()
.map(|summary| summary.config_name.as_str())
.collect::<Vec<_>>(),
expected_names
);
assert_eq!(
loaded.effective_plugin_skill_roots().len(),
expected_names.len()
);
assert_eq!(loaded.effective_apps().len(), expected_names.len());
assert!(loaded.plugins().iter().all(|plugin| plugin.error.is_none()));
};
let sample = "sample@openai-curated-remote";
let other = "other@openai-curated-remote";
for (policy, expected_names) in [
("", vec![other, sample]),
("[plugins._default]\nenabled = false", Vec::new()),
(
"[plugins._default]\nenabled = false\n[plugins.\"sample@openai-curated-remote\"]\nenabled = true",
vec![sample],
),
(
"[plugins._default]\nenabled = true\n[plugins.\"sample@openai-curated-remote\"]\nenabled = false",
vec![other],
),
(
"[plugins._default]\nenabled = false\n[plugins.\"sample@openai-curated-remote\".mcp_servers.example]\ndefault_tools_approval_mode = 'approve'",
Vec::new(),
),
// Without the new default, legacy remote account enablement still wins.
(
"[plugins.\"sample@openai-curated-remote\"]\nenabled = false",
vec![other, sample],
),
] {
write_file(&config_path, policy);
let config = load_config(codex_home.path(), codex_home.path()).await;
let loaded = manager.plugins_for_config(&config).await;
assert_active_plugins(&loaded, expected_names);
}
// Marketplace filtering removes these raw entries from the configured map,
// but remote discovery still supplies the installed bundle. Its raw policy
// must distinguish cache entries as host enablement changes.
for enabled in [true, false] {
let mut restricted_config = plugins_config_input_with_requirements(
codex_home.path(),
&format!(
"[plugins._default]\nenabled = false\n[plugins.\"sample@openai-curated-remote\"]\nenabled = {enabled}"
),
"[marketplaces]\nrestrict_to_allowed_sources = true",
);
restricted_config.remote_plugin_enabled = true;
assert!(
configured_plugins_from_stack(
&restricted_config.config_layer_stack,
codex_home.path(),
)
.is_empty()
);
let loaded = manager.plugins_for_config(&restricted_config).await;
let expected = if enabled { vec![sample] } else { Vec::new() };
assert_active_plugins(&loaded, expected);
}
let mut disabled_plugin = remote_installed_plugin("sample");
disabled_plugin.enabled = false;
disabled_plugin.availability = codex_app_server_protocol::PluginAvailability::DisabledByAdmin;
manager.write_remote_installed_plugins_cache(vec![disabled_plugin]);
write_file(
&config_path,
"[plugins._default]\nenabled = false\n[plugins.\"sample@openai-curated-remote\"]\nenabled = true",
);
let config = load_config(codex_home.path(), codex_home.path()).await;
let loaded = manager.plugins_for_config(&config).await;
assert_active_plugins(&loaded, Vec::new());
}
#[tokio::test]
async fn skill_roots_resolve_remote_plugin_identity_from_authoritative_source() {
let mut duplicate_plugin = remote_installed_plugin("sample");
@@ -3177,10 +3293,11 @@ fn loaded_plugins_cache_evicts_least_recently_used_configuration() {
configured_plugins: HashMap::from([(
format!("plugin-{index}@test"),
PluginConfig {
enabled: true,
enabled: Some(true),
mcp_servers: HashMap::new(),
},
)]),
plugin_policy: PluginsConfigToml::default(),
skill_config_rules: SkillConfigRules::default(),
remote_global_catalog_active: false,
auth_identity: None,
@@ -3225,6 +3342,7 @@ fn loaded_plugins_cache_invalidation_rejects_stale_load_completion() {
let manager = test_plugins_manager(codex_home.path().to_path_buf());
let cache_key = PluginLoadCacheKey {
configured_plugins: HashMap::new(),
plugin_policy: PluginsConfigToml::default(),
skill_config_rules: SkillConfigRules::default(),
remote_global_catalog_active: false,
auth_identity: None,
@@ -3252,6 +3370,7 @@ async fn plugins_for_config_discards_in_flight_load_after_account_change() {
);
let config = PluginsConfigInput::new(
unrestricted_config_layer_stack(),
Default::default(),
String::new(),
/*plugins_enabled*/ true,
/*remote_plugin_enabled*/ true,
@@ -7010,6 +7129,11 @@ async fn load_plugins_uses_project_config_files() {
let plugins = load_plugins_from_layer_stack(
&stack,
&stack
.effective_config()
.try_into::<codex_config::config_toml::ConfigToml>()
.unwrap()
.plugins,
crate::remote_plugin_id_resolver::RemoteInstalledPluginsSnapshot::default(),
&PluginStore::new(codex_home.path().to_path_buf()),
/*plugin_skill_snapshots*/ None,
@@ -21,10 +21,12 @@ use codex_config::RequirementSource;
use codex_config::types::MarketplaceConfig;
use codex_config::types::MarketplaceSourceType;
use codex_config::types::PluginConfig;
use codex_config::types::PluginsConfigToml;
use codex_plugin::PluginId;
use codex_utils_absolute_path::AbsolutePathBuf;
use codex_utils_path::paths_match_after_normalization;
use regex::Regex;
use serde::Deserialize;
use std::collections::HashMap;
use std::collections::HashSet;
use std::path::Path;
@@ -236,6 +238,9 @@ pub(crate) fn policy_filtered_plugin_config(
.and_then(toml::Value::as_table_mut)
{
plugins.retain(|plugin_key, _| {
if plugin_key == "_default" {
return true;
}
let Ok(plugin_id) = PluginId::parse(plugin_key) else {
return !policy.is_restricted();
};
@@ -301,8 +306,8 @@ pub(crate) fn configured_plugins_from_stack(
let Some(plugins_value) = effective_config.get("plugins") else {
return HashMap::new();
};
match plugins_value.clone().try_into() {
Ok(plugins) => plugins,
match PluginsConfigToml::deserialize(plugins_value.clone()) {
Ok(plugins) => plugins.plugins,
Err(err) => {
tracing::warn!("invalid plugins config: {err}");
HashMap::new()
@@ -82,7 +82,12 @@ async fn curated_git_requirements_control_plugin_skills() -> Result<()> {
)
.await?;
let config = PluginsConfigInput::new(
config_layer_stack,
config_layer_stack.clone(),
config_layer_stack
.effective_config()
.try_into::<codex_config::config_toml::ConfigToml>()
.unwrap()
.plugins,
"openai".to_string(),
/*plugins_enabled*/ true,
/*remote_plugin_enabled*/ false,
@@ -18,6 +18,7 @@ use wiremock::matchers::path;
fn repeated_service_configs_and_early_clones_share_one_lazy_pool() {
let input = PluginsConfigInput::new(
ConfigLayerStack::default(),
Default::default(),
"openai".to_string(),
/*plugins_enabled*/ true,
/*remote_plugin_enabled*/ true,
@@ -38,6 +39,7 @@ fn repeated_service_configs_and_early_clones_share_one_lazy_pool() {
.collect();
let new_input = PluginsConfigInput::new(
input.config_layer_stack.clone(),
input.plugins.clone(),
input.model_provider_id.clone(),
input.plugins_enabled,
input.remote_plugin_enabled,
@@ -85,6 +87,7 @@ async fn reused_pool_uses_current_endpoint_product_and_authentication() {
}
let mut input = PluginsConfigInput::new(
ConfigLayerStack::default(),
Default::default(),
"openai".to_string(),
/*plugins_enabled*/ true,
/*remote_plugin_enabled*/ true,
@@ -501,6 +501,11 @@ pub(crate) async fn load_plugins_config(codex_home: &Path, cwd: &Path) -> Plugin
.to_string();
PluginsConfigInput::new(
config_layer_stack,
effective_config
.clone()
.try_into::<codex_config::config_toml::ConfigToml>()
.unwrap()
.plugins,
model_provider_id,
feature_enabled(&effective_config, "plugins", /*default_enabled*/ true),
feature_enabled(