aKode fase 2b-2: rimosso login ChatGPT e tutti i sottosistemi solo-ChatGPT

- Login: resta solo chiave API (+ header, Bedrock). Rimossi OAuth/browser,
  device code, refresh/revoke su auth.openai.com, PAT, agent/workload identity,
  runtime agent instance, backend-client e openapi-models, workspace routing.
- Rimossi: generazione immagini (ext + skill imagegen), history notes, plugin
  remoti (catalogo, sync, share), cyber access program, daybreak, cloud config
  e requirements (config_server ora fail-closed), attestation, frozen cloud
  skills, EMA MCP auth, Codex Apps/connettori, ricerca ospitata, header/zstd/
  routing/cookie del backend Codex, fallback OPENAI_API_KEY del realtime.
- Messaggi d'errore senza link a chatgpt.com.
- Chiavi di config legacy accettate e ignorate; feature rimosse = Stage::Removed.
- Test: cancellati solo quelli del codice rimosso; test di sicurezza
  (sandbox estensioni, permessi, redazione, auth storage, requirements)
  adattati. Restano solo fallimenti d'ambiente (code-mode-host/V8, ~/.agents).
- Istruzioni di sistema invariate.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
andrea.difonzo
2026-11-10 16:20:15 +01:00
parent 82347a58ed
commit 6089fbde91
1573 changed files with 10289 additions and 177679 deletions

View File

@@ -15,11 +15,8 @@ use codex_extension_api::ExtensionRegistry;
use codex_extension_api::ExtensionRegistryBuilder;
use codex_features::Feature;
use codex_login::CodexAuth;
use codex_mcp::CODEX_APPS_MCP_SERVER_NAME;
use codex_model_provider_info::AMAZON_BEDROCK_PROVIDER_ID;
use codex_model_provider_info::OPENAI_PROVIDER_ID;
use core_test_support::mcp_test_server::MCP_TEST_SERVER_NAME;
use codex_plugin::PluginId;
use codex_protocol::auth::AuthMode;
use codex_protocol::config_types::CollaborationMode;
use codex_protocol::config_types::ModeKind;
use codex_protocol::config_types::Settings;
@@ -30,12 +27,10 @@ use codex_protocol::protocol::EventMsg;
#[cfg(unix)]
use codex_protocol::protocol::ThreadSettingsOverrides;
use codex_protocol::user_input::UserInput;
use codex_skills_extension::HostSkillsLoadInput;
use codex_skills_extension::SkillsExtensionConfig;
use codex_skills_extension::install;
use core_test_support::apps_test_server::AppsTestServer;
use core_test_support::apps_test_server::SEARCH_CALENDAR_CREATE_TOOL;
use core_test_support::apps_test_server::recorded_apps_tool_calls;
use core_test_support::mcp_test_server::CALENDAR_CREATE_EVENT_TOOL_NAME;
use core_test_support::mcp_test_server::recorded_mcp_tool_calls;
use core_test_support::responses::ResponseMock;
use core_test_support::responses::ResponsesRequest;
use core_test_support::responses::ev_assistant_message;
@@ -55,7 +50,6 @@ use core_test_support::skip_if_remote;
use core_test_support::skip_if_target_windows;
use core_test_support::stdio_server_bin;
use core_test_support::submit_thread_settings;
use core_test_support::test_codex::TestCodex;
use core_test_support::test_codex::test_codex;
use core_test_support::test_codex::turn_permission_fields;
use core_test_support::wait_for_event;
@@ -64,15 +58,9 @@ use core_test_support::wait_for_mcp_server;
use pretty_assertions::assert_eq;
use tempfile::TempDir;
use test_case::test_case;
use wiremock::Mock;
use wiremock::MockServer;
use wiremock::ResponseTemplate;
use wiremock::matchers::header;
use wiremock::matchers::method;
use wiremock::matchers::path;
const SAMPLE_PLUGIN_CONFIG_NAME: &str = "sample@test";
const SAMPLE_REMOTE_PLUGIN_CONFIG_NAME: &str = "sample@openai-curated-remote";
const SAMPLE_PLUGIN_DISPLAY_NAME: &str = "sample";
const SAMPLE_PLUGIN_DESCRIPTION: &str = "inspect sample data";
const SAMPLE_PLUGIN_APP_NAMESPACE: &str = "mcp__codex_apps__google_calendar";
@@ -89,7 +77,6 @@ fn skills_extensions() -> Arc<ExtensionRegistry<Config>> {
omit_descriptions: false,
max_context_tokens: config.skill_max_context_tokens,
bundled_skills_enabled: config.bundled_skills_enabled(),
cloud_skill_enabled: config.cloud_skill_enabled,
shadow_selection_enabled: config.features.enabled(Feature::SkillSearch),
});
Arc::new(extensions.build())
@@ -130,7 +117,7 @@ fn write_sample_plugin_manifest_and_config_at_root(
plugin_root
}
fn write_remote_plugin_script_and_config(home: &TempDir) -> std::path::PathBuf {
fn write_legacy_remote_plugin_script_and_config(home: &TempDir) -> std::path::PathBuf {
let plugin_id = PluginId::parse(REMOTE_PLUGIN_CONFIG_NAME).expect("plugin id");
let store = PluginStore::new(home.path().to_path_buf());
let plugin_root = store.plugin_root(&plugin_id, "1.2.3");
@@ -145,9 +132,6 @@ fn write_remote_plugin_script_and_config(home: &TempDir) -> std::path::PathBuf {
)
.expect("write remote plugin manifest");
std::fs::write(&script_path, "echo remote attribution\n").expect("write remote plugin script");
store
.write_remote_plugin_id(&plugin_id, "plugins~Plugin_sample")
.expect("persist remote plugin id");
std::fs::write(
home.path().join("config.toml"),
format!(
@@ -245,45 +229,6 @@ fn block_plugin_mcp_startup(home: &TempDir, command: &str) -> std::path::PathBuf
barrier
}
fn write_plugin_app_plugin(home: &TempDir) {
write_plugin_app_plugin_with_name(home, "sample");
}
fn write_plugin_app_plugin_with_name(home: &TempDir, app_name: &str) {
let plugin_root = write_sample_plugin_manifest_and_config(home);
std::fs::write(
plugin_root.join(".app.json"),
format!(
r#"{{
"apps": {{
"{app_name}": {{
"id": "calendar"
}}
}}
}}"#
),
)
.expect("write plugin app config");
}
async fn build_apps_enabled_plugin_test_codex(
server: &MockServer,
codex_home: Arc<TempDir>,
chatgpt_base_url: String,
) -> Result<TestCodex> {
let mut builder = test_codex()
.with_home(codex_home)
.with_auth(CodexAuth::create_dummy_chatgpt_auth_for_testing())
.with_config(move |config| {
config
.features
.enable(Feature::Apps)
.expect("test config should allow feature update");
config.chatgpt_base_url = chatgpt_base_url;
});
builder.build_with_remote_and_local_env(server).await
}
async fn mount_plugin_tool_search_turn(server: &MockServer) -> ResponseMock {
mount_sse_sequence(
server,
@@ -326,7 +271,7 @@ fn searched_plugin_tools(
namespace_child_tool(
&app_output,
SAMPLE_PLUGIN_APP_NAMESPACE,
SEARCH_CALENDAR_CREATE_TOOL,
CALENDAR_CREATE_EVENT_TOOL_NAME,
)
.cloned(),
namespace_child_tool(&mcp_output, SAMPLE_PLUGIN_MCP_NAMESPACE, "echo").cloned(),
@@ -334,7 +279,7 @@ fn searched_plugin_tools(
}
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn persisted_remote_plugin_command_attribution_flows_through_turn_context() -> Result<()> {
async fn legacy_remote_marketplace_plugin_commands_are_not_attributed() -> Result<()> {
skip_if_target_windows!(Ok(()), "executes a POSIX shell script");
skip_if_no_network!(Ok(()));
skip_if_remote!(
@@ -344,7 +289,7 @@ async fn persisted_remote_plugin_command_attribution_flows_through_turn_context(
let server = start_mock_server().await;
let codex_home = Arc::new(TempDir::new()?);
let script_path = write_remote_plugin_script_and_config(codex_home.as_ref());
let script_path = write_legacy_remote_plugin_script_and_config(codex_home.as_ref());
std::fs::write(&script_path, "printf done\n")?;
let builder = test_codex();
let command = shlex::try_join(["/bin/sh", script_path.to_string_lossy().as_ref()])?;
@@ -373,7 +318,7 @@ async fn persisted_remote_plugin_command_attribution_flows_through_turn_context(
let chatgpt_base_url = server.uri();
let mut builder = builder
.with_home(Arc::clone(&codex_home))
.with_auth(CodexAuth::create_dummy_chatgpt_auth_for_testing())
.with_catalog_discovery_api_key()
.with_model("gpt-5.2")
.with_config(move |config| config.chatgpt_base_url = chatgpt_base_url);
let test_codex = builder.build_with_auto_env(&server).await?;
@@ -423,12 +368,13 @@ async fn persisted_remote_plugin_command_attribution_flows_through_turn_context(
);
wait_for_event(&codex, |event| matches!(event, EventMsg::TurnComplete(_))).await;
// Cache entries under the legacy remote marketplace name are no longer trusted roots.
for (plugin_id, script_path) in [
(begin.plugin_id.as_deref(), begin.script_path.as_deref()),
(end.plugin_id.as_deref(), end.script_path.as_deref()),
] {
assert_eq!(plugin_id, Some(REMOTE_PLUGIN_CONFIG_NAME));
assert_eq!(script_path, Some("scripts/run.sh"));
assert_eq!(plugin_id, None);
assert_eq!(script_path, None);
}
Ok(())
@@ -439,7 +385,6 @@ async fn thread_disabled_plugins_filter_skills_and_tools_without_changing_shared
-> Result<()> {
skip_if_no_network!(Ok(()));
let server = start_mock_server().await;
let apps = AppsTestServer::mount_with_connector_name(&server, "Google Calendar").await?;
let home = Arc::new(TempDir::new()?);
let skill_path = dunce::canonicalize(write_plugin_skill_plugin(home.as_ref()))?;
std::fs::write(
@@ -447,15 +392,10 @@ async fn thread_disabled_plugins_filter_skills_and_tools_without_changing_shared
"---\ndescription: inspect sample data\n---\nTHREAD_PLUGIN_SKILL_BODY\n",
)?;
write_plugin_mcp_plugin(home.as_ref(), &stdio_server_bin()?);
write_plugin_app_plugin_with_name(home.as_ref(), "sample_app");
let mut builder = test_codex()
.with_home(home)
.with_extensions(skills_extensions())
.with_auth(CodexAuth::create_dummy_chatgpt_auth_for_testing())
.with_config(move |config| {
config.features.enable(Feature::Apps).unwrap();
config.chatgpt_base_url = apps.chatgpt_base_url;
});
.with_auth(CodexAuth::from_api_key("Test API Key"));
let test = builder.build_with_remote_and_local_env(&server).await?;
let manager = test.thread_manager.plugins_manager();
let plugins_input = test.config.plugins_config_input();
@@ -466,7 +406,6 @@ async fn thread_disabled_plugins_filter_skills_and_tools_without_changing_shared
"echo",
Some(serde_json::json!({"message": "plugin check"})),
),
(CODEX_APPS_MCP_SERVER_NAME, "calendar_list_events", None),
];
for (phase, enabled, injection_count) in [(0, true, 1), (1, false, 1), (2, true, 2)] {
@@ -486,17 +425,12 @@ async fn thread_disabled_plugins_filter_skills_and_tools_without_changing_shared
.await?;
}
}
let app_call_id = format!("plugin-app-{phase}");
let mcp_call_id = format!("plugin-mcp-{phase}");
let mock = mount_sse_sequence(
&server,
vec![
sse(vec![
ev_response_created("search"),
ev_tool_search_call(
&app_call_id,
&serde_json::json!({"query": "create calendar event"}),
),
ev_tool_search_call(&mcp_call_id, &serde_json::json!({"query": "echo"})),
ev_completed("search"),
]),
@@ -542,11 +476,6 @@ async fn thread_disabled_plugins_filter_skills_and_tools_without_changing_shared
);
}
for (call_id, namespace, tool) in [
(
&app_call_id,
SAMPLE_PLUGIN_APP_NAMESPACE,
SEARCH_CALENDAR_CREATE_TOOL,
),
(&mcp_call_id, SAMPLE_PLUGIN_MCP_NAMESPACE, "echo"),
] {
assert_eq!(
@@ -555,7 +484,7 @@ async fn thread_disabled_plugins_filter_skills_and_tools_without_changing_shared
enabled
);
}
let calls_before = recorded_apps_tool_calls(&server).await.len();
let calls_before = recorded_mcp_tool_calls(&server).await.len();
// Direct Apps RPC calls keep their existing behavior outside model tool filtering.
for (server_name, tool, arguments) in &tool_calls {
let result = test
@@ -564,12 +493,12 @@ async fn thread_disabled_plugins_filter_skills_and_tools_without_changing_shared
.await;
assert_eq!(
result.is_ok(),
enabled || *server_name == CODEX_APPS_MCP_SERVER_NAME,
enabled || *server_name == MCP_TEST_SERVER_NAME,
"unexpected {server_name}/{tool} result: {result:?}"
);
}
assert_eq!(
recorded_apps_tool_calls(&server).await.len() - calls_before,
recorded_mcp_tool_calls(&server).await.len() - calls_before,
1
);
assert_eq!(
@@ -774,130 +703,6 @@ async fn legacy_plugin_skill_prompt_remains_complete() -> Result<()> {
Ok(())
}
#[test_case("sites", None, true, true, (true, false); "sites enabled remote supersedes bundled")]
#[test_case("sites", Some("tpp"), true, true, (true, false); "sites configured work sku")]
#[test_case("sites", None, false, true, (false, false); "sites disabled remote does not reactivate bundled")]
#[test_case("sites", None, true, false, (false, true); "sites missing remote bundle preserves bundled")]
#[test_case("visualize", None, true, true, (true, false); "visualize enabled remote supersedes bundled")]
#[test_case("visualize", None, false, true, (false, false); "visualize disabled remote does not reactivate bundled")]
#[test_case("visualize", None, true, false, (false, true); "visualize missing remote bundle preserves bundled")]
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn bundled_plugin_compatibility_guard_in_agent_turn(
plugin_name: &str,
product_sku: Option<&str>,
remote_enabled: bool,
cache_remote_plugin: bool,
expected_skills: (bool, bool),
) -> Result<()> {
skip_if_no_network!(Ok(()));
let server = start_mock_server().await;
let response = mount_sse_once(
&server,
sse(vec![ev_response_created("resp1"), ev_completed("resp1")]),
)
.await;
Mock::given(method("GET"))
.and(path("/ps/plugins/installed"))
.and(header("OAI-Product-Sku", product_sku.unwrap_or("codex")))
.respond_with(ResponseTemplate::new(200).set_body_json(serde_json::json!({
"plugins": [{
"id": format!("plugins~Plugin_{plugin_name}"),
"name": plugin_name,
"scope": "GLOBAL",
"status": "ENABLED",
"installation_policy": "AVAILABLE",
"authentication_policy": "ON_USE",
"release": {
"version": "local",
"display_name": plugin_name,
"description": plugin_name,
"interface": {},
},
"enabled": remote_enabled,
}],
"pagination": {"next_page_token": null},
})))
.mount(&server)
.await;
let codex_home = Arc::new(TempDir::new()?);
std::fs::write(
codex_home.path().join("config.toml"),
format!(
r#"[features]
plugins = true
remote_plugin = true
[plugins."{plugin_name}@openai-bundled"]
enabled = true
"#
),
)?;
for (marketplace, skill) in [
("openai-bundled", "bundled-skill"),
("openai-curated-remote", "remote-skill"),
] {
if marketplace == "openai-curated-remote" && !cache_remote_plugin {
continue;
}
let root = codex_home
.path()
.join(format!("plugins/cache/{marketplace}/{plugin_name}/local"));
std::fs::create_dir_all(root.join(".codex-plugin"))?;
std::fs::write(
root.join(".codex-plugin/plugin.json"),
format!(r#"{{"name":"{plugin_name}"}}"#),
)?;
let skill_dir = root.join("skills").join(skill);
std::fs::create_dir_all(&skill_dir)?;
std::fs::write(
skill_dir.join("SKILL.md"),
format!("---\nname: {skill}\ndescription: test skill\n---\n\n# body\n"),
)?;
}
let chatgpt_base_url = server.uri();
let product_sku = product_sku.map(str::to_owned);
let mut builder = test_codex()
.with_home(codex_home)
.with_extensions(skills_extensions())
.with_auth(CodexAuth::create_dummy_chatgpt_auth_for_testing())
.with_config(move |config| {
config.chatgpt_base_url = chatgpt_base_url;
config.apps_mcp_product_sku = product_sku;
});
let test = builder.build_with_auto_env(&server).await?;
let auth = test.thread_manager.auth_manager().auth().await;
test.thread_manager
.plugins_manager()
.reconcile_remote_installed_plugins(&test.config.plugins_config_input(), auth.as_ref())
.await?;
test.codex
.start_or_steer_turn(TurnInputRequest::user_input(vec![UserInput::Text {
text: format!("Inspect the available {plugin_name} skills."),
text_elements: Vec::new(),
}]))
.await?;
wait_for_event(&test.codex, |event| {
matches!(event, EventMsg::TurnComplete(_))
})
.await;
let requests = response.requests();
let developer_text = requests[0].message_input_texts("developer").join("\n");
assert_eq!(
(
developer_text.contains(&format!("{plugin_name}:remote-skill")),
developer_text.contains(&format!("{plugin_name}:bundled-skill")),
),
expected_skills,
"unexpected {plugin_name} skills in developer prompt: {developer_text:?}"
);
Ok(())
}
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn agent_plugin_root_mcp_stdio_tool_round_trip_expands_reserved_paths_and_codex_env_overlay()
-> Result<()> {
@@ -1052,505 +857,6 @@ async fn agent_plugin_root_mcp_stdio_tool_round_trip_expands_reserved_paths_and_
Ok(())
}
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn curated_plugin_skills_follow_auth_switch() -> Result<()> {
const CHATGPT_CURATED_PLUGIN_SKILL: &str = "chatgpt-plugin:chatgpt-skill";
const API_CURATED_PLUGIN_SKILL: &str = "api-plugin:api-skill";
const CURATED_PLUGIN_SKILLS: &[&str] =
&[CHATGPT_CURATED_PLUGIN_SKILL, API_CURATED_PLUGIN_SKILL];
#[derive(Clone, Copy)]
enum TargetAuth {
Chatgpt,
ApiKey,
BedrockApiKey,
NoCodexAuth,
}
#[derive(Clone, Copy)]
struct Fixture {
name: &'static str,
target_auth: TargetAuth,
target_model_provider_id: &'static str,
expected_target_loaded_plugin_skills: &'static [&'static str],
expected_target_skill_description: &'static str,
}
const FIXTURES: &[Fixture] = &[
Fixture {
name: "ChatGPT",
target_auth: TargetAuth::Chatgpt,
target_model_provider_id: OPENAI_PROVIDER_ID,
expected_target_loaded_plugin_skills: &[CHATGPT_CURATED_PLUGIN_SKILL],
expected_target_skill_description: "chatgpt description",
},
Fixture {
name: "ChatGPT with a custom provider",
target_auth: TargetAuth::Chatgpt,
target_model_provider_id: "ollama",
expected_target_loaded_plugin_skills: &[CHATGPT_CURATED_PLUGIN_SKILL],
expected_target_skill_description: "chatgpt description",
},
Fixture {
name: "API key",
target_auth: TargetAuth::ApiKey,
target_model_provider_id: OPENAI_PROVIDER_ID,
expected_target_loaded_plugin_skills: &[API_CURATED_PLUGIN_SKILL],
expected_target_skill_description: "api description before",
},
Fixture {
name: "Bedrock API key",
target_auth: TargetAuth::BedrockApiKey,
target_model_provider_id: AMAZON_BEDROCK_PROVIDER_ID,
expected_target_loaded_plugin_skills: &[API_CURATED_PLUGIN_SKILL],
expected_target_skill_description: "api description before",
},
Fixture {
name: "ambient Bedrock",
target_auth: TargetAuth::NoCodexAuth,
target_model_provider_id: AMAZON_BEDROCK_PROVIDER_ID,
expected_target_loaded_plugin_skills: &[API_CURATED_PLUGIN_SKILL],
expected_target_skill_description: "api description before",
},
Fixture {
name: "unauthenticated OpenAI",
target_auth: TargetAuth::NoCodexAuth,
target_model_provider_id: OPENAI_PROVIDER_ID,
expected_target_loaded_plugin_skills: &[API_CURATED_PLUGIN_SKILL],
expected_target_skill_description: "api description before",
},
Fixture {
name: "unauthenticated custom provider",
target_auth: TargetAuth::NoCodexAuth,
target_model_provider_id: "ollama",
expected_target_loaded_plugin_skills: &[API_CURATED_PLUGIN_SKILL],
expected_target_skill_description: "api description before",
},
];
async fn loaded_plugin_skills_for_config(test_codex: &TestCodex, config: &Config) -> String {
let plugins_input = config.plugins_config_input();
let plugins_manager = test_codex.thread_manager.plugins_manager();
let plugin_outcome = plugins_manager.plugins_for_config(&plugins_input).await;
let skills_input = HostSkillsLoadInput::new(
config.cwd.clone(),
plugin_outcome.effective_plugin_skill_roots(),
config.config_layer_stack.clone(),
)
.with_plugin_skill_snapshots(
plugins_manager.plugin_skill_snapshots_for_config(&plugins_input),
);
let skills_snapshot = test_codex
.thread_manager
.skills_service()
.snapshot_for_config(&skills_input, /*repository*/ None)
.await;
skills_snapshot
.outcome()
.skills
.iter()
.filter_map(|skill| {
let plugin_id = skill.plugin_id.as_deref()?;
let plugin_name = plugin_id
.split_once('@')
.map_or(plugin_id, |(plugin_name, _)| plugin_name);
Some(format!(
"{plugin_name}:{}\n{}",
skill.name, skill.description
))
})
.collect::<Vec<_>>()
.join("\n")
}
skip_if_no_network!(Ok(()));
let assert_loaded_plugin_skills =
|fixture_name: &str, phase: &str, skills: &str, expected: &[&str]| {
let loaded_plugin_skills = CURATED_PLUGIN_SKILLS
.iter()
.copied()
.filter(|plugin_skill| skills.contains(plugin_skill))
.collect::<Vec<_>>();
assert_eq!(
loaded_plugin_skills.as_slice(),
expected,
"unexpected curated plugin skills for {fixture_name} during {phase}: {skills:?}"
);
};
for fixture in FIXTURES {
let server = start_mock_server().await;
let codex_home = Arc::new(TempDir::new()?);
std::fs::write(
codex_home.path().join("config.toml"),
r#"[features]
plugins = true
remote_plugin = false
[plugins."chatgpt-plugin@openai-curated"]
enabled = true
[plugins."api-plugin@openai-api-curated"]
enabled = true
"#,
)?;
for (marketplace_name, plugin_name, skill_name, description) in [
(
"openai-curated",
"chatgpt-plugin",
"chatgpt-skill",
"chatgpt description",
),
(
"openai-api-curated",
"api-plugin",
"api-skill",
"api description before",
),
] {
let plugin_root = codex_home
.path()
.join("plugins/cache")
.join(marketplace_name)
.join(plugin_name)
.join("local");
std::fs::create_dir_all(plugin_root.join(".codex-plugin"))?;
std::fs::write(
plugin_root.join(".codex-plugin/plugin.json"),
format!(r#"{{"name":"{plugin_name}","description":"{plugin_name}"}}"#),
)?;
let skill_dir = plugin_root.join("skills").join(skill_name);
std::fs::create_dir_all(&skill_dir)?;
std::fs::write(
skill_dir.join("SKILL.md"),
format!("---\ndescription: {description}\n---\n\n# body\n"),
)?;
}
let mut builder = test_codex()
.with_home(Arc::clone(&codex_home))
.with_extensions(skills_extensions())
.with_auth(CodexAuth::create_dummy_chatgpt_auth_for_testing());
let test_codex = builder.build_with_auto_env(&server).await?;
let initial_skills = loaded_plugin_skills_for_config(&test_codex, &test_codex.config).await;
assert_loaded_plugin_skills(
fixture.name,
"initial ChatGPT config",
&initial_skills,
&[CHATGPT_CURATED_PLUGIN_SKILL],
);
assert!(initial_skills.contains("chatgpt description"));
std::fs::write(
codex_home.path().join(
"plugins/cache/openai-api-curated/api-plugin/local/skills/api-skill/SKILL.md",
),
"---\ndescription: api description after\n---\n\n# body\n",
)?;
let expected_auth_mode = match fixture.target_auth {
TargetAuth::Chatgpt => Some(AuthMode::Chatgpt),
TargetAuth::ApiKey => {
codex_login::login_with_api_key(
codex_home.path(),
"test-api-key",
codex_login::AuthCredentialsStoreMode::File,
codex_login::AuthKeyringBackendKind::default(),
)?;
test_codex.thread_manager.auth_manager().reload().await;
Some(AuthMode::ApiKey)
}
TargetAuth::BedrockApiKey => {
codex_login::login_with_bedrock_api_key(
codex_home.path(),
"test-bedrock-api-key",
"us-east-1",
codex_login::AuthCredentialsStoreMode::File,
codex_login::AuthKeyringBackendKind::default(),
)?;
test_codex.thread_manager.auth_manager().reload().await;
Some(AuthMode::BedrockApiKey)
}
TargetAuth::NoCodexAuth => {
test_codex.thread_manager.auth_manager().logout().await?;
None
}
};
assert_eq!(
test_codex.thread_manager.auth_manager().get_api_auth_mode(),
expected_auth_mode
);
test_codex.thread_manager.skills_service().clear_cache();
let mut target_config = test_codex.config.clone();
target_config.model_provider_id = fixture.target_model_provider_id.to_string();
let target_skills = loaded_plugin_skills_for_config(&test_codex, &target_config).await;
assert_loaded_plugin_skills(
fixture.name,
"target config",
&target_skills,
fixture.expected_target_loaded_plugin_skills,
);
assert!(
target_skills.contains(fixture.expected_target_skill_description),
"expected {:?} in current skills: {skills:?}",
fixture.expected_target_skill_description,
skills = target_skills
);
assert!(!target_skills.contains("api description after"));
}
Ok(())
}
#[test_case(true; "apps enabled")]
#[test_case(false; "apps disabled without direct MCP fallback")]
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn curated_agent_plugin_app_routing_reaches_turns(apps_enabled: bool) -> Result<()> {
skip_if_no_network!(Ok(()));
let server = start_mock_server().await;
let apps_server = AppsTestServer::mount_with_connector_name(&server, "Google Calendar").await?;
let mock = mount_plugin_tool_search_turn(&server).await;
let codex_home = Arc::new(TempDir::new()?);
let plugin_root = codex_home
.path()
.join("plugins/cache/openai-curated-remote/sample/local");
std::fs::create_dir_all(&plugin_root)?;
let command_name = format!("test_stdio_server{}", std::env::consts::EXE_SUFFIX);
codex_utils_cargo_bin::copy_executable(
std::path::Path::new(&stdio_server_bin()?),
&plugin_root.join(&command_name),
)?;
std::fs::write(
plugin_root.join("plugin.json"),
r#"{"$schema":"https://agent-plugins.org/schemas/1.0.0/plugin.schema.json","name":"sample","extensions":{"com.openai":{"apps":"./.app.json"}}}"#,
)?;
std::fs::write(
plugin_root.join(".app.json"),
r#"{"apps":{"calendar":{"id":"calendar"}}}"#,
)?;
let mcp_server = serde_json::json!({
"type": "stdio",
"command": format!("./{command_name}"),
});
std::fs::write(
plugin_root.join("mcp.json"),
serde_json::json!({
"$schema": "https://agent-plugins.org/schemas/1.0.0/mcp.schema.json",
"mcpServers": {"calendar": mcp_server, "sample": mcp_server},
})
.to_string(),
)?;
std::fs::write(
codex_home.path().join("config.toml"),
format!(
"[features]\nplugins = true\napps = {apps_enabled}\n[plugins.\"{SAMPLE_REMOTE_PLUGIN_CONFIG_NAME}\"]\nenabled = true\n"
),
)?;
let mut builder = test_codex()
.with_home(codex_home)
.with_auth(CodexAuth::create_dummy_chatgpt_auth_for_testing())
.with_config(move |config| {
config
.features
.set_enabled(Feature::Apps, apps_enabled)
.expect("test config should allow feature update");
config.chatgpt_base_url = apps_server.chatgpt_base_url;
});
let test = builder.build_with_remote_and_local_env(&server).await?;
assert!(test.config.features.enabled(Feature::Plugins));
assert_eq!(test.config.features.enabled(Feature::Apps), apps_enabled);
wait_for_mcp_server(&test.codex, "sample").await?;
test.codex
.start_or_steer_turn(TurnInputRequest::user_input(vec![UserInput::Mention {
name: "sample".into(),
path: format!("plugin://{SAMPLE_REMOTE_PLUGIN_CONFIG_NAME}"),
}]))
.await?;
wait_for_event(&test.codex, |event| {
matches!(event, EventMsg::TurnComplete(_))
})
.await;
let requests = mock.requests();
let (calendar_tool, echo_tool) = searched_plugin_tools(&requests[1]);
assert_eq!(calendar_tool.is_some(), apps_enabled);
if let Some(calendar_tool) = calendar_tool {
assert_plugin_provenance(&calendar_tool);
}
assert_plugin_provenance(&echo_tool.expect("unrelated MCP tool remains available"));
// Disabling Apps must not restore the matching direct MCP connection.
assert!(requests[0].tool_by_name("mcp__calendar", "echo").is_none());
let mcp_output = requests[1].tool_search_output(PLUGIN_MCP_SEARCH_CALL_ID);
assert!(namespace_child_tool(&mcp_output, "mcp__calendar", "echo").is_none());
let apps_connected = server
.received_requests()
.await
.expect("recorded app endpoint requests")
.iter()
.any(|request| request.url.path().trim_end_matches('/') == "/api/codex/ps/mcp");
assert_eq!(apps_connected, apps_enabled);
Ok(())
}
#[test_case("[apps.calendar]\nenabled = true", true; "enabled app")]
#[test_case("[apps.calendar]\nenabled = false", false; "disabled app")]
#[test_case("[plugins.\"sample@test\".apps.calendar]\nenabled = false", false; "nested disabled app")]
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn explicit_plugin_mentions_use_apps_for_chatgpt_dual_surface_plugins(
app_config: &str,
app_enabled: bool,
) -> Result<()> {
skip_if_no_network!(Ok(()));
let server = start_mock_server().await;
let apps_server = AppsTestServer::mount_with_connector_name(&server, "Google Calendar").await?;
let mock = mount_plugin_tool_search_turn(&server).await;
let codex_home = Arc::new(TempDir::new()?);
let rmcp_test_server_bin = match stdio_server_bin() {
Ok(bin) => bin,
Err(err) => {
eprintln!("test_stdio_server binary not available, skipping test: {err}");
return Ok(());
}
};
write_plugin_skill_plugin(codex_home.as_ref());
write_plugin_mcp_plugin(codex_home.as_ref(), &rmcp_test_server_bin);
write_plugin_app_plugin(codex_home.as_ref());
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{app_config}\n"))?;
let test_codex =
build_apps_enabled_plugin_test_codex(&server, codex_home, apps_server.chatgpt_base_url)
.await?;
let codex = Arc::clone(&test_codex.codex);
wait_for_mcp_server(&codex, CODEX_APPS_MCP_SERVER_NAME).await?;
codex
.start_or_steer_turn(TurnInputRequest::user_input(vec![
codex_protocol::user_input::UserInput::Mention {
name: "sample".into(),
path: format!("plugin://{SAMPLE_PLUGIN_CONFIG_NAME}"),
},
]))
.await?;
wait_for_event(&codex, |ev| matches!(ev, EventMsg::TurnComplete(_))).await;
let requests = mock.requests();
let request = &requests[0];
let developer_messages = request.message_input_texts("developer");
assert!(
developer_messages
.iter()
.any(|text| text.contains("Skills from this plugin")),
"expected plugin skills guidance: {developer_messages:?}"
);
assert!(
!developer_messages
.iter()
.any(|text| text.contains("MCP servers from this plugin")),
"expected plugin MCP guidance to be suppressed for ChatGPT auth: {developer_messages:?}"
);
assert_eq!(
developer_messages
.iter()
.any(|text| text.contains("Apps from this plugin")),
app_enabled,
"plugin app guidance should match app enablement: {developer_messages:?}"
);
assert_eq!(
developer_messages
.iter()
.any(|text| text.contains("if `tool_search` is available")),
app_enabled,
"plugin app search guidance should match app enablement: {developer_messages:?}"
);
assert!(
request
.tool_by_name(SAMPLE_PLUGIN_MCP_NAMESPACE, "echo")
.is_none(),
"plugin MCP tool should not leak into the request for ChatGPT auth"
);
let (calendar_tool, echo_tool) = searched_plugin_tools(&requests[1]);
assert_eq!(
calendar_tool.is_some(),
app_enabled,
"plugin app tool search should match app enablement"
);
if let Some(calendar_tool) = calendar_tool {
assert_plugin_provenance(&calendar_tool);
}
assert!(
echo_tool.is_none(),
"plugin MCP tool should be suppressed for ChatGPT auth"
);
Ok(())
}
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn explicit_plugin_mentions_keep_non_conflicting_mcp_for_chatgpt_auth() -> Result<()> {
skip_if_no_network!(Ok(()));
let server = start_mock_server().await;
let apps_server = AppsTestServer::mount_with_connector_name(&server, "Google Calendar").await?;
let mock = mount_plugin_tool_search_turn(&server).await;
let codex_home = Arc::new(TempDir::new()?);
let rmcp_test_server_bin = match stdio_server_bin() {
Ok(bin) => bin,
Err(err) => {
eprintln!("test_stdio_server binary not available, skipping test: {err}");
return Ok(());
}
};
write_plugin_skill_plugin(codex_home.as_ref());
write_plugin_mcp_plugin(codex_home.as_ref(), &rmcp_test_server_bin);
write_plugin_app_plugin_with_name(codex_home.as_ref(), "sample_app");
let test_codex =
build_apps_enabled_plugin_test_codex(&server, codex_home, apps_server.chatgpt_base_url)
.await?;
let codex = Arc::clone(&test_codex.codex);
wait_for_mcp_server(&codex, "sample").await?;
codex
.start_or_steer_turn(TurnInputRequest::user_input(vec![
codex_protocol::user_input::UserInput::Mention {
name: "sample".into(),
path: format!("plugin://{SAMPLE_PLUGIN_CONFIG_NAME}"),
},
]))
.await?;
wait_for_event(&codex, |ev| matches!(ev, EventMsg::TurnComplete(_))).await;
let requests = mock.requests();
let request = &requests[0];
let developer_messages = request.message_input_texts("developer");
assert!(
developer_messages
.iter()
.any(|text| text.contains("MCP servers from this plugin")),
"expected plugin MCP guidance to remain visible for non-conflicting app declaration: {developer_messages:?}"
);
assert!(
developer_messages
.iter()
.any(|text| text.contains("Apps from this plugin")),
"expected plugin app guidance: {developer_messages:?}"
);
let (calendar_tool, echo_tool) = searched_plugin_tools(&requests[1]);
assert!(
calendar_tool.is_some(),
"plugin app tool should be searchable"
);
let echo_tool = echo_tool.expect("plugin MCP tool should remain searchable");
assert_plugin_provenance(&echo_tool);
Ok(())
}
#[test_case(TrustLevel::Trusted, true, true, false, &[]; "trusted project disables the plugin")]
#[test_case(TrustLevel::Untrusted, true, true, false, &["echo_tool"]; "untrusted project cannot disable the plugin")]
#[test_case(TrustLevel::Trusted, false, true, true, &["echo"]; "trusted project enables system-disabled server and overrides user tool policy")]
@@ -1694,18 +1000,11 @@ async fn explicitly_requested_mcp_waits_for_startup(request: ExplicitMcpRequest)
};
let skill_path = dunce::canonicalize(write_plugin_skill_plugin(codex_home.as_ref()))?;
write_plugin_mcp_plugin(codex_home.as_ref(), &rmcp_test_server_bin);
write_plugin_app_plugin(codex_home.as_ref());
let initialize_barrier = block_plugin_mcp_startup(codex_home.as_ref(), &rmcp_test_server_bin);
let mut builder = test_codex()
.with_home(codex_home)
.with_auth(CodexAuth::from_api_key("Test API Key"))
.with_config(move |config| {
config
.features
.enable(Feature::Apps)
.expect("test config should allow feature update");
});
.with_auth(CodexAuth::from_api_key("Test API Key"));
let test_codex = builder.build_with_remote_and_local_env(&server).await?;
let codex = Arc::clone(&test_codex.codex);
@@ -1764,23 +1063,7 @@ async fn explicitly_requested_mcp_waits_for_startup(request: ExplicitMcpRequest)
"expected explicitly requested skill instructions: {user_messages:?}"
);
}
assert!(
!developer_messages
.iter()
.any(|text| text.contains("Apps from this plugin")),
"expected plugin app guidance to be suppressed for API-key auth: {developer_messages:?}"
);
assert!(
model_request
.tool_by_name(SAMPLE_PLUGIN_APP_NAMESPACE, SEARCH_CALENDAR_CREATE_TOOL)
.is_none(),
"plugin app tool should not leak into the request for API-key auth"
);
let (calendar_tool, echo_tool) = searched_plugin_tools(&requests[1]);
assert!(
calendar_tool.is_none(),
"plugin app tool should be hidden for API-key auth"
);
let (_, echo_tool) = searched_plugin_tools(&requests[1]);
let echo_tool = echo_tool.expect("plugin MCP tool should be searchable");
assert_plugin_provenance(&echo_tool);