Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
fix(test): normalize trailing whitespace at PtyResult extraction layer (#983)
worktrunk-botcdcdd34a5d3f
diff --git a/tests/integration_tests/switch_picker.rs b/tests/integration_tests/switch_picker.rsindex 7f194f2de..fbbaf541b 100644--- a/tests/integration_tests/switch_picker.rs+++ b/tests/integration_tests/switch_picker.rs@@ -63,23 +63,40 @@ struct PtyResult {impl PtyResult {/// Full screen content as rows of text.+ ///+ /// Trailing whitespace is trimmed from each row because `vt100::rows()` pads+ /// rows to the full column width with spaces. This padding is terminal buffer+ /// fill, not meaningful content, and varies across platforms. Trailing empty+ /// lines are also removed (unwritten terminal rows become empty after trim).fn screen(&self) -> String {self.parser.screen().rows(0, TERM_COLS)+ .map(|row| row.trim_end().to_string()).collect::<Vec<_>>().join("\n")+ .trim_end()+ .to_string()}/// List and preview panel content, split at the skim border column./// Avoids the │ border character that causes cross-platform rendering issues.fn panels(&self) -> (String, String) {let screen = self.parser.screen();- let list = screen.rows(0, SEPARATOR_COL).collect::<Vec<_>>().join("\n");+ let list = screen+ .rows(0, SEPARATOR_COL)+ .map(|row| row.trim_end().to_string())+ .collect::<Vec<_>>()+ .join("\n")+ .trim_end()+ .to_string();let preview = screen.rows(SEPARATOR_COL + 1, TERM_COLS - SEPARATOR_COL - 1)+ .map(|row| row.trim_end().to_string()).collect::<Vec<_>>()- .join("\n");+ .join("\n")+ .trim_end()+ .to_string();(list, preview)}}@@ -97,6 +114,18 @@ fn assert_valid_abort_exit_code(exit_code: i32) {);}+/// Collapse consecutive identical trailing lines into a single copy.+///+/// Useful for abort tests where skim's border rendering produces a variable number+/// of identical `│` rows depending on how far rendering progressed before exit.+fn collapse_trailing_dupes(s: &str) -> String {+ let mut lines: Vec<&str> = s.lines().collect();+ while lines.len() >= 2 && lines[lines.len() - 1] == lines[lines.len() - 2] {+ lines.pop();+ }+ lines.join("\n")+}+/// Check if skim is ready (shows "> " prompt indicating it's accepting input)fn is_skim_ready(screen_content: &str) -> bool {// Skim shows "> " at the start when ready, and displays item count like "1/3"@@ -338,7 +367,10 @@ fn test_switch_picker_abort_with_escape(mut repo: TestRepo) {assert_valid_abort_exit_code(result.exit_code);- let screen = result.screen();+ // Collapse trailing duplicate lines: skim's border rendering varies on abort+ // because the escape key kills the process mid-render, producing a variable+ // number of identical `│` border rows at the bottom.+ let screen = collapse_trailing_dupes(&result.screen());let settings = switch_picker_settings(&repo);settings.bind(|| {assert_snapshot!("switch_picker_abort_escape", screen);@@ -365,7 +397,7 @@ fn test_switch_picker_with_multiple_worktrees(mut repo: TestRepo) {assert_valid_abort_exit_code(result.exit_code);- let screen = result.screen();+ let screen = collapse_trailing_dupes(&result.screen());let settings = switch_picker_settings(&repo);settings.bind(|| {assert_snapshot!("switch_picker_multiple_worktrees", screen);@@ -398,7 +430,7 @@ fn test_switch_picker_with_branches(mut repo: TestRepo) {assert_valid_abort_exit_code(result.exit_code);- let screen = result.screen();+ let screen = collapse_trailing_dupes(&result.screen());let settings = switch_picker_settings(&repo);settings.bind(|| {assert_snapshot!("switch_picker_with_branches", screen);diff --git a/tests/snapshots/integration__integration_tests__switch_picker__switch_picker_abort_escape.snap b/tests/snapshots/integration__integration_tests__switch_picker__switch_picker_abort_escape.snapindex fdc1808b5..48de250e7 100644--- a/tests/snapshots/integration__integration_tests__switch_picker__switch_picker_abort_escape.snap+++ b/tests/snapshots/integration__integration_tests__switch_picker__switch_picker_abort_escape.snap@@ -4,28 +4,6 @@ expression: screen---> [QUERY]Branch Status HEAD± main↕ Remote⇅ Commit │Enter: switch | alt-c: create | Esc: cancel | ctrl-u/d: scr-> @ main ^ [HASH] │- │○ main has no uncommitted changes- │- │- │- │- │- │- │- │- │- │- │- │- │- │- │- │- │- │- │- │- │- │+> @ main ^ [HASH] │+ │○ main has no uncommitted changes│diff --git a/tests/snapshots/integration__integration_tests__switch_picker__switch_picker_multiple_worktrees.snap b/tests/snapshots/integration__integration_tests__switch_picker__switch_picker_multiple_worktrees.snapindex e9dd62127..5705f9920 100644--- a/tests/snapshots/integration__integration_tests__switch_picker__switch_picker_multiple_worktrees.snap+++ b/tests/snapshots/integration__integration_tests__switch_picker__switch_picker_multiple_worktrees.snap@@ -4,28 +4,7 @@ expression: screen---> [QUERY]Branch Status HEAD± main↕ Remote⇅ Age │Enter: switch | alt-c: create | Esc: cancel | ctrl-u/d: scr-> @ main ^ [TIME] │- + feature-one _ [TIME] │○ main has no uncommitted changes- + feature-two _ [TIME] │- │- │- │- │- │- │- │- │- │- │- │- │- │- │- │- │- │- │- │- │- │+> @ main ^ [TIME] │+ + feature-one _ [TIME] │○ main has no uncommitted changes+ + feature-two _ [TIME] ││diff --git a/tests/snapshots/integration__integration_tests__switch_picker__switch_picker_preview_log_list.snap b/tests/snapshots/integration__integration_tests__switch_picker__switch_picker_preview_log_list.snapindex c6d1f751b..19a3d5125 100644--- a/tests/snapshots/integration__integration_tests__switch_picker__switch_picker_preview_log_list.snap+++ b/tests/snapshots/integration__integration_tests__switch_picker__switch_picker_preview_log_list.snap@@ -3,5 +3,5 @@ source: tests/integration_tests/switch_picker.rsexpression: list---> [QUERY]- Branch Status HEAD± main↕ Remote⇅ Commit+ Branch Status HEAD± main↕ Remote⇅ Commit> + feature ↑ ↑5 [HASH]..diff --git a/tests/snapshots/integration__integration_tests__switch_picker__switch_picker_preview_log_preview.snap b/tests/snapshots/integration__integration_tests__switch_picker__switch_picker_preview_log_preview.snapindex 582746488..1e64cdf8d 100644--- a/tests/snapshots/integration__integration_tests__switch_picker__switch_picker_preview_log_preview.snap+++ b/tests/snapshots/integration__integration_tests__switch_picker__switch_picker_preview_log_preview.snap@@ -4,10 +4,10 @@ expression: preview---1: HEAD± | 2: log | 3: main…± | 4: remote⇅ [N/M]Enter: switch | alt-c: create | Esc: cancel | ctrl-u/d: scr--* [HASH] +1 [TIME] (feature) Add file 5 with content-* [HASH] +1 [TIME] Add file 4 with content-* [HASH] +1 [TIME] Add file 3 with content-* [HASH] +1 [TIME] Add file 2 with content-* [HASH] +1 [TIME] Add file 1 with content++* [HASH] +1 [TIME] (feature) Add file 5 with content+* [HASH] +1 [TIME] Add file 4 with content+* [HASH] +1 [TIME] Add file 3 with content+* [HASH] +1 [TIME] Add file 2 with content+* [HASH] +1 [TIME] Add file 1 with content* [HASH] +2 [TIME] (HEAD -> main) Initial commitdiff --git a/tests/snapshots/integration__integration_tests__switch_picker__switch_picker_preview_main_diff_list.snap b/tests/snapshots/integration__integration_tests__switch_picker__switch_picker_preview_main_diff_list.snapindex e02ba5ef3..63f773708 100644--- a/tests/snapshots/integration__integration_tests__switch_picker__switch_picker_preview_main_diff_list.snap+++ b/tests/snapshots/integration__integration_tests__switch_picker__switch_picker_preview_main_diff_list.snap@@ -3,5 +3,5 @@ source: tests/integration_tests/switch_picker.rsexpression: list---> [QUERY]- Branch Status HEAD± main↕ Remote⇅ Commit+ Branch Status HEAD± main↕ Remote⇅ Commit> + feature ↑ ↑2 [HASH]..diff --git a/tests/snapshots/integration__integration_tests__switch_picker__switch_picker_preview_main_diff_preview.snap b/tests/snapshots/integration__integration_tests__switch_picker__switch_picker_preview_main_diff_preview.snapindex 4c48ca09b..83c539c7d 100644--- a/tests/snapshots/integration__integration_tests__switch_picker__switch_picker_preview_main_diff_preview.snap+++ b/tests/snapshots/integration__integration_tests__switch_picker__switch_picker_preview_main_diff_preview.snap@@ -4,28 +4,28 @@ expression: preview---1: HEAD± | 2: log | 3: main…± | 4: remote⇅ [N/M]Enter: switch | alt-c: create | Esc: cancel | ctrl-u/d: scr-- feature_code.rs | 6 ++++++- tests.rs | 4 ++++- 2 files changed, 10 insertions(+)-diff --git a/feature_code.rs b/feature_code.rs-new file mode 100644-index [HASH]..[HASH]---- /dev/null-+++ b/feature_code.rs-@@ -0,0 +1,6 @@-+fn new_feature() {-+ println!("This is a new feature!");-+ let x = 42;-+ let y = x * 2;-+ println!("Result: {}", y);-+}-diff --git a/tests.rs b/tests.rs-new file mode 100644-index [HASH]..[HASH]---- /dev/null-+++ b/tests.rs-@@ -0,0 +1,4 @@-+#[test]-+fn test_new_feature() {++ feature_code.rs | 6 +++++++ tests.rs | 4 +++++ 2 files changed, 10 insertions(+)+diff --git a/feature_code.rs b/feature_code.rs+new file mode 100644+index [HASH]..[HASH]+--- /dev/null++++ b/feature_code.rs+@@ -0,0 +1,6 @@++fn new_feature() {++ println!("This is a new feature!");++ let x = 42;++ let y = x * 2;++ println!("Result: {}", y);++}+diff --git a/tests.rs b/tests.rs+new file mode 100644+index [HASH]..[HASH]+--- /dev/null++++ b/tests.rs+@@ -0,0 +1,4 @@++#[test]++fn test_new_feature() {+ assert_eq!(42 * 2, 84);diff --git a/tests/snapshots/integration__integration_tests__switch_picker__switch_picker_preview_uncommitted_list.snap b/tests/snapshots/integration__integration_tests__switch_picker__switch_picker_preview_uncommitted_list.snapindex 7f2b25ae6..2af7f835a 100644--- a/tests/snapshots/integration__integration_tests__switch_picker__switch_picker_preview_uncommitted_list.snap+++ b/tests/snapshots/integration__integration_tests__switch_picker__switch_picker_preview_uncommitted_list.snap@@ -3,5 +3,5 @@ source: tests/integration_tests/switch_picker.rsexpression: list---> [QUERY]- Branch Status HEAD± main↕ Remote⇅ Commit+ Branch Status HEAD± main↕ Remote⇅ Commit> + feature ! ↑ +3 -1 ↑1 [HASH]..diff --git a/tests/snapshots/integration__integration_tests__switch_picker__switch_picker_preview_uncommitted_preview.snap b/tests/snapshots/integration__integration_tests__switch_picker__switch_picker_preview_uncommitted_preview.snapindex b11da9188..6dfd86164 100644--- a/tests/snapshots/integration__integration_tests__switch_picker__switch_picker_preview_uncommitted_preview.snap+++ b/tests/snapshots/integration__integration_tests__switch_picker__switch_picker_preview_uncommitted_preview.snap@@ -4,15 +4,15 @@ expression: preview---1: HEAD± | 2: log | 3: main…± | 4: remote⇅ [N/M]Enter: switch | alt-c: create | Esc: cancel | ctrl-u/d: scr-- tracked.txt | 4 +++-- 1 file changed, 3 insertions(+), 1 deletion(-)-diff --git a/tracked.txt b/tracked.txt-index [HASH]..[HASH] 100644---- a/tracked.txt-+++ b/tracked.txt-@@ -1 +1,3 @@--Original content-+Modified content-+New line added++ tracked.txt | 4 +++-+ 1 file changed, 3 insertions(+), 1 deletion(-)+diff --git a/tracked.txt b/tracked.txt+index [HASH]..[HASH] 100644+--- a/tracked.txt++++ b/tracked.txt+@@ -1 +1,3 @@+-Original content++Modified content++New line added+Another linediff --git a/tests/snapshots/integration__integration_tests__switch_picker__switch_picker_with_branches.snap b/tests/snapshots/integration__integration_tests__switch_picker__switch_picker_with_branches.snapindex cf260537a..6a2bbeadb 100644--- a/tests/snapshots/integration__integration_tests__switch_picker__switch_picker_with_branches.snap+++ b/tests/snapshots/integration__integration_tests__switch_picker__switch_picker_with_branches.snap@@ -4,28 +4,7 @@ expression: screen---> [QUERY]Branch Status HEAD± main↕ Remote⇅ │Enter: switch | alt-c: create | Esc: cancel | ctrl-u/d: scr-> @ main ^ │- + active-worktree _ │○ main has no uncommitted changes- orphan-branch /_ │- │- │- │- │- │- │- │- │- │- │- │- │- │- │- │- │- │- │- │- │- │+> @ main ^ │+ + active-worktree _ │○ main has no uncommitted changes+ orphan-branch /_ ││