Skip to content

Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows

fix(select): Make TUI snapshot tests non-flaky

Maximilian Roos42e47ece5bfb
diff --git a/tests/integration_tests/select.rs b/tests/integration_tests/select.rs
index 57d500352..64af5e090 100644
--- a/tests/integration_tests/select.rs
+++ b/tests/integration_tests/select.rs
@@ -4,9 +4,8 @@
//! what the user actually sees on screen, enabling meaningful snapshot testing of
//! the skim-based TUI interface.
//!
-//! **Note:** These tests are marked `#[ignore]` because TUI timing variations cause
-//! flakiness (preview tabs appearing/not appearing, query text partially visible).
-//! Run manually with: `cargo test --test integration select:: -- --ignored`
+//! The tests normalize timing-sensitive parts of the output (query line, count
+//! indicators) to ensure stable snapshots despite TUI rendering variations.
use crate::common::TestRepo;
use insta::assert_snapshot;
@@ -20,14 +19,17 @@ use std::time::Duration;
const TERM_ROWS: u16 = 30;
const TERM_COLS: u16 = 120;
-/// Initial wait for TUI to fully render before sending input
-const TUI_RENDER_DELAY: Duration = Duration::from_millis(800);
+/// Initial wait for TUI to fully render before sending input.
+/// Must be long enough for skim to complete initial render including preview.
+const TUI_RENDER_DELAY: Duration = Duration::from_millis(1500);
-/// Delay between keystrokes to allow TUI to process input
-const KEYSTROKE_DELAY: Duration = Duration::from_millis(150);
+/// Delay between keystrokes to allow TUI to process input.
+/// Each keystroke triggers a re-render, so this must be sufficient.
+const KEYSTROKE_DELAY: Duration = Duration::from_millis(300);
-/// Final delay after last input before capturing screen
-const FINAL_CAPTURE_DELAY: Duration = Duration::from_millis(200);
+/// Final delay after last input before capturing screen.
+/// Ensures the final state is fully rendered.
+const FINAL_CAPTURE_DELAY: Duration = Duration::from_millis(500);
/// Timeout for waiting for process output before killing
const OUTPUT_TIMEOUT: Duration = Duration::from_secs(3);
@@ -190,11 +192,26 @@ fn render_terminal_screen(raw_output: &[u8]) -> String {
result
}
-/// Normalize paths in output for snapshot stability
-fn normalize_paths(output: &str) -> String {
+/// Normalize output for snapshot stability
+fn normalize_output(output: &str) -> String {
+ let mut lines: Vec<&str> = output.lines().collect();
+
+ // Normalize line 1 (query line) - replace with fixed marker
+ // This line shows typed query which has timing variations
+ if !lines.is_empty() {
+ lines[0] =
+ "> [QUERY] │[PREVIEW_HEADER]";
+ }
+
+ let output = lines.join("\n");
+
// Replace temp paths like /var/folders/.../test-repo.XXX with [REPO]
let re = regex::Regex::new(r"/[^\s]+\.tmp[^\s/]*").unwrap();
- let output = re.replace_all(output, "[REPO]");
+ let output = re.replace_all(&output, "[REPO]");
+
+ // Replace count indicators like "1/4", "3/4" etc at end of lines
+ let count_re = regex::Regex::new(r"\d+/\d+$").unwrap();
+ let output = count_re.replace_all(&output, "[N/M]");
// Replace home directory paths
if let Some(home) = home::home_dir() {
@@ -206,7 +223,7 @@ fn normalize_paths(output: &str) -> String {
}
#[test]
-#[ignore]
+
fn test_select_abort_with_escape() {
let repo = TestRepo::new();
repo.commit("Initial commit");
@@ -223,12 +240,12 @@ fn test_select_abort_with_escape() {
assert_valid_abort_exit_code(exit_code);
let screen = render_terminal_screen(&raw_output);
- let normalized = normalize_paths(&screen);
+ let normalized = normalize_output(&screen);
assert_snapshot!("select_abort_escape", normalized);
}
#[test]
-#[ignore]
+
fn test_select_with_multiple_worktrees() {
let mut repo = TestRepo::new();
repo.commit("Initial commit");
@@ -247,12 +264,12 @@ fn test_select_with_multiple_worktrees() {
assert_valid_abort_exit_code(exit_code);
let screen = render_terminal_screen(&raw_output);
- let normalized = normalize_paths(&screen);
+ let normalized = normalize_output(&screen);
assert_snapshot!("select_multiple_worktrees", normalized);
}
#[test]
-#[ignore]
+
fn test_select_with_branches() {
let mut repo = TestRepo::new();
repo.commit("Initial commit");
@@ -276,13 +293,13 @@ fn test_select_with_branches() {
assert_valid_abort_exit_code(exit_code);
let screen = render_terminal_screen(&raw_output);
- let normalized = normalize_paths(&screen);
+ let normalized = normalize_output(&screen);
assert_snapshot!("select_with_branches", normalized);
}
/// Test preview panel 1: HEAD± shows uncommitted changes
#[test]
-#[ignore]
+
fn test_select_preview_panel_uncommitted() {
let mut repo = TestRepo::new();
repo.commit("Initial commit");
@@ -327,13 +344,13 @@ fn test_select_preview_panel_uncommitted() {
assert_valid_abort_exit_code(exit_code);
let screen = render_terminal_screen(&raw_output);
- let normalized = normalize_paths(&screen);
+ let normalized = normalize_output(&screen);
assert_snapshot!("select_preview_uncommitted", normalized);
}
/// Test preview panel 2: history shows recent commits
#[test]
-#[ignore]
+
fn test_select_preview_panel_history() {
let mut repo = TestRepo::new();
repo.commit("Initial commit");
@@ -377,13 +394,13 @@ fn test_select_preview_panel_history() {
assert_valid_abort_exit_code(exit_code);
let screen = render_terminal_screen(&raw_output);
- let normalized = normalize_paths(&screen);
+ let normalized = normalize_output(&screen);
assert_snapshot!("select_preview_history", normalized);
}
/// Test preview panel 3: main…± shows diff vs main branch
#[test]
-#[ignore]
+
fn test_select_preview_panel_main_diff() {
let mut repo = TestRepo::new();
repo.commit("Initial commit");
@@ -458,6 +475,6 @@ fn test_new_feature() {
assert_valid_abort_exit_code(exit_code);
let screen = render_terminal_screen(&raw_output);
- let normalized = normalize_paths(&screen);
+ let normalized = normalize_output(&screen);
assert_snapshot!("select_preview_main_diff", normalized);
}
diff --git a/tests/integration_tests/snapshots/integration__integration_tests__select__select_abort_escape.snap b/tests/integration_tests/snapshots/integration__integration_tests__select__select_abort_escape.snap
index b4f6cf278..8591e3458 100644
--- a/tests/integration_tests/snapshots/integration__integration_tests__select__select_abort_escape.snap
+++ b/tests/integration_tests/snapshots/integration__integration_tests__select__select_abort_escape.snap
@@ -2,10 +2,10 @@
source: tests/integration_tests/select.rs
expression: normalized
---
-> │ 3/4
- Branch Status HEAD± main↕ Path Remote⇅ Co│No uncommitted changes
+> [QUERY] │[PREVIEW_HEADER]
+ Branch Status HEAD± main↕ Path Remote⇅ Co│ctrl-u/d: scroll | ctrl-p: preview
> @ main ^ . ..│
- │
+ │No uncommitted changes
│
│
│
diff --git a/tests/integration_tests/snapshots/integration__integration_tests__select__select_multiple_worktrees.snap b/tests/integration_tests/snapshots/integration__integration_tests__select__select_multiple_worktrees.snap
index 5b1dce9b5..2e143f668 100644
--- a/tests/integration_tests/snapshots/integration__integration_tests__select__select_multiple_worktrees.snap
+++ b/tests/integration_tests/snapshots/integration__integration_tests__select__select_multiple_worktrees.snap
@@ -2,10 +2,10 @@
source: tests/integration_tests/select.rs
expression: normalized
---
-> │ 3/4
- Branch Status HEAD± main↕ Path │No uncommitted changes
- @ main ^ ./test-rep..│
-> + feature-one ∅ ./feature-..│
+> [QUERY] │[PREVIEW_HEADER]
+ Branch Status HEAD± main↕ Path │ctrl-u/d: scroll | ctrl-p: preview
+> @ main ^ ./test-rep..│
+ + feature-one ∅ ./feature-..│No uncommitted changes
+ feature-two ∅ ./feature-..│
│
│
diff --git a/tests/integration_tests/snapshots/integration__integration_tests__select__select_preview_history.snap b/tests/integration_tests/snapshots/integration__integration_tests__select__select_preview_history.snap
index ada0403e7..deb3c5e5d 100644
--- a/tests/integration_tests/snapshots/integration__integration_tests__select__select_preview_history.snap
+++ b/tests/integration_tests/snapshots/integration__integration_tests__select__select_preview_history.snap
@@ -2,7 +2,7 @@
source: tests/integration_tests/select.rs
expression: normalized
---
-> eature │1: HEAD± | 2: history | 3: main…± 1/9
+> [QUERY] │[PREVIEW_HEADER]
Branch Status HEAD± main↕ Path Rem│ctrl-u/d: scroll | ctrl-p: preview
> + feature ↑ ↑5 ./feature ..│
│* b1549b6 (feature) Add file 5 with important changes
diff --git a/tests/integration_tests/snapshots/integration__integration_tests__select__select_preview_main_diff.snap b/tests/integration_tests/snapshots/integration__integration_tests__select__select_preview_main_diff.snap
index c2df77337..abbe4f521 100644
--- a/tests/integration_tests/snapshots/integration__integration_tests__select__select_preview_main_diff.snap
+++ b/tests/integration_tests/snapshots/integration__integration_tests__select__select_preview_main_diff.snap
@@ -2,7 +2,7 @@
source: tests/integration_tests/select.rs
expression: normalized
---
-> eature │1: HEAD± | 2: history | 3: main…± 1/30
+> [QUERY] │[PREVIEW_HEADER]
Branch Status HEAD± main↕ Path Rem│ctrl-u/d: scroll | ctrl-p: preview
> + feature ↑ ↑2 ./feature ..│
│ feature_code.rs | 6 ++++++
diff --git a/tests/integration_tests/snapshots/integration__integration_tests__select__select_preview_uncommitted.snap b/tests/integration_tests/snapshots/integration__integration_tests__select__select_preview_uncommitted.snap
index 58d8bd21d..0a8f14462 100644
--- a/tests/integration_tests/snapshots/integration__integration_tests__select__select_preview_uncommitted.snap
+++ b/tests/integration_tests/snapshots/integration__integration_tests__select__select_preview_uncommitted.snap
@@ -2,7 +2,7 @@
source: tests/integration_tests/select.rs
expression: normalized
---
-> eature │1: HEAD± | 2: history | 3: main…± 1/16
+> [QUERY] │[PREVIEW_HEADER]
Branch Status HEAD± main↕ Path Rem│ctrl-u/d: scroll | ctrl-p: preview
> + feature ! ↑ +3 -1 ↑1 ./feature ..│
│ tracked.txt | 4 +++-
diff --git a/tests/integration_tests/snapshots/integration__integration_tests__select__select_with_branches.snap b/tests/integration_tests/snapshots/integration__integration_tests__select__select_with_branches.snap
index c44cddd08..8826979ea 100644
--- a/tests/integration_tests/snapshots/integration__integration_tests__select__select_with_branches.snap
+++ b/tests/integration_tests/snapshots/integration__integration_tests__select__select_with_branches.snap
@@ -2,10 +2,10 @@
source: tests/integration_tests/select.rs
expression: normalized
---
-> │ 3/4
- Branch Status HEAD± main↕ Path │No uncommitted changes
- @ main ^ ./test..│
-> + active-worktree ∅ ./acti..│
+> [QUERY] │[PREVIEW_HEADER]
+ Branch Status HEAD± main↕ Path │ctrl-u/d: scroll | ctrl-p: preview
+> @ main ^ ./test..│
+ + active-worktree ∅ ./acti..│No uncommitted changes
orphan-branch ∅ ⎇ ..│
│
│