Skip to content

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

fix(test): eliminate spurious blank lines in PTY snapshots (#1040)

Maximilian Roos8408c020ffe1
diff --git a/src/commands/command_approval.rs b/src/commands/command_approval.rs
index 1f6fa6ea9..98d1d8ea3 100644
--- a/src/commands/command_approval.rs
+++ b/src/commands/command_approval.rs
@@ -156,9 +156,6 @@ fn prompt_for_batch_approval(commands: &[&HookCommand], project_id: &str) -> any
let mut response = String::new();
io::stdin().read_line(&mut response)?;
- // End the prompt line on stderr (user's input went to stdin, not stderr)
- worktrunk::styling::eprintln!();
-
Ok(response.trim().eq_ignore_ascii_case("y"))
}
diff --git a/src/commands/configure_shell.rs b/src/commands/configure_shell.rs
index 64b31940a..d2f37a855 100644
--- a/src/commands/configure_shell.rs
+++ b/src/commands/configure_shell.rs
@@ -832,9 +832,6 @@ fn prompt_yes_no() -> Result<bool, String> {
.read_line(&mut input)
.map_err(|e| e.to_string())?;
- // End the prompt line on stderr (user's input went to stdin, not stderr)
- eprintln!();
-
let response = input.trim().to_lowercase();
Ok(response == "y" || response == "yes")
}
diff --git a/src/output/prompt.rs b/src/output/prompt.rs
index bd27e0e0d..9950873c3 100644
--- a/src/output/prompt.rs
+++ b/src/output/prompt.rs
@@ -54,9 +54,6 @@ pub fn prompt_yes_no_preview(
let mut input = String::new();
io::stdin().read_line(&mut input)?;
- // End the prompt line on stderr (user's input went to stdin, not stderr)
- worktrunk::styling::eprintln!();
-
let response = input.trim().to_lowercase();
match response.as_str() {
"y" | "yes" => {
diff --git a/tests/common/pty.rs b/tests/common/pty.rs
index ba36b5b21..47ee05824 100644
--- a/tests/common/pty.rs
+++ b/tests/common/pty.rs
@@ -1,33 +1,16 @@
//! 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
+//! Three public functions — compose `build_pty_command` with a runner:
//!
-//! # Usage
+//! - **`build_pty_command`** — builds a `CommandBuilder` with env isolation
+//! - **`exec_cmd_in_pty`** — pre-buffers input, for non-interactive commands
+//! - **`exec_cmd_in_pty_prompted`** — waits for prompt marker before each input
//!
//! ```ignore
-//! use crate::common::pty::exec_in_pty;
+//! use crate::common::pty::{build_pty_command, exec_cmd_in_pty_prompted};
//!
-//! // 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(),
-//! );
+//! let cmd = build_pty_command("wt", &["switch", "feature"], dir, &env, None);
+//! let (output, exit_code) = exec_cmd_in_pty_prompted(cmd, &["y\n"], "[y/N");
//! ```
use portable_pty::{CommandBuilder, MasterPty};
@@ -191,62 +174,29 @@ fn find_cursor_request(data: &[u8]) -> Option<usize> {
.position(|window| window == pattern)
}
-/// Execute a command in a PTY with optional interactive input.
-///
-/// Returns (combined_output, exit_code).
+/// Build a CommandBuilder with standard PTY isolation and env vars.
///
-/// Output is normalized:
-/// - CRLF → LF (PTYs use CRLF on some platforms)
+/// Compose with `exec_cmd_in_pty` or `exec_cmd_in_pty_prompted`:
///
-/// Environment is isolated via `configure_pty_command()`:
-/// - Cleared and rebuilt with minimal required vars
-/// - Coverage env vars passed through
-pub fn exec_in_pty(
+/// ```ignore
+/// let cmd = build_pty_command("wt", &["switch", "feature"], dir, &env, None);
+/// let (output, exit_code) = exec_cmd_in_pty(cmd, "y\n");
+/// ```
+pub fn build_pty_command(
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();
-
+) -> CommandBuilder {
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);
}
@@ -258,45 +208,22 @@ fn exec_in_pty_impl(
"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());
// Suppress nushell auto-detection for deterministic PTY tests
cmd.env("WORKTRUNK_TEST_NUSHELL_ENV", "0");
}
- 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 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();
- }
-
- // Read output and wait for exit (platform-specific handling)
- // Note: writer is passed to read_pty_output for ConPTY cursor response handling
- let (buf, exit_code) = read_pty_output(reader, writer, pair.master, &mut child);
-
- // Normalize CRLF to LF (PTYs use CRLF on some platforms)
- let normalized = buf.replace("\r\n", "\n");
-
- (normalized, exit_code)
+ cmd
}
-/// Execute a pre-configured CommandBuilder in a PTY.
+/// Execute a CommandBuilder in a PTY, writing all input immediately.
///
-/// 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
+/// Drops the writer before waiting for the child to signal EOF — non-interactive
+/// commands may block on stdin until it closes.
///
-/// Returns (combined_output, exit_code).
+/// For interactive prompts, use `exec_cmd_in_pty_prompted` instead (it waits
+/// for the child before dropping the writer to avoid PTY echo artifacts).
pub fn exec_cmd_in_pty(cmd: CommandBuilder, input: &str) -> (String, i32) {
let pair = super::open_pty();
@@ -311,61 +238,141 @@ pub fn exec_cmd_in_pty(cmd: CommandBuilder, input: &str) -> (String, i32) {
writer.flush().unwrap();
}
- // Read output and wait for exit (platform-specific handling)
let (buf, exit_code) = read_pty_output(reader, writer, pair.master, &mut child);
-
- // Normalize CRLF to LF
let normalized = buf.replace("\r\n", "\n");
(normalized, exit_code)
}
-/// Execute a command in a PTY with multiple sequential inputs.
+/// Execute a CommandBuilder in a PTY, waiting for prompts before sending input.
///
-/// 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)],
+/// For each element of `inputs`, waits until `prompt_marker` appears in the
+/// output, then writes that input. This produces output where the echo appears
+/// after the prompt — matching real terminal behavior.
+pub fn exec_cmd_in_pty_prompted(
+ cmd: CommandBuilder,
inputs: &[&str],
+ prompt_marker: &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 reader = pair.master.try_clone_reader().unwrap();
- let mut writer = pair.master.take_writer().unwrap();
+ let writer = pair.master.take_writer().unwrap();
+
+ prompted_pty_interaction(reader, writer, &mut child, inputs, prompt_marker)
+}
+
+/// Core prompt-waiting logic shared by all `_prompted` variants.
+///
+/// Reads PTY output in a background thread while the main thread waits for
+/// `prompt_marker` to appear before sending each input. After all inputs are
+/// sent, waits for the child to exit, then drops the writer.
+fn prompted_pty_interaction(
+ reader: Box<dyn std::io::Read + Send>,
+ writer: Box<dyn std::io::Write + Send>,
+ child: &mut Box<dyn portable_pty::Child + Send + Sync>,
+ inputs: &[&str],
+ prompt_marker: &str,
+) -> (String, i32) {
+ use std::sync::mpsc;
+ use std::time::{Duration, Instant};
+
+ let (tx, rx) = mpsc::channel::<Vec<u8>>();
- // Write all inputs sequentially
+ // Read PTY output in background, sending chunks via channel
+ let reader_thread = std::thread::spawn(move || {
+ let mut reader = reader;
+ let mut buf = [0u8; 4096];
+ loop {
+ match std::io::Read::read(&mut reader, &mut buf) {
+ Ok(0) => break,
+ Ok(n) => {
+ if tx.send(buf[..n].to_vec()).is_err() {
+ break;
+ }
+ }
+ Err(_) => break,
+ }
+ }
+ });
+
+ let mut accumulated = Vec::new();
+ let mut writer = writer;
+ let timeout = Duration::from_secs(10);
+ let poll = Duration::from_millis(10);
+ let marker = prompt_marker.as_bytes();
+
+ // For each input, wait for a NEW prompt marker to appear, then send
+ let mut markers_seen: usize = 0;
for input in inputs {
+ let target = markers_seen + 1;
+ let start = Instant::now();
+
+ loop {
+ while let Ok(chunk) = rx.try_recv() {
+ accumulated.extend_from_slice(&chunk);
+ }
+
+ if count_marker_occurrences(&accumulated, marker) >= target {
+ markers_seen = target;
+ break;
+ }
+
+ if start.elapsed() > timeout {
+ panic!(
+ "Timed out waiting for prompt marker {:?} (occurrence {}). Output so far:\n{}",
+ prompt_marker,
+ target,
+ String::from_utf8_lossy(&accumulated)
+ );
+ }
+
+ std::thread::sleep(poll);
+ }
+
writer.write_all(input.as_bytes()).unwrap();
writer.flush().unwrap();
}
- // Read output and wait for exit (platform-specific handling)
- let (buf, exit_code) = read_pty_output(reader, writer, pair.master, &mut child);
+ // Wait for child to exit BEFORE dropping writer.
+ //
+ // portable_pty's UnixMasterWriter::drop() sends \n + EOT to the PTY.
+ // If dropped while the child is still running, the terminal echoes this
+ // \n as \r\n, creating a spurious blank line in the captured output.
+ // By waiting for the child first, the slave side closes and the echo
+ // from the Drop's \n goes to a dead PTY — no artifact.
+ //
+ // The child won't hang: after read_line() returns for all prompts, it
+ // continues executing without reading stdin. EOF isn't needed.
+ let exit_status = child.wait().unwrap();
+ let exit_code = exit_status.exit_code() as i32;
+
+ // Now safe to drop writer (child already exited, slave side closed)
+ drop(writer);
+
+ // Wait for reader thread to finish
+ let _ = reader_thread.join();
+
+ // Drain any remaining chunks
+ while let Ok(chunk) = rx.try_recv() {
+ accumulated.extend_from_slice(&chunk);
+ }
- // Normalize CRLF to LF
+ let buf = String::from_utf8_lossy(&accumulated).to_string();
let normalized = buf.replace("\r\n", "\n");
(normalized, exit_code)
}
+
+fn count_marker_occurrences(haystack: &[u8], needle: &[u8]) -> usize {
+ if needle.is_empty() || needle.len() > haystack.len() {
+ return 0;
+ }
+ haystack
+ .windows(needle.len())
+ .filter(|w| *w == needle)
+ .count()
+}
diff --git a/tests/integration_tests/approval_pty.rs b/tests/integration_tests/approval_pty.rs
index 5307cc0df..6e9f99957 100644
--- a/tests/integration_tests/approval_pty.rs
+++ b/tests/integration_tests/approval_pty.rs
@@ -8,27 +8,26 @@
//! 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::pty::{build_pty_command, exec_cmd_in_pty_prompted};
use crate::common::{TestRepo, add_pty_binary_path_filters, add_pty_filters, repo, wt_bin};
use insta::assert_snapshot;
use rstest::rstest;
-/// Execute wt in a PTY with interactive input.
-///
-/// Thin wrapper around `exec_in_pty` that passes the wt binary path.
+/// Execute wt in a PTY, waiting for the approval prompt before sending input.
fn exec_wt_in_pty(
repo: &TestRepo,
args: &[&str],
env_vars: &[(String, String)],
input: &str,
) -> (String, i32) {
- exec_in_pty(
+ let cmd = build_pty_command(
wt_bin().to_str().unwrap(),
args,
repo.root_path(),
env_vars,
- input,
- )
+ None,
+ );
+ exec_cmd_in_pty_prompted(cmd, &[input], "[y/N")
}
/// Create insta settings for approval PTY tests.
diff --git a/tests/integration_tests/configure_shell.rs b/tests/integration_tests/configure_shell.rs
index 1275856d5..508d6c8d9 100644
--- a/tests/integration_tests/configure_shell.rs
+++ b/tests/integration_tests/configure_shell.rs
@@ -1541,7 +1541,7 @@ 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::pty::exec_cmd_in_pty;
+ use crate::common::pty::exec_cmd_in_pty_prompted;
use crate::common::{
TestRepo, add_pty_filters, configure_pty_command, repo, temp_home, wt_bin,
};
@@ -1551,7 +1551,7 @@ mod pty_tests {
use std::fs;
use tempfile::TempDir;
- /// Execute shell install command in a PTY with interactive input
+ /// Execute shell install command in a PTY, waiting for prompt before input
fn exec_install_in_pty(temp_home: &TempDir, repo: &TestRepo, input: &str) -> (String, i32) {
let mut cmd = CommandBuilder::new(wt_bin());
cmd.arg("-C");
@@ -1573,7 +1573,7 @@ mod pty_tests {
// Using MISSING=1 skips the probe while still showing the compinit advisory.
cmd.env("WORKTRUNK_TEST_COMPINIT_MISSING", "1");
- exec_cmd_in_pty(cmd, input)
+ exec_cmd_in_pty_prompted(cmd, &[input], "[y/N")
}
/// Create insta settings for install PTY tests.
@@ -1590,9 +1590,6 @@ mod pty_tests {
// Remove standalone echoed input lines (just y or n on their own line)
settings.add_filter(r"^[yn]\n", "");
- // Collapse consecutive newlines (PTY timing variations)
- settings.add_filter(r"\n{2,}", "\n");
-
// Replace temp home path with ~/
settings.add_filter(&regex::escape(&temp_home.path().to_string_lossy()), "~");
diff --git a/tests/integration_tests/shell_integration_prompt.rs b/tests/integration_tests/shell_integration_prompt.rs
index 50bb5ac47..49d74bb40 100644
--- a/tests/integration_tests/shell_integration_prompt.rs
+++ b/tests/integration_tests/shell_integration_prompt.rs
@@ -203,7 +203,7 @@ 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::pty::exec_in_pty_with_home;
+ use crate::common::pty::{build_pty_command, exec_cmd_in_pty, exec_cmd_in_pty_prompted};
use crate::common::{add_pty_filters, setup_snapshot_settings, wt_bin};
use insta::assert_snapshot;
use std::path::Path;
@@ -250,14 +250,14 @@ mod pty_tests {
// Set SHELL to bash since we're testing with .bashrc
env_vars.push(("SHELL".to_string(), "/bin/bash".to_string()));
- let (output, exit_code) = exec_in_pty_with_home(
+ let cmd = build_pty_command(
wt_bin().to_str().unwrap(),
&["switch", "--create", "feature"],
repo.root_path(),
&env_vars,
- "", // No input needed - should not prompt
- temp_home.path(),
+ Some(temp_home.path()),
);
+ let (output, exit_code) = exec_cmd_in_pty(cmd, "");
assert_eq!(exit_code, 0);
@@ -295,14 +295,14 @@ mod pty_tests {
// Set SHELL to bash since we're testing with .bashrc
env_vars.push(("SHELL".to_string(), "/bin/bash".to_string()));
- let (output, exit_code) = exec_in_pty_with_home(
+ let cmd = build_pty_command(
wt_bin().to_str().unwrap(),
&["switch", "--create", "feature"],
repo.root_path(),
&env_vars,
- "n\n", // User declines
- temp_home.path(),
+ Some(temp_home.path()),
);
+ let (output, exit_code) = exec_cmd_in_pty_prompted(cmd, &["n\n"], "[y/N");
assert_eq!(exit_code, 0);
@@ -351,14 +351,14 @@ mod pty_tests {
// Set SHELL to bash since we're testing with .bashrc
env_vars.push(("SHELL".to_string(), "/bin/bash".to_string()));
- let (output, exit_code) = exec_in_pty_with_home(
+ let cmd = build_pty_command(
wt_bin().to_str().unwrap(),
&["switch", "--create", "feature"],
repo.root_path(),
&env_vars,
- "y\n", // User accepts
- temp_home.path(),
+ Some(temp_home.path()),
);
+ let (output, exit_code) = exec_cmd_in_pty_prompted(cmd, &["y\n"], "[y/N");
assert_eq!(exit_code, 0);
@@ -408,14 +408,15 @@ mod pty_tests {
// Set SHELL to bash since we're testing with .bashrc
env_vars.push(("SHELL".to_string(), "/bin/bash".to_string()));
- let (output, exit_code) = exec_in_pty_with_home(
+ let cmd = build_pty_command(
wt_bin().to_str().unwrap(),
&["switch", "--create", "feature"],
repo.root_path(),
&env_vars,
- "?\nn\n", // User requests preview, then declines
- temp_home.path(),
+ Some(temp_home.path()),
);
+ // User requests preview, then declines
+ let (output, exit_code) = exec_cmd_in_pty_prompted(cmd, &["?\n", "n\n"], "[y/N");
assert_eq!(exit_code, 0);
@@ -464,24 +465,24 @@ mod pty_tests {
env_vars.push(("SHELL".to_string(), "/bin/bash".to_string()));
// First switch - decline the prompt
- let (_, _) = exec_in_pty_with_home(
+ let cmd = build_pty_command(
wt_bin().to_str().unwrap(),
&["switch", "--create", "feature1"],
repo.root_path(),
&env_vars,
- "n\n",
- temp_home.path(),
+ Some(temp_home.path()),
);
+ let (_, _) = exec_cmd_in_pty_prompted(cmd, &["n\n"], "[y/N");
// Second switch - should NOT prompt again
- let (output, exit_code) = exec_in_pty_with_home(
+ let cmd = build_pty_command(
wt_bin().to_str().unwrap(),
&["switch", "--create", "feature2"],
repo.root_path(),
&env_vars,
- "", // No input needed
- temp_home.path(),
+ Some(temp_home.path()),
);
+ let (output, exit_code) = exec_cmd_in_pty(cmd, "");
assert_eq!(exit_code, 0);
@@ -496,7 +497,7 @@ mod pty_tests {
#[cfg(all(unix, feature = "shell-integration-tests"))]
mod commit_generation_prompt_tests {
use super::*;
- use crate::common::pty::exec_in_pty_with_home;
+ use crate::common::pty::{build_pty_command, exec_cmd_in_pty, exec_cmd_in_pty_prompted};
use crate::common::wt_bin;
use std::os::unix::fs::PermissionsExt;
use std::path::{Path, PathBuf};
@@ -529,14 +530,14 @@ mod commit_generation_prompt_tests {
// Use minimal PATH to ensure claude/codex aren't found
env_vars.push(("PATH".to_string(), "/usr/bin:/bin".to_string()));
- let (output, exit_code) = exec_in_pty_with_home(
+ let cmd = build_pty_command(
wt_bin().to_str().unwrap(),
&["step", "commit"],
repo.root_path(),
&env_vars,
- "", // No input needed - prompt should be skipped
- temp_home.path(),
+ Some(temp_home.path()),
);
+ let (output, exit_code) = exec_cmd_in_pty(cmd, "");
// Should succeed (using fallback commit message)
assert_eq!(exit_code, 0, "Command should succeed: {output}");
@@ -565,14 +566,14 @@ mod commit_generation_prompt_tests {
let path = format!("{}:/usr/bin:/bin", bin_dir.display());
env_vars.push(("PATH".to_string(), path));
- let (output, exit_code) = exec_in_pty_with_home(
+ let cmd = build_pty_command(
wt_bin().to_str().unwrap(),
&["step", "commit"],
repo.root_path(),
&env_vars,
- "n\n", // Decline the prompt
- temp_home.path(),
+ Some(temp_home.path()),
);
+ let (output, exit_code) = exec_cmd_in_pty_prompted(cmd, &["n\n"], "[y/N");
assert_eq!(exit_code, 0, "Command should succeed: {output}");
@@ -605,14 +606,14 @@ mod commit_generation_prompt_tests {
let path = format!("{}:/usr/bin:/bin", bin_dir.display());
env_vars.push(("PATH".to_string(), path));
- let (output, _exit_code) = exec_in_pty_with_home(
+ let cmd = build_pty_command(
wt_bin().to_str().unwrap(),
&["step", "commit"],
repo.root_path(),
&env_vars,
- "y\n", // Accept the prompt
- temp_home.path(),
+ Some(temp_home.path()),
);
+ let (output, _exit_code) = exec_cmd_in_pty_prompted(cmd, &["y\n"], "[y/N");
// Note: exit_code may be non-zero because our fake claude doesn't generate
// a real commit message. We're testing the prompt flow, not the LLM result.
@@ -646,14 +647,15 @@ mod commit_generation_prompt_tests {
let path = format!("{}:/usr/bin:/bin", bin_dir.display());
env_vars.push(("PATH".to_string(), path));
- let (output, exit_code) = exec_in_pty_with_home(
+ let cmd = build_pty_command(
wt_bin().to_str().unwrap(),
&["step", "commit"],
repo.root_path(),
&env_vars,
- "?\nn\n", // Request preview, then decline
- temp_home.path(),
+ Some(temp_home.path()),
);
+ // Request preview, then decline
+ let (output, exit_code) = exec_cmd_in_pty_prompted(cmd, &["?\n", "n\n"], "[y/N");
assert_eq!(exit_code, 0, "Command should succeed: {output}");
diff --git a/tests/integration_tests/shell_wrapper.rs b/tests/integration_tests/shell_wrapper.rs
index 60708fee6..00a13fd3e 100644
--- a/tests/integration_tests/shell_wrapper.rs
+++ b/tests/integration_tests/shell_wrapper.rs
@@ -315,9 +315,8 @@ fn build_shell_script(shell: &str, repo: &TestRepo, subcommand: &str, args: &[&s
}
}
-/// Execute a command in a PTY with interactive input support
+/// Execute a command in a PTY with interactive input support.
///
-/// This is similar to `exec_in_pty` but allows sending input during execution.
/// The PTY will automatically echo the input (like a real terminal), so you'll
/// see both the prompts and the input in the captured output.
///
@@ -3415,12 +3414,18 @@ mod windows_tests {
/// This test runs cmd.exe which is simpler than PowerShell and validates the core ConPTY fix.
#[test]
fn test_conpty_basic_cmd() {
- use crate::common::pty::exec_in_pty;
+ use crate::common::pty::{build_pty_command, exec_cmd_in_pty};
// Use cmd.exe for simplest possible test
let tmp = tempfile::tempdir().unwrap();
- let (output, exit_code) =
- exec_in_pty("cmd.exe", &["/C", "echo CONPTY_WORKS"], tmp.path(), &[], "");
+ let cmd = build_pty_command(
+ "cmd.exe",
+ &["/C", "echo CONPTY_WORKS"],
+ tmp.path(),
+ &[],
+ None,
+ );
+ let (output, exit_code) = exec_cmd_in_pty(cmd, "");
eprintln!("ConPTY test output: {:?}", output);
eprintln!("ConPTY test exit code: {}", exit_code);
@@ -3438,19 +3443,20 @@ mod windows_tests {
/// Diagnostic test: Verify wt --version works via ConPTY.
#[test]
fn test_conpty_wt_version() {
- use crate::common::pty::exec_in_pty;
+ use crate::common::pty::{build_pty_command, exec_cmd_in_pty};
use crate::common::wt_bin;
let wt_bin = wt_bin();
let tmp = tempfile::tempdir().unwrap();
- let (output, exit_code) = exec_in_pty(
+ let cmd = build_pty_command(
wt_bin.to_str().unwrap(),
&["--version"],
tmp.path(),
&[],
- "",
+ None,
);
+ let (output, exit_code) = exec_cmd_in_pty(cmd, "");
eprintln!("wt --version output: {:?}", output);
eprintln!("wt --version exit code: {}", exit_code);
diff --git a/tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_accept.snap b/tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_accept.snap
index 3ea866dee..a69b06464 100644
--- a/tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_accept.snap
+++ b/tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_accept.snap
@@ -2,13 +2,11 @@
source: tests/integration_tests/approval_pty.rs
expression: "&output"
---
-y
-
▲ repo needs approval to execute 1 command:
○ post-create:
  echo 'test command'
-❯ Allow and remember? [y/N]
+❯ Allow and remember? [y/N] y
◎ Running post-create project hook @ _REPO_.test-approve
  echo 'test command'
test command
diff --git a/tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_decline.snap b/tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_decline.snap
index 48941b003..4be008df8 100644
--- a/tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_decline.snap
+++ b/tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_decline.snap
@@ -2,13 +2,11 @@
source: tests/integration_tests/approval_pty.rs
expression: "&output"
---
-n
-
▲ repo needs approval to execute 1 command:
○ post-create:
  echo 'test command'
-❯ Allow and remember? [y/N]
+❯ Allow and remember? [y/N] n
○ Commands declined, continuing worktree creation
✓ Created branch test-decline from main and worktree @ _REPO_.test-decline
↳ To customize worktree locations, run wt config create
diff --git a/tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_mixed_approved_unapproved_accept.snap b/tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_mixed_approved_unapproved_accept.snap
index faa58d21d..6e730eb07 100644
--- a/tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_mixed_approved_unapproved_accept.snap
+++ b/tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_mixed_approved_unapproved_accept.snap
@@ -2,15 +2,13 @@
source: tests/integration_tests/approval_pty.rs
expression: "&output"
---
-y
-
▲ repo needs approval to execute 2 commands:
○ post-create first:
  echo 'First command'
○ post-create third:
  echo 'Third command'
-❯ Allow and remember? [y/N]
+❯ Allow and remember? [y/N] y
◎ Running post-create project:first @ _REPO_.test-mixed-accept
  echo 'First command'
First command
diff --git a/tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_mixed_approved_unapproved_decline.snap b/tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_mixed_approved_unapproved_decline.snap
index 0a5605895..3f0cb8182 100644
--- a/tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_mixed_approved_unapproved_decline.snap
+++ b/tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_mixed_approved_unapproved_decline.snap
@@ -2,15 +2,13 @@
source: tests/integration_tests/approval_pty.rs
expression: "&output"
---
-n
-
▲ repo needs approval to execute 2 commands:
○ post-create first:
  echo 'First command'
○ post-create third:
  echo 'Third command'
-❯ Allow and remember? [y/N]
+❯ Allow and remember? [y/N] n
○ Commands declined, continuing worktree creation
✓ Created branch test-mixed-decline from main and worktree @ _REPO_.test-mixed-decline
↳ To customize worktree locations, run wt config create
diff --git a/tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_multiple_commands.snap b/tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_multiple_commands.snap
index d6ebf6256..16298746a 100644
--- a/tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_multiple_commands.snap
+++ b/tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_multiple_commands.snap
@@ -2,8 +2,6 @@
source: tests/integration_tests/approval_pty.rs
expression: "&output"
---
-y
-
▲ repo needs approval to execute 3 commands:
○ post-create first:
  echo 'First command'
@@ -12,7 +10,7 @@ y
○ post-create third:
  echo 'Third command'
-❯ Allow and remember? [y/N]
+❯ Allow and remember? [y/N] y
◎ Running post-create project:first @ _REPO_.test-multi
  echo 'First command'
First command
diff --git a/tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_named_commands.snap b/tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_named_commands.snap
index 869faa04a..88916aa0d 100644
--- a/tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_named_commands.snap
+++ b/tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_named_commands.snap
@@ -2,8 +2,6 @@
source: tests/integration_tests/approval_pty.rs
expression: "&output"
---
-y
-
▲ repo needs approval to execute 3 commands:
○ post-create install:
  echo 'Installing dependencies...'
@@ -12,7 +10,7 @@ y
○ post-create test:
  echo 'Running tests...'
-❯ Allow and remember? [y/N]
+❯ Allow and remember? [y/N] y
◎ Running post-create project:install @ _REPO_.test-named
  echo 'Installing dependencies...'
Installing dependencies...
diff --git a/tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_permission_error.snap b/tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_permission_error.snap
index d62eab928..71e2463e2 100644
--- a/tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_permission_error.snap
+++ b/tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_permission_error.snap
@@ -2,13 +2,11 @@
source: tests/integration_tests/approval_pty.rs
expression: "&output"
---
-y
-
▲ repo needs approval to execute 1 command:
○ post-create:
  echo 'test command'
-❯ Allow and remember? [y/N]
+❯ Allow and remember? [y/N] y
▲ Failed to save command approval: Failed to write config file: Permission denied (os error 13)
↳ Approval will be requested again next time.
◎ Running post-create project hook @ _REPO_.test-permission
diff --git a/tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_remove_decline.snap b/tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_remove_decline.snap
index d86bd6d6f..b861a2492 100644
--- a/tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_remove_decline.snap
+++ b/tests/snapshots/integration__integration_tests__approval_pty__approval_prompt_remove_decline.snap
@@ -2,12 +2,10 @@
source: tests/integration_tests/approval_pty.rs
expression: "&output"
---
-n
-
▲ repo needs approval to execute 1 command:
○ pre-remove:
  echo 'pre-remove hook'
-❯ Allow and remember? [y/N]
+❯ Allow and remember? [y/N] n
○ Commands declined, continuing removal
◎ Removing to-remove worktree & branch in background (ancestor of main, ⊂)
diff --git a/tests/snapshots/integration__integration_tests__configure_shell__pty_tests__install_preview_declined.snap b/tests/snapshots/integration__integration_tests__configure_shell__pty_tests__install_preview_declined.snap
index 097e8d61a..1c37af45a 100644
--- a/tests/snapshots/integration__integration_tests__configure_shell__pty_tests__install_preview_declined.snap
+++ b/tests/snapshots/integration__integration_tests__configure_shell__pty_tests__install_preview_declined.snap
@@ -2,6 +2,5 @@
source: tests/integration_tests/configure_shell.rs
expression: "output.trim_start_matches('\\n')"
---
-
❯ Install shell integration? [y/N/?]
✗ Cancelled by user
diff --git a/tests/snapshots/integration__integration_tests__configure_shell__pty_tests__install_preview_with_gutter.snap b/tests/snapshots/integration__integration_tests__configure_shell__pty_tests__install_preview_with_gutter.snap
index 050bfc715..f744c7bcb 100644
--- a/tests/snapshots/integration__integration_tests__configure_shell__pty_tests__install_preview_with_gutter.snap
+++ b/tests/snapshots/integration__integration_tests__configure_shell__pty_tests__install_preview_with_gutter.snap
@@ -2,12 +2,12 @@
source: tests/integration_tests/configure_shell.rs
expression: "output.trim_start_matches('\\n')"
---
-
❯ Install shell integration? [y/N/?]
✓ Added shell extension & completions for zsh @ ~/.zshrc
↳ Skipped bash; ~/.bashrc not found
↳ Skipped fish; ~/.config/fish/functions not found
↳ Skipped nu; ~/.config/nushell/vendor/autoload not found
+
✓ Configured 1 shell
▲ Completions require compinit; add to ~/.zshrc before the wt line:
autoload -Uz compinit && compinit
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.snap
index 43ddb2fbd..afaf7f623 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
@@ -2,13 +2,11 @@
source: tests/integration_tests/shell_integration_prompt.rs
expression: "&output"
---
-y
-
✓ Created branch feature from main and worktree @ _REPO_.feature
↳ To customize worktree locations, run wt config create
▲ Cannot change directory — shell integration not installed
-❯ Install shell integration? [y/N/?]
+❯ Install shell integration? [y/N/?] y
✓ Added shell extension & completions for bash @ ~/.bashrc
↳ Skipped zsh; ~/.zshrc not found
↳ Skipped fish; ~/.config/fish/functions not found
diff --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.snap
index 437bb1f52..37b21761b 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
@@ -2,11 +2,9 @@
source: tests/integration_tests/shell_integration_prompt.rs
expression: "&output"
---
-n
-
✓ Created branch feature from main and worktree @ _REPO_.feature
↳ To customize worktree locations, run wt config create
▲ Cannot change directory — shell integration not installed
-❯ Install shell integration? [y/N/?]
+❯ Install shell integration? [y/N/?] n
↳ To enable automatic cd, run wt config shell install
diff --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.snap
index 3ce347e22..90c27853c 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
@@ -2,16 +2,13 @@
source: tests/integration_tests/shell_integration_prompt.rs
expression: "&output"
---
-?
-n
-
✓ Created branch feature from main and worktree @ _REPO_.feature
↳ To customize worktree locations, run wt config create
▲ Cannot change directory — shell integration not installed
-❯ Install shell integration? [y/N/?]
+❯ Install shell integration? [y/N/?] ?
○ Will add shell extension & completions for bash @ ~/.bashrc
  if command -v wt >/dev/null 2>&1; then eval "$(command wt config shell init bash)"; fi
-❯ Install shell integration? [y/N/?]
+❯ Install shell integration? [y/N/?] n
↳ To enable automatic cd, run wt config shell install