Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
refactor(tests): unify PTY execution into common/pty module (#675)
Maximilian Roos2293dee0436f
diff --git a/tests/common/mod.rs b/tests/common/mod.rsindex aadc2d098..e61bacddb 100644--- a/tests/common/mod.rs+++ b/tests/common/mod.rs@@ -42,6 +42,9 @@ pub mod list_snapshots;// Progressive output tests use PTY and are Unix-only for now#[cfg(unix)]pub mod progressive_output;+// PTY execution helpers - Unix-only+#[cfg(unix)]+pub mod pty;// Shell integration tests - cross-platform with PTY support#[cfg(feature = "shell-integration-tests")]pub mod shell;diff --git a/tests/common/pty.rs b/tests/common/pty.rsnew file mode 100644index 000000000..64b24806b--- /dev/null+++ b/tests/common/pty.rs@@ -0,0 +1,225 @@+//! PTY execution helpers for integration tests.+//!+//! Provides unified PTY execution with consistent:+//! - Environment isolation via `configure_pty_command()`+//! - CRLF normalization (PTYs use CRLF on some platforms)+//! - Coverage passthrough for subprocess coverage collection+//!+//! # Usage+//!+//! ```ignore+//! use crate::common::pty::exec_in_pty;+//!+//! // Simple execution with single input+//! let (output, exit_code) = exec_in_pty(+//! "wt",+//! &["switch", "--create", "feature"],+//! repo.root_path(),+//! &repo.test_env_vars(),+//! "y\n",+//! );+//!+//! // With HOME override for shell config tests+//! let (output, exit_code) = exec_in_pty_with_home(+//! "wt",+//! &["config", "shell", "install"],+//! repo.root_path(),+//! &repo.test_env_vars(),+//! "y\n",+//! temp_home.path(),+//! );+//! ```++use portable_pty::CommandBuilder;+use std::io::{Read, Write};+use std::path::Path;++/// Execute a command in a PTY with optional interactive input.+///+/// Returns (combined_output, exit_code).+///+/// Output is normalized:+/// - CRLF → LF (PTYs use CRLF on some platforms)+///+/// Environment is isolated via `configure_pty_command()`:+/// - Cleared and rebuilt with minimal required vars+/// - Coverage env vars passed through+pub fn exec_in_pty(+ command: &str,+ args: &[&str],+ working_dir: &Path,+ env_vars: &[(String, String)],+ input: &str,+) -> (String, i32) {+ exec_in_pty_impl(command, args, working_dir, env_vars, input, None)+}++/// Execute a command in a PTY with HOME directory override.+///+/// Same as `exec_in_pty` but overrides HOME and XDG_CONFIG_HOME to the+/// specified directory. Use this for tests that need isolated shell config.+pub fn exec_in_pty_with_home(+ command: &str,+ args: &[&str],+ working_dir: &Path,+ env_vars: &[(String, String)],+ input: &str,+ home_dir: &Path,+) -> (String, i32) {+ exec_in_pty_impl(command, args, working_dir, env_vars, input, Some(home_dir))+}++/// Internal implementation with optional home override.+fn exec_in_pty_impl(+ command: &str,+ args: &[&str],+ working_dir: &Path,+ env_vars: &[(String, String)],+ input: &str,+ home_dir: Option<&Path>,+) -> (String, i32) {+ let pair = super::open_pty();++ let mut cmd = CommandBuilder::new(command);+ for arg in args {+ cmd.arg(*arg);+ }+ cmd.cwd(working_dir);++ // Set up isolated environment with coverage passthrough+ super::configure_pty_command(&mut cmd);++ // Add test-specific environment variables+ for (key, value) in env_vars {+ cmd.env(key, value);+ }++ // Override HOME if provided (must be after configure_pty_command which sets HOME)+ if let Some(home) = home_dir {+ cmd.env("HOME", home.to_string_lossy().to_string());+ cmd.env(+ "XDG_CONFIG_HOME",+ home.join(".config").to_string_lossy().to_string(),+ );+ // Windows: the `home` crate uses USERPROFILE for home_dir()+ #[cfg(windows)]+ cmd.env("USERPROFILE", home.to_string_lossy().to_string());+ }++ let mut child = pair.slave.spawn_command(cmd).unwrap();+ drop(pair.slave); // Close slave in parent++ // Get reader and writer for the PTY master+ let mut reader = pair.master.try_clone_reader().unwrap();+ let mut writer = pair.master.take_writer().unwrap();++ // Write input to the PTY (simulating user typing)+ if !input.is_empty() {+ writer.write_all(input.as_bytes()).unwrap();+ writer.flush().unwrap();+ }+ drop(writer); // Close writer so command sees EOF++ // Read all output+ let mut buf = String::new();+ reader.read_to_string(&mut buf).unwrap();++ // Wait for child to exit+ let exit_status = child.wait().unwrap();+ let exit_code = exit_status.exit_code() as i32;++ // Normalize CRLF to LF (PTYs use CRLF on some platforms)+ let normalized = buf.replace("\r\n", "\n");++ (normalized, exit_code)+}++/// Execute a pre-configured CommandBuilder in a PTY.+///+/// Use this when you need custom command configuration beyond what `exec_in_pty`+/// and `exec_in_pty_with_home` provide. You're responsible for:+/// - Setting up the command (binary, args, cwd)+/// - Calling `configure_pty_command()` or equivalent for env isolation+/// - Any additional env vars+///+/// Returns (combined_output, exit_code).+pub fn exec_cmd_in_pty(cmd: CommandBuilder, input: &str) -> (String, i32) {+ let pair = super::open_pty();++ let mut child = pair.slave.spawn_command(cmd).unwrap();+ drop(pair.slave);++ let mut reader = pair.master.try_clone_reader().unwrap();+ let mut writer = pair.master.take_writer().unwrap();++ if !input.is_empty() {+ writer.write_all(input.as_bytes()).unwrap();+ writer.flush().unwrap();+ }+ drop(writer);++ let mut buf = String::new();+ reader.read_to_string(&mut buf).unwrap();++ let exit_status = child.wait().unwrap();+ let exit_code = exit_status.exit_code() as i32;++ // Normalize CRLF to LF+ let normalized = buf.replace("\r\n", "\n");++ (normalized, exit_code)+}++/// Execute a command in a PTY with multiple sequential inputs.+///+/// Each input is written and flushed before moving to the next.+/// Use this when multiple distinct user inputs are needed (e.g., multi-step prompts).+///+/// Returns (combined_output, exit_code).+pub fn exec_in_pty_multi_input(+ command: &str,+ args: &[&str],+ working_dir: &Path,+ env_vars: &[(String, String)],+ inputs: &[&str],+) -> (String, i32) {+ let pair = super::open_pty();++ let mut cmd = CommandBuilder::new(command);+ for arg in args {+ cmd.arg(*arg);+ }+ cmd.cwd(working_dir);++ // Set up isolated environment with coverage passthrough+ super::configure_pty_command(&mut cmd);++ // Add test-specific environment variables+ for (key, value) in env_vars {+ cmd.env(key, value);+ }++ let mut child = pair.slave.spawn_command(cmd).unwrap();+ drop(pair.slave);++ let mut reader = pair.master.try_clone_reader().unwrap();+ let mut writer = pair.master.take_writer().unwrap();++ // Write all inputs sequentially+ for input in inputs {+ writer.write_all(input.as_bytes()).unwrap();+ writer.flush().unwrap();+ }+ drop(writer);++ let mut buf = String::new();+ reader.read_to_string(&mut buf).unwrap();++ let exit_status = child.wait().unwrap();+ let exit_code = exit_status.exit_code() as i32;++ // Normalize CRLF to LF+ let normalized = buf.replace("\r\n", "\n");++ (normalized, exit_code)+}diff --git a/tests/integration_tests/approval_pty.rs b/tests/integration_tests/approval_pty.rsindex a86c86b10..4143b55a6 100644--- a/tests/integration_tests/approval_pty.rs+++ b/tests/integration_tests/approval_pty.rs@@ -8,64 +8,28 @@//! to simulate interactive terminals. The non-PTY tests in `approval_ui.rs` verify the//! error case (non-TTY environments).+use crate::common::pty::exec_in_pty;use crate::common::{TestRepo, add_pty_binary_path_filters, add_pty_filters, repo};use insta::assert_snapshot;use insta_cmd::get_cargo_bin;-use portable_pty::CommandBuilder;use rstest::rstest;-use std::io::{Read, Write};-use std::path::Path;-/// Execute a command in a PTY with interactive input+/// Execute wt in a PTY with interactive input.///-/// Returns (combined_output, exit_code)-fn exec_in_pty_with_input(- command: &str,+/// Thin wrapper around `exec_in_pty` that passes the wt binary path.+fn exec_wt_in_pty(+ repo: &TestRepo,args: &[&str],- working_dir: &Path,env_vars: &[(String, String)],input: &str,) -> (String, i32) {- let pair = crate::common::open_pty();-- let mut cmd = CommandBuilder::new(command);- for arg in args {- cmd.arg(arg);- }- cmd.cwd(working_dir);-- // Set up isolated environment with coverage passthrough- crate::common::configure_pty_command(&mut cmd);-- // Add test-specific environment variables- for (key, value) in env_vars {- cmd.env(key, value);- }-- let mut child = pair.slave.spawn_command(cmd).unwrap();- drop(pair.slave); // Close slave in parent-- // Get reader and writer for the PTY master- let mut reader = pair.master.try_clone_reader().unwrap();- let mut writer = pair.master.take_writer().unwrap();-- // Write input to the PTY (simulating user typing)- writer.write_all(input.as_bytes()).unwrap();- writer.flush().unwrap();- drop(writer); // Close writer so command sees EOF-- // Read all output- let mut buf = String::new();- reader.read_to_string(&mut buf).unwrap();-- // Wait for child to exit- let exit_status = child.wait().unwrap();- let exit_code = exit_status.exit_code() as i32;-- // Normalize CRLF to LF (PTYs use CRLF on some platforms)- let normalized = buf.replace("\r\n", "\n");-- (normalized, exit_code)+ exec_in_pty(+ get_cargo_bin("wt").to_str().unwrap(),+ args,+ repo.root_path(),+ env_vars,+ input,+ )}/// Create insta settings for approval PTY tests.@@ -109,10 +73,9 @@ fn test_approval_prompt_accept(repo: TestRepo) {// Configure shell integration so we get the "Restart shell" hint instead of the promptrepo.configure_shell_integration();let env_vars = test_env_vars_with_shell(&repo);- let (output, exit_code) = exec_in_pty_with_input(- get_cargo_bin("wt").to_str().unwrap(),+ let (output, exit_code) = exec_wt_in_pty(+ &repo,&["switch", "--create", "test-approve"],- repo.root_path(),&env_vars,"y\n",);@@ -134,10 +97,9 @@ fn test_approval_prompt_decline(repo: TestRepo) {// Configure shell integration so we get the "Restart shell" hint instead of the promptrepo.configure_shell_integration();let env_vars = test_env_vars_with_shell(&repo);- let (output, exit_code) = exec_in_pty_with_input(- get_cargo_bin("wt").to_str().unwrap(),+ let (output, exit_code) = exec_wt_in_pty(+ &repo,&["switch", "--create", "test-decline"],- repo.root_path(),&env_vars,"n\n",);@@ -165,10 +127,9 @@ third = "echo 'Third command'"// Configure shell integration so we get the "Restart shell" hint instead of the promptrepo.configure_shell_integration();let env_vars = test_env_vars_with_shell(&repo);- let (output, exit_code) = exec_in_pty_with_input(- get_cargo_bin("wt").to_str().unwrap(),+ let (output, exit_code) = exec_wt_in_pty(+ &repo,&["switch", "--create", "test-multi"],- repo.root_path(),&env_vars,"y\n",);@@ -218,10 +179,9 @@ fn test_approval_prompt_permission_error(repo: TestRepo) {// Configure shell integration so we get the "Restart shell" hint instead of the promptrepo.configure_shell_integration();let env_vars = test_env_vars_with_shell(&repo);- let (output, exit_code) = exec_in_pty_with_input(- get_cargo_bin("wt").to_str().unwrap(),+ let (output, exit_code) = exec_wt_in_pty(+ &repo,&["switch", "--create", "test-permission"],- repo.root_path(),&env_vars,"y\n",);@@ -264,10 +224,9 @@ test = "echo 'Running tests...'"// Configure shell integration so we get the "Restart shell" hint instead of the promptrepo.configure_shell_integration();let env_vars = test_env_vars_with_shell(&repo);- let (output, exit_code) = exec_in_pty_with_input(- get_cargo_bin("wt").to_str().unwrap(),+ let (output, exit_code) = exec_wt_in_pty(+ &repo,&["switch", "--create", "test-named"],- repo.root_path(),&env_vars,"y\n",);@@ -315,10 +274,9 @@ approved-commands = ["echo 'Second command'"]// Configure shell integration so we get the "Restart shell" hint instead of the promptrepo.configure_shell_integration();let env_vars = test_env_vars_with_shell(&repo);- let (output, exit_code) = exec_in_pty_with_input(- get_cargo_bin("wt").to_str().unwrap(),+ let (output, exit_code) = exec_wt_in_pty(+ &repo,&["switch", "--create", "test-mixed-accept"],- repo.root_path(),&env_vars,"y\n",);@@ -372,10 +330,9 @@ approved-commands = ["echo 'Second command'"]// Configure shell integration so we get the "Restart shell" hint instead of the promptrepo.configure_shell_integration();let env_vars = test_env_vars_with_shell(&repo);- let (output, exit_code) = exec_in_pty_with_input(- get_cargo_bin("wt").to_str().unwrap(),+ let (output, exit_code) = exec_wt_in_pty(+ &repo,&["switch", "--create", "test-mixed-decline"],- repo.root_path(),&env_vars,"n\n",);@@ -431,13 +388,7 @@ fn test_approval_prompt_remove_decline(repo: TestRepo) {let env_vars = test_env_vars_with_shell(&repo);// Decline the approval prompt- let (output, exit_code) = exec_in_pty_with_input(- get_cargo_bin("wt").to_str().unwrap(),- &["remove", "to-remove"],- repo.root_path(),- &env_vars,- "n\n",- );+ let (output, exit_code) = exec_wt_in_pty(&repo, &["remove", "to-remove"], &env_vars, "n\n");assert_eq!(exit_code, 0,diff --git a/tests/integration_tests/configure_shell.rs b/tests/integration_tests/configure_shell.rsindex 6394b2788..a7479b568 100644--- a/tests/integration_tests/configure_shell.rs+++ b/tests/integration_tests/configure_shell.rs@@ -1532,21 +1532,17 @@ fn test_uninstall_shell_dry_run_multiple(repo: TestRepo, temp_home: TempDir) {// PTY-based tests for interactive install preview#[cfg(all(unix, feature = "shell-integration-tests"))]mod pty_tests {- use crate::common::{- TestRepo, add_pty_filters, configure_pty_command, open_pty, repo, temp_home,- };+ use crate::common::pty::exec_cmd_in_pty;+ use crate::common::{TestRepo, add_pty_filters, configure_pty_command, repo, temp_home};use insta::assert_snapshot;use insta_cmd::get_cargo_bin;use portable_pty::CommandBuilder;use rstest::rstest;use std::fs;- use std::io::{Read, Write};use tempfile::TempDir;/// Execute shell install command in a PTY with interactive inputfn exec_install_in_pty(temp_home: &TempDir, repo: &TestRepo, input: &str) -> (String, i32) {- let pair = open_pty();-let mut cmd = CommandBuilder::new(get_cargo_bin("wt"));cmd.arg("-C");cmd.arg(repo.root_path());@@ -1565,27 +1561,7 @@ mod pty_tests {// Using MISSING=1 skips the probe while still showing the compinit advisory.cmd.env("WORKTRUNK_TEST_COMPINIT_MISSING", "1");- let mut child = pair.slave.spawn_command(cmd).unwrap();- drop(pair.slave);-- let mut reader = pair.master.try_clone_reader().unwrap();- let mut writer = pair.master.take_writer().unwrap();-- // Write input to the PTY (simulating user typing)- writer.write_all(input.as_bytes()).unwrap();- writer.flush().unwrap();- drop(writer);-- let mut buf = String::new();- reader.read_to_string(&mut buf).unwrap();-- let exit_status = child.wait().unwrap();- let exit_code = exit_status.exit_code() as i32;-- // Normalize CRLF to LF (PTYs use CRLF on some platforms)- let normalized = buf.replace("\r\n", "\n");-- (normalized, exit_code)+ exec_cmd_in_pty(cmd, input)}/// Create insta settings for install PTY tests.diff --git a/tests/integration_tests/shell_integration_prompt.rs b/tests/integration_tests/shell_integration_prompt.rsindex 12e80375d..072624127 100644--- a/tests/integration_tests/shell_integration_prompt.rs+++ b/tests/integration_tests/shell_integration_prompt.rs@@ -201,88 +201,27 @@ fn test_switch_no_shell_env_shows_hint(repo: TestRepo) {#[cfg(all(unix, feature = "shell-integration-tests"))]mod pty_tests {use super::*;- use crate::common::{configure_pty_command, open_pty, setup_snapshot_settings};+ use crate::common::pty::exec_in_pty_with_home;+ use crate::common::{add_pty_filters, setup_snapshot_settings};use insta::assert_snapshot;use insta_cmd::get_cargo_bin;- use portable_pty::CommandBuilder;- use std::io::{Read, Write};use std::path::Path;use tempfile::TempDir;- /// Execute a command in a PTY with interactive input- fn exec_in_pty_with_input(- command: &str,- args: &[&str],- working_dir: &Path,- env_vars: &[(String, String)],- home_dir: Option<&Path>,- input: &str,- ) -> (String, i32) {- let pair = open_pty();-- let mut cmd = CommandBuilder::new(command);- for arg in args {- cmd.arg(arg);- }- cmd.cwd(working_dir);-- // Set up isolated environment with coverage passthrough- configure_pty_command(&mut cmd);-- // Add test-specific environment variables- for (key, value) in env_vars {- cmd.env(key, value);- }-- // Set HOME to isolated temp directory if provided- // (must be after configure_pty_command which sets HOME to real home)- if let Some(home) = home_dir {- cmd.env("HOME", home.to_string_lossy().to_string());- cmd.env(- "XDG_CONFIG_HOME",- home.join(".config").to_string_lossy().to_string(),- );- }-- let mut child = pair.slave.spawn_command(cmd).unwrap();- drop(pair.slave);-- let mut reader = pair.master.try_clone_reader().unwrap();- let mut writer = pair.master.take_writer().unwrap();-- // Write input to the PTY (simulating user typing)- writer.write_all(input.as_bytes()).unwrap();- writer.flush().unwrap();- drop(writer);-- // Read all output- let mut buf = String::new();- reader.read_to_string(&mut buf).unwrap();-- let exit_status = child.wait().unwrap();- let exit_code = exit_status.exit_code() as i32;-- // Normalize CRLF to LF (PTYs use CRLF on some platforms)- let normalized = buf.replace("\r\n", "\n");-- (normalized, exit_code)- }-- /// Normalize output for snapshot testing- fn normalize_output(output: &str, home_dir: &Path) -> String {- // Remove platform-specific PTY control sequences- let output = regex::Regex::new(r"\^D\x08+")- .unwrap()- .replace_all(output, "");-- // Remove repository paths- let output = regex::Regex::new(r"/[^\s]+\.tmp[^\s/]+")- .unwrap()- .replace_all(&output, "[REPO]");-- // Remove home directory paths- let home_str = home_dir.display().to_string();- output.replace(&home_str, "[HOME]")+ /// Create insta settings for shell integration prompt PTY tests.+ ///+ /// Combines:+ /// - Standard repo path filters (from setup_snapshot_settings)+ /// - PTY-specific filters (^D, ANSI resets)+ /// - Home directory filter (for isolated temp home)+ fn prompt_pty_settings(repo: &TestRepo, home_dir: &Path) -> insta::Settings {+ let mut settings = setup_snapshot_settings(repo);+ add_pty_filters(&mut settings);++ // Replace temp home directory with [HOME]+ settings.add_filter(®ex::escape(&home_dir.to_string_lossy()), "[HOME]");++ settings}/// Test: Already installed (config line exists) → skip prompt@@ -310,13 +249,13 @@ mod pty_tests {// Set SHELL to bash since we're testing with .bashrcenv_vars.push(("SHELL".to_string(), "/bin/bash".to_string()));- let (output, exit_code) = exec_in_pty_with_input(+ let (output, exit_code) = exec_in_pty_with_home(get_cargo_bin("wt").to_str().unwrap(),&["switch", "--create", "feature"],repo.root_path(),&env_vars,- Some(temp_home.path()),"", // No input needed - should not prompt+ temp_home.path(),);assert_eq!(exit_code, 0);@@ -355,29 +294,27 @@ mod pty_tests {// Set SHELL to bash since we're testing with .bashrcenv_vars.push(("SHELL".to_string(), "/bin/bash".to_string()));- let (output, exit_code) = exec_in_pty_with_input(+ let (output, exit_code) = exec_in_pty_with_home(get_cargo_bin("wt").to_str().unwrap(),&["switch", "--create", "feature"],repo.root_path(),&env_vars,- Some(temp_home.path()),"n\n", // User declines+ temp_home.path(),);assert_eq!(exit_code, 0);- let normalized = normalize_output(&output, temp_home.path());-// Should contain the promptassert!(- normalized.contains("Install shell integration"),- "Should show prompt: {normalized}"+ output.contains("Install shell integration"),+ "Should show prompt: {output}");// Should have created the worktreeassert!(- normalized.contains("Created branch") && normalized.contains("and worktree"),- "Should create worktree: {normalized}"+ output.contains("Created branch") && output.contains("and worktree"),+ "Should create worktree: {output}");// Config should have skip-shell-integration-prompt = true@@ -394,10 +331,9 @@ mod pty_tests {"Should not install when declined: {bashrc_content}");- // Snapshot the output- let settings = setup_snapshot_settings(&repo);- settings.bind(|| {- assert_snapshot!("prompt_decline", normalized);+ // Snapshot the output (filters applied via settings)+ prompt_pty_settings(&repo, temp_home.path()).bind(|| {+ assert_snapshot!("prompt_decline", &output);});}@@ -414,29 +350,27 @@ mod pty_tests {// Set SHELL to bash since we're testing with .bashrcenv_vars.push(("SHELL".to_string(), "/bin/bash".to_string()));- let (output, exit_code) = exec_in_pty_with_input(+ let (output, exit_code) = exec_in_pty_with_home(get_cargo_bin("wt").to_str().unwrap(),&["switch", "--create", "feature"],repo.root_path(),&env_vars,- Some(temp_home.path()),"y\n", // User accepts+ temp_home.path(),);assert_eq!(exit_code, 0);- let normalized = normalize_output(&output, temp_home.path());-// Should contain the promptassert!(- normalized.contains("Install shell integration"),- "Should show prompt: {normalized}"+ output.contains("Install shell integration"),+ "Should show prompt: {output}");// Should show success message for configurationassert!(- normalized.contains("Configured") && normalized.contains("bash"),- "Should show configured message: {normalized}"+ output.contains("Configured") && output.contains("bash"),+ "Should show configured message: {output}");// Config should NOT have skip-shell-integration-prompt after accept@@ -454,10 +388,9 @@ mod pty_tests {"Should install when accepted: {bashrc_content}");- // Snapshot the output- let settings = setup_snapshot_settings(&repo);- settings.bind(|| {- assert_snapshot!("prompt_accept", normalized);+ // Snapshot the output (filters applied via settings)+ prompt_pty_settings(&repo, temp_home.path()).bind(|| {+ assert_snapshot!("prompt_accept", &output);});}@@ -474,35 +407,33 @@ mod pty_tests {// Set SHELL to bash since we're testing with .bashrcenv_vars.push(("SHELL".to_string(), "/bin/bash".to_string()));- let (output, exit_code) = exec_in_pty_with_input(+ let (output, exit_code) = exec_in_pty_with_home(get_cargo_bin("wt").to_str().unwrap(),&["switch", "--create", "feature"],repo.root_path(),&env_vars,- Some(temp_home.path()),"?\nn\n", // User requests preview, then declines+ temp_home.path(),);assert_eq!(exit_code, 0);- let normalized = normalize_output(&output, temp_home.path());-// Should contain the prompt (shown twice - before and after preview)assert!(- normalized.contains("Install shell integration"),- "Should show prompt: {normalized}"+ output.contains("Install shell integration"),+ "Should show prompt: {output}");// Should show preview content (gutter with config line)assert!(- normalized.contains("Will add") && normalized.contains("bash"),- "Should show preview: {normalized}"+ output.contains("Will add") && output.contains("bash"),+ "Should show preview: {output}");// Should show the config line in previewassert!(- normalized.contains("eval") && normalized.contains("wt config shell init"),- "Should show config line in preview: {normalized}"+ output.contains("eval") && output.contains("wt config shell init"),+ "Should show config line in preview: {output}");// Shell config should NOT have the integration line (user declined)@@ -512,10 +443,9 @@ mod pty_tests {"Should not install when declined after preview: {bashrc_content}");- // Snapshot the output- let settings = setup_snapshot_settings(&repo);- settings.bind(|| {- assert_snapshot!("prompt_preview_decline", normalized);+ // Snapshot the output (filters applied via settings)+ prompt_pty_settings(&repo, temp_home.path()).bind(|| {+ assert_snapshot!("prompt_preview_decline", &output);});}@@ -533,23 +463,23 @@ mod pty_tests {env_vars.push(("SHELL".to_string(), "/bin/bash".to_string()));// First switch - decline the prompt- let (_, _) = exec_in_pty_with_input(+ let (_, _) = exec_in_pty_with_home(get_cargo_bin("wt").to_str().unwrap(),&["switch", "--create", "feature1"],repo.root_path(),&env_vars,- Some(temp_home.path()),"n\n",+ temp_home.path(),);// Second switch - should NOT prompt again- let (output, exit_code) = exec_in_pty_with_input(+ let (output, exit_code) = exec_in_pty_with_home(get_cargo_bin("wt").to_str().unwrap(),&["switch", "--create", "feature2"],repo.root_path(),&env_vars,- Some(temp_home.path()),"", // No input needed+ temp_home.path(),);assert_eq!(exit_code, 0);diff --git a/tests/integration_tests/shell_wrapper.rs b/tests/integration_tests/shell_wrapper.rsindex 88d4ef9cc..92bacf7f1 100644--- a/tests/integration_tests/shell_wrapper.rs+++ b/tests/integration_tests/shell_wrapper.rs@@ -31,7 +31,7 @@// =============================================================================// Shared imports (both platforms)-use crate::common::TestRepo;+use crate::common::{TestRepo, shell::get_shell_binary};use insta_cmd::get_cargo_bin;use std::process::Command;@@ -330,14 +330,6 @@ fn build_shell_script(shell: &str, repo: &TestRepo, subcommand: &str, args: &[&s/// );/// // The output will show: "Allow? [y/N] y"/// ```-/// Get the actual shell binary name (handles powershell -> pwsh mapping)-fn get_shell_binary(shell: &str) -> &str {- match shell {- "powershell" => "pwsh",- _ => shell,- }-}-#[cfg(test)]fn exec_in_pty_interactive(shell: &str,diff --git a/tests/snapshots/integration__integration_tests__shell_integration_prompt__pty_tests__prompt_accept.snap b/tests/snapshots/integration__integration_tests__shell_integration_prompt__pty_tests__prompt_accept.snapindex 8f09b49a0..6d50125ef 100644--- a/tests/snapshots/integration__integration_tests__shell_integration_prompt__pty_tests__prompt_accept.snap+++ b/tests/snapshots/integration__integration_tests__shell_integration_prompt__pty_tests__prompt_accept.snap@@ -1,10 +1,10 @@---source: tests/integration_tests/shell_integration_prompt.rs-expression: normalized+expression: "&output"---y-[32m✓[39m [32mCreated branch [1mfeature[22m from [1mmain[22m and worktree @ [1m[REPO]/repo.feature[22m[39m+[32m✓[39m [32mCreated branch [1mfeature[22m from [1mmain[22m and worktree @ [1m_REPO_.feature[22m[39m[2m↳[22m [2mTo customize worktree locations, run [90mwt config create[39m[22m[33m▲[39m [33mCannot change directory — shell integration not installed[39mdiff --git a/tests/snapshots/integration__integration_tests__shell_integration_prompt__pty_tests__prompt_decline.snap b/tests/snapshots/integration__integration_tests__shell_integration_prompt__pty_tests__prompt_decline.snapindex 796b2eaf6..437bb1f52 100644--- a/tests/snapshots/integration__integration_tests__shell_integration_prompt__pty_tests__prompt_decline.snap+++ b/tests/snapshots/integration__integration_tests__shell_integration_prompt__pty_tests__prompt_decline.snap@@ -1,10 +1,10 @@---source: tests/integration_tests/shell_integration_prompt.rs-expression: normalized+expression: "&output"---n-[32m✓[39m [32mCreated branch [1mfeature[22m from [1mmain[22m and worktree @ [1m[REPO]/repo.feature[22m[39m+[32m✓[39m [32mCreated branch [1mfeature[22m from [1mmain[22m and worktree @ [1m_REPO_.feature[22m[39m[2m↳[22m [2mTo customize worktree locations, run [90mwt config create[39m[22m[33m▲[39m [33mCannot change directory — shell integration not installed[39mdiff --git a/tests/snapshots/integration__integration_tests__shell_integration_prompt__pty_tests__prompt_preview_decline.snap b/tests/snapshots/integration__integration_tests__shell_integration_prompt__pty_tests__prompt_preview_decline.snapindex a7e1c9e58..3ce347e22 100644--- a/tests/snapshots/integration__integration_tests__shell_integration_prompt__pty_tests__prompt_preview_decline.snap+++ b/tests/snapshots/integration__integration_tests__shell_integration_prompt__pty_tests__prompt_preview_decline.snap@@ -1,11 +1,11 @@---source: tests/integration_tests/shell_integration_prompt.rs-expression: normalized+expression: "&output"---?n-[32m✓[39m [32mCreated branch [1mfeature[22m from [1mmain[22m and worktree @ [1m[REPO]/repo.feature[22m[39m+[32m✓[39m [32mCreated branch [1mfeature[22m from [1mmain[22m and worktree @ [1m_REPO_.feature[22m[39m[2m↳[22m [2mTo customize worktree locations, run [90mwt config create[39m[22m[33m▲[39m [33mCannot change directory — shell integration not installed[39m