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
@@ -2111,8 +2111,17 @@ connectors = true
Ok(())
}
#[test_case("", None, true; "legacy activation")]
#[test_case("[plugins._default]\nenabled = false", None, false; "default disabled")]
#[test_case("[plugins._default]\nenabled = false\n[plugins.\"linear@openai-curated-remote\"]\nenabled = true", None, true; "explicitly enabled overrides default")]
#[test_case("", Some("[plugins._default]\nenabled = false"), false; "default disabled during install")]
#[test_case("", Some("[plugins._default]\nenabled = \"invalid\""), false; "invalid policy during install skips auth")]
#[tokio::test]
async fn plugin_install_starts_remote_mcp_oauth_for_install_response_only_app() -> Result<()> {
async fn plugin_install_remote_auth_setup_respects_activation_policy(
plugin_config: &str,
plugin_config_after_install: Option<&str>,
expected_auth: bool,
) -> Result<()> {
let codex_home = TempDir::new()?;
let server = MockServer::start().await;
let oauth_server = MockServer::start().await;
@@ -2123,9 +2132,36 @@ async fn plugin_install_starts_remote_mcp_oauth_for_install_response_only_app()
)
.await;
configure_remote_plugin_with_apps_test(codex_home.path(), &server)?;
let config_path = codex_home.path().join("config.toml");
let original_config = std::fs::read_to_string(&config_path)?;
let config_contents = format!("{original_config}\n{plugin_config}\n");
std::fs::write(&config_path, &config_contents)?;
mount_remote_plugin_detail(&server, REMOTE_PLUGIN_ID, "1.2.3", Some(&bundle_url)).await;
mount_empty_remote_installed_plugins(&server).await;
mount_remote_plugin_install_with_apps_needing_auth(&server, REMOTE_PLUGIN_ID, &["alpha"]).await;
let updated_config = plugin_config_after_install
.map(|plugin_config| format!("{original_config}\n{plugin_config}\n"));
let expected_config = updated_config.as_ref().unwrap_or(&config_contents).clone();
let install_config_path = config_path.clone();
Mock::given(method("POST"))
.and(path(format!(
"/backend-api/ps/plugins/{REMOTE_PLUGIN_ID}/install"
)))
.and(query_param("includeAppsNeedingAuth", "true"))
.and(header("authorization", "Bearer chatgpt-token"))
.and(header("chatgpt-account-id", "account-123"))
.respond_with(move |_request: &Request| {
if let Some(updated_config) = &updated_config {
std::fs::write(&install_config_path, updated_config)
.expect("install responder should update config");
}
ResponseTemplate::new(/*s*/ 200).set_body_json(json!({
"id": REMOTE_PLUGIN_ID,
"enabled": true,
"app_ids_needing_auth": ["alpha"],
}))
})
.mount(&server)
.await;
let mut mcp = TestAppServer::builder()
.with_codex_home(codex_home.path())
@@ -2141,16 +2177,44 @@ async fn plugin_install_starts_remote_mcp_oauth_for_install_response_only_app()
response,
PluginInstallResponse {
auth_policy: PluginAuthPolicy::OnUse,
apps_needing_auth: vec![AppSummary {
id: "alpha".to_string(),
name: "alpha".to_string(),
description: None,
install_url: Some("https://chatgpt.com/apps/alpha/alpha".to_string()),
category: None,
}],
apps_needing_auth: if expected_auth {
vec![AppSummary {
id: "alpha".to_string(),
name: "alpha".to_string(),
description: None,
install_url: Some("https://chatgpt.com/apps/alpha/alpha".to_string()),
category: None,
}]
} else {
Vec::new()
},
}
);
assert!(oauth_discovery_request_count(&oauth_server).await > 0);
if expected_auth {
assert!(oauth_discovery_request_count(&oauth_server).await > 0);
} else {
assert!(
oauth_server
.received_requests()
.await
.unwrap_or_default()
.is_empty()
);
}
wait_for_remote_plugin_request_count(
&server,
"POST",
&format!("/ps/plugins/{REMOTE_PLUGIN_ID}/install"),
/*expected_count*/ 1,
)
.await?;
assert!(
codex_home
.path()
.join("plugins/cache/openai-curated-remote/linear/1.2.3/.codex-plugin/plugin.json")
.is_file()
);
assert_eq!(std::fs::read_to_string(config_path)?, expected_config);
Ok(())
}
@@ -279,9 +279,13 @@ enabled = true
Ok(())
}
#[test_case("", true; "without default")]
#[test_case("[plugins._default]\nenabled = false", false; "default disabled")]
#[tokio::test]
async fn plugin_installed_prefers_remote_curated_conflicts_when_remote_plugin_enabled() -> Result<()>
{
async fn plugin_installed_prefers_remote_curated_conflicts_when_remote_plugin_enabled(
plugin_config: &str,
expected_remote_enabled: bool,
) -> Result<()> {
let codex_home = TempDir::new()?;
let server = MockServer::start().await;
write_openai_curated_marketplace(codex_home.path(), &["linear", "calendar"])?;
@@ -301,6 +305,8 @@ enabled = true
[plugins."calendar@openai-curated"]
enabled = true
{plugin_config}
"#,
server.uri()
),
@@ -356,9 +362,9 @@ enabled = true
local_marketplace
.plugins
.iter()
.map(|plugin| plugin.id.clone())
.map(|plugin| (plugin.id.clone(), plugin.enabled))
.collect::<Vec<_>>(),
vec!["calendar@openai-curated".to_string()]
vec![("calendar@openai-curated".to_string(), true)]
);
let remote_marketplace = response
.marketplaces
@@ -372,6 +378,7 @@ enabled = true
.map(|plugin| {
(
plugin.id.clone(),
plugin.enabled,
plugin.install_policy_source,
plugin.must_show_installation_interstitial,
)
@@ -380,11 +387,13 @@ enabled = true
vec![
(
"linear@openai-curated-remote".to_string(),
expected_remote_enabled,
Some(PluginInstallPolicySource::WorkspaceSetting),
Some(false),
),
(
"remote-only@openai-curated-remote".to_string(),
expected_remote_enabled,
Some(PluginInstallPolicySource::WorkspaceSetting),
Some(false),
),
@@ -1332,8 +1341,15 @@ async fn plugin_catalogs_skip_invalid_project_config_and_report_cwd_error() -> R
Ok(())
}
#[test_case("", "enabled = true", true; "legacy explicit enabled")]
#[test_case("[plugins._default]\nenabled = false", "mcp_servers.example.tools.search.approval_mode = 'approve'", false; "default disabled approval-only entry")]
#[test_case("[plugins._default]\nenabled = false", "enabled = true", true; "explicitly enabled overrides default")]
#[tokio::test]
async fn plugin_list_includes_install_and_enabled_state_from_config() -> Result<()> {
async fn plugin_list_includes_install_and_enabled_state_from_config(
plugin_default: &str,
plugin_settings: &str,
expected_enabled: bool,
) -> Result<()> {
let codex_home = TempDir::new()?;
let repo_root = TempDir::new()?;
std::fs::create_dir_all(repo_root.path().join(".git"))?;
@@ -1374,15 +1390,19 @@ async fn plugin_list_includes_install_and_enabled_state_from_config() -> Result<
)?;
std::fs::write(
codex_home.path().join("config.toml"),
r#"[features]
format!(
r#"[features]
plugins = true
{plugin_default}
[plugins."enabled-plugin@codex-curated"]
enabled = true
{plugin_settings}
[plugins."disabled-plugin@codex-curated"]
enabled = false
"#,
),
)?;
let mut mcp = TestAppServer::builder()
@@ -1427,7 +1447,7 @@ enabled = false
assert_eq!(marketplace.plugins[0].id, "enabled-plugin@codex-curated");
assert_eq!(marketplace.plugins[0].name, "enabled-plugin");
assert_eq!(marketplace.plugins[0].installed, true);
assert_eq!(marketplace.plugins[0].enabled, true);
assert_eq!(marketplace.plugins[0].enabled, expected_enabled);
assert_eq!(
marketplace.plugins[0].install_policy,
PluginInstallPolicy::Available
@@ -1463,6 +1483,35 @@ enabled = false
marketplace.plugins[2].auth_policy,
PluginAuthPolicy::OnInstall
);
let request_id = mcp
.send_plugin_installed_request(PluginInstalledParams {
cwds: Some(vec![AbsolutePathBuf::try_from(repo_root.path())?]),
install_suggestion_plugin_names: None,
})
.await?;
let response: PluginInstalledResponse =
timeout(DEFAULT_TIMEOUT, mcp.read_response(request_id)).await??;
let installed = response
.marketplaces
.into_iter()
.find(|entry| entry.path == marketplace.path)
.expect("expected installed repo marketplace entry");
assert_eq!(
installed
.plugins
.into_iter()
.map(|plugin| (plugin.id, plugin.installed, plugin.enabled))
.collect::<Vec<_>>(),
vec![
(
"enabled-plugin@codex-curated".to_string(),
true,
expected_enabled,
),
("disabled-plugin@codex-curated".to_string(), true, false),
]
);
Ok(())
}
@@ -2088,14 +2137,20 @@ enum ProjectPluginConfiguration {
Invalid,
}
#[test_case(ProjectPluginConfiguration::None, None; "without project override")]
#[test_case(ProjectPluginConfiguration::Disabled, None; "project disables local plugins")]
#[test_case(ProjectPluginConfiguration::Invalid, None; "invalid project preserves remote plugins")]
#[test_case(ProjectPluginConfiguration::None, Some("tpp"); "configured product sku")]
#[test_case(ProjectPluginConfiguration::None, None, "", true, true; "without project override")]
#[test_case(ProjectPluginConfiguration::Disabled, None, "", true, true; "project disables local plugins")]
#[test_case(ProjectPluginConfiguration::Invalid, None, "", true, true; "invalid project preserves remote plugins")]
#[test_case(ProjectPluginConfiguration::None, Some("tpp"), "", true, true; "configured product sku")]
#[test_case(ProjectPluginConfiguration::None, None, "[plugins._default]\nenabled = false", true, false; "default disabled")]
#[test_case(ProjectPluginConfiguration::None, None, "[plugins._default]\nenabled = false\n[plugins.\"linear@openai-curated-remote\"]\nenabled = true", true, true; "explicitly enabled")]
#[test_case(ProjectPluginConfiguration::None, None, "[plugins._default]\nenabled = false\n[plugins.\"linear@openai-curated-remote\"]\nenabled = true", false, false; "source disabled")]
#[tokio::test]
async fn plugin_list_includes_remote_marketplaces_when_remote_plugin_enabled(
project_configuration: ProjectPluginConfiguration,
product_sku: Option<&str>,
plugin_config: &str,
source_enabled: bool,
expected_enabled: bool,
) -> Result<()> {
let codex_home = TempDir::new()?;
let server = MockServer::start().await;
@@ -2103,6 +2158,9 @@ async fn plugin_list_includes_remote_marketplaces_when_remote_plugin_enabled(
codex_home.path(),
&format!("{}/backend-api/", server.uri()),
)?;
let config_path = codex_home.path().join("config.toml");
let config = std::fs::read_to_string(&config_path)?;
std::fs::write(config_path, format!("{config}\n{plugin_config}\n"))?;
write_chatgpt_auth(
codex_home.path(),
ChatGptAuthFixture::new("chatgpt-token")
@@ -2210,6 +2268,8 @@ async fn plugin_list_includes_remote_marketplaces_when_remote_plugin_enabled(
}
}"#;
let mut global_installed_body: serde_json::Value = serde_json::from_str(global_installed_body)?;
global_installed_body["plugins"][0]["enabled"] = serde_json::json!(source_enabled);
let expected_product_sku = product_sku.unwrap_or("codex");
Mock::given(method("GET"))
.and(path("/backend-api/ps/plugins/list"))
@@ -2237,7 +2297,7 @@ async fn plugin_list_includes_remote_marketplaces_when_remote_plugin_enabled(
.and(header("authorization", "Bearer chatgpt-token"))
.and(header("chatgpt-account-id", "account-123"))
.and(header("oai-product-sku", expected_product_sku))
.respond_with(ResponseTemplate::new(200).set_body_string(global_installed_body))
.respond_with(ResponseTemplate::new(200).set_body_json(global_installed_body))
.mount(&server)
.await;
Mock::given(method("GET"))
@@ -2329,7 +2389,7 @@ async fn plugin_list_includes_remote_marketplaces_when_remote_plugin_enabled(
remote_marketplace.plugins[0].installed_at,
Some(1_767_312_000)
);
assert_eq!(remote_marketplace.plugins[0].enabled, true);
assert_eq!(remote_marketplace.plugins[0].enabled, expected_enabled);
assert_eq!(
remote_marketplace.plugins[0].install_policy_source,
Some(PluginInstallPolicySource::ImplicitCanonicalApp)
@@ -61,16 +61,21 @@ use wiremock::matchers::query_param;
const DEFAULT_TIMEOUT: Duration = Duration::from_secs(10);
#[test_case(Some("skills/setup/SKILL.md"), true, true, true; "enabled matching skill")]
#[test_case(Some("skills/setup/SKILL.md"), false, true, false; "disabled plugin")]
#[test_case(Some("skills/setup/SKILL.md"), true, false, false; "disabled skill")]
#[test_case(None, true, true, false; "missing declaration")]
#[test_case(Some("skills/missing/SKILL.md"), true, true, false; "unmatched declaration")]
#[test_case(Some("skills/setup/SKILL.md"), "enabled = true", true, "", true, true; "enabled matching skill")]
#[test_case(Some("skills/setup/SKILL.md"), "enabled = false", true, "", false, false; "disabled plugin")]
#[test_case(Some("skills/setup/SKILL.md"), "enabled = true", false, "", true, false; "disabled skill")]
#[test_case(None, "enabled = true", true, "", true, false; "missing declaration")]
#[test_case(Some("skills/missing/SKILL.md"), "enabled = true", true, "", true, false; "unmatched declaration")]
#[test_case(Some("skills/setup/SKILL.md"), "", true, "", true, true; "legacy empty entry")]
#[test_case(Some("skills/setup/SKILL.md"), "", true, "[plugins._default]\nenabled = false", false, false; "default disabled empty entry")]
#[test_case(Some("skills/setup/SKILL.md"), "enabled = true", true, "[plugins._default]\nenabled = false", true, true; "explicitly enabled overrides default")]
#[tokio::test]
async fn plugin_read_selects_local_onboarding_skill(
onboarding_path: Option<&str>,
plugin_enabled: bool,
plugin_settings: &str,
skill_enabled: bool,
plugin_default: &str,
expected_plugin_enabled: bool,
expect_onboarding: bool,
) -> Result<()> {
let codex_home = TempDir::new()?;
@@ -106,8 +111,10 @@ async fn plugin_read_selects_local_onboarding_skill(
r#"[features]
plugins = true
{plugin_default}
[plugins."demo-plugin@codex-curated"]
enabled = {plugin_enabled}
{plugin_settings}
[[skills.config]]
name = "demo-plugin:setup"
@@ -146,7 +153,7 @@ enabled = {skill_enabled}
),
enabled: skill_enabled,
};
assert_eq!(response.plugin.summary.enabled, plugin_enabled);
assert_eq!(response.plugin.summary.enabled, expected_plugin_enabled);
assert!(response.plugin.skills.contains(&setup_skill));
assert_eq!(
response.plugin.onboarding_skill,
@@ -155,18 +162,20 @@ enabled = {skill_enabled}
Ok(())
}
#[test_case(Some("setup"), true, true, "AVAILABLE", true; "enabled matching skill")]
#[test_case(Some("setup"), false, true, "AVAILABLE", false; "disabled plugin")]
#[test_case(Some("setup"), true, false, "AVAILABLE", false; "disabled skill")]
#[test_case(None, true, true, "AVAILABLE", false; "missing declaration")]
#[test_case(Some("missing"), true, true, "AVAILABLE", false; "unmatched declaration")]
#[test_case(Some("setup"), true, true, "DISABLED_BY_ADMIN", false; "unavailable plugin")]
#[test_case(Some("setup"), true, true, "AVAILABLE", None, true; "enabled matching skill")]
#[test_case(Some("setup"), false, true, "AVAILABLE", None, false; "disabled plugin")]
#[test_case(Some("setup"), true, false, "AVAILABLE", None, false; "disabled skill")]
#[test_case(None, true, true, "AVAILABLE", None, false; "missing declaration")]
#[test_case(Some("missing"), true, true, "AVAILABLE", None, false; "unmatched declaration")]
#[test_case(Some("setup"), true, true, "DISABLED_BY_ADMIN", None, false; "unavailable plugin")]
#[test_case(Some("setup"), true, true, "AVAILABLE", Some(false), false; "default disabled")]
#[tokio::test]
async fn plugin_read_selects_remote_onboarding_skill(
onboarding_name: Option<&str>,
plugin_enabled: bool,
skill_enabled: bool,
status: &str,
default_enabled: Option<bool>,
expect_onboarding: bool,
) -> Result<()> {
let codex_home = TempDir::new()?;
@@ -223,8 +232,11 @@ async fn plugin_read_selects_remote_onboarding_skill(
})))
.mount(&server)
.await;
let mut mcp = TestAppServer::builder()
.with_codex_home(codex_home.path())
let mut builder = TestAppServer::builder().with_codex_home(codex_home.path());
if let Some(enabled) = default_enabled {
builder = builder.with_args(&["-c", &format!("plugins._default.enabled={enabled}")]);
}
let mut mcp = builder
.without_auto_env()
.build_initialized_with_timeout(DEFAULT_TIMEOUT)
.await?;
@@ -246,7 +258,10 @@ async fn plugin_read_selects_remote_onboarding_skill(
path: None,
enabled: skill_enabled,
};
assert_eq!(response.plugin.summary.enabled, plugin_enabled);
assert_eq!(
response.plugin.summary.enabled,
plugin_enabled && default_enabled.unwrap_or(true)
);
assert!(response.plugin.skills.contains(&setup_skill));
assert_eq!(
response.plugin.onboarding_skill,