From 1125331c6d8c38e24b87c72d6644827e56f17c75 Mon Sep 17 00:00:00 2001 From: Jussi Elo Date: Thu, 5 Nov 2026 10:57:19 +0000 Subject: [PATCH 1/5] test(dash-tui): pin the Esc menu's drawn rows, bounds and activation The Esc menu's item list is stated in three places that nothing but convention keeps in step: the wrap bound the key handling uses, the height the draw guard reserves, and the labels the draw routine paints. Pin what the menu does today before those are collapsed into one list: - the three rows drawn, in order, with the cursor only on the selected row, their column and their focus styling; - the smallest screen on which the menu is drawn at all (every item has to fit); - that the number of drawn rows equals the wrap bound; - that selection wraps in both directions over three rows and that each row runs its own action. No production code changes. Signed-off-by: Jussi Elo --- crates/rocm-dash-tui/src/app/actions.rs | 36 +++++++ crates/rocm-dash-tui/src/ui/menu.rs | 122 ++++++++++++++++++++++++ 2 files changed, 158 insertions(+) diff --git a/crates/rocm-dash-tui/src/app/actions.rs b/crates/rocm-dash-tui/src/app/actions.rs index efa84c5e6a..6f4d69a20e 100644 --- a/crates/rocm-dash-tui/src/app/actions.rs +++ b/crates/rocm-dash-tui/src/app/actions.rs @@ -1467,6 +1467,42 @@ mod tests { assert_eq!(s.options_tab, OPTIONS_TABS.len() - 1); } + #[test] + fn esc_menu_selection_wraps_over_its_three_rows_and_each_row_runs_its_own_action() { + let mut s = st(); + apply_action(&mut s, KeyAction::OpenMenu); + assert_eq!(s.menu_sel, 0, "the menu opens on its first row"); + // Up from the first row wraps to the last; down from the last wraps + // back to the first. + apply_action(&mut s, KeyAction::MenuMove(-1)); + assert_eq!(s.menu_sel, 2); + apply_action(&mut s, KeyAction::MenuMove(1)); + assert_eq!(s.menu_sel, 0); + // A full lap of down-presses visits every row once and comes back. + let mut lap = Vec::new(); + for _ in 0..3 { + apply_action(&mut s, KeyAction::MenuMove(1)); + lap.push(s.menu_sel); + } + assert_eq!(lap, [1, 2, 0]); + assert_eq!(s.modal, Modal::Menu, "moving never closes the menu"); + + // Row 0 opens Options on its first tab; row 1 opens the global help; + // row 2 is Quit, which exits at once when nothing is being served. + s.options_tab = 3; + s.menu_sel = 0; + assert!(!apply_action(&mut s, KeyAction::MenuActivate)); + assert_eq!(s.modal, Modal::Options); + assert_eq!(s.options_tab, 0); + s.modal = Modal::Menu; + s.menu_sel = 1; + assert!(!apply_action(&mut s, KeyAction::MenuActivate)); + assert_eq!(s.modal, Modal::GlobalHelp); + s.modal = Modal::Menu; + s.menu_sel = 2; + assert!(apply_action(&mut s, KeyAction::MenuActivate)); + } + #[test] fn palette_activation_switches_tab() { let mut s = st(); diff --git a/crates/rocm-dash-tui/src/ui/menu.rs b/crates/rocm-dash-tui/src/ui/menu.rs index 5afced580e..15a9a63895 100644 --- a/crates/rocm-dash-tui/src/ui/menu.rs +++ b/crates/rocm-dash-tui/src/ui/menu.rs @@ -299,6 +299,128 @@ mod tests { ); } + /// The text between the menu box's side borders, outer blanks trimmed. + fn inside(row: &str) -> &str { + row.trim().trim_matches('│').trim() + } + + /// Render `draw_menu` on a `w`x`h` screen with `sel` focused and return the + /// rows below the logo that carry menu text inside the box, as + /// `(screen row, text inside the borders)`. The bottom border does not + /// start with a side border, so it is excluded. + fn drawn_item_rows(w: u16, h: u16, sel: usize) -> Vec<(usize, String)> { + let theme = Theme::from_name("default-dark"); + let area = Rect::new(0, 0, w, h); + let rows = crate::ui::tests::rows(w, h, |f| super::draw_menu(f, area, sel, &theme)); + let logo_end = rows + .iter() + .rposition(|r| r.contains('█')) + .expect("the logo is drawn when the menu fits"); + rows.iter() + .enumerate() + .skip(logo_end + 1) + .filter(|(_, r)| r.trim_start().starts_with('│') && !inside(r).is_empty()) + .map(|(y, r)| (y, inside(r).to_string())) + .collect() + } + + #[test] + fn esc_menu_draws_options_help_quit_in_order_with_only_the_selected_row_marked() { + // Characterisation of the drawn rows: the same three labels in the same + // order, one "▸ " cursor on the selected row and a blank cursor column + // on the others. + for (sel, expected) in [ + (0usize, ["▸ Options", "Help", "Quit"]), + (1, ["Options", "▸ Help", "Quit"]), + (2, ["Options", "Help", "▸ Quit"]), + ] { + let drawn = drawn_item_rows(120, 30, sel); + let texts: Vec<&str> = drawn.iter().map(|(_, t)| t.as_str()).collect(); + assert_eq!(texts, expected, "rows drawn with sel={sel}"); + // The three items are on consecutive screen rows. + assert_eq!(drawn[1].0, drawn[0].0 + 1, "sel={sel}"); + assert_eq!(drawn[2].0, drawn[1].0 + 1, "sel={sel}"); + } + } + + #[test] + fn esc_menu_item_rows_sit_at_a_fixed_column_with_focus_styling() { + use ratatui::style::Modifier; + let theme = Theme::from_name("default-dark"); + let area = Rect::new(0, 0, 120, 30); + let mut term = Terminal::new(TestBackend::new(120, 30)).unwrap(); + term.draw(|f| super::draw_menu(f, area, 1, &theme)).unwrap(); + let rows = crate::ui::tests::rows(120, 30, |f| super::draw_menu(f, area, 1, &theme)); + let buf = term.backend().buffer(); + let y_of = |label: &str| -> u16 { + rows.iter() + .position(|r| inside(r) == label || inside(r) == format!("▸ {label}")) + .unwrap_or_else(|| panic!("no row for {label}")) as u16 + }; + // The box is 60 wide on a 120-column screen, so its left border is at + // x=30; the cursor column is 7 cells right of it and the label 2 more. + let (cursor_x, label_x) = (37u16, 39u16); + let help_y = y_of("Help"); + assert_eq!(buf[(cursor_x, help_y)].symbol(), "▸"); + assert_eq!(buf[(cursor_x, help_y)].style().fg, Some(theme.accent)); + assert_eq!(buf[(label_x, help_y)].symbol(), "H"); + assert_eq!(buf[(label_x, help_y)].style().fg, Some(theme.accent)); + assert!( + buf[(label_x, help_y)] + .style() + .add_modifier + .contains(Modifier::BOLD), + "the selected label is bold" + ); + for (label, first) in [("Options", "O"), ("Quit", "Q")] { + let y = y_of(label); + assert_eq!(buf[(label_x, y)].symbol(), first, "{label}"); + assert_eq!(buf[(label_x, y)].style().fg, Some(theme.fg), "{label}"); + assert!( + !buf[(label_x, y)] + .style() + .add_modifier + .contains(Modifier::BOLD), + "{label} is not bold when unselected" + ); + assert_eq!(buf[(cursor_x, y)].symbol(), " ", "{label} has no cursor"); + } + } + + #[test] + fn esc_menu_is_drawn_only_when_the_box_is_tall_enough_for_every_item() { + // End-to-end counterpart of `esc_menu_requires_room_for_all_items`: on + // a 120-column screen the box has 13 rows at height 19 (the logo would + // show but not every item) and 14 at height 20, the smallest screen on + // which Options, Help and Quit all fit. + let theme = Theme::from_name("default-dark"); + let render = |h: u16| { + let area = Rect::new(0, 0, 120, h); + crate::ui::tests::rows(120, h, |f| super::draw_menu(f, area, 0, &theme)).join("\n") + }; + let short = render(19); + assert!( + !short.contains('█') + && !short.contains("Options") + && !short.contains("Help") + && !short.contains("Quit"), + "height 19 must draw an empty frame:\n{short}" + ); + let just_fits = render(20); + assert!(just_fits.contains('█'), "logo at height 20"); + for label in ["Options", "Help", "Quit"] { + assert!(just_fits.contains(label), "{label} at height 20"); + } + } + + #[test] + fn esc_menu_draws_exactly_as_many_rows_as_the_selection_can_reach() { + // "How many items the menu has" is stated in the drawn rows here and + // in `MENU_ITEMS` (`app/types.rs`), the wrap bound of + // `KeyAction::MenuMove`. They must agree. + assert_eq!(drawn_item_rows(120, 30, 0).len(), crate::app::MENU_ITEMS); + } + #[test] fn draw_logo_paints_block_wordmark() { let theme = Theme::from_name("default-dark"); From e2f62f42e03fa8d642231ed2909c13b505a9b56d Mon Sep 17 00:00:00 2001 From: Jussi Elo Date: Thu, 5 Nov 2026 11:29:25 +0000 Subject: [PATCH 2/5] refactor(dash-tui): build the Esc menu from one list of items The Esc menu's item count was stated three times: `MENU_ITEMS` (the wrap bound of the key handling), `MENU_ITEM_COUNT` (the height the draw guard reserves) and the local label array in `draw_menu`, and the activation match restated the order a fourth time as bare indexes. Nothing but a doc comment kept them in step. `MENU_ITEMS` is now the one list, a slice of a new `MenuItem` enum that carries each row's label. The wrap bound is its length, `MENU_ITEM_COUNT` is derived from it, `draw_menu` iterates it, and the activation match is over `MenuItem`, so the compiler requires an arm for every row. No behaviour change: same three rows in the same order with the same labels, same wrap, same drawn output, and a selection past the last row still quits as the old `_` arm did (now pinned by a test). Signed-off-by: Jussi Elo --- crates/rocm-dash-tui/src/app/actions.rs | 28 +++++++++++++----- crates/rocm-dash-tui/src/app/mod.rs | 6 ++-- crates/rocm-dash-tui/src/app/types.rs | 33 ++++++++++++++++++++-- crates/rocm-dash-tui/src/ui/menu.rs | 30 ++++++++++++-------- docs/architecture.md | 2 +- tests/e2e-cucumber/tests/e2e/dash_steps.rs | 4 +-- 6 files changed, 76 insertions(+), 27 deletions(-) diff --git a/crates/rocm-dash-tui/src/app/actions.rs b/crates/rocm-dash-tui/src/app/actions.rs index 6f4d69a20e..2bccc48705 100644 --- a/crates/rocm-dash-tui/src/app/actions.rs +++ b/crates/rocm-dash-tui/src/app/actions.rs @@ -13,8 +13,8 @@ use crate::ui; use super::AppState; use super::summary::summarize_json_value; use super::types::{ - ActiveTab, ChatConsent, ChatKeyCtx, MENU_ITEMS, Modal, OPTIONS_TABS, PALETTE_DESTS, PaneFocus, - ScrollTarget, + ActiveTab, ChatConsent, ChatKeyCtx, MENU_ITEMS, MenuItem, Modal, OPTIONS_TABS, PALETTE_DESTS, + PaneFocus, ScrollTarget, }; #[cfg(test)] use super::types::{ChatProvider, ChatRole}; @@ -284,7 +284,7 @@ pub(crate) fn apply_action(state: &mut AppState, action: KeyAction) -> bool { } KeyAction::MenuMove(d) => match state.modal { Modal::Menu => { - state.menu_sel = wrap_cursor(state.menu_sel, d, MENU_ITEMS); + state.menu_sel = wrap_cursor(state.menu_sel, d, MENU_ITEMS.len()); } Modal::Palette => { state.palette_sel = wrap_cursor(state.palette_sel, d, PALETTE_DESTS.len()); @@ -297,12 +297,12 @@ pub(crate) fn apply_action(state: &mut AppState, action: KeyAction) -> bool { } } KeyAction::MenuActivate => match state.modal { - Modal::Menu => match state.menu_sel { - 0 => { + Modal::Menu => match MENU_ITEMS.get(state.menu_sel) { + Some(MenuItem::Options) => { state.modal = Modal::Options; state.options_tab = 0; } - 1 => { + Some(MenuItem::Help) => { state.modal = Modal::GlobalHelp; } // Issue #145: this must share `KeyAction::Quit`'s own gate — @@ -312,7 +312,10 @@ pub(crate) fn apply_action(state: &mut AppState, action: KeyAction) -> bool { // `open_quit_confirm` closes the Esc menu itself when a // prompt opens, so a decline doesn't strand the user back in // it (same as every other row here already does on success). - _ => return request_quit(state), + // A selection past the list (never set by `OpenMenu` or + // `MenuMove`, which keep it in range) still quits, as it did + // when this arm was the index fallback. + Some(MenuItem::Quit) | None => return request_quit(state), }, Modal::Palette => { if let Some((_, tab)) = PALETTE_DESTS.get(state.palette_sel) { @@ -1503,6 +1506,17 @@ mod tests { assert!(apply_action(&mut s, KeyAction::MenuActivate)); } + #[test] + fn esc_menu_selection_past_the_last_row_still_quits() { + // Nothing sets `menu_sel` out of range (`OpenMenu` resets it and + // `MenuMove` wraps it), but the activation match has always treated + // every index after Help as Quit; the list lookup keeps that. + let mut s = st(); + s.modal = Modal::Menu; + s.menu_sel = MENU_ITEMS.len() + 4; + assert!(apply_action(&mut s, KeyAction::MenuActivate)); + } + #[test] fn palette_activation_switches_tab() { let mut s = st(); diff --git a/crates/rocm-dash-tui/src/app/mod.rs b/crates/rocm-dash-tui/src/app/mod.rs index 4061e2cb35..9bbc7ef147 100644 --- a/crates/rocm-dash-tui/src/app/mod.rs +++ b/crates/rocm-dash-tui/src/app/mod.rs @@ -74,9 +74,9 @@ pub use scrollbar::{FooterChip, ScrollDrag, ScrollbarHandle}; #[cfg(test)] pub(crate) use terminal::restore_after_session; pub use types::{ - ActiveTab, ChatConsent, ChatKeyCtx, ChatRole, ChatTurn, ConnState, Focus, MENU_ITEMS, Modal, - OPTIONS_TABS, PALETTE_DESTS, PaneFocus, PlannedAction, ReplayState, ResolvedArgs, ScrollTarget, - UpdateStatus, format_mmss, + ActiveTab, ChatConsent, ChatKeyCtx, ChatRole, ChatTurn, ConnState, Focus, MENU_ITEMS, MenuItem, + Modal, OPTIONS_TABS, PALETTE_DESTS, PaneFocus, PlannedAction, ReplayState, ResolvedArgs, + ScrollTarget, UpdateStatus, format_mmss, }; pub(crate) use types::{ChatProvider, PendingApproval, SlashOutcome, SlashToolRequest}; diff --git a/crates/rocm-dash-tui/src/app/types.rs b/crates/rocm-dash-tui/src/app/types.rs index 7ffc341630..27fb3962ae 100644 --- a/crates/rocm-dash-tui/src/app/types.rs +++ b/crates/rocm-dash-tui/src/app/types.rs @@ -575,8 +575,37 @@ impl ScrollTarget { ]; } -/// Esc-menu rows: Options / Help / Quit. -pub const MENU_ITEMS: usize = 3; +/// One selectable row of the Esc main menu. +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum MenuItem { + Options, + Help, + Quit, +} + +impl MenuItem { + /// The text the menu draws for this row. + #[must_use] + pub const fn label(self) -> &'static str { + match self { + Self::Options => "Options", + Self::Help => "Help", + Self::Quit => "Quit", + } + } +} + +/// Esc-menu rows, top to bottom. +/// +/// The one list the menu is built from: the wrap bound of +/// `KeyAction::MenuMove` and the row an activation runs (`app/actions.rs`), +/// and the rows, labels and reserved height `draw_menu` paints +/// (`ui/menu.rs`), all read it. A new row is added here and gets an +/// arm in the `KeyAction::MenuActivate` match, which the compiler requires +/// for every `MenuItem`. A `MenuItem` left out of this list is not caught by +/// the compiler (stable Rust cannot check that without a derive macro this +/// crate doesn't depend on), the same limit as `ScrollTarget::ALL` above. +pub const MENU_ITEMS: &[MenuItem] = &[MenuItem::Options, MenuItem::Help, MenuItem::Quit]; /// Command-palette destinations (label, tab). pub const PALETTE_DESTS: &[(&str, ActiveTab)] = &[ diff --git a/crates/rocm-dash-tui/src/ui/menu.rs b/crates/rocm-dash-tui/src/ui/menu.rs index 15a9a63895..270f19e444 100644 --- a/crates/rocm-dash-tui/src/ui/menu.rs +++ b/crates/rocm-dash-tui/src/ui/menu.rs @@ -12,7 +12,7 @@ use ratatui::style::{Modifier, Style}; use ratatui::text::{Line, Span}; use ratatui::widgets::{Clear, Paragraph}; -use crate::app::{AppState, OPTIONS_TABS, PALETTE_DESTS}; +use crate::app::{AppState, MENU_ITEMS, OPTIONS_TABS, PALETTE_DESTS}; use crate::ui::panel::{self, BoxRole, centered_rect, draw_popup_frame, grey_overlay}; use crate::ui::theme::Theme; @@ -25,8 +25,9 @@ use crate::ui::theme::Theme; /// Row (relative to `inner.y`) where the Esc menu's selectable items begin, /// just below the 5-row logo (rows 1..=5). const MENU_ITEMS_Y: u16 = 8; -/// Number of selectable rows in the Esc menu (Options / Help / Quit). -const MENU_ITEM_COUNT: u16 = 3; +/// Number of selectable rows in the Esc menu, counted from the one list +/// ([`MENU_ITEMS`]) the key handling and the drawn rows also use. +const MENU_ITEM_COUNT: u16 = MENU_ITEMS.len() as u16; /// Minimum inner width the logo needs before the menu will render. const MENU_MIN_WIDTH: u16 = 31; @@ -54,9 +55,8 @@ pub fn draw_menu(f: &mut Frame, area: Rect, sel: usize, theme: &Theme) { let cx = inner.x + inner.width.saturating_sub(logo_w) / 2; draw_logo(f, cx, inner.y + 1, theme); - let items = ["Options", "Help", "Quit"]; let mx = inner.x + 4; - for (i, label) in items.iter().enumerate() { + for (i, item) in MENU_ITEMS.iter().enumerate() { let y = inner.y + MENU_ITEMS_Y + i as u16; if y >= inner.y + inner.height { break; @@ -75,7 +75,7 @@ pub fn draw_menu(f: &mut Frame, area: Rect, sel: usize, theme: &Theme) { f.render_widget( Paragraph::new(Line::from(vec![ Span::styled(cur, Style::default().fg(theme.accent)), - Span::styled(*label, st), + Span::styled(item.label(), st), ])), Rect::new(mx, y, inner.width.saturating_sub(4), 1), ); @@ -267,7 +267,7 @@ pub fn opt_row( #[cfg(test)] mod tests { - use super::{draw_logo, grey_overlay, opt_row}; + use super::{MENU_ITEMS, draw_logo, grey_overlay, opt_row}; use crate::ui::tests::flat; use crate::ui::theme::Theme; use ratatui::Terminal; @@ -414,11 +414,17 @@ mod tests { } #[test] - fn esc_menu_draws_exactly_as_many_rows_as_the_selection_can_reach() { - // "How many items the menu has" is stated in the drawn rows here and - // in `MENU_ITEMS` (`app/types.rs`), the wrap bound of - // `KeyAction::MenuMove`. They must agree. - assert_eq!(drawn_item_rows(120, 30, 0).len(), crate::app::MENU_ITEMS); + fn esc_menu_draws_the_rows_of_the_list_the_selection_walks() { + // The drawn rows and the wrap bound of `KeyAction::MenuMove` both come + // from `MENU_ITEMS` (`app/types.rs`), so what is drawn is exactly what + // the selection can reach, label for label. + let drawn = drawn_item_rows(120, 30, 0); + let drawn: Vec<&str> = drawn + .iter() + .map(|(_, t)| t.trim_start_matches("▸ ")) + .collect(); + let listed: Vec<&str> = MENU_ITEMS.iter().map(|i| i.label()).collect(); + assert_eq!(drawn, listed); } #[test] diff --git a/docs/architecture.md b/docs/architecture.md index edba1fc0ed..ed86486022 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -215,7 +215,7 @@ The old agent.rs was split (mechanical relocation — the shared seam types stay [`app/mod.rs`](../crates/rocm-dash-tui/src/app/mod.rs) is modularized (ROCMAI-84, Phase 4 of ROCMAI-27's sequencing) into an `app/` directory. [`app/types.rs`](../crates/rocm-dash-tui/src/app/types.rs), [`app/event_loop.rs`](../crates/rocm-dash-tui/src/app/event_loop.rs), [`app/scrollbar.rs`](../crates/rocm-dash-tui/src/app/scrollbar.rs), and [`app/actions.rs`](../crates/rocm-dash-tui/src/app/actions.rs) follow full domain extraction. [`app/chat.rs`](../crates/rocm-dash-tui/src/app/chat.rs), [`app/slash.rs`](../crates/rocm-dash-tui/src/app/slash.rs), and [`app/summary.rs`](../crates/rocm-dash-tui/src/app/summary.rs) were extracted earlier via mechanical relocation, the same convention the `agent/` split above follows. `quit_confirm`, `tool_approval`, `overlays`, `scroll` and `chat_state` each hold a further `impl AppState` block for one cohesive group of reducer methods: - [`app/mod.rs`](../crates/rocm-dash-tui/src/app/mod.rs) — keeps `AppState` and its constructor, the theme picker, row selection, the `apply_event` reducer entry point and the handful of items that stay with it (`ProviderSwitch`, `HISTORY_CAP`, `BENCH_CAP`); the rest of `AppState`'s methods live in the child-module `impl` blocks listed below (`apply_action` itself is a free function in [`app/actions.rs`](../crates/rocm-dash-tui/src/app/actions.rs)) — the modularization effort's "reducer's reason to exist." `crate::app::*` paths for the public surface moved out are unchanged via re-exports (see the re-export block's comment for what counts as "public surface"). -- [`app/types.rs`](../crates/rocm-dash-tui/src/app/types.rs) — shared type/enum defs: `Focus`, `ResolvedArgs`, connection/tab/chat/replay state, `Modal`, `UpdateStatus`, `PaneFocus`, `ScrollTarget`, the slash/plan/approval payload types, and the Esc-menu, command-palette and options-panel navigation data (`MENU_ITEMS`, `PALETTE_DESTS`, `OPTIONS_TABS`) that `app/actions.rs` reads, and that [`ui/menu.rs`](../crates/rocm-dash-tui/src/ui/menu.rs) renders (the palette destinations and options tabs; the Esc menu's own item count is a separate constant there); no `AppState` access. +- [`app/types.rs`](../crates/rocm-dash-tui/src/app/types.rs) — shared type/enum defs: `Focus`, `ResolvedArgs`, connection/tab/chat/replay state, `Modal`, `UpdateStatus`, `PaneFocus`, `ScrollTarget`, the slash/plan/approval payload types, and the Esc-menu, command-palette and options-panel navigation data (`MenuItem` and `MENU_ITEMS`, `PALETTE_DESTS`, `OPTIONS_TABS`) that `app/actions.rs` reads, and that [`ui/menu.rs`](../crates/rocm-dash-tui/src/ui/menu.rs) renders; the Esc menu's rows, their labels, the key handling's wrap bound and the height `draw_menu` reserves all come from the one `MENU_ITEMS` list; no `AppState` access. - [`app/event_loop.rs`](../crates/rocm-dash-tui/src/app/event_loop.rs) — the tick loop that drives the dashboard: `run`, `event_loop`, the frame-draw shutdown gate and the registry-probe seeding. - [`app/chat_runtime.rs`](../crates/rocm-dash-tui/src/app/chat_runtime.rs) — the live chat backend the tick loop owns, a leaf of `event_loop.rs`: `ChatRuntime` holds the agent the next submit is routed to plus the saved auto-detected local one that `/provider local` restores. `ChatRuntime::start` resolves the backend before the first frame, and `drain_provider_switch`, `drain_endpoint_rebuild` and `drain_dispatch` each consume one of `AppState`'s one-shot edges (`provider_switch`, `chat_endpoint_rebuild`, `chat_dispatch`). The detect and persist edges do not touch the backend and stay in `event_loop.rs`. - [`app/terminal.rs`](../crates/rocm-dash-tui/src/app/terminal.rs) — terminal restoration and shutdown arbitration, a leaf of `event_loop.rs`: `restore_terminal` and its writer lock, the `SHUTTING_DOWN` latch, the termination-signal watcher (`spawn_termination_watcher`; its `TerminationSignals` has a `cfg(unix)` and a `cfg(windows)` variant) and the Ctrl+C key path (`is_ctrl_c`, `exit_on_ctrl_c`). `app/mod.rs` re-exports the items the rest of the crate and `apps/rocm` use. diff --git a/tests/e2e-cucumber/tests/e2e/dash_steps.rs b/tests/e2e-cucumber/tests/e2e/dash_steps.rs index 1f87dc8581..0adff0282c 100644 --- a/tests/e2e-cucumber/tests/e2e/dash_steps.rs +++ b/tests/e2e-cucumber/tests/e2e/dash_steps.rs @@ -1964,8 +1964,8 @@ async fn dashboard_menu_is_displayed(world: &mut E2eWorld) { .unwrap_or_else(|e| panic!("dashboard menu did not appear: {e}")); } -/// Navigates `Modal::Menu`'s items (`["Options", "Help", "Quit"]`, -/// `ui/menu.rs`) down to "Quit" and activates it — `j` twice from the +/// Navigates `Modal::Menu`'s items (Options, Help, Quit: `MENU_ITEMS` in +/// the dash-TUI's `app/types.rs`) down to "Quit" and activates it — `j` twice from the /// default `menu_sel: 0`, then `Enter` (`KeyAction::MenuActivate`). Requires /// the menu to already be open (`the dashboard menu is displayed`). #[when("the user selects Quit from the dashboard menu")] From c509cead97ce54f59737ed0c7a787abbe7965287 Mon Sep 17 00:00:00 2001 From: Jussi Elo Date: Thu, 5 Nov 2026 15:03:57 +0000 Subject: [PATCH 3/5] fix(dash-tui): make an out-of-range Esc menu selection a no-op An out-of-range `menu_sel` used to share the Quit arm of the Esc menu's activation match, so it would request a quit. Nothing can set it out of range (`OpenMenu` resets it and `MenuMove` wraps it), so no user-visible behaviour changes. This deliberately tightens that unreachable state: the lookup miss now does nothing and leaves the menu open instead of taking the destructive path. The test is renamed to match and also asserts the menu stays open. Signed-off-by: Jussi Elo --- crates/rocm-dash-tui/src/app/actions.rs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/crates/rocm-dash-tui/src/app/actions.rs b/crates/rocm-dash-tui/src/app/actions.rs index 2bccc48705..4bd76526de 100644 --- a/crates/rocm-dash-tui/src/app/actions.rs +++ b/crates/rocm-dash-tui/src/app/actions.rs @@ -312,10 +312,10 @@ pub(crate) fn apply_action(state: &mut AppState, action: KeyAction) -> bool { // `open_quit_confirm` closes the Esc menu itself when a // prompt opens, so a decline doesn't strand the user back in // it (same as every other row here already does on success). - // A selection past the list (never set by `OpenMenu` or - // `MenuMove`, which keep it in range) still quits, as it did - // when this arm was the index fallback. - Some(MenuItem::Quit) | None => return request_quit(state), + Some(MenuItem::Quit) => return request_quit(state), + // Never set by `OpenMenu` or `MenuMove`, which keep the + // selection in range; do nothing rather than quit. + None => {} }, Modal::Palette => { if let Some((_, tab)) = PALETTE_DESTS.get(state.palette_sel) { @@ -1507,14 +1507,15 @@ mod tests { } #[test] - fn esc_menu_selection_past_the_last_row_still_quits() { + fn esc_menu_selection_past_the_last_row_does_nothing() { // Nothing sets `menu_sel` out of range (`OpenMenu` resets it and - // `MenuMove` wraps it), but the activation match has always treated - // every index after Help as Quit; the list lookup keeps that. + // `MenuMove` wraps it). If it ever were, activating must not take the + // destructive Quit path: no quit request, and the menu stays open. let mut s = st(); s.modal = Modal::Menu; s.menu_sel = MENU_ITEMS.len() + 4; - assert!(apply_action(&mut s, KeyAction::MenuActivate)); + assert!(!apply_action(&mut s, KeyAction::MenuActivate)); + assert_eq!(s.modal, Modal::Menu); } #[test] From 6e520033cc6736f7474e79e2ac5c41803a14829f Mon Sep 17 00:00:00 2001 From: Jussi Elo Date: Thu, 5 Nov 2026 15:08:41 +0000 Subject: [PATCH 4/5] test(dash-tui): render the Esc menu once and derive its column from the border The fixed-column test rendered draw_menu twice, once for the buffer and once for the row text, and hardcoded the cursor and label columns as absolute x=37/39, which baked in the popup's width. It now renders once, builds the row text from that same buffer, and finds the box's left border on the Help row so the columns are taken relative to it. Changing the popup's width no longer breaks the test; shifting the item column inside the box still does. Signed-off-by: Jussi Elo --- crates/rocm-dash-tui/src/ui/menu.rs | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/crates/rocm-dash-tui/src/ui/menu.rs b/crates/rocm-dash-tui/src/ui/menu.rs index 270f19e444..1c27d34840 100644 --- a/crates/rocm-dash-tui/src/ui/menu.rs +++ b/crates/rocm-dash-tui/src/ui/menu.rs @@ -350,17 +350,29 @@ mod tests { let area = Rect::new(0, 0, 120, 30); let mut term = Terminal::new(TestBackend::new(120, 30)).unwrap(); term.draw(|f| super::draw_menu(f, area, 1, &theme)).unwrap(); - let rows = crate::ui::tests::rows(120, 30, |f| super::draw_menu(f, area, 1, &theme)); + // One render: the row text and the cell styles both come from this buffer. let buf = term.backend().buffer(); + let rows: Vec = (0..buf.area.height) + .map(|y| { + (0..buf.area.width) + .map(|x| buf[(x, y)].symbol()) + .collect::() + }) + .collect(); let y_of = |label: &str| -> u16 { rows.iter() .position(|r| inside(r) == label || inside(r) == format!("▸ {label}")) .unwrap_or_else(|| panic!("no row for {label}")) as u16 }; - // The box is 60 wide on a 120-column screen, so its left border is at - // x=30; the cursor column is 7 cells right of it and the label 2 more. - let (cursor_x, label_x) = (37u16, 39u16); + // Locate the box's left border on the Help row instead of hardcoding + // where the popup sits, so a change to the popup's size does not + // break this test. The cursor column is 7 cells right of that border + // and the label 2 more. let help_y = y_of("Help"); + let border_x = (0..buf.area.width) + .find(|&x| buf[(x, help_y)].symbol() == "│") + .expect("the Help row starts inside a bordered box"); + let (cursor_x, label_x) = (border_x + 7, border_x + 9); assert_eq!(buf[(cursor_x, help_y)].symbol(), "▸"); assert_eq!(buf[(cursor_x, help_y)].style().fg, Some(theme.accent)); assert_eq!(buf[(label_x, help_y)].symbol(), "H"); From 1be71dbcfe49fcf698119013abaa855c3dbda844 Mon Sep 17 00:00:00 2001 From: Jussi Elo Date: Thu, 5 Nov 2026 15:08:54 +0000 Subject: [PATCH 5/5] test(dash-tui): pin the Esc menu's labels literally esc_menu_draws_the_rows_of_the_list_the_selection_walks compares the drawn rows with MenuItem::label(), so a wrong label appeared on both sides and could not fail it. Add a literal Options, Help, Quit assertion alongside. Signed-off-by: Jussi Elo --- crates/rocm-dash-tui/src/ui/menu.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/crates/rocm-dash-tui/src/ui/menu.rs b/crates/rocm-dash-tui/src/ui/menu.rs index 1c27d34840..74137a8b97 100644 --- a/crates/rocm-dash-tui/src/ui/menu.rs +++ b/crates/rocm-dash-tui/src/ui/menu.rs @@ -437,6 +437,8 @@ mod tests { .collect(); let listed: Vec<&str> = MENU_ITEMS.iter().map(|i| i.label()).collect(); assert_eq!(drawn, listed); + // `label()` is on both sides above, so pin the wording itself too. + assert_eq!(listed, ["Options", "Help", "Quit"]); } #[test]