Skip to content

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

feat: Enhance shell completion and diff parsing, fix rustdoc warning, and add link exclusions

Maximilian Roos85ffbee9f213
diff --git a/.markdown-link-check.json b/.markdown-link-check.json
index 7451b22f4..4fe59384f 100644
--- a/.markdown-link-check.json
+++ b/.markdown-link-check.json
@@ -2,6 +2,21 @@
"ignorePatterns": [
{
"pattern": "^https://crates\\.io/crates/worktrunk$"
+ },
+ {
+ "pattern": "^https://github\\.com/crate-ci/cargo-release$"
+ },
+ {
+ "pattern": "^https://opensource\\.org/"
+ },
+ {
+ "pattern": "^https://llm\\.datasette\\.io/"
+ },
+ {
+ "pattern": "^https://docs\\.rs/"
+ },
+ {
+ "pattern": "^https://img\\.shields\\.io/"
}
]
}
diff --git a/Cargo.lock b/Cargo.lock
index f2672d3bc..dd0b22030 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -2656,6 +2656,7 @@ dependencies = [
"insta-cmd",
"log",
"minijinja",
+ "nix 0.29.0",
"portable-pty",
"rayon",
"regex",
diff --git a/Cargo.toml b/Cargo.toml
index c40d59a1f..6c950acd2 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -28,6 +28,14 @@ path = "src/lib.rs"
name = "wt"
path = "src/main.rs"
+# Helper binary for TTY isolation in tests.
+# This binary uses setsid() to detach child processes from controlling terminals,
+# preventing PTY-related hangs in nextest. Built with `cargo build` but not installed
+# by `cargo install` (binaries in subdirectories are excluded from installation).
+[[bin]]
+name = "dev-detach"
+path = "tests/bin/dev-detach.rs"
+
[dependencies]
anstream = "0.6"
anstyle = "1.0"
@@ -64,6 +72,9 @@ unicode-width = "0.2"
[target.'cfg(unix)'.dependencies]
skim = "0.20"
+# nix crate used by dev-detach helper binary for TTY isolation in tests.
+# This is only compiled when running tests (dev-detach is not included in release builds).
+nix = { version = "0.29", default-features = false, features = ["process", "signal"] }
[build-dependencies]
vergen-gitcl = { version = "1.0.8", features = ["build"] }
@@ -88,6 +99,9 @@ name = "list"
harness = false
[lints.rust]
+# No unsafe code in the main codebase or tests.
+# TTY isolation for shell integration tests is handled by the dev-detach helper binary,
+# which uses the nix crate's safe wrappers for Unix syscalls (setsid, execvp).
unsafe_code = "forbid"
# The profile that 'dist' will build with
diff --git a/README.md b/README.md
index 19b3564d8..0b98b6262 100644
--- a/README.md
+++ b/README.md
@@ -560,7 +560,7 @@ Worktrunk is in active development. The core features are stable and ready for u
### Releases
-Use `cargo-release` to publish new versions:
+Use [cargo-release](https://github.com/crate-ci/cargo-release) to publish new versions:
```bash
cargo install cargo-release
diff --git a/src/commands/init.rs b/src/commands/init.rs
index 08f8466d9..820929a84 100644
--- a/src/commands/init.rs
+++ b/src/commands/init.rs
@@ -82,6 +82,15 @@ pub fn handle_init(shell: shell::Shell, cli_cmd: &mut Command) -> Result<(), Str
line
};
+ // For Zsh: Guard the final compdef call to avoid errors when completion system isn't loaded
+ // Not all users have compinit in their .zshrc, and --no-rcs mode never loads it
+ let line = if matches!(shell, shell::Shell::Zsh) && line.trim() == "compdef _wt wt" {
+ // Replace with guarded version that checks if compdef exists
+ " if (( $+functions[compdef] )); then compdef _wt wt; fi".to_string()
+ } else {
+ line
+ };
+
println!("{}", line);
}
diff --git a/tests/bin/dev-detach.rs b/tests/bin/dev-detach.rs
new file mode 100644
index 000000000..5e8a8d377
--- /dev/null
+++ b/tests/bin/dev-detach.rs
@@ -0,0 +1,43 @@
+//! Dev-only helper binary for TTY isolation in tests.
+//!
+//! This binary detaches child processes from controlling terminals by calling setsid()
+//! before exec'ing the target command. This prevents PTY-related hangs when running
+//! nextest in environments like unbuffer or script.
+//!
+//! Usage: dev-detach \<command\> [args...]
+//!
+//! The binary becomes a new session leader with no controlling terminal, then replaces
+//! itself with the target command via execvp().
+
+use nix::unistd::{execvp, setsid};
+use std::{env, ffi::CString, process};
+
+fn main() {
+ // Become a new session leader with no controlling terminal.
+ // This is the key to preventing PTY-related hangs - the child process
+ // starts life completely detached from any terminal.
+ if let Err(e) = setsid() {
+ eprintln!("dev-detach: setsid failed: {}", e);
+ process::exit(1);
+ }
+
+ // Get command and arguments from our argv
+ let args: Vec<String> = env::args().skip(1).collect();
+ if args.is_empty() {
+ eprintln!("usage: dev-detach <command> [args...]");
+ process::exit(2);
+ }
+
+ // Convert to CStrings for execvp
+ let prog = CString::new(args[0].clone()).unwrap();
+ let cargs: Vec<CString> = args
+ .iter()
+ .map(|a| CString::new(a.as_str()).unwrap())
+ .collect();
+
+ // Replace this process with the target command.
+ // If execvp returns, it failed.
+ let _ = execvp(&prog, &cargs);
+ eprintln!("dev-detach: execvp failed");
+ process::exit(127);
+}
diff --git a/tests/common/shell.rs b/tests/common/shell.rs
index 1c818d580..5a45c6aee 100644
--- a/tests/common/shell.rs
+++ b/tests/common/shell.rs
@@ -2,6 +2,13 @@ use super::{TestRepo, wt_command};
use insta_cmd::get_cargo_bin;
use std::process::Command;
+/// Get the path to the dev-detach helper binary.
+/// This binary calls setsid() before exec'ing the shell, detaching it from
+/// any controlling terminal and preventing PTY-related hangs.
+fn get_dev_detach_bin() -> std::path::PathBuf {
+ get_cargo_bin("dev-detach")
+}
+
/// Map shell display names to actual binaries.
pub fn get_shell_binary(shell: &str) -> &str {
match shell {
@@ -14,8 +21,11 @@ pub fn get_shell_binary(shell: &str) -> &str {
/// Execute a script in the given shell with the repo's isolated environment.
pub fn execute_shell_script(repo: &TestRepo, shell: &str, script: &str) -> String {
- let binary = get_shell_binary(shell);
- let mut cmd = Command::new(binary);
+ // Use dev-detach wrapper to fully isolate shell from controlling terminals.
+ // The dev-detach binary calls setsid() before exec'ing the shell, preventing
+ // PTY-related hangs in nextest environments (unbuffer, script, terminal emulators).
+ let detach = get_dev_detach_bin();
+ let mut cmd = Command::new(detach);
repo.clean_cli_env(&mut cmd);
// Prevent user shell config from leaking into tests.
@@ -25,7 +35,18 @@ pub fn execute_shell_script(repo: &TestRepo, shell: &str, script: &str) -> Strin
cmd.env_remove("XONSHRC");
cmd.env_remove("XDG_CONFIG_HOME");
+ // Build argument list: dev-detach <shell> [shell-flags...] -c <script>
+ let binary = get_shell_binary(shell);
+ cmd.arg(binary);
+
+ // Add shell-specific no-config flags
match shell {
+ "bash" => {
+ cmd.arg("--noprofile").arg("--norc");
+ }
+ "zsh" => {
+ cmd.arg("--no-globalrcs").arg("-f");
+ }
"fish" => {
cmd.arg("--no-config");
}
@@ -41,18 +62,36 @@ pub fn execute_shell_script(repo: &TestRepo, shell: &str, script: &str) -> Strin
_ => {}
}
+ cmd.arg("-c").arg(script);
+
+ // Null stdin, piped stdout/stderr for full TTY isolation.
+ // Combined with setsid() from dev-detach, this guarantees no controlling terminal.
+ cmd.stdin(std::process::Stdio::null());
+ cmd.stdout(std::process::Stdio::piped());
+ cmd.stderr(std::process::Stdio::piped());
+
let output = cmd
- .arg("-c")
- .arg(script)
.current_dir(repo.root_path())
.output()
.unwrap_or_else(|e| panic!("Failed to execute {} script: {}", shell, e));
+ let stderr = String::from_utf8_lossy(&output.stderr);
+
if !output.status.success() {
panic!(
"Shell script failed:\nstdout: {}\nstderr: {}",
String::from_utf8_lossy(&output.stdout),
- String::from_utf8_lossy(&output.stderr)
+ stderr
+ );
+ }
+
+ // Check for shell errors in stderr (command not found, syntax errors, etc.)
+ // These indicate problems with our shell integration code
+ if stderr.contains("command not found") || stderr.contains("not defined") {
+ panic!(
+ "Shell integration error detected:\nstderr: {}\nstdout: {}",
+ stderr,
+ String::from_utf8_lossy(&output.stdout)
);
}
@@ -71,11 +110,18 @@ pub fn generate_init_code(repo: &TestRepo, shell: &str) -> String {
.expect("Failed to generate init code");
let stdout = String::from_utf8(output.stdout).expect("Invalid UTF-8 in init code");
+ let stderr = String::from_utf8_lossy(&output.stderr);
if !output.status.success() && stdout.trim().is_empty() {
+ panic!("Failed to generate init code:\nstderr: {}", stderr);
+ }
+
+ // Check for shell errors in the generated init code when it's evaluated
+ // This catches issues like missing compdef guards
+ if stderr.contains("command not found") || stderr.contains("not defined") {
panic!(
- "Failed to generate init code:\nstderr: {}",
- String::from_utf8_lossy(&output.stderr)
+ "Init code contains errors:\nstderr: {}\nGenerated code:\n{}",
+ stderr, stdout
);
}
diff --git a/tests/integration_tests/e2e_shell.rs b/tests/integration_tests/e2e_shell.rs
index 472d72cad..5f59b8888 100644
--- a/tests/integration_tests/e2e_shell.rs
+++ b/tests/integration_tests/e2e_shell.rs
@@ -8,6 +8,7 @@ use rstest::rstest;
// bash is baseline, fish exercises alternate syntax
#[case("bash")]
#[case("fish")]
+#[case("zsh")]
// Oil remains optional until tier-2 feature flag is enabled
#[cfg_attr(feature = "tier-2-integration-tests", case("oil"))]
fn test_e2e_switch_and_remove_roundtrip(#[case] shell: &str) {
diff --git a/tests/snapshots/integration__integration_tests__init__init_zsh.snap b/tests/snapshots/integration__integration_tests__init__init_zsh.snap
index a4de7fd06..dc7cfca3f 100644
--- a/tests/snapshots/integration__integration_tests__init__init_zsh.snap
+++ b/tests/snapshots/integration__integration_tests__init__init_zsh.snap
@@ -536,7 +536,7 @@ _wt__switch_commands() {
if [ "$funcstack[1]" = "_wt" ]; then
_wt "$@"
else
- compdef _wt wt
+ if (( $+functions[compdef] )); then compdef _wt wt; fi
fi
----- stderr -----