Skip to content

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

refactor: Isolate test environment from user setup

Maximilian Roos634183c2139a
diff --git a/tests/integration_tests/shell_wrapper.rs b/tests/integration_tests/shell_wrapper.rs
index df3d3f8b1..514355fe5 100644
--- a/tests/integration_tests/shell_wrapper.rs
+++ b/tests/integration_tests/shell_wrapper.rs
@@ -232,6 +232,24 @@ fn exec_in_pty(
// Spawn the shell inside the PTY
let mut cmd = CommandBuilder::new(shell);
+ // Clear inherited environment for test isolation
+ // This prevents user environment (ZELLIJ, TMUX, custom aliases, etc.) from
+ // affecting test behavior or causing side effects (e.g., renaming Zellij tabs)
+ cmd.env_clear();
+
+ // Set minimal required environment for shells to function
+ // HOME and PATH are preserved for rustup/cargo and finding git/commands
+ cmd.env(
+ "HOME",
+ std::env::var("HOME").unwrap_or_else(|_| "/tmp".to_string()),
+ );
+ cmd.env(
+ "PATH",
+ std::env::var("PATH").unwrap_or_else(|_| "/usr/bin:/bin".to_string()),
+ );
+ cmd.env("USER", "testuser");
+ cmd.env("SHELL", shell);
+
// For zsh, isolate from user rc files to prevent TTY access issues
// User startup files (~/.zshenv, ~/.zshrc) can touch /dev/tty (e.g., stty, zle,
// compinit, GPG_TTY=$(tty)) which causes SIGTTIN/TTOU/TSTP signals when the
@@ -255,7 +273,7 @@ fn exec_in_pty(
cmd.arg(script);
cmd.cwd(working_dir);
- // Add environment variables
+ // Add test-specific environment variables
for (key, value) in env_vars {
cmd.env(key, value);
}
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 c78f6e87f..6c5cf2a31 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.worktree-failure/tests/fixtures/mixed-output.sh check1 3
+  /Users/maximilian/workspace/worktrunk.zellij/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.worktree-failure/tests/fixtures/mixed-output.sh check2 3
+  /Users/maximilian/workspace/worktrunk.zellij/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 @ e28e0ba (no commit/squash/rebase needed)
+πŸ”„ Merging 1 commit to main @ a8b5caa (no commit/squash/rebase needed)
-  * e28e0ba (HEAD -> feature) Add feature
+  * a8b5caa (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 fff418f41..ce551f713 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.worktree-failure/tests/fixtures/mixed-output.sh check1 3
+  /Users/maximilian/workspace/worktrunk.zellij/tests/fixtures/mixed-output.sh check1 3
πŸ”„ Running pre-merge: check2:
-  /Users/maximilian/workspace/worktrunk.worktree-failure/tests/fixtures/mixed-output.sh check2 3
+  /Users/maximilian/workspace/worktrunk.zellij/tests/fixtures/mixed-output.sh check2 3
-πŸ”„ Merging 1 commit to main @ e28e0ba (no commit/squash/rebase needed)
+πŸ”„ Merging 1 commit to main @ a8b5caa (no commit/squash/rebase needed)
-  * e28e0ba (HEAD -> feature) Add feature
+  * a8b5caa (HEAD -> feature) Add feature
  feature.txt | 1 +
  1 file changed, 1 insertion(+)