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)