Initial public release
Luxe 0.1.0: a coding agent harness for the terminal. See README.md to get started and CHANGELOG.md for releases.
This commit is contained in:
236
crates/luxe-tui/tests/render/activity.rs
Normal file
236
crates/luxe-tui/tests/render/activity.rs
Normal file
@@ -0,0 +1,236 @@
|
||||
//! Activity — live activity beside the conversation, the statusline, the clipboard and search.
|
||||
|
||||
use super::*;
|
||||
|
||||
/// The live activity indicator belongs to the conversation, not the sidebar: even beside a
|
||||
/// full-height dock it renders once, in the conversation column directly above the composer.
|
||||
#[test]
|
||||
fn live_activity_sits_below_the_conversation_even_beside_the_dock() {
|
||||
let (width, height) = (160, 40);
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = create_app();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
app.workspace = Some(empty_workspace("activity"));
|
||||
app.status.state = luxe_tui::app::AppState::Streaming;
|
||||
app.status.spinner_frame = 0;
|
||||
app.status.active_tool = Some("bash".into());
|
||||
app.status.on_turn_start();
|
||||
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
let content = buffer_to_string(&buffer);
|
||||
assert!(content.contains("PROJECT"), "the wide layout puts the dock beside the conversation");
|
||||
|
||||
let rows = (0..height)
|
||||
.filter(|&row| row_text(&buffer, row, width).contains(ACTIVITY_BAR_TRACK))
|
||||
.collect::<Vec<_>>();
|
||||
assert_eq!(rows.len(), 1, "exactly one activity indicator on screen, got rows {rows:?}");
|
||||
|
||||
// In the conversation column (right of the left rail), above the prompt box.
|
||||
let row = rows[0];
|
||||
let column =
|
||||
row_text(&buffer, row, width).find(ACTIVITY_BAR_TRACK).expect("the indicator") as u16;
|
||||
assert!(
|
||||
column > luxe_tui::workspace_layout::LEFT_RAIL_WIDTH,
|
||||
"the indicator is in the conversation column, not the sidebar: column {column}"
|
||||
);
|
||||
assert!(row < height - 1, "and above the prompt: row {row}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn composer_activity_shows_above_the_prompt_when_the_dock_is_hidden() {
|
||||
let (width, height) = (120, 32);
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = create_app();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
app.workspace = Some(empty_workspace("above-composer"));
|
||||
// Standard width keeps the dock hidden (auto), so activity rides above the composer instead.
|
||||
app.status.state = luxe_tui::app::AppState::Streaming;
|
||||
app.status.spinner_frame = 0;
|
||||
app.status.active_tool = Some("bash".into());
|
||||
app.status.on_turn_start();
|
||||
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
let content = buffer_to_string(&buffer);
|
||||
assert!(!content.contains("PROJECT"), "dock should be hidden at standard width: {content}");
|
||||
let activity_row = (0..height)
|
||||
.find(|&row| row_text(&buffer, row, width).contains(ACTIVITY_BAR_TRACK))
|
||||
.expect("activity row above the composer");
|
||||
// It sits above the composer/statusline, not on the bottom row.
|
||||
assert!(activity_row < height - 1, "activity should sit above the prompt: row {activity_row}");
|
||||
}
|
||||
|
||||
/// The indicator above the composer is a sweeping bar of units, not a glyph plus the word
|
||||
/// "working": the motion says "running", and only the two informative bits (elapsed, interrupt
|
||||
/// chord) follow it. The units are packed — the shaded comet is what gives the sweep its shape, and
|
||||
/// a separator between cells breaks the flow it draws.
|
||||
#[test]
|
||||
fn the_activity_indicator_is_a_sweeping_bar_with_elapsed_and_the_interrupt_chord() {
|
||||
let (width, height) = (120, 32);
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = create_app();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
app.status.state = luxe_tui::app::AppState::Streaming;
|
||||
app.status.on_turn_start();
|
||||
|
||||
let first = render_app(&mut app, &backend);
|
||||
let row = (0..height)
|
||||
.find(|&row| row_text(&first, row, width).contains(ACTIVITY_BAR_TRACK))
|
||||
.expect("the activity bar renders while a turn runs");
|
||||
let text = row_text(&first, row, width);
|
||||
assert!(!text.contains("working"), "the bar replaces the label: {text:?}");
|
||||
assert!(text.contains("to interrupt"), "the interrupt chord stays: {text:?}");
|
||||
assert!(text.contains("0.0s") || text.contains("s"), "elapsed stays: {text:?}");
|
||||
|
||||
let track = ACTIVITY_BAR_TRACK.chars().next().expect("one glyph");
|
||||
let bar_of =
|
||||
|row: &str| row.chars().filter(|g| ACTIVITY_BAR_GLYPHS.contains(g)).collect::<String>();
|
||||
assert_eq!(bar_of(&text).chars().count(), 24, "one glyph per cell, packed: {text:?}");
|
||||
assert!(!text.contains(&format!("{track} {track}")), "and no separator between them: {text:?}");
|
||||
|
||||
// The comet travels with the animation frame: two ticks per cell, so six ticks is three cells.
|
||||
// Compare the whole bar rather than its leading cell — late in a leg the head is already off the
|
||||
// rail while the tail drains, so the first lit cell can hold still while the comet moves.
|
||||
for _ in 0..6 {
|
||||
app.update(Msg::Tick);
|
||||
}
|
||||
let moved = row_text(&render_app(&mut app, &backend), row, width);
|
||||
assert_ne!(bar_of(&text), bar_of(&moved), "the comet must sweep: {text:?} then {moved:?}");
|
||||
|
||||
// Idle rows stay empty: the strip is the composer's breathing space when nothing is running.
|
||||
app.status.state = luxe_tui::app::AppState::Idle;
|
||||
let idle = row_text(&render_app(&mut app, &backend), row, width);
|
||||
assert!(!idle.contains(ACTIVITY_BAR_TRACK), "no bar when idle: {idle:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn standard_layout_shows_the_statusline_when_the_dock_is_hidden() {
|
||||
let (width, height) = (120, 32);
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = create_app();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
app.workspace = Some(empty_workspace("fallback"));
|
||||
app.push_convo(ConvoBlock::Assistant("chat stays primary".into()));
|
||||
|
||||
let content = buffer_to_string(&render_app(&mut app, &backend));
|
||||
// Auto dock is hidden below the wide threshold, so the compact statusline takes over.
|
||||
assert!(!content.contains("PROJECT"), "dock should be hidden on standard width: {content}");
|
||||
assert!(content.contains("chat stays primary"), "conversation should stay primary: {content}");
|
||||
// With the dock hidden, the project identity only appears on the compact statusline fallback.
|
||||
assert!(
|
||||
content.contains("luxe"),
|
||||
"statusline should be the compact fallback carrying the project: {content}"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hidden_statusline_bottom_aligns_the_composer() {
|
||||
let (width, height) = (160, 40);
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = create_app();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
app.workspace = Some(empty_workspace("bottom-align"));
|
||||
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
// Wide default hides the statusline, so the composer outline touches the final row inside the
|
||||
// main column (x = left-rail dock + 1-cell separator + 1-cell gutter).
|
||||
let composer_x = luxe_tui::workspace_layout::CONTEXT_DOCK_WIDTH
|
||||
+ luxe_tui::workspace_layout::CONTEXT_DOCK_SEPARATOR_WIDTH
|
||||
+ 1;
|
||||
assert_eq!(
|
||||
buffer[(composer_x, height - 1)].symbol(),
|
||||
"╰",
|
||||
"composer should bottom-align when the statusline is hidden: {}",
|
||||
buffer_to_string(&buffer)
|
||||
);
|
||||
}
|
||||
|
||||
/// Helper to convert a ratatui Buffer to a string for assertions.
|
||||
#[allow(deprecated)]
|
||||
pub(super) fn buffer_to_string(buffer: &Buffer) -> String {
|
||||
let mut content = String::new();
|
||||
for row in 0..buffer.area.height {
|
||||
for col in 0..buffer.area.width {
|
||||
let cell = buffer.get(col, row);
|
||||
content.push_str(cell.symbol());
|
||||
}
|
||||
content.push('\n');
|
||||
}
|
||||
content
|
||||
}
|
||||
|
||||
/// Clipboard: MockClipboard writes without error.
|
||||
#[tokio::test]
|
||||
async fn test_mock_clipboard_write() {
|
||||
let cb = luxe_tui::clipboard::MockClipboard;
|
||||
let result = cb.write_text("hello").await;
|
||||
assert!(result.is_ok());
|
||||
}
|
||||
|
||||
/// Search: entering search mode allows typing 'n' (which is the navigation key).
|
||||
#[test]
|
||||
fn test_search_allows_typing_n() {
|
||||
let (tx, _rx) = tokio::sync::mpsc::channel::<luxe_core::engine::Action>(64);
|
||||
let mut app = App::new(tx, KeyMap::defaults(), Config::default());
|
||||
// Enter search mode by setting the flag directly.
|
||||
app.search_state.searching = true;
|
||||
assert!(app.search_state.is_active());
|
||||
assert!(app.search_state.query.is_empty());
|
||||
// Simulate typing 'n'.
|
||||
let key = KeyEvent::new(KeyCode::Char('n'), KeyModifiers::NONE);
|
||||
let action = route_key(&mut app, &key);
|
||||
// Should NOT be a navigation action (query is empty).
|
||||
assert!(!matches!(action, RouteAction::SearchNavigate(_)));
|
||||
// Query should now contain 'n'.
|
||||
assert_eq!(app.search_state.query, "n");
|
||||
}
|
||||
|
||||
/// Search: Enter navigates to next match; 'n' types into query.
|
||||
#[test]
|
||||
fn test_search_enter_navigates() {
|
||||
let (tx, _rx) = tokio::sync::mpsc::channel::<luxe_core::engine::Action>(64);
|
||||
let mut app = App::new(tx, KeyMap::defaults(), Config::default());
|
||||
// Enter search mode and set a query.
|
||||
app.search_state.searching = true;
|
||||
app.search_state.query = "hello".to_string();
|
||||
assert_eq!(app.search_state.query, "hello");
|
||||
// Enter should navigate.
|
||||
let key = KeyEvent::new(KeyCode::Enter, KeyModifiers::NONE);
|
||||
let action = route_key(&mut app, &key);
|
||||
assert!(matches!(action, RouteAction::SearchNavigate(true)));
|
||||
}
|
||||
|
||||
/// Search: typing 'n' into query does NOT navigate (fixes reviewer finding #2).
|
||||
#[test]
|
||||
fn test_search_n_types_into_query() {
|
||||
let (tx, _rx) = tokio::sync::mpsc::channel::<luxe_core::engine::Action>(64);
|
||||
let mut app = App::new(tx, KeyMap::defaults(), Config::default());
|
||||
// Enter search mode and start typing "mai".
|
||||
app.search_state.searching = true;
|
||||
for c in "mai".chars() {
|
||||
let key = KeyEvent::new(KeyCode::Char(c), KeyModifiers::NONE);
|
||||
let _ = route_key(&mut app, &key);
|
||||
}
|
||||
assert_eq!(app.search_state.query, "mai");
|
||||
// Now 'n' should TYPE, not navigate.
|
||||
let key = KeyEvent::new(KeyCode::Char('n'), KeyModifiers::NONE);
|
||||
let action = route_key(&mut app, &key);
|
||||
assert!(!matches!(action, RouteAction::SearchNavigate(_)));
|
||||
assert_eq!(app.search_state.query, "main");
|
||||
}
|
||||
|
||||
/// Search: Up = prev match, Down = next match (spec: "Down/Up jump to next/prev").
|
||||
#[test]
|
||||
fn test_search_up_down_navigate() {
|
||||
let (tx, _rx) = tokio::sync::mpsc::channel::<luxe_core::engine::Action>(64);
|
||||
let mut app = App::new(tx, KeyMap::defaults(), Config::default());
|
||||
app.search_state.searching = true;
|
||||
app.search_state.query = "hello".to_string();
|
||||
// Up should navigate backward (prev).
|
||||
let key = KeyEvent::new(KeyCode::Up, KeyModifiers::NONE);
|
||||
let action = route_key(&mut app, &key);
|
||||
assert!(matches!(action, RouteAction::SearchNavigate(false)));
|
||||
// Down should navigate forward (next).
|
||||
let key = KeyEvent::new(KeyCode::Down, KeyModifiers::NONE);
|
||||
let action = route_key(&mut app, &key);
|
||||
assert!(matches!(action, RouteAction::SearchNavigate(true)));
|
||||
}
|
||||
222
crates/luxe-tui/tests/render/canvas.rs
Normal file
222
crates/luxe-tui/tests/render/canvas.rs
Normal file
@@ -0,0 +1,222 @@
|
||||
//! Canvas — theme colors, prose width and alignment, and the borderless conversation.
|
||||
|
||||
use super::*;
|
||||
|
||||
/// Test that theme styles actually influence rendered colors (P18 gate).
|
||||
#[test]
|
||||
fn test_theme_styles_affect_rendered_colors() {
|
||||
let tool = card_with_arguments("bash", "ls", serde_json::json!({"command": "ls"}));
|
||||
let convo = vec![
|
||||
ConvoBlock::User { text: "user".to_string(), attached: Vec::new(), chips: Vec::new() },
|
||||
ConvoBlock::Assistant("assistant".to_string()),
|
||||
ConvoBlock::Tool(Box::new(tool)),
|
||||
ConvoBlock::System("system".to_string()),
|
||||
];
|
||||
|
||||
let backend_a = test_backend(80, 24);
|
||||
let mut app_a = create_app_with_theme("dark");
|
||||
for block in &convo {
|
||||
app_a.push_convo(block.clone());
|
||||
}
|
||||
let buffer_a = render_app(&mut app_a, &backend_a);
|
||||
|
||||
let backend_b = test_backend(80, 24);
|
||||
let mut app_b = create_app_with_light_theme();
|
||||
for block in convo {
|
||||
app_b.push_convo(block);
|
||||
}
|
||||
let buffer_b = render_app(&mut app_b, &backend_b);
|
||||
|
||||
let buffers_differ = buffer_a
|
||||
.content
|
||||
.iter()
|
||||
.zip(buffer_b.content.iter())
|
||||
.any(|(a, b)| a.fg != b.fg || a.bg != b.bg);
|
||||
assert!(buffers_differ, "Dark and light themes should produce different rendered colors");
|
||||
assert_eq!(buffer_b[(0, 0)].bg, ratatui::style::Color::Rgb(0xef, 0xf1, 0xf5));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn light_theme_assistant_markdown_uses_the_configured_text_foreground() {
|
||||
let (width, height) = (80, 16);
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = create_app_with_light_theme();
|
||||
app.push_convo(ConvoBlock::Assistant("LIGHT_THEME_PROSE".into()));
|
||||
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
let (x, y) = marker_position(&buffer, "LIGHT_THEME_PROSE", width, height);
|
||||
assert_eq!(buffer[(x, y)].fg, ratatui::style::Color::Rgb(0x4c, 0x4f, 0x69));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn configured_prose_width_centers_assistant_markdown_without_narrowing_code() {
|
||||
let (width, height) = (200, 18);
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = create_app();
|
||||
app.config.conversation.prose_max_width = Some(72);
|
||||
app.config.conversation.alignment = Some(ConversationAlignment::Center);
|
||||
app.push_convo(ConvoBlock::Assistant(
|
||||
"CONFIGURED_PROSE\n\n```rust\nCONFIGURED_CODE\n```".to_string(),
|
||||
));
|
||||
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
assert_eq!(marker_position(&buffer, "CONFIGURED_PROSE", width, height).0, 62);
|
||||
assert_eq!(marker_position(&buffer, "CONFIGURED_CODE", width, height).0, 28);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn markdown_prose_and_code_use_distinct_conversation_canvases_when_centered() {
|
||||
// Centering splits the slack of the *padded* content region, so a capped block sits one cell
|
||||
// left of the band's own center; an uncapped one still hugs the gutter.
|
||||
for (width, prose_x, wide_x) in [(200, 38, 28), (140, 8, 1), (78, 1, 1)] {
|
||||
let backend = test_backend(width, 18);
|
||||
let mut app = create_app();
|
||||
app.config.conversation.alignment = Some(ConversationAlignment::Center);
|
||||
app.push_convo(ConvoBlock::Assistant(
|
||||
"PROSE_CANVAS\n\n```rust\nWIDE_CANVAS\n```".to_string(),
|
||||
));
|
||||
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
let prose = marker_position(&buffer, "PROSE_CANVAS", width, 18);
|
||||
let wide = marker_position(&buffer, "WIDE_CANVAS", width, 18);
|
||||
assert_eq!(prose.0, prose_x, "prose x at width {width}");
|
||||
assert_eq!(wide.0, wide_x, "wide x at width {width}");
|
||||
assert_eq!(buffer[(width - 1, prose.1)].symbol(), " ");
|
||||
assert_eq!(buffer[(width - 1, wide.1)].symbol(), " ");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn default_full_alignment_fills_the_width_from_the_left_gutter() {
|
||||
// The default policy fills the pane: prose and code share the left gutter and neither is
|
||||
// capped, so a wide terminal isn't left mostly empty.
|
||||
let width = 200;
|
||||
let backend = test_backend(width, 18);
|
||||
let mut app = create_app();
|
||||
app.push_convo(ConvoBlock::Assistant("PROSE_CANVAS\n\n```rust\nWIDE_CANVAS\n```".to_string()));
|
||||
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
let prose = marker_position(&buffer, "PROSE_CANVAS", width, 18);
|
||||
let wide = marker_position(&buffer, "WIDE_CANVAS", width, 18);
|
||||
assert_eq!(prose.0, wide.0, "prose and code share the left edge");
|
||||
assert!(prose.0 <= 2, "content hugs the left gutter, got x={}", prose.0);
|
||||
|
||||
// And `left` remains available for anyone who wants the readable caps back.
|
||||
let mut capped = create_app_with_config(Config {
|
||||
conversation: luxe_core::config::ConversationConfig {
|
||||
alignment: Some(ConversationAlignment::Left),
|
||||
..Default::default()
|
||||
},
|
||||
..Default::default()
|
||||
});
|
||||
capped.push_convo(ConvoBlock::Assistant("PROSE_CANVAS".to_string()));
|
||||
let buffer = render_app(&mut capped, &backend);
|
||||
assert!(marker_position(&buffer, "PROSE_CANVAS", width, 18).0 <= 2);
|
||||
}
|
||||
|
||||
/// Text used to run flush into the right edge of a band: the canvas wrapped to the band's full
|
||||
/// width, so a hard-wrapped row's last character landed on the band's last cell.
|
||||
#[test]
|
||||
fn banded_blocks_keep_a_cell_of_padding_at_both_edges() {
|
||||
let (width, height) = (60u16, 24u16);
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = create_app();
|
||||
// Unbroken tokens, so every row but the last is filled to the wrap limit exactly — word wrap
|
||||
// would leave a ragged edge and prove nothing.
|
||||
app.push_convo(ConvoBlock::User {
|
||||
text: "u".repeat(180),
|
||||
attached: Vec::new(),
|
||||
chips: Vec::new(),
|
||||
});
|
||||
let mut activity = ToolActivity::running("session-a", "call-a", "bash", "b".repeat(140), 1);
|
||||
activity.state = ToolActivityState::Succeeded;
|
||||
activity.elapsed_ms = Some(1_240);
|
||||
app.push_convo(ConvoBlock::Tool(Box::new(ToolItem {
|
||||
activity,
|
||||
expanded: false,
|
||||
details_toggled: false,
|
||||
waited_on_user_ms: 0,
|
||||
})));
|
||||
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
let bands = [
|
||||
app.theme_styles.user_msg_bg.bg.expect("a user band color"),
|
||||
app.theme_styles.tool_call_success_bg.bg.expect("a tool band color"),
|
||||
];
|
||||
let mut filled_rows = 0;
|
||||
for y in 0..height {
|
||||
let Some(right_edge) = (0..width).rev().find(|&x| bands.contains(&buffer[(x, y)].bg))
|
||||
else {
|
||||
continue;
|
||||
};
|
||||
let Some(left_edge) = (0..width).find(|&x| bands.contains(&buffer[(x, y)].bg)) else {
|
||||
continue;
|
||||
};
|
||||
let Some(last_text) =
|
||||
(left_edge..=right_edge).rev().find(|&x| buffer[(x, y)].symbol() != " ")
|
||||
else {
|
||||
continue; // the band's own blank pad row, above and below the text
|
||||
};
|
||||
assert!(
|
||||
last_text < right_edge,
|
||||
"row {y} runs flush into the band's right edge at x={right_edge}"
|
||||
);
|
||||
assert!(
|
||||
buffer[(left_edge, y)].symbol() == " ",
|
||||
"row {y} runs flush into the band's left edge at x={left_edge}"
|
||||
);
|
||||
if last_text + 1 == right_edge {
|
||||
filled_rows += 1;
|
||||
}
|
||||
}
|
||||
assert!(filled_rows >= 2, "the fixture must actually fill rows to the wrap limit");
|
||||
}
|
||||
|
||||
pub(super) fn marker_position(
|
||||
buffer: &Buffer,
|
||||
marker: &str,
|
||||
width: u16,
|
||||
height: u16,
|
||||
) -> (u16, u16) {
|
||||
for y in 0..height {
|
||||
if let Some(x) = row_text(buffer, y, width).find(marker) {
|
||||
return (x as u16, y);
|
||||
}
|
||||
}
|
||||
panic!("missing marker {marker:?}");
|
||||
}
|
||||
|
||||
/// Helper: dump a buffer row into a String of cell.symbol()s.
|
||||
pub(super) fn row_text(buffer: &Buffer, y: u16, width: u16) -> String {
|
||||
(0..width).map(|x| buffer[(x, y)].symbol()).collect()
|
||||
}
|
||||
|
||||
/// A long conversation stays virtualized without reintroducing a frame.
|
||||
#[test]
|
||||
fn test_conversation_is_borderless_and_separate_from_composer() {
|
||||
let (w, h) = (40u16, 8u16);
|
||||
let backend = test_backend(w, h);
|
||||
let mut app = create_app();
|
||||
app.status.model = "gpt-4o".into();
|
||||
for i in 0..30 {
|
||||
app.push_convo(ConvoBlock::Assistant(format!("line number {i}")));
|
||||
}
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
|
||||
// Virtualized window follows the bottom, so the newest line is visible (exact top row depends
|
||||
// on inter-message spacing).
|
||||
let full = (0..h).map(|y| row_text(&buffer, y, w)).collect::<Vec<_>>().join("\n");
|
||||
assert!(full.contains("line number 29"), "latest conversation window missing: {full:?}");
|
||||
let top = row_text(&buffer, 0, w);
|
||||
assert_eq!(buffer[(0, 0)].symbol(), " ", "conversation should have no left border");
|
||||
assert!(!top.contains("Conversation"));
|
||||
|
||||
assert!(row_text(&buffer, h - 4, w).trim_start().starts_with('╭'), "composer outline missing");
|
||||
assert!(row_text(&buffer, h - 5, w).trim().is_empty(), "conversation gap missing");
|
||||
assert!(
|
||||
row_text(&buffer, h - 2, w).trim_start().starts_with('╰'),
|
||||
"composer should touch statusline"
|
||||
);
|
||||
// The flat bar carries the model on its bottom row (mode label is gone).
|
||||
assert!(row_text(&buffer, h - 1, w).contains("gpt-4o"));
|
||||
}
|
||||
534
crates/luxe-tui/tests/render/cards.rs
Normal file
534
crates/luxe-tui/tests/render/cards.rs
Normal file
@@ -0,0 +1,534 @@
|
||||
//! Cards — tool cards, their diffs and what a rejected edit says.
|
||||
|
||||
use super::*;
|
||||
|
||||
/// Tool cards read as a sentence, not a payload, and edit results render as a line-numbered diff
|
||||
/// with elision instead of `@@` hunk headers.
|
||||
#[test]
|
||||
fn tool_cards_show_human_labels_and_line_numbered_diffs() {
|
||||
let (width, height) = (100, 24);
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = create_app();
|
||||
|
||||
// A tool with no path/command/query key used to fall back to its raw argument JSON.
|
||||
let arguments = serde_json::json!({"action": "add", "subject": "wire the dock"});
|
||||
let label = luxe_core::describe_call("todo", &arguments, "/project");
|
||||
let mut todo = ToolActivity::running("session-a", "call-todo", "todo", label, 1);
|
||||
todo.state = ToolActivityState::Succeeded;
|
||||
todo.summary = Some("Completed".into());
|
||||
app.push_convo(ConvoBlock::Tool(Box::new(ToolItem {
|
||||
activity: todo,
|
||||
expanded: false,
|
||||
details_toggled: false,
|
||||
waited_on_user_ms: 0,
|
||||
})));
|
||||
|
||||
let mut edit = ToolActivity::running("session-a", "call-edit", "edit", "src/lib.rs", 1);
|
||||
edit.state = ToolActivityState::Succeeded;
|
||||
edit.summary = Some("Completed".into());
|
||||
edit.output_preview = Some(
|
||||
"Applied 1 edit(s) to 'src/lib.rs'\n ...\n 11 fn main() {\n-12 old();\n+12 new();\n 13 }\n ..."
|
||||
.into(),
|
||||
);
|
||||
app.push_convo(ConvoBlock::Tool(Box::new(ToolItem {
|
||||
activity: edit,
|
||||
expanded: false,
|
||||
details_toggled: false,
|
||||
waited_on_user_ms: 0,
|
||||
})));
|
||||
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
let content = buffer_to_string(&buffer);
|
||||
assert!(content.contains("add · wire the dock"), "human tool label: {content}");
|
||||
assert!(!content.contains("\"action\""), "no raw argument JSON: {content}");
|
||||
assert!(!content.contains("@@"), "no unified hunk headers on the card: {content}");
|
||||
assert!(content.contains("-12"), "removed line carries its number: {content}");
|
||||
assert!(content.contains("+12"), "added line carries its number: {content}");
|
||||
assert!(content.contains('⋯'), "elided context is marked: {content}");
|
||||
assert!(!content.contains("Completed"), "a green card already says it completed: {content}");
|
||||
assert!(
|
||||
!content.contains("Applied 1 edit"),
|
||||
"the header already names the file it edited: {content}"
|
||||
);
|
||||
}
|
||||
|
||||
/// Builds a succeeded card for `tool`, with a body taken from the call's arguments the way the live
|
||||
/// projection does.
|
||||
pub(super) fn card_with_arguments(
|
||||
tool: &str,
|
||||
label: &str,
|
||||
arguments: serde_json::Value,
|
||||
) -> ToolItem {
|
||||
let mut activity = ToolActivity::running("session-a", "call-a", tool, label, 1);
|
||||
activity.state = ToolActivityState::Succeeded;
|
||||
activity.summary = Some("Completed".into());
|
||||
activity.card_body = luxe_core::tool_card_body(tool, &arguments, "/project");
|
||||
ToolItem { activity, expanded: false, details_toggled: false, waited_on_user_ms: 0 }
|
||||
}
|
||||
|
||||
/// A `write` shows the file it wrote, highlighted as that language, and accounts for what it hid.
|
||||
///
|
||||
/// It used to render the tool's *result* — a wall of green `+` rows capped at the model's token
|
||||
/// budget, with no language to highlight and no honest count of what was cut.
|
||||
#[test]
|
||||
fn a_write_card_shows_its_content_and_admits_what_it_hid() {
|
||||
let backend = test_backend(100, 40);
|
||||
let mut app = create_app();
|
||||
let content = (1..=30).map(|n| format!("let value_{n} = {n};")).collect::<Vec<_>>().join("\n");
|
||||
let mut card = card_with_arguments(
|
||||
"write",
|
||||
"src/generated.rs",
|
||||
serde_json::json!({"path": "src/generated.rs", "content": content}),
|
||||
);
|
||||
card.activity.output_preview = Some("Created 'src/generated.rs' (620 bytes)".into());
|
||||
app.push_convo(ConvoBlock::Tool(Box::new(card)));
|
||||
|
||||
let rendered = buffer_to_string(&render_app(&mut app, &backend));
|
||||
assert!(rendered.contains("write src/generated.rs"), "{rendered}");
|
||||
assert!(rendered.contains("Created · 620 B"), "the header says what it did: {rendered}");
|
||||
assert!(rendered.contains("1 let value_1 = 1;"), "content is numbered, not signed: {rendered}");
|
||||
assert!(!rendered.contains("+1 let value_1"), "a write is not a wall of additions: {rendered}");
|
||||
assert!(
|
||||
rendered.contains("20 more lines · 30 total · click or ctrl+o to expand"),
|
||||
"the footer accounts for the rest and names both ways in: {rendered}"
|
||||
);
|
||||
assert!(!rendered.contains("let value_11"), "the eleventh line is past the budget: {rendered}");
|
||||
}
|
||||
|
||||
/// Ctrl+O opens every truncated card at once, and closes them again.
|
||||
#[test]
|
||||
fn toggling_tool_output_expands_every_card() {
|
||||
let backend = test_backend(100, 60);
|
||||
let mut app = create_app();
|
||||
let content = (1..=20).map(|n| format!("line {n}")).collect::<Vec<_>>().join("\n");
|
||||
app.push_convo(ConvoBlock::Tool(Box::new(card_with_arguments(
|
||||
"write",
|
||||
"notes.txt",
|
||||
serde_json::json!({"path": "notes.txt", "content": content}),
|
||||
))));
|
||||
|
||||
let collapsed = buffer_to_string(&render_app(&mut app, &backend));
|
||||
assert!(collapsed.contains("10 more lines · 20 total"), "{collapsed}");
|
||||
assert!(!collapsed.contains("line 20"));
|
||||
|
||||
app.update(Msg::Key(KeyEvent::new(KeyCode::Char('o'), KeyModifiers::CONTROL)));
|
||||
let expanded = buffer_to_string(&render_app(&mut app, &backend));
|
||||
assert!(expanded.contains("line 20"), "ctrl+o opened the card: {expanded}");
|
||||
assert!(!expanded.contains("more lines"), "nothing left to account for: {expanded}");
|
||||
|
||||
app.update(Msg::Key(KeyEvent::new(KeyCode::Char('o'), KeyModifiers::CONTROL)));
|
||||
let recollapsed = buffer_to_string(&render_app(&mut app, &backend));
|
||||
assert!(recollapsed.contains("10 more lines · 20 total"), "and closed it again: {recollapsed}");
|
||||
}
|
||||
|
||||
/// A multi-line `bash` command is shown in full, and the header stops trying to preview it.
|
||||
#[test]
|
||||
fn a_multiline_command_is_shown_under_its_card() {
|
||||
let backend = test_backend(100, 30);
|
||||
let mut app = create_app();
|
||||
let command = "cd /tmp && python3 - <<'PY'\nimport json\nprint(json.dumps({'ok': True}))\nPY";
|
||||
app.push_convo(ConvoBlock::Tool(Box::new(card_with_arguments(
|
||||
"bash",
|
||||
&luxe_core::describe_call("bash", &serde_json::json!({"command": command}), "/project"),
|
||||
serde_json::json!({"command": command}),
|
||||
))));
|
||||
|
||||
let rendered = buffer_to_string(&render_app(&mut app, &backend));
|
||||
assert!(rendered.contains("print(json.dumps"), "the heredoc is no longer hidden: {rendered}");
|
||||
assert!(
|
||||
!rendered.contains("cd /tmp && python3 - <<'PY' …"),
|
||||
"the header's ellipsized peek would sit directly above the real thing: {rendered}"
|
||||
);
|
||||
assert!(rendered.contains("cd /tmp && python3 - <<'PY'"), "which the body draws: {rendered}");
|
||||
// A command is not a file, so it gets no line-number gutter.
|
||||
assert!(!rendered.contains("2 import json"), "{rendered}");
|
||||
|
||||
// A one-liner says everything on its header already.
|
||||
let mut single = create_app();
|
||||
single.push_convo(ConvoBlock::Tool(Box::new(card_with_arguments(
|
||||
"bash",
|
||||
"cargo build",
|
||||
serde_json::json!({"command": "cargo build"}),
|
||||
))));
|
||||
let one_line = buffer_to_string(&render_app(&mut single, &backend));
|
||||
assert_eq!(one_line.matches("cargo build").count(), 1, "said once, not twice: {one_line}");
|
||||
}
|
||||
|
||||
/// A `cd` into the directory the shell already starts in never reaches the card.
|
||||
///
|
||||
/// Most of what a model writes opens with one, and on a real project path it is fifty characters of
|
||||
/// nothing in front of the command the reader came for — wide enough on a narrow card to push the
|
||||
/// command off the end of the line. The sibling above proves the other half: a `cd` that actually
|
||||
/// goes somewhere is kept.
|
||||
#[test]
|
||||
fn a_card_drops_a_cd_into_the_directory_the_command_already_ran_in() {
|
||||
let backend = test_backend(100, 30);
|
||||
let root = "/home/dev/project";
|
||||
let command = format!("cd {root} && cargo build --workspace");
|
||||
|
||||
let mut app = create_app();
|
||||
app.push_convo(ConvoBlock::Tool(Box::new(card_with_arguments(
|
||||
"bash",
|
||||
&luxe_core::describe_call("bash", &serde_json::json!({ "command": command }), root),
|
||||
serde_json::json!({ "command": command }),
|
||||
))));
|
||||
|
||||
let rendered = buffer_to_string(&render_app(&mut app, &backend));
|
||||
assert!(rendered.contains("cargo build --workspace"), "the command survives: {rendered}");
|
||||
assert!(!rendered.contains("cd "), "and the no-op does not: {rendered}");
|
||||
}
|
||||
|
||||
/// A wide card draws its diff side by side; a narrow one stacks. Same rows, same numbers.
|
||||
#[test]
|
||||
fn a_card_diff_splits_when_wide_and_stacks_when_narrow() {
|
||||
let preview = "Applied 1 edit(s) to 'src/lib.rs'\n ...\n 11 fn main() {\n\
|
||||
-12 let label: String = category.to_string();\n\
|
||||
+12 let label = category.display_name();\n 13 }";
|
||||
let card = |width: u16| {
|
||||
let mut app = create_app();
|
||||
let mut edit = ToolActivity::running("session-a", "call-edit", "edit", "src/lib.rs", 1);
|
||||
edit.state = ToolActivityState::Succeeded;
|
||||
edit.output_preview = Some(preview.into());
|
||||
app.push_convo(ConvoBlock::Tool(Box::new(ToolItem {
|
||||
activity: edit,
|
||||
expanded: false,
|
||||
details_toggled: false,
|
||||
waited_on_user_ms: 0,
|
||||
})));
|
||||
buffer_to_string(&render_app(&mut app, &test_backend(width, 24)))
|
||||
};
|
||||
|
||||
// 197 columns is a full-screen terminal; the rule puts old beside new on one row.
|
||||
let wide = card(197);
|
||||
let paired =
|
||||
wide.lines().find(|line| line.contains("category.to_string")).expect("the replacement row");
|
||||
assert!(paired.contains('│'), "a rule divides the columns: {paired:?}");
|
||||
assert!(
|
||||
paired.contains("category.display_name"),
|
||||
"old and new share one row when wide: {paired:?}"
|
||||
);
|
||||
|
||||
// At 100 columns each side would hold half a line of Rust, so it stacks instead.
|
||||
let narrow = card(100);
|
||||
let removed =
|
||||
narrow.lines().find(|line| line.contains("category.to_string")).expect("the removal");
|
||||
assert!(!removed.contains("display_name"), "a narrow card stacks: {removed:?}");
|
||||
assert!(narrow.contains("-12") && narrow.contains("+12"), "both rows are there: {narrow}");
|
||||
}
|
||||
|
||||
/// A tab-indented file draws on the same columns as a space-indented one, down to the buffer.
|
||||
///
|
||||
/// `unicode-width` scores a tab nothing and the terminal advances it to a stop, so a card that let
|
||||
/// one through laid its columns out against a width the screen did not agree with. The rule stepped
|
||||
/// right once per level of indentation, and the surplus pushed the row past the card — where the
|
||||
/// transcript's word wrap broke it at a space, dropped the leading padding, and stranded the tail at
|
||||
/// the left margin: an addition drawn inside the column reserved for removals, with no gutter and no
|
||||
/// continuation marker to say what it was.
|
||||
///
|
||||
/// Through the real render path, because that is where the two measurements meet: the card lays a
|
||||
/// row out, and the transcript wraps whatever the card handed it.
|
||||
#[test]
|
||||
fn a_tab_indented_card_diff_draws_on_the_columns_it_was_laid_out_for() {
|
||||
// Svelte markup, tab-indented the way prettier writes it. Every tab starts on a stop, so the
|
||||
// space-indented twin below is the same file once the tabs are spent.
|
||||
const TABBED: &str = concat!(
|
||||
"Applied 1 edit(s) to 'TopbarProfileMenu.svelte'\n",
|
||||
" 415 \t\t\t<GettingStartedChecklist onCloseDrawer={closeDrawer} />\n",
|
||||
" 416 \t\t\t</div>\n",
|
||||
"-417 \t\t\t<!-- Tour launcher (desktop only, mobile needs its own tour) -->\n",
|
||||
"-418 \t\t\t<div class=\"shrink-0 px-2.5 pb-1 max-sm:hidden\">\n",
|
||||
"-419 \t\t\t\t<button type=\"button\" onclick={() => tourStore.startTour()}>\n",
|
||||
"+417 \t\t\t<!-- Tour launcher (desktop only, mobile needs its own tour). -->\n",
|
||||
"+418 \t\t\t<!-- Hidden while tourStore.isEnabled is false (see tour-store.svelte.ts). -->\n",
|
||||
"+419 \t\t\t{#if tourStore.isEnabled}",
|
||||
);
|
||||
|
||||
let card = |preview: &str| {
|
||||
let mut app = create_app();
|
||||
let mut edit =
|
||||
ToolActivity::running("session-a", "call-edit", "edit", "TopbarProfileMenu.svelte", 1);
|
||||
edit.state = ToolActivityState::Succeeded;
|
||||
edit.output_preview = Some(preview.to_string());
|
||||
app.push_convo(ConvoBlock::Tool(Box::new(ToolItem {
|
||||
activity: edit,
|
||||
expanded: true,
|
||||
details_toggled: false,
|
||||
waited_on_user_ms: 0,
|
||||
})));
|
||||
buffer_to_string(&render_app(&mut app, &test_backend(180, 30)))
|
||||
};
|
||||
|
||||
let tabbed = card(TABBED);
|
||||
assert_eq!(tabbed, card(&TABBED.replace('\t', " ")), "a tab is four cells or it is a bug");
|
||||
|
||||
// The card body: everything under the header, down to the blank line that ends the block.
|
||||
let rows: Vec<&str> = tabbed.lines().collect();
|
||||
let header = rows
|
||||
.iter()
|
||||
.position(|row| row.contains("TopbarProfileMenu.svelte"))
|
||||
.expect("the card header");
|
||||
let body: Vec<&str> =
|
||||
rows[header + 1..].iter().copied().take_while(|row| !row.trim().is_empty()).collect();
|
||||
assert!(body.len() >= 5, "the diff drew its rows: {tabbed}");
|
||||
|
||||
// Every row of a side-by-side body carries the rule, wrapped rows included — both columns are
|
||||
// padded so it cannot be otherwise. A row without one is a row the transcript re-wrapped, which
|
||||
// is the tail of one column left sitting at the margin in front of the other.
|
||||
for row in &body {
|
||||
assert!(row.contains('\u{2502}'), "a row escaped its column: {row:?}");
|
||||
}
|
||||
let columns: std::collections::HashSet<u16> =
|
||||
body.iter().map(|row| column_of(row, "\u{2502}")).collect();
|
||||
assert_eq!(columns.len(), 1, "the rule stepped with the indentation: {columns:?}");
|
||||
}
|
||||
|
||||
/// `unified` is a real override: a wide card honors it.
|
||||
#[test]
|
||||
fn the_unified_preference_survives_a_wide_card() {
|
||||
let config = Config {
|
||||
diff: luxe_core::config::DiffConfig {
|
||||
layout: Some(luxe_core::config::DiffLayout::Unified),
|
||||
..Default::default()
|
||||
},
|
||||
..Default::default()
|
||||
};
|
||||
let mut app = create_app_with_config(config);
|
||||
let mut edit = ToolActivity::running("session-a", "call-edit", "edit", "src/lib.rs", 1);
|
||||
edit.state = ToolActivityState::Succeeded;
|
||||
edit.output_preview = Some(" 11 fn main() {\n-12 old();\n+12 new();\n 13 }".into());
|
||||
app.push_convo(ConvoBlock::Tool(Box::new(ToolItem {
|
||||
activity: edit,
|
||||
expanded: false,
|
||||
details_toggled: false,
|
||||
waited_on_user_ms: 0,
|
||||
})));
|
||||
|
||||
let rendered = buffer_to_string(&render_app(&mut app, &test_backend(197, 24)));
|
||||
let removed = rendered.lines().find(|line| line.contains("old();")).expect("the removal");
|
||||
assert!(!removed.contains("new();"), "unified means unified, even at 197 columns: {removed:?}");
|
||||
}
|
||||
|
||||
/// The footer advertises expansion, so the advertised path has to work: select a card, open it.
|
||||
///
|
||||
/// Goes through the production event, because a card's identity comes from the activity projection —
|
||||
/// and per-card expansion keys off exactly that identity.
|
||||
#[test]
|
||||
fn selecting_a_card_by_keyboard_and_opening_it_works() {
|
||||
let backend = test_backend(100, 40);
|
||||
let mut app = create_app();
|
||||
app.update(Msg::Engine(luxe_core::event::Event::SessionLoaded {
|
||||
session_id: "session-a".into(),
|
||||
messages: Vec::new(),
|
||||
}));
|
||||
let content = (1..=20).map(|n| format!("line {n}")).collect::<Vec<_>>().join("\n");
|
||||
let card = card_with_arguments(
|
||||
"write",
|
||||
"notes.txt",
|
||||
serde_json::json!({"path": "notes.txt", "content": content}),
|
||||
);
|
||||
app.update(Msg::Engine(luxe_core::event::Event::ToolActivityUpdated(Box::new(card.activity))));
|
||||
|
||||
// Alt+K was bound to "select block up" and dispatched by nobody, so this was unreachable.
|
||||
app.update(Msg::Key(KeyEvent::new(KeyCode::Char('k'), KeyModifiers::ALT)));
|
||||
assert_eq!(app.selected_block, Some(0), "the card is selected");
|
||||
|
||||
// A selected card is still a card: the band it is drawn in survives the highlight, which is
|
||||
// what tells a reader it is a tool call at all.
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
let selected_bg = app.theme_styles.selected_bg.bg.expect("a selection background");
|
||||
let header = (0..40)
|
||||
.find(|&y| row_text(&buffer, y, 100).contains("write notes.txt"))
|
||||
.expect("the card header renders");
|
||||
assert_eq!(buffer[(2, header)].bg, selected_bg, "the band takes the selection tint");
|
||||
assert_eq!(
|
||||
buffer[(90, header)].bg,
|
||||
selected_bg,
|
||||
"and still runs the full width of the card, inset and all"
|
||||
);
|
||||
let pad = header.checked_sub(1).expect("a padding row above the header");
|
||||
assert_eq!(buffer[(2, pad)].bg, selected_bg, "including its padding rows");
|
||||
|
||||
app.update(Msg::Key(KeyEvent::new(KeyCode::Enter, KeyModifiers::NONE)));
|
||||
let rendered = buffer_to_string(&render_app(&mut app, &backend));
|
||||
assert!(rendered.contains("line 20"), "the card opened: {rendered}");
|
||||
}
|
||||
|
||||
/// A rejected edit produced no diff, so the card has to fall back to what the tool said — the
|
||||
/// guard's own message — instead of rendering nothing but a header and a duration.
|
||||
#[test]
|
||||
fn a_rejected_edit_says_why_on_its_card() {
|
||||
let (width, height) = (100, 24);
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = create_app();
|
||||
|
||||
let mut edit = ToolActivity::running("session-a", "call-edit", "edit", "src/lib.rs", 1);
|
||||
edit.state = ToolActivityState::Failed;
|
||||
edit.summary = Some("edited before reading the file".into());
|
||||
// A guard rejection is faster than the millisecond clock, which is exactly the case that used
|
||||
// to read as "nothing happened".
|
||||
edit.elapsed_ms = Some(0);
|
||||
edit.output_preview = Some(
|
||||
"Error: read 'src/lib.rs' before editing it (read-before-edit guard). Use the `read` \
|
||||
tool first, then retry."
|
||||
.into(),
|
||||
);
|
||||
app.push_convo(ConvoBlock::Tool(Box::new(ToolItem {
|
||||
activity: edit,
|
||||
expanded: true,
|
||||
details_toggled: false,
|
||||
waited_on_user_ms: 0,
|
||||
})));
|
||||
|
||||
let content = buffer_to_string(&render_app(&mut app, &backend));
|
||||
assert!(content.contains("edited before reading"), "the card names the reason: {content}");
|
||||
assert!(content.contains("read-before-edit guard"), "and shows the tool's words: {content}");
|
||||
assert!(content.contains("<1ms"), "a sub-millisecond call says so: {content}");
|
||||
assert!(!content.contains("0ms"), "never `0ms`, which reads as 'never ran': {content}");
|
||||
}
|
||||
|
||||
/// A cancelled or failed turn must not silently start the queued follow-ups, and must not leave
|
||||
/// them stuck behind a pending marker either — they come back to the composer instead.
|
||||
///
|
||||
/// Feeding a failing provider more turns compounds the failure, and a queue the user cannot see or
|
||||
/// reach is worse still: the message is handed back where one key re-sends it.
|
||||
#[test]
|
||||
fn cancelling_or_failing_a_turn_returns_queued_messages_instead_of_running_them() {
|
||||
let (width, height) = (80, 24);
|
||||
let backend = test_backend(width, height);
|
||||
|
||||
for stop in ["cancel", "error"] {
|
||||
let (tx, mut rx) = tokio::sync::mpsc::channel::<luxe_core::engine::Action>(64);
|
||||
let mut app = App::new(tx, KeyMap::defaults(), Config::default());
|
||||
app.update(Msg::Engine(luxe_core::event::Event::TokenDelta {
|
||||
block: 0,
|
||||
delta: "working".into(),
|
||||
}));
|
||||
app.editor.insert_text("follow-up work");
|
||||
app.update(Msg::Key(KeyEvent::new(KeyCode::Enter, KeyModifiers::ALT)));
|
||||
assert_eq!(app.queued_count(), 1, "{stop}: queued");
|
||||
let _ = rx.try_recv(); // drain nothing-expected
|
||||
|
||||
match stop {
|
||||
"cancel" => app.update(Msg::DispatchUiAction(luxe_core::keymap::UiAction::Cancel)),
|
||||
_ => app.update(Msg::Engine(luxe_core::event::Event::Error("provider down".into()))),
|
||||
}
|
||||
|
||||
assert_eq!(app.queued_count(), 0, "{stop}: nothing is left waiting");
|
||||
assert!(
|
||||
!matches!(rx.try_recv(), Ok(luxe_core::engine::Action::SubmitUserMessage { .. })),
|
||||
"{stop}: nothing was promoted"
|
||||
);
|
||||
assert_eq!(
|
||||
app.editor.current_input(),
|
||||
"follow-up work",
|
||||
"{stop}: the message is back in the composer"
|
||||
);
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
let content = buffer_to_string(&buffer);
|
||||
assert!(!content.contains("queued #"), "{stop}: and the tray row is gone: {content}");
|
||||
}
|
||||
}
|
||||
|
||||
/// Dragging past the transcript's edges scrolls it; straying sideways does not.
|
||||
#[test]
|
||||
fn dragging_past_the_transcript_edge_scrolls_but_sideways_does_not() {
|
||||
use crossterm::event::{MouseButton, MouseEvent, MouseEventKind};
|
||||
let (width, height) = (160, 16);
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = create_app();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
app.workspace = Some(empty_workspace("drag-edges"));
|
||||
for index in 0..40 {
|
||||
app.push_convo(ConvoBlock::System(format!("line {index}")));
|
||||
}
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
|
||||
// Start a drag on a transcript row (the transcript sits right of the dock rail).
|
||||
let transcript_x = width - 10;
|
||||
let first_row = (0..height)
|
||||
.find(|&y| row_text(&buffer, y, width).contains("line "))
|
||||
.expect("the transcript renders");
|
||||
let event = |kind, column, row| MouseEvent { kind, column, row, modifiers: KeyModifiers::NONE };
|
||||
let action = route_mouse(
|
||||
&mut app,
|
||||
&event(MouseEventKind::Down(MouseButton::Left), transcript_x, first_row + 1),
|
||||
);
|
||||
apply(&mut app, action);
|
||||
assert!(app.pointer.selection_drag.is_some(), "the press anchored a transcript selection");
|
||||
|
||||
// Sideways over the dock rail: no scroll.
|
||||
let before = app.scroll_state.offset;
|
||||
let action =
|
||||
route_mouse(&mut app, &event(MouseEventKind::Drag(MouseButton::Left), 2, first_row + 1));
|
||||
apply(&mut app, action);
|
||||
assert_eq!(app.scroll_state.offset, before, "a sideways drag must not scroll");
|
||||
|
||||
// Above the top row: scrolls up.
|
||||
let action =
|
||||
route_mouse(&mut app, &event(MouseEventKind::Drag(MouseButton::Left), transcript_x, 0));
|
||||
apply(&mut app, action);
|
||||
assert!(app.scroll_state.offset < before, "dragging above the pane scrolls up");
|
||||
}
|
||||
|
||||
/// A copy confirms itself on screen, and the terminal's copy chords reach that path when the
|
||||
/// terminal passes them through (it only holds them back when *it* has a selection).
|
||||
#[test]
|
||||
fn a_copy_is_confirmed_above_the_prompt_and_bound_to_the_terminal_copy_chords() {
|
||||
use crossterm::event::{MouseButton, MouseEvent, MouseEventKind};
|
||||
let (width, height) = (80, 14);
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = create_app();
|
||||
app.push_convo(ConvoBlock::Assistant("alpha bravo charlie".into()));
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
let row = (0..height)
|
||||
.find(|&y| row_text(&buffer, y, width).contains("alpha bravo charlie"))
|
||||
.expect("the reply renders");
|
||||
let start_col = column_of(&row_text(&buffer, row, width), "bravo");
|
||||
|
||||
// Ctrl+Insert (what Hyprland's Super+C lowers to) copies the live selection.
|
||||
let event = |kind, column| MouseEvent { kind, column, row, modifiers: KeyModifiers::NONE };
|
||||
let action = route_mouse(&mut app, &event(MouseEventKind::Down(MouseButton::Left), start_col));
|
||||
apply(&mut app, action);
|
||||
let action =
|
||||
route_mouse(&mut app, &event(MouseEventKind::Drag(MouseButton::Left), start_col + 5));
|
||||
apply(&mut app, action);
|
||||
app.update(Msg::Key(KeyEvent::new(KeyCode::Insert, KeyModifiers::CONTROL)));
|
||||
render_app(&mut app, &backend);
|
||||
assert_eq!(app.outbox.copy.as_deref(), Some("bravo"), "ctrl+insert copies the selection");
|
||||
|
||||
// …and the row above the prompt says so, because a captured drag leaves the terminal nothing to
|
||||
// show. Right-aligned, on its own chip, out of the activity bar's way.
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
let content = buffer_to_string(&buffer);
|
||||
let toast = (0..height)
|
||||
.find(|&y| row_text(&buffer, y, width).contains("Copied to clipboard"))
|
||||
.unwrap_or_else(|| panic!("the copy is confirmed on screen: {content}"));
|
||||
let text = row_text(&buffer, toast, width);
|
||||
assert!(text.trim_end().ends_with("Copied to clipboard"), "right-aligned: {text:?}");
|
||||
let chip = app.theme_styles.selected_bg.bg.expect("a chip background");
|
||||
// Flush to the composer's own right margin, and wearing a bold accent on a background so it
|
||||
// catches an eye on its way to the prompt.
|
||||
assert_eq!(buffer[(width - 2, toast)].bg, chip, "the chip runs to the inset right edge");
|
||||
let start = text.find('\u{f0c5}').expect("the clipboard glyph") as u16;
|
||||
assert_eq!(buffer[(start, toast)].bg, chip);
|
||||
assert_ne!(buffer[(start - 2, toast)].bg, chip, "and stops there");
|
||||
let label = text.find("Copied").expect("the label") as u16;
|
||||
assert!(buffer[(label, toast)].modifier.contains(ratatui::style::Modifier::BOLD));
|
||||
assert_eq!(buffer[(label, toast)].fg, app.theme_styles.accent.fg.expect("the accent"));
|
||||
|
||||
// It is transient: a few seconds later the row is its old self again.
|
||||
app.status.toast = app.status.toast.take().map(|(message, _)| {
|
||||
(message, std::time::Instant::now() - std::time::Duration::from_secs(30))
|
||||
});
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
assert!(!buffer_to_string(&buffer).contains("Copied to clipboard"), "the toast expires");
|
||||
|
||||
// Ctrl+Shift+C is the other conventional chord and reaches the same action.
|
||||
app.outbox.copy = None;
|
||||
app.update(Msg::Key(KeyEvent::new(
|
||||
KeyCode::Char('c'),
|
||||
KeyModifiers::CONTROL | KeyModifiers::SHIFT,
|
||||
)));
|
||||
render_app(&mut app, &backend);
|
||||
assert_eq!(app.outbox.copy.as_deref(), Some("bravo"));
|
||||
}
|
||||
405
crates/luxe-tui/tests/render/changes.rs
Normal file
405
crates/luxe-tui/tests/render/changes.rs
Normal file
@@ -0,0 +1,405 @@
|
||||
//! Changes — the dock list, the changes pane and the statusline module.
|
||||
|
||||
use super::*;
|
||||
|
||||
/// An app whose engine channel is *kept*, so a test can read the actions the UI sends and answer
|
||||
/// them the way the engine would.
|
||||
pub(super) fn create_app_with_engine(
|
||||
) -> (App, tokio::sync::mpsc::Receiver<luxe_core::engine::Action>) {
|
||||
let (tx, rx) = tokio::sync::mpsc::channel::<luxe_core::engine::Action>(64);
|
||||
(App::new(tx, KeyMap::defaults(), Config::default()), rx)
|
||||
}
|
||||
|
||||
/// A workspace with `count` changed files, biggest first, in distinct directories.
|
||||
pub(super) fn changed_workspace(scope: &str, count: usize) -> WorkspaceSnapshot {
|
||||
let mut snapshot = empty_workspace(scope);
|
||||
let files: Vec<FileChangeSummary> = (0..count)
|
||||
.map(|index| FileChangeSummary {
|
||||
path: format!("src/module{index:02}/file{index:02}.rs").into(),
|
||||
status: FileChangeStatus::Modified,
|
||||
additions: Some((count - index) as u64),
|
||||
deletions: Some(0),
|
||||
binary: false,
|
||||
})
|
||||
.collect();
|
||||
snapshot.changes = WorkspaceChangesSummary {
|
||||
total_files: files.len(),
|
||||
additions: Some(files.iter().filter_map(|file| file.additions).sum()),
|
||||
deletions: Some(0),
|
||||
files,
|
||||
truncated: false,
|
||||
};
|
||||
snapshot
|
||||
}
|
||||
|
||||
/// One replaced line, as the review's content model represents it.
|
||||
pub(super) fn one_hunk_file(path: &str) -> luxe_core::guided_review::ReviewFile {
|
||||
use luxe_core::guided_review::{
|
||||
FileId, HunkId, LineRange, NoiseKind, ReviewFile, ReviewFileStatus, ReviewHunk,
|
||||
};
|
||||
let id = FileId::from_path_lineage(
|
||||
Some(std::path::Path::new(path)),
|
||||
Some(std::path::Path::new(path)),
|
||||
);
|
||||
let line = |old, new, kind, text: &str| ReviewLine {
|
||||
old_line: old,
|
||||
new_line: new,
|
||||
kind,
|
||||
text: text.into(),
|
||||
};
|
||||
ReviewFile {
|
||||
id: id.clone(),
|
||||
old_path: Some(path.into()),
|
||||
new_path: Some(path.into()),
|
||||
status: ReviewFileStatus::Modified,
|
||||
language: Some("rs".into()),
|
||||
additions: Some(1),
|
||||
deletions: Some(1),
|
||||
hunks: vec![ReviewHunk {
|
||||
id: HunkId::from_content(&id, "h", "h"),
|
||||
old_range: LineRange::new(1, 2),
|
||||
new_range: LineRange::new(1, 2),
|
||||
heading: None,
|
||||
symbol: None,
|
||||
lines: vec![
|
||||
line(Some(1), Some(1), ReviewLineKind::Context, "fn sum() {"),
|
||||
line(Some(2), None, ReviewLineKind::Deletion, "let total = a + b;"),
|
||||
line(None, Some(2), ReviewLineKind::Addition, "let total = a - b;"),
|
||||
],
|
||||
noise: NoiseKind::Semantic,
|
||||
}],
|
||||
binary: false,
|
||||
generated: false,
|
||||
non_text: None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Opens `path` and answers the capture the UI asks for, the way the engine would.
|
||||
pub(super) fn open_changes_with(
|
||||
app: &mut App,
|
||||
rx: &mut tokio::sync::mpsc::Receiver<luxe_core::engine::Action>,
|
||||
path: &str,
|
||||
file: Option<luxe_core::guided_review::ReviewFile>,
|
||||
) {
|
||||
app.update(Msg::OpenChanges(path.to_string()));
|
||||
let request_id = loop {
|
||||
match rx.try_recv().expect("the pane asks the engine for the diff") {
|
||||
luxe_core::engine::Action::LoadFileDiff { request_id, path: asked } => {
|
||||
assert_eq!(asked, path, "it asks for the file it is showing");
|
||||
break request_id;
|
||||
}
|
||||
_ => continue,
|
||||
}
|
||||
};
|
||||
app.update(Msg::Engine(luxe_core::event::Event::FileDiffLoaded {
|
||||
request_id,
|
||||
diff: Box::new(luxe_core::file_diff::FileDiff {
|
||||
path: path.to_string(),
|
||||
file: file.map(Box::new),
|
||||
untracked: false,
|
||||
}),
|
||||
}));
|
||||
}
|
||||
|
||||
/// Whether the diff row carrying `needle` is drawn as two columns.
|
||||
///
|
||||
/// Asked of the row rather than the screen: a bare `│` also draws the scrollbar rail and the
|
||||
/// composer's own border, so a whole-buffer search for the rule finds one whether or not the diff
|
||||
/// has two columns.
|
||||
pub(super) fn split_row(buffer: &Buffer, needle: &str, app: &App, width: u16, height: u16) -> bool {
|
||||
let row = row_containing(buffer, needle, width, height);
|
||||
peek_diff_text(buffer, row, app, width).contains(" │ ")
|
||||
}
|
||||
|
||||
/// One row of the peeked diff's own columns.
|
||||
///
|
||||
/// Scoped, because with the conversation kept beside it every row also carries the rule between
|
||||
/// the two panes and whatever the transcript put after it.
|
||||
pub(super) fn peek_diff_text(buffer: &Buffer, y: u16, app: &App, width: u16) -> String {
|
||||
row_text(buffer, y, luxe_tui::view::peek_diff_column(app, width).unwrap_or(width))
|
||||
}
|
||||
|
||||
/// Screen row of the first line containing `needle`.
|
||||
pub(super) fn row_containing(buffer: &Buffer, needle: &str, width: u16, height: u16) -> u16 {
|
||||
(0..height)
|
||||
.find(|&y| row_text(buffer, y, width).contains(needle))
|
||||
.unwrap_or_else(|| panic!("no rendered row contains {needle:?}"))
|
||||
}
|
||||
|
||||
/// Screen row of the first *dock* line containing `needle`.
|
||||
///
|
||||
/// Scoped to the rail's own columns because the pane beside it shows the same file name in its
|
||||
/// header, and a whole-row search finds whichever is drawn first.
|
||||
pub(super) fn dock_row_containing(buffer: &Buffer, needle: &str, height: u16) -> u16 {
|
||||
let rail = luxe_tui::workspace_layout::CONTEXT_DOCK_WIDTH;
|
||||
(0..height)
|
||||
.find(|&y| row_text(buffer, y, rail).contains(needle))
|
||||
.unwrap_or_else(|| panic!("no dock row contains {needle:?}"))
|
||||
}
|
||||
|
||||
pub(super) fn left_click(app: &mut App, column: u16, row: u16) -> RouteAction {
|
||||
use crossterm::event::{MouseButton, MouseEvent, MouseEventKind};
|
||||
route_mouse(
|
||||
app,
|
||||
&MouseEvent {
|
||||
kind: MouseEventKind::Down(MouseButton::Left),
|
||||
column,
|
||||
row,
|
||||
modifiers: KeyModifiers::NONE,
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
pub(super) fn wheel_down(app: &mut App, column: u16, row: u16) -> RouteAction {
|
||||
use crossterm::event::{MouseEvent, MouseEventKind};
|
||||
route_mouse(
|
||||
app,
|
||||
&MouseEvent {
|
||||
kind: MouseEventKind::ScrollDown,
|
||||
column,
|
||||
row,
|
||||
modifiers: KeyModifiers::NONE,
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
/// The whole point of listing names: a click on one asks what it did to that file.
|
||||
#[test]
|
||||
fn clicking_a_dock_change_row_opens_that_files_diff() {
|
||||
let (width, height) = (160, 40);
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = create_app();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
app.workspace = Some(changed_workspace("dock-change-click", 3));
|
||||
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
let row = dock_row_containing(&buffer, "file00.rs", height);
|
||||
match left_click(&mut app, 5, row) {
|
||||
RouteAction::Msg(message) => assert!(
|
||||
matches!(&*message, Msg::OpenProjectFile(path) if path == "src/module00/file00.rs"),
|
||||
"expected the clicked file's path, got {message:?}"
|
||||
),
|
||||
other => panic!("expected a diff to open from the click, got {other:?}"),
|
||||
}
|
||||
}
|
||||
|
||||
/// The gesture that opened the pane puts it away, so one row is one control rather than a trap.
|
||||
#[test]
|
||||
fn clicking_the_open_file_again_closes_the_pane() {
|
||||
let (width, height) = (160, 40);
|
||||
let backend = test_backend(width, height);
|
||||
let (mut app, mut rx) = create_app_with_engine();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
app.workspace = Some(changed_workspace("dock-change-toggle", 3));
|
||||
let path = "src/module00/file00.rs";
|
||||
open_changes_with(&mut app, &mut rx, path, Some(one_hunk_file(path)));
|
||||
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
let row = dock_row_containing(&buffer, "file00.rs", height);
|
||||
match left_click(&mut app, 5, row) {
|
||||
RouteAction::Msg(message) => {
|
||||
assert!(matches!(*message, Msg::CloseChanges), "a second click closes it")
|
||||
}
|
||||
other => panic!("expected the pane to close, got {other:?}"),
|
||||
}
|
||||
}
|
||||
|
||||
/// A change bigger than the dock's budget is still entirely reachable: the section scrolls inside
|
||||
/// its own viewport instead of truncating, and a bar in its own lane says where you are in it.
|
||||
#[test]
|
||||
fn every_changed_file_is_reachable_by_scrolling_the_dock_list() {
|
||||
let (width, height) = (160, 40);
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = create_app();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
app.workspace = Some(changed_workspace("dock-change-scroll", 24));
|
||||
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
let first = buffer_to_string(&buffer);
|
||||
assert!(first.contains("file00.rs"), "the biggest change leads: {first}");
|
||||
assert!(!first.contains("file23.rs"), "and the smallest is below the fold");
|
||||
// The bar replaced the words: no scroll-position prose, and the thumb is against the top.
|
||||
for prose in ["more below", "scroll here", " above", "not listed"] {
|
||||
assert!(!first.contains(prose), "the lane says it instead of {prose:?}: {first}");
|
||||
}
|
||||
let lane = dock_scroll_lane(&buffer, "file00.rs", height);
|
||||
assert_eq!(lane.first().copied(), Some(THUMB), "the thumb starts at the top: {lane:?}");
|
||||
assert_eq!(lane.last().copied(), Some(TRACK), "and there is track below it: {lane:?}");
|
||||
|
||||
// Scroll until the last file arrives, bounded so a broken clamp fails instead of hanging.
|
||||
let mut reached = false;
|
||||
for _ in 0..40 {
|
||||
app.update(Msg::ScrollDockList { list: DockList::Files, up: false });
|
||||
if buffer_to_string(&render_app(&mut app, &backend)).contains("file23.rs") {
|
||||
reached = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
assert!(reached, "every changed file is reachable by scrolling");
|
||||
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
let lane = dock_scroll_lane(&buffer, "file23.rs", height);
|
||||
assert_eq!(lane.last().copied(), Some(THUMB), "the thumb followed to the end: {lane:?}");
|
||||
assert_eq!(lane.first().copied(), Some(TRACK), "leaving track behind it: {lane:?}");
|
||||
}
|
||||
|
||||
/// The dock's scrollbar lane: the track glyph, the thumb, and the column they share.
|
||||
pub(super) const TRACK: char = '\u{2595}';
|
||||
pub(super) const THUMB: char = '\u{2590}';
|
||||
/// The lane beside the dock list containing `needle`, top to bottom.
|
||||
///
|
||||
/// Found from the row the list is on rather than from a fixed column, so the test fails on a lane
|
||||
/// that moved rather than silently reading whatever is at column forty.
|
||||
pub(super) fn dock_scroll_lane(buffer: &Buffer, needle: &str, height: u16) -> Vec<char> {
|
||||
let rail = luxe_tui::workspace_layout::CONTEXT_DOCK_WIDTH;
|
||||
let column = (0..rail)
|
||||
.rev()
|
||||
.find(|&x| {
|
||||
let glyph = buffer[(x, dock_row_containing(buffer, needle, height))].symbol();
|
||||
glyph == TRACK.to_string() || glyph == THUMB.to_string()
|
||||
})
|
||||
.unwrap_or_else(|| panic!("no scrollbar lane on the row carrying {needle:?}"));
|
||||
(0..height)
|
||||
.map(|y| buffer[(column, y)].symbol().chars().next().unwrap_or(' '))
|
||||
.filter(|glyph| *glyph == TRACK || *glyph == THUMB)
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// A checklist longer than the rail is the same kind of surface: a lane beside it, the wheel over
|
||||
/// it moving it, and every todo reachable.
|
||||
///
|
||||
/// The bar starts where the *work in hand* is rather than at the top, because that is the row a
|
||||
/// reader is looking for; scrolling takes the list over, and scrolling back hands it to the plan
|
||||
/// again.
|
||||
#[test]
|
||||
fn the_plan_scrolls_under_its_own_bar_and_goes_back_to_following_the_work() {
|
||||
let (width, height) = (160, 44);
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = create_app();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
app.workspace = Some(planned_workspace("dock-plan-scroll", 20, 14));
|
||||
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
let first = buffer_to_string(&buffer);
|
||||
assert!(first.contains("step 14"), "the row in hand is in view: {first}");
|
||||
assert!(!first.contains("step 00"), "the history above it is not");
|
||||
assert!(!first.contains("earlier"), "and the lane says so instead of a count: {first}");
|
||||
let lane = dock_scroll_lane(&buffer, "step 14", height);
|
||||
assert!(lane.contains(&THUMB) && lane.contains(&TRACK), "a real bar: {lane:?}");
|
||||
assert_eq!(lane.first().copied(), Some(TRACK), "parked past the top, on the work: {lane:?}");
|
||||
|
||||
// The wheel over the checklist moves the checklist, not the panel.
|
||||
let row = dock_row_containing(&buffer, "step 14", height);
|
||||
match wheel_down(&mut app, 5, row) {
|
||||
RouteAction::Msg(message) => {
|
||||
assert!(
|
||||
matches!(*message, Msg::ScrollDockList { list: DockList::Plan, up: false }),
|
||||
"over the checklist, the wheel moves the checklist: {message:?}"
|
||||
);
|
||||
app.update(*message);
|
||||
}
|
||||
other => panic!("expected the checklist to scroll, got {other:?}"),
|
||||
}
|
||||
let scrolled = buffer_to_string(&render_app(&mut app, &backend));
|
||||
assert!(scrolled.contains("step 19"), "the tail is reachable: {scrolled}");
|
||||
|
||||
// Back to the top, then back down to the work: the plan is following again.
|
||||
for _ in 0..20 {
|
||||
app.update(Msg::ScrollDockList { list: DockList::Plan, up: true });
|
||||
}
|
||||
let top = buffer_to_string(&render_app(&mut app, &backend));
|
||||
assert!(top.contains("step 00"), "every todo is reachable: {top}");
|
||||
for _ in 0..20 {
|
||||
app.update(Msg::ScrollDockList { list: DockList::Plan, up: false });
|
||||
}
|
||||
let bottom = buffer_to_string(&render_app(&mut app, &backend));
|
||||
assert!(bottom.contains("step 19"), "and the far end too: {bottom}");
|
||||
}
|
||||
|
||||
/// A checklist that fits carries no lane at all — a bar on a complete list claims there is more.
|
||||
#[test]
|
||||
fn a_plan_that_fits_the_rail_has_no_bar() {
|
||||
let (width, height) = (160, 44);
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = create_app();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
app.workspace = Some(planned_workspace("dock-plan-short", 4, 2));
|
||||
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
let rail = luxe_tui::workspace_layout::CONTEXT_DOCK_WIDTH;
|
||||
let row = dock_row_containing(&buffer, "step 02", height);
|
||||
assert!(
|
||||
(0..rail).all(|x| ![TRACK.to_string(), THUMB.to_string()]
|
||||
.contains(&buffer[(x, row)].symbol().to_string())),
|
||||
"a complete checklist draws no lane: {}",
|
||||
row_text(&buffer, row, rail)
|
||||
);
|
||||
// And the wheel over it belongs to the panel again.
|
||||
match wheel_down(&mut app, 5, row) {
|
||||
RouteAction::Msg(message) => assert!(
|
||||
matches!(*message, Msg::ScrollDock { up: false }),
|
||||
"nothing to scroll in the section, so the panel moves: {message:?}"
|
||||
),
|
||||
other => panic!("expected the panel to scroll, got {other:?}"),
|
||||
}
|
||||
}
|
||||
|
||||
/// A session whose checklist is longer than the rail, with `active` in progress and everything
|
||||
/// before it done.
|
||||
pub(super) fn planned_workspace(scope: &str, count: usize, active: usize) -> WorkspaceSnapshot {
|
||||
let mut snapshot = empty_workspace(scope);
|
||||
let items: Vec<TodoSummaryItem> = (0..count)
|
||||
.map(|index| TodoSummaryItem {
|
||||
id: index.to_string(),
|
||||
subject: format!("step {index:02}"),
|
||||
status: match index.cmp(&active) {
|
||||
std::cmp::Ordering::Less => TodoSummaryStatus::Completed,
|
||||
std::cmp::Ordering::Equal => TodoSummaryStatus::InProgress,
|
||||
std::cmp::Ordering::Greater => TodoSummaryStatus::Pending,
|
||||
},
|
||||
blocked_by: Vec::new(),
|
||||
})
|
||||
.collect();
|
||||
snapshot.todos = TodoSummary {
|
||||
current: items.get(active).cloned(),
|
||||
pending: count.saturating_sub(active + 1),
|
||||
in_progress: 1,
|
||||
completed: active,
|
||||
blocked: 0,
|
||||
total: count,
|
||||
truncated: false,
|
||||
items,
|
||||
};
|
||||
snapshot
|
||||
}
|
||||
|
||||
/// Two scroll regions, one panel: the wheel over the file list moves the list, and the wheel
|
||||
/// anywhere else in the dock moves the panel. Without the distinction the list could never be
|
||||
/// bounded *and* complete.
|
||||
#[test]
|
||||
fn the_wheel_moves_the_change_list_over_it_and_the_panel_elsewhere() {
|
||||
let (width, height) = (160, 30);
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = create_app();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
app.workspace = Some(changed_workspace("dock-scroll-regions", 24));
|
||||
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
let over_list = dock_row_containing(&buffer, "file00.rs", height);
|
||||
let over_heading = dock_row_containing(&buffer, "PROJECT", height);
|
||||
|
||||
match wheel_down(&mut app, 5, over_list) {
|
||||
RouteAction::Msg(message) => assert!(
|
||||
matches!(*message, Msg::ScrollDockList { list: DockList::Files, up: false }),
|
||||
"over the list, the wheel moves the list: {message:?}"
|
||||
),
|
||||
other => panic!("expected the list to scroll, got {other:?}"),
|
||||
}
|
||||
match wheel_down(&mut app, 5, over_heading) {
|
||||
RouteAction::Msg(message) => assert!(
|
||||
matches!(*message, Msg::ScrollDock { up: false }),
|
||||
"elsewhere it moves the panel: {message:?}"
|
||||
),
|
||||
other => panic!("expected the panel to scroll, got {other:?}"),
|
||||
}
|
||||
}
|
||||
519
crates/luxe-tui/tests/render/changes_pane.rs
Normal file
519
crates/luxe-tui/tests/render/changes_pane.rs
Normal file
@@ -0,0 +1,519 @@
|
||||
//! Changes pane — the peeked diff, its columns, footer and stepping.
|
||||
|
||||
use super::*;
|
||||
|
||||
/// The pane takes the conversation column and gives it back — the dock and the composer never
|
||||
/// move, which is what makes the dock usable as the pane's navigation.
|
||||
#[test]
|
||||
fn the_changes_pane_replaces_the_transcript_and_esc_returns_it() {
|
||||
let (width, height) = (160, 40);
|
||||
let backend = test_backend(width, height);
|
||||
let (mut app, mut rx) = create_app_with_engine();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
app.workspace = Some(changed_workspace("changes-pane", 3));
|
||||
app.push_convo(ConvoBlock::Assistant("a distinctive transcript line".into()));
|
||||
|
||||
let transcript = buffer_to_string(&render_app(&mut app, &backend));
|
||||
assert!(transcript.contains("a distinctive transcript line"));
|
||||
|
||||
let path = "src/module00/file00.rs";
|
||||
open_changes_with(&mut app, &mut rx, path, Some(one_hunk_file(path)));
|
||||
let pane = buffer_to_string(&render_app(&mut app, &backend));
|
||||
assert!(!pane.contains("a distinctive transcript line"), "the pane owns the column: {pane}");
|
||||
assert!(pane.contains("file00.rs"), "and names the file: {pane}");
|
||||
assert!(pane.contains("FILES"), "the dock stays: {pane}");
|
||||
assert!(pane.contains("esc close"), "and says how to leave: {pane}");
|
||||
|
||||
app.update(Msg::Key(KeyEvent::new(KeyCode::Esc, KeyModifiers::NONE)));
|
||||
let back = buffer_to_string(&render_app(&mut app, &backend));
|
||||
assert!(back.contains("a distinctive transcript line"), "Esc gives the column back: {back}");
|
||||
}
|
||||
|
||||
/// The pane draws the file's actual hunks, through the review's own content model.
|
||||
#[test]
|
||||
fn the_changes_pane_draws_the_hunks_it_was_given() {
|
||||
let (width, height) = (160, 40);
|
||||
let backend = test_backend(width, height);
|
||||
let (mut app, mut rx) = create_app_with_engine();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
app.workspace = Some(changed_workspace("changes-hunks", 2));
|
||||
|
||||
app.update(Msg::OpenChanges("src/module00/file00.rs".into()));
|
||||
let loading = buffer_to_string(&render_app(&mut app, &backend));
|
||||
assert!(loading.contains("Reading the change"), "it says it is working: {loading}");
|
||||
|
||||
let path = "src/module00/file00.rs";
|
||||
// Re-open through the helper so the request the pane is waiting on is the one answered.
|
||||
app.update(Msg::CloseChanges);
|
||||
while rx.try_recv().is_ok() {}
|
||||
open_changes_with(&mut app, &mut rx, path, Some(one_hunk_file(path)));
|
||||
|
||||
let shown = buffer_to_string(&render_app(&mut app, &backend));
|
||||
assert!(shown.contains("@@ -1,2 +1,2 @@"), "the hunk header orients the reader: {shown}");
|
||||
assert!(shown.contains("let total = a + b;"), "the old line: {shown}");
|
||||
assert!(shown.contains("let total = a - b;"), "and the new one: {shown}");
|
||||
assert!(shown.contains("1 of 2"), "and where this file sits in the change: {shown}");
|
||||
}
|
||||
|
||||
/// A file that matches its base is an answer, not a failure — and never an empty surface.
|
||||
#[test]
|
||||
fn an_unchanged_file_says_so_rather_than_showing_nothing() {
|
||||
let (width, height) = (120, 24);
|
||||
let backend = test_backend(width, height);
|
||||
let (mut app, mut rx) = create_app_with_engine();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
app.workspace = Some(changed_workspace("changes-clean", 2));
|
||||
open_changes_with(&mut app, &mut rx, "src/module00/file00.rs", None);
|
||||
|
||||
let shown = buffer_to_string(&render_app(&mut app, &backend));
|
||||
assert!(shown.contains("Nothing has changed in this file"), "{shown}");
|
||||
}
|
||||
|
||||
/// A failure is shown as a sentence a person can act on, in the pane they are looking at.
|
||||
#[test]
|
||||
fn a_failed_capture_is_reported_in_the_pane() {
|
||||
let (width, height) = (120, 24);
|
||||
let backend = test_backend(width, height);
|
||||
let (mut app, mut rx) = create_app_with_engine();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
app.workspace = Some(changed_workspace("changes-failure", 2));
|
||||
|
||||
let path = "src/module00/file00.rs";
|
||||
app.update(Msg::OpenChanges(path.to_string()));
|
||||
let luxe_core::engine::Action::LoadFileDiff { request_id, .. } =
|
||||
rx.try_recv().expect("a capture was requested")
|
||||
else {
|
||||
panic!("expected a file-diff request");
|
||||
};
|
||||
app.update(Msg::Engine(luxe_core::event::Event::FileDiffFailed {
|
||||
request_id,
|
||||
path: path.to_string(),
|
||||
error: luxe_core::file_diff::FileDiffFailure::TooLarge,
|
||||
}));
|
||||
|
||||
let shown = buffer_to_string(&render_app(&mut app, &backend));
|
||||
assert!(shown.contains("This change is too large"), "capitalized like prose: {shown}");
|
||||
assert!(shown.contains("open the full review"), "and says where to go instead: {shown}");
|
||||
}
|
||||
|
||||
/// Escalating leaves the pane and asks for a review — the expensive surface, deliberately.
|
||||
///
|
||||
/// Asking is all it does: the review opens once there is a whole one to open, and until then the
|
||||
/// tray above the composer carries the wait.
|
||||
#[test]
|
||||
fn escalating_from_the_pane_opens_the_review() {
|
||||
let (width, height) = (160, 40);
|
||||
let backend = test_backend(width, height);
|
||||
let (mut app, mut rx) = create_app_with_engine();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
app.workspace = Some(changed_workspace("changes-escalate", 2));
|
||||
let path = "src/module00/file00.rs";
|
||||
open_changes_with(&mut app, &mut rx, path, Some(one_hunk_file(path)));
|
||||
let _ = render_app(&mut app, &backend);
|
||||
|
||||
app.update(Msg::DispatchUiAction(luxe_core::keymap::UiAction::ReviewOpen));
|
||||
let asked = std::iter::from_fn(|| rx.try_recv().ok())
|
||||
.any(|action| matches!(action, luxe_core::engine::Action::LoadGuidedReview { .. }));
|
||||
assert!(asked, "a review capture was requested");
|
||||
assert_eq!(app.current_view, ViewMode::Chat, "and the screen is not taken until it is ready");
|
||||
let waiting = buffer_to_string(&render_app(&mut app, &backend));
|
||||
assert!(waiting.contains("review"), "with the wait visible where the reader is: {waiting}");
|
||||
}
|
||||
|
||||
/// The bar's changes module earns its cells by carrying the way in, not just the number.
|
||||
#[test]
|
||||
fn the_statusline_changes_module_says_the_count_and_the_key() {
|
||||
let (width, height) = (150, 24);
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = create_app();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
app.workspace = Some(changed_workspace("statusline-changes", 4));
|
||||
app.dock.hide();
|
||||
app.statusline_state.show();
|
||||
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
let bar = row_text(&buffer, height - 1, width);
|
||||
assert!(bar.contains("4 files"), "the count: {bar}");
|
||||
assert!(bar.contains("ctrl+p"), "and how to see them: {bar}");
|
||||
|
||||
// Clicking it is the same affordance for the pointer already sitting on it.
|
||||
let column = column_of(&bar, "4 files");
|
||||
match left_click(&mut app, column, height - 1) {
|
||||
RouteAction::Msg(message) => assert!(
|
||||
matches!(*message, Msg::DispatchUiAction(luxe_core::keymap::UiAction::ToggleChanges)),
|
||||
"clicking the module opens the pane: {message:?}"
|
||||
),
|
||||
other => panic!("expected the module to be clickable, got {other:?}"),
|
||||
}
|
||||
}
|
||||
|
||||
/// A clean worktree spends no cells saying so.
|
||||
#[test]
|
||||
fn the_statusline_changes_module_is_absent_with_nothing_changed() {
|
||||
let (width, height) = (150, 24);
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = create_app();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
app.workspace = Some(empty_workspace("statusline-clean"));
|
||||
app.dock.hide();
|
||||
app.statusline_state.show();
|
||||
|
||||
let bar = row_text(&render_app(&mut app, &backend), height - 1, width);
|
||||
assert!(!bar.contains("files"), "no change, no module: {bar}");
|
||||
assert!(!bar.contains("ctrl+p"), "and no key to advertise: {bar}");
|
||||
}
|
||||
|
||||
/// A peeked diff keeps the conversation beside it where the column can seat both — and the whole
|
||||
/// chat stack, composer included, narrows with it.
|
||||
///
|
||||
/// A prompt spanning both columns says the text goes to both, which is not what happens: the
|
||||
/// message lands in the transcript. And a diff stopping short of the composer's rows would waste
|
||||
/// them for nothing.
|
||||
#[test]
|
||||
fn a_peeked_diff_keeps_the_conversation_and_the_composer_beside_it() {
|
||||
let path = "src/module00/file00.rs";
|
||||
let (width, height) = (240u16, 30);
|
||||
let backend = test_backend(width, height);
|
||||
let (mut app, mut rx) = create_app_with_engine();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
app.dock.hide();
|
||||
app.workspace = Some(changed_workspace("peek-three-pane", 2));
|
||||
app.push_convo(ConvoBlock::Assistant("A reply that stays readable beside the code.".into()));
|
||||
open_changes_with(&mut app, &mut rx, path, Some(one_hunk_file(path)));
|
||||
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
let diff_width = luxe_tui::view::peek_diff_column(&app, width).expect("the column seats both");
|
||||
let whole = buffer_to_string(&buffer);
|
||||
assert!(whole.contains("fn sum() {"), "the diff is on screen: {whole}");
|
||||
assert!(whole.contains("stays readable beside the code"), "and so is the exchange: {whole}");
|
||||
|
||||
// The composer belongs to the conversation column: its box starts to the right of the diff.
|
||||
let composer_row = row_containing(&buffer, "\u{256d}", width, height);
|
||||
let left_of_rule = row_text(&buffer, composer_row, diff_width);
|
||||
assert!(
|
||||
!left_of_rule.contains('\u{256d}'),
|
||||
"the prompt does not reach under the diff: {left_of_rule:?}"
|
||||
);
|
||||
|
||||
// And the diff runs the full height beside it rather than stopping where the composer starts.
|
||||
let footer_row = row_containing(&buffer, "esc close", width, height);
|
||||
assert!(footer_row > composer_row, "the diff outlasts the prompt: {whole}");
|
||||
}
|
||||
|
||||
/// On a wide terminal the diff takes what code needs and the conversation keeps the rest.
|
||||
///
|
||||
/// It used to be the other way round: the conversation was capped at eighty cells and a unified
|
||||
/// diff took everything else, so a wide screen spent most of its rows on empty diff.
|
||||
#[test]
|
||||
fn a_wide_peek_gives_the_conversation_what_the_diff_does_not_need() {
|
||||
use luxe_tui::view::peek_diff_width;
|
||||
let unified = peek_diff_width(300, false).expect("seats both");
|
||||
let split = peek_diff_width(300, true).expect("seats both");
|
||||
assert!(unified < 140, "a unified diff stops at a code measure: {unified}");
|
||||
assert!(split > unified && split < 230, "two columns get two measures: {split}");
|
||||
assert_eq!(peek_diff_width(300, false), peek_diff_width(400, false), "and stops growing");
|
||||
// Narrower than the caps, nothing changes: the transcript keeps its floor and the diff the rest
|
||||
assert_eq!(peek_diff_width(140, false), Some(140 - 57));
|
||||
assert_eq!(peek_diff_width(140, true), Some(140 - 57));
|
||||
// Whether the two share never depends on the layout, so a layout toggle never moves the chat
|
||||
for width in [128u16, 129, 200] {
|
||||
assert_eq!(peek_diff_width(width, false).is_some(), peek_diff_width(width, true).is_some());
|
||||
}
|
||||
|
||||
// On screen: a unified peek on a wide terminal, the transcript wide beside it
|
||||
let path = "src/module00/file00.rs";
|
||||
let (width, height) = (300u16, 24);
|
||||
let backend = test_backend(width, height);
|
||||
let (mut app, mut rx) = create_app_with_engine();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
app.dock.hide();
|
||||
app.workspace = Some(changed_workspace("peek-wide", 2));
|
||||
app.push_convo(ConvoBlock::Assistant("word ".repeat(60)));
|
||||
open_changes_with(&mut app, &mut rx, path, Some(one_hunk_file(path)));
|
||||
render_app(&mut app, &backend);
|
||||
assert_eq!(luxe_tui::view::peek_diff_column(&app, width), Some(split), "starts split");
|
||||
// The toggle flips what the last frame drew
|
||||
app.update(Msg::DispatchUiAction(luxe_core::keymap::UiAction::ReviewToggleSplit));
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
let diff = luxe_tui::view::peek_diff_column(&app, width).expect("shared");
|
||||
assert_eq!(diff, unified, "drawn unified, sized unified");
|
||||
let prose = row_containing(&buffer, "word word", width, height);
|
||||
let words = row_text(&buffer, prose, width).matches("word").count();
|
||||
assert!(words > 30, "the transcript has room for a line of prose: {words} words");
|
||||
}
|
||||
|
||||
/// Below that width the diff takes the column alone, because a transcript in forty cells is a
|
||||
/// column of two-word lines.
|
||||
#[test]
|
||||
fn a_narrow_peek_gives_the_diff_the_whole_column() {
|
||||
let path = "src/module00/file00.rs";
|
||||
let (width, height) = (110u16, 24);
|
||||
let backend = test_backend(width, height);
|
||||
let (mut app, mut rx) = create_app_with_engine();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
app.dock.hide();
|
||||
app.workspace = Some(changed_workspace("peek-two-pane", 2));
|
||||
app.push_convo(ConvoBlock::Assistant("A reply that has to wait its turn.".into()));
|
||||
open_changes_with(&mut app, &mut rx, path, Some(one_hunk_file(path)));
|
||||
|
||||
assert!(luxe_tui::view::peek_diff_width(width, false).is_none(), "too narrow for both");
|
||||
let whole = buffer_to_string(&render_app(&mut app, &backend));
|
||||
assert!(whole.contains("fn sum() {"), "the diff is on screen: {whole}");
|
||||
assert!(!whole.contains("has to wait its turn"), "and the transcript waits: {whole}");
|
||||
}
|
||||
|
||||
/// A pane with room for two readable columns draws two; one without draws the unified list. Nobody
|
||||
/// has to ask for it, which is why the width test has to be conservative rather than eager.
|
||||
#[test]
|
||||
fn the_pane_draws_two_columns_only_where_they_would_read() {
|
||||
let path = "src/module00/file00.rs";
|
||||
// 260 rather than 200: with the conversation kept beside it, a diff needs the wider terminal
|
||||
// before its own two columns fit. At 90 the pane has the main column to itself and still
|
||||
// cannot seat two readable ones.
|
||||
for (width, expect_split) in [(260u16, true), (90u16, false)] {
|
||||
let backend = test_backend(width, 24);
|
||||
let (mut app, mut rx) = create_app_with_engine();
|
||||
app.update(Msg::TerminalResized { width, height: 24 });
|
||||
app.dock.hide();
|
||||
app.workspace = Some(changed_workspace("changes-split", 2));
|
||||
open_changes_with(&mut app, &mut rx, path, Some(one_hunk_file(path)));
|
||||
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
assert_eq!(
|
||||
split_row(&buffer, "fn sum() {", &app, width, 24),
|
||||
expect_split,
|
||||
"at {width} columns, split should be {expect_split}: {}",
|
||||
buffer_to_string(&buffer)
|
||||
);
|
||||
// Either way the change itself is legible.
|
||||
let shown = buffer_to_string(&buffer);
|
||||
assert!(shown.contains("let total = a - b;"), "the new line is shown: {shown}");
|
||||
}
|
||||
}
|
||||
|
||||
/// One key, both diff surfaces: the action names a layout rather than a surface.
|
||||
#[test]
|
||||
fn the_layout_toggle_switches_the_pane_between_columns_and_the_list() {
|
||||
// Wide enough for the diff to keep two columns beside the conversation the peek now keeps.
|
||||
let (width, height) = (260, 24);
|
||||
let backend = test_backend(width, height);
|
||||
let (mut app, mut rx) = create_app_with_engine();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
app.dock.hide();
|
||||
app.workspace = Some(changed_workspace("changes-toggle-split", 2));
|
||||
let path = "src/module00/file00.rs";
|
||||
open_changes_with(&mut app, &mut rx, path, Some(one_hunk_file(path)));
|
||||
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
assert!(
|
||||
split_row(&buffer, "fn sum() {", &app, width, height),
|
||||
"wide enough, so it starts split"
|
||||
);
|
||||
let split = buffer_to_string(&buffer);
|
||||
assert!(split.contains("ctrl+b unified diff"), "and offers the other layout: {split}");
|
||||
|
||||
app.update(Msg::DispatchUiAction(luxe_core::keymap::UiAction::ReviewToggleSplit));
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
assert!(
|
||||
!split_row(&buffer, "fn sum() {", &app, width, height),
|
||||
"one press switches to the list"
|
||||
);
|
||||
let unified = buffer_to_string(&buffer);
|
||||
assert!(unified.contains("ctrl+b side-by-side diff"), "and offers the way back: {unified}");
|
||||
}
|
||||
|
||||
/// Stepping between files does not make the layout shortcut blink.
|
||||
///
|
||||
/// `ChangesView::show` drops the loaded diff and the next capture takes a frame, so anything that
|
||||
/// asks "can this draw two columns?" through `view.file()` gets `None` in between. Answering
|
||||
/// `false` there dropped the shortcut out of the footer and put it back a frame later — every hint
|
||||
/// to its right shifted twice per file switch. The last resolved layout carries across the gap
|
||||
/// instead, so the row holds still.
|
||||
#[test]
|
||||
fn stepping_between_files_holds_the_footer_still() {
|
||||
let (width, height) = (200, 24);
|
||||
let backend = test_backend(width, height);
|
||||
let (mut app, mut rx) = create_app_with_engine();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
app.dock.hide();
|
||||
app.workspace = Some(changed_workspace("changes-footer-still", 2));
|
||||
let first = "src/module00/file00.rs";
|
||||
open_changes_with(&mut app, &mut rx, first, Some(one_hunk_file(first)));
|
||||
|
||||
let footer_of = |app: &mut App| -> String {
|
||||
let buffer = render_app(app, &backend);
|
||||
let row = row_containing(&buffer, "esc close", width, height);
|
||||
peek_diff_text(&buffer, row, app, width).trim().to_string()
|
||||
};
|
||||
let settled = footer_of(&mut app);
|
||||
assert!(settled.contains("diff"), "precondition: the layout shortcut is on the row: {settled}");
|
||||
|
||||
// Mid-switch: the next diff has been asked for but has not arrived.
|
||||
app.update(Msg::ChangesStepFile(true));
|
||||
let loading = footer_of(&mut app);
|
||||
assert_eq!(loading, settled, "the footer must not reflow while the next diff loads");
|
||||
}
|
||||
|
||||
/// The left column is the old file and the right is the new one, so each numbers its own side.
|
||||
/// Printing the old number beside new content is a false statement about where that line lives.
|
||||
#[test]
|
||||
fn each_split_column_numbers_its_own_side() {
|
||||
// Wide enough for the diff to keep two columns beside the conversation the peek now keeps.
|
||||
let (width, height) = (260, 24);
|
||||
let backend = test_backend(width, height);
|
||||
let (mut app, mut rx) = create_app_with_engine();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
app.dock.hide();
|
||||
app.workspace = Some(changed_workspace("changes-split-numbers", 2));
|
||||
let path = "src/module00/file00.rs";
|
||||
// Context at old 9 / new 4, so the two sides cannot be confused for one another.
|
||||
let mut file = one_hunk_file(path);
|
||||
file.hunks[0].lines[0].old_line = Some(9);
|
||||
file.hunks[0].lines[0].new_line = Some(4);
|
||||
open_changes_with(&mut app, &mut rx, path, Some(file));
|
||||
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
let row = row_containing(&buffer, "fn sum() {", width, height);
|
||||
let text = peek_diff_text(&buffer, row, &app, width);
|
||||
let (left, right) = text.split_once(" │ ").expect("a split row has two columns");
|
||||
assert!(left.contains('9'), "the old column carries the old number: {left:?}");
|
||||
assert!(right.contains('4'), "the new column carries the new one: {right:?}");
|
||||
assert!(!right.contains('9'), "and not the old one: {right:?}");
|
||||
}
|
||||
|
||||
/// A rule sits over the pane's shortcuts, the way one sits under its header: straight after the
|
||||
/// last line of code, the keys read as one more line of it.
|
||||
#[test]
|
||||
fn the_pane_rules_off_its_footer() {
|
||||
let path = "src/module00/file00.rs";
|
||||
let (width, height) = (120u16, 20u16);
|
||||
let backend = test_backend(width, height);
|
||||
let (mut app, mut rx) = create_app_with_engine();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
app.dock.hide();
|
||||
app.workspace = Some(changed_workspace("changes-rule", 3));
|
||||
open_changes_with(&mut app, &mut rx, path, Some(one_hunk_file(path)));
|
||||
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
let row = row_containing(&buffer, "esc close", width, height);
|
||||
let above = peek_diff_text(&buffer, row - 1, &app, width);
|
||||
assert!(above.trim().chars().all(|c| c == '─') && above.trim().len() > 20, "{above:?}");
|
||||
}
|
||||
|
||||
/// A footer that truncates mid-label is worse than one that says less: `Alt+W no wr` teaches the
|
||||
/// reader that the row cannot be trusted.
|
||||
#[test]
|
||||
fn the_pane_footer_drops_whole_shortcuts_rather_than_truncating_one() {
|
||||
let path = "src/module00/file00.rs";
|
||||
for width in [50u16, 60, 70, 90, 120, 200] {
|
||||
let backend = test_backend(width, 20);
|
||||
let (mut app, mut rx) = create_app_with_engine();
|
||||
app.update(Msg::TerminalResized { width, height: 20 });
|
||||
app.dock.hide();
|
||||
app.workspace = Some(changed_workspace("changes-footer", 3));
|
||||
open_changes_with(&mut app, &mut rx, path, Some(one_hunk_file(path)));
|
||||
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
let row = row_containing(&buffer, "esc close", width, 20);
|
||||
let footer = peek_diff_text(&buffer, row, &app, width);
|
||||
assert!(
|
||||
footer.trim_end().ends_with("esc close"),
|
||||
"the way out is never the thing that gets cut, at {width}: {footer:?}"
|
||||
);
|
||||
// Every segment on the row is a whole shortcut, so nothing was cut mid-label.
|
||||
const WHOLE: [&str; 9] = [
|
||||
"alt+m whole file",
|
||||
"alt+m changes",
|
||||
"alt+n next file",
|
||||
"alt+p previous",
|
||||
"ctrl+b side-by-side diff",
|
||||
"ctrl+b unified diff",
|
||||
"alt+o open in editor",
|
||||
"alt+w stop wrapping",
|
||||
"ctrl+g review this file",
|
||||
];
|
||||
for segment in footer.trim().split(" · ") {
|
||||
assert!(
|
||||
segment == "esc close" || WHOLE.contains(&segment),
|
||||
"{segment:?} is not a whole shortcut at {width}: {footer:?}"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A peek at a file outside the project says where it is, and stops short of a review.
|
||||
///
|
||||
/// The pane is the same pane, and the footer is where the difference has to show: a review is
|
||||
/// captured from the project's own worktree, so `Ctrl+G review this file` over a file that lives
|
||||
/// somewhere else names a destination that cannot exist.
|
||||
#[test]
|
||||
fn peeking_a_file_outside_the_project_offers_everything_but_the_review() {
|
||||
let (width, height) = (140, 24);
|
||||
let backend = test_backend(width, height);
|
||||
let (mut app, mut rx) = create_app_with_engine();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
app.dock.hide();
|
||||
app.workspace = Some(external_workspace());
|
||||
|
||||
let path = "/work/sdk/src/client.ts";
|
||||
open_changes_with(&mut app, &mut rx, path, Some(one_hunk_file(path)));
|
||||
let content = buffer_to_string(&render_app(&mut app, &backend));
|
||||
assert!(content.contains("/work/sdk/src/client.ts"), "the header says where it is: {content}");
|
||||
assert!(content.contains("esc close"), "the footer is drawn: {content}");
|
||||
assert!(
|
||||
!content.contains("review this file"),
|
||||
"and offers no review of a file no review can contain: {content}"
|
||||
);
|
||||
}
|
||||
|
||||
/// Stepping walks every file this session changed, the project's own first and the rest after —
|
||||
/// the list is what changed, and work done elsewhere changed too.
|
||||
#[test]
|
||||
fn stepping_runs_off_the_projects_changes_into_the_work_done_elsewhere() {
|
||||
let (width, height) = (140, 24);
|
||||
let backend = test_backend(width, height);
|
||||
let (mut app, mut rx) = create_app_with_engine();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
app.dock.hide();
|
||||
let mut workspace = changed_workspace("changes-stepping", 1);
|
||||
workspace.external = external_workspace().external;
|
||||
app.workspace = Some(workspace);
|
||||
|
||||
let path = "src/module00/file00.rs";
|
||||
open_changes_with(&mut app, &mut rx, path, Some(one_hunk_file(path)));
|
||||
app.update(Msg::ChangesStepFile(true));
|
||||
let content = buffer_to_string(&render_app(&mut app, &backend));
|
||||
assert!(content.contains("client.ts"), "the next file is the one elsewhere: {content}");
|
||||
assert!(content.contains("2 of 2"), "and it is counted in the same list: {content}");
|
||||
}
|
||||
|
||||
/// The pane cannot scroll sideways, so it wraps from the start: a clipped line here would put
|
||||
/// content out of reach rather than one keystroke away.
|
||||
#[test]
|
||||
fn the_pane_wraps_long_lines_without_being_asked() {
|
||||
let (width, height) = (120, 24);
|
||||
let backend = test_backend(width, height);
|
||||
let (mut app, mut rx) = create_app_with_engine();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
app.dock.hide();
|
||||
app.workspace = Some(changed_workspace("changes-wrap", 2));
|
||||
let path = "src/module00/file00.rs";
|
||||
let mut file = one_hunk_file(path);
|
||||
// One-sided, so the pane stays a unified list at any width: wrapping a *column* is the split
|
||||
// renderer's own business, and the continuation and clipped forms below only exist here.
|
||||
file.status = luxe_core::guided_review::ReviewFileStatus::Added;
|
||||
let tail = "the-tail-that-must-not-be-lost";
|
||||
file.hunks[0].lines[0].text = format!("let head = \"{}{tail}\";", "padding-".repeat(20));
|
||||
open_changes_with(&mut app, &mut rx, path, Some(file));
|
||||
|
||||
let shown = buffer_to_string(&render_app(&mut app, &backend));
|
||||
assert!(shown.contains(tail), "the end of a long line is still reachable: {shown}");
|
||||
assert!(shown.contains('↳'), "and it says where it continued: {shown}");
|
||||
assert!(shown.contains("alt+w stop wrapping"), "the footer offers to stop wrapping: {shown}");
|
||||
|
||||
// Turning it off clips instead, and says so.
|
||||
app.update(Msg::DispatchUiAction(luxe_core::keymap::UiAction::ChangesToggleWordWrap));
|
||||
let clipped = buffer_to_string(&render_app(&mut app, &backend));
|
||||
assert!(!clipped.contains(tail), "clipped now: {clipped}");
|
||||
assert!(clipped.contains('…'), "and marked as clipped: {clipped}");
|
||||
}
|
||||
207
crates/luxe-tui/tests/render/chat_keys.rs
Normal file
207
crates/luxe-tui/tests/render/chat_keys.rs
Normal file
@@ -0,0 +1,207 @@
|
||||
//! Chat keys — arrows, paging and the scroll state under them.
|
||||
|
||||
use super::*;
|
||||
|
||||
/// Plain arrows belong to the composer; modified arrows remain conversation bindings.
|
||||
#[test]
|
||||
fn test_route_key_chat_arrows_edit_the_composer() {
|
||||
let (tx, _rx) = tokio::sync::mpsc::channel::<luxe_core::engine::Action>(64);
|
||||
let mut app = App::new(tx, KeyMap::defaults(), Config::default());
|
||||
app.current_view = ViewMode::Chat;
|
||||
app.editor.insert_text("alpha\nbeta");
|
||||
|
||||
match route_key(&mut app, &key(KeyCode::Up)) {
|
||||
RouteAction::Msg(message) => app.update(*message),
|
||||
action => panic!("plain Up did not reach the editor: {action:?}"),
|
||||
}
|
||||
assert_eq!(app.editor.visual_cursor(80).row, 0);
|
||||
|
||||
let alt_down = KeyEvent::new(KeyCode::Down, KeyModifiers::ALT);
|
||||
assert!(matches!(
|
||||
route_key(&mut app, &alt_down),
|
||||
RouteAction::Msg(message) if matches!(*message, Msg::Key(_))
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn open_palette_receives_arrow_keys_before_chat_scrolling() {
|
||||
let (tx, _rx) = tokio::sync::mpsc::channel::<luxe_core::engine::Action>(64);
|
||||
let mut app = App::new(tx, KeyMap::defaults(), Config::default());
|
||||
app.overlays.palette = Some(luxe_tui::palette::PaletteState::open(
|
||||
luxe_tui::commands::CommandRegistry::all().arrange(
|
||||
&luxe_tui::commands::CommandContext::default(),
|
||||
&KeyMap::defaults(),
|
||||
&[],
|
||||
),
|
||||
));
|
||||
|
||||
match route_key(&mut app, &key(KeyCode::Down)) {
|
||||
RouteAction::Msg(message) => app.update(*message),
|
||||
action => panic!("palette arrow leaked to chat routing: {action:?}"),
|
||||
}
|
||||
|
||||
assert_eq!(app.overlays.palette.as_ref().map(|state| state.selected()), Some(1));
|
||||
assert_eq!(app.scroll_state.offset, 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_route_key_chat_inserts_j_and_k() {
|
||||
let (tx, _rx) = tokio::sync::mpsc::channel::<luxe_core::engine::Action>(64);
|
||||
let mut app = App::new(tx, KeyMap::defaults(), Config::default());
|
||||
app.current_view = ViewMode::Chat;
|
||||
|
||||
for character in ['j', 'k'] {
|
||||
match route_key(&mut app, &key(KeyCode::Char(character))) {
|
||||
RouteAction::Msg(msg) => app.update(*msg),
|
||||
action => panic!("expected editor input for {character:?}, got {action:?}"),
|
||||
}
|
||||
}
|
||||
|
||||
assert_eq!(app.editor.current_input(), "jk");
|
||||
}
|
||||
|
||||
/// Page keys scroll the conversation without reserving printable editor keys.
|
||||
#[test]
|
||||
fn test_route_key_chat_page_scroll() {
|
||||
let (tx, _rx) = tokio::sync::mpsc::channel::<luxe_core::engine::Action>(64);
|
||||
let mut app = App::new(tx, KeyMap::defaults(), Config::default());
|
||||
app.current_view = ViewMode::Chat;
|
||||
|
||||
assert!(matches!(
|
||||
route_key(&mut app, &key(KeyCode::PageUp)),
|
||||
RouteAction::Scroll(luxe_tui::main_loop::ScrollAction::PageUp)
|
||||
));
|
||||
assert!(matches!(
|
||||
route_key(&mut app, &key(KeyCode::PageDown)),
|
||||
RouteAction::Scroll(luxe_tui::main_loop::ScrollAction::PageDown)
|
||||
));
|
||||
|
||||
for character in ['b', 'f', 'G', 'y'] {
|
||||
match route_key(&mut app, &key(KeyCode::Char(character))) {
|
||||
RouteAction::Msg(message) => app.update(*message),
|
||||
action => panic!("printable {character:?} was intercepted: {action:?}"),
|
||||
}
|
||||
}
|
||||
assert_eq!(app.editor.current_input(), "bfGy");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn standard_paste_bindings_request_a_unified_clipboard_read() {
|
||||
let mut app = create_app();
|
||||
for paste_key in [
|
||||
KeyEvent::new(KeyCode::Char('v'), KeyModifiers::CONTROL),
|
||||
KeyEvent::new(KeyCode::Insert, KeyModifiers::SHIFT),
|
||||
] {
|
||||
app.outbox.clipboard_paste = false;
|
||||
match route_key(&mut app, &paste_key) {
|
||||
RouteAction::Msg(message) => app.update(*message),
|
||||
action => panic!("standard paste did not reach App: {action:?}"),
|
||||
}
|
||||
assert!(app.outbox.clipboard_paste);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_route_key_chat_ctrl_end_scrolls_to_bottom() {
|
||||
let (tx, _rx) = tokio::sync::mpsc::channel::<luxe_core::engine::Action>(64);
|
||||
let mut app = App::new(tx, KeyMap::defaults(), Config::default());
|
||||
app.current_view = ViewMode::Chat;
|
||||
let ctrl_end = KeyEvent::new(KeyCode::End, KeyModifiers::CONTROL);
|
||||
|
||||
assert!(matches!(
|
||||
route_key(&mut app, &ctrl_end),
|
||||
RouteAction::Scroll(luxe_tui::main_loop::ScrollAction::ToBottom)
|
||||
));
|
||||
}
|
||||
|
||||
/// Chat view: non-scroll keys still pass through as Msg::Key.
|
||||
#[test]
|
||||
fn test_route_key_chat_non_scroll_passes_through() {
|
||||
let (tx, _rx) = tokio::sync::mpsc::channel::<luxe_core::engine::Action>(64);
|
||||
let mut app = App::new(tx, KeyMap::defaults(), Config::default());
|
||||
app.current_view = ViewMode::Chat;
|
||||
|
||||
assert!(matches!(
|
||||
route_key(&mut app, &key(KeyCode::Char('a'))),
|
||||
RouteAction::Msg(message) if matches!(*message, Msg::Key(_))
|
||||
));
|
||||
assert!(matches!(
|
||||
route_key(&mut app, &key(KeyCode::Char('/'))),
|
||||
RouteAction::Msg(message) if matches!(*message, Msg::Key(_))
|
||||
));
|
||||
}
|
||||
|
||||
/// Scroll state: line_down moves offset by 1.
|
||||
#[test]
|
||||
fn test_scroll_state_new_starts_at_bottom() {
|
||||
let scroll = luxe_tui::scroll::ScrollState::new(10, 100);
|
||||
assert_eq!(scroll.offset, 90); // starts at bottom (100 - 10)
|
||||
assert!(scroll.follow);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_scroll_state_line_up() {
|
||||
let mut scroll = luxe_tui::scroll::ScrollState::new(10, 100);
|
||||
scroll.follow = false;
|
||||
scroll.line_up();
|
||||
assert_eq!(scroll.offset, 89);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_scroll_state_page_down_at_bottom() {
|
||||
let mut scroll = luxe_tui::scroll::ScrollState::new(10, 100);
|
||||
scroll.follow = false;
|
||||
scroll.offset = 50;
|
||||
scroll.page_down();
|
||||
assert_eq!(scroll.offset, 60); // moved down by 10
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_scroll_state_to_bottom() {
|
||||
let mut scroll = luxe_tui::scroll::ScrollState::new(10, 100);
|
||||
scroll.offset = 50;
|
||||
scroll.follow = false;
|
||||
scroll.to_bottom();
|
||||
assert_eq!(scroll.offset, 90);
|
||||
assert!(scroll.follow);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_scroll_state_position_percent() {
|
||||
let scroll = luxe_tui::scroll::ScrollState::new(10, 100);
|
||||
assert_eq!(scroll.position_percent(), 100); // at bottom (90/90)
|
||||
|
||||
let mut scroll = luxe_tui::scroll::ScrollState::new(10, 100);
|
||||
scroll.follow = false;
|
||||
scroll.offset = 45;
|
||||
assert_eq!(scroll.position_percent(), 50); // 45 / 90 = 50%
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_scroll_state_window() {
|
||||
let scroll = luxe_tui::scroll::ScrollState::new(10, 100);
|
||||
let win = scroll.window();
|
||||
assert_eq!(win.start, 90);
|
||||
assert_eq!(win.end, 100);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_scroll_state_on_resize() {
|
||||
let mut scroll = luxe_tui::scroll::ScrollState::new(10, 100);
|
||||
scroll.follow = false;
|
||||
scroll.offset = 80;
|
||||
scroll.on_resize(20);
|
||||
assert_eq!(scroll.viewport, 20);
|
||||
assert_eq!(scroll.offset, 80); // within new bounds
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_default_chat_omits_conversation_label() {
|
||||
let backend = test_backend(80, 24);
|
||||
let mut app = create_app();
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
let top = row_text(&buffer, 0, 80);
|
||||
|
||||
assert!(!top.contains("Conversation"), "conversation label should be hidden: {top:?}");
|
||||
assert!(!top.contains('%'), "scroll percentage should be hidden: {top:?}");
|
||||
}
|
||||
138
crates/luxe-tui/tests/render/clicks.rs
Normal file
138
crates/luxe-tui/tests/render/clicks.rs
Normal file
@@ -0,0 +1,138 @@
|
||||
//! Clicks — copy affordances, the composer cursor and prose that is not a button.
|
||||
|
||||
use super::*;
|
||||
|
||||
/// Each fenced code block renders a muted "copy" caption at its **top right**, where every editor
|
||||
/// and every chat client puts one; clicking it copies the block's source text. It sits on
|
||||
/// selectable text, so like every transcript click it acts on the release.
|
||||
#[test]
|
||||
fn clicking_a_code_block_copy_affordance_copies_the_code() {
|
||||
use crossterm::event::{MouseButton, MouseEvent, MouseEventKind};
|
||||
let (width, height) = (100, 30);
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = create_app();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
app.push_convo(ConvoBlock::Assistant(
|
||||
"Here is the answer:\n\n```rust\nlet answer = 42;\n```\n".into(),
|
||||
));
|
||||
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
let row = (0..height)
|
||||
.find(|&y| row_text(&buffer, y, width).contains("copy"))
|
||||
.expect("the code-block copy affordance renders");
|
||||
let code = (0..height)
|
||||
.find(|&y| row_text(&buffer, y, width).contains("let answer = 42;"))
|
||||
.expect("the code renders");
|
||||
assert!(row < code, "the affordance is above the block, not a stray word under it");
|
||||
|
||||
// The block is framed: a rule above carrying the language and the copy affordance, a rule
|
||||
// below, and the two ending on the same column so they read as one box. The frame may be
|
||||
// *wider* than the code — a box around three words is still a box — but never narrower.
|
||||
let last_column = |y: u16| {
|
||||
(0..width).rev().find(|&x| buffer[(x, y)].symbol().trim() != "").expect("a drawn row")
|
||||
};
|
||||
let closing = (code + 1..height)
|
||||
.find(|&y| row_text(&buffer, y, width).trim().starts_with('\u{2500}'))
|
||||
.expect("the block is closed by a rule");
|
||||
assert_eq!(
|
||||
last_column(row),
|
||||
last_column(closing),
|
||||
"the frame's rules must line up: {:?} against {:?}",
|
||||
row_text(&buffer, row, width).trim_end(),
|
||||
row_text(&buffer, closing, width).trim_end(),
|
||||
);
|
||||
assert!(
|
||||
last_column(row) >= last_column(code),
|
||||
"the frame is at least as wide as what it frames: {:?}",
|
||||
row_text(&buffer, row, width).trim_end(),
|
||||
);
|
||||
assert!(
|
||||
row_text(&buffer, row, width).contains("rust"),
|
||||
"the opening rule names the language: {:?}",
|
||||
row_text(&buffer, row, width).trim_end(),
|
||||
);
|
||||
|
||||
let column = last_column(row) - 1;
|
||||
let event = |kind| MouseEvent { kind, column, row, modifiers: KeyModifiers::NONE };
|
||||
// The affordance sits on selectable text, so it acts on the release — a press there could
|
||||
// still be the start of a drag.
|
||||
assert!(matches!(
|
||||
route_mouse(&mut app, &event(MouseEventKind::Down(MouseButton::Left))),
|
||||
RouteAction::None
|
||||
));
|
||||
match route_mouse(&mut app, &event(MouseEventKind::Up(MouseButton::Left))) {
|
||||
RouteAction::Msg(message) => match *message {
|
||||
Msg::CopyText(text) => {
|
||||
assert!(text.contains("let answer = 42;"), "copies the code text, got {text:?}")
|
||||
}
|
||||
other => panic!("expected a CopyText message, got {other:?}"),
|
||||
},
|
||||
other => panic!("expected a copy message from the click, got {other:?}"),
|
||||
}
|
||||
}
|
||||
|
||||
/// Editor click-to-cursor: clicking a cell in the composer places the cursor at that visual
|
||||
/// position (the inverse of `visual_cursor`) — anchoring a selection there is what moves it.
|
||||
#[test]
|
||||
fn clicking_the_composer_places_the_cursor() {
|
||||
use crossterm::event::{MouseButton, MouseEvent, MouseEventKind};
|
||||
let (width, height) = (100, 30);
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = create_app();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
app.editor.insert_text("hello world");
|
||||
assert_eq!(app.editor.cursor(), 11, "cursor starts at the end of the inserted text");
|
||||
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
let row = (0..height)
|
||||
.find(|&y| row_text(&buffer, y, width).contains("hello world"))
|
||||
.expect("the composer text renders");
|
||||
// Click the 'w' of "world" (offset 6 in "hello world").
|
||||
let wx = (0..width).find(|&x| buffer[(x, row)].symbol() == "w").expect("the 'w' cell renders");
|
||||
let click = MouseEvent {
|
||||
kind: MouseEventKind::Down(MouseButton::Left),
|
||||
column: wx,
|
||||
row,
|
||||
modifiers: KeyModifiers::NONE,
|
||||
};
|
||||
// The press anchors a selection at that cell, which is what places the caret.
|
||||
assert!(matches!(route_mouse(&mut app, &click), RouteAction::None));
|
||||
assert_eq!(app.editor.cursor(), 6, "clicking the 'w' cell moves the cursor to offset 6");
|
||||
}
|
||||
|
||||
/// A click on plain transcript prose neither selects nor copies the message: prose is there to be
|
||||
/// read and dragged across, and a click that copies a whole message behind the reader's back was
|
||||
/// the single least predictable thing the mouse did.
|
||||
#[test]
|
||||
fn clicking_transcript_prose_neither_selects_nor_copies_it() {
|
||||
use crossterm::event::{MouseButton, MouseEvent, MouseEventKind};
|
||||
let (width, height) = (100, 30);
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = create_app();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
app.push_convo(ConvoBlock::User {
|
||||
text: "first message".into(),
|
||||
attached: Vec::new(),
|
||||
chips: Vec::new(),
|
||||
});
|
||||
app.push_convo(ConvoBlock::Assistant("second message reply".into()));
|
||||
app.push_convo(ConvoBlock::User {
|
||||
text: "third message".into(),
|
||||
attached: Vec::new(),
|
||||
chips: Vec::new(),
|
||||
});
|
||||
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
let row = (0..height)
|
||||
.find(|&y| row_text(&buffer, y, width).contains("second message"))
|
||||
.expect("the second block renders");
|
||||
let event = |kind| MouseEvent { kind, column: 10, row, modifiers: KeyModifiers::NONE };
|
||||
for kind in [MouseEventKind::Down(MouseButton::Left), MouseEventKind::Up(MouseButton::Left)] {
|
||||
let action = route_mouse(&mut app, &event(kind));
|
||||
apply(&mut app, action);
|
||||
}
|
||||
assert_eq!(app.selected_block, None, "a click leaves the keyboard selection alone");
|
||||
assert!(app.outbox.copy.is_none(), "and copies nothing");
|
||||
render_app(&mut app, &backend);
|
||||
assert!(app.outbox.copy.is_none(), "still nothing on the next frame");
|
||||
}
|
||||
228
crates/luxe-tui/tests/render/composer.rs
Normal file
228
crates/luxe-tui/tests/render/composer.rs
Normal file
@@ -0,0 +1,228 @@
|
||||
//! Composer — the input box: its border, its growth, pastes and the pickers anchored to it.
|
||||
|
||||
use super::*;
|
||||
|
||||
/// Finds the composer's rounded top-left corner cell.
|
||||
pub(super) fn composer_corner(buffer: &Buffer) -> (u16, u16) {
|
||||
(0..buffer.area.height)
|
||||
.flat_map(|y| (0..buffer.area.width).map(move |x| (x, y)))
|
||||
.find(|&(x, y)| buffer[(x, y)].symbol() == "╭")
|
||||
.expect("composer top-left corner")
|
||||
}
|
||||
|
||||
/// The outline used to change color with a vim-style editor mode whenever the statusline was
|
||||
/// hidden. It is the theme's base border color now, in every state.
|
||||
#[test]
|
||||
fn composer_border_keeps_the_base_color_in_every_state() {
|
||||
let (width, height) = (80, 24);
|
||||
let mut app = create_app();
|
||||
app.statusline_state.hide();
|
||||
let base = app.theme_styles.border_accent.fg.expect("base border color");
|
||||
|
||||
let buffer = render_app(&mut app, &test_backend(width, height));
|
||||
assert_eq!(buffer[composer_corner(&buffer)].fg, base, "empty composer");
|
||||
|
||||
app.editor.insert_text("typing");
|
||||
let buffer = render_app(&mut app, &test_backend(width, height));
|
||||
assert_eq!(buffer[composer_corner(&buffer)].fg, base, "composer holding a draft");
|
||||
|
||||
app.selected_block = Some(0);
|
||||
let buffer = render_app(&mut app, &test_backend(width, height));
|
||||
assert_eq!(buffer[composer_corner(&buffer)].fg, base, "conversation block selected");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn multiline_input_grows_the_composer_and_preserves_line_breaks() {
|
||||
let (width, height) = (80, 24);
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = create_app();
|
||||
app.editor.insert_text("alpha\nbeta");
|
||||
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
|
||||
assert!(row_text(&buffer, height - 4, width).contains("alpha"));
|
||||
assert!(row_text(&buffer, height - 3, width).contains("beta"));
|
||||
assert!(row_text(&buffer, height - 2, width).trim_start().starts_with('╰'));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_composer_grows_the_moment_the_draft_wraps() {
|
||||
// The prompt box is framed, so its text area is two columns narrower than the terminal.
|
||||
// Measuring the wrap at any wider value let the draft spill onto a second row while the frame
|
||||
// was still one row tall — the first line scrolled out of sight and only the wrapped word
|
||||
// showed until another keystroke arrived.
|
||||
let (width, height) = (80, 24);
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = create_app();
|
||||
// 73 a's + " bravo!": exactly 80 cells, so it fits a measurement that forgot the frame but not
|
||||
// the 78 the box actually draws at.
|
||||
let head = "a".repeat(73);
|
||||
app.editor.insert_text(&format!("{head} bravo!"));
|
||||
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
assert!(row_text(&buffer, height - 4, width).contains(&head), "the first row keeps the draft");
|
||||
assert!(row_text(&buffer, height - 3, width).contains("bravo!"), "the wrapped word is visible");
|
||||
assert!(row_text(&buffer, height - 2, width).trim_start().starts_with('╰'), "box bottom");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_composer_grows_beside_the_dock_at_the_column_it_actually_wraps_at() {
|
||||
// The sidebar case, which is where this was reported: the composer lives in the main column,
|
||||
// so the wrap column comes off *that* width, not the terminal's.
|
||||
let (width, height) = (160u16, 40u16);
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = seeded_app("nord", FixtureScenario::DockWide).unwrap();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
let metrics = luxe_tui::workspace_layout::resolve_workspace_layout(width);
|
||||
assert!(metrics.separator_width >= 1, "precondition: the dock sits beside the conversation");
|
||||
|
||||
// Sized so the trailing word overflows the real text area but would still fit the two extra
|
||||
// columns the old measurement assumed — the exact window where the box used to lag.
|
||||
// A column of air off the separator, then the frame
|
||||
let text_width = usize::from(metrics.conversation_width) - 3;
|
||||
let head = "a".repeat(text_width - " bravo!".len() + 2);
|
||||
app.editor.insert_text(&format!("{head} bravo!"));
|
||||
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
let composer_top =
|
||||
(0..height).rfind(|&y| row_text(&buffer, y, width).contains('╭')).expect("composer top");
|
||||
assert!(
|
||||
row_text(&buffer, composer_top + 1, width).contains(&head),
|
||||
"the first row keeps the draft: {}",
|
||||
buffer_to_string(&buffer)
|
||||
);
|
||||
assert!(
|
||||
row_text(&buffer, composer_top + 2, width).contains("bravo!"),
|
||||
"the wrapped word gets its own row: {}",
|
||||
buffer_to_string(&buffer)
|
||||
);
|
||||
}
|
||||
|
||||
pub(super) fn assert_composer_paste_background(app: &mut App, marker: &str) {
|
||||
let (width, height) = (80, 24);
|
||||
let backend = test_backend(width, height);
|
||||
let expected_bg = app.theme_styles.paste_indicator.bg.expect("paste background");
|
||||
let buffer = render_app(app, &backend);
|
||||
let row = height - 3;
|
||||
// The composer is flush to the edge, so its inner text starts at x=1 (border at x=0)
|
||||
let marker_start = 1 + "before ".len() as u16;
|
||||
let marker_end = marker_start + marker.len() as u16 - 1;
|
||||
let normal_bg = buffer[(1, row)].bg;
|
||||
|
||||
assert!(row_text(&buffer, row, width).contains(&format!("before {marker} after")));
|
||||
assert_ne!(normal_bg, expected_bg);
|
||||
for column in marker_start..=marker_end {
|
||||
assert_eq!(buffer[(column, row)].bg, expected_bg, "column {column}");
|
||||
}
|
||||
assert_eq!(buffer[(marker_end + 2, row)].bg, normal_bg);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn compact_text_paste_has_a_distinct_background() {
|
||||
let mut app = create_app();
|
||||
app.editor.insert_text("before ");
|
||||
app.editor.paste_text("one\ntwo\nthree");
|
||||
app.editor.insert_text(" after");
|
||||
|
||||
assert_composer_paste_background(&mut app, "[Pasted 3 lines]");
|
||||
}
|
||||
|
||||
#[cfg(feature = "clipboard-images")]
|
||||
#[test]
|
||||
fn compact_image_paste_uses_clean_wording_and_a_distinct_background() {
|
||||
let mut app = create_app();
|
||||
app.editor.insert_text("before ");
|
||||
assert!(app.editor.attach_image(vec![255, 0, 0, 255], 1, 1));
|
||||
app.editor.insert_text(" after");
|
||||
|
||||
assert_composer_paste_background(&mut app, "[Pasted Image]");
|
||||
}
|
||||
|
||||
/// A slash command being typed shows in the composer.
|
||||
#[test]
|
||||
fn a_slash_command_being_typed_shows_in_the_composer() {
|
||||
let backend = test_backend(80, 24);
|
||||
let mut app = create_app();
|
||||
app.editor.insert_text("/help");
|
||||
|
||||
let rendered = buffer_to_string(&render_app(&mut app, &backend));
|
||||
|
||||
assert!(rendered.contains("/help"), "the command is missing: {rendered}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_slash_picker_is_anchored_to_input() {
|
||||
let (w, h) = (80, 24);
|
||||
let backend = test_backend(w, h);
|
||||
let mut app = create_app();
|
||||
app.update(Msg::Key(key(KeyCode::Char('/'))));
|
||||
app.update(Msg::Key(key(KeyCode::Char('h'))));
|
||||
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
let content = buffer_to_string(&buffer);
|
||||
let picker_title_row = (0..h)
|
||||
.find(|&y| row_text(&buffer, y, w).contains(" Commands "))
|
||||
.expect("slash picker title");
|
||||
|
||||
assert!(picker_title_row > 0, "picker must not be pinned to the top edge");
|
||||
// The picker sits one row above the composer and shares its column
|
||||
assert_eq!(buffer[(0, h - 5)].symbol(), "╰", "picker bottom-left must align with the composer");
|
||||
assert!(content.contains("│/h"), "query should render without a prompt glyph: {content}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn slash_picker_matches_composer_width_beside_the_dock() {
|
||||
// Regression: the slash/@ pickers used to render at the full terminal width, so beside a
|
||||
// side-by-side dock they spilled over the sidebar. They must inherit the composer's column.
|
||||
let (w, h) = (160u16, 40u16);
|
||||
let backend = test_backend(w, h);
|
||||
let mut app = seeded_app("nord", FixtureScenario::DockWide).unwrap();
|
||||
app.update(Msg::TerminalResized { width: w, height: h });
|
||||
|
||||
let metrics = luxe_tui::workspace_layout::resolve_workspace_layout(w);
|
||||
assert!(metrics.dock_width > 0 && metrics.separator_width >= 1, "precondition: side-by-side");
|
||||
|
||||
app.update(Msg::Key(key(KeyCode::Char('/'))));
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
|
||||
// The composer box (rounded corners) defines the promptbox width.
|
||||
let comp_row =
|
||||
(0..h).find(|&y| row_text(&buffer, y, w).contains('╭')).expect("composer top border");
|
||||
let comp_left = (0..w).find(|&x| buffer[(x, comp_row)].symbol() == "╭").unwrap();
|
||||
let comp_right = (comp_left..w).find(|&x| buffer[(x, comp_row)].symbol() == "╮").unwrap();
|
||||
|
||||
// The picker box shares the composer's rounded corners and must line up with it, not the
|
||||
// terminal edges.
|
||||
let title_row = (0..h)
|
||||
.find(|&y| row_text(&buffer, y, w).contains(" Commands "))
|
||||
.expect("slash picker title");
|
||||
let flyout_left = (0..w).find(|&x| buffer[(x, title_row)].symbol() == "╭").unwrap();
|
||||
let flyout_right = (flyout_left..w).find(|&x| buffer[(x, title_row)].symbol() == "╮").unwrap();
|
||||
|
||||
assert_eq!(flyout_left, comp_left, "picker left edge must match the composer");
|
||||
assert_eq!(flyout_right, comp_right, "picker right edge must match the composer");
|
||||
assert!(
|
||||
flyout_left >= metrics.dock_width + metrics.separator_width,
|
||||
"picker must not cover the left sidebar (left={flyout_left}, dock={})",
|
||||
metrics.dock_width
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_mention_picker_is_anchored_to_input() {
|
||||
let (w, h) = (80, 24);
|
||||
let backend = test_backend(w, h);
|
||||
let mut app = create_app();
|
||||
app.update(Msg::Key(key(KeyCode::Char('@'))));
|
||||
app.update(Msg::Key(key(KeyCode::Char('c'))));
|
||||
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
let content = buffer_to_string(&buffer);
|
||||
let picker_title_row = (0..h)
|
||||
.find(|&y| row_text(&buffer, y, w).contains(" Files "))
|
||||
.expect("mention picker title");
|
||||
|
||||
assert!(picker_title_row > 0, "picker must not be pinned to the top edge");
|
||||
assert_eq!(buffer[(0, h - 5)].symbol(), "╰", "picker bottom-left must align with the composer");
|
||||
assert!(content.contains("│@c"), "query should render without a prompt glyph: {content}");
|
||||
}
|
||||
632
crates/luxe-tui/tests/render/dock.rs
Normal file
632
crates/luxe-tui/tests/render/dock.rs
Normal file
@@ -0,0 +1,632 @@
|
||||
//! Dock — the rail's sections, its changes, counts and scrolling.
|
||||
|
||||
use super::*;
|
||||
|
||||
pub(super) fn empty_workspace(scope: &str) -> WorkspaceSnapshot {
|
||||
WorkspaceSnapshot::empty(
|
||||
WorkspaceScopeId::new(scope),
|
||||
ProjectIdentity::non_git("/work/luxe".into(), "luxe", "~/work/luxe"),
|
||||
)
|
||||
}
|
||||
|
||||
/// The Changes dock section always surfaces the way into review when there are changes (not only
|
||||
/// on overflow), and it says which key, so review stays discoverable without a keymap lookup.
|
||||
#[test]
|
||||
fn changes_section_surfaces_the_review_changes_affordance() {
|
||||
let (width, height) = (160, 40);
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = create_app();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
let mut snapshot = empty_workspace("changes-affordance");
|
||||
snapshot.changes = WorkspaceChangesSummary {
|
||||
files: vec![FileChangeSummary {
|
||||
path: "src/lib.rs".into(),
|
||||
status: FileChangeStatus::Modified,
|
||||
additions: Some(2),
|
||||
deletions: Some(1),
|
||||
binary: false,
|
||||
}],
|
||||
total_files: 1,
|
||||
additions: Some(2),
|
||||
deletions: Some(1),
|
||||
truncated: false,
|
||||
};
|
||||
app.workspace = Some(snapshot);
|
||||
|
||||
let content = buffer_to_string(&render_app(&mut app, &backend));
|
||||
assert!(content.contains("FILES"), "Files section renders: {content}");
|
||||
assert!(
|
||||
content.contains("ctrl+p preview · ctrl+g review"),
|
||||
"the Changes section surfaces both ways in, even without overflow: {content}"
|
||||
);
|
||||
}
|
||||
|
||||
/// A folder row is a name and nothing else. The ± numbers belong to the file rows under it;
|
||||
/// repeating a total on every folder doubled the digits in a 42-cell rail for no new information.
|
||||
/// A file at the project root sits at the tree's top level, under no heading at all.
|
||||
#[test]
|
||||
fn the_tree_counts_on_files_and_never_on_folders() {
|
||||
let (width, height) = (160, 40);
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = create_app();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
let changed = |path: &str, additions, deletions| FileChangeSummary {
|
||||
path: path.into(),
|
||||
status: FileChangeStatus::Modified,
|
||||
additions: Some(additions),
|
||||
deletions: Some(deletions),
|
||||
binary: false,
|
||||
};
|
||||
let mut snapshot = empty_workspace("changes-directories");
|
||||
snapshot.changes = WorkspaceChangesSummary {
|
||||
files: vec![
|
||||
changed("README.md", 7, 2),
|
||||
changed("src/lib.rs", 4, 1),
|
||||
changed("src/app.rs", 9, 3),
|
||||
],
|
||||
total_files: 3,
|
||||
additions: Some(20),
|
||||
deletions: Some(6),
|
||||
truncated: false,
|
||||
};
|
||||
app.workspace = Some(snapshot);
|
||||
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
let row = |needle: &str| {
|
||||
(0..height)
|
||||
.map(|y| row_text(&buffer, y, width))
|
||||
.find(|text| text.contains(needle))
|
||||
.unwrap_or_else(|| panic!("no dock row containing {needle:?}"))
|
||||
};
|
||||
let unnumbered = |text: &str| !text.contains('+') && !text.contains('\u{2212}');
|
||||
|
||||
let root = row("README.md");
|
||||
assert!(root.contains("+7") && root.contains('M'), "a root file is a row like any: {root}");
|
||||
let source = row(" src");
|
||||
assert!(unnumbered(&source), "a folder carries no counts: {source}");
|
||||
// The files still carry theirs — that is where the numbers were always readable.
|
||||
let file = row("app.rs");
|
||||
assert!(file.contains("+9") && file.contains('\u{2212}'), "file counts stay: {file}");
|
||||
}
|
||||
|
||||
/// The hint names keys, and never a click — without mouse capture the terminal keeps the pointer,
|
||||
/// and a row that offered a click would be advertising a gesture that does nothing.
|
||||
#[test]
|
||||
fn the_change_hints_name_keys_rather_than_promising_a_click() {
|
||||
let (width, height) = (160, 40);
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = create_app_with_config(Config { mouse: Some(false), ..Config::default() });
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
let mut snapshot = empty_workspace("changes-hint-no-mouse");
|
||||
snapshot.changes = WorkspaceChangesSummary {
|
||||
files: vec![FileChangeSummary {
|
||||
path: "src/lib.rs".into(),
|
||||
status: FileChangeStatus::Modified,
|
||||
additions: Some(2),
|
||||
deletions: Some(1),
|
||||
binary: false,
|
||||
}],
|
||||
total_files: 1,
|
||||
additions: Some(2),
|
||||
deletions: Some(1),
|
||||
truncated: false,
|
||||
};
|
||||
app.workspace = Some(snapshot);
|
||||
|
||||
let content = buffer_to_string(&render_app(&mut app, &backend));
|
||||
assert!(content.contains("ctrl+p preview · ctrl+g review"), "the keys are named: {content}");
|
||||
assert!(!content.contains("Click"), "and no click is offered: {content}");
|
||||
}
|
||||
|
||||
/// The review's open comments stay on the wire and off the rail.
|
||||
///
|
||||
/// The count is `Draft + Open + NeedsVerification` — one state the reader has already acted on and
|
||||
/// two that want them back — and the rail could reach none of them: it has no click target, and
|
||||
/// `Ctrl+G` captures a *new* review rather than resuming the pinned one. A row that names
|
||||
/// unfinished business with no route to it is worse than silence. `ReviewSummary` stays on the
|
||||
/// snapshot, which is a published protocol.
|
||||
#[test]
|
||||
fn the_dock_draws_no_review_section_for_a_snapshot_that_carries_open_comments() {
|
||||
let (width, height) = (160, 40);
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = create_app();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
let mut snapshot = empty_workspace("dock-review-gate");
|
||||
snapshot.review = Some(ReviewSummary {
|
||||
id: "review-1".into(),
|
||||
title: "Fix the stale reference".into(),
|
||||
source: "working tree".into(),
|
||||
unresolved_findings: 2,
|
||||
completed_at_ms: 2,
|
||||
});
|
||||
assert_eq!(
|
||||
snapshot.review.as_ref().map(|review| review.unresolved_findings),
|
||||
Some(2),
|
||||
"the snapshot still carries them"
|
||||
);
|
||||
app.workspace = Some(snapshot);
|
||||
|
||||
let content = buffer_to_string(&render_app(&mut app, &backend));
|
||||
assert!(content.contains("PROJECT"), "the rail still renders: {content}");
|
||||
assert!(!content.contains("REVIEW"), "no review heading: {content}");
|
||||
assert!(!content.contains("open comment"), "no comment count: {content}");
|
||||
assert!(!content.contains("Fix the stale reference"), "no review title: {content}");
|
||||
}
|
||||
|
||||
/// Clicking the dock's "Review changes" affordance opens Guided Review (plan B3 mouse hook): the
|
||||
/// render publishes a wrapping-aware region and the click dispatches `UiAction::ReviewOpen`.
|
||||
#[test]
|
||||
fn clicking_the_dock_review_changes_affordance_opens_review() {
|
||||
use crossterm::event::{MouseButton, MouseEvent, MouseEventKind};
|
||||
let (width, height) = (160, 40);
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = create_app();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
let mut snapshot = empty_workspace("dock-review-click");
|
||||
snapshot.changes = WorkspaceChangesSummary {
|
||||
files: vec![FileChangeSummary {
|
||||
path: "src/lib.rs".into(),
|
||||
status: FileChangeStatus::Modified,
|
||||
additions: Some(2),
|
||||
deletions: Some(1),
|
||||
binary: false,
|
||||
}],
|
||||
total_files: 1,
|
||||
additions: Some(2),
|
||||
deletions: Some(1),
|
||||
truncated: false,
|
||||
};
|
||||
app.workspace = Some(snapshot);
|
||||
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
let row = (0..height)
|
||||
.find(|&y| row_text(&buffer, y, width).contains("ctrl+g review"))
|
||||
.expect("the review affordance renders");
|
||||
let hints = row_text(&buffer, row, width).trim_end().to_string();
|
||||
assert!(hints.trim_start().starts_with("ctrl+p preview · ctrl+g review"), "{hints}");
|
||||
|
||||
// The row carries two affordances, so each has to answer for its own words.
|
||||
let click_at = |app: &mut _, column| {
|
||||
route_mouse(
|
||||
app,
|
||||
&MouseEvent {
|
||||
kind: MouseEventKind::Down(MouseButton::Left),
|
||||
column,
|
||||
row,
|
||||
modifiers: KeyModifiers::NONE,
|
||||
},
|
||||
)
|
||||
};
|
||||
let review_column =
|
||||
u16::try_from(hints.find("ctrl+g").expect("the review hint is on the row") + 2)
|
||||
.expect("a narrow rail");
|
||||
match click_at(&mut app, review_column) {
|
||||
RouteAction::Msg(message) => assert!(
|
||||
matches!(*message, Msg::DispatchUiAction(luxe_core::keymap::UiAction::ReviewOpen)),
|
||||
"clicking the review words dispatches ReviewOpen"
|
||||
),
|
||||
other => panic!("expected a ReviewOpen dispatch from the click, got {other:?}"),
|
||||
}
|
||||
let peek_column =
|
||||
u16::try_from(hints.find("ctrl+p").expect("the preview hint is on the row") + 2)
|
||||
.expect("a narrow rail");
|
||||
match click_at(&mut app, peek_column) {
|
||||
RouteAction::Msg(message) => assert!(
|
||||
matches!(*message, Msg::DispatchUiAction(luxe_core::keymap::UiAction::ToggleChanges)),
|
||||
"clicking the preview hint opens the preview, not the review"
|
||||
),
|
||||
other => panic!("expected a ToggleChanges dispatch from the click, got {other:?}"),
|
||||
}
|
||||
}
|
||||
|
||||
/// Clicking the dock's model row opens the model picker (plan B3): in the wide layout the
|
||||
/// statusline hides and MODEL telemetry relocates into the dock footer as a clickable row.
|
||||
#[test]
|
||||
fn clicking_the_dock_model_row_opens_the_model_picker() {
|
||||
use crossterm::event::{MouseButton, MouseEvent, MouseEventKind};
|
||||
let (width, height) = (160, 40);
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = create_app();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
app.workspace = Some(empty_workspace("dock-model-click"));
|
||||
app.status.model = "test-model-xyz".into();
|
||||
app.status.context_window = 128_000;
|
||||
app.status.context_pct = 10.0;
|
||||
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
let row = (0..height)
|
||||
.find(|&y| row_text(&buffer, y, width).contains("test-model-xyz"))
|
||||
.expect("the model row renders in the dock footer");
|
||||
let click = MouseEvent {
|
||||
kind: MouseEventKind::Down(MouseButton::Left),
|
||||
column: 5,
|
||||
row,
|
||||
modifiers: KeyModifiers::NONE,
|
||||
};
|
||||
match route_mouse(&mut app, &click) {
|
||||
RouteAction::Msg(message) => {
|
||||
assert!(matches!(*message, Msg::OpenModelPicker), "the model row opens the picker")
|
||||
}
|
||||
other => panic!("expected an open-model-picker message, got {other:?}"),
|
||||
}
|
||||
}
|
||||
|
||||
/// The mouse wheel scrolls the informational dock when the cursor is over the panel (there is no
|
||||
/// keyboard focus). A notch down advances the offset; the top clamps at zero.
|
||||
#[test]
|
||||
fn wheel_over_the_dock_scrolls_its_content() {
|
||||
// A short viewport so the dock's (bounded) sections overflow the middle and a real max exists.
|
||||
let (width, height) = (160, 12);
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = create_app();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
let mut snapshot = empty_workspace("dock-wheel-scroll");
|
||||
// Plan is a fixed-size section (heading + counts + one row per todo), so eight of them reliably
|
||||
// overflow a 12-row dock regardless of the height-scaled Changes cap.
|
||||
let items: Vec<TodoSummaryItem> = (0..8)
|
||||
.map(|n| TodoSummaryItem {
|
||||
id: n.to_string(),
|
||||
subject: format!("Task {n}"),
|
||||
status: TodoSummaryStatus::Pending,
|
||||
blocked_by: Vec::new(),
|
||||
})
|
||||
.collect();
|
||||
snapshot.todos =
|
||||
TodoSummary { pending: items.len(), total: items.len(), items, ..TodoSummary::default() };
|
||||
app.workspace = Some(snapshot);
|
||||
// Render once so the dock publishes its scroll region + max offset.
|
||||
let _ = render_app(&mut app, &backend);
|
||||
assert_eq!(app.dock.scroll, 0);
|
||||
|
||||
// A wheel over the dock rail (column 5) is inside the panel on a wide layout.
|
||||
use crossterm::event::MouseEventKind;
|
||||
let wheel = |kind| crossterm::event::MouseEvent {
|
||||
kind,
|
||||
column: 5,
|
||||
row: 10,
|
||||
modifiers: KeyModifiers::NONE,
|
||||
};
|
||||
match route_mouse(&mut app, &wheel(MouseEventKind::ScrollDown)) {
|
||||
RouteAction::Msg(message) => app.update(*message),
|
||||
other => {
|
||||
panic!("expected a dock-scroll message from a wheel over the panel, got {other:?}")
|
||||
}
|
||||
}
|
||||
assert!(app.dock.scroll > 0, "a wheel notch over the dock advances its scroll");
|
||||
|
||||
for _ in 0..5 {
|
||||
if let RouteAction::Msg(message) = route_mouse(&mut app, &wheel(MouseEventKind::ScrollUp)) {
|
||||
app.update(*message);
|
||||
}
|
||||
}
|
||||
assert_eq!(app.dock.scroll, 0, "scrolling back up clamps at the top");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn dock_position_right_places_the_full_height_sidebar_on_the_right() {
|
||||
let (width, height) = (160, 40);
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = create_app();
|
||||
app.dock.position = luxe_core::config::DockPosition::Right;
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
app.workspace = Some(empty_workspace("dock-right"));
|
||||
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
// The right rail hugs the right edge: panel starts at width - dock, its separator precedes it,
|
||||
// and the heading sits flush at the 1-col content margin into the panel.
|
||||
let dock_start = width - luxe_tui::workspace_layout::CONTEXT_DOCK_WIDTH;
|
||||
let separator_x = dock_start - 1;
|
||||
let context_x =
|
||||
(0..width).find(|&x| buffer[(x, 0)].symbol() == "P").expect("dock heading should render");
|
||||
assert_eq!(
|
||||
context_x,
|
||||
dock_start + 1 + DOCK_HEADING_LEAD,
|
||||
"right dock heading badge opens on the 1-col content margin into the panel"
|
||||
);
|
||||
assert_eq!(
|
||||
buffer[(separator_x, 0)].symbol(),
|
||||
"│",
|
||||
"separator on the top row precedes the right panel"
|
||||
);
|
||||
assert_eq!(
|
||||
buffer[(separator_x, height - 1)].symbol(),
|
||||
"│",
|
||||
"right sidebar separator should reach the bottom row (full height)"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hidden_statusline_relocates_model_telemetry_into_the_dock() {
|
||||
let (width, height) = (160, 40);
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = create_app();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
app.workspace = Some(empty_workspace("telemetry"));
|
||||
app.status.model = "gpt-4o".into();
|
||||
app.status.context_window = 128_000;
|
||||
app.status.context_pct = 42.0;
|
||||
app.status.prompt_tokens = 1_200;
|
||||
app.status.completion_tokens = 340;
|
||||
app.status.session = luxe_core::usage::SessionUsage::single(
|
||||
luxe_core::usage::UsageSource::Agent,
|
||||
luxe_core::usage::UsageTotals {
|
||||
calls: 3,
|
||||
prompt_tokens: 12_400,
|
||||
completion_tokens: 3_800,
|
||||
cost_usd: 0.42,
|
||||
..Default::default()
|
||||
},
|
||||
);
|
||||
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
let content = buffer_to_string(&buffer);
|
||||
// Wide + auto statusline => statusline hidden (the composer bottom-aligns), so telemetry
|
||||
// migrates into the dock instead of riding the bar.
|
||||
let composer_x = luxe_tui::workspace_layout::CONTEXT_DOCK_WIDTH
|
||||
+ luxe_tui::workspace_layout::CONTEXT_DOCK_SEPARATOR_WIDTH
|
||||
+ 1;
|
||||
assert_eq!(
|
||||
buffer[(composer_x, height - 1)].symbol(),
|
||||
"╰",
|
||||
"statusline should be hidden on wide: {content}"
|
||||
);
|
||||
// Two sections, because they answer two questions: what is answering, and what this session
|
||||
// has consumed — how full its window is, how many tokens went through it, what that cost.
|
||||
assert!(content.contains("MODEL"), "missing the model section: {content}");
|
||||
assert!(content.contains("gpt-4o"), "missing relocated model: {content}");
|
||||
assert!(content.contains("thinking"), "the model's reasoning level rides with it: {content}");
|
||||
assert!(content.contains("SESSION"), "missing the session section: {content}");
|
||||
assert!(content.contains("42% of 128k"), "missing relocated context usage: {content}");
|
||||
assert!(content.contains("$0.42"), "missing relocated session cost: {content}");
|
||||
assert!(!content.contains("CONTEXT"), "the meter reads under SESSION now: {content}");
|
||||
assert!(!content.contains("lsp "), "the constant lsp row is gone: {content}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn forced_statusline_beside_the_sidebar_keeps_the_dock_model_section() {
|
||||
let (width, height) = (160, 40);
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = create_app();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
app.workspace = Some(empty_workspace("beside"));
|
||||
app.status.model = "gpt-4o".into();
|
||||
app.statusline_state.show();
|
||||
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
let content = buffer_to_string(&buffer);
|
||||
// The sidebar's MODEL footer is decoupled from the statusline: a forced-on statusline sits
|
||||
// beside the full-height sidebar and BOTH carry telemetry (the sidebar keeps its own footer
|
||||
// rather than emptying it). `auto` still yields exactly one copy by hiding the bar.
|
||||
assert!(
|
||||
row_text(&buffer, height - 1, width).contains("gpt-4o"),
|
||||
"forced statusline should show the model on its bottom row: {content}"
|
||||
);
|
||||
assert!(content.contains("PROJECT"), "sidebar should still render: {content}");
|
||||
assert!(
|
||||
content.contains("MODEL"),
|
||||
"sidebar should keep its MODEL section even with the statusline shown: {content}"
|
||||
);
|
||||
// The sidebar remains full-height even with the statusline in the main column.
|
||||
let sep_x = luxe_tui::workspace_layout::CONTEXT_DOCK_WIDTH;
|
||||
assert_eq!(
|
||||
buffer[(sep_x, height - 1)].symbol(),
|
||||
"│",
|
||||
"sidebar should still reach the bottom row"
|
||||
);
|
||||
}
|
||||
|
||||
/// Diagnostics stay on the wire and off the rail.
|
||||
///
|
||||
/// The snapshot still carries them — `Event::WorkspaceUpdated` is a published protocol and an RPC
|
||||
/// front-end may want them — but the dock draws no section for them. The counts only cover files
|
||||
/// the agent edited this session with a warm language server attached, so a rail read as fact
|
||||
/// cannot show them: `✗ 0` there reads as "the project is clean" and means "nothing found in what I
|
||||
/// touched". The agent gets every diagnostic injected after the edit that caused it, which is where
|
||||
/// it can still be acted on.
|
||||
#[test]
|
||||
fn the_dock_draws_no_diagnostics_section_for_a_snapshot_that_carries_them() {
|
||||
let (width, height) = (160, 40);
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = create_app();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
let mut snapshot = empty_workspace("diagnostics");
|
||||
snapshot.diagnostics = DiagnosticsSummary {
|
||||
errors: 3,
|
||||
warnings: 2,
|
||||
infos: 0,
|
||||
hints: 0,
|
||||
files: vec![
|
||||
FileDiagnostics {
|
||||
path: "src/main.rs".into(),
|
||||
errors: 3,
|
||||
warnings: 1,
|
||||
infos: 0,
|
||||
hints: 0,
|
||||
},
|
||||
FileDiagnostics {
|
||||
path: "src/lib.rs".into(),
|
||||
errors: 0,
|
||||
warnings: 1,
|
||||
infos: 0,
|
||||
hints: 0,
|
||||
},
|
||||
],
|
||||
total_files: 5,
|
||||
truncated: true,
|
||||
};
|
||||
assert!(!snapshot.diagnostics.is_empty(), "the snapshot still carries them");
|
||||
app.workspace = Some(snapshot);
|
||||
|
||||
let content = buffer_to_string(&render_app(&mut app, &backend));
|
||||
assert!(content.contains("PROJECT"), "the rail still renders: {content}");
|
||||
assert!(!content.contains("DIAGNOSTICS"), "no diagnostics heading: {content}");
|
||||
assert!(!content.contains("src/main.rs"), "no per-file diagnostic row: {content}");
|
||||
assert!(!content.contains("3✗"), "no per-file counts: {content}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn idle_dock_omits_the_now_section() {
|
||||
let (width, height) = (160, 40);
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = create_app();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
// Empty snapshot: no attention, no telemetry, idle turn.
|
||||
app.workspace = Some(empty_workspace("idle"));
|
||||
|
||||
let content = buffer_to_string(&render_app(&mut app, &backend));
|
||||
assert!(content.contains("PROJECT"), "identity should still render: {content}");
|
||||
// NOW is attention-only now: an idle dock shows no permanent "● Idle" row.
|
||||
assert!(!content.contains("NOW"), "idle dock must omit the NOW heading: {content}");
|
||||
assert!(!content.contains("● Idle"), "idle dock must omit the '● Idle' row: {content}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn dock_footer_bottom_anchors_model_telemetry() {
|
||||
let (width, height) = (160, 40);
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = create_app();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
app.workspace = Some(empty_workspace("footer-telemetry"));
|
||||
app.status.model = "gpt-4o".into();
|
||||
app.status.context_window = 128_000;
|
||||
app.status.context_pct = 42.0;
|
||||
app.status.cost_usd = Some(0.42);
|
||||
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
let content = buffer_to_string(&buffer);
|
||||
assert!(content.contains("MODEL"), "footer should carry telemetry: {content}");
|
||||
let project_row = (0..height)
|
||||
.find(|&row| row_text(&buffer, row, width).contains("PROJECT"))
|
||||
.expect("PROJECT heading row");
|
||||
let model_row = (0..height)
|
||||
.find(|&row| row_text(&buffer, row, width).contains("MODEL"))
|
||||
.expect("MODEL heading row");
|
||||
// Identity stays at the top; telemetry sinks to the bottom near the composer.
|
||||
assert!(model_row > project_row, "telemetry should sit below identity: {content}");
|
||||
// Heading, model, thinking and mode, then SESSION's heading, context and cost
|
||||
assert!(
|
||||
model_row >= height - 7,
|
||||
"telemetry should be bottom-anchored (row {model_row} of {height}): {content}"
|
||||
);
|
||||
}
|
||||
|
||||
/// The CHANGES section colors each file's counts like its summary line and the Guided Review file
|
||||
/// rows: additions in the success color, deletions in the error color (not a flat muted run).
|
||||
#[test]
|
||||
fn dock_changes_group_rows_color_the_add_remove_counts() {
|
||||
let (width, height) = (160, 40);
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = create_app();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
let mut snapshot = empty_workspace("changes-color");
|
||||
snapshot.changes = WorkspaceChangesSummary {
|
||||
files: vec![FileChangeSummary {
|
||||
path: "src/lib.rs".into(),
|
||||
status: FileChangeStatus::Modified,
|
||||
additions: Some(12),
|
||||
deletions: Some(3),
|
||||
binary: false,
|
||||
}],
|
||||
total_files: 1,
|
||||
additions: Some(12),
|
||||
deletions: Some(3),
|
||||
truncated: false,
|
||||
};
|
||||
app.workspace = Some(snapshot);
|
||||
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
// The file row carries the counts; the heading over a single file leaves them to it.
|
||||
let row = (0..height)
|
||||
.find(|&y| {
|
||||
let text = row_text(&buffer, y, width);
|
||||
text.contains("lib.rs") && text.contains("+12")
|
||||
})
|
||||
.expect("the changed file row renders");
|
||||
let plus_col = (0..width).find(|&x| buffer[(x, row)].symbol() == "+").expect("additions count");
|
||||
let minus_col =
|
||||
(plus_col + 1..width).find(|&x| buffer[(x, row)].symbol() == "−").expect("deletions count");
|
||||
assert_eq!(
|
||||
buffer[(plus_col, row)].fg,
|
||||
app.theme_styles.success.fg.expect("success fg"),
|
||||
"additions should use the success color"
|
||||
);
|
||||
assert_eq!(
|
||||
buffer[(minus_col, row)].fg,
|
||||
app.theme_styles.error.fg.expect("error fg"),
|
||||
"deletions should use the error color"
|
||||
);
|
||||
}
|
||||
|
||||
/// The dock's changed files are a list you pick from, so the one under the pointer is cut from the
|
||||
/// slab that means *chosen* everywhere else — tapering into the rail's own fill, not the color
|
||||
/// behind it, and without moving the name off the column it shares with every other row.
|
||||
#[test]
|
||||
fn a_hovered_dock_file_row_is_cut_into_a_slab_on_the_rails_own_fill() {
|
||||
luxe_tui::glyphs::set_tier(luxe_tui::glyphs::GlyphTier::Nerd);
|
||||
let (width, height) = (160, 40);
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = create_app();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
// Every bundled theme paints the rail the same color as the app background, which would let a
|
||||
// cap cut against the wrong canvas pass unnoticed. A theme is free to raise it, so this one
|
||||
// does.
|
||||
const RAIL: ratatui::style::Color = ratatui::style::Color::Rgb(0x21, 0x1e, 0x1a);
|
||||
app.theme_styles.tool_bg = ratatui::style::Style::new().bg(RAIL);
|
||||
let mut snapshot = empty_workspace("changes-hover");
|
||||
let file = |path: &str| FileChangeSummary {
|
||||
path: path.into(),
|
||||
status: FileChangeStatus::Modified,
|
||||
additions: Some(4),
|
||||
deletions: Some(1),
|
||||
binary: false,
|
||||
};
|
||||
snapshot.changes = WorkspaceChangesSummary {
|
||||
files: vec![file("src/lib.rs"), file("src/main.rs")],
|
||||
total_files: 2,
|
||||
additions: Some(8),
|
||||
deletions: Some(2),
|
||||
truncated: false,
|
||||
};
|
||||
app.workspace = Some(snapshot);
|
||||
|
||||
let plain = render_app(&mut app, &backend);
|
||||
app.pointer.hover = Some(luxe_tui::mouse::MouseTarget::DockFile("src/lib.rs".into()));
|
||||
let hovered = render_app(&mut app, &backend);
|
||||
|
||||
let column = |buffer: &ratatui::buffer::Buffer, needle: &str| -> (u16, u16) {
|
||||
(0..height)
|
||||
.find_map(|y| {
|
||||
let text = row_text(buffer, y, width);
|
||||
text.find(needle)
|
||||
.map(|byte| (unicode_width::UnicodeWidthStr::width(&text[..byte]) as u16, y))
|
||||
})
|
||||
.unwrap_or_else(|| panic!("the {needle} row renders"))
|
||||
};
|
||||
let (name_x, row) = column(&hovered, "lib.rs");
|
||||
assert_eq!(
|
||||
(name_x, row),
|
||||
column(&plain, "lib.rs"),
|
||||
"the indent a file row already spent is the slab's own frame, so nothing moves"
|
||||
);
|
||||
|
||||
let line = row_text(&hovered, row, width);
|
||||
let cap = luxe_tui::widgets::Cap::Open.glyph();
|
||||
let cut = line.find(cap).expect("the hovered row opens on a cut");
|
||||
let cut_x = unicode_width::UnicodeWidthStr::width(&line[..cut]) as u16;
|
||||
assert!(cut_x < name_x, "and the cut opens before the name: {line:?}");
|
||||
|
||||
// A cap is the slab's color over the canvas *behind* it. On a raised rail that canvas is the
|
||||
// rail's own fill; against the app background it would leave a notch at the diagonal.
|
||||
assert_eq!(
|
||||
hovered[(cut_x, row)].bg,
|
||||
RAIL,
|
||||
"the cut tapers into the rail, not into the color behind it"
|
||||
);
|
||||
assert_eq!(
|
||||
hovered[(cut_x, row)].fg,
|
||||
app.theme_styles.selected_bg.bg.expect("the theme defines a selection"),
|
||||
);
|
||||
// The row that is not hovered keeps the rail's fill and no cut at all.
|
||||
let (_, other) = column(&hovered, "main.rs");
|
||||
assert!(!row_text(&hovered, other, width).contains(cap), "only one row is chosen");
|
||||
}
|
||||
295
crates/luxe-tui/tests/render/elsewhere.rs
Normal file
295
crates/luxe-tui/tests/render/elsewhere.rs
Normal file
@@ -0,0 +1,295 @@
|
||||
//! Elsewhere — work done outside the project, listed in the rail.
|
||||
|
||||
use super::*;
|
||||
|
||||
/// A session that changed one file in a checkout of its own, somewhere else.
|
||||
pub(super) fn external_workspace() -> luxe_core::WorkspaceSnapshot {
|
||||
let mut snapshot = empty_workspace("elsewhere");
|
||||
snapshot.external = luxe_core::ExternalChangesSummary {
|
||||
roots: vec![luxe_core::ExternalRootSummary {
|
||||
root: "/work/sdk".into(),
|
||||
display_path: "~/work/sdk".into(),
|
||||
git_branch: Some("main".into()),
|
||||
git: true,
|
||||
files: vec![FileChangeSummary {
|
||||
path: "src/client.ts".into(),
|
||||
status: FileChangeStatus::Modified,
|
||||
additions: Some(18),
|
||||
deletions: Some(3),
|
||||
binary: false,
|
||||
}],
|
||||
total_files: 1,
|
||||
truncated: false,
|
||||
}],
|
||||
total_files: 1,
|
||||
additions: Some(18),
|
||||
deletions: Some(3),
|
||||
truncated: false,
|
||||
};
|
||||
snapshot
|
||||
}
|
||||
|
||||
/// Work done outside the project gets its own section, and deliberately no way into review.
|
||||
///
|
||||
/// A review is captured from the project's Git worktree and its chapters end in commits to it, so
|
||||
/// a file that lives somewhere else can never be one of its items. Offering the affordance over
|
||||
/// these rows would advertise something the review cannot do — a *peek* is a promise the section
|
||||
/// can keep, and that is the one its rows carry.
|
||||
#[test]
|
||||
fn dock_lists_external_work_without_offering_to_review_it() {
|
||||
let (width, height) = (160, 44);
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = create_app();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
app.workspace = Some(external_workspace());
|
||||
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
let content = buffer_to_string(&buffer);
|
||||
assert!(content.contains("ELSEWHERE"), "the section is drawn: {content}");
|
||||
assert!(content.contains("1 file outside this project"), "singular, and it says where");
|
||||
assert!(content.contains("~/work/sdk"), "the place is named");
|
||||
assert!(content.contains("main"), "and its branch, since Git reports the whole tree there");
|
||||
assert!(content.contains("client.ts"), "with the file under it");
|
||||
assert!(
|
||||
!content.contains("to review"),
|
||||
"no review affordance: a project review cannot contain these files\n{content}"
|
||||
);
|
||||
}
|
||||
|
||||
/// A file listed elsewhere opens the same way a file listed in CHANGES does.
|
||||
///
|
||||
/// The rows are drawn in the project's own hand — same marker, same ±, same indent — so a reader
|
||||
/// who has learned that a file name opens its change has already been told these do too. They
|
||||
/// carry the absolute path, which is what tells every surface downstream that the project's Git
|
||||
/// cannot answer for them.
|
||||
#[test]
|
||||
fn clicking_an_elsewhere_row_peeks_that_file() {
|
||||
let (width, height) = (160, 44);
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = create_app();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
app.workspace = Some(external_workspace());
|
||||
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
let row = dock_row_containing(&buffer, "client.ts", height);
|
||||
match left_click(&mut app, 5, row) {
|
||||
RouteAction::Msg(message) => assert!(
|
||||
matches!(&*message, Msg::OpenChanges(path) if path == "/work/sdk/src/client.ts"),
|
||||
"expected the file's absolute path, got {message:?}"
|
||||
),
|
||||
other => panic!("expected a peek to open from the click, got {other:?}"),
|
||||
}
|
||||
}
|
||||
|
||||
/// Looking at a file elsewhere is the only thing that can happen to it, so it is what makes the
|
||||
/// section recede: a place with nothing left unread folds to its heading.
|
||||
///
|
||||
/// Driven through the pane the way a reader would, because the recording is the peek's own doing:
|
||||
/// nothing else marks these files, and a look that did not mark one would leave the section
|
||||
/// growing for the whole session no matter what the reader did about it.
|
||||
#[test]
|
||||
fn an_elsewhere_place_folds_once_everything_under_it_has_been_seen() {
|
||||
let (width, height) = (160, 44);
|
||||
let backend = test_backend(width, height);
|
||||
let (mut app, mut rx) = create_app_with_engine();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
app.workspace = Some(external_workspace());
|
||||
|
||||
let content = buffer_to_string(&render_app(&mut app, &backend));
|
||||
assert!(content.contains("client.ts"), "unread work is listed: {content}");
|
||||
|
||||
let path = "/work/sdk/src/client.ts";
|
||||
open_changes_with(&mut app, &mut rx, path, Some(one_hunk_file(path)));
|
||||
let reading = buffer_to_string(&render_app(&mut app, &backend));
|
||||
assert!(
|
||||
reading.contains("client.ts"),
|
||||
"the row stays while the pane is showing it — a fold here would take it out from under \
|
||||
the click that opened it: {reading}"
|
||||
);
|
||||
|
||||
app.update(Msg::CloseChanges);
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
let content = buffer_to_string(&buffer);
|
||||
assert!(!content.contains("client.ts"), "a place with nothing unread folds away: {content}");
|
||||
assert!(content.contains("~/work/sdk"), "but never silently: {content}");
|
||||
assert!(content.contains("1 file"), "and it says how much is under it: {content}");
|
||||
|
||||
// The heading is the control, so a folded place can always be opened again.
|
||||
let row = dock_row_containing(&buffer, "~/work/sdk", height);
|
||||
match left_click(&mut app, 5, row) {
|
||||
RouteAction::Msg(message) => {
|
||||
assert!(
|
||||
matches!(&*message, Msg::ToggleExternalPlace(place) if place == "/work/sdk"),
|
||||
"expected the place to toggle, got {message:?}"
|
||||
);
|
||||
app.update(*message);
|
||||
}
|
||||
other => panic!("expected a fold toggle from the click, got {other:?}"),
|
||||
}
|
||||
let content = buffer_to_string(&render_app(&mut app, &backend));
|
||||
assert!(content.contains("client.ts"), "unfolded by hand: {content}");
|
||||
}
|
||||
|
||||
/// Files elsewhere are grouped under folder headings the way the project's own are, so a folder
|
||||
/// reads the same wherever the rail draws one.
|
||||
///
|
||||
/// A file at a place's own root gets no heading: the place above it already is its directory, and
|
||||
/// a `/ (root)` row under it would say the same thing twice.
|
||||
#[test]
|
||||
fn elsewhere_groups_its_files_under_folder_headings() {
|
||||
let (width, height) = (160, 44);
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = create_app();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
app.workspace = Some(places_workspace("elsewhere-folders", 1, 2));
|
||||
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
let rail = luxe_tui::workspace_layout::CONTEXT_DOCK_WIDTH;
|
||||
// Where a row's name starts, after its guides, chevron and icon: what the eye reads as nesting.
|
||||
let indent = |needle: &str| {
|
||||
let row = row_text(&buffer, dock_row_containing(&buffer, needle, height), rail);
|
||||
row[..row.find(needle).expect("the row has it")].chars().count()
|
||||
};
|
||||
|
||||
// Place, then folder, then the files under it — each a step further in.
|
||||
let (place, folder, file) = (indent("~/work/place0"), indent("nested"), indent("file00.ts"));
|
||||
assert!(place < folder && folder < file, "place {place}, folder {folder}, file {file}");
|
||||
|
||||
// The file sitting at the place's own root skips the folder level entirely.
|
||||
assert_eq!(indent("root.ts"), folder, "a root file sits where a folder heading would");
|
||||
let content = buffer_to_string(&buffer);
|
||||
assert!(!content.contains("(root)"), "and needs no heading of its own: {content}");
|
||||
}
|
||||
|
||||
/// ELSEWHERE is a viewport onto every place, not the first three of them: the caps that used to
|
||||
/// count the rest are gone, and the lane beside it reaches them instead.
|
||||
#[test]
|
||||
fn every_place_elsewhere_is_reachable_by_scrolling() {
|
||||
let (width, height) = (160, 44);
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = create_app();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
app.workspace = Some(places_workspace("elsewhere-scroll", 6, 2));
|
||||
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
let content = buffer_to_string(&buffer);
|
||||
assert!(content.contains("~/work/place0"), "the first place leads: {content}");
|
||||
assert!(!content.contains("~/work/place5"), "and the last is below the fold");
|
||||
assert!(!content.contains("more place"), "counted places are gone: {content}");
|
||||
let lane = dock_scroll_lane(&buffer, "~/work/place0", height);
|
||||
assert_eq!(lane.first().copied(), Some(THUMB), "the thumb is at the top: {lane:?}");
|
||||
|
||||
// The wheel over the section moves the section, and reaches the last place.
|
||||
let row = dock_row_containing(&buffer, "~/work/place0", height);
|
||||
assert!(
|
||||
matches!(wheel_down(&mut app, 5, row), RouteAction::Msg(message)
|
||||
if matches!(*message, Msg::ScrollDockList { list: DockList::Elsewhere, up: false })),
|
||||
"the wheel over ELSEWHERE moves ELSEWHERE"
|
||||
);
|
||||
// One notch opens the window inside the first place — which still has to say which place, and
|
||||
// which folder, its rows are under.
|
||||
app.update(Msg::ScrollDockList { list: DockList::Elsewhere, up: false });
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
let rail = luxe_tui::workspace_layout::CONTEXT_DOCK_WIDTH;
|
||||
let headline = dock_row_containing(&buffer, "outside this project", height);
|
||||
let under = |offset: u16| row_text(&buffer, headline + offset, rail);
|
||||
assert!(under(1).contains("~/work/place0"), "the place is repeated: {:?}", under(1));
|
||||
assert!(under(2).contains("nested"), "and the folder inside it: {:?}", under(2));
|
||||
assert!(under(3).contains("file0"), "before the rows the window actually opened on");
|
||||
|
||||
let mut reached = false;
|
||||
for _ in 0..40 {
|
||||
app.update(Msg::ScrollDockList { list: DockList::Elsewhere, up: false });
|
||||
if buffer_to_string(&render_app(&mut app, &backend)).contains("~/work/place5") {
|
||||
reached = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
assert!(reached, "every place is reachable by scrolling");
|
||||
}
|
||||
|
||||
/// `count` places outside the project, each with `files` files under a folder plus one at its root.
|
||||
pub(super) fn places_workspace(scope: &str, count: usize, files: usize) -> WorkspaceSnapshot {
|
||||
let mut snapshot = empty_workspace(scope);
|
||||
let change = |path: String| FileChangeSummary {
|
||||
path: path.into(),
|
||||
status: FileChangeStatus::Modified,
|
||||
additions: Some(4),
|
||||
deletions: Some(1),
|
||||
binary: false,
|
||||
};
|
||||
let roots: Vec<luxe_core::ExternalRootSummary> = (0..count)
|
||||
.map(|place| {
|
||||
let mut entries: Vec<FileChangeSummary> =
|
||||
(0..files).map(|index| change(format!("nested/file{index:02}.ts"))).collect();
|
||||
entries.push(change("root.ts".to_string()));
|
||||
luxe_core::ExternalRootSummary {
|
||||
root: format!("/work/place{place}").into(),
|
||||
display_path: format!("~/work/place{place}"),
|
||||
git_branch: None,
|
||||
git: false,
|
||||
total_files: entries.len(),
|
||||
files: entries,
|
||||
truncated: false,
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
snapshot.external = luxe_core::ExternalChangesSummary {
|
||||
total_files: roots.iter().map(|root| root.total_files).sum(),
|
||||
additions: Some(4),
|
||||
deletions: Some(1),
|
||||
roots,
|
||||
truncated: false,
|
||||
};
|
||||
snapshot
|
||||
}
|
||||
|
||||
/// A file touched again since it was looked at is new work, whatever was read before — the same
|
||||
/// rule the project's own reviewed markers follow, and what keeps a fold from hiding fresh edits.
|
||||
#[test]
|
||||
fn work_done_elsewhere_since_the_last_look_comes_back_unread() {
|
||||
let (width, height) = (160, 44);
|
||||
let backend = test_backend(width, height);
|
||||
let (mut app, mut rx) = create_app_with_engine();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
app.workspace = Some(external_workspace());
|
||||
|
||||
let path = "/work/sdk/src/client.ts";
|
||||
open_changes_with(&mut app, &mut rx, path, Some(one_hunk_file(path)));
|
||||
app.update(Msg::CloseChanges);
|
||||
assert!(!buffer_to_string(&render_app(&mut app, &backend)).contains("client.ts"), "seen");
|
||||
|
||||
if let Some(workspace) = app.workspace.as_mut() {
|
||||
workspace.external.roots[0].files[0].additions = Some(40);
|
||||
}
|
||||
let content = buffer_to_string(&render_app(&mut app, &backend));
|
||||
assert!(content.contains("client.ts"), "touched again since, so unread again: {content}");
|
||||
}
|
||||
|
||||
/// The project's own Changes section keeps its way into review — the assertion above only means
|
||||
/// something if the affordance is present when it should be.
|
||||
#[test]
|
||||
fn dock_still_offers_review_for_the_projects_own_changes() {
|
||||
let (width, height) = (160, 44);
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = create_app();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
let mut snapshot = empty_workspace("changes");
|
||||
snapshot.changes = WorkspaceChangesSummary {
|
||||
files: vec![FileChangeSummary {
|
||||
path: "src/lib.rs".into(),
|
||||
status: FileChangeStatus::Modified,
|
||||
additions: Some(1),
|
||||
deletions: Some(0),
|
||||
binary: false,
|
||||
}],
|
||||
total_files: 1,
|
||||
additions: Some(1),
|
||||
deletions: Some(0),
|
||||
truncated: false,
|
||||
};
|
||||
app.workspace = Some(snapshot);
|
||||
|
||||
let content = buffer_to_string(&render_app(&mut app, &backend));
|
||||
assert!(content.contains("ctrl+g review"), "in-project changes lead to a review: {content}");
|
||||
}
|
||||
297
crates/luxe-tui/tests/render/files.rs
Normal file
297
crates/luxe-tui/tests/render/files.rs
Normal file
@@ -0,0 +1,297 @@
|
||||
//! Files — the project tree, the file view and the start screen's flyouts.
|
||||
|
||||
use super::*;
|
||||
|
||||
/// The next action the app sends that is not the tree asking for a folder.
|
||||
pub(super) fn next_action_but_listings(
|
||||
rx: &mut tokio::sync::mpsc::Receiver<luxe_core::engine::Action>,
|
||||
) -> luxe_core::engine::Action {
|
||||
loop {
|
||||
match rx.try_recv().expect("an action was sent") {
|
||||
luxe_core::engine::Action::ListDirectory { .. } => continue,
|
||||
action => return action,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Opens `path` from the tree as an unchanged file, and lands `text` as what the engine read.
|
||||
pub(super) fn open_file_view(
|
||||
app: &mut App,
|
||||
rx: &mut tokio::sync::mpsc::Receiver<luxe_core::engine::Action>,
|
||||
path: &str,
|
||||
text: &str,
|
||||
) {
|
||||
app.update(Msg::OpenProjectFile(path.to_string()));
|
||||
let request_id = match next_action_but_listings(rx) {
|
||||
luxe_core::engine::Action::ReadProjectFile { request_id, path: asked } => {
|
||||
assert_eq!(asked, path, "it reads the file it is showing");
|
||||
request_id
|
||||
}
|
||||
other => panic!("an unchanged file is read, not diffed: {other:?}"),
|
||||
};
|
||||
app.update(Msg::Engine(luxe_core::event::Event::ProjectFileRead {
|
||||
request_id,
|
||||
file: Box::new(luxe_core::project_files::ProjectFile {
|
||||
path: path.to_string(),
|
||||
text: text.to_string(),
|
||||
bytes: text.len() as u64,
|
||||
truncated: false,
|
||||
binary: false,
|
||||
}),
|
||||
}));
|
||||
}
|
||||
|
||||
/// A workspace arriving is what asks for the project root, and a listing that lands is drawn
|
||||
/// beside the changes — the tree is the project, not only the part of it that changed.
|
||||
#[test]
|
||||
fn the_tree_lists_the_project_beside_its_changes() {
|
||||
let (width, height) = (160, 40);
|
||||
let backend = test_backend(width, height);
|
||||
let (mut app, mut rx) = create_app_with_engine();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
app.update(Msg::Engine(luxe_core::event::Event::WorkspaceUpdated(Box::new(
|
||||
changed_workspace("tree-listing", 1),
|
||||
))));
|
||||
let request_id = match rx.try_recv().expect("the root is asked for") {
|
||||
luxe_core::engine::Action::ListDirectory { request_id, path, .. } => {
|
||||
assert_eq!(path, "", "the project root first");
|
||||
request_id
|
||||
}
|
||||
other => panic!("expected a listing request, got {other:?}"),
|
||||
};
|
||||
let entry = |name: &str, kind| luxe_core::project_files::DirectoryEntry {
|
||||
name: name.into(),
|
||||
kind,
|
||||
ignored: false,
|
||||
};
|
||||
use luxe_core::project_files::EntryKind;
|
||||
app.update(Msg::Engine(luxe_core::event::Event::DirectoryListed {
|
||||
request_id,
|
||||
listing: luxe_core::project_files::DirectoryListing {
|
||||
path: String::new(),
|
||||
entries: vec![
|
||||
entry("docs", EntryKind::Directory),
|
||||
entry("src", EntryKind::Directory),
|
||||
entry("Cargo.toml", EntryKind::File),
|
||||
],
|
||||
omitted: 0,
|
||||
},
|
||||
}));
|
||||
let content = buffer_to_string(&render_app(&mut app, &backend));
|
||||
assert!(content.contains("Cargo.toml"), "an unchanged file is in the tree: {content}");
|
||||
assert!(content.contains("docs"), "and a folder nothing changed in: {content}");
|
||||
assert!(content.contains("file00.rs"), "and the change, revealed: {content}");
|
||||
}
|
||||
|
||||
/// A file that did not change opens whole, numbered and highlighted, with no Diff to switch to.
|
||||
#[test]
|
||||
fn an_unchanged_file_opens_whole_in_the_file_view() {
|
||||
let (width, height) = (160, 40);
|
||||
let backend = test_backend(width, height);
|
||||
let (mut app, mut rx) = create_app_with_engine();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
app.workspace = Some(changed_workspace("file-view", 1));
|
||||
open_file_view(&mut app, &mut rx, "README.md", "# Title\nsecond line\n");
|
||||
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
let content = buffer_to_string(&buffer);
|
||||
assert!(content.contains("README.md"), "the header names it: {content}");
|
||||
let second = row_containing(&buffer, "second line", width, height);
|
||||
assert!(row_text(&buffer, second, width).contains(" 2 "), "lines are numbered: {content}");
|
||||
assert!(!content.contains("DIFF"), "nothing changed, so there is no diff to show: {content}");
|
||||
assert!(content.contains("esc close"), "and it says how to leave: {content}");
|
||||
}
|
||||
|
||||
/// Dragging down the line numbers picks lines, and Ask turns the pick into a mention in the
|
||||
/// composer — a pointer to the lines, not a paste of them. (A drag over the code selects text.)
|
||||
#[test]
|
||||
fn picked_lines_become_a_mention_in_the_composer() {
|
||||
let (width, height) = (160, 40);
|
||||
let backend = test_backend(width, height);
|
||||
let (mut app, mut rx) = create_app_with_engine();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
app.workspace = Some(changed_workspace("file-pick", 1));
|
||||
open_file_view(&mut app, &mut rx, "README.md", "one\ntwo\nthree\nfour\n");
|
||||
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
let from = row_containing(&buffer, "two", width, height);
|
||||
let to = row_containing(&buffer, "three", width, height);
|
||||
// The number, the keyboard's mark, the change bar and a space come before the code
|
||||
let gutter = column_of(&row_text(&buffer, from, width), "two") - 4;
|
||||
use crossterm::event::{MouseButton, MouseEvent, MouseEventKind};
|
||||
for (kind, row) in [
|
||||
(MouseEventKind::Down(MouseButton::Left), from),
|
||||
(MouseEventKind::Drag(MouseButton::Left), to),
|
||||
(MouseEventKind::Up(MouseButton::Left), to),
|
||||
] {
|
||||
let event = MouseEvent { kind, column: gutter, row, modifiers: KeyModifiers::NONE };
|
||||
let action = route_mouse(&mut app, &event);
|
||||
apply(&mut app, action);
|
||||
}
|
||||
let content = buffer_to_string(&render_app(&mut app, &backend));
|
||||
assert!(content.contains("ask about lines 2–3"), "the pick offers the question: {content}");
|
||||
|
||||
app.update(Msg::PeekSelectionAction(luxe_tui::mouse::PeekSelectionAction::Ask));
|
||||
assert_eq!(app.editor.current_input().trim(), "@[file:README.md:2-3]");
|
||||
}
|
||||
|
||||
/// A right-click on a file in the tree offers what can be done with it, each with its key.
|
||||
#[test]
|
||||
fn a_right_click_on_a_file_opens_its_menu() {
|
||||
let (width, height) = (160, 40);
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = create_app();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
app.workspace = Some(changed_workspace("file-menu", 2));
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
let row = dock_row_containing(&buffer, "file00.rs", height);
|
||||
|
||||
use crossterm::event::{MouseButton, MouseEvent, MouseEventKind};
|
||||
let event = MouseEvent {
|
||||
kind: MouseEventKind::Down(MouseButton::Right),
|
||||
column: 12,
|
||||
row,
|
||||
modifiers: KeyModifiers::NONE,
|
||||
};
|
||||
route_mouse(&mut app, &event);
|
||||
let menu = app.overlays.context_menu.as_ref().expect("a menu opened");
|
||||
let labels: Vec<&str> = menu.items.iter().map(|item| item.label.as_str()).collect();
|
||||
assert!(labels.contains(&"Show the diff"), "a changed file offers its diff: {labels:?}");
|
||||
assert!(labels.contains(&"Copy path"), "{labels:?}");
|
||||
let content = buffer_to_string(&render_app(&mut app, &backend));
|
||||
assert!(content.contains("Open in editor"), "and it is drawn: {content}");
|
||||
|
||||
// A click anywhere else puts it away
|
||||
left_click(&mut app, 120, 2);
|
||||
assert!(app.overlays.context_menu.is_none());
|
||||
}
|
||||
|
||||
/// `Ctrl+T` puts the keyboard in the tree, the tree's own keys move through it, and `Enter` shows
|
||||
/// the file the cursor is on.
|
||||
#[test]
|
||||
fn the_keyboard_walks_the_tree() {
|
||||
let (width, height) = (160, 40);
|
||||
let (mut app, mut rx) = create_app_with_engine();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
app.workspace = Some(changed_workspace("file-keys", 2));
|
||||
let key = |code| Msg::Key(KeyEvent::new(code, KeyModifiers::NONE));
|
||||
|
||||
app.update(Msg::Key(KeyEvent::new(KeyCode::Char('t'), KeyModifiers::CONTROL)));
|
||||
assert!(app.files.focused, "the keyboard is in the tree");
|
||||
assert_eq!(app.files.cursor.as_deref(), Some("src"), "on its first row");
|
||||
for _ in 0..2 {
|
||||
app.update(key(KeyCode::Char('j')));
|
||||
}
|
||||
assert_eq!(app.files.cursor.as_deref(), Some("src/module00/file00.rs"));
|
||||
app.update(key(KeyCode::Enter));
|
||||
match next_action_but_listings(&mut rx) {
|
||||
luxe_core::engine::Action::LoadFileDiff { path, .. } => {
|
||||
assert_eq!(path, "src/module00/file00.rs", "a changed file opens on its diff")
|
||||
}
|
||||
other => panic!("expected the diff to load, got {other:?}"),
|
||||
}
|
||||
assert_eq!(app.editor.current_input(), "", "the keys moved the tree, not the draft");
|
||||
|
||||
app.update(key(KeyCode::Esc));
|
||||
assert!(!app.files.focused, "Esc gives the keyboard back");
|
||||
}
|
||||
|
||||
/// The peek's FILE / DIFF switch: both faces in capitals, both slabs, neither moving when the
|
||||
/// view flips, and the hidden face — the whole of it — is what a click reaches.
|
||||
#[test]
|
||||
fn the_view_switch_names_both_faces_and_the_hidden_one_takes_the_click() {
|
||||
let (width, height) = (200, 24);
|
||||
let backend = test_backend(width, height);
|
||||
let (mut app, mut rx) = create_app_with_engine();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
app.dock.hide();
|
||||
app.workspace = Some(changed_workspace("view-switch", 2));
|
||||
let path = "src/module00/file00.rs";
|
||||
open_changes_with(&mut app, &mut rx, path, Some(one_hunk_file(path)));
|
||||
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
let header = row_containing(&buffer, "DIFF", width, height);
|
||||
let text = row_text(&buffer, header, width);
|
||||
let (file_at, diff_at) = (text.find("FILE"), text.find("DIFF"));
|
||||
assert!(file_at.is_some(), "the hidden face is named in capitals too: {text}");
|
||||
assert!(!text.contains(" file "), "and never as a lowercase word: {text}");
|
||||
let file_x = text[..file_at.unwrap()].chars().count() as u16;
|
||||
let lit = buffer[(file_x + 1, header)].bg;
|
||||
assert_ne!(lit, buffer[(width - 1, header)].bg, "the hidden face sits on a slab of its own");
|
||||
|
||||
// Every cell of the hidden badge is the click target, and none of the showing one is
|
||||
for x in file_x.saturating_sub(2)..file_x + 4 + 4 {
|
||||
assert_eq!(
|
||||
app.hit.borrow().at(x, header),
|
||||
Some(&luxe_tui::mouse::MouseTarget::ChangesFooter(
|
||||
luxe_tui::mouse::ChangesFooterAction::ToggleView
|
||||
)),
|
||||
"column {x} of the hidden face toggles the view"
|
||||
);
|
||||
}
|
||||
let diff_x = text[..diff_at.unwrap()].chars().count() as u16;
|
||||
assert_eq!(app.hit.borrow().at(diff_x + 1, header), None, "the showing face is not a button");
|
||||
|
||||
app.update(Msg::DispatchUiAction(luxe_core::keymap::UiAction::ChangesToggleView));
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
let flipped = row_text(&buffer, header, width);
|
||||
assert_eq!(flipped.find("FILE"), file_at, "FILE holds its column when the view flips");
|
||||
assert_eq!(flipped.find("DIFF"), diff_at, "and so does DIFF");
|
||||
}
|
||||
|
||||
/// Drives a key through the start screen the way the event loop does.
|
||||
pub(super) fn press_on_dashboard(app: &mut App, code: KeyCode) {
|
||||
match route_key(app, &key(code)) {
|
||||
RouteAction::Msg(message) => app.update(*message),
|
||||
RouteAction::Dashboard(outcome) => app.handle_dashboard_outcome(outcome),
|
||||
RouteAction::None => {}
|
||||
other => panic!("{code:?} routed to {other:?}"),
|
||||
}
|
||||
}
|
||||
|
||||
/// The start screen's prompt is the session's composer, so `/` and `@` open its flyouts — under
|
||||
/// the prompt rather than over it, since here the room is below — and the launcher's list folds
|
||||
/// away while one is open.
|
||||
#[test]
|
||||
fn the_start_screens_prompt_opens_the_composers_flyouts_below_it() {
|
||||
let (width, height) = (140, 40);
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = seeded_app("nord", FixtureScenario::Dashboard).expect("the fixture");
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
|
||||
press_on_dashboard(&mut app, KeyCode::Char('@'));
|
||||
assert!(app.overlays.mention.is_some(), "@ opens the mention flyout");
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
let prompt = row_containing(&buffer, "build", width, height);
|
||||
let mention = row_containing(&buffer, "Mention", width, height);
|
||||
assert!(mention > prompt, "it hangs below the prompt: {mention} vs {prompt}");
|
||||
let screen = buffer_to_string(&buffer);
|
||||
assert!(!screen.contains("New session"), "and the list has made way for it: {screen}");
|
||||
|
||||
press_on_dashboard(&mut app, KeyCode::Esc);
|
||||
assert!(app.overlays.mention.is_none(), "esc puts it away");
|
||||
assert_eq!(app.current_view, ViewMode::Dashboard, "and nothing else");
|
||||
}
|
||||
|
||||
/// A command chosen from the slash flyout runs the way the launcher runs one: the theme picker
|
||||
/// opens over the start screen rather than in a session that is not there.
|
||||
#[test]
|
||||
fn a_command_chosen_from_the_slash_flyout_runs_on_the_start_screen() {
|
||||
let (width, height) = (140, 40);
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = seeded_app("nord", FixtureScenario::Dashboard).expect("the fixture");
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
for character in "/theme".chars() {
|
||||
press_on_dashboard(&mut app, KeyCode::Char(character));
|
||||
}
|
||||
assert!(app.overlays.slash_flyout.is_some(), "/ opens the command flyout");
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
let prompt = row_containing(&buffer, "build", width, height);
|
||||
let commands = row_containing(&buffer, "Commands", width, height);
|
||||
assert!(commands > prompt, "below the prompt: {commands} vs {prompt}");
|
||||
|
||||
press_on_dashboard(&mut app, KeyCode::Enter);
|
||||
assert!(app.overlays.theme_picker.is_some(), "the theme picker opened");
|
||||
assert_eq!(app.current_view, ViewMode::Dashboard, "over the start screen");
|
||||
assert!(app.editor.current_input().is_empty(), "and the command left the prompt");
|
||||
}
|
||||
441
crates/luxe-tui/tests/render/hints.rs
Normal file
441
crates/luxe-tui/tests/render/hints.rs
Normal file
@@ -0,0 +1,441 @@
|
||||
//! Hints — what an idle turn offers, the first-steps line and the review footer.
|
||||
|
||||
use super::*;
|
||||
|
||||
/// The turn-end invitation: quiet, honest, and only once a review has actually happened.
|
||||
#[test]
|
||||
fn an_idle_turn_invites_a_review_of_what_is_unreviewed() {
|
||||
let (width, height) = (120, 30);
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = create_app();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
let mut snapshot = empty_workspace("invitation");
|
||||
snapshot.changes = WorkspaceChangesSummary {
|
||||
files: vec![
|
||||
FileChangeSummary {
|
||||
path: "src/lib.rs".into(),
|
||||
status: FileChangeStatus::Modified,
|
||||
additions: Some(12),
|
||||
deletions: Some(3),
|
||||
binary: false,
|
||||
},
|
||||
FileChangeSummary {
|
||||
path: "src/new.rs".into(),
|
||||
status: FileChangeStatus::Added,
|
||||
additions: Some(40),
|
||||
deletions: Some(0),
|
||||
binary: false,
|
||||
},
|
||||
],
|
||||
total_files: 2,
|
||||
additions: Some(52),
|
||||
deletions: Some(3),
|
||||
truncated: false,
|
||||
};
|
||||
app.workspace = Some(snapshot);
|
||||
|
||||
// No prior review: "everything is unreviewed" is true and useless, so nothing is said.
|
||||
let first = buffer_to_string(&render_app(&mut app, &backend));
|
||||
assert!(!first.contains("since your last review"), "nothing to compare against: {first}");
|
||||
|
||||
// After a review that covered one of the two files, the other is the increment.
|
||||
app.review.seen = Some(luxe_core::guided_review::SeenReview {
|
||||
revision_id: None,
|
||||
at_ms: 1,
|
||||
item_ids: vec!["hunk:seen".into()],
|
||||
files: [("src/lib.rs".to_string(), (12, 3))].into_iter().collect(),
|
||||
});
|
||||
let content = buffer_to_string(&render_app(&mut app, &backend));
|
||||
|
||||
assert!(
|
||||
content.contains("1 file changed since your last review"),
|
||||
"the increment is named: {content}"
|
||||
);
|
||||
assert!(content.contains("ctrl+g to review"), "and it says how: {content}");
|
||||
assert!(
|
||||
!content.contains("for commands"),
|
||||
"the invitation is about something that happened, so it has the row: {content}"
|
||||
);
|
||||
}
|
||||
|
||||
/// The row above the composer, as text, and where the composer's frame starts.
|
||||
pub(super) fn row_above_composer(buffer: &Buffer, width: u16, height: u16) -> (String, u16) {
|
||||
let composer = (0..height)
|
||||
.rev()
|
||||
.find(|&y| {
|
||||
let row = row_text(buffer, y, width);
|
||||
row.contains('╭') && row.contains('╮')
|
||||
})
|
||||
.expect("the composer's frame");
|
||||
(row_text(buffer, composer - 1, width), composer)
|
||||
}
|
||||
|
||||
/// A conversation that has not started says where the composer's doors are, in the row above it,
|
||||
/// and says nothing once there is a message. Nothing else on screen names `/`, `Ctrl+K` or `@`.
|
||||
#[test]
|
||||
fn a_fresh_conversation_names_the_composers_doors_until_its_first_message() {
|
||||
let (width, height) = (190, 30);
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = create_app();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
|
||||
let (row, _) = row_above_composer(&render_app(&mut app, &backend), width, height);
|
||||
assert!(
|
||||
row.contains("shift+tab for plan mode · / or ctrl+k for commands · @ to reference files, skills, and more · /help for keys"),
|
||||
"{row:?}"
|
||||
);
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
let (row, composer) = row_above_composer(&buffer, width, height);
|
||||
let styled = |needle: &str| {
|
||||
let x = row[..row.find(needle).expect(needle)].chars().count() as u16;
|
||||
buffer[(x, composer - 1)].fg
|
||||
};
|
||||
assert_eq!(Some(styled("ctrl+k")), app.theme_styles.accent.fg, "a key reads as a key");
|
||||
assert_eq!(Some(styled("shift+tab")), app.theme_styles.accent.fg, "the mode key too");
|
||||
assert_eq!(Some(styled("for commands")), app.theme_styles.muted.fg, "the words stay quiet");
|
||||
|
||||
// A notice — the line `--issue` leaves — does not start a conversation
|
||||
app.push_convo(ConvoBlock::System("Issue #12 — will be sent with your first message.".into()));
|
||||
let (row, _) = row_above_composer(&render_app(&mut app, &backend), width, height);
|
||||
assert!(row.contains("for commands"), "a notice is not a conversation: {row:?}");
|
||||
|
||||
app.push_convo(ConvoBlock::User {
|
||||
text: "hello".into(),
|
||||
attached: Vec::new(),
|
||||
chips: Vec::new(),
|
||||
});
|
||||
let (row, _) = row_above_composer(&render_app(&mut app, &backend), width, height);
|
||||
assert!(!row.contains("for commands"), "gone once the conversation starts: {row:?}");
|
||||
|
||||
// Nor does a conversation with a reply in it count as fresh, whoever wrote the rest
|
||||
let mut replied = create_app();
|
||||
replied.update(Msg::TerminalResized { width, height });
|
||||
replied.push_convo(ConvoBlock::Assistant("Here is the plan.".into()));
|
||||
let (row, _) = row_above_composer(&render_app(&mut replied, &backend), width, height);
|
||||
assert!(!row.contains("for commands"), "{row:?}");
|
||||
}
|
||||
|
||||
/// The mode hint names the mode the key would switch to, and the key that is bound to do it.
|
||||
#[test]
|
||||
fn the_first_steps_hint_names_the_mode_shift_tab_reaches() {
|
||||
let (width, height) = (190, 30);
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = create_app();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
app.status.mode = "plan".into();
|
||||
let (row, _) = row_above_composer(&render_app(&mut app, &backend), width, height);
|
||||
assert!(
|
||||
row.contains(" shift+tab for build mode · / or"),
|
||||
"planning, it offers build: {row:?}"
|
||||
);
|
||||
|
||||
let keymap = KeyMap::defaults().with_overrides(std::collections::HashMap::from([(
|
||||
"tui.app.cycle_mode".to_string(),
|
||||
vec!["not a chord".to_string()],
|
||||
)]));
|
||||
let (tx, _rx) = tokio::sync::mpsc::channel::<luxe_core::engine::Action>(8);
|
||||
let mut unbound = App::new(tx, keymap, Config::default());
|
||||
unbound.update(Msg::TerminalResized { width, height });
|
||||
let (row, _) = row_above_composer(&render_app(&mut unbound, &backend), width, height);
|
||||
assert!(!row.contains("mode") && row.contains("/ or ctrl+k"), "unbound, left out: {row:?}");
|
||||
}
|
||||
|
||||
/// The palette's key is the one bound now; with none bound it is left out rather than invented.
|
||||
#[test]
|
||||
fn the_first_steps_hint_names_the_palette_key_you_bound() {
|
||||
let (width, height) = (140, 30);
|
||||
let backend = test_backend(width, height);
|
||||
let bound = |chords: &[&str]| {
|
||||
let keymap = KeyMap::defaults().with_overrides(std::collections::HashMap::from([(
|
||||
"tui.app.open_palette".to_string(),
|
||||
chords.iter().map(|chord| chord.to_string()).collect(),
|
||||
)]));
|
||||
let (tx, _rx) = tokio::sync::mpsc::channel::<luxe_core::engine::Action>(8);
|
||||
let mut app = App::new(tx, keymap, Config::default());
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
row_above_composer(&render_app(&mut app, &backend), width, height).0
|
||||
};
|
||||
assert!(bound(&["alt+p"]).contains("/ or alt+p for commands"));
|
||||
// Every chord unparseable leaves the action unbound
|
||||
let unbound = bound(&["not a chord"]);
|
||||
assert!(unbound.contains(" / for commands · @"), "{unbound:?}");
|
||||
}
|
||||
|
||||
/// On a narrow terminal the hint gives up its tail first, and says nothing rather than half a
|
||||
/// phrase when even the commands will not fit. A running turn has the row, and so does a review
|
||||
/// invitation, which is about something that happened.
|
||||
#[test]
|
||||
fn the_first_steps_hint_shortens_from_its_tail_and_gives_way() {
|
||||
let height = 30;
|
||||
let row_at = |width: u16, app: &mut App| {
|
||||
let backend = test_backend(width, height);
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
row_above_composer(&render_app(app, &backend), width, height).0
|
||||
};
|
||||
let mut app = create_app();
|
||||
let medium = row_at(80, &mut app);
|
||||
assert!(medium.contains("shift+tab for plan mode · / or ctrl+k for commands"), "{medium:?}");
|
||||
assert!(!medium.contains('@'), "the tail goes first: {medium:?}");
|
||||
let narrow = row_at(40, &mut app);
|
||||
assert!(narrow.contains("shift+tab for plan mode") && !narrow.contains('/'), "{narrow:?}");
|
||||
let tiny = row_at(22, &mut app);
|
||||
assert!(!tiny.contains("for comm") && !tiny.contains("shift"), "no half phrases: {tiny:?}");
|
||||
|
||||
app.status.flash_toast("Copied to clipboard");
|
||||
let toasted = row_at(140, &mut app);
|
||||
assert!(toasted.contains("Copied") && !toasted.contains("for commands"), "{toasted:?}");
|
||||
app.status.toast = None;
|
||||
|
||||
app.status.state = luxe_tui::app::AppState::Streaming;
|
||||
let running = row_at(140, &mut app);
|
||||
assert!(!running.contains("for commands"), "a running turn owns the row: {running:?}");
|
||||
}
|
||||
|
||||
/// The footer keeps to the keys a reader works with. The reading toggles — layout, guide,
|
||||
/// churn — are listed by help, and a footer that also carried them stopped being read at all.
|
||||
#[test]
|
||||
fn the_footer_keeps_to_the_keys_that_work() {
|
||||
let (width, height) = (200, 30);
|
||||
let mut app = seeded_app("nord", FixtureScenario::GuidedReviewNoise).unwrap();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
let buffer = render_app(&mut app, &test_backend(width, height));
|
||||
// The diff pane's share of the row: the rail's foot sits beside it, across the rule
|
||||
let row = row_text(&buffer, height - 1, width);
|
||||
let footer = row.rsplit('│').next().unwrap_or_default();
|
||||
assert_eq!(
|
||||
footer.trim(),
|
||||
"space next · c comment · a ask agent · alt+enter finish · ? help",
|
||||
"{footer}"
|
||||
);
|
||||
}
|
||||
|
||||
/// Scrolling clamps at the file's last row, and the pane draws one file at a time — so without a
|
||||
/// marker there, hitting the bottom is indistinguishable from a scroll that stopped working.
|
||||
#[test]
|
||||
fn the_bottom_of_a_file_says_so_when_the_chapter_carries_on() {
|
||||
let (width, height) = (140, 30);
|
||||
let mut app = seeded_app("nord", FixtureScenario::GuidedReviewLarge).unwrap();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
|
||||
// The first chapter owns several files, so the first file's end is not the chapter's end.
|
||||
for _ in 0..200 {
|
||||
app.update(Msg::GuidedReviewLineNext);
|
||||
}
|
||||
let text = buffer_to_string(&render_app(&mut app, &test_backend(width, height)));
|
||||
assert!(text.contains("end of file"), "the bottom of the file is named: {text}");
|
||||
assert!(text.contains("— end of file —"), "and nothing else, mid-chapter: {text}");
|
||||
}
|
||||
|
||||
/// Stepping to a chapter's last stop is what records it reviewed; scrolling there is not. The
|
||||
/// end-of-reading marker is the only place that distinction becomes visible.
|
||||
#[test]
|
||||
fn the_end_of_a_chapter_says_whether_it_was_reviewed() {
|
||||
let (width, height) = (120, 30);
|
||||
let mut app = seeded_app("nord", FixtureScenario::GuidedReviewReady).unwrap();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
|
||||
for _ in 0..60 {
|
||||
app.update(Msg::GuidedReviewLineNext);
|
||||
}
|
||||
let scrolled = buffer_to_string(&render_app(&mut app, &test_backend(width, height)));
|
||||
assert!(
|
||||
scrolled.contains("end of the last chapter"),
|
||||
"scrolling to the end is not reviewing it: {scrolled}"
|
||||
);
|
||||
|
||||
for _ in 0..6 {
|
||||
app.update(Msg::GuidedReviewHunkNext);
|
||||
}
|
||||
let stepped = buffer_to_string(&render_app(&mut app, &test_backend(width, height)));
|
||||
assert!(stepped.contains("last chapter reviewed"), "stepping through it records it: {stepped}");
|
||||
}
|
||||
|
||||
/// The fold controls describe churn. A review that has none is the common case for a
|
||||
/// feature-sized change, and offering `f`/`d` there taught the reviewer that pressing a key
|
||||
/// named on screen can do nothing at all — which costs every other key its credibility.
|
||||
#[test]
|
||||
fn the_fold_controls_appear_only_where_there_is_churn_to_fold() {
|
||||
let (width, height) = (120, 30);
|
||||
|
||||
let mut clean = seeded_app("nord", FixtureScenario::GuidedReviewReady).unwrap();
|
||||
clean.update(Msg::TerminalResized { width, height });
|
||||
let text = buffer_to_string(&render_app(&mut clean, &test_backend(width, height)));
|
||||
assert!(!text.contains("f opens them"), "nothing mechanical, so no fold control: {text}");
|
||||
assert!(!text.contains("d why"), "and nothing for it to explain: {text}");
|
||||
assert!(text.contains("space next"), "the working controls stay: {text}");
|
||||
|
||||
let mut noisy = seeded_app("nord", FixtureScenario::GuidedReviewNoise).unwrap();
|
||||
noisy.update(Msg::TerminalResized { width, height });
|
||||
let text = buffer_to_string(&render_app(&mut noisy, &test_backend(width, height)));
|
||||
assert!(text.contains("f opens them"), "a formatting-only hunk earns the control: {text}");
|
||||
}
|
||||
|
||||
/// Prints the FILES section so its shape can be reviewed as text, without a screenshot.
|
||||
#[test]
|
||||
fn dock_changes_shape_snapshot() {
|
||||
let (width, height) = (160, 44);
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = create_app();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
let mut snapshot = empty_workspace("luxe");
|
||||
let file = |path: &str, status: FileChangeStatus, a: Option<u64>, d: Option<u64>| {
|
||||
FileChangeSummary { path: path.into(), status, additions: a, deletions: d, binary: false }
|
||||
};
|
||||
snapshot.changes = WorkspaceChangesSummary {
|
||||
files: vec![
|
||||
file("crates/luxe-core/src/usage.rs", FileChangeStatus::Added, Some(214), Some(0)),
|
||||
file(
|
||||
"crates/luxe-core/src/engine/usage.rs",
|
||||
FileChangeStatus::Added,
|
||||
Some(160),
|
||||
Some(0),
|
||||
),
|
||||
file(
|
||||
"crates/luxe-core/src/engine/turn.rs",
|
||||
FileChangeStatus::Modified,
|
||||
Some(18),
|
||||
Some(24),
|
||||
),
|
||||
file(
|
||||
"crates/luxe-core/src/engine/compact.rs",
|
||||
FileChangeStatus::Modified,
|
||||
Some(14),
|
||||
Some(2),
|
||||
),
|
||||
file(
|
||||
"crates/luxe-tui/src/view/dock.rs",
|
||||
FileChangeStatus::Modified,
|
||||
Some(96),
|
||||
Some(31),
|
||||
),
|
||||
file(
|
||||
"crates/luxe-tui/src/app/status.rs",
|
||||
FileChangeStatus::Modified,
|
||||
Some(41),
|
||||
Some(48),
|
||||
),
|
||||
file("crates/luxe-tui/src/cost_report.rs", FileChangeStatus::Added, Some(131), Some(0)),
|
||||
file(
|
||||
"docs/design/a-very-long-design-document-name.md",
|
||||
FileChangeStatus::Untracked,
|
||||
Some(402),
|
||||
Some(0),
|
||||
),
|
||||
file("assets/logo.png", FileChangeStatus::Added, None, None),
|
||||
],
|
||||
total_files: 9,
|
||||
additions: Some(1076),
|
||||
deletions: Some(105),
|
||||
truncated: false,
|
||||
};
|
||||
app.workspace = Some(snapshot);
|
||||
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
println!("\n=== mixed roots ===\n{}", changes_block(&buffer, height));
|
||||
|
||||
// Everything under one root: the prefix is said once and the headings shorten.
|
||||
let mut app = create_app();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
let mut snapshot = empty_workspace("luxe");
|
||||
snapshot.changes = WorkspaceChangesSummary {
|
||||
files: vec![
|
||||
file("crates/luxe-core/src/usage.rs", FileChangeStatus::Added, Some(214), Some(0)),
|
||||
file(
|
||||
"crates/luxe-core/src/engine/turn.rs",
|
||||
FileChangeStatus::Modified,
|
||||
Some(18),
|
||||
Some(24),
|
||||
),
|
||||
file(
|
||||
"crates/luxe-tui/src/view/dock.rs",
|
||||
FileChangeStatus::Modified,
|
||||
Some(96),
|
||||
Some(31),
|
||||
),
|
||||
],
|
||||
total_files: 3,
|
||||
additions: Some(328),
|
||||
deletions: Some(55),
|
||||
truncated: false,
|
||||
};
|
||||
app.workspace = Some(snapshot);
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
let shared = changes_block(&buffer, height);
|
||||
println!("\n=== shared root ===\n{shared}");
|
||||
assert!(shared.contains("crates"), "one folder heads the tree: {shared}");
|
||||
assert!(shared.contains("luxe-core/src"), "a lone chain is one row: {shared}");
|
||||
assert!(shared.contains("usage.rs"), "files are named: {shared}");
|
||||
}
|
||||
|
||||
/// The FILES block as plain text, for reviewing its shape without a screenshot.
|
||||
pub(super) fn changes_block(buffer: &Buffer, height: u16) -> String {
|
||||
(0..height)
|
||||
.map(|y| row_text(buffer, y, 42).trim_end().to_string())
|
||||
.skip_while(|line| !line.contains("FILES"))
|
||||
.take_while(|line| !line.contains("MODEL"))
|
||||
.filter(|line| !line.is_empty())
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n")
|
||||
}
|
||||
|
||||
/// Prints the guide pane so its shape can be reviewed as text, without a screenshot.
|
||||
#[test]
|
||||
fn guide_pane_shape_snapshot() {
|
||||
let (width, height) = (160, 44);
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = seeded_app("nord", FixtureScenario::GuidedReviewBrief).unwrap();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
let guide_width = luxe_tui::workspace_layout::guide_pane_width(width);
|
||||
let guide: Vec<String> =
|
||||
(0..height).map(|y| row_text(&buffer, y, guide_width).trim_end().to_string()).collect();
|
||||
println!("\n{}", guide.join("\n").trim_end());
|
||||
assert!(guide.iter().any(|line| line.contains("REVIEW")), "the pane names itself");
|
||||
assert!(guide.iter().any(|line| line.contains("Step ")), "and says where you are");
|
||||
}
|
||||
|
||||
/// An untracked *directory* is one dock row and several review files, so comparing counts made
|
||||
/// "Workspace changed" permanently true over a review that matched the working tree exactly.
|
||||
#[test]
|
||||
fn a_pinned_review_that_matches_the_working_tree_is_not_called_stale() {
|
||||
let (width, height) = (170, 40);
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = seeded_app("nord", FixtureScenario::GuidedReviewReady).unwrap();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
let mut snapshot = empty_workspace("staleness");
|
||||
// Git collapses the untracked directory; the review lists the one file inside it.
|
||||
snapshot.changes = WorkspaceChangesSummary {
|
||||
files: vec![FileChangeSummary {
|
||||
path: "src/".into(),
|
||||
status: FileChangeStatus::Untracked,
|
||||
additions: None,
|
||||
deletions: None,
|
||||
binary: false,
|
||||
}],
|
||||
total_files: 1,
|
||||
additions: None,
|
||||
deletions: None,
|
||||
truncated: false,
|
||||
};
|
||||
app.workspace = Some(snapshot.clone());
|
||||
|
||||
let matching = buffer_to_string(&render_app(&mut app, &backend));
|
||||
assert!(
|
||||
!matching.contains("Workspace changed"),
|
||||
"the review covers exactly what the dock reports: {matching}"
|
||||
);
|
||||
|
||||
// A file the review has never heard of *is* a real divergence.
|
||||
snapshot.changes.files.push(FileChangeSummary {
|
||||
path: "src/elsewhere.rs".into(),
|
||||
status: FileChangeStatus::Modified,
|
||||
additions: Some(1),
|
||||
deletions: Some(0),
|
||||
binary: false,
|
||||
});
|
||||
snapshot.changes.total_files = 2;
|
||||
app.workspace = Some(snapshot);
|
||||
|
||||
let moved = buffer_to_string(&render_app(&mut app, &backend));
|
||||
assert!(moved.contains("Workspace changed"), "real drift still says so: {moved}");
|
||||
}
|
||||
172
crates/luxe-tui/tests/render/images.rs
Normal file
172
crates/luxe-tui/tests/render/images.rs
Normal file
@@ -0,0 +1,172 @@
|
||||
//! Images — inline captures at each fidelity tier.
|
||||
|
||||
use super::*;
|
||||
|
||||
/// A PNG whose halves are different colors, so a rasterized cell is checkable.
|
||||
pub(super) fn split_png(width: u32, height: u32) -> String {
|
||||
use base64::Engine as _;
|
||||
let mut pixels = image::RgbaImage::new(width, height);
|
||||
let midpoint = height / 2;
|
||||
for (_, y, pixel) in pixels.enumerate_pixels_mut() {
|
||||
*pixel = if y < midpoint {
|
||||
image::Rgba([220, 40, 40, 255])
|
||||
} else {
|
||||
image::Rgba([40, 60, 220, 255])
|
||||
};
|
||||
}
|
||||
let mut png = std::io::Cursor::new(Vec::new());
|
||||
image::DynamicImage::ImageRgba8(pixels)
|
||||
.write_to(&mut png, image::ImageFormat::Png)
|
||||
.expect("encode png");
|
||||
base64::engine::general_purpose::STANDARD.encode(png.into_inner())
|
||||
}
|
||||
|
||||
/// A store drawing at `tier` against cells of a known size, so the geometry is not the host's.
|
||||
pub(super) fn pinned_store(tier: luxe_tui::graphics::ImageTier) -> luxe_tui::graphics::ImageStore {
|
||||
luxe_tui::graphics::ImageStore::new(
|
||||
tier,
|
||||
luxe_tui::graphics::CellSize { width: 10, height: 20 },
|
||||
)
|
||||
}
|
||||
|
||||
/// An app holding one pasted image, drawn at `tier`.
|
||||
pub(super) fn app_with_image(tier: luxe_tui::graphics::ImageTier) -> App {
|
||||
let mut app = create_app();
|
||||
app.images = pinned_store(tier);
|
||||
let key = app.attachment_image_key();
|
||||
let origin = app.image_origin("pasted image", None);
|
||||
assert!(app.intern_image(&key, &split_png(320, 160), origin));
|
||||
app.push_convo(ConvoBlock::Image { key, width: 320, height: 160 });
|
||||
app
|
||||
}
|
||||
|
||||
pub(super) fn rows_of(buffer: &Buffer) -> Vec<String> {
|
||||
let width = buffer.area.width as usize;
|
||||
buffer
|
||||
.content
|
||||
.chunks(width)
|
||||
.map(|row| row.iter().map(|cell| cell.symbol().to_string()).collect())
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// With images off — or on a terminal that cannot draw them — the reader still learns that there
|
||||
/// was one and how big it was. An image nobody can show is a fact about the conversation.
|
||||
#[test]
|
||||
fn an_undrawable_image_is_still_named_in_words() {
|
||||
let backend = test_backend(80, 24);
|
||||
let mut app = app_with_image(luxe_tui::graphics::ImageTier::Text);
|
||||
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
let line = rows_of(&buffer)
|
||||
.into_iter()
|
||||
.find(|row| row.contains("pasted image"))
|
||||
.expect("the image is named");
|
||||
assert!(line.contains("320") && line.contains("160"), "with its size: {line:?}");
|
||||
}
|
||||
|
||||
/// An image the store refused — unreadable, or past the size caps — must not render as a blank gap
|
||||
/// the reader has no way to interpret.
|
||||
#[test]
|
||||
fn an_image_that_could_not_be_taken_in_says_so() {
|
||||
let backend = test_backend(80, 24);
|
||||
let mut app = create_app();
|
||||
let key = app.attachment_image_key();
|
||||
let origin = app.image_origin("pasted image", None);
|
||||
assert!(!app.intern_image(&key, "not-base64-at-all!!", origin));
|
||||
app.push_convo(ConvoBlock::Image { key, width: 320, height: 160 });
|
||||
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
assert!(
|
||||
rows_of(&buffer).iter().any(|row| row.contains("image unavailable")),
|
||||
"an image that could not be decoded is reported, not silently dropped"
|
||||
);
|
||||
}
|
||||
|
||||
/// The blocks tier draws the picture as ordinary colored cells: `▀` with the upper scanline as
|
||||
/// foreground and the lower as background. Nothing else in the transcript can tell the difference,
|
||||
/// which is exactly why it works in every terminal.
|
||||
#[test]
|
||||
fn the_blocks_tier_draws_the_image_as_colored_cells() {
|
||||
let backend = test_backend(80, 24);
|
||||
let mut app = app_with_image(luxe_tui::graphics::ImageTier::Blocks);
|
||||
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
let painted: Vec<_> = buffer.content.iter().filter(|cell| cell.symbol() == "▀").collect();
|
||||
assert!(painted.len() > 40, "the image occupies real cells: {}", painted.len());
|
||||
assert!(
|
||||
painted.iter().any(|cell| matches!(cell.fg, ratatui::style::Color::Rgb(r, _, b) if r > b)),
|
||||
"the red half of the source is on screen"
|
||||
);
|
||||
assert!(
|
||||
painted.iter().any(|cell| matches!(cell.bg, ratatui::style::Color::Rgb(r, _, b) if b > r)),
|
||||
"and so is the blue half"
|
||||
);
|
||||
}
|
||||
|
||||
/// The pixel tier writes placeholder cells the terminal resolves into an image: a real symbol and
|
||||
/// a real foreground color, so ratatui's diff erases them like any other text. What this guards is
|
||||
/// that no escape sequence is ever smuggled into a cell — cells the diff cannot reason about are
|
||||
/// how an image gets left behind on screen after it scrolls away.
|
||||
#[test]
|
||||
fn the_pixel_tier_writes_only_addressable_cells() {
|
||||
let backend = test_backend(80, 24);
|
||||
let mut app = app_with_image(luxe_tui::graphics::ImageTier::Pixels);
|
||||
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
let placeholders: Vec<_> =
|
||||
buffer.content.iter().filter(|cell| cell.symbol().starts_with('\u{10EEEE}')).collect();
|
||||
assert!(placeholders.len() > 40, "the image occupies real cells: {}", placeholders.len());
|
||||
assert!(
|
||||
placeholders.iter().all(|cell| matches!(cell.fg, ratatui::style::Color::Rgb(..))),
|
||||
"every image cell names its image through a foreground color"
|
||||
);
|
||||
for cell in buffer.content.iter() {
|
||||
assert!(!cell.symbol().contains('\u{1b}'), "no escape sequence reaches the cell buffer");
|
||||
}
|
||||
assert!(
|
||||
app.images.drain_control().contains("a=T,U=1"),
|
||||
"and the image itself is owed to the stream, not to the buffer"
|
||||
);
|
||||
}
|
||||
|
||||
/// A screenshot's picture belongs to the call that produced it, and it is never behind the expand
|
||||
/// toggle: for `screenshot` the image *is* the result.
|
||||
#[test]
|
||||
fn a_tool_cards_image_renders_without_being_expanded() {
|
||||
use luxe_core::message::{ContentBlock, Message, Role, ToolOutput};
|
||||
|
||||
let backend = test_backend(100, 40);
|
||||
let mut app = create_app();
|
||||
app.images = pinned_store(luxe_tui::graphics::ImageTier::Blocks);
|
||||
app.update(Msg::Engine(luxe_core::Event::SessionLoaded {
|
||||
session_id: "session-a".into(),
|
||||
messages: vec![],
|
||||
}));
|
||||
app.update(Msg::Engine(luxe_core::Event::ToolActivityUpdated(Box::new(
|
||||
luxe_core::ToolActivity::running("session-a", "call-1", "screenshot", "mode=url", 1),
|
||||
))));
|
||||
app.update(Msg::Engine(luxe_core::Event::MessageCommitted {
|
||||
session_id: "session-a".into(),
|
||||
entry_id: luxe_core::session::EntryId("entry-1".into()),
|
||||
message: Message {
|
||||
role: Role::Tool,
|
||||
content: vec![ContentBlock::ToolResult {
|
||||
call_id: "call-1".into(),
|
||||
content: vec![
|
||||
ToolOutput::Text("Captured url (320x160)".into()),
|
||||
ToolOutput::Image {
|
||||
data: split_png(320, 160),
|
||||
mime: "image/png".into(),
|
||||
name: Some(".luxe/screenshots/shot-1.png".into()),
|
||||
},
|
||||
],
|
||||
is_error: false,
|
||||
}],
|
||||
},
|
||||
}));
|
||||
|
||||
assert!(!app.tool_output_expanded, "the card is collapsed");
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
let painted = buffer.content.iter().filter(|cell| cell.symbol() == "▀").count();
|
||||
assert!(painted > 40, "the screenshot is on screen anyway: {painted} cells");
|
||||
}
|
||||
340
crates/luxe-tui/tests/render/layout.rs
Normal file
340
crates/luxe-tui/tests/render/layout.rs
Normal file
@@ -0,0 +1,340 @@
|
||||
//! Layout — selection highlight, composer and statusline, and the dock beside or over the chat.
|
||||
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn selected_conversation_block_uses_visual_highlight_and_escape_clears_it() {
|
||||
let (w, h) = (80, 24);
|
||||
let backend = test_backend(w, h);
|
||||
let mut app = create_app();
|
||||
app.push_convo(ConvoBlock::User {
|
||||
text: "selected text".into(),
|
||||
attached: Vec::new(),
|
||||
chips: Vec::new(),
|
||||
});
|
||||
app.selected_block = Some(0);
|
||||
let selected_bg = app.theme_styles.selected_bg.bg.expect("selected background");
|
||||
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
let row = (0..h)
|
||||
.find(|&y| row_text(&buffer, y, w).contains("selected text"))
|
||||
.expect("selected message row");
|
||||
assert!((0..w).any(|x| buffer[(x, row)].bg == selected_bg));
|
||||
|
||||
assert!(matches!(
|
||||
route_key(&mut app, &key(KeyCode::Esc)),
|
||||
RouteAction::Msg(message) if matches!(*message, Msg::Tick)
|
||||
));
|
||||
assert!(app.selected_block.is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn composer_and_statusline_are_adjacent_distinct_surfaces() {
|
||||
let (w, h) = (80, 24);
|
||||
let backend = test_backend(w, h);
|
||||
let mut app = create_app();
|
||||
app.status.model = "gpt-4o".into();
|
||||
app.status.git_branch = Some("main".into());
|
||||
app.status.context_pct = 42.0;
|
||||
app.status.context_window = 128_000;
|
||||
app.editor.insert_text("hello");
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
let composer: String = (h - 5..h).map(|row| row_text(&buffer, row, w)).collect();
|
||||
|
||||
assert!(!composer.contains("Status"));
|
||||
assert!(!composer.contains("Input"));
|
||||
assert!(composer.contains("│hello"), "input should start at the first inner cell");
|
||||
assert!(composer.contains("gpt-4o"));
|
||||
assert!(composer.contains("42.0%/128k"));
|
||||
// The bar is flat now: no editor mode label, no powerline arrow separators.
|
||||
assert!(!composer.contains("INSERT"), "mode label is gone: {composer:?}");
|
||||
assert!(!composer.contains('\u{e0b0}'), "no left powerline separator");
|
||||
assert!(!composer.contains('\u{e0b2}'), "no right powerline separator");
|
||||
assert!(row_text(&buffer, h - 2, w).trim_start().starts_with('╰'));
|
||||
let statusline = row_text(&buffer, h - 1, w);
|
||||
assert!(statusline.contains("gpt-4o"), "model anchors the statusline row: {statusline:?}");
|
||||
// Both draw flush to the terminal's edges, and line up with each other there
|
||||
let corner_left =
|
||||
(0..w).find(|&x| buffer[(x, h - 4)].symbol() == "╭").expect("composer top-left corner");
|
||||
let corner_right = (0..w)
|
||||
.rev()
|
||||
.find(|&x| buffer[(x, h - 4)].symbol() == "╮")
|
||||
.expect("composer top-right corner");
|
||||
// Painted, not inked: a band opens on a pad cell, which is blank but carries the slab's color.
|
||||
// The canvas is read off the empty transcript, since the bar now reaches column 0
|
||||
let canvas = buffer[(0, 0)].bg;
|
||||
let painted = |x: u16| buffer[(x, h - 1)].symbol() != " " || buffer[(x, h - 1)].bg != canvas;
|
||||
let statusline_left = (0..w).find(|&x| painted(x)).expect("statusline left content");
|
||||
let statusline_right = (0..w).rev().find(|&x| painted(x)).expect("statusline right content");
|
||||
assert_eq!(corner_left, statusline_left, "statusline aligns with the prompt box left edge");
|
||||
assert_eq!(corner_right, statusline_right, "statusline aligns with the prompt box right edge");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn standard_context_dock_overlays_the_configured_side_without_narrowing_the_footer() {
|
||||
let (width, height) = (120, 32);
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = create_app();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
app.dock.show();
|
||||
app.status.model = "gpt-4o".into();
|
||||
app.push_convo(ConvoBlock::Assistant("conversation remains primary".into()));
|
||||
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
let content = buffer_to_string(&buffer);
|
||||
assert!(content.contains("PROJECT"), "missing Context overlay: {content}");
|
||||
// Overlay is not side-by-side, so the statusline stays as the compact footer (auto). The
|
||||
// model name anchors the bar's bottom row (there is no editor-mode label anymore).
|
||||
assert!(
|
||||
row_text(&buffer, height - 1, width).contains("gpt-4o"),
|
||||
"footer should remain visible on the bottom row: {content}"
|
||||
);
|
||||
|
||||
// Left is the default side, so the overlay hugs the left edge; the heading sits flush against
|
||||
// it, matching the full-height dock.
|
||||
let context_x =
|
||||
(0..width).find(|&x| buffer[(x, 0)].symbol() == "P").expect("dock heading should render");
|
||||
assert_eq!(
|
||||
context_x, DOCK_HEADING_LEAD,
|
||||
"overlay must occupy the leftmost dock cells by default"
|
||||
);
|
||||
}
|
||||
|
||||
/// The overlay dock owns its cells. A `Block` only restyles what is already in the buffer, so the
|
||||
/// conversation underneath used to show through wherever a dock row was shorter than the line it
|
||||
/// covered — recolored as dock text, which reads as garbled dock content rather than as chat.
|
||||
#[test]
|
||||
fn the_overlay_dock_covers_the_conversation_underneath_it() {
|
||||
let (width, height) = (120, 32);
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = create_app();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
app.dock.show();
|
||||
// Long enough to run under the whole dock column on several rows.
|
||||
app.push_convo(ConvoBlock::Assistant("BLEED ".repeat(40)));
|
||||
app.workspace = Some(empty_workspace("dock-overlay-bleed"));
|
||||
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
let dock_width = luxe_tui::workspace_layout::CONTEXT_DOCK_WIDTH;
|
||||
for y in 0..height {
|
||||
let covered: String = (0..dock_width).map(|x| buffer[(x, y)].symbol()).collect();
|
||||
assert!(
|
||||
!covered.contains("BLEED"),
|
||||
"conversation text shows through the overlay on row {y}: {covered:?}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn compact_context_dock_replaces_chat_and_hides_the_composer() {
|
||||
let (width, height) = (78, 30);
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = create_app();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
app.dock.show();
|
||||
app.status.model = "qwen3.8-27b".into();
|
||||
app.status.context_window = 128_000;
|
||||
app.status.context_pct = 42.0;
|
||||
app.editor.insert_text("composer must stay hidden");
|
||||
app.push_convo(ConvoBlock::Assistant("chat must stay hidden".into()));
|
||||
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
let content = buffer_to_string(&buffer);
|
||||
assert!(content.contains("PROJECT"), "missing replacement Context surface: {content}");
|
||||
assert!(content.contains("CONTEXT"), "Context footer should replace editor mode: {content}");
|
||||
assert!(
|
||||
content.contains("pgup/Dn scroll"),
|
||||
"footer should explain independent Context scrolling: {content}"
|
||||
);
|
||||
assert!(content.contains("esc"), "footer should explain how to return to chat: {content}");
|
||||
assert!(!content.contains("chat must stay hidden"), "chat leaked into replacement: {content}");
|
||||
assert!(
|
||||
!content.contains("composer must stay hidden"),
|
||||
"composer leaked into replacement: {content}"
|
||||
);
|
||||
|
||||
let context_x =
|
||||
(0..width).find(|&x| buffer[(x, 0)].symbol() == "P").expect("dock heading should render");
|
||||
assert_eq!(
|
||||
context_x, DOCK_HEADING_LEAD,
|
||||
"the heading badge's leading edge sits on the terminal's edge"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn wide_context_dock_is_a_full_height_left_panel_and_hides_the_statusline() {
|
||||
let (width, height) = (160, 40);
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = create_app();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
app.push_convo(ConvoBlock::Assistant("conversation remains primary".into()));
|
||||
|
||||
let mut snapshot = WorkspaceSnapshot::empty(
|
||||
WorkspaceScopeId::new("dock-render"),
|
||||
ProjectIdentity {
|
||||
root: "/work/luxe".into(),
|
||||
display_name: "luxe".into(),
|
||||
display_path: "~/work/luxe".into(),
|
||||
git_branch: Some("feature/context-dock".into()),
|
||||
git_dirty: true,
|
||||
git_head: None,
|
||||
},
|
||||
);
|
||||
snapshot.session = Some(WorkspaceSessionSummary {
|
||||
id: "session-1".into(),
|
||||
title: "Render the Context Dock".into(),
|
||||
updated_at_ms: 1,
|
||||
});
|
||||
snapshot.todos = TodoSummary {
|
||||
current: Some(TodoSummaryItem {
|
||||
id: "2".into(),
|
||||
subject: "Render the Context Plan".into(),
|
||||
status: TodoSummaryStatus::InProgress,
|
||||
blocked_by: Vec::new(),
|
||||
}),
|
||||
items: vec![
|
||||
TodoSummaryItem {
|
||||
id: "2".into(),
|
||||
subject: "Render the Context Plan".into(),
|
||||
status: TodoSummaryStatus::InProgress,
|
||||
blocked_by: Vec::new(),
|
||||
},
|
||||
TodoSummaryItem {
|
||||
id: "3".into(),
|
||||
subject: "Capture responsive fixtures".into(),
|
||||
status: TodoSummaryStatus::Blocked,
|
||||
blocked_by: vec!["2".into()],
|
||||
},
|
||||
TodoSummaryItem {
|
||||
id: "4".into(),
|
||||
subject: "Write the dock tests".into(),
|
||||
status: TodoSummaryStatus::Pending,
|
||||
blocked_by: Vec::new(),
|
||||
},
|
||||
TodoSummaryItem {
|
||||
id: "1".into(),
|
||||
subject: "Model the sections".into(),
|
||||
status: TodoSummaryStatus::Completed,
|
||||
blocked_by: Vec::new(),
|
||||
},
|
||||
],
|
||||
pending: 1,
|
||||
in_progress: 1,
|
||||
completed: 3,
|
||||
blocked: 1,
|
||||
total: 8,
|
||||
truncated: true,
|
||||
};
|
||||
snapshot.changes = WorkspaceChangesSummary {
|
||||
files: vec![
|
||||
FileChangeSummary {
|
||||
path: "crates/luxe-tui/src/view/dock.rs".into(),
|
||||
status: FileChangeStatus::Modified,
|
||||
additions: Some(12),
|
||||
deletions: Some(3),
|
||||
binary: false,
|
||||
},
|
||||
FileChangeSummary {
|
||||
path: "assets/context-preview.png".into(),
|
||||
status: FileChangeStatus::Added,
|
||||
additions: None,
|
||||
deletions: None,
|
||||
binary: true,
|
||||
},
|
||||
],
|
||||
total_files: 4,
|
||||
additions: None,
|
||||
deletions: None,
|
||||
truncated: true,
|
||||
};
|
||||
snapshot.review = Some(ReviewSummary {
|
||||
id: "review-1".into(),
|
||||
title: "Fix the stale reference".into(),
|
||||
source: "last turn".into(),
|
||||
unresolved_findings: 1,
|
||||
completed_at_ms: 2,
|
||||
});
|
||||
snapshot.tooling.debug_sessions = vec![DebugSessionStatus {
|
||||
id: "dbg-1".into(),
|
||||
adapter: "codelldb".into(),
|
||||
program: "target/debug/app".into(),
|
||||
terminated: false,
|
||||
stopped: true,
|
||||
stop_reason: Some("breakpoint".into()),
|
||||
}];
|
||||
app.workspace = Some(snapshot);
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
let content = buffer_to_string(&buffer);
|
||||
assert!(content.contains("conversation remains primary"), "missing transcript: {content}");
|
||||
assert!(content.contains("PROJECT"), "missing identity heading: {content}");
|
||||
// Identity is project + branch only: the auto-derived session title and the task slug were
|
||||
// dropped as chrome that restated what the user already knew.
|
||||
assert!(!content.contains("Session ·"), "session title row was dropped: {content}");
|
||||
assert!(!content.contains("Task ·"), "task slug row was dropped: {content}");
|
||||
// The badge holds the word and the ratio rides bare beside it, so the run of headings down the
|
||||
// rail stays one kind of object — hence the closing cap between the two.
|
||||
assert!(content.contains("PLAN"), "missing the Plan heading: {content}");
|
||||
assert!(content.contains("3/8"), "Plan heading carries the ratio: {content}");
|
||||
// Every todo is its own checklist row, in-progress first, with per-status glyphs.
|
||||
assert!(content.contains("◉ Render the Context Plan"), "in-progress row: {content}");
|
||||
// The blocked row is its mark and its subject: the ids it waits on are shown nowhere else
|
||||
assert!(content.contains("⊘ Capture responsive fixtu"), "blocked row: {content}");
|
||||
assert!(!content.contains("needs"), "no dependency note: {content}");
|
||||
assert!(content.contains("○ Write the dock tests"), "a pending row: {content}");
|
||||
assert!(content.contains("✓ Model the sections"), "a completed row: {content}");
|
||||
assert!(content.contains("├─") || content.contains("└─"), "tree connectors: {content}");
|
||||
// What a list is not showing is the bar's to say: the rail counts none of it in words.
|
||||
assert!(!content.contains("not listed"), "the rail counts nothing in words: {content}");
|
||||
assert!(!content.contains("more"), "and folds nothing into a tail: {content}");
|
||||
assert!(!content.contains("Open Plan"), "the dock must not advertise a phantom action");
|
||||
assert!(content.contains("FILES"), "missing the Files heading: {content}");
|
||||
// With no prior review the headline *is* the total, said once.
|
||||
assert!(content.contains("4 changed"), "missing the changes headline: {content}");
|
||||
assert!(!content.contains("in the worktree"), "the total is not said twice: {content}");
|
||||
assert!(
|
||||
content.contains("ctrl+g review"),
|
||||
"the Changes section names the way into review: {content}"
|
||||
);
|
||||
assert!(content.contains("ctrl+p preview"), "and the cheaper way in beside it: {content}");
|
||||
// The rail carries what the reader can act on. A review's open comments and a live debug
|
||||
// session are both true here and both stay off it: neither is reachable from the rail, and the
|
||||
// debugger is the agent's tool — `/debug` answers on demand, as `/lsp` does.
|
||||
assert!(!content.contains("REVIEW"), "no review section: {content}");
|
||||
assert!(!content.contains("open comment"), "and no comment count: {content}");
|
||||
assert!(!content.contains("DEBUG"), "no debug section: {content}");
|
||||
assert!(!content.contains("stopped: breakpoint"), "and no session state: {content}");
|
||||
assert!(
|
||||
!content.contains("LOOP"),
|
||||
"loop gate must not surface in the interactive dock: {content}"
|
||||
);
|
||||
assert!(!content.contains("Gate ·"), "gate verdict must not surface: {content}");
|
||||
// The dock has no selection highlight or collapse markers anymore.
|
||||
assert!(!content.contains("▶"), "informational dock shows no collapse markers: {content}");
|
||||
// The full-height sidebar carries context on wide terminals, so the statusline auto-hides and
|
||||
// the composer bottom-aligns to the final body row (no compact bar beneath it).
|
||||
let composer_x = luxe_tui::workspace_layout::CONTEXT_DOCK_WIDTH
|
||||
+ luxe_tui::workspace_layout::CONTEXT_DOCK_SEPARATOR_WIDTH
|
||||
+ 1;
|
||||
assert_eq!(
|
||||
buffer[(composer_x, height - 1)].symbol(),
|
||||
"╰",
|
||||
"statusline should be hidden beside the sidebar: {content}"
|
||||
);
|
||||
// The sidebar is a full-height LEFT column: its heading opens on the first row and the panel
|
||||
// still occupies the top and bottom rows of the viewport.
|
||||
let context_x =
|
||||
(0..width).find(|&x| buffer[(x, 0)].symbol() == "P").expect("dock heading should render");
|
||||
assert_eq!(
|
||||
context_x, DOCK_HEADING_LEAD,
|
||||
"left dock heading badge opens on the terminal's edge"
|
||||
);
|
||||
// The left rail is followed by its separator, and both span the whole viewport height:
|
||||
// the divider glyph is present on the very first and very last rows.
|
||||
let sep_x = usize::from(luxe_tui::workspace_layout::CONTEXT_DOCK_WIDTH);
|
||||
assert_eq!(buffer[(sep_x as u16, 0)].symbol(), "│", "separator missing on the top row");
|
||||
assert_eq!(
|
||||
buffer[(sep_x as u16, height - 1)].symbol(),
|
||||
"│",
|
||||
"separator should reach the bottom row (full-height sidebar)"
|
||||
);
|
||||
}
|
||||
63
crates/luxe-tui/tests/render/main.rs
Normal file
63
crates/luxe-tui/tests/render/main.rs
Normal file
@@ -0,0 +1,63 @@
|
||||
//! Render test: verify the view renders correctly without a real terminal.
|
||||
//!
|
||||
//! Uses ratatui's TestBackend to render into an in-memory buffer.
|
||||
|
||||
use crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
|
||||
use luxe_core::config::{Config, ConversationAlignment};
|
||||
use luxe_core::guided_review::{ReviewLine, ReviewLineKind};
|
||||
use luxe_core::keymap::KeyMap;
|
||||
use luxe_core::{
|
||||
DebugSessionStatus, DiagnosticsSummary, FileChangeStatus, FileChangeSummary, FileDiagnostics,
|
||||
ProjectIdentity, ReviewSummary, SessionSummary as WorkspaceSessionSummary, TodoSummary,
|
||||
TodoSummaryItem, TodoSummaryStatus, ToolActivity, ToolActivityState, WorkspaceChangesSummary,
|
||||
WorkspaceScopeId, WorkspaceSnapshot,
|
||||
};
|
||||
use luxe_tui::app::input::review_keys::claim;
|
||||
use luxe_tui::app::{App, ConvoBlock, Msg, ToolItem, ViewMode};
|
||||
use luxe_tui::clipboard::ClipboardSink;
|
||||
use luxe_tui::dashboard::{DashboardState, SessionSummary};
|
||||
use luxe_tui::fixture::{seeded_app, FixtureScenario};
|
||||
use luxe_tui::main_loop::{route_key, route_mouse, route_mouse_at, RouteAction};
|
||||
use luxe_tui::session_picker::{SessionEntry, SessionPickerState};
|
||||
use luxe_tui::view::render;
|
||||
use luxe_tui::workspace_dock::DockList;
|
||||
use ratatui::backend::TestBackend;
|
||||
use ratatui::buffer::Buffer;
|
||||
use ratatui::Terminal;
|
||||
|
||||
mod activity;
|
||||
mod canvas;
|
||||
mod cards;
|
||||
mod changes;
|
||||
mod changes_pane;
|
||||
mod chat_keys;
|
||||
mod clicks;
|
||||
mod composer;
|
||||
mod dock;
|
||||
mod elsewhere;
|
||||
mod files;
|
||||
mod hints;
|
||||
mod images;
|
||||
mod layout;
|
||||
mod peek_selection;
|
||||
mod pickers;
|
||||
mod reasoning;
|
||||
mod reveal;
|
||||
mod review_context;
|
||||
mod review_guide;
|
||||
mod routing;
|
||||
mod selection;
|
||||
mod steering;
|
||||
mod support;
|
||||
mod transcript;
|
||||
|
||||
use activity::*;
|
||||
use canvas::*;
|
||||
use cards::*;
|
||||
use changes::*;
|
||||
use composer::*;
|
||||
use dock::*;
|
||||
use elsewhere::*;
|
||||
use images::*;
|
||||
use routing::*;
|
||||
use support::*;
|
||||
167
crates/luxe-tui/tests/render/peek_selection.rs
Normal file
167
crates/luxe-tui/tests/render/peek_selection.rs
Normal file
@@ -0,0 +1,167 @@
|
||||
//! Peek selection — text selected with the mouse in the Changes pane, by the character.
|
||||
|
||||
use super::*;
|
||||
use crossterm::event::{MouseButton, MouseEvent, MouseEventKind};
|
||||
use luxe_tui::fixture::seed_file_view;
|
||||
|
||||
const FILE: &str = "fn alpha() {\n\tlet bravo = 1;\n}\n";
|
||||
|
||||
/// A File view on `text`, drawn once so the pointer has something to land on.
|
||||
fn file_view(text: &str, width: u16, height: u16) -> (App, TestBackend, Buffer) {
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = create_app();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
seed_file_view(&mut app, "src/lib.rs", text, None);
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
(app, backend, buffer)
|
||||
}
|
||||
|
||||
fn mouse(app: &mut App, kind: MouseEventKind, (column, row): (u16, u16)) {
|
||||
let event = MouseEvent { kind, column, row, modifiers: KeyModifiers::NONE };
|
||||
let action = route_mouse(app, &event);
|
||||
apply(app, action);
|
||||
}
|
||||
|
||||
/// Presses at `from`, drags to `to` and lets go.
|
||||
fn drag(app: &mut App, from: (u16, u16), to: (u16, u16)) {
|
||||
mouse(app, MouseEventKind::Down(MouseButton::Left), from);
|
||||
mouse(app, MouseEventKind::Drag(MouseButton::Left), to);
|
||||
mouse(app, MouseEventKind::Up(MouseButton::Left), to);
|
||||
}
|
||||
|
||||
/// Where `needle` first sits on screen, as `(column, row)`.
|
||||
fn find(buffer: &Buffer, needle: &str, width: u16, height: u16) -> (u16, u16) {
|
||||
let row = row_containing(buffer, needle, width, height);
|
||||
(column_of(&row_text(buffer, row, width), needle), row)
|
||||
}
|
||||
|
||||
/// A drag over the File view's code highlights the characters it covers and copies them on
|
||||
/// release, as it does in the transcript. The code used to be only a line-pick target, so the same
|
||||
/// drag picked the whole line instead.
|
||||
#[test]
|
||||
fn dragging_over_file_view_code_selects_and_copies_the_characters() {
|
||||
let (width, height) = (100, 20);
|
||||
let (mut app, backend, buffer) = file_view(FILE, width, height);
|
||||
let (column, row) = find(&buffer, "bravo", width, height);
|
||||
|
||||
mouse(&mut app, MouseEventKind::Down(MouseButton::Left), (column, row));
|
||||
mouse(&mut app, MouseEventKind::Drag(MouseButton::Left), (column + 5, row));
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
let selected = app.theme_styles.selected_bg.bg.expect("a selection background");
|
||||
assert_eq!(buffer[(column, row)].bg, selected, "the dragged code is highlighted");
|
||||
assert_ne!(buffer[(column + 6, row)].bg, selected, "and nothing past it");
|
||||
|
||||
mouse(&mut app, MouseEventKind::Up(MouseButton::Left), (column + 5, row));
|
||||
let shown = buffer_to_string(&render_app(&mut app, &backend));
|
||||
assert_eq!(app.outbox.copy.as_deref(), Some("bravo"));
|
||||
assert!(!shown.contains("ask about"), "no lines were picked: {shown}");
|
||||
}
|
||||
|
||||
/// A drag across lines copies the source between its ends: no line numbers, and the tab that
|
||||
/// indents the second line comes back a tab rather than the spaces it is drawn as.
|
||||
#[test]
|
||||
fn a_drag_across_lines_copies_the_source_tabs_and_all() {
|
||||
let (width, height) = (100, 20);
|
||||
let (mut app, _backend, buffer) = file_view(FILE, width, height);
|
||||
let start = find(&buffer, "alpha", width, height);
|
||||
let (column, row) = find(&buffer, "bravo", width, height);
|
||||
|
||||
drag(&mut app, start, (column + 5, row));
|
||||
assert_eq!(app.outbox.copy.as_deref(), Some("alpha() {\n\tlet bravo"));
|
||||
}
|
||||
|
||||
/// The line numbers still pick whole lines, which is how a reader asks the agent about them.
|
||||
#[test]
|
||||
fn a_drag_down_the_line_numbers_still_picks_lines() {
|
||||
let (width, height) = (100, 20);
|
||||
let (mut app, backend, buffer) = file_view(FILE, width, height);
|
||||
let (code, first) = find(&buffer, "fn alpha", width, height);
|
||||
let (_, second) = find(&buffer, "bravo", width, height);
|
||||
// The number, the keyboard's mark, the change bar and a space come before the code
|
||||
let gutter = code - 4;
|
||||
|
||||
drag(&mut app, (gutter, first), (gutter, second));
|
||||
let shown = buffer_to_string(&render_app(&mut app, &backend));
|
||||
assert!(shown.contains("ask about lines 1–2"), "the lines are picked: {shown}");
|
||||
assert!(app.outbox.copy.is_none(), "and a pick copies nothing by itself");
|
||||
}
|
||||
|
||||
/// A double-click on the File view's code takes the word under it, the way it does elsewhere.
|
||||
#[test]
|
||||
fn a_double_click_on_file_view_code_takes_the_word() {
|
||||
let (width, height) = (100, 20);
|
||||
let (mut app, backend, buffer) = file_view(FILE, width, height);
|
||||
let (column, row) = find(&buffer, "bravo", width, height);
|
||||
let now = std::time::Instant::now();
|
||||
|
||||
click_cell(&mut app, column + 2, row, now);
|
||||
click_cell(&mut app, column + 2, row, now);
|
||||
render_app(&mut app, &backend);
|
||||
assert_eq!(app.outbox.copy.as_deref(), Some("bravo"));
|
||||
}
|
||||
|
||||
/// A long line wraps, and a drag on a later row selects what that row shows, not the same columns
|
||||
/// from the start of the line.
|
||||
#[test]
|
||||
fn a_drag_on_a_wrapped_row_selects_what_that_row_shows() {
|
||||
let (width, height) = (90, 20);
|
||||
let line = (0..60).map(|index| format!("w{index:03}")).collect::<Vec<_>>().join(" ");
|
||||
let (mut app, _backend, buffer) = file_view(&line, width, height);
|
||||
let (_, first) = find(&buffer, "w000", width, height);
|
||||
// Whichever word sits whole on the row after the first, wherever the wrap fell
|
||||
let text = row_text(&buffer, first + 1, width);
|
||||
let word = (0..60)
|
||||
.map(|index| format!("w{index:03}"))
|
||||
.find(|word| text.contains(&format!("{word} ")))
|
||||
.expect("the line wraps onto a second row");
|
||||
let column = column_of(&text, &word);
|
||||
|
||||
drag(&mut app, (column, first + 1), (column + 4, first + 1));
|
||||
assert_eq!(app.outbox.copy.as_deref(), Some(word.as_str()));
|
||||
}
|
||||
|
||||
/// In a side-by-side diff a drag stays in the column it began in: down the new side it copies the
|
||||
/// new file's lines and skips the deletion the old side draws beside them.
|
||||
#[test]
|
||||
fn a_drag_down_the_new_column_copies_only_new_code() {
|
||||
let (width, height) = (260, 24);
|
||||
let backend = test_backend(width, height);
|
||||
let (mut app, mut rx) = create_app_with_engine();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
app.dock.hide();
|
||||
app.workspace = Some(changed_workspace("peek-select-split", 2));
|
||||
let path = "src/module00/file00.rs";
|
||||
open_changes_with(&mut app, &mut rx, path, Some(one_hunk_file(path)));
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
assert!(split_row(&buffer, "fn sum() {", &app, width, height), "the diff is side by side");
|
||||
|
||||
let top = row_containing(&buffer, "fn sum() {", width, height);
|
||||
let text = row_text(&buffer, top, width);
|
||||
let (byte, _) = text.match_indices("fn sum() {").nth(1).expect("both columns show it");
|
||||
let new_side = text[..byte].chars().count() as u16;
|
||||
let (end, bottom) = find(&buffer, "let total = a - b;", width, height);
|
||||
|
||||
drag(&mut app, (new_side, top), (end + 18, bottom));
|
||||
assert_eq!(app.outbox.copy.as_deref(), Some("fn sum() {\nlet total = a - b;"));
|
||||
}
|
||||
|
||||
/// The unified diff selects the same way, across a deletion and the addition under it, and never
|
||||
/// copies the line numbers or the `-`/`+` signs.
|
||||
#[test]
|
||||
fn a_drag_over_the_unified_diff_copies_its_code() {
|
||||
let (width, height) = (90, 24);
|
||||
let backend = test_backend(width, height);
|
||||
let (mut app, mut rx) = create_app_with_engine();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
app.dock.hide();
|
||||
app.workspace = Some(changed_workspace("peek-select-unified", 2));
|
||||
let path = "src/module00/file00.rs";
|
||||
open_changes_with(&mut app, &mut rx, path, Some(one_hunk_file(path)));
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
assert!(!split_row(&buffer, "fn sum() {", &app, width, height), "the diff is unified");
|
||||
|
||||
let start = find(&buffer, "let total = a + b;", width, height);
|
||||
let (end, bottom) = find(&buffer, "let total = a - b;", width, height);
|
||||
drag(&mut app, start, (end + 18, bottom));
|
||||
assert_eq!(app.outbox.copy.as_deref(), Some("let total = a + b;\nlet total = a - b;"));
|
||||
}
|
||||
177
crates/luxe-tui/tests/render/pickers.rs
Normal file
177
crates/luxe-tui/tests/render/pickers.rs
Normal file
@@ -0,0 +1,177 @@
|
||||
//! Pickers — the thinking, palette and slash rows answer a click.
|
||||
|
||||
use super::*;
|
||||
|
||||
/// Picker clicks (plan B4): clicking a thinking-level row selects + applies it (closing the
|
||||
/// picker) via the shared accept path.
|
||||
#[test]
|
||||
fn clicking_a_thinking_level_row_applies_and_closes_it() {
|
||||
use crossterm::event::{MouseButton, MouseEvent, MouseEventKind};
|
||||
let (width, height) = (100, 30);
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = create_app();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
app.open_thinking_picker();
|
||||
assert!(app.overlays.thinking_picker.is_some(), "picker opens");
|
||||
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
let row = (0..height)
|
||||
.find(|&y| row_text(&buffer, y, width).contains("Medium"))
|
||||
.expect("a thinking-level row renders");
|
||||
let click = MouseEvent {
|
||||
kind: MouseEventKind::Down(MouseButton::Left),
|
||||
column: width / 2,
|
||||
row,
|
||||
modifiers: KeyModifiers::NONE,
|
||||
};
|
||||
match route_mouse(&mut app, &click) {
|
||||
RouteAction::Msg(message) => app.update(*message),
|
||||
other => panic!("expected a synthetic-accept message from the click, got {other:?}"),
|
||||
}
|
||||
assert!(app.overlays.thinking_picker.is_none(), "clicking a level applies and closes it");
|
||||
}
|
||||
|
||||
/// The picker only offers what the active model accepts: a level it can't honor is labeled and
|
||||
/// dimmed, the cursor jumps over it, a click on it does nothing, and the frame names the model the
|
||||
/// annotations belong to.
|
||||
#[test]
|
||||
fn the_thinking_picker_disables_levels_the_model_cannot_honor() {
|
||||
use crossterm::event::{MouseButton, MouseEvent, MouseEventKind};
|
||||
use luxe_core::provider::{ModelInfo, ThinkingLevel};
|
||||
let (width, height) = (100, 30);
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = create_app();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
// An extended-thinking Claude: it reasons, but there is no xhigh or ultra to ask for.
|
||||
app.set_model_catalog(
|
||||
Vec::new(),
|
||||
Some(ModelInfo {
|
||||
display_name: Some("Claude Sonnet 4.5".to_string()),
|
||||
reasoning: true,
|
||||
thinking_level_map: std::collections::HashMap::from([
|
||||
("high".to_string(), Some("high".to_string())),
|
||||
("xhigh".to_string(), None),
|
||||
("ultra".to_string(), None),
|
||||
]),
|
||||
..Default::default()
|
||||
}),
|
||||
);
|
||||
app.open_thinking_picker();
|
||||
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
let screen = buffer_to_string(&buffer);
|
||||
assert!(screen.contains("Claude Sonnet 4.5"), "the frame names the model: {screen}");
|
||||
// Rows sit inside the modal frame behind a cursor gutter, so strip the chrome before matching.
|
||||
let level_row = |label: &str| {
|
||||
(0..height)
|
||||
.find(|&y| {
|
||||
row_text(&buffer, y, width)
|
||||
.trim_start()
|
||||
.trim_start_matches(['│', '❯', ' '])
|
||||
.starts_with(label)
|
||||
})
|
||||
.unwrap_or_else(|| panic!("no row for {label}: {screen}"))
|
||||
};
|
||||
assert!(
|
||||
!row_text(&buffer, level_row("Medium"), width).contains("not supported"),
|
||||
"a level the model honors carries no note"
|
||||
);
|
||||
for label in ["X-High", "Ultra"] {
|
||||
assert!(
|
||||
row_text(&buffer, level_row(label), width).contains("not supported"),
|
||||
"{label} must be labeled unsupported: {screen}"
|
||||
);
|
||||
}
|
||||
|
||||
let click = |row| MouseEvent {
|
||||
kind: MouseEventKind::Down(MouseButton::Left),
|
||||
column: width / 2,
|
||||
row,
|
||||
modifiers: KeyModifiers::NONE,
|
||||
};
|
||||
assert!(
|
||||
matches!(route_mouse(&mut app, &click(level_row("Ultra"))), RouteAction::None),
|
||||
"clicking an unsupported level does nothing"
|
||||
);
|
||||
assert!(app.overlays.thinking_picker.is_some(), "the picker stays open");
|
||||
|
||||
match route_mouse(&mut app, &click(level_row("Medium"))) {
|
||||
RouteAction::Msg(message) => app.update(*message),
|
||||
other => panic!("a supported level should accept the click, got {other:?}"),
|
||||
}
|
||||
assert!(app.overlays.thinking_picker.is_none(), "a supported level applies and closes it");
|
||||
assert_eq!(app.status.thinking, ThinkingLevel::Medium);
|
||||
}
|
||||
|
||||
/// Palette clicks (plan B5): clicking a palette row moves the selection there and dispatches it
|
||||
/// via the shared accept path, closing the palette.
|
||||
#[test]
|
||||
fn clicking_a_palette_row_dispatches_and_closes_it() {
|
||||
use crossterm::event::{MouseButton, MouseEvent, MouseEventKind};
|
||||
let (width, height) = (120, 40);
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = create_app();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
// Ctrl+K opens the command palette.
|
||||
app.update(Msg::Key(KeyEvent::new(KeyCode::Char('k'), KeyModifiers::CONTROL)));
|
||||
assert!(app.overlays.palette.is_some(), "ctrl+k opens the palette");
|
||||
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
let row = (0..height)
|
||||
.find(|&y| row_text(&buffer, y, width).contains("Change theme"))
|
||||
.expect("a palette command row renders");
|
||||
// On the words, since the pane beside the list is not a row
|
||||
let column = row_text(&buffer, row, width).find("Change theme").expect("found above") as u16;
|
||||
let click = MouseEvent {
|
||||
kind: MouseEventKind::Down(MouseButton::Left),
|
||||
column,
|
||||
row,
|
||||
modifiers: KeyModifiers::NONE,
|
||||
};
|
||||
match route_mouse(&mut app, &click) {
|
||||
RouteAction::Msg(message) => app.update(*message),
|
||||
other => panic!("expected a synthetic-accept message from the click, got {other:?}"),
|
||||
}
|
||||
assert!(app.overlays.palette.is_none(), "clicking a palette row dispatches and closes it");
|
||||
assert!(app.overlays.theme_picker.is_some(), "and runs the row that was clicked");
|
||||
}
|
||||
|
||||
/// Slash-flyout clicks: clicking a flyout row accepts it via the shared path, and accepting
|
||||
/// **runs** the command.
|
||||
///
|
||||
/// `/diff` takes an optional target, and picking it used to complete `"/diff "` into the composer
|
||||
/// and stop — which reads as nothing having happened, and was reported as exactly that. Tab is the
|
||||
/// key for completing an argument; Enter and a click run the command's bare form.
|
||||
#[test]
|
||||
fn clicking_a_slash_flyout_row_accepts_it() {
|
||||
use crossterm::event::{MouseButton, MouseEvent, MouseEventKind};
|
||||
let (width, height) = (120, 40);
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = create_app();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
app.update(Msg::Key(KeyEvent::new(KeyCode::Char('/'), KeyModifiers::NONE)));
|
||||
assert!(app.overlays.slash_flyout.is_some(), "typing / opens the slash flyout");
|
||||
// Filter down to it rather than trusting its position: the flyout shows a bounded window, so
|
||||
// asserting against the unfiltered list makes this test fail whenever a command is added
|
||||
// anywhere above `/diff`.
|
||||
for character in "dif".chars() {
|
||||
app.update(Msg::Key(KeyEvent::new(KeyCode::Char(character), KeyModifiers::NONE)));
|
||||
}
|
||||
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
let row = (0..height)
|
||||
.find(|&y| row_text(&buffer, y, width).contains("Review changes"))
|
||||
.expect("the /diff (Review changes) flyout row renders");
|
||||
let click = MouseEvent {
|
||||
kind: MouseEventKind::Down(MouseButton::Left),
|
||||
column: 20,
|
||||
row,
|
||||
modifiers: KeyModifiers::NONE,
|
||||
};
|
||||
match route_mouse(&mut app, &click) {
|
||||
RouteAction::Msg(message) => app.update(*message),
|
||||
other => panic!("expected a synthetic-accept message from the click, got {other:?}"),
|
||||
}
|
||||
assert!(app.overlays.slash_flyout.is_none(), "accepting closes the flyout");
|
||||
assert_eq!(app.editor.current_input(), "", "accepting runs the command and clears the draft");
|
||||
}
|
||||
133
crates/luxe-tui/tests/render/reasoning.rs
Normal file
133
crates/luxe-tui/tests/render/reasoning.rs
Normal file
@@ -0,0 +1,133 @@
|
||||
//! Reasoning — a reasoning block keeps its shape as it commits.
|
||||
|
||||
use super::*;
|
||||
|
||||
/// Streams `parts` as reasoning deltas, one per provider block index.
|
||||
pub(super) fn stream_reasoning(app: &mut App, parts: &[(usize, &str)]) {
|
||||
for (block, delta) in parts {
|
||||
app.update(Msg::Engine(luxe_core::Event::ThinkingDelta {
|
||||
block: *block,
|
||||
delta: (*delta).to_string(),
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn commit_reasoning(app: &mut App, parts: &[&str], answer: Option<&str>) {
|
||||
use luxe_core::message::{ContentBlock, Message, Role};
|
||||
let mut content: Vec<ContentBlock> = parts
|
||||
.iter()
|
||||
.map(|text| ContentBlock::Thinking {
|
||||
text: (*text).to_string(),
|
||||
signature: None,
|
||||
id: None,
|
||||
encrypted: None,
|
||||
opaque: None,
|
||||
})
|
||||
.collect();
|
||||
if let Some(answer) = answer {
|
||||
content.push(ContentBlock::Text(answer.to_string()));
|
||||
}
|
||||
app.update(Msg::Engine(luxe_core::Event::MessageCommitted {
|
||||
session_id: "s".into(),
|
||||
entry_id: luxe_core::session::EntryId("e1".into()),
|
||||
message: Message { role: Role::Assistant, content },
|
||||
}));
|
||||
}
|
||||
|
||||
pub(super) fn chat_app() -> App {
|
||||
let mut app = create_app();
|
||||
app.update(Msg::Engine(luxe_core::Event::SessionLoaded {
|
||||
session_id: "s".into(),
|
||||
messages: vec![],
|
||||
}));
|
||||
app
|
||||
}
|
||||
|
||||
/// The symptom, stated as the invariant: committing a message must not change what is on screen.
|
||||
///
|
||||
/// A message can carry several reasoning items. Core keeps one block per provider output index, so
|
||||
/// if the stream reports them all as block 0 the front-end merges them into one item and the commit
|
||||
/// has to tear the tail down and rebuild it — which the reader sees as the reasoning reflowing, its
|
||||
/// spacing changing, under them.
|
||||
#[test]
|
||||
fn committing_a_multi_part_reasoning_message_does_not_reflow_it() {
|
||||
let backend = test_backend(100, 40);
|
||||
let mut app = chat_app();
|
||||
let parts = ["**Verifying the capture**", "Checking whether the tool is loaded yet."];
|
||||
|
||||
stream_reasoning(&mut app, &[(0, parts[0]), (1, parts[1])]);
|
||||
app.reveal_catch_up();
|
||||
let streamed = rows_of(&render_app(&mut app, &backend));
|
||||
|
||||
commit_reasoning(&mut app, &parts, None);
|
||||
app.reveal_catch_up();
|
||||
let committed = rows_of(&render_app(&mut app, &backend));
|
||||
|
||||
assert_eq!(
|
||||
streamed, committed,
|
||||
"the transcript changed when the message committed — nothing about it should move"
|
||||
);
|
||||
assert_eq!(
|
||||
app.convo.len(),
|
||||
2,
|
||||
"each reasoning item is its own block, streamed and committed alike"
|
||||
);
|
||||
}
|
||||
|
||||
/// Reasoning that carries no text is a replay token, not content: OpenAI returns an item holding
|
||||
/// only `id`/`encrypted_content` whenever summaries are off. Drawing it would invent a block the
|
||||
/// stream never produced — and inventing one is what forces the commit to rebuild the tail.
|
||||
#[test]
|
||||
fn reasoning_with_no_text_is_never_drawn_and_never_reflows() {
|
||||
use luxe_core::message::{ContentBlock, Message, Role};
|
||||
|
||||
let backend = test_backend(100, 40);
|
||||
let mut app = chat_app();
|
||||
app.update(Msg::Engine(luxe_core::Event::TokenDelta { block: 0, delta: "Done.".into() }));
|
||||
app.reveal_catch_up();
|
||||
let streamed = rows_of(&render_app(&mut app, &backend));
|
||||
|
||||
app.update(Msg::Engine(luxe_core::Event::MessageCommitted {
|
||||
session_id: "s".into(),
|
||||
entry_id: luxe_core::session::EntryId("e1".into()),
|
||||
message: Message {
|
||||
role: Role::Assistant,
|
||||
content: vec![
|
||||
// The replay token: no summary text, only what must be sent back next turn.
|
||||
ContentBlock::Thinking {
|
||||
text: String::new(),
|
||||
signature: None,
|
||||
id: Some("rs_1".into()),
|
||||
encrypted: Some("ENC==".into()),
|
||||
opaque: None,
|
||||
},
|
||||
ContentBlock::Text("Done.".into()),
|
||||
],
|
||||
},
|
||||
}));
|
||||
app.reveal_catch_up();
|
||||
|
||||
assert_eq!(rows_of(&render_app(&mut app, &backend)), streamed, "nothing moved");
|
||||
assert_eq!(app.convo.len(), 1, "the replay token is not a transcript item");
|
||||
}
|
||||
|
||||
/// The ordinary case has to keep working: one reasoning item, then the answer, refreshed in place.
|
||||
#[test]
|
||||
fn a_single_reasoning_item_still_commits_in_place() {
|
||||
let backend = test_backend(100, 40);
|
||||
let mut app = chat_app();
|
||||
|
||||
stream_reasoning(&mut app, &[(0, "Thinking about it.")]);
|
||||
app.update(Msg::Engine(luxe_core::Event::TokenDelta {
|
||||
block: 0,
|
||||
delta: "Here is the answer.".into(),
|
||||
}));
|
||||
app.reveal_catch_up();
|
||||
let streamed = rows_of(&render_app(&mut app, &backend));
|
||||
|
||||
commit_reasoning(&mut app, &["Thinking about it."], Some("Here is the answer."));
|
||||
app.reveal_catch_up();
|
||||
|
||||
assert_eq!(rows_of(&render_app(&mut app, &backend)), streamed);
|
||||
assert_eq!(app.convo.len(), 2, "reasoning and answer, not duplicated");
|
||||
}
|
||||
602
crates/luxe-tui/tests/render/reveal.rs
Normal file
602
crates/luxe-tui/tests/render/reveal.rs
Normal file
@@ -0,0 +1,602 @@
|
||||
//! Reveal — streamed text paced onto the screen, and what never waits.
|
||||
|
||||
use super::*;
|
||||
|
||||
/// One provider lump, the size Anthropic actually delivers (~75 characters at a time).
|
||||
pub(super) const LUMP: &str =
|
||||
"alpha the provider hands you text in lumps and the render loop paints omega";
|
||||
/// Characters of `text` a frame is showing, ignoring everything between them.
|
||||
///
|
||||
/// Letters only: wrapping breaks the text across rows, and the chrome those rows end with — a
|
||||
/// scrollbar lane, a panel border — would otherwise interrupt the match.
|
||||
pub(super) fn revealed_count(frame: &str, text: &str) -> usize {
|
||||
let flat: String = frame.chars().filter(char::is_ascii_alphanumeric).collect();
|
||||
let target: Vec<char> = text.chars().filter(char::is_ascii_alphanumeric).collect();
|
||||
(0..=target.len())
|
||||
.rev()
|
||||
.find(|n| flat.contains(&target[..*n].iter().collect::<String>()))
|
||||
.unwrap_or(0)
|
||||
}
|
||||
|
||||
/// Runs the reveal forward the way the event loop does: one frame every 12 ms.
|
||||
///
|
||||
/// `at` is the frame the clock has reached and is advanced in place, so successive calls continue
|
||||
/// rather than replaying from the start. Jumping the clock instead of stepping it would prove nothing
|
||||
/// — a frame's timestep is capped precisely so that a suspended terminal cannot dump the whole buffer
|
||||
/// on its next frame.
|
||||
pub(super) fn advance_frames(
|
||||
app: &mut App,
|
||||
backend: &TestBackend,
|
||||
base: std::time::Instant,
|
||||
at: &mut u32,
|
||||
frames: u32,
|
||||
) -> String {
|
||||
let mut painted = String::new();
|
||||
for _ in 0..frames {
|
||||
*at += 1;
|
||||
app.status.frame_clock = Some(base + std::time::Duration::from_millis(12) * *at);
|
||||
painted = buffer_to_string(&render_app(app, backend));
|
||||
}
|
||||
painted
|
||||
}
|
||||
|
||||
/// Streamed prose is paced onto the screen instead of landing in the provider's lumps.
|
||||
#[test]
|
||||
fn streamed_prose_is_revealed_as_it_is_paced() {
|
||||
let backend = test_backend(60, 20);
|
||||
let mut app = create_app();
|
||||
let base = std::time::Instant::now();
|
||||
app.status.frame_clock = Some(base);
|
||||
let total = LUMP.chars().filter(|c| !c.is_whitespace()).count();
|
||||
|
||||
app.update(Msg::Engine(luxe_core::event::Event::TokenDelta { block: 0, delta: LUMP.into() }));
|
||||
let mut at = 0;
|
||||
// Nothing yet: the reveal gathers a buffer before its first paint, rather than showing the
|
||||
// opening characters and freezing until the next arrival lands.
|
||||
let first = buffer_to_string(&render_app(&mut app, &backend));
|
||||
assert_eq!(revealed_count(&first, LUMP), 0, "the first paint waits for a buffer: {first}");
|
||||
|
||||
// Past the priming ceiling it starts painting — and paces, rather than dropping the lot.
|
||||
let started = advance_frames(&mut app, &backend, base, &mut at, 45);
|
||||
let seen = revealed_count(&started, LUMP);
|
||||
assert!(seen > 0, "painting has started: {started}");
|
||||
assert!(seen < total, "but it stays behind the text that arrived: {seen} of {total}");
|
||||
|
||||
// A few frames on, more of it has resolved.
|
||||
let midway = advance_frames(&mut app, &backend, base, &mut at, 10);
|
||||
let more = revealed_count(&midway, LUMP);
|
||||
assert!(more > seen, "the reveal advances with the clock: {more} vs {seen}");
|
||||
|
||||
// The turn ends, so nothing more can arrive: the buffer drains to its deadline.
|
||||
app.update(Msg::Engine(luxe_core::event::Event::TurnEnded {
|
||||
reason: luxe_core::event::StopReason::EndTurn,
|
||||
}));
|
||||
let done = advance_frames(&mut app, &backend, base, &mut at, 60);
|
||||
assert_eq!(revealed_count(&done, LUMP), total, "a finished message is all there: {done}");
|
||||
assert!(!app.reveal.pending(), "and the reveal has nothing left to show");
|
||||
}
|
||||
|
||||
/// The ordering rule, end to end: a card cannot appear above prose that is still arriving.
|
||||
#[test]
|
||||
fn a_tool_card_waits_for_the_prose_above_it() {
|
||||
let backend = test_backend(60, 20);
|
||||
let mut app = create_app();
|
||||
let base = std::time::Instant::now();
|
||||
app.status.frame_clock = Some(base);
|
||||
|
||||
app.update(Msg::Engine(luxe_core::event::Event::TokenDelta { block: 0, delta: LUMP.into() }));
|
||||
let mut activity = ToolActivity::running("session-a", "call-read", "read", "src/lib.rs", 1);
|
||||
activity.state = ToolActivityState::Succeeded;
|
||||
app.push_convo(ConvoBlock::Tool(Box::new(ToolItem {
|
||||
activity,
|
||||
expanded: false,
|
||||
details_toggled: false,
|
||||
waited_on_user_ms: 0,
|
||||
})));
|
||||
|
||||
let held = buffer_to_string(&render_app(&mut app, &backend));
|
||||
assert!(!held.contains("src/lib.rs"), "the card waits its turn: {held}");
|
||||
|
||||
// The card being there at all means the message is complete, so the prose drains and both land.
|
||||
let mut at = 0;
|
||||
let landed = advance_frames(&mut app, &backend, base, &mut at, 90);
|
||||
assert!(landed.contains("src/lib.rs"), "and lands once the prose is done: {landed}");
|
||||
assert_eq!(
|
||||
revealed_count(&landed, LUMP),
|
||||
LUMP.chars().filter(|c| !c.is_whitespace()).count(),
|
||||
"with the prose complete above it: {landed}"
|
||||
);
|
||||
}
|
||||
|
||||
/// Reasoning shown as a one-line peek has nothing to type out, and must never gate what follows.
|
||||
#[test]
|
||||
fn collapsed_reasoning_is_never_paced() {
|
||||
let config = Config {
|
||||
conversation: luxe_core::config::ConversationConfig {
|
||||
thinking: Some(luxe_core::config::ThinkingDisplay::Collapsed),
|
||||
..Default::default()
|
||||
},
|
||||
..Default::default()
|
||||
};
|
||||
let backend = test_backend(60, 20);
|
||||
let mut app = create_app_with_config(config);
|
||||
app.status.frame_clock = Some(std::time::Instant::now());
|
||||
app.update(Msg::Engine(luxe_core::event::Event::ThinkingDelta {
|
||||
block: 0,
|
||||
delta: "weighing the options before answering".into(),
|
||||
}));
|
||||
let frame = buffer_to_string(&render_app(&mut app, &backend));
|
||||
assert!(frame.contains("weighing the options"), "the peek is drawn at once: {frame}");
|
||||
}
|
||||
|
||||
/// `stream_reveal: off` is a real off: the same instant paint as before the reveal existed.
|
||||
#[test]
|
||||
fn stream_reveal_off_paints_every_arrival_immediately() {
|
||||
let config = Config {
|
||||
conversation: luxe_core::config::ConversationConfig {
|
||||
stream_reveal: Some(luxe_core::config::StreamReveal::Off),
|
||||
..Default::default()
|
||||
},
|
||||
..Default::default()
|
||||
};
|
||||
let backend = test_backend(60, 20);
|
||||
let mut app = create_app_with_config(config);
|
||||
app.status.frame_clock = Some(std::time::Instant::now());
|
||||
app.update(Msg::Engine(luxe_core::event::Event::TokenDelta { block: 0, delta: LUMP.into() }));
|
||||
let frame = buffer_to_string(&render_app(&mut app, &backend));
|
||||
assert!(frame.contains("alpha") && frame.contains("omega"), "all of it, at once: {frame}");
|
||||
}
|
||||
|
||||
/// Anything that needs the user stops animating around them.
|
||||
#[test]
|
||||
fn a_permission_prompt_shows_everything_that_arrived() {
|
||||
let backend = test_backend(60, 24);
|
||||
let mut app = create_app();
|
||||
app.status.frame_clock = Some(std::time::Instant::now());
|
||||
app.update(Msg::Engine(luxe_core::event::Event::TokenDelta { block: 0, delta: LUMP.into() }));
|
||||
let total = LUMP.chars().filter(char::is_ascii_alphanumeric).count();
|
||||
let held = buffer_to_string(&render_app(&mut app, &backend));
|
||||
assert!(revealed_count(&held, LUMP) < total, "mid-reveal to begin with: {held}");
|
||||
|
||||
app.update(Msg::Engine(luxe_core::event::Event::PermissionRequested {
|
||||
id: luxe_core::permission::PermissionRequestId::new(),
|
||||
session_id: "session-a".into(),
|
||||
tool: "bash".into(),
|
||||
permission: "bash".into(),
|
||||
summary: "Run: rm -rf /etc".into(),
|
||||
always_patterns: Vec::new(),
|
||||
}));
|
||||
let asked = buffer_to_string(&render_app(&mut app, &backend));
|
||||
assert!(asked.contains("Permission required"), "the prompt is up: {asked}");
|
||||
// Nothing is held back behind it either — dismissing it has to reveal a whole message rather
|
||||
// than the half sentence the reveal happened to be on.
|
||||
assert!(!app.reveal.pending(), "a question is not asked over text that is still arriving");
|
||||
|
||||
app.update(Msg::Engine(luxe_core::event::Event::TurnEnded {
|
||||
reason: luxe_core::event::StopReason::EndTurn,
|
||||
}));
|
||||
let answered = buffer_to_string(&render_app(&mut app, &backend));
|
||||
assert_eq!(revealed_count(&answered, LUMP), total, "all of it is there: {answered}");
|
||||
}
|
||||
|
||||
/// A prompt grows up from the composer over a `Clear`, so it used to paint out whatever the
|
||||
/// transcript had last drawn there — which is the output it is asking about. The conversation
|
||||
/// stands down by the rows the panel takes instead, and both are readable at once.
|
||||
#[test]
|
||||
fn a_prompt_above_the_composer_does_not_cover_the_output_that_prompted_it() {
|
||||
let backend = test_backend(60, 30);
|
||||
let ask = |app: &mut App, event| {
|
||||
app.update(Msg::Key(KeyEvent::new(KeyCode::Esc, KeyModifiers::NONE)));
|
||||
app.update(Msg::Engine(event));
|
||||
buffer_to_string(&render_app(app, &backend))
|
||||
};
|
||||
|
||||
let mut app = create_app();
|
||||
// Longer than the viewport, so the tail sits at the bottom whichever way the transcript grows.
|
||||
for index in 0..40 {
|
||||
app.push_convo(ConvoBlock::Assistant(format!("reasoning line {index}")));
|
||||
}
|
||||
// The composer is the last panel on screen, so its top border is the last one drawn.
|
||||
let composer_row =
|
||||
|frame: &str| frame.lines().collect::<Vec<_>>().iter().rposition(|row| row.contains('╭'));
|
||||
let idle = buffer_to_string(&render_app(&mut app, &backend));
|
||||
assert!(idle.contains("reasoning line 39"), "the tail is on screen to begin with: {idle}");
|
||||
let composer = composer_row(&idle).expect("a composer");
|
||||
|
||||
let asked = ask(
|
||||
&mut app,
|
||||
luxe_core::event::Event::QuestionAsked {
|
||||
id: luxe_core::question::QuestionRequestId::new(),
|
||||
session_id: "session-a".into(),
|
||||
prompt: "Which runtime should the worker use?".into(),
|
||||
options: vec!["tokio".into(), "async-std".into()],
|
||||
multi: false,
|
||||
},
|
||||
);
|
||||
assert!(asked.contains("Which runtime"), "the question is up: {asked}");
|
||||
assert!(asked.contains("reasoning line 39"), "and so is what prompted it: {asked}");
|
||||
|
||||
let approved = ask(
|
||||
&mut app,
|
||||
luxe_core::event::Event::PermissionRequested {
|
||||
id: luxe_core::permission::PermissionRequestId::new(),
|
||||
session_id: "session-a".into(),
|
||||
tool: "bash".into(),
|
||||
permission: "bash".into(),
|
||||
summary: "Run: rm -rf build".into(),
|
||||
always_patterns: Vec::new(),
|
||||
},
|
||||
);
|
||||
assert!(approved.contains("Permission required"), "the ask is up: {approved}");
|
||||
assert!(approved.contains("reasoning line 39"), "and so is what prompted it: {approved}");
|
||||
|
||||
// The rows come out of the conversation, never out of the prompt the reader types into.
|
||||
for frame in [&asked, &approved] {
|
||||
assert_eq!(composer_row(frame), Some(composer), "the composer moved: {frame}");
|
||||
}
|
||||
|
||||
// A terminal with no rows to spare keeps the prompt whole and the composer intact — the
|
||||
// conversation can only stand down from rows it has.
|
||||
let cramped = buffer_to_string(&render_app(&mut app, &test_backend(60, 12)));
|
||||
assert!(cramped.contains("Allow once"), "the prompt is not squeezed: {cramped}");
|
||||
let rows: Vec<&str> = cramped.lines().collect();
|
||||
let top = composer_row(&cramped).expect("a composer");
|
||||
assert!(rows[top + 2].contains('╰'), "the composer kept its rows: {cramped}");
|
||||
}
|
||||
|
||||
/// Scrolled away from the bottom there is no animation to see, so nothing is held back — and coming
|
||||
/// back to the bottom shows the whole message rather than a stale prefix of it.
|
||||
#[test]
|
||||
fn scrolling_away_from_the_bottom_stops_holding_text_back() {
|
||||
let backend = test_backend(60, 10);
|
||||
let mut app = create_app();
|
||||
// Enough transcript to have somewhere to scroll.
|
||||
for index in 0..8 {
|
||||
app.push_convo(ConvoBlock::User {
|
||||
text: format!("earlier {index}"),
|
||||
attached: Vec::new(),
|
||||
chips: Vec::new(),
|
||||
});
|
||||
}
|
||||
let base = std::time::Instant::now();
|
||||
app.status.frame_clock = Some(base);
|
||||
app.update(Msg::Engine(luxe_core::event::Event::TokenDelta { block: 0, delta: LUMP.into() }));
|
||||
let _ = render_app(&mut app, &backend);
|
||||
|
||||
app.scroll_state.up_by(3);
|
||||
assert!(!app.scroll_state.follow, "scrolling up leaves the bottom");
|
||||
let _ = render_app(&mut app, &backend);
|
||||
assert!(!app.reveal.pending(), "nothing is held back while the tail is off screen");
|
||||
|
||||
app.scroll_state.to_bottom();
|
||||
let back = buffer_to_string(&render_app(&mut app, &backend));
|
||||
assert_eq!(
|
||||
revealed_count(&back, LUMP),
|
||||
LUMP.chars().filter(|c| !c.is_whitespace()).count(),
|
||||
"coming back to the bottom shows the whole message: {back}"
|
||||
);
|
||||
}
|
||||
|
||||
/// Where `needle` starts in the rendered buffer, as `(x, y)`.
|
||||
pub(super) fn find_in_buffer(buffer: &Buffer, needle: &str) -> Option<(u16, u16)> {
|
||||
(0..buffer.area.height).find_map(|y| {
|
||||
let row: String = (0..buffer.area.width).map(|x| buffer[(x, y)].symbol()).collect();
|
||||
row.find(needle).map(|byte| (row[..byte].chars().count() as u16, y))
|
||||
})
|
||||
}
|
||||
|
||||
/// The bug: a stream that goes quiet without closing left its last word painted on the canvas.
|
||||
///
|
||||
/// The trail that fades in behind the reveal cursor says "these characters are still arriving".
|
||||
/// When the frontier catches up and nothing follows — a model pausing mid-answer, a block waiting
|
||||
/// on the one after it, a provider that stops before it closes — the claim stops being true and the
|
||||
/// newest characters are simply text the reader cannot see. Measured here the way a reader meets
|
||||
/// it: the foreground the terminal is actually told to paint.
|
||||
#[test]
|
||||
fn a_stalled_stream_resolves_its_last_characters() {
|
||||
let backend = test_backend(110, 20);
|
||||
let mut app = create_app();
|
||||
let base = std::time::Instant::now();
|
||||
app.status.frame_clock = Some(base);
|
||||
let total = LUMP.chars().filter(|c| !c.is_whitespace()).count();
|
||||
app.update(Msg::Engine(luxe_core::event::Event::TokenDelta { block: 0, delta: LUMP.into() }));
|
||||
|
||||
// Pace it out to the end of the lump. Nothing closes the stream, so the item stays growing.
|
||||
let mut at = 0u32;
|
||||
for _ in 0..400 {
|
||||
let painted = advance_frames(&mut app, &backend, base, &mut at, 1);
|
||||
if revealed_count(&painted, LUMP) == total {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
let (head_x, head_y) = find_in_buffer(&buffer, "alpha").expect("the settled start is drawn");
|
||||
let (tail_x, tail_y) = find_in_buffer(&buffer, "omega").expect("the newest word is drawn");
|
||||
let tail = (tail_x + 4, tail_y);
|
||||
let settled_fg = buffer[(head_x, head_y)].fg;
|
||||
|
||||
assert_ne!(
|
||||
buffer[tail].fg, settled_fg,
|
||||
"precondition: the character that just landed is still fading in"
|
||||
);
|
||||
|
||||
// Nothing more arrives. The tail has to become readable, and on its own.
|
||||
let budget = 40;
|
||||
advance_frames(&mut app, &backend, base, &mut at, budget);
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
|
||||
assert_eq!(
|
||||
buffer[tail].fg, settled_fg,
|
||||
"the last character of a stalled stream is still painted on the background"
|
||||
);
|
||||
assert!(
|
||||
!app.reveal.pending(),
|
||||
"and the reveal clock stops rather than spinning on a still frame"
|
||||
);
|
||||
}
|
||||
|
||||
/// A still screen must be still. The image viewer draws over a transcript that also draws the same
|
||||
/// image, and asking the store for one image at two sizes made every frame release and re-transmit
|
||||
/// it — which shows up as the picture flickering while nothing is happening.
|
||||
#[test]
|
||||
fn the_open_image_viewer_does_not_re_transmit_on_every_frame() {
|
||||
let backend = test_backend(100, 32);
|
||||
let mut app = app_with_image(luxe_tui::graphics::ImageTier::Pixels);
|
||||
let key = app.newest_visible_image().expect("the transcript has an image");
|
||||
app.update(Msg::OpenImageViewer(key));
|
||||
|
||||
render_app(&mut app, &backend);
|
||||
assert!(!app.images.drain_control().is_empty(), "the first frame transmits it");
|
||||
|
||||
for frame in 0..4 {
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
assert!(
|
||||
app.images.drain_control().is_empty(),
|
||||
"frame {frame} re-transmitted the image the viewer is already showing"
|
||||
);
|
||||
assert!(
|
||||
buffer.content.iter().any(|cell| cell.symbol().starts_with('\u{10EEEE}')),
|
||||
"and it is still on screen"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Closing the viewer puts the transcript's own copy back, at the transcript's size.
|
||||
#[test]
|
||||
fn closing_the_viewer_returns_the_transcript_to_its_own_size() {
|
||||
let backend = test_backend(100, 32);
|
||||
let mut app = app_with_image(luxe_tui::graphics::ImageTier::Pixels);
|
||||
let key = app.newest_visible_image().expect("an image");
|
||||
|
||||
render_app(&mut app, &backend);
|
||||
let inline = app.images.fit(&key, 60, 12).expect("a transcript fit");
|
||||
|
||||
app.update(Msg::OpenImageViewer(key.clone()));
|
||||
render_app(&mut app, &backend);
|
||||
app.images.drain_control();
|
||||
|
||||
app.update(Msg::CloseImageViewer);
|
||||
assert!(app.overlays.image_viewer.is_none());
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
assert!(
|
||||
buffer.content.iter().any(|cell| cell.symbol().starts_with('\u{10EEEE}')),
|
||||
"the transcript draws it again"
|
||||
);
|
||||
assert!(inline.rows >= 1, "and the transcript's own size is still a real one");
|
||||
}
|
||||
|
||||
/// Which image rows the buffer is currently showing, in screen order.
|
||||
///
|
||||
/// A kitty placeholder addresses itself, so the buffer says exactly which row of the image each
|
||||
/// cell is displaying — which is what makes the clipping checkable rather than a matter of opinion.
|
||||
pub(super) fn painted_image_rows(buffer: &Buffer) -> Vec<u16> {
|
||||
let width = buffer.area.width as usize;
|
||||
buffer
|
||||
.content
|
||||
.chunks(width)
|
||||
.filter_map(|row| {
|
||||
let symbol = row
|
||||
.iter()
|
||||
.map(|cell| cell.symbol())
|
||||
.find(|symbol| symbol.starts_with('\u{10EEEE}'))?;
|
||||
// Second char is the row diacritic; its index in the protocol's alphabet is the row.
|
||||
let diacritic = symbol.chars().nth(1)?;
|
||||
u16::try_from(ROW_DIACRITICS.iter().position(|mark| *mark == diacritic)?).ok()
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// The first few entries of the protocol's coordinate alphabet — enough for any capped image.
|
||||
pub(super) const ROW_DIACRITICS: [char; 24] = [
|
||||
'\u{305}', '\u{30D}', '\u{30E}', '\u{310}', '\u{312}', '\u{33D}', '\u{33E}', '\u{33F}',
|
||||
'\u{346}', '\u{34A}', '\u{34B}', '\u{34C}', '\u{350}', '\u{351}', '\u{352}', '\u{357}',
|
||||
'\u{35B}', '\u{363}', '\u{364}', '\u{365}', '\u{366}', '\u{367}', '\u{368}', '\u{369}',
|
||||
];
|
||||
/// Scrolling a picture through a viewport made of text is the case the whole placement design
|
||||
/// exists for. Only the visible rows are painted, they are the *right* rows, and when the image
|
||||
/// leaves the viewport nothing of it is left behind — the ghost image that every cursor-positioned
|
||||
/// approach has to clean up by hand, and that this one cannot produce.
|
||||
#[test]
|
||||
fn an_image_scrolls_through_the_viewport_without_leaving_anything_behind() {
|
||||
let backend = test_backend(100, 18);
|
||||
let mut app = app_with_image(luxe_tui::graphics::ImageTier::Pixels);
|
||||
for index in 0..40 {
|
||||
app.push_convo(ConvoBlock::Assistant(format!("line of prose number {index}")));
|
||||
}
|
||||
app.update(Msg::TerminalResized { width: 100, height: 18 });
|
||||
|
||||
// Walk the transcript from the top, one line at a time, and watch the image go by.
|
||||
app.scroll_state.follow = false;
|
||||
let mut seen_partial_top = false;
|
||||
let mut seen_whole = false;
|
||||
let mut fit_rows = 0;
|
||||
|
||||
for offset in 0..30 {
|
||||
app.scroll_state.offset = offset;
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
let rows = painted_image_rows(&buffer);
|
||||
if rows.is_empty() {
|
||||
continue;
|
||||
}
|
||||
// Whatever is on screen is a contiguous run of the image's rows, in order.
|
||||
assert!(
|
||||
rows.windows(2).all(|pair| pair[1] == pair[0] + 1),
|
||||
"image rows on screen are contiguous and in order, got {rows:?}"
|
||||
);
|
||||
fit_rows = fit_rows.max(rows.last().copied().unwrap_or(0) + 1);
|
||||
if *rows.first().expect("non-empty") > 0 {
|
||||
seen_partial_top = true;
|
||||
}
|
||||
if rows.len() > 1 && rows.first() == Some(&0) {
|
||||
seen_whole = true;
|
||||
}
|
||||
}
|
||||
|
||||
// And with the transcript scrolled well past it, not one cell of it survives. The image sits
|
||||
// at the top of this transcript, so "past it" is a large offset.
|
||||
app.scroll_state.offset = 40;
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
let left_behind = painted_image_rows(&buffer);
|
||||
|
||||
assert!(fit_rows > 1, "the image occupied several rows: {fit_rows}");
|
||||
assert!(seen_whole, "it was fully visible at some point");
|
||||
assert!(seen_partial_top, "and clipped at the top of the viewport at another");
|
||||
assert!(
|
||||
left_behind.is_empty(),
|
||||
"scrolled away entirely, no placeholder cell is left behind — the ghost image this \
|
||||
placement design exists to make impossible; found {left_behind:?}"
|
||||
);
|
||||
}
|
||||
|
||||
/// The tool the reader never asked to watch. `activate_tools` loads a deferred tool's schema — a
|
||||
/// fact about Luxe's request budget, not a step in anyone's task — and it lands directly in front
|
||||
/// of the tool that actually did something. A successful one leaves no card; a failed one does,
|
||||
/// because a call nobody can see cannot explain the stall it caused.
|
||||
#[test]
|
||||
fn a_successful_schema_load_leaves_no_card_but_a_failed_one_does() {
|
||||
let backend = test_backend(100, 24);
|
||||
let mut app = create_app();
|
||||
app.update(Msg::Engine(luxe_core::Event::SessionLoaded {
|
||||
session_id: "session-a".into(),
|
||||
messages: vec![],
|
||||
}));
|
||||
|
||||
let activity = |call: &str, name: &str, state, revision| {
|
||||
let mut activity = luxe_core::ToolActivity::running("session-a", call, name, name, 1);
|
||||
activity.state = state;
|
||||
activity.revision = revision;
|
||||
luxe_core::Event::ToolActivityUpdated(Box::new(activity))
|
||||
};
|
||||
|
||||
app.update(Msg::Engine(activity("c1", "activate_tools", ToolActivityState::Running, 0)));
|
||||
app.update(Msg::Engine(activity("c1", "activate_tools", ToolActivityState::Succeeded, 1)));
|
||||
app.update(Msg::Engine(activity("c2", "screenshot", ToolActivityState::Succeeded, 1)));
|
||||
|
||||
let rendered = rows_of(&render_app(&mut app, &backend)).join("\n");
|
||||
assert!(rendered.contains("screenshot"), "the tool that did something is on screen");
|
||||
assert!(
|
||||
!rendered.contains("activate_tools"),
|
||||
"the schema load that went fine is not: {rendered}"
|
||||
);
|
||||
// The state is still recorded, so nothing downstream lost track of the call.
|
||||
assert!(app.tool_activity.contains_key(&("session-a".into(), "c1".into())));
|
||||
|
||||
// One that failed has to be visible — the model is about to do something inexplicable.
|
||||
app.update(Msg::Engine(activity("c3", "activate_tools", ToolActivityState::Failed, 1)));
|
||||
let rendered = rows_of(&render_app(&mut app, &backend)).join("\n");
|
||||
assert!(rendered.contains("activate_tools"), "a failed schema load explains itself");
|
||||
}
|
||||
|
||||
/// Rows of the transcript that carry anything, as a crude "how much is on screen" measure.
|
||||
pub(super) fn occupied_rows(buffer: &Buffer) -> usize {
|
||||
rows_of(buffer).iter().filter(|row| !row.trim().is_empty()).count()
|
||||
}
|
||||
|
||||
/// A turn only ever adds. Content that appears and then vanishes reads as a glitch even when the
|
||||
/// end state is right, and the transcript has several ways to do it by accident: the staggered
|
||||
/// reveal, a card gaining its body, and — since images — a card growing by the height of a picture
|
||||
/// the moment the pixels land. This drives the exact event order of a `screenshot` turn and asserts
|
||||
/// the transcript never shrinks between frames.
|
||||
#[test]
|
||||
fn a_streaming_turn_never_takes_content_back() {
|
||||
use luxe_core::message::{ContentBlock, Message, Role, ToolOutput};
|
||||
|
||||
let backend = test_backend(100, 40);
|
||||
let mut app = create_app();
|
||||
app.images = pinned_store(luxe_tui::graphics::ImageTier::Pixels);
|
||||
app.update(Msg::Engine(luxe_core::Event::SessionLoaded {
|
||||
session_id: "s".into(),
|
||||
messages: vec![],
|
||||
}));
|
||||
// The reveal is what stages content in; pace it off so this measures structure, not animation.
|
||||
app.reveal_catch_up();
|
||||
|
||||
let mut frames: Vec<(&str, usize)> = Vec::new();
|
||||
let mut observe = |app: &mut App, label: &'static str| {
|
||||
app.reveal_catch_up();
|
||||
frames.push((label, occupied_rows(&render_app(app, &backend))));
|
||||
};
|
||||
|
||||
app.push_convo(ConvoBlock::User {
|
||||
text: "how does the page look?".into(),
|
||||
attached: vec![],
|
||||
chips: Vec::new(),
|
||||
});
|
||||
observe(&mut app, "user message");
|
||||
|
||||
app.update(Msg::Engine(luxe_core::Event::ThinkingDelta {
|
||||
block: 0,
|
||||
delta: "Checking whether the screenshot tool is loaded.".into(),
|
||||
}));
|
||||
observe(&mut app, "reasoning");
|
||||
|
||||
let call = luxe_core::ToolActivity::running("s", "c1", "screenshot", "url · e.com", 1);
|
||||
app.update(Msg::Engine(luxe_core::Event::ToolActivityUpdated(Box::new(call.clone()))));
|
||||
observe(&mut app, "tool started");
|
||||
|
||||
// The result commits first (this is where the pixels arrive), then the activity goes terminal.
|
||||
app.update(Msg::Engine(luxe_core::Event::MessageCommitted {
|
||||
session_id: "s".into(),
|
||||
entry_id: luxe_core::session::EntryId("e1".into()),
|
||||
message: Message {
|
||||
role: Role::Tool,
|
||||
content: vec![ContentBlock::ToolResult {
|
||||
call_id: "c1".into(),
|
||||
content: vec![
|
||||
ToolOutput::Text("Captured url (320x160).".into()),
|
||||
ToolOutput::Image {
|
||||
data: split_png(320, 160),
|
||||
mime: "image/png".into(),
|
||||
name: None,
|
||||
},
|
||||
],
|
||||
is_error: false,
|
||||
}],
|
||||
},
|
||||
}));
|
||||
observe(&mut app, "image arrived");
|
||||
|
||||
let mut done = call;
|
||||
done.revision = 1;
|
||||
done.state = ToolActivityState::Succeeded;
|
||||
done.elapsed_ms = Some(362);
|
||||
app.update(Msg::Engine(luxe_core::Event::ToolActivityUpdated(Box::new(done))));
|
||||
observe(&mut app, "tool finished");
|
||||
|
||||
app.update(Msg::Engine(luxe_core::Event::TokenDelta {
|
||||
block: 1,
|
||||
delta: "A sparse white page with a centered heading.".into(),
|
||||
}));
|
||||
observe(&mut app, "answer");
|
||||
|
||||
for pair in frames.windows(2) {
|
||||
let ((before, was), (after, now)) = (pair[0], pair[1]);
|
||||
assert!(
|
||||
now >= was,
|
||||
"the transcript shrank going from {before} ({was} rows) to {after} ({now} rows) — \
|
||||
content that appears and then vanishes reads as a glitch"
|
||||
);
|
||||
}
|
||||
assert!(frames.last().expect("frames").1 > frames[0].1, "and it grew overall: {frames:?}");
|
||||
}
|
||||
344
crates/luxe-tui/tests/render/review_context.rs
Normal file
344
crates/luxe-tui/tests/render/review_context.rs
Normal file
@@ -0,0 +1,344 @@
|
||||
//! Review context — the backdrop, the rail and the guide's head.
|
||||
|
||||
use super::*;
|
||||
|
||||
/// A modal overlay dims the review behind it, but a blanket `set_style(dim)` patched every cell's
|
||||
/// foreground — and nearly every bundled theme maps `selectedBg` to the same color as `dim`, so the
|
||||
/// selected file row and diff line rendered as unreadable solid blocks. Highlighted cells must step
|
||||
/// up to `muted` instead.
|
||||
#[test]
|
||||
fn modal_backdrop_keeps_highlighted_review_rows_readable() {
|
||||
let (width, height) = (160, 40);
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = seeded_app("nord", FixtureScenario::GuidedReviewReady).unwrap();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
|
||||
let selected_bg = app.theme_styles.selected_bg.bg.expect("selection background");
|
||||
let dim = app.theme_styles.dim.fg.expect("dim foreground");
|
||||
let muted = app.theme_styles.muted.fg.expect("muted foreground");
|
||||
assert_eq!(dim, selected_bg, "nord maps selectedBg onto dim — the case this guards");
|
||||
|
||||
let before = render_app(&mut app, &backend);
|
||||
let highlighted: Vec<(u16, u16)> = (0..height)
|
||||
.flat_map(|y| (0..width).map(move |x| (x, y)))
|
||||
.filter(|&(x, y)| before[(x, y)].bg == selected_bg)
|
||||
.collect();
|
||||
assert!(!highlighted.is_empty(), "the fixture renders a selected row");
|
||||
|
||||
app.update(Msg::GuidedReviewToggleHelp);
|
||||
let after = render_app(&mut app, &backend);
|
||||
for (x, y) in highlighted {
|
||||
// Overlay cells legitimately repaint; only the backdrop behind it is under test.
|
||||
if after[(x, y)].bg != selected_bg {
|
||||
continue;
|
||||
}
|
||||
assert_ne!(
|
||||
after[(x, y)].fg,
|
||||
selected_bg,
|
||||
"cell ({x},{y}) became invisible dim-on-dim behind the overlay"
|
||||
);
|
||||
assert_eq!(after[(x, y)].fg, muted, "highlighted backdrop cells step up to muted");
|
||||
}
|
||||
}
|
||||
|
||||
/// The review carries no wait, because it does not open until there is nothing left to wait for.
|
||||
///
|
||||
/// Every heading, sentence and per-file note here arrives with the guide pass, which takes tens of
|
||||
/// seconds on a local model. This surface used to open on a structural placeholder and rewrite
|
||||
/// itself under the reader — first silently, then behind a spinner that only advanced if something
|
||||
/// happened to tick. Both were answers to the wrong question: the reader should not be on this
|
||||
/// screen yet. The waiting is announced in the tray above the composer, where they are.
|
||||
#[test]
|
||||
fn the_review_surface_never_shows_a_wait_and_the_tray_does() {
|
||||
let (width, height) = (160, 40);
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = seeded_app("nord", FixtureScenario::GuidedReviewReady).unwrap();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
|
||||
let shown = buffer_to_string(&render_app(&mut app, &backend));
|
||||
assert!(!shown.contains("writing the guide"), "no wait on the review: {shown}");
|
||||
|
||||
// And in the conversation, a review being prepared says so where it can be read.
|
||||
let mut chat = seeded_app("nord", FixtureScenario::ChatIdle).unwrap();
|
||||
chat.update(Msg::TerminalResized { width, height });
|
||||
chat.review.queued = Some(luxe_tui::app::QueuedReview {
|
||||
target: luxe_core::guided_review::ReviewTarget::WorkingTree,
|
||||
state: luxe_tui::app::QueuedReviewState::Capturing,
|
||||
});
|
||||
let waiting = buffer_to_string(&render_app(&mut chat, &backend));
|
||||
assert!(waiting.contains("capturing"), "the tray carries the wait: {waiting}");
|
||||
|
||||
chat.review.queued.as_mut().expect("queued").state = luxe_tui::app::QueuedReviewState::Ready;
|
||||
let ready = buffer_to_string(&render_app(&mut chat, &backend));
|
||||
assert!(ready.contains("review ready"), "and then offers: {ready}");
|
||||
}
|
||||
|
||||
/// A review opens on deterministic chapters and upgrades in place, so the rail must say which it
|
||||
/// is showing — a structural placeholder read as the agent's explanation is worse than no prose.
|
||||
#[test]
|
||||
fn the_rail_names_how_the_visible_chapters_were_produced() {
|
||||
let (width, height) = (160, 40);
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = seeded_app("nord", FixtureScenario::GuidedReviewReady).unwrap();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
|
||||
let review = app.guided_review.clone().expect("fixture review");
|
||||
app.update(Msg::Engine(luxe_core::event::Event::GuidedReviewGuideUpdated {
|
||||
request_id: luxe_core::guided_review::ReviewLoadRequestId::new(),
|
||||
review_id: review.id.clone(),
|
||||
revision_id: review.revision_id.clone(),
|
||||
chapters: review.chapters.clone(),
|
||||
provenance: luxe_core::guided_review::GuideProvenance::Model { batches: 1 },
|
||||
brief: None,
|
||||
}));
|
||||
let model_written = buffer_to_string(&render_app(&mut app, &backend));
|
||||
assert!(!model_written.contains("structural guide"), "the model wrote these chapters");
|
||||
|
||||
app.update(Msg::Engine(luxe_core::event::Event::GuidedReviewGuideUpdated {
|
||||
request_id: luxe_core::guided_review::ReviewLoadRequestId::new(),
|
||||
review_id: review.id.clone(),
|
||||
revision_id: review.revision_id,
|
||||
chapters: review.chapters,
|
||||
provenance: luxe_core::guided_review::GuideProvenance::Structural { reason: None },
|
||||
brief: None,
|
||||
}));
|
||||
let structural = buffer_to_string(&render_app(&mut app, &backend));
|
||||
assert!(structural.contains("structural guide"), "fallback says so: {structural}");
|
||||
}
|
||||
|
||||
/// A Guide computed for a revision the reviewer has moved past must never replace what is on
|
||||
/// screen — the prose would describe a different diff.
|
||||
#[test]
|
||||
fn a_guide_for_another_revision_is_discarded() {
|
||||
let (width, height) = (160, 40);
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = seeded_app("nord", FixtureScenario::GuidedReviewReady).unwrap();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
let review = app.guided_review.clone().expect("fixture review");
|
||||
let original = review.chapters[0].title.clone();
|
||||
|
||||
let mut replacement = review.chapters.clone();
|
||||
replacement[0].title = "Chapters from a stale revision".into();
|
||||
app.update(Msg::Engine(luxe_core::event::Event::GuidedReviewGuideUpdated {
|
||||
request_id: luxe_core::guided_review::ReviewLoadRequestId::new(),
|
||||
review_id: review.id,
|
||||
revision_id: luxe_core::guided_review::ReviewRevisionId::from_canonical_bytes(b"other"),
|
||||
chapters: replacement,
|
||||
provenance: luxe_core::guided_review::GuideProvenance::Model { batches: 1 },
|
||||
brief: None,
|
||||
}));
|
||||
|
||||
let after = app.guided_review.as_ref().expect("review");
|
||||
assert_eq!(after.chapters[0].title, original);
|
||||
// The prose on screen is still the review's own, not the one written for a diff the
|
||||
// reader is no longer looking at.
|
||||
let rendered = buffer_to_string(&render_app(&mut app, &backend));
|
||||
assert!(rendered.contains(&original), "{rendered}");
|
||||
assert!(!rendered.contains("Chapters from a stale revision"), "{rendered}");
|
||||
}
|
||||
|
||||
/// The guide is the landing surface: intent, what the change does, and the contents — read before
|
||||
/// the diff, so attention goes to judgement rather than reconstruction.
|
||||
#[test]
|
||||
fn the_guide_leads_with_intent_and_the_contents() {
|
||||
let (width, height) = (160, 44);
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = seeded_app("nord", FixtureScenario::GuidedReviewBrief).unwrap();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
|
||||
let content = buffer_to_string(&render_app(&mut app, &backend));
|
||||
|
||||
// The summary is written for a reviewer, not replayed from the conversation they just left.
|
||||
assert!(
|
||||
content.contains("unrepresentable"),
|
||||
"the model's account of what the change does: {content}"
|
||||
);
|
||||
assert!(content.contains("Shared notification model"), "and the contents: {content}");
|
||||
// Headings are gone with the sections they labeled: the intent is the first thing in the pane,
|
||||
// so nothing has to announce it.
|
||||
for gone in ["Why this change", "What it does", "The walkthrough"] {
|
||||
assert!(!content.contains(gone), "{gone:?} is a heading over nothing now: {content}");
|
||||
}
|
||||
// The shell history is not a verdict: a grep that matched nothing is not a failed check.
|
||||
assert!(!content.contains("How it was verified"), "the synthesized list is gone: {content}");
|
||||
assert!(!content.contains("Checks failed"), "and so is the verdict it fed: {content}");
|
||||
// Coverage gaps go to the agent and to the file being read, never to a ranked list: a missing
|
||||
// test is work to hand off, not a call for the reviewer's judgement.
|
||||
assert!(
|
||||
!content.contains("has no covering test"),
|
||||
"coverage gaps are not ranked call-outs: {content}"
|
||||
);
|
||||
// One word for the unit of reading. The guide counts "Chapters", the footer moves by
|
||||
// "chapter", the diff ends "end of chapter".
|
||||
assert!(!content.contains("section"), "a chapter is never called a section: {content}");
|
||||
assert!(!content.contains("walked"), "progress is stated as reviewed: {content}");
|
||||
}
|
||||
|
||||
/// A review is captured from the project's worktree, so files changed anywhere else are absent
|
||||
/// from it and no amount of reading the diff will reveal them. The rail has to say so.
|
||||
#[test]
|
||||
fn the_review_says_when_the_session_worked_outside_the_project() {
|
||||
let (width, height) = (160, 44);
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = seeded_app("nord", FixtureScenario::GuidedReviewBrief).unwrap();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
|
||||
let mut workspace = empty_workspace("luxe");
|
||||
workspace.external = luxe_core::ExternalChangesSummary {
|
||||
roots: vec![luxe_core::ExternalRootSummary {
|
||||
root: "/home/dev/work/sdk".into(),
|
||||
display_path: "~/work/sdk".into(),
|
||||
git_branch: Some("main".into()),
|
||||
git: true,
|
||||
files: Vec::new(),
|
||||
total_files: 2,
|
||||
truncated: false,
|
||||
}],
|
||||
total_files: 2,
|
||||
additions: Some(9),
|
||||
deletions: Some(1),
|
||||
truncated: false,
|
||||
};
|
||||
app.workspace = Some(workspace);
|
||||
|
||||
let content = buffer_to_string(&render_app(&mut app, &backend));
|
||||
assert!(
|
||||
content.contains("2 files changed elsewhere"),
|
||||
"the review names the work it cannot cover: {content}"
|
||||
);
|
||||
|
||||
// And says nothing at all when there is nothing to say, which is what makes the line above
|
||||
// worth reading when it appears.
|
||||
app.workspace.as_mut().expect("seeded above").external =
|
||||
luxe_core::ExternalChangesSummary::default();
|
||||
let content = buffer_to_string(&render_app(&mut app, &backend));
|
||||
assert!(!content.contains("changed elsewhere"), "nothing outside, nothing claimed: {content}");
|
||||
}
|
||||
|
||||
/// Without a model-written brief the guide still says what it knows — and says whose words those
|
||||
/// are, so a raw transcript is never mistaken for a summary.
|
||||
#[test]
|
||||
fn a_guide_with_no_model_summary_falls_back_to_the_record_and_labels_it() {
|
||||
let (width, height) = (160, 44);
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = seeded_app("nord", FixtureScenario::GuidedReviewBrief).unwrap();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
let written = buffer_to_string(&render_app(&mut app, &backend));
|
||||
assert!(
|
||||
!written.contains("no summary was written"),
|
||||
"a real summary is not labeled as a stand-in: {written}"
|
||||
);
|
||||
|
||||
app.guided_review.as_mut().expect("a review").brief = None;
|
||||
let content = buffer_to_string(&render_app(&mut app, &backend));
|
||||
assert!(
|
||||
content.contains("no summary was written"),
|
||||
"labeled, so the record does not pass as a summary: {content}"
|
||||
);
|
||||
}
|
||||
|
||||
/// Side-by-side is a view of the unified row space, not a second one: it shows the whole file, keeps
|
||||
/// the columns on fixed screen positions, and pairs each removal with its replacement.
|
||||
#[test]
|
||||
fn side_by_side_shows_the_file_with_aligned_columns_and_word_emphasis() {
|
||||
let (width, height) = (180, 40);
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = seeded_app("nord", FixtureScenario::GuidedReviewWide).unwrap();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
let content = buffer_to_string(&buffer);
|
||||
|
||||
// The old renderer showed exactly one hunk; the fixture file has two.
|
||||
assert!(content.contains("@@ -4,3 +4,4 @@"), "first hunk: {content}");
|
||||
assert!(content.contains("@@ -18,1 +18,2 @@"), "second hunk in the same view: {content}");
|
||||
|
||||
// The removal and its replacement share a row: old text left, new text right.
|
||||
let row = (0..height)
|
||||
.find(|&y| {
|
||||
let text = row_text(&buffer, y, width);
|
||||
text.contains("pub category: String,") && text.contains("NotificationCategory")
|
||||
})
|
||||
.expect("the replaced line renders as one paired row");
|
||||
|
||||
// The column rule sits at the same screen column on every rendered row, which is what the old
|
||||
// renderer got wrong (an unpadded context cell moved it).
|
||||
let divider = (0..width)
|
||||
.find(|&x| buffer[(x, row)].symbol() == "│")
|
||||
.expect("a column rule on the paired row");
|
||||
let rows_with_content: Vec<u16> =
|
||||
(0..height).filter(|&y| row_text(&buffer, y, width).contains("pub ")).collect();
|
||||
assert!(rows_with_content.len() >= 3, "several source rows render");
|
||||
for y in rows_with_content {
|
||||
assert_eq!(
|
||||
buffer[(divider, y)].symbol(),
|
||||
"│",
|
||||
"the rule holds its column on row {y}: {content}"
|
||||
);
|
||||
}
|
||||
|
||||
// Word-level emphasis on both sides: pairing is exact here, so the changed span is too — bold in
|
||||
// both columns, and never struck through.
|
||||
let marked_with = |needle: &str, modifier: ratatui::style::Modifier| {
|
||||
let (y, column) = (0..height)
|
||||
.find_map(|y| {
|
||||
let text = row_text(&buffer, y, width);
|
||||
text.find(needle).map(|byte| (y, text[..byte].chars().count() as u16))
|
||||
})
|
||||
.unwrap_or_else(|| panic!("{needle} renders somewhere"));
|
||||
buffer[(column, y)].modifier.contains(modifier)
|
||||
};
|
||||
assert!(
|
||||
marked_with("String,", ratatui::style::Modifier::BOLD),
|
||||
"the removed type is bold: {content}"
|
||||
);
|
||||
assert!(
|
||||
!marked_with("String,", ratatui::style::Modifier::CROSSED_OUT),
|
||||
"and readable: {content}"
|
||||
);
|
||||
assert!(
|
||||
marked_with("NotificationCategory", ratatui::style::Modifier::BOLD),
|
||||
"the added type is bold: {content}"
|
||||
);
|
||||
}
|
||||
|
||||
/// Soft-wrap works in side-by-side too: a long line stays fully visible, the two columns stay
|
||||
/// vertically aligned, and one logical row keeps one click target across every visual line it spans.
|
||||
#[test]
|
||||
fn side_by_side_soft_wraps_long_lines_without_losing_column_alignment() {
|
||||
let (width, height) = (200, 40);
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = seeded_app("nord", FixtureScenario::GuidedReviewWide).unwrap();
|
||||
// A replaced line far longer than either column can show.
|
||||
{
|
||||
let file = &mut app.guided_review.as_mut().unwrap().files[0];
|
||||
let long_old = format!(" pub category: String, // {}", "old ".repeat(40));
|
||||
let long_new = format!(" pub category: NotificationCategory, // {}", "new ".repeat(40));
|
||||
for line in &mut file.hunks[0].lines {
|
||||
match line.kind {
|
||||
ReviewLineKind::Deletion => line.text = long_old.clone(),
|
||||
ReviewLineKind::Addition => line.text = long_new.clone(),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
app.update(Msg::DispatchUiAction(luxe_core::keymap::UiAction::ReviewToggleWordWrap));
|
||||
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
let content = buffer_to_string(&buffer);
|
||||
|
||||
// The tail of both sides is on screen rather than clipped off the right edge.
|
||||
assert!(content.contains("new new"), "the added line wrapped into view: {content}");
|
||||
assert!(content.contains("old old"), "the removed line wrapped into view: {content}");
|
||||
// Continuation rows are marked, as they are unified.
|
||||
assert!(content.contains('↳'), "wrapped rows carry a continuation glyph: {content}");
|
||||
|
||||
// The rule holds one screen column across every wrapped row. Scanned inside the content pane
|
||||
// only: the rail divider and the mode tabs draw their own vertical rules.
|
||||
let pane = luxe_tui::workspace_layout::LEFT_RAIL_WIDTH
|
||||
+ luxe_tui::workspace_layout::CONTEXT_DOCK_SEPARATOR_WIDTH;
|
||||
let columns: std::collections::HashSet<u16> = (0..height)
|
||||
.filter_map(|y| (pane..width).find(|&x| buffer[(x, y)].symbol() == "│"))
|
||||
.collect();
|
||||
assert_eq!(columns.len(), 1, "the rule never wanders: {columns:?}");
|
||||
}
|
||||
430
crates/luxe-tui/tests/render/review_guide.rs
Normal file
430
crates/luxe-tui/tests/render/review_guide.rs
Normal file
@@ -0,0 +1,430 @@
|
||||
//! Review guide — the guide pane's rows, the noise fixtures and the review source picker.
|
||||
|
||||
use super::*;
|
||||
|
||||
/// Guide file-row clicks (plan B6): after a render publishes each file row's wrapped-Y region,
|
||||
/// clicking a guide file row selects that file.
|
||||
#[test]
|
||||
fn clicking_a_guide_file_row_selects_that_file() {
|
||||
use crossterm::event::{MouseButton, MouseEvent, MouseEventKind};
|
||||
let (width, height) = (140, 40);
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = seeded_app("nord", FixtureScenario::GuidedReviewReady).unwrap();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
let expected = app.guided_review.as_ref().unwrap().files[0].id.clone();
|
||||
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
// Search only the left rail (its file row) — the content pane's sticky breadcrumb also names
|
||||
// the file, so scanning the full row width would match that instead.
|
||||
let row = (0..height)
|
||||
.find(|&y| row_text(&buffer, y, 40).contains("src/notification.rs"))
|
||||
.expect("the guide file row renders");
|
||||
let click = MouseEvent {
|
||||
kind: MouseEventKind::Down(MouseButton::Left),
|
||||
column: 10, // inside the guide rail
|
||||
row,
|
||||
modifiers: KeyModifiers::NONE,
|
||||
};
|
||||
match route_mouse(&mut app, &click) {
|
||||
RouteAction::Msg(message) => assert!(
|
||||
matches!(*message, Msg::GuidedReviewSelectFile(ref id) if id == &expected),
|
||||
"clicking the file row selects that file"
|
||||
),
|
||||
other => panic!("expected a select-file message from the click, got {other:?}"),
|
||||
}
|
||||
}
|
||||
|
||||
/// Clicking a chapter row in the guide points the review at that chapter.
|
||||
#[test]
|
||||
fn clicking_a_guide_chapter_row_opens_it() {
|
||||
use crossterm::event::{MouseButton, MouseEvent, MouseEventKind};
|
||||
let (width, height) = (160, 44);
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = seeded_app("nord", FixtureScenario::GuidedReviewDemo).unwrap();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
render_app(&mut app, &backend);
|
||||
|
||||
let (rect, chapter_id) = app
|
||||
.hit
|
||||
.borrow()
|
||||
.clicks()
|
||||
.find_map(|(rect, target)| match target {
|
||||
luxe_tui::mouse::MouseTarget::ReviewGuideChapter(id) => Some((rect, id.clone())),
|
||||
_ => None,
|
||||
})
|
||||
.expect("the guide publishes its chapter rows");
|
||||
let click = MouseEvent {
|
||||
kind: MouseEventKind::Down(MouseButton::Left),
|
||||
column: rect.x + 1,
|
||||
row: rect.y,
|
||||
modifiers: KeyModifiers::NONE,
|
||||
};
|
||||
match route_mouse(&mut app, &click) {
|
||||
RouteAction::Msg(message) => match *message {
|
||||
Msg::GuidedReviewOpenChapter(id) => assert_eq!(id, chapter_id),
|
||||
other => panic!("expected the chapter under the pointer, got {other:?}"),
|
||||
},
|
||||
other => panic!("expected a chapter to open, got {other:?}"),
|
||||
}
|
||||
}
|
||||
|
||||
/// Clicking a guide file row opens exactly that file.
|
||||
#[test]
|
||||
fn clicking_a_guide_file_row_reads_what_it_points_at() {
|
||||
use crossterm::event::{MouseButton, MouseEvent, MouseEventKind};
|
||||
let (width, height) = (140, 40);
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = seeded_app("nord", FixtureScenario::GuidedReviewReady).unwrap();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
let guide = luxe_tui::workspace_layout::guide_pane_width(width);
|
||||
let row = (0..height)
|
||||
.find(|&y| {
|
||||
let text: String =
|
||||
(0..guide).map(|x| buffer[(x, y)].symbol()).collect::<Vec<_>>().join("");
|
||||
text.contains("M src/notification.rs")
|
||||
})
|
||||
.expect("the file row renders under its chapter");
|
||||
let click = MouseEvent {
|
||||
kind: MouseEventKind::Down(MouseButton::Left),
|
||||
column: 10,
|
||||
row,
|
||||
modifiers: KeyModifiers::NONE,
|
||||
};
|
||||
match route_mouse(&mut app, &click) {
|
||||
RouteAction::Msg(message) => {
|
||||
assert!(matches!(*message, Msg::GuidedReviewSelectFile(_)));
|
||||
app.update(*message);
|
||||
}
|
||||
other => panic!("expected the file row to open, got {other:?}"),
|
||||
}
|
||||
// The detail pane follows the guide's selection with no second step.
|
||||
let after = buffer_to_string(&render_app(&mut app, &backend));
|
||||
assert!(after.contains("src/notification.rs"), "the file is on screen: {after}");
|
||||
assert!(after.contains("@@"), "and its diff beside the guide: {after}");
|
||||
}
|
||||
|
||||
/// The guide is the contents page: every chapter, and the files under it, with the evidence that
|
||||
/// accounts for them. Hunk rows appear under the file being read and nowhere else.
|
||||
#[test]
|
||||
fn the_guide_lists_every_chapter_and_file_with_its_evidence() {
|
||||
let (width, height) = (140, 30);
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = seeded_app("nord", FixtureScenario::GuidedReviewNoise).unwrap();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
|
||||
let guide = luxe_tui::workspace_layout::guide_pane_width(width);
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
let content: String =
|
||||
(0..height).map(|y| row_text(&buffer, y, guide)).collect::<Vec<_>>().join("\n");
|
||||
|
||||
assert!(content.contains("01 / 01"), "the chapter, numbered: {content}");
|
||||
assert!(content.contains("Shared notification model"), "and titled: {content}");
|
||||
assert!(content.contains("M src/notification.rs"), "its file, with status: {content}");
|
||||
assert!(content.contains("+3 \u{2212}2"), "with real counts, not a \u{b1}: {content}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn guided_review_help_overlay_is_local_and_names_review_controls() {
|
||||
let (width, height) = (100, 24);
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = seeded_app("nord", FixtureScenario::GuidedReviewReady).unwrap();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
app.update(Msg::GuidedReviewToggleHelp);
|
||||
|
||||
let content = buffer_to_string(&render_app(&mut app, &backend));
|
||||
assert!(content.contains("Help · Guided Review"), "missing help title: {content}");
|
||||
// Grouped, complete help (plan A4): every verb group is present, including the feedback and
|
||||
// finish keys the old help omitted.
|
||||
for expected in [
|
||||
"Move",
|
||||
"Read",
|
||||
"Feedback",
|
||||
"Session",
|
||||
"next stop; past the last, finish",
|
||||
"open collapsed churn",
|
||||
"ask; the agent answers",
|
||||
"comment, for the agent to act on",
|
||||
"all comments: send, reply, verify",
|
||||
"resolve or verify",
|
||||
"show or hide the guide",
|
||||
"ctrl+r",
|
||||
"alt+enter",
|
||||
"back to chat",
|
||||
"? close",
|
||||
] {
|
||||
assert!(content.contains(expected), "help missing {expected:?}: {content}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn guided_review_noise_fixture_collapses_and_expands_formatting_hunks() {
|
||||
let (width, height) = (140, 24);
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = seeded_app("nord", FixtureScenario::GuidedReviewNoise).unwrap();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
|
||||
let collapsed = buffer_to_string(&render_app(&mut app, &backend));
|
||||
// The folded run says what it is on its own row in the diff, so the guide does not repeat it
|
||||
assert!(
|
||||
collapsed.contains("1 change · 2 lines ·") && collapsed.contains("enter opens"),
|
||||
"missing the fold row: {collapsed}"
|
||||
);
|
||||
assert!(!collapsed.contains("mechanical change collapsed"), "a banner too: {collapsed}");
|
||||
assert!(!collapsed.contains("f opens them"), "and its hint: {collapsed}");
|
||||
assert!(!collapsed.contains("@@ -1,1 +1,1 @@ imports"), "folded hunk rendered: {collapsed}");
|
||||
|
||||
app.update(Msg::GuidedReviewToggleNoiseDetails);
|
||||
let details = buffer_to_string(&render_app(&mut app, &backend));
|
||||
// The explanation names *why this hunk* was folded, not a generic blurb about the classifier.
|
||||
assert!(
|
||||
details.contains("1 whitespace-only, tokens identical"),
|
||||
"missing per-class fold reason: {details}"
|
||||
);
|
||||
assert!(
|
||||
details.contains("Semantic and comment-only changes stay"),
|
||||
"missing the visibility promise: {details}"
|
||||
);
|
||||
assert!(details.contains("1 mechanical change collapsed · 2 lines"), "{details}");
|
||||
|
||||
app.update(Msg::GuidedReviewToggleNoise);
|
||||
let expanded = buffer_to_string(&render_app(&mut app, &backend));
|
||||
assert!(expanded.contains("@@ -1,1 +1,1 @@ imports"), "expanded hunk missing: {expanded}");
|
||||
assert!(!expanded.contains("collapsed · 2 lines"), "stale fold summary: {expanded}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn guided_review_noise_summary_survives_medium_and_narrow_layouts() {
|
||||
for (width, expected) in
|
||||
[(100, "1 mechanical change collapsed · 2 lines · f opens them"), (80, "1 collapsed")]
|
||||
{
|
||||
let height = 24;
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = seeded_app("nord", FixtureScenario::GuidedReviewNoise).unwrap();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
|
||||
let content = buffer_to_string(&render_app(&mut app, &backend));
|
||||
assert!(content.contains(expected), "missing {expected:?}: {content}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn guided_review_medium_context_explains_noise_classification() {
|
||||
let (width, height) = (100, 24);
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = seeded_app("nord", FixtureScenario::GuidedReviewNoise).unwrap();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
|
||||
let collapsed = buffer_to_string(&render_app(&mut app, &backend));
|
||||
assert!(
|
||||
collapsed.contains("1 mechanical change collapsed · 2 lines · f opens them"),
|
||||
"missing folded summary: {collapsed}"
|
||||
);
|
||||
|
||||
app.update(Msg::GuidedReviewToggleNoiseDetails);
|
||||
let expanded = buffer_to_string(&render_app(&mut app, &backend));
|
||||
assert!(
|
||||
expanded.contains("1/2 folded: format/generated/lockfile/mechanical;")
|
||||
&& expanded.contains("semantic/comments kept · d close"),
|
||||
"missing medium classification detail: {expanded}"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn guided_review_narrow_context_discloses_noise_classification() {
|
||||
let (width, height) = (80, 24);
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = seeded_app("nord", FixtureScenario::GuidedReviewNoise).unwrap();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
|
||||
app.update(Msg::GuidedReviewToggleNoiseDetails);
|
||||
let content = buffer_to_string(&render_app(&mut app, &backend));
|
||||
assert!(
|
||||
content.contains("1 fmt/gen/lock/mech"),
|
||||
"missing narrow classification disclosure: {content}"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn guided_review_narrow_fixture_keeps_chapter_and_file_orientation() {
|
||||
let (width, height) = (80, 24);
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = seeded_app("nord", FixtureScenario::GuidedReviewReady).unwrap();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
|
||||
let content = buffer_to_string(&render_app(&mut app, &backend));
|
||||
assert!(
|
||||
content.contains("01/01 · Shared notification model · src/notification.rs"),
|
||||
"missing narrow chapter/file header: {content}"
|
||||
);
|
||||
assert!(
|
||||
content.contains("@@ -4,3 +4,4 @@ pub struct Notification"),
|
||||
"missing narrow diff: {content}"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn guided_review_tiny_fixture_explains_the_minimum_size() {
|
||||
let (width, height) = (30, 5);
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = seeded_app("nord", FixtureScenario::GuidedReviewReady).unwrap();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
|
||||
let content = buffer_to_string(&render_app(&mut app, &backend));
|
||||
assert!(
|
||||
content.contains("Review needs 40 × 5 cells"),
|
||||
"missing minimum-size message: {content}"
|
||||
);
|
||||
assert!(content.contains("esc back to chat"), "missing return guidance: {content}");
|
||||
assert!(!content.contains("@@ -4,3"), "tiny terminal rendered a partial diff: {content}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn guided_review_source_picker_enter_dispatches_the_selected_source() {
|
||||
let (tx, _rx) = tokio::sync::mpsc::channel::<luxe_core::engine::Action>(64);
|
||||
let mut app = App::new(tx, KeyMap::defaults(), Config::default());
|
||||
app.current_view = ViewMode::GuidedReview;
|
||||
app.update(Msg::GuidedReviewToggleSourcePicker);
|
||||
|
||||
assert!(matches!(
|
||||
claim(&mut app, &key(KeyCode::Enter)),
|
||||
Some(Msg::GuidedReviewSelectSourcePicker)
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn guided_review_source_reference_routes_plain_text_before_review_keys() {
|
||||
let (tx, _rx) = tokio::sync::mpsc::channel::<luxe_core::engine::Action>(64);
|
||||
let mut app = App::new(tx, KeyMap::defaults(), Config::default());
|
||||
app.current_view = ViewMode::GuidedReview;
|
||||
app.update(Msg::GuidedReviewToggleSourcePicker);
|
||||
app.update(Msg::GuidedReviewSourcePickerNext);
|
||||
app.update(Msg::GuidedReviewSelectSourcePicker);
|
||||
|
||||
assert!(matches!(
|
||||
claim(&mut app, &key(KeyCode::Char('f'))),
|
||||
Some(Msg::GuidedReviewSourceReferenceInsert('f'))
|
||||
));
|
||||
assert!(matches!(
|
||||
claim(&mut app, &key(KeyCode::Backspace)),
|
||||
Some(Msg::GuidedReviewSourceReferenceBackspace)
|
||||
));
|
||||
assert!(matches!(
|
||||
claim(&mut app, &key(KeyCode::Esc)),
|
||||
Some(Msg::GuidedReviewCancelSourceReference)
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn guided_review_source_picker_names_targets_and_unavailable_last_turn() {
|
||||
let (width, height) = (100, 24);
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = seeded_app("nord", FixtureScenario::GuidedReviewReady).unwrap();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
app.update(Msg::GuidedReviewToggleSourcePicker);
|
||||
|
||||
let content = buffer_to_string(&render_app(&mut app, &backend));
|
||||
assert!(content.contains("Change review source"), "missing source picker: {content}");
|
||||
assert!(content.contains("› Working Tree"), "missing selected working tree: {content}");
|
||||
assert!(content.contains("Last Turn"), "missing last-turn source: {content}");
|
||||
assert!(
|
||||
content.contains("unavailable — no completed turn"),
|
||||
"missing disabled reason: {content}"
|
||||
);
|
||||
assert!(content.contains("Base"), "missing base source: {content}");
|
||||
assert!(content.contains("Commit"), "missing commit source: {content}");
|
||||
assert!(
|
||||
content.contains("enter load · ↑/↓ choose · esc close"),
|
||||
"missing source controls: {content}"
|
||||
);
|
||||
|
||||
app.update(Msg::GuidedReviewSourcePickerNext);
|
||||
app.update(Msg::GuidedReviewSelectSourcePicker);
|
||||
let base_content = buffer_to_string(&render_app(&mut app, &backend));
|
||||
assert!(
|
||||
base_content.contains("Base reference: _"),
|
||||
"missing Base reference entry: {base_content}"
|
||||
);
|
||||
|
||||
app.update(Msg::GuidedReviewSourceReferenceInsert('m'));
|
||||
app.update(Msg::GuidedReviewSourceReferenceInsert('a'));
|
||||
app.update(Msg::GuidedReviewSourceReferenceInsert('i'));
|
||||
app.update(Msg::GuidedReviewSourceReferenceBackspace);
|
||||
let typed_content = buffer_to_string(&render_app(&mut app, &backend));
|
||||
assert!(
|
||||
typed_content.contains("Base reference: ma"),
|
||||
"missing typed Base reference: {typed_content}"
|
||||
);
|
||||
|
||||
app.update(Msg::GuidedReviewCancelSourceReference);
|
||||
app.update(Msg::GuidedReviewSourcePickerNext);
|
||||
app.update(Msg::GuidedReviewSelectSourcePicker);
|
||||
let commit_content = buffer_to_string(&render_app(&mut app, &backend));
|
||||
assert!(
|
||||
commit_content.contains("Commit object ID: _"),
|
||||
"missing Commit object ID entry: {commit_content}"
|
||||
);
|
||||
assert!(
|
||||
commit_content.contains("enter load commit · esc back"),
|
||||
"missing Commit entry controls: {commit_content}"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn guided_review_wide_fixture_renders_chapter_context_beside_the_diff() {
|
||||
let (width, height) = (140, 24);
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = seeded_app("nord", FixtureScenario::GuidedReviewReady).unwrap();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
|
||||
let content = buffer_to_string(&render_app(&mut app, &backend));
|
||||
assert!(content.contains("01 / 01"), "missing chapter progress: {content}");
|
||||
assert!(content.contains("Shared notification model"), "missing chapter title: {content}");
|
||||
assert!(content.contains("M src/notification.rs"), "missing the file row: {content}");
|
||||
assert!(
|
||||
content.contains("pub struct Notification hunk 1 of 2"),
|
||||
"the detail pane names what it is showing: {content}"
|
||||
);
|
||||
assert!(content.contains("@@ -4,3 +4,4 @@"), "missing adjacent diff: {content}");
|
||||
// Both halves at once: the story and the code it describes, with no mode between them.
|
||||
assert!(content.contains("Shared notification model") && content.contains("@@"));
|
||||
|
||||
app.update(Msg::GuidedReviewHunkNext);
|
||||
let next_hunk_content = buffer_to_string(&render_app(&mut app, &backend));
|
||||
assert!(
|
||||
next_hunk_content.contains("› @@ -18,1 +18,2 @@ impl Notification"),
|
||||
"next hunk did not become visibly selected: {next_hunk_content}"
|
||||
);
|
||||
assert!(
|
||||
!next_hunk_content.contains("› @@ -4,3 +4,4 @@ pub struct Notification"),
|
||||
"previous hunk retained selected marker: {next_hunk_content}"
|
||||
);
|
||||
|
||||
app.update(Msg::GuidedReviewHunkPrevious);
|
||||
let previous_hunk_content = buffer_to_string(&render_app(&mut app, &backend));
|
||||
assert!(
|
||||
previous_hunk_content.contains("› @@ -4,3 +4,4 @@ pub struct Notification"),
|
||||
"previous hunk did not restore the original marker: {previous_hunk_content}"
|
||||
);
|
||||
assert!(
|
||||
!previous_hunk_content.contains("› @@ -18,1 +18,2 @@ impl Notification"),
|
||||
"next hunk retained selected marker after moving back: {previous_hunk_content}"
|
||||
);
|
||||
|
||||
// Progress is the step you are on — never a per-hunk tally, and never a second counter beside
|
||||
// it counting something else.
|
||||
let workload_content = buffer_to_string(&render_app(&mut app, &backend));
|
||||
assert!(workload_content.contains("Step "), "the rail says where you are: {workload_content}");
|
||||
assert!(!workload_content.contains("to review"), "and only once: {workload_content}");
|
||||
assert!(!workload_content.contains("Reviewed "), "no completion counter: {workload_content}");
|
||||
assert!(workload_content.contains("space next"), "stepping is offered: {workload_content}");
|
||||
|
||||
// Walking to the end of a chapter records it as read — against the chapter itself, in the
|
||||
// guide, rather than as a second tally in the foot.
|
||||
app.update(Msg::GuidedReviewHunkNext);
|
||||
app.update(Msg::GuidedReviewHunkNext);
|
||||
let walked_content = buffer_to_string(&render_app(&mut app, &backend));
|
||||
assert!(walked_content.contains("reviewed"), "the chapter is marked: {walked_content}");
|
||||
assert!(!walked_content.contains("Chapters 1/1"), "and not counted twice: {walked_content}");
|
||||
}
|
||||
378
crates/luxe-tui/tests/render/routing.rs
Normal file
378
crates/luxe-tui/tests/render/routing.rs
Normal file
@@ -0,0 +1,378 @@
|
||||
//! Routing — keys and clicks reach the surface they belong to: dashboards, pickers and the review.
|
||||
|
||||
use super::*;
|
||||
|
||||
pub(super) fn key(code: KeyCode) -> KeyEvent {
|
||||
KeyEvent::new(code, KeyModifiers::NONE)
|
||||
}
|
||||
|
||||
/// Session-picker clicks (plan B4): clicking a session row resolves straight to SessionSelected
|
||||
/// for the clicked row (not the default first row).
|
||||
#[test]
|
||||
fn clicking_a_session_picker_row_selects_that_session() {
|
||||
use crossterm::event::{MouseButton, MouseEvent, MouseEventKind};
|
||||
let (width, height) = (120, 40);
|
||||
let backend = test_backend(width, height);
|
||||
let (tx, _rx) = tokio::sync::mpsc::channel::<luxe_core::engine::Action>(64);
|
||||
let mut app = App::new(tx, KeyMap::defaults(), Config::default());
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
app.overlays.session_picker = Some(SessionPickerState::new(vec![
|
||||
SessionEntry {
|
||||
id: "session-1".to_string(),
|
||||
name: "First session".to_string(),
|
||||
age: "just now".to_string(),
|
||||
search_text: "first".to_string(),
|
||||
preview: Vec::new(),
|
||||
},
|
||||
SessionEntry {
|
||||
id: "session-2".to_string(),
|
||||
name: "Second session".to_string(),
|
||||
age: "1h ago".to_string(),
|
||||
search_text: "second".to_string(),
|
||||
preview: Vec::new(),
|
||||
},
|
||||
]));
|
||||
app.current_view = ViewMode::SessionPicker;
|
||||
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
let row = (0..height)
|
||||
.find(|&y| row_text(&buffer, y, width).contains("Second session"))
|
||||
.expect("the second session row renders");
|
||||
let click = MouseEvent {
|
||||
kind: MouseEventKind::Down(MouseButton::Left),
|
||||
column: width / 2,
|
||||
row,
|
||||
modifiers: KeyModifiers::NONE,
|
||||
};
|
||||
match route_mouse(&mut app, &click) {
|
||||
RouteAction::SessionSelected(id) => assert_eq!(id, "session-2", "click selects that row"),
|
||||
other => panic!("expected SessionSelected from the click, got {other:?}"),
|
||||
}
|
||||
}
|
||||
|
||||
/// Picker selection returns the session id, and the main-loop consumer emits LoadSession.
|
||||
#[test]
|
||||
fn test_session_picker_selection_emits_load_session() {
|
||||
let (tx, mut rx) = tokio::sync::mpsc::channel::<luxe_core::engine::Action>(64);
|
||||
let mut app = App::new(tx, KeyMap::defaults(), Config::default());
|
||||
let entries = vec![
|
||||
SessionEntry {
|
||||
id: "session-1".to_string(),
|
||||
name: "First session".to_string(),
|
||||
age: "just now".to_string(),
|
||||
search_text: "First session prompt".to_string(),
|
||||
preview: Vec::new(),
|
||||
},
|
||||
SessionEntry {
|
||||
id: "session-2".to_string(),
|
||||
name: "Second session".to_string(),
|
||||
age: "1h ago".to_string(),
|
||||
search_text: "Second session prompt".to_string(),
|
||||
preview: Vec::new(),
|
||||
},
|
||||
];
|
||||
app.overlays.session_picker = Some(SessionPickerState::new(entries));
|
||||
app.current_view = ViewMode::SessionPicker;
|
||||
|
||||
match route_key(&mut app, &key(KeyCode::Enter)) {
|
||||
RouteAction::SessionSelected(id) => {
|
||||
assert_eq!(id, "session-1");
|
||||
// Mirror the consumer's side effect.
|
||||
app.engine_tx.try_send(luxe_core::engine::Action::LoadSession(id)).unwrap();
|
||||
}
|
||||
other => panic!("expected SessionSelected, got {other:?}"),
|
||||
}
|
||||
match rx.try_recv() {
|
||||
Ok(luxe_core::engine::Action::LoadSession(id)) => assert_eq!(id, "session-1"),
|
||||
other => panic!("expected LoadSession action, got {other:?}"),
|
||||
}
|
||||
}
|
||||
|
||||
/// Chat (default) view passes keys straight through as Msg::Key.
|
||||
#[test]
|
||||
fn test_route_key_chat_passes_through() {
|
||||
let (tx, _rx) = tokio::sync::mpsc::channel::<luxe_core::engine::Action>(64);
|
||||
let mut app = App::new(tx, KeyMap::defaults(), Config::default());
|
||||
app.current_view = ViewMode::Chat;
|
||||
let action = route_key(&mut app, &key(KeyCode::Char('a')));
|
||||
assert!(
|
||||
matches!(action, RouteAction::Msg(ref message) if matches!(**message, Msg::Key(_))),
|
||||
"got {action:?}"
|
||||
);
|
||||
}
|
||||
|
||||
/// The start screen takes text, so Esc never quits it — that is how a half-typed prompt gets lost
|
||||
/// by reflex. Ctrl+C does, as it does everywhere.
|
||||
#[test]
|
||||
fn test_route_key_dashboard_esc_stays_and_ctrl_c_quits() {
|
||||
let (tx, _rx) = tokio::sync::mpsc::channel::<luxe_core::engine::Action>(64);
|
||||
let mut app = App::new(tx, KeyMap::defaults(), Config::default());
|
||||
let dash = DashboardState::new(vec![SessionSummary {
|
||||
id: "s1".to_string(),
|
||||
name: "Session one".to_string(),
|
||||
age: "now".to_string(),
|
||||
search_text: "Session one prompt".to_string(),
|
||||
preview: Vec::new(),
|
||||
worktree: None,
|
||||
}]);
|
||||
app.enter_dashboard(dash);
|
||||
let action = route_key(&mut app, &key(KeyCode::Esc));
|
||||
assert!(
|
||||
matches!(action, RouteAction::Dashboard(luxe_tui::dashboard::DashOutcome::None)),
|
||||
"got {action:?}"
|
||||
);
|
||||
let quit = KeyEvent::new(KeyCode::Char('c'), KeyModifiers::CONTROL);
|
||||
let action = route_key(&mut app, &quit);
|
||||
assert!(
|
||||
matches!(action, RouteAction::Dashboard(luxe_tui::dashboard::DashOutcome::Quit)),
|
||||
"got {action:?}"
|
||||
);
|
||||
}
|
||||
|
||||
/// The project-context list owns the keys and the pointer while it is up.
|
||||
///
|
||||
/// Opening it does not change the view mode — the dashboard stays behind it on purpose — and the
|
||||
/// routing asked for the view mode. So the arrows walked the column *underneath* the overlay, a
|
||||
/// click reached the menu through it, and Esc quit Luxe instead of closing the list.
|
||||
#[test]
|
||||
fn the_project_context_list_takes_the_keys_from_the_dashboard_behind_it() {
|
||||
let mut app = seeded_app("nord", FixtureScenario::DashboardContextFiles).expect("the fixture");
|
||||
app.update(Msg::TerminalResized { width: 160, height: 40 });
|
||||
let backend = test_backend(160, 40);
|
||||
render_app(&mut app, &backend);
|
||||
|
||||
let selected = |a: &App| a.overlays.context_files.as_ref().expect("list open").selected();
|
||||
assert_eq!(selected(&app), 0);
|
||||
|
||||
for code in [KeyCode::Down, KeyCode::Char('j'), KeyCode::Tab] {
|
||||
let action = route_key(&mut app, &key(code));
|
||||
match action {
|
||||
RouteAction::Msg(message) => app.update(*message),
|
||||
other => panic!("{code:?} escaped the list: {other:?}"),
|
||||
}
|
||||
}
|
||||
assert_eq!(selected(&app), 2, "j and ↓ walk the list; Tab is not its key");
|
||||
assert!(app.editor.current_input().is_empty(), "and the prompt underneath typed nothing");
|
||||
|
||||
// Esc puts the list away rather than quitting Luxe.
|
||||
let action = route_key(&mut app, &key(KeyCode::Esc));
|
||||
match action {
|
||||
RouteAction::Msg(message) => app.update(*message),
|
||||
other => panic!("Esc left the list: {other:?}"),
|
||||
}
|
||||
assert!(app.overlays.context_files.is_none());
|
||||
assert!(!app.should_quit);
|
||||
assert_eq!(app.current_view, ViewMode::Dashboard);
|
||||
|
||||
// And a click lands on the row it is over, opening it the way Enter does.
|
||||
let mut app = seeded_app("nord", FixtureScenario::DashboardContextFiles).expect("the fixture");
|
||||
app.update(Msg::TerminalResized { width: 160, height: 40 });
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
let row = (0..buffer.area.height)
|
||||
.find(|&y| {
|
||||
(0..buffer.area.width)
|
||||
.map(|x| buffer[(x, y)].symbol())
|
||||
.collect::<String>()
|
||||
.contains("release-notes")
|
||||
})
|
||||
.expect("the fixture lists a skill");
|
||||
click_cell(&mut app, buffer.area.width / 2, row, std::time::Instant::now());
|
||||
assert_eq!(
|
||||
app.outbox.editor_file.take(),
|
||||
Some(std::path::PathBuf::from("/repo/.luxe/skills/release-notes/SKILL.md")),
|
||||
"a click opens the row it landed on"
|
||||
);
|
||||
}
|
||||
|
||||
/// With nothing configured, setup leads the list and Enter opens the surface that answers it — and
|
||||
/// the dashboard is not drawn underneath.
|
||||
#[test]
|
||||
fn test_route_key_dashboard_configuration_opens_the_setup_surface() {
|
||||
let mut app = create_app();
|
||||
let mut dashboard = DashboardState::new(Vec::new());
|
||||
dashboard.set_provider_configured(false);
|
||||
app.enter_dashboard(dashboard);
|
||||
|
||||
let action = route_key(&mut app, &key(KeyCode::Enter));
|
||||
assert!(
|
||||
matches!(action, RouteAction::Dashboard(luxe_tui::dashboard::DashOutcome::OpenConfig)),
|
||||
"got {action:?}"
|
||||
);
|
||||
let RouteAction::Dashboard(outcome) = action else { unreachable!() };
|
||||
app.handle_dashboard_outcome(outcome);
|
||||
assert_eq!(app.current_view, ViewMode::Configuration);
|
||||
assert!(app.overlays.configuration.is_some());
|
||||
|
||||
let backend = test_backend(120, 40);
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
let screen: String = buffer.content.iter().map(|cell| cell.symbol()).collect();
|
||||
assert!(screen.contains("Configuration"), "{screen}");
|
||||
assert!(!screen.contains("New session"), "the dashboard is gone, not behind it: {screen}");
|
||||
}
|
||||
|
||||
/// The whole point of the surface: a login opens *in* it, so nothing is ever half-covered.
|
||||
#[test]
|
||||
fn a_login_started_from_configuration_draws_inside_the_surface() {
|
||||
let mut app = seeded_app("nord", FixtureScenario::Configuration).expect("the fixture");
|
||||
app.update(Msg::TerminalResized { width: 120, height: 40 });
|
||||
let backend = test_backend(120, 40);
|
||||
let text =
|
||||
|buffer: &Buffer| -> String { buffer.content.iter().map(|cell| cell.symbol()).collect() };
|
||||
|
||||
// Row one: sign in to a subscription.
|
||||
match route_key(&mut app, &key(KeyCode::Enter)) {
|
||||
RouteAction::Configuration(outcome) => app.apply_configuration_outcome(outcome),
|
||||
other => panic!("expected a configuration outcome, got {other:?}"),
|
||||
}
|
||||
assert!(app.overlays.auth_wizard.is_some());
|
||||
|
||||
let screen = text(&render_app(&mut app, &backend));
|
||||
assert!(screen.contains("Sign in to a subscription"), "{screen}");
|
||||
assert!(
|
||||
!screen.contains("Edit configuration files"),
|
||||
"the menu gave up its region rather than sitting behind the panel: {screen}"
|
||||
);
|
||||
|
||||
// Escape returns to the menu it was chosen from, not out of the surface.
|
||||
app.update(Msg::Key(key(KeyCode::Esc)));
|
||||
assert!(app.overlays.auth_wizard.is_none());
|
||||
assert_eq!(app.current_view, ViewMode::Configuration);
|
||||
assert!(text(&render_app(&mut app, &backend)).contains("Edit configuration files"));
|
||||
}
|
||||
|
||||
/// Choosing a model is the last step of setting a provider up, so a login that landed walks into
|
||||
/// it by itself, in the same region — and it has to be *drawn*: an overlay that owns the keyboard
|
||||
/// while invisible is the worst of both.
|
||||
#[test]
|
||||
fn a_finished_login_walks_into_the_model_picker_inside_the_surface() {
|
||||
use luxe_tui::fixture::{seed_login_wizard, LoginFixture};
|
||||
|
||||
let mut app = seeded_app("nord", FixtureScenario::Configuration).expect("the fixture");
|
||||
app.update(Msg::TerminalResized { width: 120, height: 40 });
|
||||
seed_login_wizard(&mut app, LoginFixture::Done);
|
||||
|
||||
assert!(app.overlays.auth_wizard.is_none(), "success is not a screen to dismiss");
|
||||
assert!(app.overlays.model_picker.is_some(), "a finished login opens the model picker itself");
|
||||
|
||||
let backend = test_backend(120, 40);
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
let screen: String = buffer.content.iter().map(|cell| cell.symbol()).collect();
|
||||
assert!(screen.contains("Select model"), "{screen}");
|
||||
assert!(screen.contains("GPT-5.6"), "{screen}");
|
||||
// What the login had to say rides along as the picker's opening line rather than being lost
|
||||
// with the screen that used to report it — including which model it left the session on, so
|
||||
// the preselected row does not read as a choice nobody made.
|
||||
assert!(screen.contains("Signed in to OpenAI"), "{screen}");
|
||||
assert!(screen.contains("Now on GPT-5.6"), "{screen}");
|
||||
// The count of models is not on it: they are the rows underneath.
|
||||
assert!(!screen.contains("47 models available"), "{screen}");
|
||||
}
|
||||
|
||||
/// Esc in the SessionPicker closes it (even without a live picker).
|
||||
#[test]
|
||||
fn test_route_key_session_picker_esc_closes() {
|
||||
let (tx, _rx) = tokio::sync::mpsc::channel::<luxe_core::engine::Action>(64);
|
||||
let mut app = App::new(tx, KeyMap::defaults(), Config::default());
|
||||
app.current_view = ViewMode::SessionPicker;
|
||||
let action = route_key(&mut app, &key(KeyCode::Esc));
|
||||
assert!(matches!(action, RouteAction::PickerClosed), "got {action:?}");
|
||||
}
|
||||
|
||||
/// Guided Review: row and page keys move the diff window rather than the composer.
|
||||
///
|
||||
/// One meaning per key, in every state the surface can be in. These used to be conditional on
|
||||
/// which pane held focus, which is how `↑`/`↓` came to do nothing at all on the landing surface.
|
||||
#[test]
|
||||
fn test_route_key_guided_review_navigation_moves_diff_rows() {
|
||||
let mut app = seeded_app("nord", FixtureScenario::GuidedReviewReady).unwrap();
|
||||
app.update(Msg::TerminalResized { width: 160, height: 44 });
|
||||
assert!(matches!(claim(&mut app, &key(KeyCode::Down)), Some(Msg::GuidedReviewLineNext)));
|
||||
assert!(matches!(claim(&mut app, &key(KeyCode::Up)), Some(Msg::GuidedReviewLinePrevious)));
|
||||
assert!(matches!(
|
||||
claim(&mut app, &KeyEvent::new(KeyCode::Down, KeyModifiers::CONTROL)),
|
||||
Some(Msg::GuidedReviewFileNext)
|
||||
));
|
||||
assert!(matches!(
|
||||
claim(&mut app, &KeyEvent::new(KeyCode::Up, KeyModifiers::CONTROL)),
|
||||
Some(Msg::GuidedReviewFilePrevious)
|
||||
));
|
||||
assert!(matches!(claim(&mut app, &key(KeyCode::PageDown)), Some(Msg::GuidedReviewPageNext)));
|
||||
assert!(matches!(claim(&mut app, &key(KeyCode::PageUp)), Some(Msg::GuidedReviewPagePrevious)));
|
||||
assert!(matches!(claim(&mut app, &key(KeyCode::Char(' '))), Some(Msg::GuidedReviewHunkNext)));
|
||||
assert!(matches!(claim(&mut app, &key(KeyCode::Right)), Some(Msg::GuidedReviewColumnNext)));
|
||||
assert!(matches!(claim(&mut app, &key(KeyCode::Left)), Some(Msg::GuidedReviewColumnPrevious)));
|
||||
// Chords the keymap owns fall through to it rather than being claimed here.
|
||||
for bound in [
|
||||
key(KeyCode::Char('n')),
|
||||
key(KeyCode::Char(']')),
|
||||
key(KeyCode::Char('[')),
|
||||
key(KeyCode::Home),
|
||||
KeyEvent::new(KeyCode::Char('b'), KeyModifiers::CONTROL),
|
||||
KeyEvent::new(KeyCode::Char('v'), KeyModifiers::ALT),
|
||||
] {
|
||||
assert!(claim(&mut app, &bound).is_none(), "{bound:?} belongs to the keymap");
|
||||
}
|
||||
// And the key the surface retired answers with nothing rather than something surprising: Tab
|
||||
// used to move focus, and a focus move that quietly became a pane move would be worse than a
|
||||
// key that does nothing.
|
||||
assert!(
|
||||
matches!(claim(&mut app, &key(KeyCode::Tab)), Some(Msg::Tick)),
|
||||
"Tab is swallowed, never leaked to the composer"
|
||||
);
|
||||
}
|
||||
|
||||
/// The Guided Review surface is borderless (it reads as the same canvas as chat), while its
|
||||
/// overlays keep the shared rounded panel corners (`PANEL_BORDER_TYPE`).
|
||||
#[test]
|
||||
fn guided_review_surface_is_borderless_and_overlays_use_rounded_corners() {
|
||||
let (width, height) = (140, 40);
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = seeded_app("nord", FixtureScenario::GuidedReviewReady).unwrap();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
|
||||
// Borderless surface: no outer frame corners anywhere (only the thin rail divider remains).
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
let any_frame_corner = (0..width)
|
||||
.flat_map(|x| (0..height).map(move |y| (x, y)))
|
||||
.any(|(x, y)| matches!(buffer[(x, y)].symbol(), "╭" | "╮" | "╰" | "╯"));
|
||||
assert!(!any_frame_corner, "the review surface must be borderless");
|
||||
|
||||
// Opening the help overlay adds an interior rounded panel — proves overlays are rounded too.
|
||||
app.update(Msg::GuidedReviewToggleHelp);
|
||||
let with_help = render_app(&mut app, &backend);
|
||||
let interior_rounded_corner = (1..width - 1)
|
||||
.flat_map(|x| (1..height - 1).map(move |y| (x, y)))
|
||||
.any(|(x, y)| with_help[(x, y)].symbol() == "╭");
|
||||
assert!(interior_rounded_corner, "help overlay must render a rounded top-left corner");
|
||||
let any_square_corner = (0..width)
|
||||
.flat_map(|x| (0..height).map(move |y| (x, y)))
|
||||
.any(|(x, y)| matches!(with_help[(x, y)].symbol(), "┌" | "┐" | "└" | "┘"));
|
||||
assert!(!any_square_corner, "no Guided Review panel may use square corners");
|
||||
}
|
||||
|
||||
/// Region-precise wheel: after a render publishes the hit regions, a notch over the guide scrolls
|
||||
/// the guide's own prose, and over the diff scrolls source lines.
|
||||
///
|
||||
/// The guide's wheel used to walk the file selection, which made reading the section you were not
|
||||
/// standing in impossible — every notch dragged the review's position along with the view.
|
||||
#[test]
|
||||
fn wheel_over_review_panes_scrolls_the_surface_under_the_cursor() {
|
||||
use crossterm::event::{MouseEvent, MouseEventKind};
|
||||
let (width, height) = (140, 40);
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = seeded_app("nord", FixtureScenario::GuidedReviewReady).unwrap();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
let _ = render_app(&mut app, &backend); // publishes app.hit scroll regions
|
||||
|
||||
let wheel = |kind, column| MouseEvent { kind, column, row: 6, modifiers: KeyModifiers::NONE };
|
||||
// Left rail (guide pane) -> the prose scrolls; the cursor is not what moves.
|
||||
assert!(matches!(
|
||||
route_mouse(&mut app, &wheel(MouseEventKind::ScrollDown, 5)),
|
||||
RouteAction::Msg(message) if matches!(*message, Msg::GuidedReviewScrollGuide { up: false })
|
||||
));
|
||||
// Right pane (diff) -> line scroll.
|
||||
assert!(matches!(
|
||||
route_mouse(&mut app, &wheel(MouseEventKind::ScrollUp, 90)),
|
||||
RouteAction::Msg(message) if matches!(*message, Msg::GuidedReviewLinePrevious)
|
||||
));
|
||||
}
|
||||
509
crates/luxe-tui/tests/render/selection.rs
Normal file
509
crates/luxe-tui/tests/render/selection.rs
Normal file
@@ -0,0 +1,509 @@
|
||||
//! Selection — thinking output, drags, double clicks and folding by click.
|
||||
|
||||
use super::*;
|
||||
|
||||
/// Reasoning renders muted + italic: the body carries `Modifier::ITALIC` in the `thinkingText`
|
||||
/// color, and the collapsed block shows a one-line peek rather than the full body. The styling is
|
||||
/// the whole cue — no "thinking" banner is printed above it.
|
||||
#[test]
|
||||
fn thinking_output_is_muted_italic_with_a_collapsed_peek() {
|
||||
use ratatui::style::Modifier;
|
||||
let (width, height) = (120, 40);
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = seeded_app("nord", FixtureScenario::ChatThinking).unwrap();
|
||||
let thinking_fg = app.theme_styles.thinking_text.fg.expect("thinkingText color");
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
|
||||
assert!(
|
||||
!buffer_to_string(&buffer).contains("thinking"),
|
||||
"the redundant reasoning label is gone"
|
||||
);
|
||||
|
||||
// A word only the reasoning body says is italic in the muted color.
|
||||
let body_row = (0..height)
|
||||
.find(|&y| row_text(&buffer, y, width).contains("partial"))
|
||||
.expect("the reasoning body renders");
|
||||
let text = row_text(&buffer, body_row, width);
|
||||
let col = text.find("partial").expect("the reasoning token") as u16;
|
||||
assert!(
|
||||
buffer[(col, body_row)].modifier.contains(Modifier::ITALIC),
|
||||
"reasoning renders in italic"
|
||||
);
|
||||
assert_eq!(buffer[(col, body_row)].fg, thinking_fg, "reasoning uses the thinkingText color");
|
||||
|
||||
// The collapsed block peeks at its rendered first line and says what it is standing in for.
|
||||
let content = buffer_to_string(&buffer);
|
||||
assert!(
|
||||
content.contains("Planning the test · +1 more line"),
|
||||
"the collapsed peek shows the section title and the count: {content}"
|
||||
);
|
||||
assert!(
|
||||
!content.contains("single case"),
|
||||
"the collapsed block hides the rest of the reasoning body"
|
||||
);
|
||||
}
|
||||
|
||||
/// Reasoning is markdown in practice, so it renders as markdown: the `**title**` a GPT model leads
|
||||
/// each section with becomes a bold title in the reasoning color, and a backticked symbol takes the
|
||||
/// theme's code hue. The syntax that produced either one never reaches the screen.
|
||||
#[test]
|
||||
fn thinking_output_renders_its_markdown_without_showing_the_syntax() {
|
||||
use ratatui::style::Modifier;
|
||||
let (width, height) = (120, 40);
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = seeded_app("nord", FixtureScenario::ChatThinking).unwrap();
|
||||
let thinking_fg = app.theme_styles.thinking_text.fg.expect("thinkingText color");
|
||||
let code_fg = app.theme_styles.md_code.fg.expect("mdCode color");
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
let content = buffer_to_string(&buffer);
|
||||
|
||||
assert!(content.contains("Tracing the buffering"), "the section title renders: {content}");
|
||||
assert!(
|
||||
!content.contains("**") && !content.contains('`'),
|
||||
"no markdown syntax survives into the transcript: {content}"
|
||||
);
|
||||
|
||||
let cell = |needle: &str| {
|
||||
let row = (0..height)
|
||||
.find(|&y| row_text(&buffer, y, width).contains(needle))
|
||||
.unwrap_or_else(|| panic!("{needle} renders: {content}"));
|
||||
let col = row_text(&buffer, row, width).find(needle).expect("the column") as u16;
|
||||
&buffer[(col, row)]
|
||||
};
|
||||
|
||||
let title = cell("Tracing the buffering");
|
||||
assert!(title.modifier.contains(Modifier::BOLD), "a reasoning title is bold");
|
||||
assert!(title.modifier.contains(Modifier::ITALIC), "and stays in the reasoning voice");
|
||||
assert_eq!(title.fg, thinking_fg, "a title spends weight rather than a color");
|
||||
|
||||
// `Parser::feed` appears in both an answer and the reasoning above it, so pick the reasoning
|
||||
// line by something only it says.
|
||||
let code_row = (0..height)
|
||||
.find(|&y| {
|
||||
let text = row_text(&buffer, y, width);
|
||||
text.contains("Parser::feed") && text.contains("whole input")
|
||||
})
|
||||
.expect("the reasoning line naming the symbol");
|
||||
let code_col = row_text(&buffer, code_row, width).find("Parser::feed").expect("the column");
|
||||
let code = &buffer[(code_col as u16, code_row)];
|
||||
assert_eq!(code.fg, code_fg, "a backticked symbol keeps the code hue inside reasoning");
|
||||
assert!(code.modifier.contains(Modifier::ITALIC), "and is still italic");
|
||||
|
||||
// A list the model wrote renders as one, in the reasoning color.
|
||||
let bullet = cell("• a multi-byte token");
|
||||
assert_eq!(bullet.fg, thinking_fg, "a reasoning list marker takes the reasoning color");
|
||||
}
|
||||
|
||||
/// Capturing the mouse takes the terminal's own click-drag selection away, so a drag over the
|
||||
/// transcript must select, highlight, and copy in-app.
|
||||
#[test]
|
||||
fn dragging_over_the_transcript_selects_highlights_and_copies() {
|
||||
use crossterm::event::{MouseButton, MouseEvent, MouseEventKind};
|
||||
let (width, height) = (60, 12);
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = create_app();
|
||||
app.push_convo(ConvoBlock::Assistant("alpha bravo charlie".into()));
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
let row = (0..height)
|
||||
.find(|&y| row_text(&buffer, y, width).contains("alpha bravo charlie"))
|
||||
.expect("the reply renders");
|
||||
let start_col = column_of(&row_text(&buffer, row, width), "bravo");
|
||||
|
||||
let event = |kind, column, row| MouseEvent { kind, column, row, modifiers: KeyModifiers::NONE };
|
||||
let press = event(MouseEventKind::Down(MouseButton::Left), start_col, row);
|
||||
let action = route_mouse(&mut app, &press);
|
||||
apply(&mut app, action);
|
||||
assert!(app.pointer.selection_drag.is_some(), "a press on the transcript anchors a selection");
|
||||
|
||||
let drag = event(MouseEventKind::Drag(MouseButton::Left), start_col + 5, row);
|
||||
let action = route_mouse(&mut app, &drag);
|
||||
apply(&mut app, action);
|
||||
let selection = app.pointer.selection.clone().expect("the drag records a selection");
|
||||
assert!(!selection.grid.is_empty());
|
||||
|
||||
// The dragged cells render with the selection background.
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
let selected_bg = app.theme_styles.selected_bg.bg.expect("selection background");
|
||||
assert_eq!(buffer[(start_col, row)].bg, selected_bg, "the first selected cell is highlighted");
|
||||
assert_ne!(
|
||||
buffer[(start_col + 6, row)].bg,
|
||||
selected_bg,
|
||||
"cells past the selection stay unstyled"
|
||||
);
|
||||
|
||||
// Releasing copies, exactly like a terminal's copy-on-select, and says so — the clipboard
|
||||
// itself is invisible.
|
||||
let release = event(MouseEventKind::Up(MouseButton::Left), start_col + 5, row);
|
||||
let action = route_mouse(&mut app, &release);
|
||||
apply(&mut app, action);
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
assert_eq!(app.outbox.copy.as_deref(), Some("bravo"));
|
||||
assert!(app.pointer.selection_drag.is_none(), "the drag ends on release");
|
||||
assert!(
|
||||
buffer_to_string(&buffer).contains("Copied to clipboard"),
|
||||
"the row above the prompt should confirm the copy: {}",
|
||||
buffer_to_string(&buffer)
|
||||
);
|
||||
|
||||
// Esc drops the selection instead of reaching the composer.
|
||||
app.update(Msg::Key(KeyEvent::new(KeyCode::Esc, KeyModifiers::NONE)));
|
||||
assert!(app.pointer.selection.is_none(), "Esc clears the selection");
|
||||
}
|
||||
|
||||
/// An overlay drawn over the transcript takes it out of reach: a press on the overlay's own padding
|
||||
/// must not start a selection in the message hidden behind it, and a drag there must not copy it.
|
||||
#[test]
|
||||
fn an_open_overlay_stops_the_transcript_offering_text_and_clicks() {
|
||||
use crossterm::event::{MouseButton, MouseEvent, MouseEventKind};
|
||||
let (width, height) = (100, 30);
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = create_app();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
app.push_convo(ConvoBlock::Assistant("alpha bravo charlie".into()));
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
let row = (0..height)
|
||||
.find(|&y| row_text(&buffer, y, width).contains("alpha bravo charlie"))
|
||||
.expect("the reply renders");
|
||||
|
||||
// Ctrl+K opens the command palette over the chat surface.
|
||||
app.update(Msg::Key(KeyEvent::new(KeyCode::Char('k'), KeyModifiers::CONTROL)));
|
||||
render_app(&mut app, &backend);
|
||||
|
||||
let event = |kind| MouseEvent { kind, column: 4, row, modifiers: KeyModifiers::NONE };
|
||||
for kind in [
|
||||
MouseEventKind::Down(MouseButton::Left),
|
||||
MouseEventKind::Drag(MouseButton::Left),
|
||||
MouseEventKind::Up(MouseButton::Left),
|
||||
] {
|
||||
let action = route_mouse(&mut app, &event(kind));
|
||||
apply(&mut app, action);
|
||||
}
|
||||
assert!(app.pointer.selection.is_none(), "no selection starts behind the overlay");
|
||||
render_app(&mut app, &backend);
|
||||
assert!(app.outbox.copy.is_none(), "and nothing hidden is copied");
|
||||
}
|
||||
|
||||
/// A selection has to survive the transcript moving under it. Output arriving, a card opening — the
|
||||
/// line indices it was made from are stale within a frame, so each end is pinned to the transcript
|
||||
/// line it landed on and re-found every frame. Dropping the selection instead made it impossible to
|
||||
/// copy anything out of a session that was still streaming.
|
||||
#[test]
|
||||
fn a_transcript_selection_survives_new_output_above_it() {
|
||||
use crossterm::event::{MouseButton, MouseEvent, MouseEventKind};
|
||||
let (width, height) = (60, 20);
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = create_app();
|
||||
app.push_convo(ConvoBlock::Assistant("alpha bravo charlie".into()));
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
let row = (0..height)
|
||||
.find(|&y| row_text(&buffer, y, width).contains("alpha bravo charlie"))
|
||||
.expect("the reply renders");
|
||||
let start_col = column_of(&row_text(&buffer, row, width), "bravo");
|
||||
|
||||
let event = |kind, column| MouseEvent { kind, column, row, modifiers: KeyModifiers::NONE };
|
||||
let action = route_mouse(&mut app, &event(MouseEventKind::Down(MouseButton::Left), start_col));
|
||||
apply(&mut app, action);
|
||||
let action =
|
||||
route_mouse(&mut app, &event(MouseEventKind::Drag(MouseButton::Left), start_col + 5));
|
||||
apply(&mut app, action);
|
||||
let before = app.pointer.selection.clone().expect("the drag records a selection");
|
||||
|
||||
// Two new blocks land above nothing and below everything, and the *first* block grows — which
|
||||
// moves every rendered line under the selection.
|
||||
app.convo[0]
|
||||
.set_block(ConvoBlock::Assistant("alpha bravo charlie\n\nand a second paragraph".into()));
|
||||
app.push_convo(ConvoBlock::System("a later line".into()));
|
||||
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
let after = app.pointer.selection.clone().expect("the selection survives the reflow");
|
||||
assert_eq!(after.pins, before.pins, "it is pinned to the same transcript lines");
|
||||
assert_eq!(
|
||||
after.grid.bounds().0.column,
|
||||
before.grid.bounds().0.column,
|
||||
"and covers the same columns"
|
||||
);
|
||||
|
||||
// Still the same cells on screen, and still what the release copies.
|
||||
let moved_row = (0..height)
|
||||
.find(|&y| row_text(&buffer, y, width).contains("alpha bravo charlie"))
|
||||
.expect("the reply still renders");
|
||||
let selected_bg = app.theme_styles.selected_bg.bg.expect("selection background");
|
||||
assert_eq!(buffer[(start_col, moved_row)].bg, selected_bg, "the same word stays highlighted");
|
||||
|
||||
let action =
|
||||
route_mouse(&mut app, &event(MouseEventKind::Up(MouseButton::Left), start_col + 5));
|
||||
apply(&mut app, action);
|
||||
render_app(&mut app, &backend);
|
||||
assert_eq!(app.outbox.copy.as_deref(), Some("bravo"));
|
||||
}
|
||||
|
||||
/// Double-click grabs the word under the pointer, triple-click the whole line — the two gestures
|
||||
/// mouse capture takes away from the terminal. Both copy on release, like any other selection.
|
||||
#[test]
|
||||
fn a_double_click_takes_the_word_and_a_triple_click_the_line() {
|
||||
let (width, height) = (60, 12);
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = create_app();
|
||||
app.push_convo(ConvoBlock::Assistant("call Parser::feed on it".into()));
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
let row = (0..height)
|
||||
.find(|&y| row_text(&buffer, y, width).contains("Parser::feed"))
|
||||
.expect("the reply renders");
|
||||
let column = column_of(&row_text(&buffer, row, width), "Parser") + 3;
|
||||
let now = std::time::Instant::now();
|
||||
|
||||
// Chained presses on one cell escalate: the first is a caret, the second the word.
|
||||
click_cell(&mut app, column, row, now);
|
||||
assert!(app.outbox.copy.is_none(), "one click selects nothing to copy");
|
||||
click_cell(&mut app, column, row, now);
|
||||
render_app(&mut app, &backend);
|
||||
assert_eq!(
|
||||
app.outbox.copy.as_deref(),
|
||||
Some("Parser::feed"),
|
||||
"a double-click takes the whole symbol, colons included"
|
||||
);
|
||||
|
||||
// A third press takes the line — padding trimmed, since nobody wants the band on the clipboard.
|
||||
app.outbox.copy = None;
|
||||
click_cell(&mut app, column, row, now);
|
||||
render_app(&mut app, &backend);
|
||||
assert_eq!(app.outbox.copy.as_deref(), Some("call Parser::feed on it"));
|
||||
|
||||
// Far enough apart, the chain breaks and each press is its own caret again.
|
||||
app.outbox.copy = None;
|
||||
click_cell(&mut app, column, row, now + std::time::Duration::from_secs(1));
|
||||
render_app(&mut app, &backend);
|
||||
assert!(app.outbox.copy.is_none(), "a late click is a fresh single click");
|
||||
}
|
||||
|
||||
/// The composer answers the same two gestures, over its own buffer.
|
||||
#[test]
|
||||
fn a_double_click_in_the_composer_takes_the_word_under_it() {
|
||||
let (width, height) = (60, 12);
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = create_app();
|
||||
app.editor.insert_text("edit crates/luxe-tui/src/view.rs now");
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
let row = (0..height)
|
||||
.find(|&y| row_text(&buffer, y, width).contains("view.rs"))
|
||||
.expect("the draft renders");
|
||||
let column = column_of(&row_text(&buffer, row, width), "crates") + 2;
|
||||
let now = std::time::Instant::now();
|
||||
|
||||
click_cell(&mut app, column, row, now);
|
||||
click_cell(&mut app, column, row, now);
|
||||
assert_eq!(
|
||||
app.outbox.copy.as_deref(),
|
||||
Some("crates/luxe-tui/src/view.rs"),
|
||||
"a double-click takes the whole path"
|
||||
);
|
||||
|
||||
app.outbox.copy = None;
|
||||
click_cell(&mut app, column, row, now);
|
||||
assert_eq!(app.editor.selected_text().as_deref(), Some("edit crates/luxe-tui/src/view.rs now"));
|
||||
}
|
||||
|
||||
/// A click on a block that is holding something back opens it — the mouse equivalent of the expand
|
||||
/// chord, and the reason a truncated card's footer names both.
|
||||
#[test]
|
||||
fn clicking_a_truncated_card_expands_it() {
|
||||
use crossterm::event::{MouseButton, MouseEvent, MouseEventKind};
|
||||
let (width, height) = (100, 40);
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = create_app();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
let content = (1..=30).map(|n| format!("let value_{n} = {n};")).collect::<Vec<_>>().join("\n");
|
||||
let mut card = card_with_arguments(
|
||||
"write",
|
||||
"src/generated.rs",
|
||||
serde_json::json!({"path": "src/generated.rs", "content": content}),
|
||||
);
|
||||
card.activity.output_preview = Some("Created 'src/generated.rs' (620 bytes)".into());
|
||||
app.push_convo(ConvoBlock::Tool(Box::new(card)));
|
||||
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
assert!(!buffer_to_string(&buffer).contains("let value_11"), "the card starts truncated");
|
||||
let row = (0..height)
|
||||
.find(|&y| row_text(&buffer, y, width).contains("write src/generated.rs"))
|
||||
.expect("the card header renders");
|
||||
|
||||
let press = MouseEvent {
|
||||
kind: MouseEventKind::Down(MouseButton::Left),
|
||||
column: 10,
|
||||
row,
|
||||
modifiers: KeyModifiers::NONE,
|
||||
};
|
||||
let now = std::time::Instant::now();
|
||||
let action = route_mouse_at(&mut app, &press, now);
|
||||
assert!(matches!(action, RouteAction::None), "the press only anchors a selection");
|
||||
apply(&mut app, action);
|
||||
let release = MouseEvent { kind: MouseEventKind::Up(MouseButton::Left), ..press };
|
||||
let action = route_mouse_at(&mut app, &release, now);
|
||||
apply(&mut app, action);
|
||||
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
assert!(
|
||||
buffer_to_string(&buffer).contains("let value_11"),
|
||||
"the click opened the card: {}",
|
||||
buffer_to_string(&buffer)
|
||||
);
|
||||
assert!(app.outbox.copy.is_none(), "opening a card copies nothing");
|
||||
|
||||
// A later click on the header closes it again. The card grew and a short transcript grows
|
||||
// upward, so the header has to be found again each time rather than assumed to have stayed put.
|
||||
let row_of = |app: &mut App, needle: &str| {
|
||||
let buffer = render_app(app, &backend);
|
||||
(0..height)
|
||||
.find(|&y| row_text(&buffer, y, width).contains(needle))
|
||||
.unwrap_or_else(|| panic!("{needle} renders: {}", buffer_to_string(&buffer)))
|
||||
};
|
||||
|
||||
let header = row_of(&mut app, "write src/generated.rs");
|
||||
click_cell(&mut app, 10, header, now + std::time::Duration::from_secs(1));
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
assert!(!buffer_to_string(&buffer).contains("let value_11"), "a second click re-collapses it");
|
||||
|
||||
// A click on the card's *body* selects text instead of folding it away: collapsing the card out
|
||||
// from under a double-click is how you make a path in it impossible to grab.
|
||||
let header = row_of(&mut app, "write src/generated.rs");
|
||||
click_cell(&mut app, 10, header, now + std::time::Duration::from_secs(2));
|
||||
let body = row_of(&mut app, "let value_2 = 2;");
|
||||
click_cell(&mut app, 10, body, now + std::time::Duration::from_secs(3));
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
assert!(buffer_to_string(&buffer).contains("let value_11"), "the card stays open");
|
||||
}
|
||||
|
||||
/// The footer says "click or Ctrl+O to expand", so clicking the footer has to expand. A hint that
|
||||
/// names an affordance the row itself does not offer is worse than no hint.
|
||||
#[test]
|
||||
fn clicking_the_truncation_footer_expands_the_card() {
|
||||
let (width, height) = (100, 40);
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = create_app();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
let content = (1..=30).map(|n| format!("let value_{n} = {n};")).collect::<Vec<_>>().join("\n");
|
||||
app.push_convo(ConvoBlock::Tool(Box::new(card_with_arguments(
|
||||
"write",
|
||||
"src/generated.rs",
|
||||
serde_json::json!({"path": "src/generated.rs", "content": content}),
|
||||
))));
|
||||
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
let footer = (0..height)
|
||||
.find(|&y| row_text(&buffer, y, width).contains("click or ctrl+o to expand"))
|
||||
.expect("the truncation footer renders");
|
||||
click_cell(&mut app, 10, footer, std::time::Instant::now());
|
||||
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
assert!(
|
||||
buffer_to_string(&buffer).contains("let value_30"),
|
||||
"the footer's own click opened the card: {}",
|
||||
buffer_to_string(&buffer)
|
||||
);
|
||||
}
|
||||
|
||||
/// The same click opens a collapsed reasoning block, which is the other thing in the transcript
|
||||
/// with a body behind a one-line peek.
|
||||
#[test]
|
||||
fn clicking_a_collapsed_reasoning_block_expands_it() {
|
||||
use crossterm::event::{MouseButton, MouseEvent, MouseEventKind};
|
||||
let (width, height) = (100, 30);
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = create_app();
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
app.push_convo(ConvoBlock::Thinking {
|
||||
text: "**Checking the config**\n\nStart with the loader, then the merge order.".into(),
|
||||
expanded: false,
|
||||
});
|
||||
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
assert!(!buffer_to_string(&buffer).contains("merge order"), "it starts collapsed");
|
||||
let row = (0..height)
|
||||
.find(|&y| row_text(&buffer, y, width).contains("Checking the config"))
|
||||
.expect("the peek renders");
|
||||
|
||||
let event = |kind| MouseEvent { kind, column: 5, row, modifiers: KeyModifiers::NONE };
|
||||
for kind in [MouseEventKind::Down(MouseButton::Left), MouseEventKind::Up(MouseButton::Left)] {
|
||||
let action = route_mouse(&mut app, &event(kind));
|
||||
apply(&mut app, action);
|
||||
}
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
assert!(
|
||||
buffer_to_string(&buffer).contains("merge order"),
|
||||
"the click expanded the reasoning: {}",
|
||||
buffer_to_string(&buffer)
|
||||
);
|
||||
}
|
||||
|
||||
/// The composer owns its own selection (buffer offsets), highlights it, and copies on release.
|
||||
#[test]
|
||||
fn dragging_in_the_composer_selects_and_copies_the_draft_text() {
|
||||
use crossterm::event::{MouseButton, MouseEvent, MouseEventKind};
|
||||
let (width, height) = (60, 12);
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = create_app();
|
||||
app.editor.insert_text("select this text");
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
let row = (0..height)
|
||||
.find(|&y| row_text(&buffer, y, width).contains("select this text"))
|
||||
.expect("the draft renders");
|
||||
let start_col = column_of(&row_text(&buffer, row, width), "this");
|
||||
|
||||
let event = |kind, column| MouseEvent { kind, column, row, modifiers: KeyModifiers::NONE };
|
||||
let action = route_mouse(&mut app, &event(MouseEventKind::Down(MouseButton::Left), start_col));
|
||||
apply(&mut app, action);
|
||||
let action =
|
||||
route_mouse(&mut app, &event(MouseEventKind::Drag(MouseButton::Left), start_col + 9));
|
||||
apply(&mut app, action);
|
||||
assert_eq!(app.editor.selected_text().as_deref(), Some("this text"));
|
||||
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
let selected_bg = app.theme_styles.selected_bg.bg.expect("selection background");
|
||||
assert_eq!(buffer[(start_col, row)].bg, selected_bg, "the composer paints its selection");
|
||||
|
||||
let action =
|
||||
route_mouse(&mut app, &event(MouseEventKind::Up(MouseButton::Left), start_col + 9));
|
||||
apply(&mut app, action);
|
||||
assert_eq!(app.outbox.copy.as_deref(), Some("this text"));
|
||||
|
||||
// Typing replaces the selection, the way every other editor behaves.
|
||||
app.update(Msg::Key(KeyEvent::new(KeyCode::Char('X'), KeyModifiers::NONE)));
|
||||
assert_eq!(app.editor.current_input(), "select X");
|
||||
}
|
||||
|
||||
/// Hovering a list row moves the same highlight the arrow keys would.
|
||||
#[test]
|
||||
fn hovering_a_picker_row_moves_the_keyboard_selection() {
|
||||
use crossterm::event::{MouseEvent, MouseEventKind};
|
||||
let (width, height) = (80, 24);
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = create_app();
|
||||
app.update(Msg::Key(key(KeyCode::Char('/'))));
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
|
||||
let rows: Vec<u16> =
|
||||
(0..height).filter(|&y| row_text(&buffer, y, width).contains('❯')).collect();
|
||||
assert_eq!(rows.len(), 1, "exactly one row carries the selection cursor");
|
||||
let selected_row = rows[0];
|
||||
let other_row = selected_row + 1;
|
||||
|
||||
let moved = MouseEvent {
|
||||
kind: MouseEventKind::Moved,
|
||||
column: 4,
|
||||
row: other_row,
|
||||
modifiers: KeyModifiers::NONE,
|
||||
};
|
||||
let action = route_mouse(&mut app, &moved);
|
||||
apply(&mut app, action);
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
assert!(
|
||||
row_text(&buffer, other_row, width).contains('❯'),
|
||||
"the hovered row takes the selection cursor"
|
||||
);
|
||||
assert!(
|
||||
!row_text(&buffer, selected_row, width).contains('❯'),
|
||||
"the previously selected row gives it up"
|
||||
);
|
||||
}
|
||||
255
crates/luxe-tui/tests/render/steering.rs
Normal file
255
crates/luxe-tui/tests/render/steering.rs
Normal file
@@ -0,0 +1,255 @@
|
||||
//! Steering — a message sent mid-turn, recalled, queued or never delivered.
|
||||
|
||||
use super::*;
|
||||
|
||||
/// A mid-turn submission steers by default: it's pinned above the composer and handed to the
|
||||
/// running turn, without resetting turn state or entering the transcript before it lands.
|
||||
#[test]
|
||||
fn a_message_sent_mid_turn_steers_instead_of_starting_a_turn() {
|
||||
let (width, height) = (80, 24);
|
||||
let backend = test_backend(width, height);
|
||||
let (tx, mut rx) = tokio::sync::mpsc::channel::<luxe_core::engine::Action>(64);
|
||||
let mut app = App::new(tx, KeyMap::defaults(), Config::default());
|
||||
// A live session, so the committed steer below is accepted the way the runtime sends it.
|
||||
app.update(Msg::Engine(luxe_core::event::Event::SessionLoaded {
|
||||
session_id: "session-a".into(),
|
||||
messages: vec![],
|
||||
}));
|
||||
|
||||
// A turn is running: the status clock is ticking.
|
||||
app.update(Msg::Engine(luxe_core::event::Event::TokenDelta {
|
||||
block: 0,
|
||||
delta: "working".into(),
|
||||
}));
|
||||
let started = app.status.turn_started.expect("the turn clock is running");
|
||||
|
||||
app.editor.insert_text("actually, check the tests too");
|
||||
app.update(Msg::Key(key(KeyCode::Enter)));
|
||||
|
||||
match rx.try_recv().expect("a steer action reaches the engine") {
|
||||
luxe_core::engine::Action::SteerTurn { content } => {
|
||||
assert_eq!(content, "actually, check the tests too");
|
||||
}
|
||||
other => panic!("expected SteerTurn, got {other:?}"),
|
||||
}
|
||||
assert_eq!(app.status.turn_started, Some(started), "steering must not restart the turn clock");
|
||||
|
||||
// Held above the composer, not dropped into the transcript where the turn's own output would
|
||||
// scroll it away.
|
||||
assert_eq!(app.pending_submissions.len(), 1);
|
||||
assert!(
|
||||
!app.convo.iter().any(|item| matches!(item.block(), ConvoBlock::User { .. })),
|
||||
"a steer isn't a transcript message until it lands"
|
||||
);
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
let content = buffer_to_string(&buffer);
|
||||
assert!(content.contains("steering"), "the tray says what's pending: {content}");
|
||||
assert!(content.contains("check the tests too"), "and shows the message: {content}");
|
||||
|
||||
// Delivery is announced twice by design: the engine commits the steer as a real user entry
|
||||
// (`MessageCommitted`, which carries the persisted id) and then reports the delivery. Exactly
|
||||
// one transcript row may come out of that pair — landing both is what showed every steer twice.
|
||||
app.update(Msg::Engine(luxe_core::event::Event::MessageCommitted {
|
||||
session_id: "session-a".into(),
|
||||
entry_id: luxe_core::session::EntryId("entry-steer".into()),
|
||||
message: luxe_core::message::Message::user("actually, check the tests too"),
|
||||
}));
|
||||
app.update(Msg::Engine(luxe_core::event::Event::SteeringDelivered { count: 1 }));
|
||||
|
||||
assert!(app.pending_submissions.is_empty(), "the tray row retires on delivery");
|
||||
let steers = app
|
||||
.convo
|
||||
.iter()
|
||||
.filter(|item| {
|
||||
matches!(item.block(), ConvoBlock::User { text, .. } if text == "actually, check the tests too")
|
||||
})
|
||||
.count();
|
||||
assert_eq!(steers, 1, "the delivered steer appears exactly once in the transcript");
|
||||
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
let content = buffer_to_string(&buffer);
|
||||
assert!(!content.contains("steering"), "the tray row retires on delivery: {content}");
|
||||
assert!(content.contains("check the tests too"), "the message stays, in the transcript");
|
||||
}
|
||||
|
||||
/// Cancelling hands a steer the engine never took in back to the composer.
|
||||
///
|
||||
/// A message that never ran belongs somewhere it can be fixed and re-sent, not in the transcript as
|
||||
/// a read-only row — interrupting is usually the first half of "let me put that differently". The
|
||||
/// engine has to be told as well: a steer is admitted the moment it is submitted, so a UI that only
|
||||
/// cleared its own tray would leave the recalled text queued for the next turn's first checkpoint.
|
||||
#[test]
|
||||
fn a_cancelled_steer_comes_back_to_the_composer() {
|
||||
let (tx, mut rx) = tokio::sync::mpsc::channel::<luxe_core::engine::Action>(64);
|
||||
let mut app = App::new(tx, KeyMap::defaults(), Config::default());
|
||||
app.update(Msg::Engine(luxe_core::event::Event::TokenDelta {
|
||||
block: 0,
|
||||
delta: "working".into(),
|
||||
}));
|
||||
app.editor.insert_text("never mind, stop");
|
||||
app.update(Msg::Key(key(KeyCode::Enter)));
|
||||
assert!(matches!(rx.try_recv(), Ok(luxe_core::engine::Action::SteerTurn { .. })));
|
||||
assert_eq!(app.editor.current_input(), "", "submitting cleared the draft");
|
||||
|
||||
app.update(Msg::Key(KeyEvent::new(KeyCode::Esc, KeyModifiers::CONTROL)));
|
||||
|
||||
assert!(app.pending_submissions.is_empty(), "nothing is left waiting");
|
||||
assert_eq!(app.editor.current_input(), "never mind, stop", "and it is editable again");
|
||||
assert!(
|
||||
!app.convo.iter().any(
|
||||
|item| matches!(item.block(), ConvoBlock::User { text, .. } if text == "never mind, stop")
|
||||
),
|
||||
"a message that never ran is not transcript history"
|
||||
);
|
||||
let sent: Vec<_> = std::iter::from_fn(|| rx.try_recv().ok()).collect();
|
||||
assert!(
|
||||
sent.iter().any(|action| matches!(action, luxe_core::engine::Action::Cancel)),
|
||||
"the turn is still cancelled: {sent:?}"
|
||||
);
|
||||
assert!(
|
||||
sent.iter().any(|action| matches!(action, luxe_core::engine::Action::WithdrawSteering)),
|
||||
"and the engine drops the steer it had buffered: {sent:?}"
|
||||
);
|
||||
}
|
||||
|
||||
/// Alt+Up takes back everything waiting, in the order it was typed, ahead of the current draft.
|
||||
#[test]
|
||||
fn the_recall_key_returns_every_waiting_message_to_the_composer() {
|
||||
let (width, height) = (80, 24);
|
||||
let backend = test_backend(width, height);
|
||||
let (tx, mut rx) = tokio::sync::mpsc::channel::<luxe_core::engine::Action>(64);
|
||||
let mut app = App::new(tx, KeyMap::defaults(), Config::default());
|
||||
app.update(Msg::Engine(luxe_core::event::Event::TokenDelta {
|
||||
block: 0,
|
||||
delta: "working".into(),
|
||||
}));
|
||||
|
||||
app.editor.insert_text("also check the reconnect backoff");
|
||||
app.update(Msg::Key(key(KeyCode::Enter)));
|
||||
app.editor.insert_text("then update the architecture doc");
|
||||
app.update(Msg::Key(KeyEvent::new(KeyCode::Enter, KeyModifiers::ALT)));
|
||||
assert_eq!(app.pending_submissions.len(), 2, "one steer, one follow-up");
|
||||
|
||||
// The tray says which key brings them back, or the feature is invisible.
|
||||
let content = buffer_to_string(&render_app(&mut app, &backend));
|
||||
assert!(content.contains("alt+up to edit them here"), "{content}");
|
||||
|
||||
app.editor.insert_text("and a half-typed third");
|
||||
app.update(Msg::Key(KeyEvent::new(KeyCode::Up, KeyModifiers::ALT)));
|
||||
|
||||
assert!(app.pending_submissions.is_empty(), "the tray empties");
|
||||
assert_eq!(
|
||||
app.editor.current_input(),
|
||||
"also check the reconnect backoff\n\nthen update the architecture doc\n\nand a half-typed third",
|
||||
"restored in submission order, before what was being typed"
|
||||
);
|
||||
let sent: Vec<_> = std::iter::from_fn(|| rx.try_recv().ok()).collect();
|
||||
assert!(
|
||||
sent.iter().any(|action| matches!(action, luxe_core::engine::Action::WithdrawSteering)),
|
||||
"the buffered steer is withdrawn: {sent:?}"
|
||||
);
|
||||
|
||||
// Pressing it again has nothing to take back, and says so rather than reading as a dead key.
|
||||
app.update(Msg::Key(KeyEvent::new(KeyCode::Up, KeyModifiers::ALT)));
|
||||
let content = buffer_to_string(&render_app(&mut app, &backend));
|
||||
assert!(content.contains("Nothing waiting to restore"), "{content}");
|
||||
}
|
||||
|
||||
/// A steer that could not be sent at all still shows up, marked as never sent.
|
||||
///
|
||||
/// The one remaining path to that marker: with the engine gone there is nothing to recall from and
|
||||
/// nothing that will ever deliver it, so the transcript is where it has to be said.
|
||||
#[test]
|
||||
fn a_steer_the_engine_never_received_is_marked_never_sent() {
|
||||
let (tx, rx) = tokio::sync::mpsc::channel::<luxe_core::engine::Action>(64);
|
||||
drop(rx);
|
||||
let mut app = App::new(tx, KeyMap::defaults(), Config::default());
|
||||
app.update(Msg::Engine(luxe_core::event::Event::TokenDelta {
|
||||
block: 0,
|
||||
delta: "working".into(),
|
||||
}));
|
||||
|
||||
app.editor.insert_text("one more thing");
|
||||
app.update(Msg::Key(key(KeyCode::Enter)));
|
||||
|
||||
assert!(app.pending_submissions.is_empty(), "nothing is waiting on a delivery that can't come");
|
||||
let landed = app
|
||||
.convo
|
||||
.iter()
|
||||
.find(
|
||||
|item| matches!(item.block(), ConvoBlock::User { text, .. } if text == "one more thing"),
|
||||
)
|
||||
.expect("the undeliverable steer is in the transcript");
|
||||
assert!(app.was_never_sent(&landed.id), "and is marked as never sent");
|
||||
}
|
||||
|
||||
/// The tray holds its ground while the turn keeps streaming: a pending message must not drift up
|
||||
/// with the transcript or scroll out of view before it has run.
|
||||
#[test]
|
||||
fn a_pending_message_stays_pinned_above_the_composer_while_output_streams() {
|
||||
let (width, height) = (80, 24);
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = create_app();
|
||||
app.update(Msg::Engine(luxe_core::event::Event::TokenDelta {
|
||||
block: 0,
|
||||
delta: "working".into(),
|
||||
}));
|
||||
app.editor.insert_text("one more thing");
|
||||
app.update(Msg::Key(KeyEvent::new(KeyCode::Enter, KeyModifiers::ALT)));
|
||||
|
||||
let row_of_tray = |app: &mut App| {
|
||||
let buffer = render_app(app, &backend);
|
||||
(0..height).find(|&y| row_text(&buffer, y, width).contains("one more thing"))
|
||||
};
|
||||
let before = row_of_tray(&mut app).expect("the tray row renders");
|
||||
|
||||
for index in 0..40 {
|
||||
app.update(Msg::Engine(luxe_core::event::Event::TokenDelta {
|
||||
block: 0,
|
||||
delta: format!("streamed line {index}\n"),
|
||||
}));
|
||||
}
|
||||
let after = row_of_tray(&mut app).expect("the tray row is still on screen");
|
||||
assert_eq!(before, after, "a pending message holds its row while the transcript scrolls");
|
||||
}
|
||||
|
||||
/// Alt+Enter queues a follow-up turn instead: held (visibly, with its position) until the current
|
||||
/// turn ends, then promoted one at a time.
|
||||
#[test]
|
||||
fn alt_enter_queues_a_follow_up_turn_promoted_when_the_turn_ends() {
|
||||
let (width, height) = (80, 24);
|
||||
let backend = test_backend(width, height);
|
||||
let (tx, mut rx) = tokio::sync::mpsc::channel::<luxe_core::engine::Action>(64);
|
||||
let mut app = App::new(tx, KeyMap::defaults(), Config::default());
|
||||
app.update(Msg::Engine(luxe_core::event::Event::TokenDelta {
|
||||
block: 0,
|
||||
delta: "working".into(),
|
||||
}));
|
||||
|
||||
app.editor.insert_text("then update the docs");
|
||||
app.update(Msg::Key(KeyEvent::new(KeyCode::Enter, KeyModifiers::ALT)));
|
||||
assert!(rx.try_recv().is_err(), "a queued message must not reach the engine yet");
|
||||
assert_eq!(app.queued_count(), 1);
|
||||
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
let content = buffer_to_string(&buffer);
|
||||
assert!(content.contains("queued"), "the queued message says so: {content}");
|
||||
assert!(content.contains("#1"), "and carries its position: {content}");
|
||||
|
||||
// The turn ends: exactly one queued message is promoted into a real turn.
|
||||
app.update(Msg::Engine(luxe_core::event::Event::TurnEnded {
|
||||
reason: luxe_core::event::StopReason::EndTurn,
|
||||
}));
|
||||
match rx.try_recv().expect("the queued message is promoted") {
|
||||
luxe_core::engine::Action::SubmitUserMessage { content, .. } => {
|
||||
assert_eq!(content, "then update the docs");
|
||||
}
|
||||
other => panic!("expected SubmitUserMessage, got {other:?}"),
|
||||
}
|
||||
assert_eq!(app.queued_count(), 0);
|
||||
assert!(app.status.turn_started.is_some(), "promotion starts the turn clock");
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
let content = buffer_to_string(&buffer);
|
||||
assert!(!content.contains("queued"), "the tray row retires on promotion: {content}");
|
||||
assert!(content.contains("then update the docs"), "and the message joins the transcript");
|
||||
}
|
||||
92
crates/luxe-tui/tests/render/support.rs
Normal file
92
crates/luxe-tui/tests/render/support.rs
Normal file
@@ -0,0 +1,92 @@
|
||||
//! Support — the app, backend and click helpers every render scenario builds on.
|
||||
|
||||
use super::*;
|
||||
|
||||
/// Helper to create a test backend with the given size.
|
||||
pub(crate) fn test_backend(width: u16, height: u16) -> TestBackend {
|
||||
TestBackend::new(width, height)
|
||||
}
|
||||
|
||||
/// Cells a dock heading badge spends in front of its label: the opening cap and one pad.
|
||||
///
|
||||
/// The badge's *leading edge* is what lands on the panel's content margin, so a test looking for
|
||||
/// the label finds it this far in. Spent at every glyph tier — below nerd the cap is a filled cell
|
||||
/// rather than a chamfer, so the column does not move.
|
||||
pub(crate) const DOCK_HEADING_LEAD: u16 = 2;
|
||||
|
||||
/// The activity bar's unspent unit — `▏`, the default `ActivityBarStyle::Bars` track glyph. How a
|
||||
/// test finds the row the indicator is on.
|
||||
pub(crate) const ACTIVITY_BAR_TRACK: &str = "\u{258f}";
|
||||
/// Every glyph the default bar can draw — the comet's weights, tapering onto the rail's own.
|
||||
pub(crate) const ACTIVITY_BAR_GLYPHS: [char; 4] = ['\u{258c}', '\u{258d}', '\u{258e}', '\u{258f}'];
|
||||
|
||||
/// Screen column where `needle` starts in a rendered row (cells, not bytes).
|
||||
pub(crate) fn column_of(text: &str, needle: &str) -> u16 {
|
||||
let byte = text.find(needle).unwrap_or_else(|| panic!("{needle:?} missing from row {text:?}"));
|
||||
text[..byte].chars().count() as u16
|
||||
}
|
||||
|
||||
/// Applies a routed mouse action the way the event loop would (the subset the mouse tests emit).
|
||||
pub(crate) fn apply(app: &mut App, action: RouteAction) {
|
||||
use luxe_tui::main_loop::ScrollAction;
|
||||
match action {
|
||||
RouteAction::Msg(message) => app.update(*message),
|
||||
RouteAction::Scroll(ScrollAction::Up(lines)) => app.scroll_state.up_by(lines),
|
||||
RouteAction::Scroll(ScrollAction::Down(lines)) => app.scroll_state.down_by(lines),
|
||||
RouteAction::None => {}
|
||||
other => panic!("unexpected route action in a mouse test: {other:?}"),
|
||||
}
|
||||
}
|
||||
|
||||
/// Presses and releases the left button at one cell, at `at` on the multi-click clock.
|
||||
///
|
||||
/// Two clicks a test fires back to back land microseconds apart, which is a *double*-click; passing
|
||||
/// the instant is how a test says "two separate clicks" or "one deliberate double-click".
|
||||
pub(crate) fn click_cell(app: &mut App, column: u16, row: u16, at: std::time::Instant) {
|
||||
use crossterm::event::{MouseButton, MouseEvent, MouseEventKind};
|
||||
for kind in [MouseEventKind::Down(MouseButton::Left), MouseEventKind::Up(MouseButton::Left)] {
|
||||
let event = MouseEvent { kind, column, row, modifiers: KeyModifiers::NONE };
|
||||
let action = route_mouse_at(app, &event, at);
|
||||
apply(app, action);
|
||||
}
|
||||
}
|
||||
|
||||
/// Helper to render the app and get the buffer.
|
||||
pub(crate) fn render_app(app: &mut App, backend: &TestBackend) -> Buffer {
|
||||
let mut terminal = Terminal::new(backend.clone()).unwrap();
|
||||
terminal
|
||||
.draw(|f| {
|
||||
render(f, app);
|
||||
})
|
||||
.unwrap();
|
||||
terminal.backend().buffer().clone()
|
||||
}
|
||||
|
||||
/// Helper to create an app with a dummy channel.
|
||||
pub(crate) fn create_app() -> App {
|
||||
let (tx, _rx) = tokio::sync::mpsc::channel::<luxe_core::engine::Action>(64);
|
||||
App::new(tx, KeyMap::defaults(), Config::default())
|
||||
}
|
||||
|
||||
/// Helper to create an app with a specific theme.
|
||||
pub(crate) fn create_app_with_config(config: Config) -> App {
|
||||
let (tx, _rx) = tokio::sync::mpsc::channel::<luxe_core::engine::Action>(64);
|
||||
App::new(tx, KeyMap::defaults(), config)
|
||||
}
|
||||
|
||||
/// Helper to create an app with a specific theme.
|
||||
pub(crate) fn create_app_with_theme(theme: &str) -> App {
|
||||
let (tx, _rx) = tokio::sync::mpsc::channel::<luxe_core::engine::Action>(64);
|
||||
App::new(
|
||||
tx,
|
||||
KeyMap::defaults(),
|
||||
Config { theme: Some(theme.to_string()), ..Default::default() },
|
||||
)
|
||||
}
|
||||
|
||||
/// An app in a light palette. No built-in is light any more, but a reader's own theme can be.
|
||||
pub(crate) fn create_app_with_light_theme() -> App {
|
||||
let mut app = create_app_with_theme("luxe");
|
||||
app.theme_styles = luxe_tui::fixture::light_theme_styles();
|
||||
app
|
||||
}
|
||||
437
crates/luxe-tui/tests/render/transcript.rs
Normal file
437
crates/luxe-tui/tests/render/transcript.rs
Normal file
@@ -0,0 +1,437 @@
|
||||
//! Transcript — messages, cards and system notices drawn in the conversation, and how a scrolled view holds its place.
|
||||
|
||||
use super::*;
|
||||
|
||||
/// An empty conversation still draws the composer, where typing will land.
|
||||
#[test]
|
||||
fn an_empty_conversation_draws_the_composer() {
|
||||
let backend = test_backend(80, 24);
|
||||
let mut app = create_app();
|
||||
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
|
||||
let (x, y) = composer_corner(&buffer);
|
||||
assert!(y > 0, "the composer sits under the conversation, not at the top: ({x}, {y})");
|
||||
assert_eq!(buffer[(x, y)].symbol(), "\u{256d}", "a rounded corner opens the box");
|
||||
}
|
||||
|
||||
/// Messages draw in the order they were said, the reader's first.
|
||||
#[test]
|
||||
fn messages_draw_in_the_order_they_were_said() {
|
||||
let backend = test_backend(80, 24);
|
||||
let mut app = create_app();
|
||||
app.push_convo(ConvoBlock::User {
|
||||
text: "Hello".to_string(),
|
||||
attached: Vec::new(),
|
||||
chips: Vec::new(),
|
||||
});
|
||||
app.push_convo(ConvoBlock::Assistant("Hi there!".to_string()));
|
||||
|
||||
let rendered = buffer_to_string(&render_app(&mut app, &backend));
|
||||
|
||||
let hello =
|
||||
rendered.find("Hello").unwrap_or_else(|| panic!("the message is missing: {rendered}"));
|
||||
let reply =
|
||||
rendered.find("Hi there!").unwrap_or_else(|| panic!("the reply is missing: {rendered}"));
|
||||
assert!(hello < reply, "the reader's message comes first: {rendered}");
|
||||
}
|
||||
|
||||
/// Test rendering with a tool call.
|
||||
#[test]
|
||||
fn test_render_with_tool_call() {
|
||||
let backend = test_backend(80, 24);
|
||||
let mut app = create_app();
|
||||
|
||||
app.push_convo(ConvoBlock::Tool(Box::new(ToolItem {
|
||||
activity: ToolActivity::running("session-a", "call-a", "bash", "ls -la", 1),
|
||||
expanded: false,
|
||||
details_toggled: false,
|
||||
waited_on_user_ms: 0,
|
||||
})));
|
||||
|
||||
let rendered = buffer_to_string(&render_app(&mut app, &backend));
|
||||
assert!(rendered.contains("ls -la"), "running command missing: {rendered}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn expanded_tool_details_render_and_wrap_inside_the_conversation() {
|
||||
let (width, height) = (48, 18);
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = create_app();
|
||||
let mut activity = ToolActivity::running("session-a", "call-a", "bash", "cargo test", 1);
|
||||
activity.state = ToolActivityState::Failed;
|
||||
activity.input_preview = Some("--package luxe-tui --features detailed-tools".into());
|
||||
activity.output_preview =
|
||||
Some("tool output must wrap inside the visible conversation pane tail".into());
|
||||
activity.summary = Some("validation failed".into());
|
||||
app.push_convo(ConvoBlock::Tool(Box::new(ToolItem {
|
||||
activity,
|
||||
expanded: true,
|
||||
details_toggled: false,
|
||||
waited_on_user_ms: 0,
|
||||
})));
|
||||
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
let content = buffer_to_string(&buffer);
|
||||
|
||||
assert!(content.contains("arguments:"), "missing arguments detail: {content}");
|
||||
assert!(content.contains("output:"), "missing output detail: {content}");
|
||||
assert!(content.contains("pane tail"), "wrapped output tail was clipped: {content}");
|
||||
// The outcome rides on the header line — a `result:` row underneath would say it twice.
|
||||
assert!(content.contains("validation failed"), "the outcome is on the card: {content}");
|
||||
assert!(!content.contains("result:"), "no redundant result row: {content}");
|
||||
}
|
||||
|
||||
/// A question card is one exchange in two rows, so the answer has to land on the *header's*
|
||||
/// columns rather than under the body indent every other card's payload uses. Measured off the
|
||||
/// rendered buffer, because the columns are what a reader sees: nothing in the source says `12`.
|
||||
#[test]
|
||||
fn a_question_cards_answer_lines_up_with_the_question_it_answers() {
|
||||
let (width, height) = (150u16, 34u16);
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = seeded_app("nord", FixtureScenario::ChatQuestion).expect("the fixture");
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
let rows: Vec<String> = (0..height).map(|y| row_text(&buffer, y, width)).collect();
|
||||
let asked = rows
|
||||
.iter()
|
||||
.find(|row| row.contains("Where should the ingest worker live?"))
|
||||
.expect("the question card's header");
|
||||
let answered =
|
||||
rows.iter().find(|row| row.contains("its own crate")).expect("the answer under it");
|
||||
|
||||
assert_eq!(
|
||||
column_of(asked, "question"),
|
||||
column_of(answered, "answer"),
|
||||
"the labels share a column:\n{asked}\n{answered}"
|
||||
);
|
||||
assert_eq!(
|
||||
column_of(asked, "Where should"),
|
||||
column_of(answered, "its own crate"),
|
||||
"and so do the words they label:\n{asked}\n{answered}"
|
||||
);
|
||||
}
|
||||
|
||||
/// The reader's own decision is drawn in the reader's own color, the one a user turn takes — not in
|
||||
/// the body color that would leave it indistinguishable from the question above it.
|
||||
#[test]
|
||||
fn a_question_cards_answer_is_drawn_in_the_color_a_user_turn_is() {
|
||||
let (width, height) = (150u16, 34u16);
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = seeded_app("nord", FixtureScenario::ChatQuestion).expect("the fixture");
|
||||
app.update(Msg::TerminalResized { width, height });
|
||||
let accent = app.theme_styles.accent.fg.expect("an accent color");
|
||||
let text = app.theme_styles.text.fg.expect("a text color");
|
||||
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
let (x, y) = marker_position(&buffer, "its own crate", width, height);
|
||||
assert_eq!(buffer[(x, y)].fg, accent, "the answer takes the user's color");
|
||||
assert_ne!(accent, text, "precondition: the theme draws them differently");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_running_tool_card_animates_its_spinner_and_the_thumb_takes_the_accent() {
|
||||
let backend = test_backend(60, 12);
|
||||
let mut app = create_app();
|
||||
for index in 0..30 {
|
||||
app.push_convo(ConvoBlock::System(format!("filler {index}")));
|
||||
}
|
||||
let activity = ToolActivity::running("session-a", "call-a", "bash", "cargo test", 1);
|
||||
app.push_convo(ConvoBlock::Tool(Box::new(ToolItem {
|
||||
activity,
|
||||
expanded: false,
|
||||
details_toggled: false,
|
||||
waited_on_user_ms: 0,
|
||||
})));
|
||||
|
||||
let frame_zero = render_app(&mut app, &backend);
|
||||
let row_zero: String = frame_zero.content.iter().map(|cell| cell.symbol()).collect();
|
||||
app.status.spinner_frame = 4;
|
||||
let frame_four = render_app(&mut app, &backend);
|
||||
let row_four: String = frame_four.content.iter().map(|cell| cell.symbol()).collect();
|
||||
assert_ne!(row_zero, row_four, "the running glyph is frozen across spinner frames");
|
||||
|
||||
// The scrollbar thumb is the positional indicator, so it wears the accent, not the border.
|
||||
let accent = app.theme_styles.accent.fg.expect("theme accent has a foreground");
|
||||
let border = app.theme_styles.border.fg.expect("theme border has a foreground");
|
||||
assert_ne!(accent, border, "fixture theme must distinguish accent from border");
|
||||
let thumbs =
|
||||
frame_four.content.iter().filter(|cell| cell.symbol() == "\u{2590}").collect::<Vec<_>>();
|
||||
assert!(!thumbs.is_empty(), "a taller-than-viewport transcript draws a thumb");
|
||||
assert!(
|
||||
thumbs.iter().all(|cell| cell.fg == accent),
|
||||
"scrollbar thumb should use the theme accent"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn scrolling_up_between_renders_is_not_undone_by_anchor_restore() {
|
||||
// Every frame used to re-derive the offset from the *previous* frame's anchor whenever follow
|
||||
// was off, so each manual scroll was reverted before it could be seen. Drive the real
|
||||
// two-frame sequence: render, scroll, render.
|
||||
let backend = test_backend(60, 10);
|
||||
let mut app = create_app();
|
||||
for index in 0..40 {
|
||||
app.push_convo(ConvoBlock::System(format!("transcript line {index}")));
|
||||
}
|
||||
|
||||
render_app(&mut app, &backend);
|
||||
assert!(app.scroll_state.follow, "a fresh transcript follows the tail");
|
||||
let bottom = app.scroll_state.offset;
|
||||
|
||||
for _ in 0..5 {
|
||||
app.scroll_state.line_up();
|
||||
}
|
||||
assert_eq!(app.scroll_state.offset, bottom - 5);
|
||||
|
||||
render_app(&mut app, &backend);
|
||||
assert_eq!(app.scroll_state.offset, bottom - 5, "the render pass clobbered a manual scroll");
|
||||
|
||||
// And it keeps moving on subsequent scrolls rather than sticking at the first position.
|
||||
app.scroll_state.page_up();
|
||||
let after_page = app.scroll_state.offset;
|
||||
render_app(&mut app, &backend);
|
||||
assert_eq!(app.scroll_state.offset, after_page);
|
||||
|
||||
// Scrolling back to the bottom re-arms follow, and new content sticks to the tail again.
|
||||
app.scroll_state.to_bottom();
|
||||
render_app(&mut app, &backend);
|
||||
app.push_convo(ConvoBlock::System("fresh tail".into()));
|
||||
render_app(&mut app, &backend);
|
||||
assert!(app.scroll_state.follow);
|
||||
assert_eq!(app.scroll_state.offset, app.scroll_state.total - app.scroll_state.viewport);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn content_growing_above_a_scrolled_viewport_keeps_the_anchored_line() {
|
||||
// The other half of the contract: while scrolled up, a block *above* the viewport growing
|
||||
// (tool output streaming in) must not shove the reader's position around.
|
||||
let backend = test_backend(60, 10);
|
||||
let mut app = create_app();
|
||||
app.push_convo(ConvoBlock::Assistant("first reply".into()));
|
||||
for index in 0..30 {
|
||||
app.push_convo(ConvoBlock::System(format!("item {index}")));
|
||||
}
|
||||
|
||||
render_app(&mut app, &backend);
|
||||
for _ in 0..8 {
|
||||
app.scroll_state.line_up();
|
||||
}
|
||||
render_app(&mut app, &backend);
|
||||
let anchored = app.conversation_anchor.clone().expect("anchor after scrolling up");
|
||||
|
||||
// Grow the very first block, which sits above the viewport.
|
||||
app.convo[0].set_block(ConvoBlock::Assistant("first reply\n\nwith\n\nmore\n\nlines".into()));
|
||||
render_app(&mut app, &backend);
|
||||
|
||||
let after = app.conversation_anchor.as_ref().expect("anchor after growth");
|
||||
assert_eq!(after.item_id, anchored.item_id, "same item still at the top of the viewport");
|
||||
assert_eq!(after.visual_line_within_item, anchored.visual_line_within_item);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn expanding_a_tool_above_the_viewport_preserves_anchor_and_selection() {
|
||||
let backend = test_backend(60, 10);
|
||||
let mut app = create_app();
|
||||
let mut activity = ToolActivity::running("session-a", "call-a", "bash", "cargo test", 1);
|
||||
activity.input_preview = Some("--package luxe-tui --features detailed-tools".into());
|
||||
activity.output_preview = Some("tool output that becomes several wrapped detail lines".into());
|
||||
activity.summary = Some("completed".into());
|
||||
app.push_convo(ConvoBlock::Tool(Box::new(ToolItem {
|
||||
activity,
|
||||
expanded: false,
|
||||
details_toggled: false,
|
||||
waited_on_user_ms: 0,
|
||||
})));
|
||||
app.push_convo(ConvoBlock::Assistant("anchored assistant reply".into()));
|
||||
for index in 0..6 {
|
||||
app.push_convo(ConvoBlock::System(format!("trailing item {index}")));
|
||||
}
|
||||
let anchor_id = app.convo[1].id.clone();
|
||||
app.selected_block = Some(1);
|
||||
|
||||
render_app(&mut app, &backend);
|
||||
// The tool renders as a padded band (top pad, line, bottom pad) and the assistant adds a
|
||||
// leading gap, so its first line sits at index 3.
|
||||
app.scroll_state.offset = 3;
|
||||
app.scroll_state.follow = false;
|
||||
app.conversation_anchor = None;
|
||||
render_app(&mut app, &backend);
|
||||
let before = app.conversation_anchor.clone().expect("assistant anchor before expansion");
|
||||
assert_eq!(before.item_id, anchor_id);
|
||||
|
||||
let ConvoBlock::Tool(tool) = app.convo[0].block_mut() else {
|
||||
panic!("first item must be a tool");
|
||||
};
|
||||
tool.expanded = true;
|
||||
render_app(&mut app, &backend);
|
||||
|
||||
let after = app.conversation_anchor.as_ref().expect("assistant anchor after expansion");
|
||||
assert_eq!(after.item_id, anchor_id);
|
||||
assert_eq!(after.screen_row, before.screen_row);
|
||||
assert_eq!(app.selected_block, Some(1));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn expanding_a_tool_below_the_viewport_preserves_anchor_and_selection() {
|
||||
let backend = test_backend(60, 10);
|
||||
let mut app = create_app();
|
||||
app.push_convo(ConvoBlock::Assistant("anchored assistant reply".into()));
|
||||
for index in 0..6 {
|
||||
app.push_convo(ConvoBlock::System(format!("middle item {index}")));
|
||||
}
|
||||
let mut activity = ToolActivity::running("session-a", "call-b", "bash", "cargo test", 1);
|
||||
activity.input_preview = Some("--package luxe-tui --features detailed-tools".into());
|
||||
activity.output_preview = Some("tool output that becomes several wrapped detail lines".into());
|
||||
activity.summary = Some("completed".into());
|
||||
app.push_convo(ConvoBlock::Tool(Box::new(ToolItem {
|
||||
activity,
|
||||
expanded: false,
|
||||
details_toggled: false,
|
||||
waited_on_user_ms: 0,
|
||||
})));
|
||||
let anchor_id = app.convo[0].id.clone();
|
||||
let tool_index = app.convo.len() - 1;
|
||||
app.selected_block = Some(0);
|
||||
|
||||
render_app(&mut app, &backend);
|
||||
app.scroll_state.offset = 0;
|
||||
app.scroll_state.follow = false;
|
||||
app.conversation_anchor = None;
|
||||
render_app(&mut app, &backend);
|
||||
let before = app.conversation_anchor.clone().expect("assistant anchor before expansion");
|
||||
assert_eq!(before.item_id, anchor_id);
|
||||
|
||||
let ConvoBlock::Tool(tool) = app.convo[tool_index].block_mut() else {
|
||||
panic!("last item must be a tool");
|
||||
};
|
||||
tool.expanded = true;
|
||||
render_app(&mut app, &backend);
|
||||
|
||||
let after = app.conversation_anchor.as_ref().expect("assistant anchor after expansion");
|
||||
assert_eq!(after.item_id, anchor_id);
|
||||
assert_eq!(after.screen_row, before.screen_row);
|
||||
assert_eq!(app.selected_block, Some(0));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn successful_tool_groups_collapse_and_restore_member_order() {
|
||||
// The run the message asked for is what folds, so a card carries the place it was promised.
|
||||
fn succeeded(call_id: &str, label: &str, index: u32) -> ToolItem {
|
||||
let mut activity = ToolActivity::running("session-a", call_id, "read", label, 1);
|
||||
activity.state = ToolActivityState::Succeeded;
|
||||
activity.summary = Some("Completed".into());
|
||||
activity.run = Some(luxe_core::ToolRun { index, total: 4 });
|
||||
ToolItem { activity, expanded: false, details_toggled: false, waited_on_user_ms: 0 }
|
||||
}
|
||||
|
||||
let backend = test_backend(80, 20);
|
||||
let mut app = create_app();
|
||||
for (index, (call_id, label)) in
|
||||
[("call-a", "first.rs"), ("call-b", "second.rs"), ("call-c", "third.rs")]
|
||||
.into_iter()
|
||||
.enumerate()
|
||||
{
|
||||
let index = u32::try_from(index).unwrap() + 1;
|
||||
app.push_convo(ConvoBlock::Tool(Box::new(succeeded(call_id, label, index))));
|
||||
}
|
||||
let mut failed = succeeded("call-failed", "failure.rs", 4);
|
||||
failed.activity.state = ToolActivityState::Failed;
|
||||
failed.activity.summary = Some("validation failed".into());
|
||||
app.push_convo(ConvoBlock::Tool(Box::new(failed)));
|
||||
|
||||
let collapsed = buffer_to_string(&render_app(&mut app, &backend));
|
||||
assert!(collapsed.contains("3 read calls"), "missing collapsed group: {collapsed}");
|
||||
// Listed by name under the count, but as a list: no member draws its own card header
|
||||
let listed: Vec<&str> = collapsed.lines().filter(|line| line.contains("first.rs")).collect();
|
||||
assert_eq!(listed.len(), 1, "the run lists each member once: {collapsed}");
|
||||
assert!(!listed[0].contains("read"), "and not as a card of its own: {collapsed}");
|
||||
let order = ["first.rs", "second.rs", "third.rs"].map(|name| collapsed.find(name));
|
||||
assert!(order.windows(2).all(|pair| pair[0] < pair[1]), "in order: {collapsed}");
|
||||
assert!(collapsed.contains("failure.rs"), "failure must remain standalone: {collapsed}");
|
||||
|
||||
app.selected_block = Some(1);
|
||||
assert!(app.toggle_selected_tool_details());
|
||||
let expanded = buffer_to_string(&render_app(&mut app, &backend));
|
||||
assert!(!expanded.contains("3 read calls"), "opened into its cards: {expanded}");
|
||||
let first = expanded.find("first.rs").expect("first group member");
|
||||
let second = expanded.find("second.rs").expect("second group member");
|
||||
let third = expanded.find("third.rs").expect("third group member");
|
||||
assert!(first < second && second < third, "group member order changed: {expanded}");
|
||||
assert!(expanded.contains("failure.rs"), "failure must remain standalone: {expanded}");
|
||||
}
|
||||
|
||||
/// Test rendering with an error state.
|
||||
#[test]
|
||||
fn test_render_with_error() {
|
||||
let backend = test_backend(80, 24);
|
||||
let mut app = create_app();
|
||||
|
||||
let mut item = card_with_arguments("bash", "ls", serde_json::json!({"command": "ls"}));
|
||||
item.activity.state = ToolActivityState::Failed;
|
||||
item.activity.summary = Some("Something went wrong".into());
|
||||
app.push_convo(ConvoBlock::Tool(Box::new(item)));
|
||||
|
||||
let rendered = buffer_to_string(&render_app(&mut app, &backend));
|
||||
assert!(rendered.contains("Something went wrong"), "failure missing: {rendered}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn long_conversation_content_wraps_to_the_visible_width() {
|
||||
let (width, height) = (32, 16);
|
||||
let backend = test_backend(width, height);
|
||||
let mut app = create_app();
|
||||
app.push_convo(ConvoBlock::System(
|
||||
"provider error: this deliberately long message must remain inside the conversation pane END"
|
||||
.to_string(),
|
||||
));
|
||||
|
||||
let buffer = render_app(&mut app, &backend);
|
||||
let rows = (0..height).map(|y| row_text(&buffer, y, width)).collect::<Vec<_>>();
|
||||
let start = rows.iter().position(|row| row.contains("provider error"));
|
||||
let end = rows.iter().position(|row| row.contains("END"));
|
||||
|
||||
assert!(start.is_some(), "wrapped message start is missing: {rows:?}");
|
||||
assert!(end.is_some(), "wrapped message tail was clipped: {rows:?}");
|
||||
assert!(end > start, "long content should occupy more than one row: {rows:?}");
|
||||
assert!(app.scroll_state.total >= 3);
|
||||
}
|
||||
|
||||
/// A system message is drawn as written.
|
||||
#[test]
|
||||
fn a_system_message_is_drawn_as_written() {
|
||||
let backend = test_backend(80, 24);
|
||||
let mut app = create_app();
|
||||
app.push_convo(ConvoBlock::System("Starting session...".to_string()));
|
||||
|
||||
let rendered = buffer_to_string(&render_app(&mut app, &backend));
|
||||
|
||||
assert!(rendered.contains("Starting session..."), "the notice is missing: {rendered}");
|
||||
}
|
||||
|
||||
/// The statusline names the model it was given.
|
||||
#[test]
|
||||
fn the_statusline_names_the_model() {
|
||||
let backend = test_backend(80, 24);
|
||||
let mut app = create_app();
|
||||
app.status.model = "gpt-4".to_string();
|
||||
app.status.context_pct = 50.0;
|
||||
app.status.state = luxe_tui::app::AppState::Idle;
|
||||
|
||||
let rendered = buffer_to_string(&render_app(&mut app, &backend));
|
||||
|
||||
assert!(rendered.contains("gpt-4"), "the model is missing: {rendered}");
|
||||
}
|
||||
|
||||
/// What is typed shows in the composer.
|
||||
#[test]
|
||||
fn typed_text_shows_in_the_composer() {
|
||||
let backend = test_backend(80, 24);
|
||||
let mut app = create_app();
|
||||
app.editor.insert_text("Hello, world!");
|
||||
|
||||
let rendered = buffer_to_string(&render_app(&mut app, &backend));
|
||||
|
||||
assert!(rendered.contains("Hello, world!"), "the draft is missing: {rendered}");
|
||||
}
|
||||
Reference in New Issue
Block a user