From fed1dd3b8d62f1635eef400aa1cf24534f8d28e0 Mon Sep 17 00:00:00 2001 From: martinauyeung-oai <280153141+martinauyeung-oai@users.noreply.github.com> Date: Tue, 7 Jul 2026 04:26:39 -0700 Subject: [PATCH] Move MCP UI capability tests to sibling module --- codex-rs/codex-mcp/src/client_capabilities.rs | 94 +------------------ .../src/client_capabilities_tests.rs | 92 ++++++++++++++++++ 2 files changed, 94 insertions(+), 92 deletions(-) create mode 100644 codex-rs/codex-mcp/src/client_capabilities_tests.rs diff --git a/codex-rs/codex-mcp/src/client_capabilities.rs b/codex-rs/codex-mcp/src/client_capabilities.rs index 7876b08c10..df7696039c 100644 --- a/codex-rs/codex-mcp/src/client_capabilities.rs +++ b/codex-rs/codex-mcp/src/client_capabilities.rs @@ -64,95 +64,5 @@ pub(crate) fn with_client_capabilities_meta( } #[cfg(test)] -mod tests { - use pretty_assertions::assert_eq; - use serde_json::json; - - use super::*; - - #[test] - fn recognizes_only_the_webview_mime_type() { - let extensions = HashMap::from([ - ( - MCP_APP_UI_EXTENSION_ID.to_string(), - json!({ - "mimeTypes": [ - MCP_APP_UI_WEBVIEW_MIME_TYPE, - "text/x-dil;profile=mcp-app", - ], - }), - ), - ("example/other".to_string(), json!({"enabled": true})), - ]); - - assert!(supports_mcp_app_ui_webview(Some(&extensions))); - assert!(!supports_mcp_app_ui_webview(Some(&HashMap::from([( - MCP_APP_UI_EXTENSION_ID.to_string(), - json!({"mimeTypes": ["text/x-dil;profile=mcp-app"]}), - ),])))); - assert!(!supports_mcp_app_ui_webview(Some(&HashMap::from([( - MCP_APP_UI_EXTENSION_ID.to_string(), - json!("invalid") - ),])))); - } - - #[test] - fn trusted_capabilities_replace_spoofed_request_metadata() { - let meta = with_client_capabilities_meta( - Some(json!({ - MCP_CLIENT_CAPABILITIES_META_KEY: {"spoofed": true}, - "caller": "preserved", - })), - /*supports_mcp_app_ui_webview*/ true, - ); - - assert_eq!( - meta, - Some(json!({ - "caller": "preserved", - MCP_CLIENT_CAPABILITIES_META_KEY: { - "extensions": { - MCP_APP_UI_EXTENSION_ID: { - "mimeTypes": [ - MCP_APP_UI_WEBVIEW_MIME_TYPE, - ] - } - } - } - })) - ); - } - - #[test] - fn absent_host_capabilities_remove_spoofed_request_metadata() { - assert_eq!( - with_client_capabilities_meta( - Some(json!({ - MCP_CLIENT_CAPABILITIES_META_KEY: {"spoofed": true}, - "caller": "preserved", - })), - /*supports_mcp_app_ui_webview*/ false, - ), - Some(json!({"caller": "preserved"})) - ); - } - - #[test] - fn invalid_caller_metadata_does_not_suppress_trusted_capabilities() { - assert_eq!( - with_client_capabilities_meta( - Some(json!("invalid")), - /*supports_mcp_app_ui_webview*/ true, - ), - Some(json!({ - MCP_CLIENT_CAPABILITIES_META_KEY: { - "extensions": { - MCP_APP_UI_EXTENSION_ID: { - "mimeTypes": [MCP_APP_UI_WEBVIEW_MIME_TYPE], - } - } - } - })) - ); - } -} +#[path = "client_capabilities_tests.rs"] +mod tests; diff --git a/codex-rs/codex-mcp/src/client_capabilities_tests.rs b/codex-rs/codex-mcp/src/client_capabilities_tests.rs new file mode 100644 index 0000000000..b6e9836e69 --- /dev/null +++ b/codex-rs/codex-mcp/src/client_capabilities_tests.rs @@ -0,0 +1,92 @@ +use std::collections::HashMap; + +use pretty_assertions::assert_eq; +use serde_json::json; + +use super::*; + +#[test] +fn recognizes_only_the_webview_mime_type() { + let extensions = HashMap::from([ + ( + MCP_APP_UI_EXTENSION_ID.to_string(), + json!({ + "mimeTypes": [ + MCP_APP_UI_WEBVIEW_MIME_TYPE, + "text/x-dil;profile=mcp-app", + ], + }), + ), + ("example/other".to_string(), json!({"enabled": true})), + ]); + + assert!(supports_mcp_app_ui_webview(Some(&extensions))); + assert!(!supports_mcp_app_ui_webview(Some(&HashMap::from([( + MCP_APP_UI_EXTENSION_ID.to_string(), + json!({"mimeTypes": ["text/x-dil;profile=mcp-app"]}), + ),])))); + assert!(!supports_mcp_app_ui_webview(Some(&HashMap::from([( + MCP_APP_UI_EXTENSION_ID.to_string(), + json!("invalid") + ),])))); +} + +#[test] +fn trusted_capabilities_replace_spoofed_request_metadata() { + let meta = with_client_capabilities_meta( + Some(json!({ + MCP_CLIENT_CAPABILITIES_META_KEY: {"spoofed": true}, + "caller": "preserved", + })), + /*supports_mcp_app_ui_webview*/ true, + ); + + assert_eq!( + meta, + Some(json!({ + "caller": "preserved", + MCP_CLIENT_CAPABILITIES_META_KEY: { + "extensions": { + MCP_APP_UI_EXTENSION_ID: { + "mimeTypes": [ + MCP_APP_UI_WEBVIEW_MIME_TYPE, + ] + } + } + } + })) + ); +} + +#[test] +fn absent_host_capabilities_remove_spoofed_request_metadata() { + assert_eq!( + with_client_capabilities_meta( + Some(json!({ + MCP_CLIENT_CAPABILITIES_META_KEY: {"spoofed": true}, + "caller": "preserved", + })), + /*supports_mcp_app_ui_webview*/ false, + ), + Some(json!({"caller": "preserved"})) + ); +} + +#[test] +fn invalid_caller_metadata_does_not_suppress_trusted_capabilities() { + assert_eq!( + with_client_capabilities_meta( + Some(json!("invalid")), + /*supports_mcp_app_ui_webview*/ true, + ), + Some(json!({ + MCP_CLIENT_CAPABILITIES_META_KEY: { + "extensions": { + MCP_APP_UI_EXTENSION_ID: { + "mimeTypes": [MCP_APP_UI_WEBVIEW_MIME_TYPE], + } + } + } + })) + ); +}