Consolidate TUI tests and prune snapshots (#64232)

## What changed

- Use table-driven tests for Markdown file links, credit display, and text
  truncation so related cases share setup and assertions.
- Combine checks for history search deduplication and boundaries, Vim cursor
  movement with arrow keys and `hjkl`, and status-line previews that mix runtime
  values with placeholders.
- Remove standalone tests and snapshots, including the Windows paused-goal
  footer snapshot, while retaining the test that checks Esc pauses the goal.

GitOrigin-RevId: b508e7d46e81451186b04d4d9e9d3557596e04c3
This commit is contained in:
Eric Traut
2026-11-26 22:54:05 +00:00
committed by copyberry
parent 588439645d
commit b9e830fb98
26 changed files with 82 additions and 891 deletions
-18
View File
@@ -2332,24 +2332,6 @@ impl App {
mod tests {
use super::*;
#[test]
fn terminal_thread_read_error_detection_matches_not_loaded_errors() {
let err = color_eyre::eyre::eyre!(
"thread/read failed during TUI session lookup: thread/read failed: thread not loaded: thr_123"
);
assert!(App::is_terminal_thread_read_error(&err));
}
#[test]
fn terminal_thread_read_error_detection_ignores_transient_failures() {
let err = color_eyre::eyre::eyre!(
"thread/read failed during TUI session lookup: thread/read transport error: broken pipe"
);
assert!(!App::is_terminal_thread_read_error(&err));
}
#[test]
fn closed_state_for_thread_read_error_preserves_live_state_without_cache_on_transient_error() {
let err = color_eyre::eyre::eyre!(
+1 -16
View File
@@ -488,21 +488,6 @@ mod tests {
rendered.join("\n")
}
#[test]
fn skill_load_warning_state_suppresses_repeated_active_errors() {
let mut state = SkillLoadWarningState::default();
let error = skill_error("/repo/.codex/skills/abc/SKILL.md", "invalid description");
assert_eq!(
state.newly_active_errors(std::slice::from_ref(&error)),
vec![error.clone()]
);
assert_eq!(
state.newly_active_errors(std::slice::from_ref(&error)),
Vec::<SkillErrorInfo>::new()
);
}
#[test]
fn skill_load_warning_state_reemits_after_error_clears() {
let mut state = SkillLoadWarningState::default();
@@ -536,7 +521,7 @@ mod tests {
}
#[test]
fn skill_load_warning_state_clear_allows_active_error_again() {
fn skill_load_warnings_suppress_repeats_until_cleared() {
let mut state = SkillLoadWarningState::default();
let error = skill_error("/repo/.codex/skills/abc/SKILL.md", "invalid description");
@@ -1196,13 +1196,15 @@ mod tests {
}
#[test]
fn search_matches_local_history_and_stops_at_boundaries() {
fn local_history_search_skips_duplicates_and_stops_at_boundaries() {
let (tx, _rx) = unbounded_channel::<AppEvent>();
let tx = AppEventSender::new(tx);
let mut history = ChatComposerHistory::new();
history.record_local_submission(HistoryEntry::new("git status".to_string()));
history.record_local_submission(HistoryEntry::new("cargo test -p codex-tui".to_string()));
history.record_local_submission(HistoryEntry::new("git status".to_string()));
history.record_local_submission(HistoryEntry::new("cargo fmt".to_string()));
history.record_local_submission(HistoryEntry::new("git diff".to_string()));
assert_eq!(
@@ -1259,55 +1261,6 @@ mod tests {
&tx
)
);
}
#[test]
fn search_skips_duplicate_local_matches() {
let (tx, _rx) = unbounded_channel::<AppEvent>();
let tx = AppEventSender::new(tx);
let mut history = ChatComposerHistory::new();
history.record_local_submission(HistoryEntry::new("git status".to_string()));
history.record_local_submission(HistoryEntry::new("cargo test -p codex-tui".to_string()));
history.record_local_submission(HistoryEntry::new("git status".to_string()));
history.record_local_submission(HistoryEntry::new("git diff".to_string()));
assert_eq!(
HistorySearchResult::Found(HistoryEntry::new("git diff".to_string())),
history.search(
"git",
HistorySearchDirection::Older,
/*restart*/ true,
&tx
)
);
assert_eq!(
HistorySearchResult::Found(HistoryEntry::new("git status".to_string())),
history.search(
"git",
HistorySearchDirection::Older,
/*restart*/ false,
&tx
)
);
assert_eq!(
HistorySearchResult::AtBoundary,
history.search(
"git",
HistorySearchDirection::Older,
/*restart*/ false,
&tx
)
);
assert_eq!(
HistorySearchResult::Found(HistoryEntry::new("git diff".to_string())),
history.search(
"git",
HistorySearchDirection::Newer,
/*restart*/ false,
&tx
)
);
assert_eq!(
HistorySearchResult::Found(HistoryEntry::new("git status".to_string())),
history.search(
@@ -1,17 +0,0 @@
---
source: tui/src/bottom_pane/feedback_view.rs
expression: rendered
---
Do you want to upload logs before reporting issue?
Logs may include the full conversation history of this Codex process
These logs are retained for 90 days and are used solely for troubles
You can review the exact content of the logs before they’re uploaded
<LOG_PATH>
› 1. Yes Share the current Codex session logs and diagnostics with the team
for troubleshooting.
2. No
3. Cancel
@@ -1,5 +0,0 @@
---
source: tui/src/bottom_pane/footer.rs
expression: terminal.backend()
---
" Italic text "
@@ -1,5 +0,0 @@
---
source: tui/src/bottom_pane/mod.rs
expression: "render_snapshot(&pane, area1)"
---
› Ask Codex to do a
+11 -122
View File
@@ -462,7 +462,6 @@ mod tests {
use super::*;
use crate::app_event_sender::AppEventSender;
use crate::bottom_pane::multi_select_picker::tests::render_lines;
use crate::terminal_hyperlinks::HyperlinkLine;
use insta::assert_snapshot;
use pretty_assertions::assert_eq;
use tokio::sync::mpsc::unbounded_channel;
@@ -603,93 +602,7 @@ mod tests {
}
#[test]
fn preview_uses_runtime_values() {
let preview_data = StatusSurfacePreviewData::from_iter([
(
StatusLineItem::ModelName.preview_item(),
"gpt-5".to_string(),
),
(
StatusLineItem::CurrentDir.preview_item(),
"/repo".to_string(),
),
]);
let items = [
MultiSelectItem {
id: StatusLineItem::ModelName.to_string(),
name: String::new(),
description: None,
enabled: true,
orderable: true,
section_break_after: false,
on_activate: None,
},
MultiSelectItem {
id: StatusLineItem::CurrentDir.to_string(),
name: String::new(),
description: None,
enabled: true,
orderable: true,
section_break_after: false,
on_activate: None,
},
];
assert_eq!(
line_text(
preview_data.status_line_for_items(
items
.iter()
.filter_map(|item| item.id.parse::<StatusLineItem>().ok()),
/*use_theme_colors*/ true,
)
),
Some("gpt-5 · /repo".to_string())
);
}
#[test]
fn preview_uses_placeholders_when_runtime_values_are_missing() {
let preview_data = StatusSurfacePreviewData::from_iter([(
StatusSurfacePreviewItem::Model,
"gpt-5".to_string(),
)]);
let items = [
MultiSelectItem {
id: StatusLineItem::ModelName.to_string(),
name: String::new(),
description: None,
enabled: true,
orderable: true,
section_break_after: false,
on_activate: None,
},
MultiSelectItem {
id: StatusLineItem::GitBranch.to_string(),
name: String::new(),
description: None,
enabled: true,
orderable: true,
section_break_after: false,
on_activate: None,
},
];
assert_eq!(
line_text(
preview_data.status_line_for_items(
items
.iter()
.filter_map(|item| item.id.parse::<StatusLineItem>().ok()),
/*use_theme_colors*/ true,
)
),
Some("gpt-5 · feat/awesome-feature".to_string())
);
}
#[test]
fn preview_includes_thread_title() {
fn preview_fills_missing_runtime_values_with_placeholders() {
let preview_data = StatusSurfacePreviewData::from_iter([
(
StatusLineItem::ModelName.preview_item(),
@@ -700,37 +613,17 @@ mod tests {
"Roadmap cleanup".to_string(),
),
]);
let items = [
MultiSelectItem {
id: StatusLineItem::ModelName.to_string(),
name: String::new(),
description: None,
enabled: true,
orderable: true,
section_break_after: false,
on_activate: None,
},
MultiSelectItem {
id: StatusLineItem::ThreadTitle.to_string(),
name: String::new(),
description: None,
enabled: true,
orderable: true,
section_break_after: false,
on_activate: None,
},
];
let preview = preview_data.status_line_for_items(
[
StatusLineItem::ModelName,
StatusLineItem::GitBranch,
StatusLineItem::ThreadTitle,
],
/*use_theme_colors*/ true,
);
assert_eq!(
line_text(
preview_data.status_line_for_items(
items
.iter()
.filter_map(|item| item.id.parse::<StatusLineItem>().ok()),
/*use_theme_colors*/ true,
)
),
Some("gpt-5 · Roadmap cleanup".to_string())
preview.unwrap().line.to_string(),
"gpt-5 · feat/awesome-feature · Roadmap cleanup"
);
}
@@ -857,8 +750,4 @@ mod tests {
.join("\n")
);
}
fn line_text(content: Option<HyperlinkLine>) -> Option<String> {
content.map(|line| line.line.to_string())
}
}
+14 -12
View File
@@ -2639,22 +2639,24 @@ mod tests {
}
#[test]
fn vim_normal_arrow_keys_move_cursor() {
fn vim_normal_arrows_and_hjkl_move_cursor() {
let mut t = ta_with("ab\ncd");
t.set_cursor(/*pos*/ 1);
t.set_vim_enabled(/*enabled*/ true);
t.input(KeyEvent::new(KeyCode::Right, KeyModifiers::NONE));
assert_eq!(t.cursor(), 2);
t.input(KeyEvent::new(KeyCode::Down, KeyModifiers::NONE));
assert_eq!(t.cursor(), 5);
t.input(KeyEvent::new(KeyCode::Left, KeyModifiers::NONE));
assert_eq!(t.cursor(), 4);
t.input(KeyEvent::new(KeyCode::Up, KeyModifiers::NONE));
assert_eq!(t.cursor(), 1);
for (key, cursor) in [
(KeyCode::Right, 2),
(KeyCode::Down, 5),
(KeyCode::Left, 4),
(KeyCode::Up, 1),
(KeyCode::Char('l'), 2),
(KeyCode::Char('j'), 5),
(KeyCode::Char('h'), 4),
(KeyCode::Char('k'), 1),
] {
t.input(KeyEvent::new(key, KeyModifiers::NONE));
assert_eq!(t.cursor(), cursor, "{key:?}");
}
}
#[test]
@@ -1,12 +0,0 @@
---
source: tui/src/chatwidget/tests/status_and_layout.rs
expression: snapshot
---
" "
"• Working (0s • esc to interrupt) "
" "
" "
"› Ask Codex to do anything "
" "
" GPT-5.6-Sol default · /tmp/project "
" ? for shortcuts Goal paused (/goal resume) "
@@ -2609,11 +2609,6 @@ async fn esc_interrupt_pauses_active_goal_turn() {
.draw(|f| chat.render(f.area(), f.buffer_mut()))
.expect("draw goal paused footer");
let snapshot = normalized_backend_snapshot(terminal.backend());
#[cfg(target_os = "windows")]
insta::with_settings!({ snapshot_suffix => "windows" }, {
assert_chatwidget_snapshot!("esc_interrupt_goal_paused_footer", snapshot);
});
#[cfg(not(target_os = "windows"))]
assert_chatwidget_snapshot!("esc_interrupt_goal_paused_footer", snapshot);
}
-18
View File
@@ -700,24 +700,6 @@ fn ps_output_empty_snapshot() {
insta::assert_snapshot!(rendered);
}
#[tokio::test]
async fn session_info_uses_availability_nux_tooltip_override() {
let config = test_config().await;
let cell = new_session_info(
&config,
&crate::local_settings::LocalSettings::from(&config),
"gpt-5",
"gpt-5",
&session_configured_event("gpt-5"),
/*is_first_event*/ false,
Some("Model just became available".to_string()),
Some(PlanType::Free),
);
let rendered = render_transcript(&cell).join("\n");
assert!(rendered.contains("Model just became available"));
}
#[tokio::test]
async fn session_info_availability_nux_tooltip_snapshot() {
let config = test_config().await;
-120
View File
@@ -3914,47 +3914,6 @@ mod tests {
expect_conflict(&keymap, "motion_left", "select_inner_text_object");
}
#[test]
fn vim_normal_defaults_include_insert_and_arrow_aliases() {
let runtime = RuntimeKeymap::defaults();
assert_eq!(
runtime.vim_normal.enter_insert,
vec![
key_hint::plain(KeyCode::Char('i')),
key_hint::plain(KeyCode::Insert)
]
);
assert_eq!(
runtime.vim_normal.move_left,
vec![
key_hint::plain(KeyCode::Char('h')),
key_hint::plain(KeyCode::Left)
]
);
assert_eq!(
runtime.vim_normal.move_right,
vec![
key_hint::plain(KeyCode::Char('l')),
key_hint::plain(KeyCode::Right)
]
);
assert_eq!(
runtime.vim_normal.move_up,
vec![
key_hint::plain(KeyCode::Char('k')),
key_hint::plain(KeyCode::Up)
]
);
assert_eq!(
runtime.vim_normal.move_down,
vec![
key_hint::plain(KeyCode::Char('j')),
key_hint::plain(KeyCode::Down)
]
);
}
#[test]
fn invalid_global_copy_binding_reports_global_path() {
let mut keymap = TuiKeymap::default();
@@ -4566,85 +4525,6 @@ mod tests {
);
}
#[test]
fn default_editor_delete_forward_word_includes_alt_d() {
let runtime = RuntimeKeymap::defaults();
assert!(
runtime
.editor
.delete_forward_word
.contains(&key_hint::alt(KeyCode::Char('d')))
);
}
#[test]
fn default_editor_deletion_includes_modified_backspace_delete_aliases() {
let runtime = RuntimeKeymap::defaults();
assert!(
runtime
.editor
.delete_backward
.contains(&key_hint::shift(KeyCode::Backspace))
);
assert!(
runtime
.editor
.delete_forward
.contains(&key_hint::shift(KeyCode::Delete))
);
assert!(
runtime
.editor
.delete_backward_word
.contains(&key_hint::ctrl(KeyCode::Backspace))
);
assert!(
runtime
.editor
.delete_backward_word
.contains(&KeyBinding::new(
KeyCode::Backspace,
KeyModifiers::CONTROL | KeyModifiers::SHIFT
))
);
assert!(
runtime
.editor
.delete_forward_word
.contains(&key_hint::ctrl(KeyCode::Delete))
);
assert!(
runtime
.editor
.delete_forward_word
.contains(&KeyBinding::new(
KeyCode::Delete,
KeyModifiers::CONTROL | KeyModifiers::SHIFT
))
);
}
#[test]
fn default_composer_toggle_shortcuts_includes_shift_question_mark() {
let runtime = RuntimeKeymap::defaults();
assert!(
runtime
.composer
.toggle_shortcuts
.contains(&key_hint::shift(KeyCode::Char('?')))
);
}
#[test]
fn default_approval_open_fullscreen_includes_ctrl_shift_a() {
let runtime = RuntimeKeymap::defaults();
assert!(runtime.approval.open_fullscreen.contains(&KeyBinding::new(
KeyCode::Char('a'),
KeyModifiers::CONTROL | KeyModifiers::SHIFT
)));
}
#[test]
fn primary_binding_returns_first_or_none() {
let bindings = vec![
-13
View File
@@ -1382,19 +1382,6 @@ mod tests {
);
}
#[test]
fn picker_narrow_uses_compact_tabs() {
let runtime = RuntimeKeymap::defaults();
let params = build_keymap_picker_params(&runtime, &TuiKeymap::default());
let rendered = render_picker(params, /*width*/ 78);
assert!(rendered.contains("Keymap"));
assert!(rendered.contains("Open Transcript"));
assert!(rendered.contains("ctrl-t"));
assert!(!rendered.contains("Selected Action"));
assert!(!rendered.contains("Source: default keymap"));
}
#[test]
fn action_menu_content_snapshot() {
let unbound_keymap = keymap_with_bindings(&TuiKeymap::default(), "global", "copy", &[])
+23 -123
View File
@@ -1129,21 +1129,29 @@ fn file_link_keeps_unrelated_relative_label_with_matching_suffix() {
}
#[test]
fn file_link_appends_line_number_when_label_lacks_it() {
let text = render_markdown_text_for_cwd(
"[markdown_render.rs](/Users/example/code/codex/codex-rs/tui/src/markdown_render.rs:74)",
Path::new("/Users/example/code/codex"),
);
let expected = Text::from(Line::from_iter([
"markdown_render.rs".into(),
" (".into(),
Span::styled(
"codex-rs/tui/src/markdown_render.rs:74",
MarkdownStyles::default().code,
),
")".into(),
]));
assert_eq!(text, expected);
fn file_link_preserves_the_label_and_formats_the_target_location() {
let point = "file:///repo/src/lib.rs#L74C3";
let range = "/repo/src/lib.rs:74:3-76:9";
let hash_range = "file:///repo/src/lib.rs#L74C3-L76C9";
for (label, target, location) in [
("lib.rs", "/repo/src/lib.rs:74", "src/lib.rs:74"),
("lib.rs", point, "src/lib.rs:74:3"),
("lib.rs#L74C3", point, "src/lib.rs:74:3"),
("lib.rs", range, "src/lib.rs:74:3-76:9"),
("lib.rs:74:3-76:9", range, "src/lib.rs:74:3-76:9"),
("lib.rs", hash_range, "src/lib.rs:74:3-76:9"),
("lib.rs#L74C3-L76C9", hash_range, "src/lib.rs:74:3-76:9"),
] {
let markdown = format!("[{label}]({target})");
let text = render_markdown_text_for_cwd(&markdown, Path::new("/repo"));
let expected = Text::from(Line::from_iter([
label.into(),
" (".into(),
Span::styled(location, MarkdownStyles::default().code),
")".into(),
]));
assert_eq!(text, expected, "{markdown}");
}
}
#[test]
@@ -1190,96 +1198,6 @@ fn file_links_preserve_foreign_windows_paths_and_anchors_snapshot() {
");
}
#[test]
fn file_link_appends_hash_anchor_when_label_lacks_it() {
let text = render_markdown_text_for_cwd(
"[markdown_render.rs](file:///Users/example/code/codex/codex-rs/tui/src/markdown_render.rs#L74C3)",
Path::new("/Users/example/code/codex"),
);
let expected = Text::from(Line::from_iter([
"markdown_render.rs".into(),
" (".into(),
Span::styled(
"codex-rs/tui/src/markdown_render.rs:74:3",
MarkdownStyles::default().code,
),
")".into(),
]));
assert_eq!(text, expected);
}
#[test]
fn file_link_uses_target_path_for_hash_anchor() {
let text = render_markdown_text_for_cwd(
"[markdown_render.rs#L74C3](file:///Users/example/code/codex/codex-rs/tui/src/markdown_render.rs#L74C3)",
Path::new("/Users/example/code/codex"),
);
let expected = Text::from(Line::from_iter([
"markdown_render.rs#L74C3".into(),
" (".into(),
Span::styled(
"codex-rs/tui/src/markdown_render.rs:74:3",
MarkdownStyles::default().code,
),
")".into(),
]));
assert_eq!(text, expected);
}
#[test]
fn file_link_appends_range_when_label_lacks_it() {
let text = render_markdown_text_for_cwd(
"[markdown_render.rs](/Users/example/code/codex/codex-rs/tui/src/markdown_render.rs:74:3-76:9)",
Path::new("/Users/example/code/codex"),
);
let expected = Text::from(Line::from_iter([
"markdown_render.rs".into(),
" (".into(),
Span::styled(
"codex-rs/tui/src/markdown_render.rs:74:3-76:9",
MarkdownStyles::default().code,
),
")".into(),
]));
assert_eq!(text, expected);
}
#[test]
fn file_link_uses_target_path_for_range() {
let text = render_markdown_text_for_cwd(
"[markdown_render.rs:74:3-76:9](/Users/example/code/codex/codex-rs/tui/src/markdown_render.rs:74:3-76:9)",
Path::new("/Users/example/code/codex"),
);
let expected = Text::from(Line::from_iter([
"markdown_render.rs:74:3-76:9".into(),
" (".into(),
Span::styled(
"codex-rs/tui/src/markdown_render.rs:74:3-76:9",
MarkdownStyles::default().code,
),
")".into(),
]));
assert_eq!(text, expected);
}
#[test]
fn file_link_appends_hash_range_when_label_lacks_it() {
let text = render_markdown_text_for_cwd(
"[markdown_render.rs](file:///Users/example/code/codex/codex-rs/tui/src/markdown_render.rs#L74C3-L76C9)",
Path::new("/Users/example/code/codex"),
);
let expected = Text::from(Line::from_iter([
"markdown_render.rs".into(),
" (".into(),
Span::styled(
"codex-rs/tui/src/markdown_render.rs:74:3-76:9",
MarkdownStyles::default().code,
),
")".into(),
]));
assert_eq!(text, expected);
}
#[test]
fn multiline_file_link_label_after_styled_prefix_does_not_panic() {
set_syntax_theme(syntect::highlighting::Theme::default());
@@ -1303,24 +1221,6 @@ fn multiline_file_link_label_after_styled_prefix_does_not_panic() {
assert_eq!(text, expected);
}
#[test]
fn file_link_uses_target_path_for_hash_range() {
let text = render_markdown_text_for_cwd(
"[markdown_render.rs#L74C3-L76C9](file:///Users/example/code/codex/codex-rs/tui/src/markdown_render.rs#L74C3-L76C9)",
Path::new("/Users/example/code/codex"),
);
let expected = Text::from(Line::from_iter([
"markdown_render.rs#L74C3-L76C9".into(),
" (".into(),
Span::styled(
"codex-rs/tui/src/markdown_render.rs:74:3-76:9",
MarkdownStyles::default().code,
),
")".into(),
]));
assert_eq!(text, expected);
}
#[test]
fn url_link_shows_destination() {
set_syntax_theme(syntect::highlighting::Theme::default());
@@ -1,15 +0,0 @@
---
source: tui/src/diff_render.rs
assertion_line: 765
expression: terminal.backend()
---
"• Proposed Change README.md (+2 -0) "
" 1 +first line "
" 2 +second line "
" "
" "
" "
" "
" "
" "
" "
@@ -1,15 +0,0 @@
---
source: tui/src/diff_render.rs
assertion_line: 765
expression: terminal.backend()
---
"• Proposed Change example.txt (+1 -1) "
" 1 "
" 2 -Y "
" 2 +Y changed "
" "
" "
" "
" "
" "
" "
@@ -1,13 +0,0 @@
---
source: tui/src/diff_render.rs
assertion_line: 765
expression: terminal.backend()
---
"• Proposed Change README.md (+1 -1) "
" 1 -# Codex CLI (Rust Implementation) "
" 1 +# Codex CLI (Rust Implementation) banana "
" "
" "
" "
" "
" "
@@ -1,17 +0,0 @@
---
source: tui/src/diff_render.rs
assertion_line: 765
expression: terminal.backend()
---
"• Proposed Change src/lib.rs → src/lib_new.rs (+1 -1) "
" 1 line one "
" 2 -line two "
" 2 +line two changed "
" 3 line three "
" "
" "
" "
" "
" "
" "
" "
@@ -1,21 +0,0 @@
---
source: tui/src/diff_render.rs
assertion_line: 765
expression: terminal.backend()
---
"• Proposed Change example.txt (+2 -2) "
" 1 line 1 "
" 2 -line 2 "
" 2 +line two changed "
" 3 line 3 "
" 4 line 4 "
" 5 line 5 "
" ⋮ "
" 6 line 6 "
" 7 line 7 "
" 8 line 8 "
" 9 -line 9 "
" 9 +line nine changed "
" 10 line 10 "
" "
" "
@@ -1,13 +0,0 @@
---
source: tui/src/resume_picker.rs
expression: snapshot
---
Resume a previous session Sort: Created at
Type to search
Created at Updated at Branch CWD Conversation
No sessions yet
enter to resume esc to start new ctrl + c to quit tab to toggle sort
@@ -1,7 +0,0 @@
---
source: tui/src/resume_picker.rs
expression: snapshot
---
Created Updated Branch CWD Conversation
> - 2 days ago - - Keep this for now
- 3 days ago - - Named thread
@@ -1,12 +0,0 @@
---
source: tui/src/status_indicator_widget.rs
expression: terminal.backend()
---
"• Working (0s • esc to interrupt) "
" "
" ↳ first "
" ↳ second "
" alt + ↑ edit "
" "
" "
" "
@@ -1,13 +0,0 @@
---
source: tui/src/status_indicator_widget.rs
assertion_line: 289
expression: terminal.backend()
---
"• Working (0s • esc to interrupt) "
" "
" ↳ first "
" ↳ second "
" ⌥ + ↑ edit "
" "
" "
" "
+16 -171
View File
@@ -1245,113 +1245,7 @@ async fn status_snapshot_uses_generic_limit_labels_for_unsupported_windows() {
}
#[tokio::test]
async fn status_snapshot_shows_unlimited_credits() {
let temp_home = TempDir::new().expect("temp home");
let config = test_config(&temp_home).await;
let account_display = test_status_account_display();
let usage = TokenUsage::default();
let captured_at = chrono::Local
.with_ymd_and_hms(2024, 2, 3, 4, 5, 6)
.single()
.expect("timestamp");
let snapshot = RateLimitSnapshot {
limit_id: None,
limit_name: None,
normal_model_slug: None,
primary: None,
secondary: None,
credits: Some(CreditsSnapshot {
has_credits: true,
unlimited: true,
balance: None,
}),
individual_limit: None,
spend_control_reached: None,
plan_type: None,
rate_limit_reached_type: None,
};
let rate_display = rate_limit_snapshot_display(&snapshot, captured_at);
let model_slug = get_model_offline_for_tests(config.model.as_deref());
let token_info = token_info_for(&model_slug, &config, &usage);
let composite = new_status_output(
&config,
account_display.as_ref(),
Some(&token_info),
&usage,
&None,
/*thread_name*/ None,
/*forked_from*/ None,
Some(&rate_display),
/*quota_plan*/ None,
captured_at,
&model_slug,
/*collaboration_mode*/ None,
/*reasoning_effort_override*/ None,
);
let rendered = render_lines(&composite.display_lines(/*width*/ 120));
assert!(
rendered
.iter()
.any(|line| line.contains("Credits:") && line.contains("Unlimited")),
"expected Credits: Unlimited line, got {rendered:?}"
);
}
#[tokio::test]
async fn status_snapshot_shows_positive_credits() {
let temp_home = TempDir::new().expect("temp home");
let config = test_config(&temp_home).await;
let account_display = test_status_account_display();
let usage = TokenUsage::default();
let captured_at = chrono::Local
.with_ymd_and_hms(2024, 3, 4, 5, 6, 7)
.single()
.expect("timestamp");
let snapshot = RateLimitSnapshot {
limit_id: None,
limit_name: None,
normal_model_slug: None,
primary: None,
secondary: None,
credits: Some(CreditsSnapshot {
has_credits: true,
unlimited: false,
balance: Some("12.5".to_string()),
}),
individual_limit: None,
spend_control_reached: None,
plan_type: None,
rate_limit_reached_type: None,
};
let rate_display = rate_limit_snapshot_display(&snapshot, captured_at);
let model_slug = get_model_offline_for_tests(config.model.as_deref());
let token_info = token_info_for(&model_slug, &config, &usage);
let composite = new_status_output(
&config,
account_display.as_ref(),
Some(&token_info),
&usage,
&None,
/*thread_name*/ None,
/*forked_from*/ None,
Some(&rate_display),
/*quota_plan*/ None,
captured_at,
&model_slug,
/*collaboration_mode*/ None,
/*reasoning_effort_override*/ None,
);
let rendered = render_lines(&composite.display_lines(/*width*/ 120));
assert!(
rendered
.iter()
.any(|line| line.contains("Credits:") && line.contains("13 credits")),
"expected Credits line with rounded credits, got {rendered:?}"
);
}
#[tokio::test]
async fn status_snapshot_shows_available_credits_without_display_balance() {
async fn status_renders_unlimited_rounded_or_available_credits() {
let temp_home = TempDir::new().expect("temp home");
let config = test_config(&temp_home).await;
let account_display = test_status_account_display();
@@ -1362,12 +1256,15 @@ async fn status_snapshot_shows_available_credits_without_display_balance() {
.expect("timestamp");
let model_slug = get_model_offline_for_tests(config.model.as_deref());
let token_info = token_info_for(&model_slug, &config, &usage);
for balance in [
None,
Some(String::new()),
Some("0".to_string()),
Some("not-a-number".to_string()),
Some("inf".to_string()),
for (has_credits, unlimited, balance, expected) in [
(true, true, None, "Unlimited"),
(false, true, None, "Unlimited"),
(true, false, Some("12.5"), "13 credits"),
(true, false, None, "Available"),
(true, false, Some(""), "Available"),
(true, false, Some("0"), "Available"),
(true, false, Some("not-a-number"), "Available"),
(true, false, Some("inf"), "Available"),
] {
let snapshot = RateLimitSnapshot {
limit_id: None,
@@ -1376,9 +1273,9 @@ async fn status_snapshot_shows_available_credits_without_display_balance() {
primary: None,
secondary: None,
credits: Some(CreditsSnapshot {
has_credits: true,
unlimited: false,
balance,
has_credits,
unlimited,
balance: balance.map(str::to_string),
}),
individual_limit: None,
spend_control_reached: None,
@@ -1405,65 +1302,13 @@ async fn status_snapshot_shows_available_credits_without_display_balance() {
assert!(
rendered
.iter()
.any(|line| line.contains("Credits:") && line.contains("Available")),
"expected Credits: Available line, got {rendered:?}"
.any(|line| line.contains("Credits:") && line.contains(expected)),
"expected {expected} for {:?}, got {rendered:?}",
snapshot.credits
);
}
}
#[tokio::test]
async fn status_snapshot_respects_unlimited_without_has_credits_flag() {
let temp_home = TempDir::new().expect("temp home");
let config = test_config(&temp_home).await;
let account_display = test_status_account_display();
let usage = TokenUsage::default();
let captured_at = chrono::Local
.with_ymd_and_hms(2024, 5, 6, 7, 8, 9)
.single()
.expect("timestamp");
let snapshot = RateLimitSnapshot {
limit_id: None,
limit_name: None,
normal_model_slug: None,
primary: None,
secondary: None,
credits: Some(CreditsSnapshot {
has_credits: false,
unlimited: true,
balance: None,
}),
individual_limit: None,
spend_control_reached: None,
plan_type: None,
rate_limit_reached_type: None,
};
let rate_display = rate_limit_snapshot_display(&snapshot, captured_at);
let model_slug = get_model_offline_for_tests(config.model.as_deref());
let token_info = token_info_for(&model_slug, &config, &usage);
let composite = new_status_output(
&config,
account_display.as_ref(),
Some(&token_info),
&usage,
&None,
/*thread_name*/ None,
/*forked_from*/ None,
Some(&rate_display),
/*quota_plan*/ None,
captured_at,
&model_slug,
/*collaboration_mode*/ None,
/*reasoning_effort_override*/ None,
);
let rendered = render_lines(&composite.display_lines(/*width*/ 120));
assert!(
rendered
.iter()
.any(|line| line.contains("Credits:") && line.contains("Unlimited")),
"expected Credits: Unlimited line, got {rendered:?}"
);
}
#[tokio::test]
async fn status_card_token_usage_excludes_cached_tokens() {
let temp_home = TempDir::new().expect("temp home");
+14 -53
View File
@@ -347,59 +347,20 @@ mod tests {
use pretty_assertions::assert_eq;
#[test]
fn test_truncate_text() {
let text = "Hello, world!";
let truncated = truncate_text(text, /*max_graphemes*/ 8);
assert_eq!(truncated, "Hello...");
}
#[test]
fn test_truncate_empty_string() {
let text = "";
let truncated = truncate_text(text, /*max_graphemes*/ 5);
assert_eq!(truncated, "");
}
#[test]
fn test_truncate_max_graphemes_zero() {
let text = "Hello";
let truncated = truncate_text(text, /*max_graphemes*/ 0);
assert_eq!(truncated, "");
}
#[test]
fn test_truncate_max_graphemes_one() {
let text = "Hello";
let truncated = truncate_text(text, /*max_graphemes*/ 1);
assert_eq!(truncated, "H");
}
#[test]
fn test_truncate_max_graphemes_two() {
let text = "Hello";
let truncated = truncate_text(text, /*max_graphemes*/ 2);
assert_eq!(truncated, "He");
}
#[test]
fn test_truncate_max_graphemes_three_boundary() {
let text = "Hello";
let truncated = truncate_text(text, /*max_graphemes*/ 3);
assert_eq!(truncated, "...");
}
#[test]
fn test_truncate_text_shorter_than_limit() {
let text = "Hi";
let truncated = truncate_text(text, /*max_graphemes*/ 10);
assert_eq!(truncated, "Hi");
}
#[test]
fn test_truncate_text_exact_length() {
let text = "Hello";
let truncated = truncate_text(text, /*max_graphemes*/ 5);
assert_eq!(truncated, "Hello");
fn truncate_text_respects_the_grapheme_limit_and_leaves_room_for_ellipsis() {
for (text, limit, expected) in [
("", 5, ""),
("Hello", 0, ""),
("Hello", 1, "H"),
("Hello", 2, "He"),
("Hello", 3, "..."),
("Hello", 5, "Hello"),
("Hi", 10, "Hi"),
("Hello, world!", 8, "Hello..."),
] {
let truncated = truncate_text(text, limit);
assert_eq!(truncated, expected, "{text:?}, limit {limit}");
}
}
#[test]
@@ -1,5 +0,0 @@
---
source: tui/tests/suite/daemon_compatibility.rs
expression: warning
---
⚠ Running without the shared background server: code-mode host fallback policy requires embedded mode.