Skip to content

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

Refactor helper binaries into a workspace

Maximilian Rooscfca6567bb87
diff --git a/Cargo.lock b/Cargo.lock
index 49bf96c22..46b2bc4fc 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -607,6 +607,13 @@ dependencies = [
"syn",
]
+[[package]]
+name = "dev-detach"
+version = "0.1.0"
+dependencies = [
+ "nix 0.30.1",
+]
+
[[package]]
name = "digest"
version = "0.10.7"
@@ -1719,6 +1726,10 @@ dependencies = [
"winapi",
]
+[[package]]
+name = "setup-select-test"
+version = "0.1.0"
+
[[package]]
name = "sha2"
version = "0.10.9"
diff --git a/Cargo.toml b/Cargo.toml
index 6da82bff9..e1574b722 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,3 +1,6 @@
+[workspace]
+members = ["tests/helpers/dev-detach", "tests/helpers/setup-select-test"]
+
[package]
name = "worktrunk"
version = "0.1.5"
@@ -29,21 +32,6 @@ 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).
-# Uses conditional compilation: real implementation on Unix, stub on Windows.
-[[bin]]
-name = "dev-detach"
-path = "tests/bin/dev-detach.rs"
-
-# Helper binary to setup test environment for debugging `wt beta select`.
-# Creates a temporary repo with known state for manual testing.
-[[bin]]
-name = "setup-select-test"
-path = "tests/bin/setup-select-test.rs"
-
[dependencies]
anstream = "0.6"
anstyle = "1.0"
@@ -78,8 +66,6 @@ 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.30", default-features = false, features = ["process", "signal"] }
[build-dependencies]
diff --git a/tests/common/shell.rs b/tests/common/shell.rs
index 5a45c6aee..526672a0a 100644
--- a/tests/common/shell.rs
+++ b/tests/common/shell.rs
@@ -5,7 +5,34 @@ 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.
+///
+/// Automatically builds dev-detach if it doesn't exist, so `cargo test` works
+/// with zero setup.
fn get_dev_detach_bin() -> std::path::PathBuf {
+ use std::sync::OnceLock;
+
+ // Build dev-detach once on first call if needed
+ static BUILT: OnceLock<()> = OnceLock::new();
+ BUILT.get_or_init(|| {
+ // Check if dev-detach binary exists in target directory
+ let expected_path = std::env::current_exe()
+ .ok()
+ .and_then(|p| p.parent().map(|p| p.join("dev-detach")))
+ .filter(|p| p.exists());
+
+ if expected_path.is_none() {
+ eprintln!("Building dev-detach helper binary...");
+ let status = Command::new("cargo")
+ .args(["build", "-p", "dev-detach"])
+ .status()
+ .expect("Failed to run cargo build");
+
+ if !status.success() {
+ panic!("Failed to build dev-detach");
+ }
+ }
+ });
+
get_cargo_bin("dev-detach")
}
diff --git a/tests/helpers/dev-detach/Cargo.toml b/tests/helpers/dev-detach/Cargo.toml
new file mode 100644
index 000000000..292f40863
--- /dev/null
+++ b/tests/helpers/dev-detach/Cargo.toml
@@ -0,0 +1,17 @@
+# Test helper binary for TTY isolation in shell integration tests.
+# This is a workspace member (not a separate workspace) to share target/ and Cargo.lock.
+# Never published to crates.io (publish = false) - only used during development and CI.
+[package]
+name = "dev-detach"
+version = "0.1.0"
+edition = "2024"
+publish = false
+
+[dependencies]
+# Only needed on Unix for setsid() functionality
+[target.'cfg(unix)'.dependencies]
+nix = { version = "0.30", default-features = false, features = ["process", "signal"] }
+
+[lints.rust]
+# dev-detach uses nix crate's safe wrappers, no direct unsafe code
+unsafe_code = "forbid"
diff --git a/tests/bin/dev-detach.rs b/tests/helpers/dev-detach/src/main.rs
similarity index 100%
rename from tests/bin/dev-detach.rs
rename to tests/helpers/dev-detach/src/main.rs
diff --git a/tests/helpers/setup-select-test/Cargo.toml b/tests/helpers/setup-select-test/Cargo.toml
new file mode 100644
index 000000000..a8828998e
--- /dev/null
+++ b/tests/helpers/setup-select-test/Cargo.toml
@@ -0,0 +1,8 @@
+# Helper binary to setup test environment for debugging `wt beta select`.
+# This is a workspace member (not a separate workspace) to share target/ and Cargo.lock.
+# Never published to crates.io (publish = false) - only used during development.
+[package]
+name = "setup-select-test"
+version = "0.1.0"
+edition = "2024"
+publish = false
diff --git a/tests/bin/setup-select-test.rs b/tests/helpers/setup-select-test/src/main.rs
similarity index 100%
rename from tests/bin/setup-select-test.rs
rename to tests/helpers/setup-select-test/src/main.rs