diff --git a/codex-rs/tui/src/chatwidget/plugin_catalog.rs b/codex-rs/tui/src/chatwidget/plugin_catalog.rs index 79cec717e7..0f476af7dd 100644 --- a/codex-rs/tui/src/chatwidget/plugin_catalog.rs +++ b/codex-rs/tui/src/chatwidget/plugin_catalog.rs @@ -54,6 +54,7 @@ use ratatui::prelude::Widget; use ratatui::style::Stylize; use ratatui::text::Line; use ratatui::text::Span; +use ratatui::text::Text; use ratatui::widgets::Paragraph; use ratatui::widgets::Wrap; use unicode_width::UnicodeWidthStr; @@ -1002,8 +1003,16 @@ impl ChatWidget { }); } if let Some(description) = plugin_detail_description(plugin) { + // Blank lines must not grow the popup header. + let description = Text::from( + description + .lines() + .filter(|line| !line.trim().is_empty()) + .map(|line| Line::from(line.to_string())) + .collect::>(), + ); header.push( - ratatui::widgets::Paragraph::new(Line::from(description.dim())) + ratatui::widgets::Paragraph::new(description.dim()) .wrap(ratatui::widgets::Wrap { trim: false }), ); } diff --git a/codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__tests__plugin_detail_popup_description_line_breaks_100.snap b/codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__tests__plugin_detail_popup_description_line_breaks_100.snap new file mode 100644 index 0000000000..b3e7420978 --- /dev/null +++ b/codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__tests__plugin_detail_popup_description_line_breaks_100.snap @@ -0,0 +1,21 @@ +--- +source: tui/src/chatwidget/tests/popups_and_settings.rs +expression: strip_osc8_for_snapshot(&popup) +--- + Plugins + Paragraphs · Installed by admin · ChatGPT Marketplace + Work from your conversation. + Find and summarize Jira issues with full context. + Supporting both read and write actions. + + +› 1. Back to plugins Return to the plugin list + Installed by admin This plugin is installed by your workspace admin + Source Local + Auth Auth on install + Skills No plugin skills + Hooks No plugin hooks + Apps No plugin apps + MCP Servers No plugin MCP servers + + esc close diff --git a/codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__tests__plugin_detail_popup_description_line_breaks_40.snap b/codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__tests__plugin_detail_popup_description_line_breaks_40.snap new file mode 100644 index 0000000000..208c17a9f5 --- /dev/null +++ b/codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__tests__plugin_detail_popup_description_line_breaks_40.snap @@ -0,0 +1,24 @@ +--- +source: tui/src/chatwidget/tests/popups_and_settings.rs +expression: strip_osc8_for_snapshot(&popup) +--- + Plugins + Paragraphs · Installed by admin · + ChatGPT Marketplace + Work from your conversation. + Find and summarize Jira issues with + full context. + Supporting both read and write + actions. + + +› 1. Back to plugins + Installed by admin + Source + Auth + Skills + Hooks + Apps + MCP Servers + + esc close diff --git a/codex-rs/tui/src/chatwidget/tests/popups_and_settings.rs b/codex-rs/tui/src/chatwidget/tests/popups_and_settings.rs index f020776810..90b3097709 100644 --- a/codex-rs/tui/src/chatwidget/tests/popups_and_settings.rs +++ b/codex-rs/tui/src/chatwidget/tests/popups_and_settings.rs @@ -668,6 +668,320 @@ async fn plugin_detail_popup_snapshot_labels_personal_marketplace_as_local() { ); } +#[tokio::test] +async fn plugins_popup_stays_disabled_when_feature_is_disabled() { + let (mut chat, mut rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await; + chat.set_feature_enabled(Feature::Plugins, /*enabled*/ false); + chat.add_plugins_output(); + assert!(!chat.has_active_view()); + let rendered = drain_insert_history(&mut rx) + .iter() + .map(|lines| lines_to_single_string(lines)) + .collect::>() + .join("\n"); + assert!(rendered.contains("Plugins are disabled."), "{rendered}"); +} + +#[tokio::test] +async fn plugin_detail_popup_collapses_blank_lines_and_preserves_wrapping() { + let (mut chat, _rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await; + chat.set_feature_enabled(Feature::Plugins, /*enabled*/ true); + let summary = plugins_test_summary( + "plugin-paragraphs", + "paragraphs", + Some("Paragraphs"), + Some("Description rendering."), + /*installed*/ true, + /*enabled*/ true, + PluginInstallPolicy::InstalledByDefault, + ); + let cwd = chat.config.cwd.to_path_buf(); + chat.on_plugins_loaded( + cwd.clone(), + Ok(plugins_test_response(vec![ + plugins_test_curated_marketplace(vec![summary.clone()]), + ])), + ); + chat.add_plugins_output(); + let mut plugin = plugins_test_detail( + summary, + Some( + "Work from your conversation.\n\nFind and summarize Jira issues with full context.\n\nSupporting both read and write actions.", + ), + &[], + &[], + &[], + &[], + ); + let mut expected_heights = None; + for separator in [ + "\n".to_string(), + "\n\n".to_string(), + "\r\n\r\n\r\n".to_string(), + "\n\r\n\n\r\n".to_string(), + "\n \t\r\n \n\r\n".to_string(), + "\r\n".repeat(/*n*/ 1000), + ] { + plugin.description = Some(format!( + "Work from your conversation.{separator}Find and summarize Jira issues with full context.{separator}Supporting both read and write actions." + )); + chat.on_plugin_detail_loaded( + cwd.clone(), + Ok(PluginReadResponse { + plugin: plugin.clone(), + }), + ); + let mut heights = Vec::new(); + for width in [100, 40] { + let popup = render_bottom_popup(&chat, width); + let description = popup + .lines() + .skip_while(|line| !line.contains("Work from your conversation.")) + .take_while(|line| !line.contains("Back to plugins")) + .map(str::trim) + .collect::>() + .join("\n"); + let description = description.trim(); + assert!(description.lines().all(|line| !line.is_empty()), "{popup}"); + assert_eq!( + description.lines().collect::>().join(" "), + "Work from your conversation. Find and summarize Jira issues with full context. Supporting both read and write actions.", + "width {width}:\n{popup}" + ); + if width == 100 { + assert_eq!(description.lines().count(), 3, "{popup}"); + } else { + assert!(description.contains("Find and summarize Jira issues with\nfull context.")); + } + heights.push(chat.desired_height(width)); + if separator != "\n" { + assert_chatwidget_snapshot!( + format!("plugin_detail_popup_description_line_breaks_{width}"), + strip_osc8_for_snapshot(&popup) + ); + } + } + if let Some(expected) = &expected_heights { + assert_eq!( + &heights, expected, + "blank lines must not increase popup height" + ); + } else { + expected_heights = Some(heights); + } + } + + let single_paragraph = "Work from your conversation. Find and summarize Jira issues with full context. Supporting both read and write actions."; + plugin.description = Some(single_paragraph.to_string()); + chat.on_plugin_detail_loaded(cwd, Ok(PluginReadResponse { plugin })); + for width in [40, 100] { + let popup = render_bottom_popup(&chat, width); + let mut lines = popup + .lines() + .skip_while(|line| !line.contains("Work from your conversation.")) + .take_while(|line| !line.contains("Back to plugins")) + .map(str::trim) + .collect::>(); + while lines.last() == Some(&"") { + lines.pop(); + } + assert!(lines.iter().all(|line| !line.is_empty()), "{popup}"); + assert_eq!(lines.join(" "), single_paragraph, "{popup}"); + } +} + +#[tokio::test] +async fn plugin_detail_popup_preserves_plain_text_and_dim_style() { + let (mut chat, _rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await; + chat.set_feature_enabled(Feature::Plugins, /*enabled*/ true); + let summary = plugins_test_summary( + "plugin-text", + "text", + Some("Text"), + /*description*/ None, + /*installed*/ false, + /*enabled*/ true, + PluginInstallPolicy::Available, + ); + let cwd = chat.config.cwd.to_path_buf(); + chat.on_plugins_loaded( + cwd.clone(), + Ok(plugins_test_response(vec![ + plugins_test_curated_marketplace(vec![summary.clone()]), + ])), + ); + chat.add_plugins_output(); + for newline in ["\n", "\r\n"] { + let description = format!( + "Literal **bold** *italic* `code`.{newline}café 日本語.{newline}{newline}[link](https://example.com)." + ); + let plugin = plugins_test_detail(summary.clone(), Some(&description), &[], &[], &[], &[]); + chat.on_plugin_detail_loaded(cwd.clone(), Ok(PluginReadResponse { plugin })); + for width in [40, 100] { + let popup = render_bottom_popup(&chat, width); + assert!( + popup.contains("Literal **bold** *italic* `code`."), + "{popup}" + ); + assert!(popup.contains("[link](https://example.com)."), "{popup}"); + let area = Rect::new( + /*x*/ 0, + /*y*/ 0, + width, + chat.desired_height(width), + ); + let mut buf = Buffer::empty(area); + chat.render(area, &mut buf); + let text_row = (0..area.height) + .find(|y| { + (0..width) + .map(|x| buf[(x, *y)].symbol()) + .collect::() + .contains("Literal") + }) + .expect("plain text row"); + let next_row = (0..width) + .map(|x| buf[(x, text_row + 1)].symbol()) + .collect::(); + assert_eq!( + next_row.split_whitespace().collect::(), + "café日本語." + ); + let link_row = (0..width) + .map(|x| buf[(x, text_row + 2)].symbol()) + .collect::(); + assert!(link_row.contains("[link](https://example.com)."), "{popup}"); + for y in [text_row, text_row + 1, text_row + 2] { + for x in 0..width { + let cell = &buf[(x, y)]; + if !cell.symbol().trim().is_empty() { + assert!(cell.modifier.contains(ratatui::style::Modifier::DIM)); + assert!(!cell.modifier.intersects( + ratatui::style::Modifier::BOLD | ratatui::style::Modifier::ITALIC + )); + } + } + } + } + } +} + +#[tokio::test] +async fn plugin_detail_popup_preserves_description_fallbacks() { + for (detail, long, short, expected) in [ + ( + Some(" Detail text. "), + Some("Long fallback."), + Some("Short fallback."), + Some("Detail text."), + ), + ( + None, + Some("Long fallback."), + Some("Short fallback."), + Some("Long fallback."), + ), + (None, None, Some("Short fallback."), Some("Short fallback.")), + (None, None, None, None), + ( + Some(" \r\n "), + Some("Long fallback."), + Some("Short fallback."), + None, + ), + (None, Some(""), Some("Short fallback."), None), + ] { + for installed in [false, true] { + let (mut chat, _rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await; + chat.set_feature_enabled(Feature::Plugins, /*enabled*/ true); + let mut summary = plugins_test_summary( + "plugin-fallback", + "fallback", + Some("Fallback"), + short, + installed, + /*enabled*/ true, + PluginInstallPolicy::Available, + ); + summary + .interface + .as_mut() + .expect("interface") + .long_description = long.map(str::to_string); + let cwd = chat.config.cwd.to_path_buf(); + chat.on_plugins_loaded( + cwd.clone(), + Ok(plugins_test_response(vec![ + plugins_test_curated_marketplace(vec![summary.clone()]), + ])), + ); + chat.add_plugins_output(); + let plugin = plugins_test_detail(summary, detail, &[], &[], &[], &[]); + chat.on_plugin_detail_loaded(cwd, Ok(PluginReadResponse { plugin })); + for width in [40, 100] { + let popup = render_bottom_popup(&chat, width); + for candidate in ["Detail text.", "Long fallback.", "Short fallback."] { + assert_eq!( + popup.contains(candidate), + expected == Some(candidate), + "{popup}" + ); + } + assert!(popup.contains("Back to plugins"), "{popup}"); + assert_eq!(popup.contains("Data shared"), !installed, "{popup}"); + } + } + } +} + +#[tokio::test] +async fn plugin_detail_popup_long_description_keeps_actions_in_short_viewport() { + for width in [40, 100] { + let (mut chat, mut rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await; + chat.set_feature_enabled(Feature::Plugins, /*enabled*/ true); + let summary = plugins_test_summary( + "plugin-long", + "long", + Some("Long"), + /*description*/ None, + /*installed*/ false, + /*enabled*/ true, + PluginInstallPolicy::Available, + ); + let cwd = chat.config.cwd.to_path_buf(); + chat.on_plugins_loaded( + cwd.clone(), + Ok(plugins_test_response(vec![ + plugins_test_curated_marketplace(vec![summary.clone()]), + ])), + ); + chat.add_plugins_output(); + let description = "Long description with ordinary wrapping and multiple paragraphs.\n\n" + .repeat(/*n*/ 30); + let plugin = plugins_test_detail(summary, Some(&description), &[], &[], &[], &[]); + chat.on_plugin_detail_loaded(cwd, Ok(PluginReadResponse { plugin })); + let area = Rect::new(/*x*/ 0, /*y*/ 0, width, /*height*/ 12); + let mut buf = Buffer::empty(area); + chat.render(area, &mut buf); + let popup = (0..area.height) + .map(|y| (0..width).map(|x| buf[(x, y)].symbol()).collect::()) + .collect::>() + .join("\n"); + assert!(popup.contains("Back to plugins"), "{popup}"); + while rx.try_recv().is_ok() {} + chat.handle_key_event(KeyEvent::from(KeyCode::Down)); + chat.render(area, &mut buf); + let popup = (0..area.height) + .map(|y| (0..width).map(|x| buf[(x, y)].symbol()).collect::()) + .collect::>() + .join("\n"); + assert!(popup.contains("Install plugin"), "{popup}"); + chat.handle_key_event(KeyEvent::from(KeyCode::Enter)); + assert_matches!(rx.try_recv(), Ok(AppEvent::OpenPluginInstallLoading { .. })); + assert_matches!(rx.try_recv(), Ok(AppEvent::FetchPluginInstall { .. })); + } +} + #[tokio::test] async fn plugin_detail_popup_snapshot_shows_npm_source() { let (mut chat, _rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;