From 0671b870b00f7a60cc59308377a08424f7c3c7e9 Mon Sep 17 00:00:00 2001 From: Felipe Coury Date: Thu, 28 May 2026 21:08:46 -0300 Subject: [PATCH] fix(tui): wrap usage error card text --- ...sage_error_wraps_long_backend_message.snap | 13 +++++++++ .../chatwidget/tests/popups_and_settings.rs | 27 +++++++++++++++++++ codex-rs/tui/src/chatwidget/usage.rs | 8 ++++-- 3 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__tests__usage_error_wraps_long_backend_message.snap diff --git a/codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__tests__usage_error_wraps_long_backend_message.snap b/codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__tests__usage_error_wraps_long_backend_message.snap new file mode 100644 index 0000000000..f799c5caf2 --- /dev/null +++ b/codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__tests__usage_error_wraps_long_backend_message.snap @@ -0,0 +1,13 @@ +--- +source: tui/src/chatwidget/tests/popups_and_settings.rs +expression: rendered +--- +/usage + +╭────────────────────────────────────────────────────────╮ +│ Usage by token share │ +│ Percent of consumed tokens in this selected range │ +│ │ +│ Failed to load usage: sqlite state database could not │ +│ be opened because the configured path is unavailable │ +╰────────────────────────────────────────────────────────╯ 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 705ff4cb81..1658a64710 100644 --- a/codex-rs/tui/src/chatwidget/tests/popups_and_settings.rs +++ b/codex-rs/tui/src/chatwidget/tests/popups_and_settings.rs @@ -244,6 +244,33 @@ async fn usage_output_reports_unattributed_usage() { assert_chatwidget_snapshot!("usage_output_unattributed", rendered); } +#[tokio::test] +async fn usage_error_wraps_long_backend_message() { + let (mut chat, mut rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await; + + chat.add_usage_output(); + assert_matches!( + rx.try_recv(), + Ok(AppEvent::FetchUsage { + request_id: 0, + range: UsageRange::Day, + }) + ); + chat.on_usage_loaded( + /*request_id*/ 0, + Err( + "sqlite state database could not be opened because the configured path is unavailable" + .to_string(), + ), + ); + + let Ok(AppEvent::InsertHistoryCell(cell)) = rx.try_recv() else { + panic!("expected usage history cell"); + }; + let rendered = lines_to_single_string(&cell.display_lines(/*width*/ 60)); + assert_chatwidget_snapshot!("usage_error_wraps_long_backend_message", rendered); +} + #[tokio::test] async fn usage_output_weekly_snapshot() { let (mut chat, mut rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await; diff --git a/codex-rs/tui/src/chatwidget/usage.rs b/codex-rs/tui/src/chatwidget/usage.rs index adbdb30ee2..0100f2e6ad 100644 --- a/codex-rs/tui/src/chatwidget/usage.rs +++ b/codex-rs/tui/src/chatwidget/usage.rs @@ -106,12 +106,16 @@ impl HistoryCell for UsageErrorHistoryCell { let Some(available_width) = usage_card_available_width(width) else { return Vec::new(); }; - let lines = vec![ + let mut lines = vec![ Line::from(USAGE_TITLE.bold()), Line::from(USAGE_SUBTITLE.dim()), Line::default(), - Line::from(format!(" Failed to load usage: {}", self.error)), ]; + push_wrapped_text( + &mut lines, + format!(" Failed to load usage: {}", self.error), + available_width, + ); let inner_width = lines .iter() .map(line_display_width)