From 0fdb0142416590884dad4a8960a4cf6611e9f150 Mon Sep 17 00:00:00 2001 From: Dylan Hurd Date: Mon, 16 Feb 2026 14:08:46 -0800 Subject: [PATCH] clean up snapshot tests --- codex-rs/tui/src/bottom_pane/footer.rs | 91 +++++++++++++------ ...tests__footer_mode_esc_hint_backtrack.snap | 2 +- ...r_mode_overlay_then_external_esc_hint.snap | 2 +- codex-rs/tui/src/bottom_pane/textarea.rs | 7 +- 4 files changed, 67 insertions(+), 35 deletions(-) diff --git a/codex-rs/tui/src/bottom_pane/footer.rs b/codex-rs/tui/src/bottom_pane/footer.rs index 2f9348cc14..3d282015ee 100644 --- a/codex-rs/tui/src/bottom_pane/footer.rs +++ b/codex-rs/tui/src/bottom_pane/footer.rs @@ -1014,7 +1014,7 @@ mod tests { use ratatui::backend::TestBackend; fn snapshot_footer(name: &str, props: FooterProps) { - snapshot_footer_with_mode_indicator(name, 80, &props, None); + snapshot_footer_with_mode_indicator(name, 80, &props, None, None); } fn draw_footer_frame( @@ -1022,6 +1022,7 @@ mod tests { height: u16, props: &FooterProps, collaboration_mode_indicator: Option, + right_context_override: Option>, ) { terminal .draw(|f| { @@ -1084,7 +1085,9 @@ mod tests { compact } } else { - Some(context_window_line(None, None)) + right_context_override + .clone() + .or_else(|| Some(context_window_line(None, None))) }; let right_width = right_line .as_ref() @@ -1172,10 +1175,17 @@ mod tests { width: u16, props: &FooterProps, collaboration_mode_indicator: Option, + right_context_override: Option>, ) { let height = footer_height(props).max(1); let mut terminal = Terminal::new(TestBackend::new(width, height)).unwrap(); - draw_footer_frame(&mut terminal, height, props, collaboration_mode_indicator); + draw_footer_frame( + &mut terminal, + height, + props, + collaboration_mode_indicator, + right_context_override, + ); assert_snapshot!(name, terminal.backend()); } @@ -1186,7 +1196,13 @@ mod tests { ) -> String { let height = footer_height(props).max(1); let mut terminal = Terminal::new(VT100Backend::new(width, height)).expect("terminal"); - draw_footer_frame(&mut terminal, height, props, collaboration_mode_indicator); + draw_footer_frame( + &mut terminal, + height, + props, + collaboration_mode_indicator, + None, + ); terminal.backend().vt100().screen().contents() } @@ -1304,36 +1320,44 @@ mod tests { }, ); - snapshot_footer( + let context_running = FooterProps { + mode: FooterMode::ComposerEmpty, + esc_backtrack_hint: false, + use_shift_enter_hint: false, + is_task_running: true, + steer_enabled: false, + collaboration_modes_enabled: false, + is_wsl: false, + quit_shortcut_key: key_hint::ctrl(KeyCode::Char('c')), + status_line_value: None, + status_line_enabled: false, + }; + snapshot_footer_with_mode_indicator( "footer_shortcuts_context_running", - FooterProps { - mode: FooterMode::ComposerEmpty, - esc_backtrack_hint: false, - use_shift_enter_hint: false, - is_task_running: true, - steer_enabled: false, - collaboration_modes_enabled: false, - is_wsl: false, - quit_shortcut_key: key_hint::ctrl(KeyCode::Char('c')), - status_line_value: None, - status_line_enabled: false, - }, + 80, + &context_running, + None, + Some(context_window_line(Some(72), None)), ); - snapshot_footer( + let context_tokens_used = FooterProps { + mode: FooterMode::ComposerEmpty, + esc_backtrack_hint: false, + use_shift_enter_hint: false, + is_task_running: false, + steer_enabled: false, + collaboration_modes_enabled: false, + is_wsl: false, + quit_shortcut_key: key_hint::ctrl(KeyCode::Char('c')), + status_line_value: None, + status_line_enabled: false, + }; + snapshot_footer_with_mode_indicator( "footer_context_tokens_used", - FooterProps { - mode: FooterMode::ComposerEmpty, - esc_backtrack_hint: false, - use_shift_enter_hint: false, - is_task_running: false, - steer_enabled: false, - collaboration_modes_enabled: false, - is_wsl: false, - quit_shortcut_key: key_hint::ctrl(KeyCode::Char('c')), - status_line_value: None, - status_line_enabled: false, - }, + 80, + &context_tokens_used, + None, + Some(context_window_line(None, Some(123_456))), ); snapshot_footer( @@ -1386,6 +1410,7 @@ mod tests { 120, &props, Some(CollaborationModeIndicator::Plan), + None, ); snapshot_footer_with_mode_indicator( @@ -1393,6 +1418,7 @@ mod tests { 50, &props, Some(CollaborationModeIndicator::Plan), + None, ); let props = FooterProps { @@ -1413,6 +1439,7 @@ mod tests { 120, &props, Some(CollaborationModeIndicator::Plan), + None, ); let props = FooterProps { @@ -1448,6 +1475,7 @@ mod tests { 120, &props, Some(CollaborationModeIndicator::Plan), + None, ); let props = FooterProps { @@ -1468,6 +1496,7 @@ mod tests { 120, &props, Some(CollaborationModeIndicator::Plan), + Some(context_window_line(Some(50), None)), ); let props = FooterProps { @@ -1489,6 +1518,7 @@ mod tests { 120, &props, None, + None, ); let props = FooterProps { @@ -1511,6 +1541,7 @@ mod tests { 40, &props, Some(CollaborationModeIndicator::Plan), + None, ); } diff --git a/codex-rs/tui/src/bottom_pane/snapshots/codex_tui__bottom_pane__chat_composer__tests__footer_mode_esc_hint_backtrack.snap b/codex-rs/tui/src/bottom_pane/snapshots/codex_tui__bottom_pane__chat_composer__tests__footer_mode_esc_hint_backtrack.snap index 2fce42cc26..5b101f024b 100644 --- a/codex-rs/tui/src/bottom_pane/snapshots/codex_tui__bottom_pane__chat_composer__tests__footer_mode_esc_hint_backtrack.snap +++ b/codex-rs/tui/src/bottom_pane/snapshots/codex_tui__bottom_pane__chat_composer__tests__footer_mode_esc_hint_backtrack.snap @@ -10,4 +10,4 @@ expression: terminal.backend() " " " " " " -" esc again to edit previous message " +" esc again to edit previous message 100% context left " diff --git a/codex-rs/tui/src/bottom_pane/snapshots/codex_tui__bottom_pane__chat_composer__tests__footer_mode_overlay_then_external_esc_hint.snap b/codex-rs/tui/src/bottom_pane/snapshots/codex_tui__bottom_pane__chat_composer__tests__footer_mode_overlay_then_external_esc_hint.snap index 2fce42cc26..5b101f024b 100644 --- a/codex-rs/tui/src/bottom_pane/snapshots/codex_tui__bottom_pane__chat_composer__tests__footer_mode_overlay_then_external_esc_hint.snap +++ b/codex-rs/tui/src/bottom_pane/snapshots/codex_tui__bottom_pane__chat_composer__tests__footer_mode_overlay_then_external_esc_hint.snap @@ -10,4 +10,4 @@ expression: terminal.backend() " " " " " " -" esc again to edit previous message " +" esc again to edit previous message 100% context left " diff --git a/codex-rs/tui/src/bottom_pane/textarea.rs b/codex-rs/tui/src/bottom_pane/textarea.rs index d6fdbc5589..3dd3459c10 100644 --- a/codex-rs/tui/src/bottom_pane/textarea.rs +++ b/codex-rs/tui/src/bottom_pane/textarea.rs @@ -570,9 +570,10 @@ impl TextArea { fn handle_vim_normal(&mut self, event: KeyEvent) { if let Some(op) = self.vim_operator.take() - && self.handle_vim_operator(op, event) { - return; - } + && self.handle_vim_operator(op, event) + { + return; + } match event { KeyEvent {