mirror of
https://github.com/openai/codex.git
synced 2026-11-24 23:20:47 +00:00
Test plugin MCP tool approval overrides in the plugin cache (#63635)
## What changed Extend the plugin manager's cache test to verify that a per-tool `approval_mode = "approve"` takes effect after the cache is warmed with other configurations and is still returned after `.mcp.json` is removed. Remove the core test for this scenario and its test-only approval lookup. GitOrigin-RevId: f99d18b435f2c1f3e0574ec2ffedbe24249e6346
This commit is contained in:
@@ -3355,6 +3355,20 @@ enabled = false"#,
|
||||
let second_snapshots = manager
|
||||
.plugin_skill_snapshots_for_config(&second_config)
|
||||
.expect("second configuration snapshots");
|
||||
let approval_config = config(
|
||||
r#"[plugins."sample@test".mcp_servers.sample.tools.search]
|
||||
approval_mode = "approve""#,
|
||||
);
|
||||
let approval_outcome = manager.plugins_for_config(&approval_config).await;
|
||||
assert_eq!(
|
||||
approval_outcome.plugins()[0].mcp_servers["sample"]
|
||||
.tools
|
||||
.get("search"),
|
||||
Some(&McpServerToolConfig {
|
||||
approval_mode: Some(AppToolApproval::Approve),
|
||||
..Default::default()
|
||||
}),
|
||||
);
|
||||
std::fs::remove_file(plugin_root.join(".mcp.json")).unwrap();
|
||||
|
||||
assert_eq!(
|
||||
@@ -3376,6 +3390,10 @@ approval_mode = "prompt""#
|
||||
Some(second_snapshots),
|
||||
);
|
||||
assert_eq!(manager.plugins_for_config(&second_config).await, second);
|
||||
assert_eq!(
|
||||
manager.plugins_for_config(&approval_config).await,
|
||||
approval_outcome,
|
||||
);
|
||||
manager.clear_cache();
|
||||
assert_eq!(
|
||||
[first_config, second_config]
|
||||
|
||||
@@ -1432,56 +1432,6 @@ const MCP_TOOL_THREAD_ID_META_KEY: &str = "threadId";
|
||||
const MCP_TOOL_CONNECTED_ACCOUNT_EMAIL_META_KEY: &str = "connected_account_email";
|
||||
const MCP_TOOL_RESOURCE_URI_META_KEY: &str = "resource_uri";
|
||||
|
||||
#[cfg(test)]
|
||||
async fn custom_mcp_tool_approval_mode(
|
||||
sess: &Session,
|
||||
turn_context: &TurnContext,
|
||||
server: &str,
|
||||
tool_name: &str,
|
||||
) -> AppToolApproval {
|
||||
let user_configured_mode = turn_context
|
||||
.config
|
||||
.config_layer_stack
|
||||
.effective_config()
|
||||
.as_table()
|
||||
.and_then(|table| table.get("mcp_servers"))
|
||||
.cloned()
|
||||
.and_then(|value| {
|
||||
HashMap::<String, codex_config::types::McpServerConfig>::deserialize(value).ok()
|
||||
})
|
||||
.and_then(|servers| {
|
||||
let server_config = servers.get(server)?;
|
||||
Some(
|
||||
server_config
|
||||
.tools
|
||||
.get(tool_name)
|
||||
.and_then(|tool| tool.approval_mode)
|
||||
.or(server_config.default_tools_approval_mode)
|
||||
.unwrap_or_default(),
|
||||
)
|
||||
});
|
||||
if let Some(user_configured_mode) = user_configured_mode {
|
||||
return user_configured_mode;
|
||||
}
|
||||
|
||||
sess.services
|
||||
.plugins_manager
|
||||
.plugins_for_config(&turn_context.config.plugins_config_input())
|
||||
.await
|
||||
.plugins()
|
||||
.iter()
|
||||
.filter(|plugin| plugin.is_active())
|
||||
.find_map(|plugin| {
|
||||
let server_config = plugin.mcp_servers.get(server)?;
|
||||
server_config
|
||||
.tools
|
||||
.get(tool_name)
|
||||
.and_then(|tool| tool.approval_mode)
|
||||
.or(server_config.default_tools_approval_mode)
|
||||
})
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
fn build_mcp_tool_call_request_meta(
|
||||
step_context: &StepContext,
|
||||
server: &str,
|
||||
|
||||
@@ -2820,59 +2820,6 @@ async fn persist_custom_mcp_tool_approval_writes_tool_override() {
|
||||
assert!(contents.contains("[mcp_servers.docs.tools.search]"));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn custom_mcp_tool_approval_mode_uses_updated_plugin_mcp_policy_after_cache_warm() {
|
||||
let (session, mut turn_context) = make_session_and_context().await;
|
||||
let codex_home = session.codex_home().await;
|
||||
write_sample_plugin_mcp(codex_home.as_path());
|
||||
std::fs::write(
|
||||
codex_home.join(CONFIG_TOML_FILE),
|
||||
r#"
|
||||
[features]
|
||||
plugins = true
|
||||
|
||||
[plugins."sample@test"]
|
||||
enabled = true
|
||||
"#,
|
||||
)
|
||||
.expect("seed config");
|
||||
let initial_config = ConfigBuilder::default()
|
||||
.codex_home(codex_home.to_path_buf())
|
||||
.build()
|
||||
.await
|
||||
.expect("load initial config");
|
||||
session
|
||||
.services
|
||||
.plugins_manager
|
||||
.plugins_for_config(&initial_config.plugins_config_input())
|
||||
.await;
|
||||
std::fs::write(
|
||||
codex_home.join(CONFIG_TOML_FILE),
|
||||
r#"
|
||||
[features]
|
||||
plugins = true
|
||||
|
||||
[plugins."sample@test"]
|
||||
enabled = true
|
||||
|
||||
[plugins."sample@test".mcp_servers.sample.tools.search]
|
||||
approval_mode = "approve"
|
||||
"#,
|
||||
)
|
||||
.expect("update config");
|
||||
let updated_config = ConfigBuilder::default()
|
||||
.codex_home(codex_home.to_path_buf())
|
||||
.build()
|
||||
.await
|
||||
.expect("load updated config");
|
||||
turn_context.config = Arc::new(updated_config);
|
||||
|
||||
assert_eq!(
|
||||
custom_mcp_tool_approval_mode(&session, &turn_context, "sample", "search").await,
|
||||
AppToolApproval::Approve
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn maybe_persist_mcp_tool_approval_reloads_session_config() {
|
||||
let (session, turn_context) = make_session_and_context().await;
|
||||
|
||||
Reference in New Issue
Block a user