Skip to content

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

feat: Emit progress messages for shell wrappers

Maximilian Roos35c9b2b039f5
diff --git a/src/output/directive.rs b/src/output/directive.rs
index e8a903b56..64cc77355 100644
--- a/src/output/directive.rs
+++ b/src/output/directive.rs
@@ -20,9 +20,12 @@ impl DirectiveOutput {
io::stdout().flush()
}
- pub fn progress(&mut self, _message: String) -> io::Result<()> {
- // Progress messages are only for humans - suppress in directive mode
- Ok(())
+ pub fn progress(&mut self, message: String) -> io::Result<()> {
+ // Progress messages are for humans - output them just like success messages
+ // The shell wrapper will display these to users
+ let plain = strip_str(&message).to_string();
+ write!(io::stdout(), "{}\0", plain)?;
+ io::stdout().flush()
}
pub fn change_directory(&mut self, path: &Path) -> io::Result<()> {
diff --git a/tests/integration_tests/directives.rs b/tests/integration_tests/directives.rs
index ef0c796de..bd04290c5 100644
--- a/tests/integration_tests/directives.rs
+++ b/tests/integration_tests/directives.rs
@@ -173,7 +173,15 @@ fn test_merge_internal_keep() {
.arg("--keep")
.current_dir(&feature_wt);
- assert_cmd_snapshot!(cmd, @"success: true\nexit_code: 0\n----- stdout -----\nKept worktree (use 'wt remove' to clean up)\0\n----- stderr -----");
+ assert_cmd_snapshot!(cmd, @"success: true
+exit_code: 0
+----- stdout -----
+πŸ”„ Validating merge...\0πŸ”„ Rebasing onto main...\0πŸ”„ Pushing 1 commit to main @ [SHA]
+\0* 6551244 (HEAD -> feature) Add feature file
+\0 feature.txt | 1 +
+ 1 file changed, 1 insertion(+)
+\0βœ… Pushed to main (1 commit, 1 file, +1) \0\0Kept worktree (use 'wt remove' to clean up)\0
+----- stderr -----");
});
}
@@ -229,6 +237,14 @@ fn test_merge_internal_remove() {
.arg("main")
.current_dir(&feature_wt);
- assert_cmd_snapshot!(cmd, @"success: true\nexit_code: 0\n----- stdout -----\n__WORKTRUNK_CD__[PATH]\0Returned to primary at [REPO]\0\n----- stderr -----");
+ assert_cmd_snapshot!(cmd, @"success: true
+exit_code: 0
+----- stdout -----
+πŸ”„ Validating merge...\0πŸ”„ Rebasing onto main...\0πŸ”„ Pushing 1 commit to main @ [SHA]
+\0* 6551244 (HEAD -> feature) Add feature file
+\0 feature.txt | 1 +
+ 1 file changed, 1 insertion(+)
+\0βœ… Pushed to main (1 commit, 1 file, +1) \0πŸ”„ Cleaning up worktree...\0__WORKTRUNK_CD__[PATH]\0\0Returned to primary at [REPO]\0
+----- stderr -----");
});
}
diff --git a/tests/integration_tests/shell_wrapper.rs b/tests/integration_tests/shell_wrapper.rs
index 478982465..5a5b15c44 100644
--- a/tests/integration_tests/shell_wrapper.rs
+++ b/tests/integration_tests/shell_wrapper.rs
@@ -12,20 +12,52 @@ use crate::common::TestRepo;
use insta::assert_snapshot;
use insta_cmd::get_cargo_bin;
use std::fs;
-use std::path::Path;
use std::process::Command;
-/// Generate the bash wrapper script from template
-fn generate_bash_wrapper(_repo: &TestRepo) -> String {
- let template_path = Path::new(env!("CARGO_MANIFEST_DIR"))
- .join("templates")
- .join("bash.sh");
- let template = fs::read_to_string(&template_path).expect("Failed to read bash template");
-
- // Simple template substitution (matches what `wt init` does)
- template
- .replace("{{ shell_name }}", "bash")
- .replace("{{ cmd_prefix }}", "wt")
+/// Generate the bash wrapper script using the actual `wt init` command
+fn generate_bash_wrapper(repo: &TestRepo) -> String {
+ let wt_bin = get_cargo_bin("wt");
+
+ let mut cmd = Command::new(&wt_bin);
+ cmd.arg("init").arg("bash");
+
+ // Configure environment
+ repo.clean_cli_env(&mut cmd);
+
+ let output = cmd.output().expect("Failed to run wt init bash");
+
+ if !output.status.success() {
+ panic!(
+ "wt init bash failed with exit code: {:?}\nOutput:\n{}",
+ output.status.code(),
+ String::from_utf8_lossy(&output.stderr)
+ );
+ }
+
+ String::from_utf8(output.stdout).expect("wt init bash produced invalid UTF-8")
+}
+
+/// Generate the fish wrapper script using the actual `wt init` command
+fn generate_fish_wrapper(repo: &TestRepo) -> String {
+ let wt_bin = get_cargo_bin("wt");
+
+ let mut cmd = Command::new(&wt_bin);
+ cmd.arg("init").arg("fish");
+
+ // Configure environment
+ repo.clean_cli_env(&mut cmd);
+
+ let output = cmd.output().expect("Failed to run wt init fish");
+
+ if !output.status.success() {
+ panic!(
+ "wt init fish failed with exit code: {:?}\nOutput:\n{}",
+ output.status.code(),
+ String::from_utf8_lossy(&output.stderr)
+ );
+ }
+
+ String::from_utf8(output.stdout).expect("wt init fish produced invalid UTF-8")
}
/// Execute a command through the bash shell wrapper
@@ -62,10 +94,10 @@ fn exec_through_bash_wrapper(repo: &TestRepo, subcommand: &str, args: &[&str]) -
script.push_str(subcommand);
for arg in args {
script.push_str(" ");
- // Quote arguments with spaces
- if arg.contains(' ') {
+ // Quote arguments that need special handling (spaces, semicolons, etc.)
+ if arg.contains(' ') || arg.contains(';') || arg.contains('\'') {
script.push_str("'");
- script.push_str(arg);
+ script.push_str(&arg.replace('\'', "'\\''"));
script.push_str("'");
} else {
script.push_str(arg);
@@ -100,6 +132,79 @@ fn exec_through_bash_wrapper(repo: &TestRepo, subcommand: &str, args: &[&str]) -
combined
}
+/// Execute a command through the fish shell wrapper
+///
+/// This simulates what actually happens when users run `wt switch`, etc. in their Fish shell:
+/// 1. The `wt` function is defined (from shell integration)
+/// 2. It calls `_wt_exec --internal switch ...`
+/// 3. The wrapper parses NUL-delimited output and handles directives
+/// 4. Users see only the final human-friendly output
+///
+/// Returns the combined stdout+stderr output as users would see it
+fn exec_through_fish_wrapper(repo: &TestRepo, subcommand: &str, args: &[&str]) -> String {
+ let wrapper_script = generate_fish_wrapper(repo);
+
+ // Get the path to wt binary
+ let wt_bin = get_cargo_bin("wt");
+
+ // Build the full script that sources the wrapper and runs the command
+ let mut script = String::new();
+
+ // Set environment variables
+ script.push_str(&format!("set -x WORKTRUNK_BIN '{}'\n", wt_bin.display()));
+ script.push_str(&format!(
+ "set -x WORKTRUNK_CONFIG_PATH '{}'\n",
+ repo.test_config_path().display()
+ ));
+ script.push_str("set -x CLICOLOR_FORCE 1\n"); // Force colors for snapshot testing
+
+ // Source the wrapper
+ script.push_str(&wrapper_script);
+ script.push_str("\n");
+
+ // Run the command
+ script.push_str("wt ");
+ script.push_str(subcommand);
+ for arg in args {
+ script.push_str(" ");
+ // Quote arguments that need special handling (spaces, semicolons, etc.)
+ if arg.contains(' ') || arg.contains(';') || arg.contains('\'') {
+ script.push_str("'");
+ script.push_str(&arg.replace('\'', "'\\''"));
+ script.push_str("'");
+ } else {
+ script.push_str(arg);
+ }
+ }
+ script.push_str("\n");
+
+ // Execute through fish
+ let mut cmd = Command::new("fish");
+ cmd.arg("-c").arg(&script).current_dir(repo.root_path());
+
+ // Configure git environment
+ repo.clean_cli_env(&mut cmd);
+
+ let output = cmd.output().expect("Failed to execute fish wrapper");
+
+ // Combine stdout and stderr as users would see in a terminal
+ let mut combined = String::from_utf8_lossy(&output.stdout).to_string();
+ if !output.stderr.is_empty() {
+ combined.push_str(&String::from_utf8_lossy(&output.stderr));
+ }
+
+ // Check that command succeeded
+ if !output.status.success() {
+ panic!(
+ "Command failed with exit code: {:?}\nOutput:\n{}",
+ output.status.code(),
+ combined
+ );
+ }
+
+ combined
+}
+
/// Assert that output contains no directive leaks
fn assert_no_directive_leaks(output: &str) {
assert!(
@@ -114,146 +219,385 @@ fn assert_no_directive_leaks(output: &str) {
);
}
-#[test]
-fn test_switch_create_through_wrapper_no_directive_leak() {
- let repo = TestRepo::new();
- repo.commit("Initial commit");
+mod tests {
+ use super::*;
- let output = exec_through_bash_wrapper(&repo, "switch", &["--create", "feature"]);
+ // ========================================================================
+ // Bash Shell Wrapper Tests
+ // ========================================================================
- // The critical assertion: directives must never appear in user-facing output
- assert_no_directive_leaks(&output);
+ #[test]
+ fn test_switch_create_through_wrapper_no_directive_leak() {
+ let repo = TestRepo::new();
+ repo.commit("Initial commit");
- // Normalize paths in output for snapshot testing
- let normalized = regex::Regex::new(r"/private/var/folders/[^/]+/[^/]+/T/\.tmp[^/]+")
- .unwrap()
- .replace_all(&output, "[TMPDIR]");
+ let output = exec_through_bash_wrapper(&repo, "switch", &["--create", "feature"]);
- // Snapshot the output for regression testing
- assert_snapshot!(normalized.as_ref());
-}
+ // The critical assertion: directives must never appear in user-facing output
+ assert_no_directive_leaks(&output);
+
+ // Normalize paths in output for snapshot testing
+ let normalized = regex::Regex::new(r"/private/var/folders/[^/]+/[^/]+/T/\.tmp[^/]+")
+ .unwrap()
+ .replace_all(&output, "[TMPDIR]");
+
+ // Snapshot the output for regression testing
+ assert_snapshot!(normalized.as_ref());
+ }
-#[test]
-fn test_switch_with_post_start_command_no_directive_leak() {
- let repo = TestRepo::new();
- repo.commit("Initial commit");
+ #[test]
+ fn test_switch_with_post_start_command_no_directive_leak() {
+ let repo = TestRepo::new();
+ repo.commit("Initial commit");
- // Configure a post-start command in the project config (this is where the bug manifests)
- // The println! in handle_post_start_commands causes directive leaks
- let config_dir = repo.root_path().join(".config");
- fs::create_dir_all(&config_dir).expect("Failed to create .config dir");
- fs::write(
- config_dir.join("wt.toml"),
- r#"post-start-command = "echo 'test command executed'""#,
- )
- .expect("Failed to write project config");
+ // Configure a post-start command in the project config (this is where the bug manifests)
+ // The println! in handle_post_start_commands causes directive leaks
+ let config_dir = repo.root_path().join(".config");
+ fs::create_dir_all(&config_dir).expect("Failed to create .config dir");
+ fs::write(
+ config_dir.join("wt.toml"),
+ r#"post-start-command = "echo 'test command executed'""#,
+ )
+ .expect("Failed to write project config");
- repo.commit("Add post-start command");
+ repo.commit("Add post-start command");
- // Pre-approve the command in user config
- fs::write(
- repo.test_config_path(),
- r#"worktree-path = "../{main-worktree}.{branch}"
+ // Pre-approve the command in user config
+ fs::write(
+ repo.test_config_path(),
+ r#"worktree-path = "../{main-worktree}.{branch}"
[[approved-commands]]
project = "test-repo"
command = "echo 'test command executed'"
"#,
- )
- .expect("Failed to write user config");
+ )
+ .expect("Failed to write user config");
- let output = exec_through_bash_wrapper(&repo, "switch", &["--create", "feature-with-hooks"]);
+ let output =
+ exec_through_bash_wrapper(&repo, "switch", &["--create", "feature-with-hooks"]);
- // The critical assertion: directives must never appear in user-facing output
- // This is where the bug occurs - "πŸ”„ Starting (background):" is printed with println!
- // which causes it to concatenate with the directive
- assert_no_directive_leaks(&output);
+ // The critical assertion: directives must never appear in user-facing output
+ // This is where the bug occurs - "πŸ”„ Starting (background):" is printed with println!
+ // which causes it to concatenate with the directive
+ assert_no_directive_leaks(&output);
- // Normalize paths in output for snapshot testing
- let normalized = regex::Regex::new(r"/private/var/folders/[^/]+/[^/]+/T/\.tmp[^/]+")
- .unwrap()
- .replace_all(&output, "[TMPDIR]");
+ // Normalize paths in output for snapshot testing
+ let normalized = regex::Regex::new(r"/private/var/folders/[^/]+/[^/]+/T/\.tmp[^/]+")
+ .unwrap()
+ .replace_all(&output, "[TMPDIR]");
- // Snapshot the output
- assert_snapshot!(normalized.as_ref());
-}
+ // Snapshot the output
+ assert_snapshot!(normalized.as_ref());
+ }
-#[test]
-fn test_switch_with_execute_through_wrapper() {
- let repo = TestRepo::new();
- repo.commit("Initial commit");
-
- // Use --force to skip approval prompt in tests
- let output = exec_through_bash_wrapper(
- &repo,
- "switch",
- &[
- "--create",
- "test-exec",
- "--execute",
- "echo executed",
- "--force",
- ],
- );
+ #[test]
+ fn test_switch_with_execute_through_wrapper() {
+ let repo = TestRepo::new();
+ repo.commit("Initial commit");
+
+ // Use --force to skip approval prompt in tests
+ let output = exec_through_bash_wrapper(
+ &repo,
+ "switch",
+ &[
+ "--create",
+ "test-exec",
+ "--execute",
+ "echo executed",
+ "--force",
+ ],
+ );
- // No directives should leak
- assert_no_directive_leaks(&output);
+ // No directives should leak
+ assert_no_directive_leaks(&output);
- // The executed command output should appear
- assert!(
- output.contains("executed"),
- "Execute command output missing"
- );
+ // The executed command output should appear
+ assert!(
+ output.contains("executed"),
+ "Execute command output missing"
+ );
- // Normalize paths in output for snapshot testing
- let normalized = regex::Regex::new(r"/private/var/folders/[^/]+/[^/]+/T/\.tmp[^/]+")
- .unwrap()
- .replace_all(&output, "[TMPDIR]");
+ // Normalize paths in output for snapshot testing
+ let normalized = regex::Regex::new(r"/private/var/folders/[^/]+/[^/]+/T/\.tmp[^/]+")
+ .unwrap()
+ .replace_all(&output, "[TMPDIR]");
- // Snapshot the output
- assert_snapshot!(normalized.as_ref());
-}
+ // Snapshot the output
+ assert_snapshot!(normalized.as_ref());
+ }
-#[test]
-fn test_remove_through_wrapper_no_directive_leak() {
- let mut repo = TestRepo::new();
- repo.commit("Initial commit");
+ #[test]
+ fn test_remove_through_wrapper_no_directive_leak() {
+ let mut repo = TestRepo::new();
+ repo.commit("Initial commit");
- // Create a worktree to remove
- repo.add_worktree("to-remove", "to-remove");
+ // Create a worktree to remove
+ repo.add_worktree("to-remove", "to-remove");
- let output = exec_through_bash_wrapper(&repo, "remove", &["to-remove"]);
+ let output = exec_through_bash_wrapper(&repo, "remove", &["to-remove"]);
- // No directives should leak
- assert_no_directive_leaks(&output);
+ // No directives should leak
+ assert_no_directive_leaks(&output);
- // Normalize paths in output for snapshot testing
- let normalized = regex::Regex::new(r"/private/var/folders/[^/]+/[^/]+/T/\.tmp[^/]+")
- .unwrap()
- .replace_all(&output, "[TMPDIR]");
+ // Normalize paths in output for snapshot testing
+ let normalized = regex::Regex::new(r"/private/var/folders/[^/]+/[^/]+/T/\.tmp[^/]+")
+ .unwrap()
+ .replace_all(&output, "[TMPDIR]");
- // Snapshot the output
- assert_snapshot!(normalized.as_ref());
-}
+ // Snapshot the output
+ assert_snapshot!(normalized.as_ref());
+ }
+
+ #[test]
+ fn test_merge_through_wrapper_no_directive_leak() {
+ let mut repo = TestRepo::new();
+ repo.commit("Initial commit");
+
+ // Create a feature branch
+ repo.add_worktree("feature", "feature");
+
+ let output = exec_through_bash_wrapper(&repo, "merge", &["main"]);
+
+ // No directives should leak
+ assert_no_directive_leaks(&output);
+
+ // Normalize paths in output for snapshot testing
+ let normalized = regex::Regex::new(r"/private/var/folders/[^/]+/[^/]+/T/\.tmp[^/]+")
+ .unwrap()
+ .replace_all(&output, "[TMPDIR]");
+
+ // Snapshot the output
+ assert_snapshot!(normalized.as_ref());
+ }
+
+ #[test]
+ fn test_wrapper_preserves_progress_messages() {
+ let repo = TestRepo::new();
+ repo.commit("Initial commit");
+
+ // Configure a post-start background command that will trigger progress output
+ let config_dir = repo.root_path().join(".config");
+ fs::create_dir_all(&config_dir).expect("Failed to create .config dir");
+ fs::write(
+ config_dir.join("wt.toml"),
+ r#"post-start-command = "echo 'background task'""#,
+ )
+ .expect("Failed to write project config");
+
+ repo.commit("Add post-start command");
+
+ // Pre-approve the command in user config
+ fs::write(
+ repo.test_config_path(),
+ r#"worktree-path = "../{main-worktree}.{branch}"
+
+[[approved-commands]]
+project = "test-repo"
+command = "echo 'background task'"
+"#,
+ )
+ .expect("Failed to write user config");
+
+ let output = exec_through_bash_wrapper(&repo, "switch", &["--create", "feature-bg"]);
+
+ // No directives should leak
+ assert_no_directive_leaks(&output);
+
+ // Critical assertion: progress messages should appear to users
+ // This is the test that catches the bug where progress() is suppressed in directive mode
+ assert!(
+ output.contains("Starting (background)"),
+ "Progress message 'Starting (background)' missing from output. \
+ Output:\n{}",
+ output
+ );
-#[test]
-fn test_merge_through_wrapper_no_directive_leak() {
- let mut repo = TestRepo::new();
- repo.commit("Initial commit");
+ // The background command itself should be shown via gutter formatting
+ assert!(
+ output.contains("background task"),
+ "Background command content missing from output"
+ );
+
+ // Normalize paths in output for snapshot testing
+ let normalized = regex::Regex::new(r"/private/var/folders/[^/]+/[^/]+/T/\.tmp[^/]+")
+ .unwrap()
+ .replace_all(&output, "[TMPDIR]");
+
+ // Snapshot the full output
+ assert_snapshot!(normalized.as_ref());
+ }
+
+ // ============================================================================
+ // Fish Shell Wrapper Tests
+ // ============================================================================
+ //
+ // These tests verify that the Fish shell wrapper correctly:
+ // 1. Parses NUL-delimited directives from `wt --internal`
+ // 2. Never leaks directives to users
+ // 3. Preserves all user-visible output (progress, success, hints)
+ // 4. Handles Fish-specific psub process substitution correctly
+ //
+ // Fish uses `read -z` to parse NUL-delimited chunks and `psub` for
+ // process substitution. These have known limitations (fish-shell #1040)
+ // but work correctly for our use case.
+
+ #[test]
+ fn test_fish_switch_create_no_directive_leak() {
+ let repo = TestRepo::new();
+ repo.commit("Initial commit");
+
+ let output = exec_through_fish_wrapper(&repo, "switch", &["--create", "fish-feature"]);
+
+ // Critical: directives must never appear in user-facing output
+ assert_no_directive_leaks(&output);
+
+ // Normalize paths in output for snapshot testing
+ let normalized = regex::Regex::new(r"/private/var/folders/[^/]+/[^/]+/T/\.tmp[^/]+")
+ .unwrap()
+ .replace_all(&output, "[TMPDIR]");
+
+ assert_snapshot!(normalized.as_ref());
+ }
+
+ #[test]
+ fn test_fish_wrapper_preserves_progress_messages() {
+ let repo = TestRepo::new();
+ repo.commit("Initial commit");
+
+ // Configure a post-start background command that will trigger progress output
+ let config_dir = repo.root_path().join(".config");
+ fs::create_dir_all(&config_dir).expect("Failed to create .config dir");
+ fs::write(
+ config_dir.join("wt.toml"),
+ r#"post-start-command = "echo 'fish background task'""#,
+ )
+ .expect("Failed to write project config");
+
+ repo.commit("Add post-start command");
+
+ // Pre-approve the command in user config
+ fs::write(
+ repo.test_config_path(),
+ r#"worktree-path = "../{main-worktree}.{branch}"
+
+[[approved-commands]]
+project = "test-repo"
+command = "echo 'fish background task'"
+"#,
+ )
+ .expect("Failed to write user config");
+
+ let output = exec_through_fish_wrapper(&repo, "switch", &["--create", "fish-bg"]);
+
+ // No directives should leak
+ assert_no_directive_leaks(&output);
+
+ // Critical: progress messages should appear to users through Fish wrapper
+ assert!(
+ output.contains("Starting (background)"),
+ "Progress message 'Starting (background)' missing from Fish wrapper output. \
+ Output:\n{}",
+ output
+ );
+
+ // The background command itself should be shown via gutter formatting
+ assert!(
+ output.contains("fish background task"),
+ "Background command content missing from output"
+ );
- // Create a feature branch
- repo.add_worktree("feature", "feature");
+ // Normalize paths in output for snapshot testing
+ let normalized = regex::Regex::new(r"/private/var/folders/[^/]+/[^/]+/T/\.tmp[^/]+")
+ .unwrap()
+ .replace_all(&output, "[TMPDIR]");
- let output = exec_through_bash_wrapper(&repo, "merge", &["main"]);
+ assert_snapshot!(normalized.as_ref());
+ }
+
+ #[test]
+ fn test_fish_remove_no_directive_leak() {
+ let mut repo = TestRepo::new();
+ repo.commit("Initial commit");
+
+ // Create a worktree to remove
+ repo.add_worktree("fish-to-remove", "fish-to-remove");
+
+ let output = exec_through_fish_wrapper(&repo, "remove", &["fish-to-remove"]);
+
+ // No directives should leak
+ assert_no_directive_leaks(&output);
+
+ // Normalize paths in output for snapshot testing
+ let normalized = regex::Regex::new(r"/private/var/folders/[^/]+/[^/]+/T/\.tmp[^/]+")
+ .unwrap()
+ .replace_all(&output, "[TMPDIR]");
+
+ assert_snapshot!(normalized.as_ref());
+ }
+
+ #[test]
+ fn test_fish_multiline_command_execution() {
+ let repo = TestRepo::new();
+ repo.commit("Initial commit");
+
+ // Test that Fish wrapper handles multi-line commands correctly
+ // This tests Fish's NUL-byte parsing with embedded newlines
+ // Use actual newlines in the command string
+ let multiline_cmd = "echo 'line 1'; echo 'line 2'; echo 'line 3'";
+
+ // Use --force to skip approval prompt in tests
+ let output = exec_through_fish_wrapper(
+ &repo,
+ "switch",
+ &[
+ "--create",
+ "fish-multiline",
+ "--execute",
+ multiline_cmd,
+ "--force",
+ ],
+ );
- // No directives should leak
- assert_no_directive_leaks(&output);
+ // No directives should leak
+ assert_no_directive_leaks(&output);
- // Normalize paths in output for snapshot testing
- let normalized = regex::Regex::new(r"/private/var/folders/[^/]+/[^/]+/T/\.tmp[^/]+")
- .unwrap()
- .replace_all(&output, "[TMPDIR]");
+ // All three lines should be executed and visible
+ assert!(output.contains("line 1"), "First line missing");
+ assert!(output.contains("line 2"), "Second line missing");
+ assert!(output.contains("line 3"), "Third line missing");
- // Snapshot the output
- assert_snapshot!(normalized.as_ref());
+ // Normalize paths in output for snapshot testing
+ let normalized = regex::Regex::new(r"/private/var/folders/[^/]+/[^/]+/T/\.tmp[^/]+")
+ .unwrap()
+ .replace_all(&output, "[TMPDIR]");
+
+ assert_snapshot!(normalized.as_ref());
+ }
+
+ #[test]
+ fn test_fish_wrapper_handles_empty_chunks() {
+ let repo = TestRepo::new();
+ repo.commit("Initial commit");
+
+ // Test edge case: command that produces minimal output
+ // This verifies Fish's `test -n "$chunk"` check works correctly
+ let output = exec_through_fish_wrapper(&repo, "switch", &["--create", "fish-minimal"]);
+
+ // No directives should leak even with minimal output
+ assert_no_directive_leaks(&output);
+
+ // Should still show success message
+ assert!(
+ output.contains("Created new worktree"),
+ "Success message missing from minimal output"
+ );
+
+ // Normalize paths in output for snapshot testing
+ let normalized = regex::Regex::new(r"/private/var/folders/[^/]+/[^/]+/T/\.tmp[^/]+")
+ .unwrap()
+ .replace_all(&output, "[TMPDIR]");
+
+ assert_snapshot!(normalized.as_ref());
+ }
}
diff --git a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__fish_multiline_command_execution.snap b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__fish_multiline_command_execution.snap
new file mode 100644
index 000000000..469ec5864
--- /dev/null
+++ b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__fish_multiline_command_execution.snap
@@ -0,0 +1,8 @@
+---
+source: tests/integration_tests/shell_wrapper.rs
+expression: normalized.as_ref()
+---
+Created new worktree for fish-multiline at [TMPDIR]/test-repo.fish-multiline
+line 1
+line 2
+line 3
diff --git a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__fish_remove_no_directive_leak.snap b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__fish_remove_no_directive_leak.snap
new file mode 100644
index 000000000..ba57bc54a
--- /dev/null
+++ b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__fish_remove_no_directive_leak.snap
@@ -0,0 +1,5 @@
+---
+source: tests/integration_tests/shell_wrapper.rs
+expression: normalized.as_ref()
+---
+Removed worktree for fish-to-remove
diff --git a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__fish_switch_create_no_directive_leak.snap b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__fish_switch_create_no_directive_leak.snap
new file mode 100644
index 000000000..3653a65c8
--- /dev/null
+++ b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__fish_switch_create_no_directive_leak.snap
@@ -0,0 +1,7 @@
+---
+source: tests/integration_tests/shell_wrapper.rs
+expression: normalized.as_ref()
+---
+Created new worktree for fish-feature at [TMPDIR]/test-repo.fish-feature
+
+To enable automatic cd, run: wt configure-shell
diff --git a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__fish_wrapper_handles_empty_chunks.snap b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__fish_wrapper_handles_empty_chunks.snap
new file mode 100644
index 000000000..07cb096e3
--- /dev/null
+++ b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__fish_wrapper_handles_empty_chunks.snap
@@ -0,0 +1,7 @@
+---
+source: tests/integration_tests/shell_wrapper.rs
+expression: normalized.as_ref()
+---
+Created new worktree for fish-minimal at [TMPDIR]/test-repo.fish-minimal
+
+To enable automatic cd, run: wt configure-shell
diff --git a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__fish_wrapper_preserves_progress_messages.snap b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__fish_wrapper_preserves_progress_messages.snap
new file mode 100644
index 000000000..54ffee1a0
--- /dev/null
+++ b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__fish_wrapper_preserves_progress_messages.snap
@@ -0,0 +1,10 @@
+---
+source: tests/integration_tests/shell_wrapper.rs
+expression: normalized.as_ref()
+---
+πŸ”„ Starting (background):
+ echo 'fish background task'
+
+Created new worktree for fish-bg at [TMPDIR]/test-repo.fish-bg
+
+To enable automatic cd, run: wt configure-shell
diff --git a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__merge_through_wrapper_no_directive_leak.snap b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__merge_through_wrapper_no_directive_leak.snap
index 257f059b0..e87fc5646 100644
--- a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__merge_through_wrapper_no_directive_leak.snap
+++ b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__merge_through_wrapper_no_directive_leak.snap
@@ -1,5 +1,6 @@
---
source: tests/integration_tests/shell_wrapper.rs
-expression: output
+expression: normalized.as_ref()
---
+πŸ”„ Validating merge...
Already on main, nothing to merge
diff --git a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__switch_create_through_wrapper_no_directive_leak.snap b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__switch_create_through_wrapper_no_directive_leak.snap
index b66a41aa2..b422750b2 100644
--- a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__switch_create_through_wrapper_no_directive_leak.snap
+++ b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__switch_create_through_wrapper_no_directive_leak.snap
@@ -3,3 +3,5 @@ source: tests/integration_tests/shell_wrapper.rs
expression: normalized.as_ref()
---
Created new worktree for feature at [TMPDIR]/test-repo.feature
+
+To enable automatic cd, run: wt configure-shell
diff --git a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__switch_with_post_start_command_no_directive_leak.snap b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__switch_with_post_start_command_no_directive_leak.snap
index 97233a8db..41378e994 100644
--- a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__switch_with_post_start_command_no_directive_leak.snap
+++ b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__switch_with_post_start_command_no_directive_leak.snap
@@ -2,4 +2,9 @@
source: tests/integration_tests/shell_wrapper.rs
expression: normalized.as_ref()
---
+πŸ”„ Starting (background):
+ echo 'test command executed'
+
Created new worktree for feature-with-hooks at [TMPDIR]/test-repo.feature-with-hooks
+
+To enable automatic cd, run: wt configure-shell
diff --git a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__fish_multiline_command_execution.snap b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__fish_multiline_command_execution.snap
new file mode 100644
index 000000000..469ec5864
--- /dev/null
+++ b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__fish_multiline_command_execution.snap
@@ -0,0 +1,8 @@
+---
+source: tests/integration_tests/shell_wrapper.rs
+expression: normalized.as_ref()
+---
+Created new worktree for fish-multiline at [TMPDIR]/test-repo.fish-multiline
+line 1
+line 2
+line 3
diff --git a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__fish_remove_no_directive_leak.snap b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__fish_remove_no_directive_leak.snap
new file mode 100644
index 000000000..ba57bc54a
--- /dev/null
+++ b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__fish_remove_no_directive_leak.snap
@@ -0,0 +1,5 @@
+---
+source: tests/integration_tests/shell_wrapper.rs
+expression: normalized.as_ref()
+---
+Removed worktree for fish-to-remove
diff --git a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__fish_switch_create_no_directive_leak.snap b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__fish_switch_create_no_directive_leak.snap
new file mode 100644
index 000000000..3653a65c8
--- /dev/null
+++ b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__fish_switch_create_no_directive_leak.snap
@@ -0,0 +1,7 @@
+---
+source: tests/integration_tests/shell_wrapper.rs
+expression: normalized.as_ref()
+---
+Created new worktree for fish-feature at [TMPDIR]/test-repo.fish-feature
+
+To enable automatic cd, run: wt configure-shell
diff --git a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__fish_wrapper_handles_empty_chunks.snap b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__fish_wrapper_handles_empty_chunks.snap
new file mode 100644
index 000000000..07cb096e3
--- /dev/null
+++ b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__fish_wrapper_handles_empty_chunks.snap
@@ -0,0 +1,7 @@
+---
+source: tests/integration_tests/shell_wrapper.rs
+expression: normalized.as_ref()
+---
+Created new worktree for fish-minimal at [TMPDIR]/test-repo.fish-minimal
+
+To enable automatic cd, run: wt configure-shell
diff --git a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__fish_wrapper_preserves_progress_messages.snap b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__fish_wrapper_preserves_progress_messages.snap
new file mode 100644
index 000000000..54ffee1a0
--- /dev/null
+++ b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__fish_wrapper_preserves_progress_messages.snap
@@ -0,0 +1,10 @@
+---
+source: tests/integration_tests/shell_wrapper.rs
+expression: normalized.as_ref()
+---
+πŸ”„ Starting (background):
+ echo 'fish background task'
+
+Created new worktree for fish-bg at [TMPDIR]/test-repo.fish-bg
+
+To enable automatic cd, run: wt configure-shell
diff --git a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_through_wrapper_no_directive_leak.snap b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_through_wrapper_no_directive_leak.snap
new file mode 100644
index 000000000..e87fc5646
--- /dev/null
+++ b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__merge_through_wrapper_no_directive_leak.snap
@@ -0,0 +1,6 @@
+---
+source: tests/integration_tests/shell_wrapper.rs
+expression: normalized.as_ref()
+---
+πŸ”„ Validating merge...
+Already on main, nothing to merge
diff --git a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__remove_through_wrapper_no_directive_leak.snap b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__remove_through_wrapper_no_directive_leak.snap
new file mode 100644
index 000000000..5b5123bd0
--- /dev/null
+++ b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__remove_through_wrapper_no_directive_leak.snap
@@ -0,0 +1,5 @@
+---
+source: tests/integration_tests/shell_wrapper.rs
+expression: normalized.as_ref()
+---
+Removed worktree for to-remove
diff --git a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__switch_create_through_wrapper_no_directive_leak.snap b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__switch_create_through_wrapper_no_directive_leak.snap
new file mode 100644
index 000000000..b422750b2
--- /dev/null
+++ b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__switch_create_through_wrapper_no_directive_leak.snap
@@ -0,0 +1,7 @@
+---
+source: tests/integration_tests/shell_wrapper.rs
+expression: normalized.as_ref()
+---
+Created new worktree for feature at [TMPDIR]/test-repo.feature
+
+To enable automatic cd, run: wt configure-shell
diff --git a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__switch_with_execute_through_wrapper.snap b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__switch_with_execute_through_wrapper.snap
new file mode 100644
index 000000000..884eb3b3b
--- /dev/null
+++ b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__switch_with_execute_through_wrapper.snap
@@ -0,0 +1,6 @@
+---
+source: tests/integration_tests/shell_wrapper.rs
+expression: normalized.as_ref()
+---
+Created new worktree for test-exec at [TMPDIR]/test-repo.test-exec
+executed
diff --git a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__switch_with_post_start_command_no_directive_leak.snap b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__switch_with_post_start_command_no_directive_leak.snap
new file mode 100644
index 000000000..41378e994
--- /dev/null
+++ b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__switch_with_post_start_command_no_directive_leak.snap
@@ -0,0 +1,10 @@
+---
+source: tests/integration_tests/shell_wrapper.rs
+expression: normalized.as_ref()
+---
+πŸ”„ Starting (background):
+ echo 'test command executed'
+
+Created new worktree for feature-with-hooks at [TMPDIR]/test-repo.feature-with-hooks
+
+To enable automatic cd, run: wt configure-shell
diff --git a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__wrapper_preserves_progress_messages.snap b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__wrapper_preserves_progress_messages.snap
new file mode 100644
index 000000000..18bdf6bd7
--- /dev/null
+++ b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__tests__wrapper_preserves_progress_messages.snap
@@ -0,0 +1,10 @@
+---
+source: tests/integration_tests/shell_wrapper.rs
+expression: normalized.as_ref()
+---
+πŸ”„ Starting (background):
+ echo 'background task'
+
+Created new worktree for feature-bg at [TMPDIR]/test-repo.feature-bg
+
+To enable automatic cd, run: wt configure-shell
diff --git a/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__wrapper_preserves_progress_messages.snap b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__wrapper_preserves_progress_messages.snap
new file mode 100644
index 000000000..18bdf6bd7
--- /dev/null
+++ b/tests/integration_tests/snapshots/integration__integration_tests__shell_wrapper__wrapper_preserves_progress_messages.snap
@@ -0,0 +1,10 @@
+---
+source: tests/integration_tests/shell_wrapper.rs
+expression: normalized.as_ref()
+---
+πŸ”„ Starting (background):
+ echo 'background task'
+
+Created new worktree for feature-bg at [TMPDIR]/test-repo.feature-bg
+
+To enable automatic cd, run: wt configure-shell
diff --git a/tests/snapshots/integration__integration_tests__e2e_shell__bash_e2e_switch_linebreaks.snap b/tests/snapshots/integration__integration_tests__e2e_shell__bash_e2e_switch_linebreaks.snap
index 973ea8331..673e47d2a 100644
--- a/tests/snapshots/integration__integration_tests__e2e_shell__bash_e2e_switch_linebreaks.snap
+++ b/tests/snapshots/integration__integration_tests__e2e_shell__bash_e2e_switch_linebreaks.snap
@@ -3,4 +3,6 @@ source: tests/integration_tests/e2e_shell.rs
expression: output
---
Created new worktree for test-branch at [REPO].test-branch
+
+To enable automatic cd, run: wt configure-shell
MARKER
diff --git a/tests/snapshots/integration__integration_tests__switch__switch_existing_internal.snap b/tests/snapshots/integration__integration_tests__switch__switch_existing_internal.snap
index f95aa9dbb..e5317ec7b 100644
Binary files a/tests/snapshots/integration__integration_tests__switch__switch_existing_internal.snap and b/tests/snapshots/integration__integration_tests__switch__switch_existing_internal.snap differ
diff --git a/tests/snapshots/integration__integration_tests__switch__switch_internal_mode.snap b/tests/snapshots/integration__integration_tests__switch__switch_internal_mode.snap
index 36bc51d45..28874ef36 100644
Binary files a/tests/snapshots/integration__integration_tests__switch__switch_internal_mode.snap and b/tests/snapshots/integration__integration_tests__switch__switch_internal_mode.snap differ