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
+81 -23
View File
@@ -1788,14 +1788,21 @@ async fn reload_user_config_layer_updates_effective_apps_config() {
assert_eq!(app.destructive_enabled, Some(false));
}
#[test_case("[shell_environment_policy]\nexclude = [\"SECRET_*\", 17]"; "shell policy")]
#[test_case("[plugins._default]\nenabled = false\n[plugins.\"sample@openai-curated-remote\"]\nenabled = \"false\""; "plugin policy")]
#[tokio::test]
async fn reload_user_config_layer_keeps_previous_config_for_malformed_shell_policy() {
async fn reload_user_config_layer_keeps_previous_config_for_malformed_policy(
malformed_policy: &str,
) {
let (session, _turn_context) = make_session_and_context().await;
let codex_home = session.codex_home().await;
std::fs::create_dir_all(&codex_home).expect("create codex home");
let config_toml_path = codex_home.join(CONFIG_TOML_FILE);
std::fs::write(&config_toml_path, "[apps.calendar]\nenabled = false\n")
.expect("write valid user config");
std::fs::write(
&config_toml_path,
"[apps.calendar]\nenabled = false\n[plugins._default]\nenabled = false\n",
)
.expect("write valid user config");
session.reload_user_config_layer().await;
let previous_config = session
.get_config()
@@ -1806,25 +1813,19 @@ async fn reload_user_config_layer_keeps_previous_config_for_malformed_shell_poli
std::fs::write(
&config_toml_path,
r#"
[apps.calendar]
enabled = true
[shell_environment_policy]
exclude = ["SECRET_*", 17]
"#,
format!("[apps.calendar]\nenabled = true\n{malformed_policy}\n"),
)
.expect("write malformed user config");
session.reload_user_config_layer().await;
let current_config = session
.get_config()
.await
let config = session.get_config().await;
let current_config = config
.config_layer_stack
.effective_user_config()
.expect("current user config");
assert_eq!(current_config, previous_config);
assert!(!config.plugins.allows_plugin("sample@openai-curated-remote"));
}
#[tokio::test]
@@ -10085,8 +10086,7 @@ async fn step_context_keeps_its_mcp_runtime_for_tools() -> anyhow::Result<()> {
.capture_step_context(turn_context, &CancellationToken::new())
.await?;
let mut refresh_config = step_context.turn.config.as_ref().clone();
refresh_config.mcp_servers.set(HashMap::from([(
let mut added_servers = HashMap::from([(
"newer".to_string(),
McpServerConfig {
auth: Default::default(),
@@ -10115,20 +10115,47 @@ async fn step_context_keeps_its_mcp_runtime_for_tools() -> anyhow::Result<()> {
oauth_resource: None,
tools: HashMap::new(),
},
)]))?;
)]);
let ordinary: McpServerConfig = serde_json::from_value(json!({
"url": "https://ordinary.example/mcp",
"enabled": false,
}))?;
let mut current_config = session.get_config().await.as_ref().clone();
current_config.plugins = toml::from_str("[_default]\nenabled = false\n")?;
current_config
.mcp_servers
.set(HashMap::from([("ordinary".to_string(), ordinary.clone())]))?;
session
.refresh_mcp_servers_now(
step_context.turn.as_ref(),
&refresh_config,
/*elicitation_reviewer*/ None,
)
.state
.lock()
.await
.session_configuration
.original_config_do_not_use = Arc::new(current_config.clone());
let mut stale_ordinary = ordinary;
stale_ordinary.enabled = true;
added_servers.insert("ordinary".to_string(), stale_ordinary);
let mut expected_servers = codex_mcp::configured_mcp_servers(step_context.mcp.config());
expected_servers.extend(current_config.mcp_servers.get().clone());
expected_servers.insert("newer".to_string(), added_servers["newer"].clone());
session
.refresh_mcp_servers_now(added_servers, /*elicitation_reviewer*/ None)
.await;
let next_step = session
.capture_step_context(Arc::clone(&step_context.turn), &CancellationToken::new())
.await
.expect("a fresh cancellation token cannot be cancelled");
assert!(codex_mcp::configured_mcp_servers(next_step.mcp.config()).contains_key("newer"));
assert_eq!(
codex_mcp::configured_mcp_servers(next_step.mcp.config()),
expected_servers
);
assert_eq!(next_step.mcp.config().plugins, current_config.plugins);
assert_eq!(session.get_config().await.plugins, current_config.plugins);
assert_eq!(
step_context.mcp.config().plugins,
step_context.turn.config.plugins
);
assert_ne!(step_context.mcp.config().plugins, current_config.plugins);
session.mark_mcp_runtime_dirty();
session.refresh_mcp_if_dirty().await;
@@ -10138,7 +10165,11 @@ async fn step_context_keeps_its_mcp_runtime_for_tools() -> anyhow::Result<()> {
.current_binding()
.await
.expect("refreshed runtime should be available");
assert!(codex_mcp::configured_mcp_servers(current.config()).contains_key("newer"));
assert_eq!(
codex_mcp::configured_mcp_servers(current.config()),
expected_servers
);
assert_eq!(current.config().plugins, current_config.plugins);
let router = &step_context.tool_router;
assert!(
@@ -10150,6 +10181,33 @@ async fn step_context_keeps_its_mcp_runtime_for_tools() -> anyhow::Result<()> {
Ok(())
}
#[tokio::test]
async fn mcp_dependency_refresh_preserves_current_server_constraints() -> anyhow::Result<()> {
let (session, _) = make_session_and_context().await;
let mut config = session.get_config().await.as_ref().clone();
config.mcp_servers = crate::config::Constrained::allow_only(config.mcp_servers.get().clone());
let config = Arc::new(config);
session
.state
.lock()
.await
.session_configuration
.original_config_do_not_use = Arc::clone(&config);
session
.refresh_mcp_servers_now(
HashMap::from([(
"dependency".to_string(),
serde_json::from_value(json!({"command": "missing-test-mcp-server"}))?,
)]),
/*elicitation_reviewer*/ None,
)
.await;
assert!(Arc::ptr_eq(&session.get_config().await, &config));
Ok(())
}
#[tokio::test]
async fn spawn_task_does_not_update_previous_turn_settings_for_non_run_turn_tasks() {
let (sess, tc, _rx) = make_session_and_context_with_rx().await;