Skip to content

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.rs
index 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 testing
fn 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.snap
index 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.rs
expression: output.normalized()
---
πŸ”„ Running pre-merge: check1:
-  /Users/maximilian/workspace/worktrunk.zellij/tests/fixtures/mixed-output.sh check1 3
+  [WORKSPACE]/tests/fixtures/mixed-output.sh check1 3
[check1] stdout line 1
[check1] stderr line 1
@@ -15,7 +15,7 @@ expression: output.normalized()
[check1] stderr complete
πŸ”„ Running pre-merge: check2:
-  /Users/maximilian/workspace/worktrunk.zellij/tests/fixtures/mixed-output.sh check2 3
+  [WORKSPACE]/tests/fixtures/mixed-output.sh check2 3
[check2] stdout line 1
[check2] stderr line 1
@@ -26,9 +26,9 @@ expression: output.normalized()
[check2] stdout complete
[check2] stderr complete
-πŸ”„ Merging 1 commit to main @ a8b5caa (no commit/squash/rebase needed)
+πŸ”„ Merging 1 commit to main @ [HASH] (no commit/squash/rebase needed)
-  * a8b5caa (HEAD -> feature) Add feature
+  * [HASH] (HEAD -> feature) Add feature
  feature.txt | 1 +
  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.snap
index 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
πŸ”„ Running pre-merge: check1:
-  /Users/maximilian/workspace/worktrunk.zellij/tests/fixtures/mixed-output.sh check1 3
+  [WORKSPACE]/tests/fixtures/mixed-output.sh check1 3
πŸ”„ Running pre-merge: check2:
-  /Users/maximilian/workspace/worktrunk.zellij/tests/fixtures/mixed-output.sh check2 3
+  [WORKSPACE]/tests/fixtures/mixed-output.sh check2 3
-πŸ”„ Merging 1 commit to main @ a8b5caa (no commit/squash/rebase needed)
+πŸ”„ Merging 1 commit to main @ [HASH] (no commit/squash/rebase needed)
-  * a8b5caa (HEAD -> feature) Add feature
+  * [HASH] (HEAD -> feature) Add feature
  feature.txt | 1 +
  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.snap
index 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
-πŸ”„ Merging 1 commit to main @ d067f01 (no commit/squash/rebase needed)
+πŸ”„ Merging 1 commit to main @ [HASH] (no commit/squash/rebase needed)
-  * d067f01 (HEAD -> feature) Add feature
+  * [HASH] (HEAD -> feature) Add feature
  feature.txt | 1 +
  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.snap
index 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()
  echo 'βœ“ All 47 tests passed in 2.3s'
-πŸ”„ Merging 1 commit to main @ d067f01 (no commit/squash/rebase needed)
+πŸ”„ Merging 1 commit to main @ [HASH] (no commit/squash/rebase needed)
-  * d067f01 (HEAD -> feature) Add feature
+  * [HASH] (HEAD -> feature) Add feature
  feature.txt | 1 +
  1 file changed, 1 insertion(+)