Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
feat: Normalize snapshot test output and accept normalized snapshots
Maximilian Roos6ce2f18a0cd7
diff --git a/tests/integration_tests/shell_wrapper.rs b/tests/integration_tests/shell_wrapper.rsindex 514355fe5..ddf0651af 100644--- a/tests/integration_tests/shell_wrapper.rs+++ b/tests/integration_tests/shell_wrapper.rs@@ -45,6 +45,21 @@ static TMPDIR_REGEX: LazyLock<regex::Regex> = LazyLock::new(|| {.expect("Invalid tmpdir regex pattern")});+/// Regex for normalizing workspace paths (dynamically built from CARGO_MANIFEST_DIR)+/// Matches: <project_root>/tests/fixtures/+/// Replaces with: [WORKSPACE]/tests/fixtures/+static WORKSPACE_REGEX: LazyLock<regex::Regex> = LazyLock::new(|| {+ let manifest_dir = env!("CARGO_MANIFEST_DIR");+ let pattern = format!(r"{}/tests/fixtures/", regex::escape(manifest_dir));+ regex::Regex::new(&pattern).expect("Invalid workspace regex pattern")+});++/// Regex for normalizing git commit hashes (7-character hex)+/// Matches 7-character lowercase hex sequences (git short hashes)+/// Note: No word boundaries because ANSI codes (ending with 'm') directly precede hashes+static COMMIT_HASH_REGEX: LazyLock<regex::Regex> =+ LazyLock::new(|| regex::Regex::new(r"[0-9a-f]{7}").expect("Invalid commit hash regex pattern"));+/// Output from executing a command through a shell wrapper#[derive(Debug)]struct ShellOutput {@@ -71,13 +86,20 @@ impl ShellOutput {/// Normalize paths and ANSI codes in output for snapshot testingfn normalized(&self) -> String {- // First normalize paths- let path_normalized = TMPDIR_REGEX.replace_all(&self.combined, "[TMPDIR]");+ // First normalize temporary directory paths+ let tmpdir_normalized = TMPDIR_REGEX.replace_all(&self.combined, "[TMPDIR]");++ // Then normalize workspace paths (varying directory names)+ let workspace_normalized =+ WORKSPACE_REGEX.replace_all(&tmpdir_normalized, "[WORKSPACE]/tests/fixtures/");++ // Normalize commit hashes (7-character hex strings)+ let hash_normalized = COMMIT_HASH_REGEX.replace_all(&workspace_normalized, "[HASH]");// Then normalize ANSI codes: remove redundant leading reset codes// This handles differences between macOS and Linux PTY ANSI generation- let has_trailing_newline = path_normalized.ends_with('\n');- let mut result = path_normalized+ let has_trailing_newline = hash_normalized.ends_with('\n');+ let mut result = hash_normalized.lines().map(|line| {// Strip leading \x1b[0m reset codes (may appear as ESC[0m in the output)diff --git a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_mixed_stdout_stderr_bash.snap b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_mixed_stdout_stderr_bash.snapindex 6c5cf2a31..aff496126 100644--- a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_mixed_stdout_stderr_bash.snap+++ b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_mixed_stdout_stderr_bash.snap@@ -3,7 +3,7 @@ source: tests/integration_tests/shell_wrapper.rsexpression: output.normalized()---π [36mRunning pre-merge: [1mcheck1[0m:[0m-[40m [0m [1m[34m/Users/maximilian/workspace/worktrunk.zellij/tests/fixtures/mixed-output.sh[0m check1 3[0m+[40m [0m [1m[34m[WORKSPACE]/tests/fixtures/mixed-output.sh[0m check1 3[0m[check1] stdout line 1[check1] stderr line 1@@ -15,7 +15,7 @@ expression: output.normalized()[check1] stderr completeπ [36mRunning pre-merge: [1mcheck2[0m:[0m-[40m [0m [1m[34m/Users/maximilian/workspace/worktrunk.zellij/tests/fixtures/mixed-output.sh[0m check2 3[0m+[40m [0m [1m[34m[WORKSPACE]/tests/fixtures/mixed-output.sh[0m check2 3[0m[check2] stdout line 1[check2] stderr line 1@@ -26,9 +26,9 @@ expression: output.normalized()[check2] stdout complete[check2] stderr complete-π [36mMerging 1 commit to [1m[36mmain[0m @ [2m[36ma8b5caa[0m[0m (no commit/squash/rebase needed)+π [36mMerging 1 commit to [1m[36mmain[0m @ [2m[36m[HASH][0m[0m (no commit/squash/rebase needed)-[40m [0m * [33ma8b5caa[m[33m ([m[1;36mHEAD[m[33m -> [m[1;32mfeature[m[33m)[m Add feature+[40m [0m * [33m[HASH][m[33m ([m[1;36mHEAD[m[33m -> [m[1;32mfeature[m[33m)[m Add feature[40m [0m feature.txt | 1 [32m+[m[40m [0m 1 file changed, 1 insertion(+)diff --git a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_mixed_stdout_stderr_zsh.snap b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_mixed_stdout_stderr_zsh.snapindex ce551f713..4ba0fde4b 100644--- a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_mixed_stdout_stderr_zsh.snap+++ b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_mixed_stdout_stderr_zsh.snap@@ -19,16 +19,16 @@ expression: output.normalized()[check2] stdout complete[check2] stderr completeπ [36mRunning pre-merge: [1mcheck1[0m:[0m-[40m [0m [1m[34m/Users/maximilian/workspace/worktrunk.zellij/tests/fixtures/mixed-output.sh[0m check1 3[0m+[40m [0m [1m[34m[WORKSPACE]/tests/fixtures/mixed-output.sh[0m check1 3[0mπ [36mRunning pre-merge: [1mcheck2[0m:[0m-[40m [0m [1m[34m/Users/maximilian/workspace/worktrunk.zellij/tests/fixtures/mixed-output.sh[0m check2 3[0m+[40m [0m [1m[34m[WORKSPACE]/tests/fixtures/mixed-output.sh[0m check2 3[0m-π [36mMerging 1 commit to [1m[36mmain[0m @ [2m[36ma8b5caa[0m[0m (no commit/squash/rebase needed)+π [36mMerging 1 commit to [1m[36mmain[0m @ [2m[36m[HASH][0m[0m (no commit/squash/rebase needed)-[40m [0m * [33ma8b5caa[m[33m ([m[1;36mHEAD[m[33m -> [m[1;32mfeature[m[33m)[m Add feature+[40m [0m * [33m[HASH][m[33m ([m[1;36mHEAD[m[33m -> [m[1;32mfeature[m[33m)[m Add feature[40m [0m feature.txt | 1 [32m+[m[40m [0m 1 file changed, 1 insertion(+)diff --git a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_pre_merge_success_bash.snap b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_pre_merge_success_bash.snapindex 430720753..4d56ecb07 100644--- a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_pre_merge_success_bash.snap+++ b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_pre_merge_success_bash.snap@@ -17,9 +17,9 @@ expression: output.normalized()β All 47 tests passed in 2.3s-π [36mMerging 1 commit to [1m[36mmain[0m @ [2m[36md067f01[0m[0m (no commit/squash/rebase needed)+π [36mMerging 1 commit to [1m[36mmain[0m @ [2m[36m[HASH][0m[0m (no commit/squash/rebase needed)-[40m [0m * [33md067f01[m[33m ([m[1;36mHEAD[m[33m -> [m[1;32mfeature[m[33m)[m Add feature+[40m [0m * [33m[HASH][m[33m ([m[1;36mHEAD[m[33m -> [m[1;32mfeature[m[33m)[m Add feature[40m [0m feature.txt | 1 [32m+[m[40m [0m 1 file changed, 1 insertion(+)diff --git a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_pre_merge_success_zsh.snap b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_pre_merge_success_zsh.snapindex c59fc3adc..c9252b462 100644--- a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_pre_merge_success_zsh.snap+++ b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_with_pre_merge_success_zsh.snap@@ -17,9 +17,9 @@ expression: output.normalized()[40m [0m [1m[34mecho[0m [32m'β All 47 tests passed in 2.3s'[0m[0m-π [36mMerging 1 commit to [1m[36mmain[0m @ [2m[36md067f01[0m[0m (no commit/squash/rebase needed)+π [36mMerging 1 commit to [1m[36mmain[0m @ [2m[36m[HASH][0m[0m (no commit/squash/rebase needed)-[40m [0m * [33md067f01[m[33m ([m[1;36mHEAD[m[33m -> [m[1;32mfeature[m[33m)[m Add feature+[40m [0m * [33m[HASH][m[33m ([m[1;36mHEAD[m[33m -> [m[1;32mfeature[m[33m)[m Add feature[40m [0m feature.txt | 1 [32m+[m[40m [0m 1 file changed, 1 insertion(+)