Skip to content

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

fix(tests): seed tempfile's name generator per process (#4693)

Worktrunk Botbac7f7e137cf
diff --git a/Cargo.lock b/Cargo.lock
index 61170c86f..fef966c4f 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -4741,6 +4741,7 @@ dependencies = [
"dirs 7.0.0",
"dunce",
"etcetera",
+ "fastrand",
"fs2",
"gix-url",
"home",
diff --git a/Cargo.toml b/Cargo.toml
index 9a9c12abe..1f0254a9c 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -272,6 +272,9 @@ petname = { version = "=3.2.0", default-features = false, features = ["default-w
petname-macros = "=3.2.0"
tempfile = "3.27"
+# The generator tempfile names come from; the test helpers seed it per
+# process (`testing::temp_builder`, #4692).
+fastrand = "2.1.1"
# Timed waits on child processes (`Cmd::timeout`, `Cmd::delayed_stream`, the
# picker's pager). Replaced `wait-timeout`, whose SIGCHLD handler aborts the
diff --git a/clippy.toml b/clippy.toml
new file mode 100644
index 000000000..e8899c2a2
--- /dev/null
+++ b/clippy.toml
@@ -0,0 +1,8 @@
+# tempfile's own random names collide across concurrently started test
+# processes (#4692); the suite's helpers seed the name generator per process.
+# Production code keeps these constructors and opts out at the call site.
+disallowed-methods = [
+ { path = "tempfile::tempdir", reason = "use worktrunk::testing::tempdir (#4692)" },
+ { path = "tempfile::TempDir::new", reason = "use worktrunk::testing::tempdir (#4692)" },
+ { path = "tempfile::NamedTempFile::new", reason = "use worktrunk::testing::named_tempfile (#4692)" },
+]
diff --git a/src/cache.rs b/src/cache.rs
index 87815603b..a220205ab 100644
--- a/src/cache.rs
+++ b/src/cache.rs
@@ -218,7 +218,6 @@ pub fn count_json_files(dir: &Path) -> usize {
#[cfg(test)]
mod tests {
use super::*;
- use tempfile::TempDir;
#[derive(serde::Serialize, serde::Deserialize, PartialEq, Debug)]
struct V {
@@ -227,7 +226,7 @@ mod tests {
#[test]
fn test_read_write_roundtrip() {
- let tmp = TempDir::new().unwrap();
+ let tmp = crate::testing::tempdir().unwrap();
let path = tmp.path().join("sub/entry.json");
// Missing file is a miss.
@@ -240,7 +239,7 @@ mod tests {
#[test]
fn test_read_corrupt_json_returns_none() {
- let tmp = TempDir::new().unwrap();
+ let tmp = crate::testing::tempdir().unwrap();
let path = tmp.path().join("bad.json");
fs::write(&path, "not json {{").unwrap();
assert!(read_json::<V>(&path).is_none());
@@ -248,14 +247,14 @@ mod tests {
#[test]
fn test_clear_one_missing_returns_false() {
- let tmp = TempDir::new().unwrap();
+ let tmp = crate::testing::tempdir().unwrap();
let path = tmp.path().join("nope.json");
assert!(!clear_one(&path).unwrap());
}
#[test]
fn test_clear_one_propagates_non_not_found() {
- let tmp = TempDir::new().unwrap();
+ let tmp = crate::testing::tempdir().unwrap();
// Put a directory where a file is expected so remove_file returns
// EISDIR (or similar), not NotFound.
let path = tmp.path().join("dir.json");
@@ -266,7 +265,7 @@ mod tests {
#[test]
fn test_clear_json_files_counts_and_skips() {
- let tmp = TempDir::new().unwrap();
+ let tmp = crate::testing::tempdir().unwrap();
let dir = tmp.path().join("c");
fs::create_dir_all(&dir).unwrap();
fs::write(dir.join("a.json"), "{}").unwrap();
@@ -284,13 +283,13 @@ mod tests {
#[test]
fn test_clear_json_files_missing_dir_is_zero() {
- let tmp = TempDir::new().unwrap();
+ let tmp = crate::testing::tempdir().unwrap();
assert_eq!(clear_json_files(&tmp.path().join("nope")).unwrap(), 0);
}
#[test]
fn test_clear_json_files_propagates_read_dir_error() {
- let tmp = TempDir::new().unwrap();
+ let tmp = crate::testing::tempdir().unwrap();
// Put a file where a directory is expected — read_dir returns
// NotADirectory (not NotFound).
let path = tmp.path().join("not-a-dir");
@@ -301,7 +300,7 @@ mod tests {
#[test]
fn test_count_json_files() {
- let tmp = TempDir::new().unwrap();
+ let tmp = crate::testing::tempdir().unwrap();
let dir = tmp.path().join("c");
fs::create_dir_all(&dir).unwrap();
fs::write(dir.join("a.json"), "{}").unwrap();
@@ -313,7 +312,7 @@ mod tests {
#[test]
fn test_sweep_lru_trims_oldest_entries() {
- let tmp = TempDir::new().unwrap();
+ let tmp = crate::testing::tempdir().unwrap();
let dir = tmp.path().join("c");
fs::create_dir_all(&dir).unwrap();
@@ -335,7 +334,7 @@ mod tests {
#[test]
fn test_sweep_lru_no_op_under_bound() {
- let tmp = TempDir::new().unwrap();
+ let tmp = crate::testing::tempdir().unwrap();
let dir = tmp.path().join("c");
fs::create_dir_all(&dir).unwrap();
diff --git a/src/command_log.rs b/src/command_log.rs
index 53396b4ce..d2b41e687 100644
--- a/src/command_log.rs
+++ b/src/command_log.rs
@@ -225,7 +225,7 @@ mod tests {
#[test]
fn test_write_creates_file_lazily() {
- let dir = tempfile::tempdir().unwrap();
+ let dir = crate::testing::tempdir().unwrap();
let mut logger = CommandLog::new(dir.path(), "wt test");
assert!(!dir.path().join("commands.jsonl").exists());
@@ -242,7 +242,7 @@ mod tests {
#[test]
fn test_write_tolerates_unavailable_log_directory() {
- let dir = tempfile::tempdir().unwrap();
+ let dir = crate::testing::tempdir().unwrap();
let blocked = dir.path().join("not-a-directory");
fs::write(&blocked, "preserved contents").unwrap();
let mut logger = CommandLog::new(&blocked, "wt test");
@@ -255,7 +255,7 @@ mod tests {
#[test]
fn test_write_appends_multiple_entries() {
- let dir = tempfile::tempdir().unwrap();
+ let dir = crate::testing::tempdir().unwrap();
let mut logger = CommandLog::new(dir.path(), "wt test");
logger.write("a", "cmd-a", Some(0), Some(Duration::from_millis(1)));
@@ -273,7 +273,7 @@ mod tests {
#[test]
fn test_rotation_at_size_limit() {
- let dir = tempfile::tempdir().unwrap();
+ let dir = crate::testing::tempdir().unwrap();
let log_path = dir.path().join("commands.jsonl");
// Write a file just over MAX_LOG_SIZE
diff --git a/src/commands/backup.rs b/src/commands/backup.rs
index 42d1c60cc..38d10e254 100644
--- a/src/commands/backup.rs
+++ b/src/commands/backup.rs
@@ -165,7 +165,7 @@ mod tests {
#[test]
fn test_back_up_clobbered_path_moves_to_fresh_suffix() {
- let temp = tempfile::tempdir().unwrap();
+ let temp = worktrunk::testing::tempdir().unwrap();
let stale = temp.path().join("feature");
std::fs::create_dir(&stale).unwrap();
std::fs::write(stale.join("file"), "content").unwrap();
@@ -182,7 +182,7 @@ mod tests {
#[test]
fn test_back_up_clobbered_path_falls_back_when_suffix_taken() {
- let temp = tempfile::tempdir().unwrap();
+ let temp = worktrunk::testing::tempdir().unwrap();
let stale = temp.path().join("feature");
std::fs::create_dir(&stale).unwrap();
@@ -208,7 +208,7 @@ mod tests {
// A missing source fails the rename with a non-AlreadyExists error,
// which surfaces (with the "Failed to move" context) rather than being
// retried.
- let temp = tempfile::tempdir().unwrap();
+ let temp = worktrunk::testing::tempdir().unwrap();
let missing = temp.path().join("does-not-exist");
let err = back_up_clobbered_path(&missing, "20250101-000000").unwrap_err();
assert!(
@@ -221,7 +221,7 @@ mod tests {
fn test_back_up_clobbered_path_keeps_incrementing_past_many_collisions() {
// There is no attempt cap: the move keeps counting up until a free
// name is found, however many backups already exist.
- let temp = tempfile::tempdir().unwrap();
+ let temp = worktrunk::testing::tempdir().unwrap();
let stale = temp.path().join("feature");
std::fs::create_dir(&stale).unwrap();
@@ -239,7 +239,7 @@ mod tests {
#[test]
fn test_back_up_clobbered_path_now_uses_timestamped_suffix() {
- let temp = tempfile::tempdir().unwrap();
+ let temp = worktrunk::testing::tempdir().unwrap();
let stale = temp.path().join("feature");
std::fs::create_dir(&stale).unwrap();
diff --git a/src/commands/command_executor.rs b/src/commands/command_executor.rs
index aa292f4b2..1389f8d3c 100644
--- a/src/commands/command_executor.rs
+++ b/src/commands/command_executor.rs
@@ -928,7 +928,10 @@ mod tests {
#[test]
fn test_hook_spawn_failure_retains_io_error_and_has_no_child_exit_code() {
- let missing = tempfile::tempdir().unwrap().path().join("missing-cwd");
+ let missing = worktrunk::testing::tempdir()
+ .unwrap()
+ .path()
+ .join("missing-cwd");
let shell = worktrunk::shell_exec::ShellConfig::get().unwrap();
let error = worktrunk::shell_exec::Cmd::new(shell.executable.to_string_lossy())
.current_dir(&missing)
diff --git a/src/commands/configure_shell.rs b/src/commands/configure_shell.rs
index f800c3f2b..10d1b4323 100644
--- a/src/commands/configure_shell.rs
+++ b/src/commands/configure_shell.rs
@@ -1854,7 +1854,7 @@ mod tests {
("replaced", Some(previewed), Some(b"user\r\n".as_slice())),
("deleted", Some(previewed), None),
] {
- let dir = tempfile::TempDir::new().unwrap();
+ let dir = worktrunk::testing::tempdir().unwrap();
let completion = dir.path().join("wt.fish");
if let Some(content) = current {
fs::write(&completion, content).unwrap();
@@ -1868,7 +1868,7 @@ mod tests {
#[test]
fn test_apply_shell_completions_verifies_before_creating_parent() {
- let dir = tempfile::TempDir::new().unwrap();
+ let dir = worktrunk::testing::tempdir().unwrap();
let completion = dir.path().join("removed/wt.fish");
let preview = CompletionResult {
shell: Shell::Fish,
@@ -1891,7 +1891,7 @@ mod tests {
#[test]
fn test_apply_shell_completions_skips_shell_missing_from_apply_scan() {
- let dir = tempfile::TempDir::new().unwrap();
+ let dir = worktrunk::testing::tempdir().unwrap();
let completion = dir.path().join("wt.fish");
let preview = CompletionResult {
shell: Shell::Fish,
@@ -1973,7 +1973,7 @@ mod tests {
#[test]
fn test_scan_managed_files_skips_wrong_extension_and_directories() {
- let dir = tempfile::TempDir::new().unwrap();
+ let dir = worktrunk::testing::tempdir().unwrap();
let root = dir.path();
// Wrong extension: skipped.
fs::write(root.join("notes.txt"), "anything").unwrap();
@@ -1988,7 +1988,7 @@ mod tests {
#[test]
fn test_remove_config_file_requires_matching_preimage() {
- let dir = tempfile::TempDir::new().unwrap();
+ let dir = worktrunk::testing::tempdir().unwrap();
let wrapper = dir.path().join("wt.fish");
let previewed = b"# worktrunk shell integration for fish\n";
fs::write(&wrapper, "# user replacement\n").unwrap();
@@ -2006,7 +2006,7 @@ mod tests {
#[test]
fn test_preimage_verification_rejects_directories() {
- let dir = tempfile::TempDir::new().unwrap();
+ let dir = worktrunk::testing::tempdir().unwrap();
let integration_error = remove_config_file(dir.path(), b"").unwrap_err();
let completion_error = verify_completion_preimage(dir.path(), None).unwrap_err();
@@ -2023,7 +2023,7 @@ mod tests {
#[test]
fn test_configure_shell_rejects_invalid_utf8_before_modifying_file() {
- let dir = tempfile::TempDir::new().unwrap();
+ let dir = worktrunk::testing::tempdir().unwrap();
let rc = dir.path().join(".zshrc");
let content = b"# non-UTF-8: \xff\n";
fs::write(&rc, content).unwrap();
@@ -2038,7 +2038,7 @@ mod tests {
#[test]
fn test_configure_shell_already_exists_before_invalid_utf8() {
- let dir = tempfile::TempDir::new().unwrap();
+ let dir = worktrunk::testing::tempdir().unwrap();
let rc = dir.path().join(".zshrc");
let content = b"eval \"$(wt config shell init zsh)\"\n# non-UTF-8: \xff\n";
fs::write(&rc, content).unwrap();
@@ -2054,7 +2054,7 @@ mod tests {
fn test_configure_shell_reports_dangling_symlink() {
use std::os::unix::fs::symlink;
- let dir = tempfile::TempDir::new().unwrap();
+ let dir = worktrunk::testing::tempdir().unwrap();
let rc = dir.path().join(".zshrc");
let target = dir.path().join("missing-target");
symlink(&target, &rc).unwrap();
@@ -2076,7 +2076,7 @@ mod tests {
#[cfg(unix)]
#[test]
fn test_configure_shell_reports_non_symlink_create_error() {
- let dir = tempfile::TempDir::new().unwrap();
+ let dir = worktrunk::testing::tempdir().unwrap();
let rc = dir.path().join("x".repeat(300));
let error = configure_shell_file(Shell::Zsh, &rc, false, true, "wt")
@@ -2112,7 +2112,7 @@ mod tests {
fn test_new_rc_error_reports_live_symlink_as_concurrent_creator() {
use std::os::unix::fs::symlink;
- let dir = tempfile::TempDir::new().unwrap();
+ let dir = worktrunk::testing::tempdir().unwrap();
let target = dir.path().join("target");
let path = dir.path().join(".zshrc");
fs::write(&target, "# concurrent config\n").unwrap();
@@ -2130,7 +2130,7 @@ mod tests {
#[test]
fn test_configure_shell_appends_without_replacing_existing_file() {
- let dir = tempfile::TempDir::new().unwrap();
+ let dir = worktrunk::testing::tempdir().unwrap();
let rc = dir.path().join(".zshrc");
let hard_link = dir.path().join("zshrc-hard-link");
fs::write(&rc, "export EDITOR=hx\n").unwrap();
@@ -2150,7 +2150,7 @@ mod tests {
#[test]
fn test_configure_shell_opens_rc_with_exclusive_lock() {
- let dir = tempfile::TempDir::new().unwrap();
+ let dir = worktrunk::testing::tempdir().unwrap();
let rc = dir.path().join(".zshrc");
fs::write(&rc, "export EDITOR=hx\n").unwrap();
@@ -2171,7 +2171,7 @@ mod tests {
#[test]
fn test_open_locked_rc_file_reports_open_errors() {
- let dir = tempfile::TempDir::new().unwrap();
+ let dir = worktrunk::testing::tempdir().unwrap();
let missing = dir.path().join("missing-zshrc");
let error = open_locked_rc_file(&missing).unwrap_err();
@@ -2184,7 +2184,7 @@ mod tests {
#[test]
fn test_append_shell_integration_reports_write_errors() {
- let dir = tempfile::TempDir::new().unwrap();
+ let dir = worktrunk::testing::tempdir().unwrap();
let rc = dir.path().join(".zshrc");
let original = "export EDITOR=hx\n";
fs::write(&rc, original).unwrap();
@@ -2209,7 +2209,7 @@ mod tests {
#[test]
fn test_configure_shell_rereads_open_file_before_appending() {
- let dir = tempfile::TempDir::new().unwrap();
+ let dir = worktrunk::testing::tempdir().unwrap();
let rc = dir.path().join(".zshrc");
fs::write(&rc, "export EDITOR=hx\n").unwrap();
@@ -2245,7 +2245,7 @@ mod tests {
#[test]
fn test_uninstall_previewed_lines_preserves_mixed_line_endings() {
- let dir = tempfile::TempDir::new().unwrap();
+ let dir = worktrunk::testing::tempdir().unwrap();
let rc = dir.path().join("profile.ps1");
let integration = "Invoke-Expression (& wt config shell init powershell)";
fs::write(
@@ -2309,7 +2309,7 @@ mod tests {
#[test]
fn test_uninstall_from_file_preserves_mode_and_leaves_no_temp_file() {
use std::os::unix::fs::PermissionsExt;
- let dir = tempfile::TempDir::new().unwrap();
+ let dir = worktrunk::testing::tempdir().unwrap();
let rc = dir.path().join(".bashrc");
write_rc(&rc);
// 0644 is the usual rc mode and differs from the 0600 a fresh temp file
@@ -2333,7 +2333,7 @@ mod tests {
// A dotfile manager's layout: the real file lives in a repo and `~/.bashrc`
// is a link to it. The rewrite must follow the link, not replace it —
// otherwise the user's rc silently stops tracking their dotfiles.
- let dir = tempfile::TempDir::new().unwrap();
+ let dir = worktrunk::testing::tempdir().unwrap();
let repo = dir.path().join("dotfiles");
let home = dir.path().join("home");
fs::create_dir(&repo).unwrap();
@@ -2361,7 +2361,7 @@ mod tests {
#[test]
fn test_uninstall_from_file_leaves_rc_intact_when_write_fails() {
use std::os::unix::fs::PermissionsExt;
- let dir = tempfile::TempDir::new().unwrap();
+ let dir = worktrunk::testing::tempdir().unwrap();
let rc = dir.path().join(".bashrc");
write_rc(&rc);
let original = fs::read_to_string(&rc).unwrap();
@@ -2387,7 +2387,7 @@ mod tests {
fn test_preimage_writes_leave_files_intact_on_io_error() {
use std::os::unix::fs::PermissionsExt;
- let dir = tempfile::TempDir::new().unwrap();
+ let dir = worktrunk::testing::tempdir().unwrap();
let wrapper = dir.path().join("wt.fish");
let completion = dir.path().join("completions.fish");
let wrapper_content = b"# worktrunk shell integration for fish\n";
@@ -2433,7 +2433,7 @@ mod tests {
#[test]
fn test_scan_managed_files_skips_unreadable_file() {
use std::os::unix::fs::PermissionsExt;
- let dir = tempfile::TempDir::new().unwrap();
+ let dir = worktrunk::testing::tempdir().unwrap();
let root = dir.path();
let unreadable = root.join("locked.fish");
fs::write(&unreadable, "function wt\nend\n").unwrap();
diff --git a/src/commands/hook_plan.rs b/src/commands/hook_plan.rs
index 01722c15c..e724733f8 100644
--- a/src/commands/hook_plan.rs
+++ b/src/commands/hook_plan.rs
@@ -469,7 +469,7 @@ mod tests {
// With the project command approved, it survives the read-only gate.
// A tempdir-backed approvals path keeps the write off the real user
// config dir, which the nix build sandbox makes unwritable.
- let temp_dir = tempfile::tempdir().unwrap();
+ let temp_dir = worktrunk::testing::tempdir().unwrap();
let approvals_path = temp_dir.path().join("approvals.toml");
let mut approvals = Approvals::default();
approvals
diff --git a/src/commands/list/model/item.rs b/src/commands/list/model/item.rs
index 019da8137..8750b75c9 100644
--- a/src/commands/list/model/item.rs
+++ b/src/commands/list/model/item.rs
@@ -1170,7 +1170,7 @@ mod tests {
#[test]
fn construction_and_reclassification_update_list_item_identity() {
- let root = tempfile::tempdir().unwrap();
+ let root = worktrunk::testing::tempdir().unwrap();
let worktree_ref = WorktreeRef::new(root.path(), Some("feature"), "abc123");
let worktree_id = worktree_ref.clone().into_branch_ref().id().clone();
let mut item = ListItem::new_worktree(worktree_ref, WorktreeData::default());
diff --git a/src/commands/picker/mod.rs b/src/commands/picker/mod.rs
index 49d4990bf..a7ce2f849 100644
--- a/src/commands/picker/mod.rs
+++ b/src/commands/picker/mod.rs
@@ -2896,7 +2896,7 @@ pub mod tests {
fn test_do_removal_removes_worktree_and_branch() {
let test = worktrunk::testing::TestRepo::with_initial_commit();
let repo = worktrunk::git::Repository::at(test.path()).unwrap();
- let wt_dir = tempfile::tempdir().unwrap();
+ let wt_dir = worktrunk::testing::tempdir().unwrap();
let wt_path = wt_dir.path().join("feature");
repo.run_command(&[
@@ -3047,7 +3047,7 @@ pub mod tests {
fn test_do_removal_removes_detached_worktree() {
let test = worktrunk::testing::TestRepo::with_initial_commit();
let repo = worktrunk::git::Repository::at(test.path()).unwrap();
- let wt_dir = tempfile::tempdir().unwrap();
+ let wt_dir = worktrunk::testing::tempdir().unwrap();
let wt_path = wt_dir.path().join("detached");
repo.run_command(&[
@@ -3195,7 +3195,7 @@ pub mod tests {
fn test_do_removal_skips_unapproved_pre_remove_hook() {
let test = worktrunk::testing::TestRepo::with_initial_commit();
let repo = worktrunk::git::Repository::at(test.path()).unwrap();
- let wt_dir = tempfile::tempdir().unwrap();
+ let wt_dir = worktrunk::testing::tempdir().unwrap();
let wt_path = wt_dir.path().join("feature");
repo.run_command(&[
"worktree",
@@ -3209,7 +3209,7 @@ pub mod tests {
// A `pre-remove` hook in the invoking worktree's `.config/wt.toml` —
// the config the picker removal resolves against — that would write a
// marker if it ever ran.
- let marker_dir = tempfile::tempdir().unwrap();
+ let marker_dir = worktrunk::testing::tempdir().unwrap();
let marker = marker_dir.path().join("pre-remove-ran");
fs::create_dir_all(test.path().join(".config")).unwrap();
fs::write(
@@ -3471,7 +3471,7 @@ pub mod tests {
fn test_apply_removes_selected_detached_worktree_by_path_token() {
let test = worktrunk::testing::TestRepo::with_initial_commit();
let repo = worktrunk::git::Repository::at(test.path()).unwrap();
- let wt_dir = tempfile::tempdir().unwrap();
+ let wt_dir = worktrunk::testing::tempdir().unwrap();
let first_path = wt_dir.path().join("detached-one");
let second_path = wt_dir.path().join("detached-two");
@@ -3555,7 +3555,7 @@ pub mod tests {
// picker prelude primes it at startup.
let factory_repo = worktrunk::git::Repository::at(test.path()).unwrap();
- let wt_dir = tempfile::tempdir().unwrap();
+ let wt_dir = worktrunk::testing::tempdir().unwrap();
let doomed_path = wt_dir.path().join("doomed");
factory_repo
.run_command(&[
@@ -3975,7 +3975,7 @@ pub mod tests {
fn test_apply_restores_row_when_removal_fails() {
let test = worktrunk::testing::TestRepo::with_initial_commit();
let repo = worktrunk::git::Repository::at(test.path()).unwrap();
- let wt_dir = tempfile::tempdir().unwrap();
+ let wt_dir = worktrunk::testing::tempdir().unwrap();
let wt_path = wt_dir.path().join("feature");
repo.run_command(&[
"worktree",
@@ -3998,7 +3998,7 @@ pub mod tests {
// Approve `false` so the hook is selected into the read-only plan and
// actually runs; an isolated approvals path keeps real config untouched.
let pid = repo.project_identifier().unwrap();
- let approvals_dir = tempfile::tempdir().unwrap();
+ let approvals_dir = worktrunk::testing::tempdir().unwrap();
let approvals_path = approvals_dir.path().join("approvals.toml");
let mut approvals = Approvals::default();
approvals
@@ -4076,7 +4076,7 @@ pub mod tests {
let test = worktrunk::testing::TestRepo::with_initial_commit();
let repo = worktrunk::git::Repository::at(test.path()).unwrap();
- let wt_dir = tempfile::tempdir().unwrap();
+ let wt_dir = worktrunk::testing::tempdir().unwrap();
let wt_path = wt_dir.path().join("feature");
repo.run_command(&[
"worktree",
@@ -4170,7 +4170,7 @@ pub mod tests {
fn test_apply_drops_morphed_row_when_pre_remove_hook_integrates_branch() {
let test = worktrunk::testing::TestRepo::with_initial_commit();
let repo = worktrunk::git::Repository::at(test.path()).unwrap();
- let wt_dir = tempfile::tempdir().unwrap();
+ let wt_dir = worktrunk::testing::tempdir().unwrap();
let wt_path = wt_dir.path().join("feature");
repo.run_command(&[
"worktree",
@@ -4202,7 +4202,7 @@ pub mod tests {
.unwrap();
let pid = repo.project_identifier().unwrap();
- let approvals_dir = tempfile::tempdir().unwrap();
+ let approvals_dir = worktrunk::testing::tempdir().unwrap();
let approvals_path = approvals_dir.path().join("approvals.toml");
let mut approvals = Approvals::default();
approvals
@@ -4265,7 +4265,7 @@ pub mod tests {
fn test_apply_drops_unmorphable_kept_branch_row() {
let test = worktrunk::testing::TestRepo::with_initial_commit();
let repo = worktrunk::git::Repository::at(test.path()).unwrap();
- let wt_dir = tempfile::tempdir().unwrap();
+ let wt_dir = worktrunk::testing::tempdir().unwrap();
let wt_path = wt_dir.path().join("feature");
repo.run_command(&[
"worktree",
@@ -4331,7 +4331,7 @@ pub mod tests {
fn test_apply_drops_integrated_worktree_row() {
let test = worktrunk::testing::TestRepo::with_initial_commit();
let repo = worktrunk::git::Repository::at(test.path()).unwrap();
- let wt_dir = tempfile::tempdir().unwrap();
+ let wt_dir = worktrunk::testing::tempdir().unwrap();
let wt_path = wt_dir.path().join("feature");
// No extra commit → `feature` sits at main's commit (integrated), so
// SafeDelete deletes the branch along with the worktree.
diff --git a/src/commands/picker/pager.rs b/src/commands/picker/pager.rs
index 52edd3920..edaace553 100644
--- a/src/commands/picker/pager.rs
+++ b/src/commands/picker/pager.rs
@@ -263,7 +263,7 @@ mod tests {
#[cfg(unix)]
fn test_pipe_through_pager_descendant_pipes_time_out() {
for redirect in ["", ">/dev/null"] {
- let fixture = tempfile::tempdir().unwrap();
+ let fixture = worktrunk::testing::tempdir().unwrap();
let release = fixture.path().join("release");
let done = fixture.path().join("done");
let quote =
diff --git a/src/commands/picker/preview_orchestrator.rs b/src/commands/picker/preview_orchestrator.rs
index 9ed7344a1..e2e7aa030 100644
--- a/src/commands/picker/preview_orchestrator.rs
+++ b/src/commands/picker/preview_orchestrator.rs
@@ -961,7 +961,7 @@ mod tests {
#[test]
fn detached_worktrees_at_same_commit_have_distinct_preview_ids() {
let t = TestRepo::with_initial_commit();
- let linked = tempfile::tempdir().unwrap();
+ let linked = worktrunk::testing::tempdir().unwrap();
let clean_path = linked.path().join("clean");
let dirty_path = linked.path().join("dirty");
let clean_arg = clean_path.to_str().unwrap();
diff --git a/src/commands/run_pipeline.rs b/src/commands/run_pipeline.rs
index 8fff4b1f5..4e125e1c7 100644
--- a/src/commands/run_pipeline.rs
+++ b/src/commands/run_pipeline.rs
@@ -349,7 +349,7 @@ mod tests {
#[test]
fn pipeline_spawn_failure_retains_working_directory_and_io_cause() {
- let dir = tempfile::tempdir().unwrap();
+ let dir = worktrunk::testing::tempdir().unwrap();
let missing = dir.path().join("missing-worktree");
let log = fs::File::create(dir.path().join("command.log")).unwrap();
let error = spawn_shell_command("true", &missing, log).err().unwrap();
diff --git a/src/commands/step/promote.rs b/src/commands/step/promote.rs
index bab4b55c8..a1fe60e8c 100644
--- a/src/commands/step/promote.rs
+++ b/src/commands/step/promote.rs
@@ -470,7 +470,7 @@ mod tests {
#[test]
fn test_move_entry_file() {
- let tmp = tempfile::tempdir().unwrap();
+ let tmp = worktrunk::testing::tempdir().unwrap();
let src = tmp.path().join("source.txt");
let dest = tmp.path().join("subdir/dest.txt");
@@ -483,7 +483,7 @@ mod tests {
#[test]
fn test_move_entry_directory() {
- let tmp = tempfile::tempdir().unwrap();
+ let tmp = worktrunk::testing::tempdir().unwrap();
let src = tmp.path().join("srcdir");
let dest = tmp.path().join("nested/destdir");
@@ -546,7 +546,7 @@ mod tests {
#[test]
fn test_copy_and_remove_file() {
- let tmp = tempfile::tempdir().unwrap();
+ let tmp = worktrunk::testing::tempdir().unwrap();
let src = tmp.path().join("source.txt");
let dest = tmp.path().join("dest.txt");
@@ -559,7 +559,7 @@ mod tests {
#[test]
fn test_copy_and_remove_directory() {
- let tmp = tempfile::tempdir().unwrap();
+ let tmp = worktrunk::testing::tempdir().unwrap();
let src = tmp.path().join("srcdir");
let dest = tmp.path().join("destdir");
@@ -583,7 +583,7 @@ mod tests {
// destroyed rather than moved. A source that is already gone is the
// deterministic case: `copy_leaf` reports the skip, and the delete —
// which would take a file recreated since — must not be reached.
- let tmp = tempfile::tempdir().unwrap();
+ let tmp = worktrunk::testing::tempdir().unwrap();
let src = tmp.path().join("gone.txt");
let dest = tmp.path().join("dest.txt");
@@ -604,7 +604,7 @@ mod tests {
// `distribute_staged` runs after the branch exchange, and a promote
// that dies there leaves the staged files behind a `check_leftover_
// staging` refusal whose remedy deletes them.
- let tmp = tempfile::tempdir().unwrap();
+ let tmp = worktrunk::testing::tempdir().unwrap();
let src = tmp.path().join("srcdir");
let dest = tmp.path().join("destdir");
fs::create_dir_all(&src).unwrap();
diff --git a/src/commands/step/prune.rs b/src/commands/step/prune.rs
index 29fedaffb..e237015ea 100644
--- a/src/commands/step/prune.rs
+++ b/src/commands/step/prune.rs
@@ -1555,7 +1555,7 @@ mod tests {
#[test]
fn ref_write_times_follow_the_ref_backend() {
- let dir = tempfile::tempdir().unwrap();
+ let dir = worktrunk::testing::tempdir().unwrap();
let write = |relative: &str, epoch: u64| {
let path = dir.path().join(relative);
fs::create_dir_all(path.parent().unwrap()).unwrap();
@@ -1580,7 +1580,7 @@ mod tests {
assert_eq!(reftable.epoch("loose").unwrap(), 400);
// With neither a loose ref nor shared storage, nothing dates the branch.
- let empty = tempfile::tempdir().unwrap();
+ let empty = worktrunk::testing::tempdir().unwrap();
let none = RefWriteTimes::read(empty.path(), false, ["gone"]).unwrap();
assert_eq!(
none.epoch("gone").unwrap_err().to_string(),
diff --git a/src/commands/worktree/switch.rs b/src/commands/worktree/switch.rs
index 9cd947260..4ddeabd5e 100644
--- a/src/commands/worktree/switch.rs
+++ b/src/commands/worktree/switch.rs
@@ -2394,7 +2394,7 @@ mod tests {
#[test]
#[cfg(windows)]
fn deep_worktree_keeps_operational_path_separate_from_identity() {
- let temp = tempfile::tempdir().expect("temp dir");
+ let temp = worktrunk::testing::tempdir().expect("temp dir");
let mut deep = temp.path().join("deep");
while deep.as_os_str().len() < 320 {
deep.push("nested-worktree-directory");
diff --git a/src/completion.rs b/src/completion.rs
index 4d81d970a..a2c57ea22 100644
--- a/src/completion.rs
+++ b/src/completion.rs
@@ -1117,7 +1117,7 @@ mod tests {
#[test]
fn test_discover_finds_wt_executables() {
use std::os::unix::fs::PermissionsExt;
- let dir = tempfile::tempdir().unwrap();
+ let dir = worktrunk::testing::tempdir().unwrap();
for name in ["wt-alpha", "wt-beta"] {
let path = dir.path().join(name);
@@ -1133,7 +1133,7 @@ mod tests {
#[test]
fn test_discover_skips_non_executable() {
use std::os::unix::fs::PermissionsExt;
- let dir = tempfile::tempdir().unwrap();
+ let dir = worktrunk::testing::tempdir().unwrap();
let exec = dir.path().join("wt-exec");
std::fs::write(&exec, "#!/bin/sh\n").unwrap();
@@ -1151,8 +1151,8 @@ mod tests {
#[test]
fn test_discover_deduplicates_across_dirs() {
use std::os::unix::fs::PermissionsExt;
- let dir1 = tempfile::tempdir().unwrap();
- let dir2 = tempfile::tempdir().unwrap();
+ let dir1 = worktrunk::testing::tempdir().unwrap();
+ let dir2 = worktrunk::testing::tempdir().unwrap();
for dir in [dir1.path(), dir2.path()] {
let path = dir.join("wt-dup");
@@ -1169,7 +1169,7 @@ mod tests {
#[test]
fn test_discover_skips_bare_prefix_and_non_matching() {
use std::os::unix::fs::PermissionsExt;
- let dir = tempfile::tempdir().unwrap();
+ let dir = worktrunk::testing::tempdir().unwrap();
// "wt-" with no suffix should be skipped
let empty = dir.path().join("wt-");
@@ -1231,7 +1231,7 @@ mod tests {
#[test]
fn test_discover_results_are_sorted() {
use std::os::unix::fs::PermissionsExt;
- let dir = tempfile::tempdir().unwrap();
+ let dir = worktrunk::testing::tempdir().unwrap();
// Create in reverse alphabetical order
for name in ["wt-zebra", "wt-apple", "wt-mango"] {
@@ -1334,7 +1334,7 @@ mod tests {
#[test]
fn test_forward_to_custom_binary() {
use std::os::unix::fs::PermissionsExt;
- let dir = tempfile::tempdir().unwrap();
+ let dir = worktrunk::testing::tempdir().unwrap();
let script = dir.path().join("wt-fake");
std::fs::write(&script, "#!/bin/sh\nprintf '%s\\n%s' '--all' '--verbose'\n").unwrap();
std::fs::set_permissions(&script, std::fs::Permissions::from_mode(0o755)).unwrap();
@@ -1354,7 +1354,7 @@ mod tests {
#[test]
fn test_forward_to_failing_binary() {
use std::os::unix::fs::PermissionsExt;
- let dir = tempfile::tempdir().unwrap();
+ let dir = worktrunk::testing::tempdir().unwrap();
let script = dir.path().join("wt-fail");
std::fs::write(&script, "#!/bin/sh\nexit 1\n").unwrap();
std::fs::set_permissions(&script, std::fs::Permissions::from_mode(0o755)).unwrap();
diff --git a/src/config/approvals.rs b/src/config/approvals.rs
index 73319d985..68af44df5 100644
--- a/src/config/approvals.rs
+++ b/src/config/approvals.rs
@@ -504,7 +504,7 @@ mod tests {
use tempfile::TempDir;
fn test_dir() -> (TempDir, PathBuf) {
- let temp_dir = TempDir::new().unwrap();
+ let temp_dir = crate::testing::tempdir().unwrap();
let approvals_path = temp_dir.path().join("approvals.toml");
(temp_dir, approvals_path)
}
@@ -862,7 +862,7 @@ approved-commands = ["npm test"]
/// untouched and must not report that any approvals were saved.
#[test]
fn test_save_to_blocked_parent_preserves_file() {
- let dir = TempDir::new().unwrap();
+ let dir = crate::testing::tempdir().unwrap();
let parent = dir.path().join("blocked");
std::fs::write(&parent, "keep this file").unwrap();
let path = parent.join("approvals.toml");
@@ -883,7 +883,7 @@ approved-commands = ["npm test"]
fn test_save_failure_preserves_existing_file() {
use std::os::unix::fs::PermissionsExt;
- let temp_dir = TempDir::new().unwrap();
+ let temp_dir = crate::testing::tempdir().unwrap();
let approvals_dir = temp_dir.path().join("readonly");
std::fs::create_dir(&approvals_dir).unwrap();
let path = approvals_dir.join("approvals.toml");
@@ -1028,7 +1028,7 @@ approved-commands = ["npm test"]
/// `load_from_config_file` extracts approved-commands from a config.toml file.
#[test]
fn test_load_from_config_file() {
- let temp_dir = TempDir::new().unwrap();
+ let temp_dir = crate::testing::tempdir().unwrap();
let config_path = temp_dir.path().join("config.toml");
std::fs::write(
@@ -1054,7 +1054,7 @@ approved-commands = ["cargo build"]
/// existing commands alongside the new one.
#[test]
fn test_mutation_picks_up_config_toml_fallback() {
- let temp_dir = TempDir::new().unwrap();
+ let temp_dir = crate::testing::tempdir().unwrap();
let approvals_path = temp_dir.path().join("approvals.toml");
let config_path = temp_dir.path().join("config.toml");
@@ -1090,7 +1090,7 @@ approved-commands = ["npm install"]
#[test]
fn test_load_from_path_nonexistent() {
- let temp_dir = TempDir::new().unwrap();
+ let temp_dir = crate::testing::tempdir().unwrap();
let path = temp_dir.path().join("nonexistent.toml");
let approvals = load_from_path(&path).unwrap();
assert!(approvals.projects.is_empty());
@@ -1098,7 +1098,7 @@ approved-commands = ["npm install"]
#[test]
fn test_load_from_file_invalid_toml() {
- let temp_dir = TempDir::new().unwrap();
+ let temp_dir = crate::testing::tempdir().unwrap();
let path = temp_dir.path().join("approvals.toml");
std::fs::write(&path, "this is { not valid toml").unwrap();
let err = Approvals::load_from_file(&path).unwrap_err();
@@ -1111,7 +1111,7 @@ approved-commands = ["npm install"]
#[test]
fn test_load_from_file_rejects_unknown_top_level_key() {
- let temp_dir = TempDir::new().unwrap();
+ let temp_dir = crate::testing::tempdir().unwrap();
let path = temp_dir.path().join("approvals.toml");
std::fs::write(
&path,
@@ -1131,7 +1131,7 @@ approved-commands = ["npm test"]
#[test]
fn test_load_from_file_rejects_unknown_project_key() {
- let temp_dir = TempDir::new().unwrap();
+ let temp_dir = crate::testing::tempdir().unwrap();
let path = temp_dir.path().join("approvals.toml");
std::fs::write(
&path,
@@ -1151,7 +1151,7 @@ approved-command = ["npm test"]
#[test]
fn test_load_from_config_file_invalid_toml() {
- let temp_dir = TempDir::new().unwrap();
+ let temp_dir = crate::testing::tempdir().unwrap();
let config_path = temp_dir.path().join("config.toml");
std::fs::write(&config_path, "not { valid toml here").unwrap();
let err = Approvals::load_from_config_file(&config_path).unwrap_err();
diff --git a/src/config/deprecation.rs b/src/config/deprecation.rs
index 7534f2a91..c8ea63084 100644
--- a/src/config/deprecation.rs
+++ b/src/config/deprecation.rs
@@ -1669,6 +1669,10 @@ fn format_migration_diff(
migrated: &str,
label: &str,
) -> anyhow::Result<Option<String>> {
+ #[expect(
+ clippy::disallowed_methods,
+ reason = "production code; the disallowed-methods rule targets the test suite (#4692)"
+ )]
let dir = tempfile::tempdir().context("failed to create tempdir for migration diff")?;
let subdir = dir.path().join(label);
std::fs::create_dir(&subdir).context("failed to create subdir in fresh tempdir")?;
@@ -4399,7 +4403,7 @@ approved-commands = ["npm install"]
#[test]
fn test_copy_approved_commands_creates_approvals_file() {
- let temp_dir = tempfile::TempDir::new().unwrap();
+ let temp_dir = crate::testing::tempdir().unwrap();
let config_path = temp_dir.path().join("config.toml");
let content = r#"
[projects."github.com/user/repo"]
@@ -4437,7 +4441,7 @@ approved-commands = ["cargo build"]
#[test]
fn test_copy_approved_commands_skips_when_approvals_exists() {
- let temp_dir = tempfile::TempDir::new().unwrap();
+ let temp_dir = crate::testing::tempdir().unwrap();
let config_path = temp_dir.path().join("config.toml");
let approvals_path = temp_dir.path().join("approvals.toml");
let content = r#"
@@ -4458,7 +4462,7 @@ approved-commands = ["npm install"]
#[test]
fn test_copy_approved_commands_errors_when_existing_approvals_invalid() {
- let temp_dir = tempfile::TempDir::new().unwrap();
+ let temp_dir = crate::testing::tempdir().unwrap();
let config_path = temp_dir.path().join("config.toml");
let approvals_path = temp_dir.path().join("approvals.toml");
let content = r#"
@@ -4481,7 +4485,7 @@ approved-commands = ["npm install"]
#[test]
fn test_copy_approved_commands_skips_when_empty() {
- let temp_dir = tempfile::TempDir::new().unwrap();
+ let temp_dir = crate::testing::tempdir().unwrap();
let config_path = temp_dir.path().join("config.toml");
let content = r#"
[projects."github.com/user/repo"]
@@ -4506,7 +4510,7 @@ worktree-path = ".worktrees/{{ branch | sanitize }}"
fn test_copy_approved_commands_surfaces_write_failure() {
use std::os::unix::fs::PermissionsExt;
- let temp_dir = tempfile::TempDir::new().unwrap();
+ let temp_dir = crate::testing::tempdir().unwrap();
let config_path = temp_dir.path().join("config.toml");
let content = r#"
[projects."github.com/user/repo"]
@@ -4549,7 +4553,7 @@ approved-commands = ["npm install"]
/// "nothing to copy" — same data-loss class as the write-failure case.
#[test]
fn test_copy_approved_commands_surfaces_read_failure() {
- let temp_dir = tempfile::TempDir::new().unwrap();
+ let temp_dir = crate::testing::tempdir().unwrap();
let config_path = temp_dir.path().join("config.toml");
std::fs::write(&config_path, "this is = = not valid toml\n").unwrap();
diff --git a/src/config/user/tests.rs b/src/config/user/tests.rs
index 75d0ed21e..410b045fb 100644
--- a/src/config/user/tests.rs
+++ b/src/config/user/tests.rs
@@ -622,7 +622,7 @@ worktree-path = "../{{ main_worktree }}.{{ branch }}"
#[test]
fn test_set_project_worktree_path() {
- let dir = tempfile::tempdir().unwrap();
+ let dir = crate::testing::tempdir().unwrap();
let config_path = dir.path().join("config.toml");
std::fs::write(&config_path, "# empty config\n").unwrap();
@@ -1967,7 +1967,7 @@ test = "npm test"
/// file contains invalid TOML.
#[test]
fn test_mutation_invalid_toml() {
- let dir = tempfile::tempdir().unwrap();
+ let dir = crate::testing::tempdir().unwrap();
let config_path = dir.path().join("config.toml");
// Create initial valid config so file exists
@@ -2172,7 +2172,7 @@ project-only = "only-project"
fn test_mutation_permission_error() {
use std::os::unix::fs::PermissionsExt;
- let dir = tempfile::tempdir().unwrap();
+ let dir = crate::testing::tempdir().unwrap();
let config_path = dir.path().join("config.toml");
// Create a valid config file
@@ -2844,7 +2844,7 @@ fn test_edit_takes_the_migrations_when_one_lands_on_its_path() {
// A deprecated `[commit-generation]` migrates to `[commit.generation]` only
// while that table is absent, so the command can't be written there as the
// file stands: the edit takes the load-time migrations with it, and says so.
- let dir = tempfile::tempdir().unwrap();
+ let dir = crate::testing::tempdir().unwrap();
let config_path = dir.path().join("config.toml");
std::fs::write(
&config_path,
@@ -2909,7 +2909,7 @@ fn test_edit_takes_the_migrations_when_one_lands_on_its_path() {
fn test_mutation_fails_on_a_file_that_is_not_a_valid_config_and_leaves_it() {
// Valid TOML that doesn't deserialize as a config (a hand edit like
// `commit = "oops"`) fails the reload, before anything is written.
- let dir = tempfile::tempdir().unwrap();
+ let dir = crate::testing::tempdir().unwrap();
let config_path = dir.path().join("config.toml");
let content = "commit = \"oops\"\n";
std::fs::write(&config_path, content).unwrap();
@@ -2934,7 +2934,7 @@ fn test_set_project_worktree_path_noop_when_unchanged() {
// mutator: when the path already matches, nothing is written. We verify
// this by checking that the file content is byte-identical across a
// redundant call.
- let dir = tempfile::tempdir().unwrap();
+ let dir = crate::testing::tempdir().unwrap();
let config_path = dir.path().join("config.toml");
std::fs::write(&config_path, "# keep\n").unwrap();
@@ -2968,7 +2968,7 @@ fn test_set_commit_generation_command_noop_when_unchanged() {
// mutator: when the command already matches, nothing is written. We verify
// this by checking that the file content is byte-identical across a
// redundant call.
- let dir = tempfile::tempdir().unwrap();
+ let dir = crate::testing::tempdir().unwrap();
let config_path = dir.path().join("config.toml");
std::fs::write(&config_path, "# keep\n").unwrap();
@@ -3002,7 +3002,7 @@ fn test_set_skip_shell_integration_prompt_noop_on_second_call() {
// mutator. The mutator runs on the file's config — after the first
// write, the flag is true on disk, so a second call sees it already true
// and writes nothing.
- let dir = tempfile::tempdir().unwrap();
+ let dir = crate::testing::tempdir().unwrap();
let config_path = dir.path().join("config.toml");
std::fs::write(&config_path, "# empty\n").unwrap();
@@ -3028,7 +3028,7 @@ fn test_mutation_keeps_in_memory_config_the_file_lacks() {
// and `--config-set`. A mutation applies its change to it without
// replacing it with the file's config, so the rest of the command still
// reads those values.
- let dir = tempfile::tempdir().unwrap();
+ let dir = crate::testing::tempdir().unwrap();
let config_path = dir.path().join("config.toml");
std::fs::write(&config_path, "[list]\nfull = true\n").unwrap();
@@ -3079,7 +3079,7 @@ fn test_acquire_config_lock_fails_when_parent_is_file() {
// Covers the create_dir_all error branch in acquire_config_lock:
// if the config path's parent is actually a regular file, we can't
// create the lock directory and the mutation fails fast.
- let dir = tempfile::tempdir().unwrap();
+ let dir = crate::testing::tempdir().unwrap();
let blocker = dir.path().join("blocker");
std::fs::write(&blocker, "i am a file").unwrap();
@@ -3104,7 +3104,7 @@ fn test_with_locked_mutation_propagates_write_error() {
// fails, and with_locked_mutation returns that error to the caller.
use std::os::unix::fs::PermissionsExt;
- let dir = tempfile::tempdir().unwrap();
+ let dir = crate::testing::tempdir().unwrap();
let config_dir = dir.path().join("config");
std::fs::create_dir(&config_dir).unwrap();
let config_path = config_dir.join("config.toml");
@@ -3150,7 +3150,7 @@ fn test_with_locked_mutation_propagates_write_error() {
/// documents face, whether or not writing them takes the migrations along.
#[test]
fn test_with_locked_mutation_refuses_an_edit_that_does_not_load_back() {
- let dir = tempfile::tempdir().unwrap();
+ let dir = crate::testing::tempdir().unwrap();
let config_path = dir.path().join("config.toml");
std::fs::write(&config_path, "# valid\n").unwrap();
diff --git a/src/copy.rs b/src/copy.rs
index 01d45a2f9..c455f7ff9 100644
--- a/src/copy.rs
+++ b/src/copy.rs
@@ -568,7 +568,7 @@ mod tests {
#[test]
fn test_remove_if_exists_reports_removal() {
- let dir = tempfile::tempdir().unwrap();
+ let dir = crate::testing::tempdir().unwrap();
let file = dir.path().join("file");
fs::write(&file, b"contents").unwrap();
@@ -588,7 +588,7 @@ mod tests {
// Simulates a source file that existed during the caller's directory
// walk but is gone by copy time (e.g. a concurrent build rewriting
// `target/`). Should be skipped, not treated as a fatal error.
- let dest_dir = tempfile::tempdir().unwrap();
+ let dest_dir = crate::testing::tempdir().unwrap();
let src = dest_dir.path().join("does-not-exist");
let dest = dest_dir.path().join("dest");
@@ -603,7 +603,7 @@ mod tests {
// Under `force` the skip must not cost the destination its contents:
// the source is stat'd before the destination is removed, so a source
// that is already gone leaves the existing destination in place.
- let dir = tempfile::tempdir().unwrap();
+ let dir = crate::testing::tempdir().unwrap();
let src = dir.path().join("does-not-exist");
let dest = dir.path().join("dest");
fs::write(&dest, b"pre-existing content").unwrap();
@@ -618,7 +618,7 @@ mod tests {
fn test_copy_leaf_skips_existing_destination() {
// The destination check moved ahead of the source stat; without
// `force` an existing destination still wins and keeps its contents.
- let dir = tempfile::tempdir().unwrap();
+ let dir = crate::testing::tempdir().unwrap();
let src = dir.path().join("src");
let dest = dir.path().join("dest");
fs::write(&src, b"source content").unwrap();
@@ -675,7 +675,7 @@ mod tests {
// `PermissionDenied`; a file another process puts there before the
// byte copy must survive, and the `AlreadyExists` it causes is what
// `copy_leaf` skips on.
- let temp = tempfile::tempdir().unwrap();
+ let temp = crate::testing::tempdir().unwrap();
let src = temp.path().join("src");
let dest = temp.path().join("dest");
fs::write(&src, "source").unwrap();
@@ -693,7 +693,7 @@ mod tests {
#[test]
fn test_copy_to_new_file_copies_contents_and_mode() {
- let temp = tempfile::tempdir().unwrap();
+ let temp = crate::testing::tempdir().unwrap();
let src = temp.path().join("script.sh");
let dest = temp.path().join("copy.sh");
fs::write(&src, "#!/bin/sh\n").unwrap();
@@ -728,7 +728,7 @@ mod tests {
{
let src_dir = temp.path().join("dir");
fs::create_dir(&src_dir).unwrap();
- let out = tempfile::tempdir().unwrap();
+ let out = crate::testing::tempdir().unwrap();
let dest = out.path().join("partial");
assert!(copy_to_new_file(&src_dir, &dest).is_err());
assert_eq!(fs::read_dir(out.path()).unwrap().count(), 0);
@@ -740,8 +740,8 @@ mod tests {
#[cfg(unix)]
#[test]
fn test_failed_copy_cleanup_leaves_racing_destination() {
- let temp = tempfile::tempdir().unwrap();
- let out = tempfile::tempdir().unwrap();
+ let temp = crate::testing::tempdir().unwrap();
+ let out = crate::testing::tempdir().unwrap();
let dest = out.path().join("dest");
fs::write(&dest, "racer").unwrap();
@@ -752,7 +752,7 @@ mod tests {
#[test]
fn test_discard_temp_reports_cleanup_failure() {
- let dir = tempfile::tempdir().unwrap();
+ let dir = crate::testing::tempdir().unwrap();
let temp = tempfile::NamedTempFile::new_in(dir.path()).unwrap();
let err = discard_temp(temp, io::Error::from(ErrorKind::AlreadyExists));
@@ -778,7 +778,7 @@ mod tests {
fn test_copy_leaf_force_replaces_existing_destination() {
// The counterpart: with `force` the destination is removed and the
// source copied over it, reporting the source's byte count.
- let dir = tempfile::tempdir().unwrap();
+ let dir = crate::testing::tempdir().unwrap();
let src = dir.path().join("src");
let dest = dir.path().join("dest");
fs::write(&src, b"source content").unwrap();
@@ -800,7 +800,7 @@ mod tests {
// The skipped count is what tells a caller that deletes the source
// whether the destination received everything. An idempotent re-run
// skips a leaf that is already there, and says so.
- let dir = tempfile::tempdir().unwrap();
+ let dir = crate::testing::tempdir().unwrap();
let src = dir.path().join("src");
let dest = dir.path().join("dest");
fs::create_dir_all(&src).unwrap();
@@ -822,7 +822,7 @@ mod tests {
// A socket is dropped at classification, not counted: the count exists
// so a caller that deletes the source can refuse, and a socket carries
// no content that refusal would protect.
- let dir = tempfile::tempdir().unwrap();
+ let dir = crate::testing::tempdir().unwrap();
let src = dir.path().join("src");
let dest = dir.path().join("dest");
fs::create_dir_all(&src).unwrap();
@@ -844,7 +844,7 @@ mod tests {
fn test_copy_dir_recursive_reports_no_skips_for_a_complete_copy() {
// The control: a clean copy reports zero, which is what lets a move
// treat any non-zero count as a reason to keep the source.
- let dir = tempfile::tempdir().unwrap();
+ let dir = crate::testing::tempdir().unwrap();
let src = dir.path().join("src");
let dest = dir.path().join("dest");
fs::create_dir_all(src.join("nested")).unwrap();
@@ -865,7 +865,7 @@ mod tests {
// another for its short root — so the copy was refused as "outside" a
// worktree it was inside (#3898). Off Windows the depth is unremarkable
// and this just exercises a deep tree.
- let dir = tempfile::tempdir().unwrap();
+ let dir = crate::testing::tempdir().unwrap();
let src_root = dir.path().join("src");
let dest_root = dir.path().join("dest");
@@ -901,7 +901,7 @@ mod tests {
// A read-only source copies to a read-only destination; setting its
// time must not need write access to it.
use std::os::unix::fs::PermissionsExt;
- let dir = tempfile::tempdir().unwrap();
+ let dir = crate::testing::tempdir().unwrap();
let src = dir.path().join("src");
let dest = dir.path().join("dest");
fs::write(&src, b"content").unwrap();
@@ -926,7 +926,7 @@ mod tests {
// A subdirectory that vanishes mid-walk is skipped, but the root the
// caller named is not — its absence is a real error, and nothing is
// created at the destination.
- let dir = tempfile::tempdir().unwrap();
+ let dir = crate::testing::tempdir().unwrap();
let src = dir.path().join("does-not-exist");
let dest = dir.path().join("dest");
diff --git a/src/diagnostic.rs b/src/diagnostic.rs
index 95a135b24..e1b964e6c 100644
--- a/src/diagnostic.rs
+++ b/src/diagnostic.rs
@@ -525,7 +525,6 @@ fn format_config_section(path: &std::path::Path, kind: ConfigFileKind) -> String
#[cfg(test)]
mod tests {
use super::*;
- use tempfile::TempDir;
#[test]
fn test_format_config_section_file_not_found() {
@@ -541,7 +540,7 @@ mod tests {
#[test]
fn test_format_config_section_empty_file() {
- let tmp = TempDir::new().unwrap();
+ let tmp = worktrunk::testing::tempdir().unwrap();
let path = tmp.path().join("empty.toml");
std::fs::write(&path, "").unwrap();
@@ -551,7 +550,7 @@ mod tests {
#[test]
fn test_format_config_section_with_content() {
- let tmp = TempDir::new().unwrap();
+ let tmp = worktrunk::testing::tempdir().unwrap();
let path = tmp.path().join("config.toml");
std::fs::write(&path, "key = \"value\"\n").unwrap();
@@ -561,7 +560,7 @@ mod tests {
#[test]
fn test_format_config_section_adds_trailing_newline() {
- let tmp = TempDir::new().unwrap();
+ let tmp = worktrunk::testing::tempdir().unwrap();
let path = tmp.path().join("config.toml");
std::fs::write(&path, "no-newline").unwrap();
@@ -571,7 +570,7 @@ mod tests {
#[test]
fn test_format_config_section_truncates_long_content() {
- let tmp = TempDir::new().unwrap();
+ let tmp = worktrunk::testing::tempdir().unwrap();
let path = tmp.path().join("big.toml");
let content = "x".repeat(5000);
std::fs::write(&path, &content).unwrap();
@@ -586,7 +585,7 @@ mod tests {
// A multi-byte char straddling the 4000-byte cut must not panic the
// slice. "🦀" is 4 bytes; padding 3998 ASCII bytes puts a crab boundary
// at 3998/4002/4006/... so byte 4000 lands mid-character.
- let tmp = TempDir::new().unwrap();
+ let tmp = worktrunk::testing::tempdir().unwrap();
let path = tmp.path().join("emoji.toml");
let content = format!("{}{}", "x".repeat(3998), "🦀".repeat(100));
std::fs::write(&path, &content).unwrap();
diff --git a/src/git/fsmonitor.rs b/src/git/fsmonitor.rs
index 27180fcd6..61ffc69a6 100644
--- a/src/git/fsmonitor.rs
+++ b/src/git/fsmonitor.rs
@@ -632,7 +632,7 @@ mod tests {
#[cfg(unix)]
#[test]
fn canonicalize_socket_resolves_symlinked_git_dir_and_falls_back_when_gone() {
- let tmp = tempfile::tempdir().unwrap();
+ let tmp = crate::testing::tempdir().unwrap();
let real = tmp.path().join("real-gitdir");
std::fs::create_dir(&real).unwrap();
let link = tmp.path().join("link-gitdir");
@@ -904,7 +904,7 @@ mod tests {
// makes sh a group leader (the `sleep` inherits its group) so the
// orphaned grandchild can be reaped after sh is killed — see the group
// SIGKILL below.
- let tmp = tempfile::tempdir().unwrap();
+ let tmp = crate::testing::tempdir().unwrap();
let ready = tmp.path().join("ready");
let mut child = Command::new("sh")
.arg("-c")
diff --git a/src/git/mod.rs b/src/git/mod.rs
index 9e731812f..f7b4bc479 100644
--- a/src/git/mod.rs
+++ b/src/git/mod.rs
@@ -1236,7 +1236,7 @@ mod tests {
#[test]
fn branch_ref_preserves_git_item_identity() {
- let root = tempfile::tempdir().unwrap();
+ let root = crate::testing::tempdir().unwrap();
let first_path = root.path().join("first");
let second_path = root.path().join("second");
std::fs::create_dir_all(&first_path).unwrap();
diff --git a/src/git/reap.rs b/src/git/reap.rs
index 2c9c69f5b..5e23b2468 100644
--- a/src/git/reap.rs
+++ b/src/git/reap.rs
@@ -290,7 +290,7 @@ mod tests {
#[cfg(target_os = "linux")]
#[test]
fn missing_procfs_yields_no_processes() {
- let root = tempfile::tempdir().unwrap();
+ let root = crate::testing::tempdir().unwrap();
assert!(processes_from_proc(&root.path().join("absent")).is_empty());
}
diff --git a/src/git/remove.rs b/src/git/remove.rs
index bcf3066d8..b454c75c9 100644
--- a/src/git/remove.rs
+++ b/src/git/remove.rs
@@ -894,7 +894,7 @@ mod tests {
/// drain that finds another holding the lock leaves the entries to it.
#[test]
fn drain_trash_deletes_staged_entries_once_the_lock_is_free() {
- let temp = tempfile::tempdir().unwrap();
+ let temp = crate::testing::tempdir().unwrap();
let trash = temp.path().join("trash");
let staged = trash.join("repo.feature-branch-1700000000");
let foreign = trash.join("not-staged");
@@ -929,7 +929,7 @@ mod tests {
fn drain_trash_stops_at_an_undeletable_entry() {
use std::os::unix::fs::PermissionsExt;
- let temp = tempfile::tempdir().unwrap();
+ let temp = crate::testing::tempdir().unwrap();
let trash = temp.path().join("trash");
fs::create_dir(&trash).unwrap();
fs::write(trash.join("stuck-1700000000"), "x").unwrap();
@@ -1495,7 +1495,7 @@ mod tests {
fn test_fsmonitor_socket_resolves_to_linked_worktree_git_dir() {
use crate::git::Repository;
- let tmp = tempfile::tempdir().unwrap();
+ let tmp = crate::testing::tempdir().unwrap();
let git = |dir: &Path| crate::testing::configure_git_env(Cmd::new("git")).current_dir(dir);
let main = tmp.path().join("repo");
@@ -1545,7 +1545,7 @@ mod tests {
fn test_fsmonitor_stop_unresolvable_git_dir_is_noop() {
use crate::git::Repository;
- let tmp = tempfile::tempdir().unwrap();
+ let tmp = crate::testing::tempdir().unwrap();
let main = tmp.path().join("repo");
std::fs::create_dir(&main).unwrap();
crate::testing::configure_git_env(Cmd::new("git"))
@@ -1574,7 +1574,7 @@ mod tests {
fn test_fsmonitor_force_kill_unheld_socket_is_noop() {
use crate::git::Repository;
- let tmp = tempfile::tempdir().unwrap();
+ let tmp = crate::testing::tempdir().unwrap();
let main = tmp.path().join("repo");
std::fs::create_dir(&main).unwrap();
crate::testing::configure_git_env(Cmd::new("git"))
diff --git a/src/git/repository/tests.rs b/src/git/repository/tests.rs
index c0d310723..453cad858 100644
--- a/src/git/repository/tests.rs
+++ b/src/git/repository/tests.rs
@@ -425,7 +425,7 @@ fn repo_path_ignores_non_local_core_worktree() {
// with a stray global `core.worktree` in a normal repo should still see
// `parent(.git)` as the repo root — `rev-parse --show-toplevel` fails
// from inside `.git` in that case and we fall through.
- let tmp = tempfile::tempdir().unwrap();
+ let tmp = crate::testing::tempdir().unwrap();
let git_dir = tmp.path().join(".git");
std::fs::create_dir(&git_dir).unwrap();
@@ -1156,7 +1156,7 @@ fn build_worktree_config_bare_layout() -> (tempfile::TempDir, std::path::PathBuf
use super::canonicalize;
use crate::shell_exec::Cmd;
- let tmp = tempfile::tempdir().unwrap();
+ let tmp = crate::testing::tempdir().unwrap();
let project_root = canonicalize(tmp.path()).unwrap().join("myproject");
std::fs::create_dir_all(&project_root).unwrap();
let git_dir = project_root.join(".git");
@@ -1305,7 +1305,7 @@ fn prewarm_partial_warm_runs_only_the_cold_threads() {
use super::canonicalize;
use crate::shell_exec::Cmd;
- let tmp = tempfile::tempdir().unwrap();
+ let tmp = crate::testing::tempdir().unwrap();
let init_repo = |name: &str| {
let root = canonicalize(tmp.path()).unwrap().join(name);
std::fs::create_dir_all(&root).unwrap();
@@ -1439,7 +1439,7 @@ fn prewarm_still_caches_preload_when_worktree_config_disabled() {
use super::canonicalize;
use crate::shell_exec::Cmd;
- let tmp = tempfile::tempdir().unwrap();
+ let tmp = crate::testing::tempdir().unwrap();
let root = canonicalize(tmp.path()).unwrap().join("normal");
std::fs::create_dir_all(&root).unwrap();
@@ -1469,7 +1469,7 @@ fn prewarm_after_early_repository_still_preloads_config() {
use super::canonicalize;
use crate::shell_exec::Cmd;
- let tmp = tempfile::tempdir().unwrap();
+ let tmp = crate::testing::tempdir().unwrap();
let root = canonicalize(tmp.path()).unwrap().join("early");
std::fs::create_dir_all(&root).unwrap();
@@ -2091,7 +2091,7 @@ fn test_worktree_for_branch_dedups_duplicate_warning() {
use crate::shell_exec::Cmd;
use std::path::Path;
- let tmp = tempfile::tempdir().unwrap();
+ let tmp = crate::testing::tempdir().unwrap();
let root = canonicalize(tmp.path()).unwrap().join("repo");
std::fs::create_dir_all(&root).unwrap();
let git = |args: &[&str], dir: &Path| {
@@ -2655,7 +2655,7 @@ fn build_separate_git_dir_layout_with(
use super::canonicalize;
use crate::shell_exec::Cmd;
- let tmp = tempfile::tempdir().unwrap();
+ let tmp = crate::testing::tempdir().unwrap();
let root = canonicalize(tmp.path()).unwrap();
let store = root.join("store").join("repo.gitdir");
let work_tree = root.join("work");
diff --git a/src/git/repository/working_tree.rs b/src/git/repository/working_tree.rs
index 28cf63690..868f5c16d 100644
--- a/src/git/repository/working_tree.rs
+++ b/src/git/repository/working_tree.rs
@@ -1861,7 +1861,7 @@ mod tests {
// graceful degradation (bare-repo aliases, deleted-CWD recovery), but
// that fallback must never be cached — otherwise `prewarm_info`'s
// short-circuit would misreport `is_inside: true` on the next call.
- let tmp = tempfile::tempdir().unwrap();
+ let tmp = crate::testing::tempdir().unwrap();
let test = TestRepo::with_initial_commit();
let repo = Repository::at(test.root_path()).unwrap();
let wt = repo.worktree_at(tmp.path());
diff --git a/src/help_pager.rs b/src/help_pager.rs
index 42302a9e3..51d68a1a0 100644
--- a/src/help_pager.rs
+++ b/src/help_pager.rs
@@ -196,7 +196,7 @@ mod tests {
#[test]
fn pager_that_cannot_execute_triggers_fallback() {
assert!(!super::pipe_through_pager("worktrunk-test-missing-pager", "help text").unwrap());
- let script = tempfile::NamedTempFile::new().unwrap();
+ let script = worktrunk::testing::named_tempfile().unwrap();
std::fs::write(script.path(), "#!/bin/sh\n").unwrap();
// NamedTempFile is not executable: the shell returns reserved status 126.
let command = shell_escape::unix::escape(script.path().to_string_lossy());
diff --git a/src/output/commit_generation.rs b/src/output/commit_generation.rs
index 171fab609..10132b714 100644
--- a/src/output/commit_generation.rs
+++ b/src/output/commit_generation.rs
@@ -342,7 +342,7 @@ mod tests {
#[test]
fn test_codex_instructions_file_is_minimal_and_preserves_existing_content() {
- let tmp = tempfile::tempdir().unwrap();
+ let tmp = worktrunk::testing::tempdir().unwrap();
let path = tmp.path().join(".codex/worktrunk-commit-instructions.txt");
assert!(ensure_codex_instructions_file(&path).unwrap());
@@ -435,7 +435,7 @@ mod tests {
fn test_command_exists_in_finds_binary_on_explicit_path() {
// Provide our own search path so the positive case doesn't depend
// on which standard tools the inherited PATH happens to ship.
- let tmp = tempfile::tempdir().unwrap();
+ let tmp = worktrunk::testing::tempdir().unwrap();
#[cfg(windows)]
let bin_name = "wt-fake-bin.exe";
#[cfg(not(windows))]
@@ -459,7 +459,7 @@ mod tests {
#[test]
fn test_command_exists_in_returns_false_when_paths_empty() {
- let tmp = tempfile::tempdir().unwrap();
+ let tmp = worktrunk::testing::tempdir().unwrap();
assert!(!command_exists_in(
"__nonexistent__",
Some(tmp.path().as_os_str()),
diff --git a/src/output/concurrent.rs b/src/output/concurrent.rs
index 0d96b4493..f7f3e6548 100644
--- a/src/output/concurrent.rs
+++ b/src/output/concurrent.rs
@@ -660,7 +660,7 @@ mod tests {
("exit 7", "exit code 7", 7),
("kill -9 $$", "killed by signal 9", 137),
] {
- let cwd = tempfile::tempdir().unwrap();
+ let cwd = worktrunk::testing::tempdir().unwrap();
let directives = DirectivePassthrough::default();
let mut outcomes = run_concurrent_commands(&[ConcurrentCommand {
label: "check",
@@ -679,7 +679,7 @@ mod tests {
#[test]
fn test_concurrent_spawn_failure_retains_member_outcomes_and_io_source() {
- let cwd = tempfile::tempdir().unwrap();
+ let cwd = worktrunk::testing::tempdir().unwrap();
let missing = cwd.path().join("missing");
let directives = DirectivePassthrough::default();
let specs =
diff --git a/src/output/handlers.rs b/src/output/handlers.rs
index fde0b9814..d54060052 100644
--- a/src/output/handlers.rs
+++ b/src/output/handlers.rs
@@ -2676,7 +2676,7 @@ mod tests {
#[test]
fn test_resolve_subdir_in_target_subdir_exists() {
- let dir = tempfile::tempdir().unwrap();
+ let dir = worktrunk::testing::tempdir().unwrap();
let source = dir.path().join("source");
let target = dir.path().join("target");
std::fs::create_dir_all(source.join("apps/gateway")).unwrap();
@@ -2694,7 +2694,7 @@ mod tests {
// so `strip_prefix` fails and the shell lands at the target root with no
// error rather than at the mirrored subdirectory (#3898). Off Windows
// the depth is unremarkable and this just exercises a deep tree.
- let dir = tempfile::tempdir().unwrap();
+ let dir = worktrunk::testing::tempdir().unwrap();
let source = dir.path().join("source");
let target = dir.path().join("target");
@@ -2711,7 +2711,7 @@ mod tests {
#[test]
fn test_resolve_subdir_in_target_subdir_missing() {
- let dir = tempfile::tempdir().unwrap();
+ let dir = worktrunk::testing::tempdir().unwrap();
let source = dir.path().join("source");
let target = dir.path().join("target");
std::fs::create_dir_all(source.join("apps/gateway")).unwrap();
@@ -2724,7 +2724,7 @@ mod tests {
#[test]
fn test_resolve_subdir_in_target_at_root() {
- let dir = tempfile::tempdir().unwrap();
+ let dir = worktrunk::testing::tempdir().unwrap();
let source = dir.path().join("source");
let target = dir.path().join("target");
std::fs::create_dir_all(&source).unwrap();
diff --git a/src/path.rs b/src/path.rs
index 49651d949..e2d66b01e 100644
--- a/src/path.rs
+++ b/src/path.rs
@@ -663,7 +663,7 @@ mod tests {
#[test]
#[cfg(windows)]
fn canonicalize_with_parents_agrees_across_the_verbatim_threshold() {
- let tmp = tempfile::tempdir().expect("temp dir");
+ let tmp = crate::testing::tempdir().expect("temp dir");
let root = tmp.path();
// 260 characters is `dunce`'s cutoff for stripping the prefix; overshoot
diff --git a/src/remove_dir.rs b/src/remove_dir.rs
index 30373775d..163880d9f 100644
--- a/src/remove_dir.rs
+++ b/src/remove_dir.rs
@@ -252,7 +252,7 @@ mod tests {
#[test]
fn test_remove_dir_with_progress_empty_dir() {
- let temp = tempfile::tempdir().unwrap();
+ let temp = crate::testing::tempdir().unwrap();
let dir = temp.path().join("empty");
std::fs::create_dir(&dir).unwrap();
@@ -265,7 +265,7 @@ mod tests {
#[test]
fn test_remove_dir_with_progress_counts_files_and_bytes() {
- let temp = tempfile::tempdir().unwrap();
+ let temp = crate::testing::tempdir().unwrap();
let root = temp.path().join("tree");
std::fs::create_dir_all(root.join("a/b")).unwrap();
std::fs::write(root.join("a/file1.txt"), b"hello").unwrap(); // 5 bytes
@@ -281,7 +281,7 @@ mod tests {
#[test]
fn test_remove_dir_with_progress_missing_root_is_ok() {
- let temp = tempfile::tempdir().unwrap();
+ let temp = crate::testing::tempdir().unwrap();
let missing = temp.path().join("does-not-exist");
let progress = Progress::disabled();
@@ -292,7 +292,7 @@ mod tests {
#[test]
fn test_remove_dir_with_progress_refuses_paths_without_a_name() {
- let temp = tempfile::tempdir().unwrap();
+ let temp = crate::testing::tempdir().unwrap();
let kept = temp.path().join("kept");
std::fs::create_dir_all(kept.join("child")).unwrap();
std::fs::write(kept.join("file.txt"), b"x").unwrap();
@@ -307,7 +307,7 @@ mod tests {
#[cfg(unix)]
#[test]
fn test_remove_dir_with_progress_handles_symlinks() {
- let temp = tempfile::tempdir().unwrap();
+ let temp = crate::testing::tempdir().unwrap();
let root = temp.path().join("tree");
std::fs::create_dir(&root).unwrap();
std::fs::write(root.join("real.txt"), b"abc").unwrap();
@@ -328,7 +328,7 @@ mod tests {
#[cfg(unix)]
#[test]
fn test_remove_dir_with_progress_keeps_directory_symlink_targets() {
- let temp = tempfile::tempdir().unwrap();
+ let temp = crate::testing::tempdir().unwrap();
let outside = temp.path().join("outside");
std::fs::create_dir(&outside).unwrap();
std::fs::write(outside.join("keep.txt"), b"abc").unwrap();
@@ -348,7 +348,7 @@ mod tests {
#[cfg(unix)]
#[test]
fn test_remove_dir_with_progress_unlinks_symlink_root() {
- let temp = tempfile::tempdir().unwrap();
+ let temp = crate::testing::tempdir().unwrap();
let target = temp.path().join("target");
std::fs::create_dir(&target).unwrap();
std::fs::write(target.join("keep.txt"), b"abc").unwrap();
@@ -370,7 +370,7 @@ mod tests {
fn test_remove_dir_with_progress_removes_read_only_directories() {
use std::os::unix::fs::PermissionsExt;
- let temp = tempfile::tempdir().unwrap();
+ let temp = crate::testing::tempdir().unwrap();
let root = temp.path().join("tree");
let read_only = root.join("read-only");
std::fs::create_dir_all(read_only.join("nested")).unwrap();
@@ -395,7 +395,7 @@ mod tests {
fn test_remove_dir_with_progress_removes_unreadable_directories() {
use std::os::unix::fs::PermissionsExt;
- let temp = tempfile::tempdir().unwrap();
+ let temp = crate::testing::tempdir().unwrap();
let root = temp.path().join("tree");
let unreadable = root.join("unreadable");
std::fs::create_dir_all(&unreadable).unwrap();
diff --git a/src/shell/detection.rs b/src/shell/detection.rs
index 5400969dd..bdd490296 100644
--- a/src/shell/detection.rs
+++ b/src/shell/detection.rs
@@ -528,7 +528,7 @@ mod tests {
fn test_scan_file_skips_non_utf8_line_before_integration() {
use std::io::Write;
- let dir = tempfile::tempdir().unwrap();
+ let dir = crate::testing::tempdir().unwrap();
let path = dir.path().join(".bashrc");
let mut file = fs::File::create(&path).unwrap();
// 0xE9 is `é` in Latin-1 — an invalid UTF-8 byte on its own.
diff --git a/src/shell_exec.rs b/src/shell_exec.rs
index fb537ba6b..41c00ecf1 100644
--- a/src/shell_exec.rs
+++ b/src/shell_exec.rs
@@ -3155,7 +3155,7 @@ print(*counts)
#[test]
fn test_git_bash_from_exec_path() {
- let dir = tempfile::tempdir().unwrap();
+ let dir = crate::testing::tempdir().unwrap();
let root = dir.path().join("Git");
let bin_bash = root.join("bin/bash.exe");
let usr_bash = root.join("usr/bin/bash.exe");
@@ -3246,7 +3246,7 @@ print(*counts)
fn test_sensitive_captured_output() {
const SECRET: &str = "fake-captured-token-4b8ad2";
for mode in ["run", "timeout", "concurrent", "source", "sink"] {
- let log = tempfile::NamedTempFile::new().unwrap();
+ let log = crate::testing::named_tempfile().unwrap();
let subscriber = tracing_subscriber::fmt()
.without_time()
.with_ansi(false)
@@ -3567,7 +3567,7 @@ print(*counts)
fn test_spawn_errors_identify_program_and_cwd_without_guessing_cause() {
use crate::git::ErrorExt;
use std::os::unix::fs::PermissionsExt;
- let dir = tempfile::tempdir().unwrap();
+ let dir = crate::testing::tempdir().unwrap();
let script = dir.path().join("broken-interpreter");
std::fs::write(&script, "#!/no/such/interpreter-7f3a9b2c\n").unwrap();
std::fs::set_permissions(&script, std::fs::Permissions::from_mode(0o755)).unwrap();
@@ -3641,7 +3641,7 @@ print(*counts)
#[test]
#[cfg(all(feature = "cli", unix))]
fn test_spawn_trace_retains_io_cause_once_in_every_execution_mode() {
- let log = tempfile::NamedTempFile::new().unwrap();
+ let log = crate::testing::named_tempfile().unwrap();
let subscriber = tracing_subscriber::fmt()
.without_time()
.with_ansi(false)
@@ -3715,7 +3715,7 @@ print(*counts)
#[test]
fn test_cmd_run_directory_program_path_is_errored() {
- let dir = tempfile::tempdir().unwrap();
+ let dir = crate::testing::tempdir().unwrap();
let err = Cmd::new(dir.path().to_string_lossy()).run().unwrap_err();
assert_eq!(err.kind(), ErrorKind::PermissionDenied);
}
@@ -3725,7 +3725,7 @@ print(*counts)
fn test_cmd_run_non_executable_program_path_is_errored() {
use std::os::unix::fs::PermissionsExt;
- let file = tempfile::NamedTempFile::new().unwrap();
+ let file = crate::testing::named_tempfile().unwrap();
std::fs::set_permissions(file.path(), std::fs::Permissions::from_mode(0o644)).unwrap();
let err = Cmd::new(file.path().to_string_lossy()).run().unwrap_err();
@@ -3887,7 +3887,7 @@ print(*counts)
// The first child waits for a file that only the last child creates, so
// it succeeds only if both run at once. A spawn failure in between
// stays in its own slot rather than shifting the results after it.
- let dir = tempfile::tempdir().unwrap();
+ let dir = crate::testing::tempdir().unwrap();
let flag = dir.path().join("flag");
let wait_for_flag = format!(
"for _ in $(seq 500); do [ -e '{}' ] && exit 0; sleep 0.01; done; exit 1",
diff --git a/src/signal_forwarder.rs b/src/signal_forwarder.rs
index 625c584c4..387ab8473 100644
--- a/src/signal_forwarder.rs
+++ b/src/signal_forwarder.rs
@@ -618,7 +618,7 @@ mod tests {
.unwrap();
let operation = CommandOperation::start().unwrap();
let foreground = ForegroundSignals::install(TerminalInterrupt::ChildInput).unwrap();
- let temp = tempfile::tempdir().unwrap();
+ let temp = crate::testing::tempdir().unwrap();
let marker = temp.path().join("ready");
let mut command = std::process::Command::new("sh");
command
@@ -741,7 +741,7 @@ mod tests {
thread::yield_now();
}
- let temp = tempfile::tempdir().unwrap();
+ let temp = crate::testing::tempdir().unwrap();
let marker = temp.path().join("late-child");
let child_marker = marker.clone();
let (starting, started) = mpsc::channel();
@@ -852,7 +852,7 @@ mod tests {
return;
}
- let temp = tempfile::tempdir().unwrap();
+ let temp = crate::testing::tempdir().unwrap();
let marker = temp.path().join("late-command-ran");
let operation = CommandOperation::start().unwrap();
let error = Cmd::new("python3")
diff --git a/src/testing/mock_stub.rs b/src/testing/mock_stub.rs
index 0c10cab50..498fb1197 100644
--- a/src/testing/mock_stub.rs
+++ b/src/testing/mock_stub.rs
@@ -295,7 +295,7 @@ mod tests {
let view = ["pr", "view", "42", "--json", "comments"];
let list = ["pr", "list", "--head", "flaky"];
- let dir = tempfile::tempdir().unwrap();
+ let dir = crate::testing::tempdir().unwrap();
let path = dir.path().join("gh.calls");
std::thread::scope(|scope| {
for writer in 0..WRITERS {
diff --git a/src/testing/mod.rs b/src/testing/mod.rs
index da180096e..38059422e 100644
--- a/src/testing/mod.rs
+++ b/src/testing/mod.rs
@@ -235,13 +235,15 @@ fn standard_main_only_fixture_template() -> PathBuf {
/// Build into a private scratch directory under `parent`, then rename it to
/// `dir` — the atomic claim that makes concurrent cold-cache builders race
-/// benignly. `TempDir::new_in` names the scratch uniquely per call, so
-/// builders can't collide on it whether they're separate nextest processes
-/// or threads of one `cargo test` process; the first rename into place wins
+/// benignly. The scratch name comes from a generator seeded per process (see
+/// [`tempdir`]), so builders can't collide on it whether they're separate
+/// nextest processes or threads of one `cargo test` process; the first rename into place wins
/// and losers discard their build.
fn claim_template(parent: &Path, dir: &Path, build: impl FnOnce(&Path)) {
std::fs::create_dir_all(parent).unwrap();
- let scratch = TempDir::new_in(parent).expect("create template build dir");
+ let scratch = temp_builder()
+ .tempdir_in(parent)
+ .expect("create template build dir");
build(scratch.path());
// Disarm auto-cleanup: from here the scratch either becomes `dir` or is
@@ -850,7 +852,52 @@ pub fn test_temp_root() -> &'static Path {
///
/// The fixtures' replacement for `TempDir::new()` / `tempfile::tempdir()`.
pub fn test_tempdir() -> TempDir {
- TempDir::new_in(test_temp_root()).expect("create test temp dir")
+ temp_builder()
+ .tempdir_in(test_temp_root())
+ .expect("create test temp dir")
+}
+
+/// The suite's replacement for `tempfile::tempdir()` / `TempDir::new()`.
+///
+/// `tempfile` draws names from `fastrand`'s thread-local generator, which
+/// seeds from the time and the thread id alone (smol-rs/fastrand#130). Nextest
+/// runs every test in its own process, so processes that seed in the same
+/// clock tick generate the same names; on Windows CI ~0.3% of the names a
+/// burst of short-lived processes generated were duplicates. A duplicate of a
+/// live entry is retried, but one held by an entry another process just
+/// deleted fails with `PermissionDenied` (os error 5), which `tempfile` hands
+/// back instead of retrying (#4692). The builder behind it reseeds the generator
+/// first, so names differ across processes without changing their length.
+pub fn tempdir() -> std::io::Result<TempDir> {
+ temp_builder().tempdir()
+}
+
+/// [`tempdir`]'s counterpart for `NamedTempFile::new()`.
+pub fn named_tempfile() -> std::io::Result<tempfile::NamedTempFile> {
+ temp_builder().tempfile()
+}
+
+/// A `tempfile::Builder` whose names come from a generator seeded per process.
+///
+/// `RandomState::new()` draws its keys from OS randomness once per thread, so
+/// the seed differs between processes even when the clock doesn't. Seeding
+/// once per thread keeps names distinct within the thread, and `tempfile`
+/// forks the same thread-local generator. The name length stays tempfile's
+/// own: Unix-socket tests have only a few bytes to spare under `sun_path`.
+fn temp_builder() -> tempfile::Builder<'static, 'static> {
+ use std::hash::BuildHasher;
+ thread_local! {
+ static SEEDED: std::cell::Cell<bool> = const { std::cell::Cell::new(false) };
+ }
+ SEEDED.with(|seeded| {
+ if !seeded.replace(true) {
+ fastrand::seed(
+ std::collections::hash_map::RandomState::new()
+ .hash_one(std::thread::current().id()),
+ );
+ }
+ });
+ tempfile::Builder::new()
}
/// A single fixed empty directory used as the default `current_dir` for
@@ -1136,19 +1183,11 @@ pub fn directive_file() -> (PathBuf, TempDir) {
/// A private directory for a test's directive files.
///
-/// Why not `NamedTempFile::new()` (which is what these helpers used to call):
-/// `tempfile` retries a name collision only when it surfaces as
-/// `AlreadyExists`, and on Windows `create_new` against a name already held by
-/// a *directory* — or by a file in delete-pending state — returns
-/// `PermissionDenied` instead, which it hands straight back. A full
-/// suite run leaves the shared temp directory full of `.tmpXXXXXX` entries
-/// (every `TestRepo` creates one), and under that load the call failed ~1% of
-/// the time on Windows CI: `failed to create cd temp file: … Os { code: 5 …
-/// "Access is denied." }`. `TempDir::new` isn't exposed to it — a directory
-/// collision surfaces as `AlreadyExists`, which `tempfile` retries — and the
-/// files inside carry fixed names, which nothing else can collide with.
+/// The files inside carry fixed names, which nothing outside the directory
+/// can collide with; the directory itself comes from [`tempdir`], whose
+/// per-process seed is what keeps it clear of other test processes.
fn directive_temp_dir() -> TempDir {
- TempDir::new().expect("failed to create directive temp dir")
+ tempdir().expect("failed to create directive temp dir")
}
/// Create `path` as an empty file and return it.
@@ -3706,7 +3745,7 @@ mod tests {
/// produce — keeps the winner's template and removes its own scratch.
#[test]
fn test_claim_template_winner_and_loser() {
- let parent = TempDir::new().unwrap();
+ let parent = tempdir().unwrap();
let dir = parent.path().join("template-v1");
claim_template(parent.path(), &dir, |scratch| {
diff --git a/src/utils.rs b/src/utils.rs
index 44b9c0af8..cd638b46b 100644
--- a/src/utils.rs
+++ b/src/utils.rs
@@ -283,7 +283,7 @@ mod tests {
fn prepare_log_file_does_not_chmod_symlinked_directory() {
use std::os::unix::fs::{PermissionsExt, symlink};
- let dir = tempfile::tempdir().unwrap();
+ let dir = crate::testing::tempdir().unwrap();
let outside = dir.path().join("outside");
std::fs::create_dir(&outside).unwrap();
std::fs::set_permissions(&outside, std::fs::Permissions::from_mode(0o755)).unwrap();
@@ -309,7 +309,7 @@ mod tests {
#[test]
fn test_write_atomically_creates_then_replaces() {
- let dir = tempfile::tempdir().unwrap();
+ let dir = crate::testing::tempdir().unwrap();
let path = dir.path().join("config.toml");
write_atomically(&path, "first\n").unwrap();
@@ -324,7 +324,7 @@ mod tests {
#[test]
fn test_write_new_atomically_creates_but_never_replaces() {
- let dir = tempfile::tempdir().unwrap();
+ let dir = crate::testing::tempdir().unwrap();
let path = dir.path().join("config.toml");
write_new_atomically(&path, "first\n").unwrap();
@@ -345,7 +345,7 @@ mod tests {
fn test_write_atomically_creates_owner_only() {
use std::os::unix::fs::PermissionsExt;
- let dir = tempfile::tempdir().unwrap();
+ let dir = crate::testing::tempdir().unwrap();
let path = dir.path().join("new.toml");
write_atomically(&path, "x\n").unwrap();
diff --git a/tests/cancel_background.rs b/tests/cancel_background.rs
index c79263c29..c7c5f600a 100644
--- a/tests/cancel_background.rs
+++ b/tests/cancel_background.rs
@@ -30,7 +30,7 @@ use worktrunk::shell_exec::{Cmd, cancel_background_commands, uninterruptible};
/// test harness, every other thread counts as background.
#[test]
fn cancel_stops_speculative_commands_and_spares_uninterruptible_ones() {
- let dir = tempfile::tempdir().unwrap();
+ let dir = worktrunk::testing::tempdir().unwrap();
let started = dir.path().join("started");
let marker = started.display().to_string();
diff --git a/tests/helpers/wt-perf/src/lib.rs b/tests/helpers/wt-perf/src/lib.rs
index 62cf22fc6..e88f072ce 100644
--- a/tests/helpers/wt-perf/src/lib.rs
+++ b/tests/helpers/wt-perf/src/lib.rs
@@ -58,7 +58,7 @@ pub struct FixtureRepo {
impl FixtureRepo {
/// Create a fixture with its primary worktree at `<temp>/repo`.
fn create(build: impl FnOnce(&Path)) -> Self {
- let root = tempfile::tempdir().unwrap();
+ let root = worktrunk::testing::tempdir().unwrap();
let repo = root.path().join("repo");
build(&repo);
Self { root, repo }
@@ -1014,7 +1014,7 @@ fn history_spread_shas(repo_path: &Path, count: usize) -> Vec<String> {
/// minutes per branch. Each commit adds one new file, so the branch's tree
/// genuinely diverges and the integration probes can't short-circuit.
fn add_branch_with_commits(repo_path: &Path, branch: &str, fork: &str, commits: usize) {
- let scratch = tempfile::tempdir().unwrap();
+ let scratch = worktrunk::testing::tempdir().unwrap();
let index = scratch.path().join("index");
let mut tip = fork.to_string();
for j in 0..commits {
@@ -1476,7 +1476,7 @@ mod tests {
#[test]
fn fixture_lock_excludes_an_independent_handle() {
- let temp = tempfile::tempdir().unwrap();
+ let temp = worktrunk::testing::tempdir().unwrap();
let path = temp.path().join("fixture.lock");
let first = acquire_exclusive_lock(&path);
let second = OpenOptions::new().write(true).open(&path).unwrap();
@@ -1492,7 +1492,7 @@ mod tests {
#[test]
fn imported_source_rejects_a_missing_pinned_commit_object() {
- let temp = tempfile::tempdir().unwrap();
+ let temp = worktrunk::testing::tempdir().unwrap();
init_bench_repo(temp.path());
std::fs::write(
temp.path().join(".git/refs/heads/main"),
diff --git a/tests/helpers/wt-perf/tests/cli.rs b/tests/helpers/wt-perf/tests/cli.rs
index a74afe903..c26e824da 100644
--- a/tests/helpers/wt-perf/tests/cli.rs
+++ b/tests/helpers/wt-perf/tests/cli.rs
@@ -81,7 +81,7 @@ fn setup_validation_does_not_acquire_imported_fixture() {
String::from_utf8_lossy(&output.stderr)
);
- let path = tempfile::tempdir().expect("Failed to create temp dir");
+ let path = worktrunk::testing::tempdir().expect("Failed to create temp dir");
let output = run_wt_perf(&[
"setup",
"imported",
@@ -98,7 +98,7 @@ fn setup_validation_does_not_acquire_imported_fixture() {
#[test]
fn setup_builds_a_semantic_recipe_at_an_explicit_path() {
- let root = tempfile::tempdir().expect("Failed to create temp dir");
+ let root = worktrunk::testing::tempdir().expect("Failed to create temp dir");
let repo = root.path().join("generated-fixture");
let output = run_wt_perf(&["setup", "generated", "--path", repo.to_str().unwrap()]);
assert!(
@@ -120,7 +120,7 @@ fn setup_builds_a_semantic_recipe_at_an_explicit_path() {
#[test]
fn setup_layers_prune_state_onto_a_canonical_base() {
- let root = tempfile::tempdir().expect("Failed to create temp dir");
+ let root = worktrunk::testing::tempdir().expect("Failed to create temp dir");
let repo = root.path().join("prune-fixture");
let output = run_wt_perf(&[
"setup",
@@ -170,7 +170,7 @@ fn setup_layers_prune_state_onto_a_canonical_base() {
#[test]
fn setup_never_mutates_an_existing_destination() {
- let root = tempfile::tempdir().expect("Failed to create temp dir");
+ let root = worktrunk::testing::tempdir().expect("Failed to create temp dir");
let destination = root.path().join("existing");
std::fs::create_dir(&destination).expect("Failed to create destination");
let sentinel = destination.join("sentinel");
@@ -295,7 +295,7 @@ fn test_wt_perf_trace_empty_input() {
#[test]
fn test_wt_perf_trace_from_file() {
// Create a temp file with sample trace data
- let temp_dir = tempfile::tempdir().expect("Failed to create temp dir");
+ let temp_dir = worktrunk::testing::tempdir().expect("Failed to create temp dir");
let log_file = temp_dir.path().join("trace.jsonl");
let sample_trace = r#"{"kind":"cmd_completed","ts":1000000,"tid":1,"cmd":"git rev-parse","dur_us":5000,"ok":true}
diff --git a/tests/integration_tests/approval_save.rs b/tests/integration_tests/approval_save.rs
index f3aeff99b..2a3700969 100644
--- a/tests/integration_tests/approval_save.rs
+++ b/tests/integration_tests/approval_save.rs
@@ -1,6 +1,5 @@
use insta::assert_snapshot;
use std::fs;
-use tempfile::TempDir;
use worktrunk::config::Approvals;
use worktrunk::config::UserConfig;
@@ -8,7 +7,7 @@ use worktrunk::config::UserConfig;
/// This test uses `approve_commands()` to ensure it never writes to the user's config
#[test]
fn test_approval_saves_to_disk() {
- let temp_dir = TempDir::new().unwrap();
+ let temp_dir = worktrunk::testing::tempdir().unwrap();
let approvals_path = temp_dir.path().join("worktrunk").join("approvals.toml");
// Create approvals and save to temp directory ONLY
@@ -45,7 +44,7 @@ fn test_approval_saves_to_disk() {
#[test]
fn test_duplicate_approvals_not_saved_twice() {
- let temp_dir = TempDir::new().unwrap();
+ let temp_dir = worktrunk::testing::tempdir().unwrap();
let approvals_path = temp_dir.path().join("approvals.toml");
let mut approvals = Approvals::default();
@@ -78,7 +77,7 @@ fn test_duplicate_approvals_not_saved_twice() {
#[test]
fn test_multiple_project_approvals() {
- let temp_dir = TempDir::new().unwrap();
+ let temp_dir = worktrunk::testing::tempdir().unwrap();
let approvals_path = temp_dir.path().join("approvals.toml");
let mut approvals = Approvals::default();
@@ -130,7 +129,7 @@ fn test_multiple_project_approvals() {
#[test]
fn test_isolated_config_safety() {
- let temp_dir = TempDir::new().unwrap();
+ let temp_dir = worktrunk::testing::tempdir().unwrap();
let approvals_path = temp_dir.path().join("isolated.toml");
// Read user's actual approvals before test (if it exists)
@@ -182,7 +181,7 @@ fn test_isolated_config_safety() {
#[test]
fn test_approval_saves_to_new_approvals_file() {
- let temp_dir = TempDir::new().unwrap();
+ let temp_dir = worktrunk::testing::tempdir().unwrap();
let approvals_dir = temp_dir.path().join("nested").join("config");
let approvals_path = approvals_dir.join("approvals.toml");
@@ -221,7 +220,7 @@ fn test_approval_saves_to_new_approvals_file() {
/// `[switch.picker]` has no field for.
#[test]
fn test_saving_command_beside_deprecated_commit_generation_keeps_its_template() {
- let temp_dir = TempDir::new().unwrap();
+ let temp_dir = worktrunk::testing::tempdir().unwrap();
let config_path = temp_dir.path().join("config.toml");
fs::write(
&config_path,
@@ -258,7 +257,7 @@ fn test_saving_command_beside_deprecated_commit_generation_keeps_its_template()
/// beside the original.
#[test]
fn test_saving_config_mutation_changes_only_its_value() {
- let temp_dir = TempDir::new().unwrap();
+ let temp_dir = worktrunk::testing::tempdir().unwrap();
let config_path = temp_dir.path().join("config.toml");
let initial_content = r#"# User preferences for worktrunk
@@ -341,7 +340,7 @@ notify = "echo switched"
/// the first approval, losing it.
#[test]
fn test_concurrent_approve_preserves_all_approvals() {
- let temp_dir = TempDir::new().unwrap();
+ let temp_dir = worktrunk::testing::tempdir().unwrap();
let approvals_path = temp_dir.path().join("approvals.toml");
// Process A: Start with empty approvals, approve "npm install"
@@ -398,7 +397,7 @@ fn test_concurrent_approve_preserves_all_approvals() {
/// the revoked command from its stale in-memory state.
#[test]
fn test_concurrent_revoke_preserves_all_changes() {
- let temp_dir = TempDir::new().unwrap();
+ let temp_dir = worktrunk::testing::tempdir().unwrap();
let approvals_path = temp_dir.path().join("approvals.toml");
// Setup: approvals file has two commands approved
@@ -445,7 +444,7 @@ fn test_concurrent_revoke_preserves_all_changes() {
#[test]
fn test_concurrent_approve_different_projects() {
- let temp_dir = TempDir::new().unwrap();
+ let temp_dir = worktrunk::testing::tempdir().unwrap();
let approvals_path = temp_dir.path().join("approvals.toml");
// Process A: empty approvals
@@ -503,7 +502,7 @@ fn test_truly_concurrent_approve_with_threads() {
use std::sync::{Arc, Barrier};
use std::thread;
- let temp_dir = TempDir::new().unwrap();
+ let temp_dir = worktrunk::testing::tempdir().unwrap();
let approvals_path = temp_dir.path().join("approvals.toml");
// Create 10 threads that will all try to approve at the same time
@@ -569,7 +568,7 @@ fn test_permission_error_prevents_save() {
use std::fs::Permissions;
use std::os::unix::fs::PermissionsExt;
- let temp_dir = TempDir::new().unwrap();
+ let temp_dir = worktrunk::testing::tempdir().unwrap();
let approvals_path = temp_dir.path().join("readonly").join("approvals.toml");
// Create the directory and initial approvals file
@@ -630,7 +629,7 @@ fn test_permission_error_prevents_save() {
#[test]
fn test_skip_shell_integration_prompt_saves_to_disk() {
- let temp_dir = TempDir::new().unwrap();
+ let temp_dir = worktrunk::testing::tempdir().unwrap();
let config_path = temp_dir.path().join("worktrunk").join("config.toml");
let mut config = UserConfig::default();
@@ -652,7 +651,7 @@ fn test_skip_shell_integration_prompt_saves_to_disk() {
#[test]
fn test_skip_shell_integration_prompt_idempotent() {
- let temp_dir = TempDir::new().unwrap();
+ let temp_dir = worktrunk::testing::tempdir().unwrap();
let config_path = temp_dir.path().join("config.toml");
let mut config = UserConfig::default();
@@ -678,7 +677,7 @@ fn test_skip_shell_integration_prompt_idempotent() {
#[test]
fn test_skip_commit_generation_prompt_saves_to_disk() {
- let temp_dir = TempDir::new().unwrap();
+ let temp_dir = worktrunk::testing::tempdir().unwrap();
let config_path = temp_dir.path().join("worktrunk").join("config.toml");
let mut config = UserConfig::default();
@@ -700,7 +699,7 @@ fn test_skip_commit_generation_prompt_saves_to_disk() {
#[test]
fn test_skip_commit_generation_prompt_idempotent() {
- let temp_dir = TempDir::new().unwrap();
+ let temp_dir = worktrunk::testing::tempdir().unwrap();
let config_path = temp_dir.path().join("config.toml");
let mut config = UserConfig::default();
@@ -726,7 +725,7 @@ fn test_skip_commit_generation_prompt_idempotent() {
#[test]
fn test_set_commit_generation_command_saves_to_disk() {
- let temp_dir = TempDir::new().unwrap();
+ let temp_dir = worktrunk::testing::tempdir().unwrap();
let config_path = temp_dir.path().join("worktrunk").join("config.toml");
let mut config = UserConfig::default();
@@ -751,7 +750,7 @@ fn test_set_commit_generation_command_saves_to_disk() {
#[test]
fn test_set_commit_generation_command_with_special_chars() {
- let temp_dir = TempDir::new().unwrap();
+ let temp_dir = worktrunk::testing::tempdir().unwrap();
let config_path = temp_dir.path().join("config.toml");
let mut config = UserConfig::default();
@@ -780,7 +779,7 @@ fn test_set_commit_generation_command_with_special_chars() {
fn test_saving_through_symlink_preserves_symlink() {
use std::os::unix::fs::symlink;
- let temp_dir = TempDir::new().unwrap();
+ let temp_dir = worktrunk::testing::tempdir().unwrap();
// Create a "dotfiles" directory with the actual config
let dotfiles_dir = temp_dir.path().join("dotfiles");
diff --git a/tests/integration_tests/bare_repository.rs b/tests/integration_tests/bare_repository.rs
index 1d49cf1d8..a2016177e 100644
--- a/tests/integration_tests/bare_repository.rs
+++ b/tests/integration_tests/bare_repository.rs
@@ -529,7 +529,7 @@ fn test_bare_repo_repo_path_with_inherited_relative_git_dir() {
fn test_repo_path_via_real_git_alias_bare_dot_git_layout() {
use crate::common::{configure_git_env, wt_bin};
- let temp_dir = tempfile::TempDir::new().unwrap();
+ let temp_dir = worktrunk::testing::tempdir().unwrap();
let temp_path = canonicalize(temp_dir.path()).unwrap();
// Layout: repo/.git (bare) + repo/main (linked worktree).
@@ -1553,7 +1553,7 @@ fn test_bare_repo_project_config_found_with_dash_c_flag() {
test.commit_in(&main_worktree, "Add project config");
// Run from a completely unrelated directory using -C to point at the bare repo
- let unrelated_dir = tempfile::tempdir().unwrap();
+ let unrelated_dir = worktrunk::testing::tempdir().unwrap();
let (cd_path, _guard) = directive_file();
let mut cmd = wt_command();
test.configure_wt_cmd(&mut cmd);
@@ -1720,7 +1720,7 @@ struct NestedBareRepoTest {
impl NestedBareRepoTest {
fn new() -> Self {
- let temp_dir = tempfile::TempDir::new().unwrap();
+ let temp_dir = worktrunk::testing::tempdir().unwrap();
// Create project directory with the bare repo inside as .git
let project_path = temp_dir.path().join("project");
let repo = TestRepo::bare_at(&project_path.join(".git"));
@@ -1977,7 +1977,7 @@ fn test_bare_repo_bootstrap_first_worktree() {
/// (used by BareRepoTest) to cover the exact reported scenario.
#[test]
fn test_clone_bare_repo_list_no_status_errors() {
- let temp_dir = tempfile::TempDir::new().unwrap();
+ let temp_dir = worktrunk::testing::tempdir().unwrap();
let test_config_path = temp_dir.path().join("test-config.toml");
fs::write(&test_config_path, "").unwrap();
diff --git a/tests/integration_tests/ci_status.rs b/tests/integration_tests/ci_status.rs
index 14eb61f18..86a192cb2 100644
--- a/tests/integration_tests/ci_status.rs
+++ b/tests/integration_tests/ci_status.rs
@@ -665,7 +665,7 @@ fn test_gitlab_project_id_resolved_once_per_command(mut repo: TestRepo) {
// Outside the repo under test, so the log can't dirty the working tree the
// command is inspecting.
- let call_log = tempfile::tempdir().unwrap();
+ let call_log = worktrunk::testing::tempdir().unwrap();
let mut cmd = repo.wt_command();
cmd.args(["list", "--full"]);
repo.configure_mock_commands(&mut cmd);
@@ -729,7 +729,7 @@ fn test_pr_lookup_skips_branches_on_no_remote(mut repo: TestRepo) {
repo.run_git(&["config", "branch.narrow-pushed.pushremote", "narrow"]);
repo.setup_mock_gh_with_ci_data("[]");
- let call_log = tempfile::tempdir().unwrap();
+ let call_log = worktrunk::testing::tempdir().unwrap();
let mut cmd = repo.wt_command();
cmd.args(["list", "--full"]);
repo.configure_mock_commands(&mut cmd);
@@ -1340,7 +1340,7 @@ fn test_list_full_azure_pr_lookup_names_the_repository(mut repo: TestRepo) {
// Outside the repo under test, so the log can't dirty the working tree the
// command is inspecting.
- let call_log = tempfile::tempdir().unwrap();
+ let call_log = worktrunk::testing::tempdir().unwrap();
let mut cmd = repo.wt_command();
cmd.args(["list", "--full"]);
repo.configure_mock_commands(&mut cmd);
diff --git a/tests/integration_tests/completion.rs b/tests/integration_tests/completion.rs
index f8f07ec1b..f22a4d875 100644
--- a/tests/integration_tests/completion.rs
+++ b/tests/integration_tests/completion.rs
@@ -217,7 +217,7 @@ fn test_complete_base_flag_all_formats(repo: TestRepo) {
#[rstest]
fn test_complete_outside_git_repo() {
- let temp = tempfile::tempdir().unwrap();
+ let temp = worktrunk::testing::tempdir().unwrap();
let mut settings = Settings::clone_current();
settings.set_snapshot_path("../snapshots");
@@ -2326,7 +2326,7 @@ fn test_complete_custom_subcommand_listed(repo: TestRepo) {
repo.commit("initial");
// Create a mock wt-testext binary on PATH
- let ext_dir = tempfile::tempdir().unwrap();
+ let ext_dir = worktrunk::testing::tempdir().unwrap();
MockConfig::new("wt-testext")
.command("_default", MockResponse::output("external ran\n"))
.write(ext_dir.path());
@@ -2420,7 +2420,7 @@ fn test_complete_custom_subcommand_forwards(repo: TestRepo) {
// Create a real shell script that outputs completions (not a mock_commands
// mock, which needs WORKTRUNK_TEST_MOCK_CONFIG_DIR and plays back its config
// instead of answering the COMPLETE env var).
- let ext_dir = tempfile::tempdir().unwrap();
+ let ext_dir = worktrunk::testing::tempdir().unwrap();
let retired_file = ext_dir.path().join("retired");
std::fs::write(&retired_file, "").unwrap();
let script = ext_dir.path().join("wt-testext");
@@ -2671,7 +2671,7 @@ fn test_completion_registration_rejects_invalid_complete_name(#[case] name: &str
#[cfg(unix)]
#[rstest]
fn test_completion_registration_falls_back_when_binary_name_is_invalid() {
- let dir = tempfile::tempdir().unwrap();
+ let dir = worktrunk::testing::tempdir().unwrap();
let link = dir.path().join("wt+odd");
std::os::unix::fs::symlink(crate::common::wt_bin(), &link).unwrap();
diff --git a/tests/integration_tests/config_show.rs b/tests/integration_tests/config_show.rs
index 1d216fc18..54ca79b5d 100644
--- a/tests/integration_tests/config_show.rs
+++ b/tests/integration_tests/config_show.rs
@@ -122,7 +122,7 @@ fn test_config_show_with_system_config(mut repo: TestRepo, temp_home: TempDir) {
repo.setup_mock_ci_tools_unauthenticated();
// Create system config in a temp directory
- let system_config_dir = tempfile::tempdir().unwrap();
+ let system_config_dir = worktrunk::testing::tempdir().unwrap();
let system_config_path = system_config_dir.path().join("config.toml");
fs::write(
&system_config_path,
@@ -161,7 +161,7 @@ command = "company-llm-tool"
#[rstest]
fn test_system_config_values_used_as_defaults(repo: TestRepo) {
// System config with a distinctive worktree-path template
- let system_config_dir = tempfile::tempdir().unwrap();
+ let system_config_dir = worktrunk::testing::tempdir().unwrap();
let system_config_path = system_config_dir.path().join("config.toml");
fs::write(
&system_config_path,
@@ -194,7 +194,7 @@ fn test_system_config_values_used_as_defaults(repo: TestRepo) {
#[rstest]
fn test_user_config_overrides_system_config(repo: TestRepo) {
// System config with one template
- let system_config_dir = tempfile::tempdir().unwrap();
+ let system_config_dir = worktrunk::testing::tempdir().unwrap();
let system_config_path = system_config_dir.path().join("config.toml");
fs::write(
&system_config_path,
@@ -203,7 +203,7 @@ fn test_user_config_overrides_system_config(repo: TestRepo) {
.unwrap();
// User config overrides with a different template
- let user_config_dir = tempfile::tempdir().unwrap();
+ let user_config_dir = worktrunk::testing::tempdir().unwrap();
let user_config_path = user_config_dir.path().join("config.toml");
fs::write(
&user_config_path,
@@ -244,7 +244,7 @@ fn test_user_config_overrides_system_config(repo: TestRepo) {
#[rstest]
fn test_system_and_user_hooks_deep_merged(repo: TestRepo) {
// System config defines a named pre-merge hook
- let system_config_dir = tempfile::tempdir().unwrap();
+ let system_config_dir = worktrunk::testing::tempdir().unwrap();
let system_config_path = system_config_dir.path().join("config.toml");
fs::write(
&system_config_path,
@@ -255,7 +255,7 @@ company-lint = "company-lint-tool"
.unwrap();
// User config defines a differently-named pre-merge hook
- let user_config_dir = tempfile::tempdir().unwrap();
+ let user_config_dir = worktrunk::testing::tempdir().unwrap();
let user_config_path = user_config_dir.path().join("config.toml");
fs::write(
&user_config_path,
@@ -296,7 +296,7 @@ my-lint = "my-lint-tool"
#[rstest]
fn test_user_hook_replaces_same_named_system_hook(repo: TestRepo) {
// System config defines a named hook
- let system_config_dir = tempfile::tempdir().unwrap();
+ let system_config_dir = worktrunk::testing::tempdir().unwrap();
let system_config_path = system_config_dir.path().join("config.toml");
fs::write(
&system_config_path,
@@ -307,7 +307,7 @@ lint = "company-lint-tool"
.unwrap();
// User config defines the same-named hook with different command
- let user_config_dir = tempfile::tempdir().unwrap();
+ let user_config_dir = worktrunk::testing::tempdir().unwrap();
let user_config_path = user_config_dir.path().join("config.toml");
fs::write(
&user_config_path,
@@ -347,7 +347,7 @@ lint = "my-lint-tool"
#[rstest]
fn test_system_config_hooks_preserved_when_user_doesnt_override(repo: TestRepo) {
// System config defines pre-merge and pre-commit hooks
- let system_config_dir = tempfile::tempdir().unwrap();
+ let system_config_dir = worktrunk::testing::tempdir().unwrap();
let system_config_path = system_config_dir.path().join("config.toml");
fs::write(
&system_config_path,
@@ -361,7 +361,7 @@ company-format = "company-format-tool"
.unwrap();
// User config only defines pre-merge (should leave system's pre-commit intact)
- let user_config_dir = tempfile::tempdir().unwrap();
+ let user_config_dir = worktrunk::testing::tempdir().unwrap();
let user_config_path = user_config_dir.path().join("config.toml");
fs::write(
&user_config_path,
@@ -478,7 +478,7 @@ fn test_config_show_empty_system_config(mut repo: TestRepo, temp_home: TempDir)
repo.setup_mock_ci_tools_unauthenticated();
// Create empty system config
- let system_config_dir = tempfile::tempdir().unwrap();
+ let system_config_dir = worktrunk::testing::tempdir().unwrap();
let system_config_path = system_config_dir.path().join("config.toml");
fs::write(&system_config_path, "").unwrap();
@@ -506,7 +506,7 @@ fn test_config_show_empty_system_config(mut repo: TestRepo, temp_home: TempDir)
fn test_config_show_reports_unreadable_source_and_continues(repo: TestRepo, #[case] source: &str) {
let mut cmd = repo.wt_command();
let system_dir = if source == "system" {
- let dir = tempfile::tempdir().unwrap();
+ let dir = worktrunk::testing::tempdir().unwrap();
cmd.env("WORKTRUNK_SYSTEM_CONFIG_PATH", dir.path());
Some(dir)
} else {
@@ -590,7 +590,7 @@ fn test_config_show_invalid_system_config(mut repo: TestRepo, temp_home: TempDir
repo.setup_mock_ci_tools_unauthenticated();
// Create system config with invalid TOML
- let system_config_dir = tempfile::tempdir().unwrap();
+ let system_config_dir = worktrunk::testing::tempdir().unwrap();
let system_config_path = system_config_dir.path().join("config.toml");
fs::write(&system_config_path, "invalid = [toml\n").unwrap();
@@ -615,7 +615,7 @@ fn test_config_show_invalid_system_config(mut repo: TestRepo, temp_home: TempDir
#[rstest]
fn test_system_config_unknown_keys_warning_during_load(repo: TestRepo) {
// Create system config with an unknown key
- let system_config_dir = tempfile::tempdir().unwrap();
+ let system_config_dir = worktrunk::testing::tempdir().unwrap();
let system_config_path = system_config_dir.path().join("config.toml");
fs::write(
&system_config_path,
@@ -646,7 +646,7 @@ fn test_system_config_unknown_keys_warning_during_load(repo: TestRepo) {
/// migrated to its canonical name and stays active.
#[rstest]
fn test_system_config_deprecations_pass_through_gate(repo: TestRepo) {
- let system_config_dir = tempfile::tempdir().unwrap();
+ let system_config_dir = worktrunk::testing::tempdir().unwrap();
let system_config_path = system_config_dir.path().join("config.toml");
fs::write(
&system_config_path,
@@ -684,7 +684,7 @@ pager = "delta --paging=never"
#[rstest]
fn test_config_show_outside_git_repo(mut repo: TestRepo, temp_home: TempDir) {
- let temp_dir = tempfile::tempdir().unwrap();
+ let temp_dir = worktrunk::testing::tempdir().unwrap();
// Setup mock gh/glab for deterministic BINARIES output
repo.setup_mock_ci_tools_unauthenticated();
@@ -1686,7 +1686,7 @@ fn test_config_show_full_tea_login_discovery(
"origin",
"https://gitea.example.com/example/repo.git",
]);
- let call_log = tempfile::tempdir().unwrap();
+ let call_log = worktrunk::testing::tempdir().unwrap();
let output = repo
.wt_command()
.args(["config", "show", "--full"])
@@ -1788,7 +1788,7 @@ kill -INT $$
"origin",
"https://gitea.example.com/example/repo.git",
]);
- let call_log = tempfile::tempdir().unwrap();
+ let call_log = worktrunk::testing::tempdir().unwrap();
let output = repo
.wt_command()
.args(["config", "show", "--full"])
@@ -3348,7 +3348,7 @@ fn test_pi_install_honors_agent_dir_override(temp_home: TempDir) {
// Pi expands a leading `~` in the override, so a quoted `~/…` lands under
// home rather than in a literal `~` directory beneath the cwd.
- let cwd = tempfile::tempdir().unwrap();
+ let cwd = worktrunk::testing::tempdir().unwrap();
let mut cmd = wt_command();
set_temp_home_env(&mut cmd, temp_home.path());
cmd.current_dir(cwd.path());
@@ -4905,7 +4905,7 @@ fn test_config_show_full_stops_after_cancelled_powershell_query(
fs::write(&pwsh, format!("#!/bin/sh\nkill -{signal} $$\n")).unwrap();
fs::set_permissions(&pwsh, fs::Permissions::from_mode(0o755)).unwrap();
- let call_log = TempDir::new().unwrap();
+ let call_log = worktrunk::testing::tempdir().unwrap();
let mut cmd = repo.wt_command();
cmd.env("WORKTRUNK_TEST_LATEST_VERSION", env!("CARGO_PKG_VERSION"))
.env("WORKTRUNK_TEST_MOCK_CALL_LOG_DIR", call_log.path())
@@ -4945,7 +4945,7 @@ fn test_config_show_full_continues_after_failed_powershell_query(
fs::write(&pwsh, "#!/bin/sh\nexit 130\n").unwrap();
fs::set_permissions(&pwsh, fs::Permissions::from_mode(0o755)).unwrap();
- let call_log = TempDir::new().unwrap();
+ let call_log = worktrunk::testing::tempdir().unwrap();
let mut cmd = repo.wt_command();
cmd.env("WORKTRUNK_TEST_LATEST_VERSION", env!("CARGO_PKG_VERSION"))
.env("WORKTRUNK_TEST_MOCK_CALL_LOG_DIR", call_log.path())
@@ -4979,7 +4979,7 @@ fn test_config_show_full_continues_after_failed_shell_scan(mut repo: TestRepo, t
]);
fs::create_dir(temp_home.path().join(".bashrc")).unwrap();
- let call_log = TempDir::new().unwrap();
+ let call_log = worktrunk::testing::tempdir().unwrap();
let mut cmd = repo.wt_command();
cmd.env("WORKTRUNK_TEST_LATEST_VERSION", env!("CARGO_PKG_VERSION"))
.env("WORKTRUNK_TEST_MOCK_CALL_LOG_DIR", call_log.path())
@@ -5017,7 +5017,7 @@ fn plugin_calls_when_accepted(
use std::io::Write as _;
use std::process::Stdio;
- let call_log = TempDir::new().unwrap();
+ let call_log = worktrunk::testing::tempdir().unwrap();
let mut cmd = repo.wt_command();
cmd.args(["config", "plugins", tool, action])
.current_dir(repo.root_path())
@@ -5053,7 +5053,7 @@ fn test_plugins_codex_prompt_previews_commands(mut repo: TestRepo, temp_home: Te
// Outside the repo: a call log in the working tree would leave an
// untracked file behind the command under test.
- let call_log = TempDir::new().unwrap();
+ let call_log = worktrunk::testing::tempdir().unwrap();
for (action, expected) in [
(
@@ -5134,9 +5134,9 @@ fn test_plugins_claude_prompt_previews_commands(mut repo: TestRepo) {
// Outside the repo: a call log in the working tree would leave an
// untracked file behind the command under test.
- let call_log = TempDir::new().unwrap();
+ let call_log = worktrunk::testing::tempdir().unwrap();
- let temp_home = TempDir::new().unwrap();
+ let temp_home = worktrunk::testing::tempdir().unwrap();
for (action, expected) in [
(
@@ -6183,7 +6183,7 @@ fn test_shim_ignores_a_git_in_the_current_directory(repo: TestRepo) {
MockConfig::new("git")
.command("--exec-path", MockResponse::output("not-an-install"))
.write(&project);
- let call_log = TempDir::new().unwrap();
+ let call_log = worktrunk::testing::tempdir().unwrap();
let mut cmd = std::process::Command::new("cmd.exe");
repo.configure_wt_cmd(&mut cmd);
@@ -7221,7 +7221,7 @@ mod plugin_prompt_pty {
#[rstest]
fn test_config_show_json(repo: TestRepo, temp_home: TempDir) {
- let system_config_dir = tempfile::tempdir().unwrap();
+ let system_config_dir = worktrunk::testing::tempdir().unwrap();
let system_config_path = system_config_dir.path().join("config.toml");
fs::write(
&system_config_path,
@@ -7273,7 +7273,7 @@ fn test_config_show_json_allows_invalid_runtime_override(
#[case] env_value: &str,
#[case] inline: Option<&str>,
) {
- let system_config_dir = tempfile::tempdir().unwrap();
+ let system_config_dir = worktrunk::testing::tempdir().unwrap();
let system_config_path = system_config_dir.path().join("config.toml");
fs::write(&system_config_path, "[list]\nbranches = true\n").unwrap();
let global_config_dir = temp_home.path().join(".config").join("worktrunk");
@@ -7358,7 +7358,7 @@ fn test_config_show_rejects_semantically_invalid_system_config(
repo: TestRepo,
#[case] args: &[&str],
) {
- let system_config_dir = tempfile::tempdir().unwrap();
+ let system_config_dir = worktrunk::testing::tempdir().unwrap();
let system_config_path = system_config_dir.path().join("config.toml");
fs::write(&system_config_path, "worktree-path = \"\"\n").unwrap();
fs::write(repo.test_config_path(), "worktree-path = \"../valid\"\n").unwrap();
@@ -7478,7 +7478,7 @@ fn test_config_show_json_rejects_invalid_system_config(repo: TestRepo, temp_home
#[rstest]
fn test_config_show_json_rejects_unreadable_system_config(repo: TestRepo, temp_home: TempDir) {
- let system_config_dir = tempfile::tempdir().unwrap();
+ let system_config_dir = worktrunk::testing::tempdir().unwrap();
let mut cmd = wt_command();
repo.configure_wt_cmd(&mut cmd);
@@ -7649,7 +7649,7 @@ fn test_config_show_json_with_project_config(repo: TestRepo, temp_home: TempDir)
#[rstest]
fn test_config_show_json_outside_repo(repo: TestRepo, temp_home: TempDir) {
- let temp_dir = tempfile::tempdir().unwrap();
+ let temp_dir = worktrunk::testing::tempdir().unwrap();
let global_config_dir = temp_home.path().join(".config").join("worktrunk");
fs::create_dir_all(&global_config_dir).unwrap();
@@ -7697,7 +7697,7 @@ fn test_project_config_path_env_var_override(repo: TestRepo, temp_home: TempDir)
fs::write(&in_repo_config, "pre-start = \"in-repo-hook\"\n").unwrap();
// Write the override project config at an arbitrary path.
- let override_dir = tempfile::tempdir().unwrap();
+ let override_dir = worktrunk::testing::tempdir().unwrap();
let override_path = override_dir.path().join("override.toml");
fs::write(&override_path, "pre-start = \"override-hook\"\n").unwrap();
diff --git a/tests/integration_tests/custom.rs b/tests/integration_tests/custom.rs
index 291457569..2a13e6b0c 100644
--- a/tests/integration_tests/custom.rs
+++ b/tests/integration_tests/custom.rs
@@ -32,7 +32,7 @@ fn prepend_path(cmd: &mut Command, dir: &Path) {
/// Create a mock `wt-<name>` binary in a temp dir, and return the dir.
fn mock_bin_dir(name: &str, response: MockResponse) -> TempDir {
- let dir = TempDir::new().unwrap();
+ let dir = worktrunk::testing::tempdir().unwrap();
MockConfig::new(name)
.command("_default", response)
.write(dir.path());
@@ -47,7 +47,7 @@ fn mock_bin_dir(name: &str, response: MockResponse) -> TempDir {
/// exit 1 with no output), and that fatal line is the one the alias error
/// quotes back.
fn set_git_only_path(cmd: &mut Command) -> TempDir {
- let dir = TempDir::new().unwrap();
+ let dir = worktrunk::testing::tempdir().unwrap();
MockConfig::new("git")
.version("git version 2.43.0")
.command(
@@ -89,7 +89,7 @@ fn custom_subcommand_accepts_non_utf8_forwarded_arg() {
use std::os::unix::ffi::OsStringExt;
use std::os::unix::fs::PermissionsExt;
- let dir = TempDir::new().unwrap();
+ let dir = worktrunk::testing::tempdir().unwrap();
let script = dir.path().join("wt-wt-test-extcmd-raw");
std::fs::write(&script, "#!/bin/sh\nprintf 'custom ran\\n'\n").unwrap();
let mut perms = std::fs::metadata(&script).unwrap().permissions();
@@ -118,7 +118,7 @@ fn custom_subcommand_scrubs_shell_exec_directives_and_preserves_cd() {
DIRECTIVE_CD_FILE_ENV_VAR, DIRECTIVE_EXEC_FILE_ENV_VAR, RETIRED_DIRECTIVE_FILE_ENV_VAR,
};
- let dir = TempDir::new().unwrap();
+ let dir = worktrunk::testing::tempdir().unwrap();
let retired_file = dir.path().join("retired");
let cd_file = dir.path().join("cd");
let exec_file = dir.path().join("exec");
@@ -216,7 +216,7 @@ fn custom_subcommand_alias_outside_repo_names_the_alias() {
// dispatch ends inside try_alias with the alias-needs-repository error —
// a configured alias isn't "unrecognized", and the clap-style fallback
// would suggest the typed name itself.
- let config_dir = tempfile::tempdir().unwrap();
+ let config_dir = worktrunk::testing::tempdir().unwrap();
let config_path = config_dir.path().join("config.toml");
std::fs::write(&config_path, "[aliases]\nco = \"echo hi\"\n").unwrap();
@@ -236,11 +236,11 @@ fn custom_subcommand_alias_outside_repo_omits_gutter_when_git_says_nothing() {
// The gutter quotes git's explanation, so a fatal exit that carries no
// output leaves the alias error and its hint alone — not a blank gutter
// line where the explanation would have gone.
- let config_dir = tempfile::tempdir().unwrap();
+ let config_dir = worktrunk::testing::tempdir().unwrap();
let config_path = config_dir.path().join("config.toml");
std::fs::write(&config_path, "[aliases]\nco = \"echo hi\"\n").unwrap();
- let git_dir = TempDir::new().unwrap();
+ let git_dir = worktrunk::testing::tempdir().unwrap();
MockConfig::new("git")
.version("git version 2.43.0")
.command("rev-parse", MockResponse::exit(128))
@@ -274,13 +274,13 @@ fn custom_subcommand_alias_propagates_non_fatal_git_failure() {
// any other way surfaces as itself, the way it does for every other
// command, rather than being reported as a repository verdict git never
// gave.
- let config_dir = tempfile::tempdir().unwrap();
+ let config_dir = worktrunk::testing::tempdir().unwrap();
let config_path = config_dir.path().join("config.toml");
std::fs::write(&config_path, "[aliases]\nco = \"echo hi\"\n").unwrap();
// No `rev-parse` response, so it falls through to mock_stub's default:
// exit 1 with no output, unlike `set_git_only_path`'s fatal 128.
- let git_dir = TempDir::new().unwrap();
+ let git_dir = worktrunk::testing::tempdir().unwrap();
MockConfig::new("git")
.version("git version 2.43.0")
.write(git_dir.path());
@@ -312,7 +312,7 @@ fn custom_subcommand_alias_outside_repo_wins_over_path_binary() {
// ends in try_alias with the needs-repository error instead of falling
// through to a colliding `wt-<name>` PATH binary — the same "user config
// wins over wt-<name> PATH binaries" precedence as in-repo dispatch.
- let config_dir = tempfile::tempdir().unwrap();
+ let config_dir = worktrunk::testing::tempdir().unwrap();
let config_path = config_dir.path().join("config.toml");
std::fs::write(
&config_path,
@@ -436,7 +436,7 @@ fn custom_subcommand_respects_global_dash_c_flag() {
// doesn't exist from the parent's cwd), the child will still run because
// we pass an absolute path. So we verify by confirming the child ran and
// exited cleanly even though the parent's cwd is unrelated.
- let target_dir = TempDir::new().unwrap();
+ let target_dir = worktrunk::testing::tempdir().unwrap();
let dir = mock_bin_dir("wt-wt-test-extcmd-cwd", MockResponse::output("ok\n"));
let mut cmd = wt_command();
diff --git a/tests/integration_tests/default_branch.rs b/tests/integration_tests/default_branch.rs
index ca6236563..1a33003c5 100644
--- a/tests/integration_tests/default_branch.rs
+++ b/tests/integration_tests/default_branch.rs
@@ -812,7 +812,7 @@ fn test_default_branch_via_c_flag_from_non_repo_cwd(repo: TestRepo) {
// local probe.
repo.run_git(&["remote", "remove", "origin"]);
- let non_repo_cwd = tempfile::tempdir().unwrap();
+ let non_repo_cwd = worktrunk::testing::tempdir().unwrap();
let mut cmd = repo.wt_command();
cmd.current_dir(non_repo_cwd.path()).args([
"-C",
@@ -845,7 +845,7 @@ fn test_default_branch_via_c_flag_to_linked_worktree_of_bare_repo() {
// Make sure there's a commit so refs resolve cleanly.
test.commit_in(&main_worktree, "init");
- let non_repo_cwd = tempfile::tempdir().unwrap();
+ let non_repo_cwd = worktrunk::testing::tempdir().unwrap();
let mut cmd = test.wt_command();
cmd.current_dir(non_repo_cwd.path()).args([
"-C",
diff --git a/tests/integration_tests/diagnostic.rs b/tests/integration_tests/diagnostic.rs
index f32c1d4f7..a2fd648f4 100644
--- a/tests/integration_tests/diagnostic.rs
+++ b/tests/integration_tests/diagnostic.rs
@@ -65,7 +65,7 @@ fn test_auth_probe_output_is_redacted(
.command("_default", MockResponse::output("[]"))
.write(repo.mock_bin_path().unwrap());
- let call_log = tempfile::tempdir().unwrap();
+ let call_log = worktrunk::testing::tempdir().unwrap();
let output = repo
.wt_command()
.args(["config", "show", "--full", "-vv"])
@@ -1222,7 +1222,7 @@ fn test_vv_outside_repo_no_crash() {
use crate::common::wt_command;
// Create a temp directory that is NOT a git repo
- let temp_dir = tempfile::tempdir().unwrap();
+ let temp_dir = worktrunk::testing::tempdir().unwrap();
// Use `list` (not `--version`) so `init_logging` actually runs — clap
// short-circuits `--version` before logging is set up, which would
diff --git a/tests/integration_tests/directives.rs b/tests/integration_tests/directives.rs
index 5878ea244..57b95d0f0 100644
--- a/tests/integration_tests/directives.rs
+++ b/tests/integration_tests/directives.rs
@@ -21,7 +21,7 @@ fn test_switch_retired_directive_file_does_not_block_execute(
#[from(repo_with_remote)] mut repo: TestRepo,
) {
let feature_wt = repo.add_worktree("feature");
- let directive_dir = tempfile::TempDir::new().unwrap();
+ let directive_dir = worktrunk::testing::tempdir().unwrap();
let directive_path = directive_dir.path().join("directive");
let execute_marker = feature_wt.join("retired-execute-ran");
fs::write(&directive_path, "").unwrap();
@@ -58,7 +58,7 @@ fn test_current_wrapper_wins_retired_variables_and_warns(
) {
let _feature_wt = repo.add_worktree("feature");
let (cd_path, _guard) = directive_file();
- let retired_dir = tempfile::TempDir::new().unwrap();
+ let retired_dir = worktrunk::testing::tempdir().unwrap();
let retired_path = retired_dir.path().join("directive");
let retired_exec_path = retired_dir.path().join("execute");
fs::write(&retired_path, "").unwrap();
@@ -661,7 +661,7 @@ fn test_switch_preserves_symlink_path(#[from(repo_with_remote)] mut repo: TestRe
// Create a symlink to the repo's parent directory
let real_parent = repo.root_path().parent().unwrap();
- let symlink_dir = tempfile::tempdir().unwrap();
+ let symlink_dir = worktrunk::testing::tempdir().unwrap();
let symlink_path = symlink_dir.path().join("link");
unix_fs::symlink(real_parent, &symlink_path).unwrap();
@@ -727,7 +727,7 @@ fn test_switch_create_preserves_symlink_path(#[from(repo_with_remote)] repo: Tes
// Create a symlink to the repo's parent directory
let real_parent = repo.root_path().parent().unwrap();
- let symlink_dir = tempfile::tempdir().unwrap();
+ let symlink_dir = worktrunk::testing::tempdir().unwrap();
let symlink_path = symlink_dir.path().join("link");
unix_fs::symlink(real_parent, &symlink_path).unwrap();
@@ -789,7 +789,7 @@ fn test_switch_preserves_symlink_path_from_subdirectory(
// Create a symlink to the repo's parent directory
let real_parent = repo.root_path().parent().unwrap();
- let symlink_dir = tempfile::tempdir().unwrap();
+ let symlink_dir = worktrunk::testing::tempdir().unwrap();
let symlink_path = symlink_dir.path().join("link");
unix_fs::symlink(real_parent, &symlink_path).unwrap();
diff --git a/tests/integration_tests/for_each.rs b/tests/integration_tests/for_each.rs
index 2f2d64749..4947c04d3 100644
--- a/tests/integration_tests/for_each.rs
+++ b/tests/integration_tests/for_each.rs
@@ -296,7 +296,7 @@ fn test_for_each_aborts_on_signal_exit(repo: TestRepo) {
// after the first signal. for-each exec's argv directly with no implicit
// shell, so shell features (`&&`, `$$`, `$(...)`) need an explicit
// `sh -c` invocation.
- let marker_dir = tempfile::tempdir().expect("create marker tmpdir");
+ let marker_dir = worktrunk::testing::tempdir().expect("create marker tmpdir");
let marker_path = marker_dir.path().to_string_lossy().to_string();
let shell_cmd = format!("touch {marker_path}/$(basename \"$(pwd)\") && kill -TERM $$");
@@ -342,7 +342,7 @@ fn test_for_each_aborts_on_signal_exit(repo: TestRepo) {
#[rstest]
#[cfg(unix)]
fn test_for_each_stops_on_caught_ctrl_c(repo: TestRepo) {
- let marker_dir = tempfile::tempdir().unwrap();
+ let marker_dir = worktrunk::testing::tempdir().unwrap();
let pid_file = marker_dir.path().join("pid");
let script = format!(
"trap 'exit 0' INT; touch {dir}/\"$(basename \"$PWD\")\"; echo $$ > {pid}; while :; do sleep 0.1; done",
@@ -436,7 +436,7 @@ fn test_for_each_json_preserves_caught_exit_on_controller_term(
}
}
- let markers = tempfile::tempdir().unwrap();
+ let markers = worktrunk::testing::tempdir().unwrap();
let ready = markers.path().join("ready");
std::fs::create_dir(&ready).unwrap();
let worker = r#"import json, os, pathlib, signal, sys
@@ -535,7 +535,7 @@ while True:
fn test_for_each_does_not_inherit_git_discovery_vars(mut repo: TestRepo) {
let feature_path = repo.add_worktree("feature");
- let marker_dir = tempfile::tempdir().expect("create marker tmpdir");
+ let marker_dir = worktrunk::testing::tempdir().expect("create marker tmpdir");
let marker_path = marker_dir.path().to_string_lossy().to_string();
let shell_cmd = format!(
r#"printf '[%s][%s]' "$GIT_DIR" "$GIT_WORK_TREE" > {marker_path}/$(basename "$(pwd)")"#
diff --git a/tests/integration_tests/foreground_jobs.rs b/tests/integration_tests/foreground_jobs.rs
index fb7996079..924c7d1b9 100644
--- a/tests/integration_tests/foreground_jobs.rs
+++ b/tests/integration_tests/foreground_jobs.rs
@@ -940,7 +940,7 @@ fn captured_child_signal_does_not_cancel_foreground_stream() {
use std::time::{Duration, Instant};
use worktrunk::shell_exec::Cmd;
- let dir = tempfile::tempdir().unwrap();
+ let dir = worktrunk::testing::tempdir().unwrap();
let ready = dir.path().join("ready");
let release = dir.path().join("release");
let body = format!(
@@ -998,7 +998,7 @@ fn captured_deadline_and_delayed_interrupt_bound_descendant_output() {
// Capture deadline, fully buffered interruption, and a quiet pre-threshold exit.
for delay in [None, Some(-1), Some(30_000)] {
- let dir = tempfile::tempdir().unwrap();
+ let dir = worktrunk::testing::tempdir().unwrap();
let release = dir.path().join("release");
let finished = dir.path().join("finished");
let body = format!(
diff --git a/tests/integration_tests/help.rs b/tests/integration_tests/help.rs
index 8a7a7d6a2..12fa54d06 100644
--- a/tests/integration_tests/help.rs
+++ b/tests/integration_tests/help.rs
@@ -435,7 +435,7 @@ fn test_print_schema_rejects_unknown_command() {
/// exercised through a symlink because this module is Unix-only.
#[test]
fn test_dev_entry_points_take_command_from_clap() {
- let dir = tempfile::tempdir().expect("create tempdir");
+ let dir = worktrunk::testing::tempdir().expect("create tempdir");
let renamed = dir.path().join("wt.exe");
std::os::unix::fs::symlink(wt_bin(), &renamed).expect("symlink wt binary");
diff --git a/tests/integration_tests/hook_show.rs b/tests/integration_tests/hook_show.rs
index 10bcfbaa1..0e8a1eadf 100644
--- a/tests/integration_tests/hook_show.rs
+++ b/tests/integration_tests/hook_show.rs
@@ -275,7 +275,7 @@ project-hook = "echo per-project"
#[rstest]
fn test_error_with_context_formatting(temp_home: TempDir) {
- let temp_dir = tempfile::tempdir().unwrap();
+ let temp_dir = worktrunk::testing::tempdir().unwrap();
// Run wt remove outside a git repo - should show "Failed to remove worktree" context
let settings = setup_home_snapshot_settings(&temp_home);
@@ -369,7 +369,7 @@ fn test_hook_show_empty_command_lists(repo: TestRepo, temp_home: TempDir) {
#[rstest]
fn test_hook_show_outside_git_repo(temp_home: TempDir) {
- let temp_dir = tempfile::tempdir().unwrap();
+ let temp_dir = worktrunk::testing::tempdir().unwrap();
// Create user config
let global_config_dir = temp_home.path().join(".config").join("worktrunk");
diff --git a/tests/integration_tests/init.rs b/tests/integration_tests/init.rs
index 9adb36022..764e2f3b7 100644
--- a/tests/integration_tests/init.rs
+++ b/tests/integration_tests/init.rs
@@ -110,7 +110,7 @@ fn test_init_rejects_unsafe_cmd(#[case] shell: &str, repo: TestRepo) {
fn test_mock_dispatch_ignores_degenerate_argv0() {
use std::os::unix::process::CommandExt;
- let config_dir = tempfile::tempdir().unwrap();
+ let config_dir = worktrunk::testing::tempdir().unwrap();
let output = Command::new(wt_bin())
.arg0("")
.arg("--version")
@@ -135,7 +135,7 @@ fn test_mock_dispatch_survives_non_utf8_argv0() {
use std::os::unix::ffi::OsStrExt;
use std::os::unix::process::CommandExt;
- let config_dir = tempfile::tempdir().unwrap();
+ let config_dir = worktrunk::testing::tempdir().unwrap();
let output = Command::new(wt_bin())
.arg0(OsStr::from_bytes(b"\xff\xfe"))
.arg("--version")
@@ -157,7 +157,7 @@ fn test_mock_dispatch_survives_non_utf8_argv0() {
/// may not have installed at all.
#[rstest]
fn test_init_keeps_dotted_argv0_command_name(repo: TestRepo) {
- let temp_dir = tempfile::tempdir().unwrap();
+ let temp_dir = worktrunk::testing::tempdir().unwrap();
let dotted_bin = temp_dir.path().join("wt.old");
std::os::unix::fs::symlink(wt_bin(), &dotted_bin).unwrap();
@@ -221,7 +221,7 @@ fn test_init_rejects_non_utf8_argv0_command_name() {
#[rstest]
fn test_init_rejects_unsafe_argv0_command_name(repo: TestRepo) {
- let temp_dir = tempfile::tempdir().unwrap();
+ let temp_dir = worktrunk::testing::tempdir().unwrap();
let bad_bin = temp_dir.path().join("wt;touch");
std::os::unix::fs::symlink(wt_bin(), &bad_bin).unwrap();
diff --git a/tests/integration_tests/nushell_default_config_dir.rs b/tests/integration_tests/nushell_default_config_dir.rs
index 01b0ae490..56c0da480 100644
--- a/tests/integration_tests/nushell_default_config_dir.rs
+++ b/tests/integration_tests/nushell_default_config_dir.rs
@@ -35,7 +35,7 @@ fn run_nu_default_config_dir(configure_env: impl FnOnce(&mut Command)) -> String
/// (including macOS).
#[test]
fn nu_default_config_dir_uses_xdg_when_set() {
- let temp = tempfile::tempdir().unwrap();
+ let temp = worktrunk::testing::tempdir().unwrap();
let xdg = temp.path().join("custom-xdg");
let actual = run_nu_default_config_dir(|cmd| {
cmd.env("XDG_CONFIG_HOME", &xdg);
diff --git a/tests/integration_tests/post_start_commands.rs b/tests/integration_tests/post_start_commands.rs
index 96dda8d17..946cffeba 100644
--- a/tests/integration_tests/post_start_commands.rs
+++ b/tests/integration_tests/post_start_commands.rs
@@ -8,7 +8,6 @@ use insta_cmd::assert_cmd_snapshot;
use rstest::rstest;
use std::fs;
use std::thread;
-use tempfile::TempDir;
/// Helper to create snapshot with normalized paths and SHAs
///
@@ -16,7 +15,7 @@ use tempfile::TempDir;
/// Uses an isolated HOME to prevent tests from being affected by developer's shell config.
fn snapshot_switch(test_name: &str, repo: &TestRepo, args: &[&str]) {
// Create isolated HOME to ensure test determinism
- let temp_home = TempDir::new().unwrap();
+ let temp_home = worktrunk::testing::tempdir().unwrap();
let settings = setup_snapshot_settings(repo);
settings.bind(|| {
@@ -67,7 +66,7 @@ approved-commands = ["echo ran > marker.txt"]
"#,
);
- let temp_home = TempDir::new().unwrap();
+ let temp_home = worktrunk::testing::tempdir().unwrap();
let mut cmd = repo.wt_command();
cmd.args(["switch", "--create", "feature"])
.current_dir(repo.root_path());
@@ -120,7 +119,7 @@ approved-commands = [
// Table-form commands run concurrently with prefixed output;
// WORKTRUNK_TEST_SERIAL_CONCURRENT pins the line order for the snapshot.
- let temp_home = TempDir::new().unwrap();
+ let temp_home = worktrunk::testing::tempdir().unwrap();
let settings = setup_snapshot_settings(&repo);
settings.bind(|| {
let mut cmd = make_snapshot_cmd(&repo, "switch", &["--create", "feature"], None);
@@ -257,7 +256,7 @@ approved-commands = [
);
// Create isolated HOME to ensure test determinism
- let temp_home = tempfile::TempDir::new().unwrap();
+ let temp_home = worktrunk::testing::tempdir().unwrap();
let settings = setup_snapshot_settings(&repo);
settings.bind(|| {
@@ -563,7 +562,7 @@ approved-commands = ["cat > captured.txt"]
// Create worktree, piping a sentinel to wt's stdin. The pre-start hook
// inherits that stdin, so `cat` captures the sentinel verbatim.
- let temp_home = TempDir::new().unwrap();
+ let temp_home = worktrunk::testing::tempdir().unwrap();
let mut cmd = wt_command();
cmd.args(["switch", "--create", "feature-stdin"])
.current_dir(repo.root_path())
@@ -659,7 +658,7 @@ approved-commands = ["{command}"]
));
// Create worktree
- let temp_home = TempDir::new().unwrap();
+ let temp_home = worktrunk::testing::tempdir().unwrap();
let mut cmd = wt_command();
cmd.args(["switch", "--create", "feature-script"])
.current_dir(repo.root_path())
@@ -727,7 +726,7 @@ approved-commands = ["{command}"]
));
// Create worktree
- let temp_home = TempDir::new().unwrap();
+ let temp_home = worktrunk::testing::tempdir().unwrap();
let mut cmd = wt_command();
cmd.args(["switch", "--create", "bg-stdin"])
.current_dir(repo.root_path())
@@ -1590,7 +1589,7 @@ approved-commands = [
"#,
);
- let temp_home = TempDir::new().unwrap();
+ let temp_home = worktrunk::testing::tempdir().unwrap();
let mut cmd = make_snapshot_cmd(&repo, "switch", &["--create", "feature"], None);
cmd.env("WORKTRUNK_TEST_SERIAL_CONCURRENT", "1");
set_temp_home_env(&mut cmd, temp_home.path());
@@ -1629,7 +1628,7 @@ approved-commands = [
"#,
);
- let temp_home = TempDir::new().unwrap();
+ let temp_home = worktrunk::testing::tempdir().unwrap();
let mut cmd = make_snapshot_cmd(&repo, "switch", &["--create", "feature"], None);
cmd.env("WORKTRUNK_TEST_SERIAL_CONCURRENT", "1");
set_temp_home_env(&mut cmd, temp_home.path());
diff --git a/tests/integration_tests/remove.rs b/tests/integration_tests/remove.rs
index c09e5782e..002218a5f 100644
--- a/tests/integration_tests/remove.rs
+++ b/tests/integration_tests/remove.rs
@@ -4715,7 +4715,7 @@ fn test_remove_leaves_entries_to_the_running_drain(mut repo: TestRepo) {
/// fails and deletes nothing, however the directory's entries are named.
#[rstest]
fn test_drain_trash_derives_the_trash_from_the_repository(repo: TestRepo) {
- let outside = tempfile::tempdir().unwrap();
+ let outside = worktrunk::testing::tempdir().unwrap();
let lookalike = outside.path().join("backup-2024");
fs::create_dir(&lookalike).unwrap();
let output = repo
@@ -4820,7 +4820,7 @@ fn test_remove_resolves_all_fsmonitor_daemons_in_one_lsof(mut repo: TestRepo) {
// Outside the repo: a call log written under `bin_dir` (which lives at
// `<repo>/.bin`) would leave an untracked file in the working tree the
// command under test is inspecting.
- let call_log = tempfile::tempdir().unwrap();
+ let call_log = worktrunk::testing::tempdir().unwrap();
repo.add_worktree("feature-fsmon");
let output = repo
@@ -4896,7 +4896,7 @@ fn test_remove_sweep_skips_lsof_when_no_daemon_pids(mut repo: TestRepo) {
paths.insert(0, bin_dir.clone());
let new_path = std::env::join_paths(&paths).unwrap();
- let call_log = tempfile::tempdir().unwrap();
+ let call_log = worktrunk::testing::tempdir().unwrap();
repo.add_worktree("feature-fsmon");
let output = repo
diff --git a/tests/integration_tests/shell_integration_prompt.rs b/tests/integration_tests/shell_integration_prompt.rs
index fb99bdc1e..ba833cfd6 100644
--- a/tests/integration_tests/shell_integration_prompt.rs
+++ b/tests/integration_tests/shell_integration_prompt.rs
@@ -321,7 +321,7 @@ fn test_switch_stops_after_cancelled_powershell_query(
.command("_default", MockResponse::output("[]\n"))
.write(mock_bin);
- let call_log = tempfile::TempDir::new().unwrap();
+ let call_log = worktrunk::testing::tempdir().unwrap();
let mut cmd = repo.wt_command();
cmd.env("WORKTRUNK_TEST_PARENT_SHELL", "pwsh")
.env("WORKTRUNK_TEST_MOCK_CALL_LOG_DIR", call_log.path())
@@ -361,7 +361,7 @@ fn test_switch_hint_skips_shell_config_scan(mut repo: TestRepo) {
.write(mock_bin);
}
- let call_log = tempfile::TempDir::new().unwrap();
+ let call_log = worktrunk::testing::tempdir().unwrap();
let mut cmd = repo.wt_command();
cmd.env("WORKTRUNK_TEST_PARENT_SHELL", "zsh")
.env("WORKTRUNK_TEST_MOCK_CALL_LOG_DIR", call_log.path())
@@ -385,7 +385,7 @@ fn test_switch_continues_after_failed_shell_scan(repo: TestRepo) {
use crate::common::set_temp_home_env;
use std::os::unix::process::CommandExt;
- let temp_home = tempfile::TempDir::new().unwrap();
+ let temp_home = worktrunk::testing::tempdir().unwrap();
fs::create_dir(temp_home.path().join(".bashrc")).unwrap();
let marker = repo.root_path().join("executed");
@@ -417,7 +417,6 @@ mod pty_tests {
use crate::common::{add_pty_filters, setup_snapshot_settings, wt_bin};
use insta::assert_snapshot;
use std::path::Path;
- use tempfile::TempDir;
/// Create insta settings for shell integration prompt PTY tests.
///
@@ -449,7 +448,7 @@ mod pty_tests {
#[rstest]
fn test_already_installed_skips_prompt(repo: TestRepo) {
// Create isolated HOME with shell config that already has integration
- let temp_home = TempDir::new().unwrap();
+ let temp_home = worktrunk::testing::tempdir().unwrap();
let bashrc = temp_home.path().join(".bashrc");
let config_line = "if command -v wt >/dev/null 2>&1; then eval \"$(command wt config shell init bash)\"; fi";
fs::write(&bashrc, format!("{config_line}\n")).unwrap();
@@ -494,7 +493,7 @@ mod pty_tests {
#[rstest]
fn test_user_declines_prompt(repo: TestRepo) {
// Create isolated HOME with empty shell config
- let temp_home = TempDir::new().unwrap();
+ let temp_home = worktrunk::testing::tempdir().unwrap();
let bashrc = temp_home.path().join(".bashrc");
fs::write(&bashrc, "# empty bashrc\n").unwrap();
@@ -561,7 +560,7 @@ mod pty_tests {
) {
use std::os::unix::fs::PermissionsExt;
- let temp_home = TempDir::new().unwrap();
+ let temp_home = worktrunk::testing::tempdir().unwrap();
fs::write(temp_home.path().join(".bashrc"), "# empty bashrc\n").unwrap();
let bin_dir = temp_home.path().join("bin");
fs::create_dir_all(&bin_dir).unwrap();
@@ -601,7 +600,7 @@ mod pty_tests {
#[rstest]
fn test_user_accepts_prompt(repo: TestRepo) {
// Create isolated HOME with empty shell config
- let temp_home = TempDir::new().unwrap();
+ let temp_home = worktrunk::testing::tempdir().unwrap();
let bashrc = temp_home.path().join(".bashrc");
fs::write(&bashrc, "# empty bashrc\n").unwrap();
@@ -655,7 +654,7 @@ mod pty_tests {
#[rstest]
fn test_prompt_reports_shell_that_fails_after_confirmation(repo: TestRepo) {
- let temp_home = TempDir::new().unwrap();
+ let temp_home = worktrunk::testing::tempdir().unwrap();
let bashrc = temp_home.path().join(".bashrc");
let zshrc = temp_home.path().join(".zshrc");
fs::write(&bashrc, "# bash config\n").unwrap();
@@ -689,7 +688,7 @@ mod pty_tests {
#[rstest]
fn test_prompt_installs_other_shells_when_bashrc_is_invalid(repo: TestRepo) {
- let temp_home = TempDir::new().unwrap();
+ let temp_home = worktrunk::testing::tempdir().unwrap();
let bashrc = temp_home.path().join(".bashrc");
let zshrc = temp_home.path().join(".zshrc");
let invalid_bashrc = b"\xff\xfe#\0 \0t\0e\0s\0t\0\n\0";
@@ -725,7 +724,7 @@ mod pty_tests {
repo: TestRepo,
#[case] created_after_preview: bool,
) {
- let temp_home = TempDir::new().unwrap();
+ let temp_home = worktrunk::testing::tempdir().unwrap();
fs::write(temp_home.path().join(".bashrc"), "# empty bashrc\n").unwrap();
fs::create_dir_all(temp_home.path().join(".config/fish/functions")).unwrap();
@@ -764,7 +763,7 @@ mod pty_tests {
#[rstest]
fn test_user_requests_preview_then_declines(repo: TestRepo) {
// Create isolated HOME with empty shell config
- let temp_home = TempDir::new().unwrap();
+ let temp_home = worktrunk::testing::tempdir().unwrap();
let bashrc = temp_home.path().join(".bashrc");
fs::write(&bashrc, "# empty bashrc\n").unwrap();
@@ -826,7 +825,7 @@ mod pty_tests {
/// removal — otherwise `wt switch` deletes a file the prompt never mentioned.
#[rstest]
fn test_first_run_offer_previews_legacy_removal(repo: TestRepo) {
- let temp_home = TempDir::new().unwrap();
+ let temp_home = worktrunk::testing::tempdir().unwrap();
// bash: unconfigured (empty rc) → current shell not installed → offer fires.
let bashrc = temp_home.path().join(".bashrc");
@@ -889,7 +888,7 @@ mod pty_tests {
#[rstest]
fn test_no_prompt_after_first_prompt(repo: TestRepo) {
// Create isolated HOME with empty shell config
- let temp_home = TempDir::new().unwrap();
+ let temp_home = worktrunk::testing::tempdir().unwrap();
let bashrc = temp_home.path().join(".bashrc");
fs::write(&bashrc, "# empty bashrc\n").unwrap();
@@ -936,7 +935,6 @@ mod commit_generation_prompt_tests {
use crate::common::wt_bin;
use std::os::unix::fs::PermissionsExt;
use std::path::{Path, PathBuf};
- use tempfile::TempDir;
fn setup_fake_tool(temp_home: &Path, tool: &str) -> PathBuf {
// Create a fake LLM executable that does nothing
@@ -974,7 +972,7 @@ mod commit_generation_prompt_tests {
/// Test: No LLM tool available, prompt is skipped and skip flag is set
#[rstest]
fn test_no_llm_tool_sets_skip_flag(repo: TestRepo) {
- let temp_home = TempDir::new().unwrap();
+ let temp_home = worktrunk::testing::tempdir().unwrap();
// Stage a change so commit has something to do
let test_file = repo.root_path().join("test.txt");
@@ -1010,7 +1008,7 @@ mod commit_generation_prompt_tests {
/// Test: LLM tool available, user declines prompt
#[rstest]
fn test_user_declines_llm_prompt(repo: TestRepo) {
- let temp_home = TempDir::new().unwrap();
+ let temp_home = worktrunk::testing::tempdir().unwrap();
let bin_dir = setup_fake_tool(temp_home.path(), "claude");
// Stage a change
@@ -1051,7 +1049,7 @@ mod commit_generation_prompt_tests {
/// Test: LLM tool available, user accepts prompt
#[rstest]
fn test_user_accepts_llm_prompt(repo: TestRepo) {
- let temp_home = TempDir::new().unwrap();
+ let temp_home = worktrunk::testing::tempdir().unwrap();
let bin_dir = setup_fake_tool(temp_home.path(), "claude");
// Stage a change
@@ -1091,7 +1089,7 @@ mod commit_generation_prompt_tests {
#[rstest]
fn test_user_accepts_codex_prompt(repo: TestRepo) {
- let temp_home = TempDir::new().unwrap();
+ let temp_home = worktrunk::testing::tempdir().unwrap();
let output = run_codex_prompt(&repo, temp_home.path(), &["y\n"]);
assert!(output.contains("Added to user config"), "{output}");
@@ -1115,7 +1113,7 @@ mod commit_generation_prompt_tests {
#[rstest]
fn test_codex_preview_then_decline_does_not_create_instructions(repo: TestRepo) {
- let temp_home = TempDir::new().unwrap();
+ let temp_home = worktrunk::testing::tempdir().unwrap();
let output = run_codex_prompt(&repo, temp_home.path(), &["?\n", "n\n"]);
assert!(
@@ -1134,7 +1132,7 @@ mod commit_generation_prompt_tests {
#[rstest]
fn test_codex_prompt_reuses_existing_instructions(repo: TestRepo) {
- let temp_home = TempDir::new().unwrap();
+ let temp_home = worktrunk::testing::tempdir().unwrap();
let instructions = temp_home
.path()
.join(".codex/worktrunk-commit-instructions.txt");
@@ -1158,7 +1156,7 @@ mod commit_generation_prompt_tests {
#[rstest]
fn test_codex_prompt_file_creation_failure_does_not_save_command(repo: TestRepo) {
- let temp_home = TempDir::new().unwrap();
+ let temp_home = worktrunk::testing::tempdir().unwrap();
fs::write(temp_home.path().join(".codex"), "not a directory").unwrap();
let output = run_codex_prompt(&repo, temp_home.path(), &["y\n"]);
@@ -1175,7 +1173,7 @@ mod commit_generation_prompt_tests {
/// Test: User requests preview (?)
#[rstest]
fn test_user_requests_preview(repo: TestRepo) {
- let temp_home = TempDir::new().unwrap();
+ let temp_home = worktrunk::testing::tempdir().unwrap();
let bin_dir = setup_fake_tool(temp_home.path(), "claude");
// Stage a change
@@ -1213,7 +1211,7 @@ mod commit_generation_prompt_tests {
/// hint, which names the resolved path via `config_path_for_display`.
#[rstest]
fn test_user_accepts_but_save_fails_shows_manual_hint(repo: TestRepo) {
- let temp_home = TempDir::new().unwrap();
+ let temp_home = worktrunk::testing::tempdir().unwrap();
let bin_dir = setup_fake_tool(temp_home.path(), "claude");
// Stage a change
diff --git a/tests/integration_tests/shell_powershell.rs b/tests/integration_tests/shell_powershell.rs
index 35f1d1338..a5189a9aa 100644
--- a/tests/integration_tests/shell_powershell.rs
+++ b/tests/integration_tests/shell_powershell.rs
@@ -79,7 +79,7 @@ if ($cmd -and $cmd.CommandType -eq 'Function') {{
fn test_powershell_wrapper_passes_short_flags_through() {
// Create a .ps1 mock that prints each argument on its own line.
// Using .ps1 (not a shell script) so this works on Windows too.
- let temp_dir = tempfile::tempdir().unwrap();
+ let temp_dir = worktrunk::testing::tempdir().unwrap();
let mock_bin = temp_dir.path().join("mock-wt.ps1");
std::fs::write(&mock_bin, "foreach ($a in $args) { Write-Output $a }\n").unwrap();
@@ -136,7 +136,7 @@ wt remove -D test --force
/// `return $null` emitted nothing, hiding the bug.
#[test]
fn test_powershell_wrapper_no_stray_exit_code_on_stdout() {
- let temp_dir = tempfile::tempdir().unwrap();
+ let temp_dir = worktrunk::testing::tempdir().unwrap();
let mock_bin = temp_dir.path().join("mock-wt.ps1");
// Emit a single distinctive line, then exit 0 like a real native binary.
std::fs::write(&mock_bin, "Write-Output 'MOCK_OUTPUT_LINE'\nexit 0\n").unwrap();
diff --git a/tests/integration_tests/shell_wrapper.rs b/tests/integration_tests/shell_wrapper.rs
index a96b2f41f..5a0c2d93a 100644
--- a/tests/integration_tests/shell_wrapper.rs
+++ b/tests/integration_tests/shell_wrapper.rs
@@ -514,7 +514,7 @@ fn exec_bash_truly_interactive(
use std::time::{Duration, Instant};
// Write setup script to a temp file
- let tmp_dir = tempfile::tempdir().unwrap();
+ let tmp_dir = worktrunk::testing::tempdir().unwrap();
let script_path = tmp_dir.path().join("setup.sh");
fs::write(&script_path, setup_script).unwrap();
@@ -899,7 +899,7 @@ mod unix_tests {
// also make the test less faithful to the platform it stands in for:
// Windows takes the `$nu.os-info.family` branch, where cleanup uses the
// nushell builtin and does run.
- let bin_dir = tempfile::tempdir().unwrap();
+ let bin_dir = worktrunk::testing::tempdir().unwrap();
for tool in ["nu", "git", "rm", "printf"] {
let resolved = which::which(tool)
.unwrap_or_else(|e| panic!("{tool} must be installed to run tests: {e}"));
@@ -1043,7 +1043,7 @@ mod unix_tests {
fn test_nu_wrapper_cleanup_survives_rm_alias(repo: TestRepo) {
// A dedicated TMPDIR so the wrapper's `mktemp` files are the only
// occupants, and a leak is directly observable.
- let tmp = tempfile::tempdir().unwrap();
+ let tmp = worktrunk::testing::tempdir().unwrap();
let tmp_path = tmp.path().to_string_lossy().to_string();
let mut script = String::new();
@@ -1237,7 +1237,7 @@ mod unix_tests {
fn test_nu_wrapper_execute_failure_runs_cleanup(repo: TestRepo) {
// A dedicated TMPDIR so the wrapper's `mktemp` files are the only
// occupants and a leak is directly observable.
- let tmp = tempfile::tempdir().unwrap();
+ let tmp = worktrunk::testing::tempdir().unwrap();
let tmp_path = tmp.path().to_string_lossy().to_string();
let mut script = String::new();
@@ -1277,7 +1277,7 @@ mod unix_tests {
#[rstest]
fn test_nu_wrapper_cd_failure_runs_cleanup(repo: TestRepo) {
use std::os::unix::fs::PermissionsExt;
- let tmp = tempfile::tempdir().unwrap();
+ let tmp = worktrunk::testing::tempdir().unwrap();
let executable = repo.root_path().join("invalid-directive");
fs::write(
&executable,
@@ -1334,7 +1334,7 @@ mod unix_tests {
fn test_nu_wrapper_signal_status_runs_cleanup(mut repo: TestRepo) {
repo.add_worktree("nu-signal");
let target = canonicalize(repo.worktree_path("nu-signal")).unwrap();
- let tmp = tempfile::tempdir().unwrap();
+ let tmp = worktrunk::testing::tempdir().unwrap();
let tmp_path = tmp.path().to_string_lossy().to_string();
let mut script = String::new();
append_wrapper_setup(&mut script, "nu", &repo);
@@ -3276,7 +3276,7 @@ fi
/// PATH override. `/etc/zshenv` is always sourced and cannot be bypassed,
/// but it doesn't typically touch PATH on the environments we care about.
fn completion_test_path(wt_bin: &std::path::Path) -> (tempfile::TempDir, String) {
- let dir = tempfile::tempdir().unwrap();
+ let dir = worktrunk::testing::tempdir().unwrap();
std::os::unix::fs::symlink(wt_bin, dir.path().join("wt")).unwrap();
// Only include the symlink dir + essential system dirs. This prevents
// any user-installed `wt-*` binaries (e.g. ~/.cargo/bin/wt-sync) or
@@ -3550,7 +3550,7 @@ for c in "${{COMPREPLY[@]}}"; do echo "${{c%% *}}"; done
let wt_bin_dir = wt_bin.parent().unwrap();
// Create a temp file for the redirect target
- let tmp_dir = tempfile::tempdir().unwrap();
+ let tmp_dir = worktrunk::testing::tempdir().unwrap();
let redirect_file = tmp_dir.path().join("subprocess.log");
let redirect_path = redirect_file.display().to_string();
@@ -3678,7 +3678,7 @@ echo "SCRIPT_COMPLETED"
let wt_bin_dir = wt_bin.parent().unwrap();
// Create temp dir for marker file and pager script
- let tmp_dir = tempfile::tempdir().unwrap();
+ let tmp_dir = worktrunk::testing::tempdir().unwrap();
let marker_file = tmp_dir.path().join("pager_invoked.marker");
let pager_script = tmp_dir.path().join("test_pager.sh");
@@ -3846,7 +3846,7 @@ mod windows_tests {
use crate::common::pty::{build_pty_command, exec_cmd_in_pty};
// Use cmd.exe for simplest possible test
- let tmp = tempfile::tempdir().unwrap();
+ let tmp = worktrunk::testing::tempdir().unwrap();
let cmd = build_pty_command(
"cmd.exe",
&["/C", "echo CONPTY_WORKS"],
@@ -3876,7 +3876,7 @@ mod windows_tests {
use crate::common::wt_bin;
let wt_bin = wt_bin();
- let tmp = tempfile::tempdir().unwrap();
+ let tmp = worktrunk::testing::tempdir().unwrap();
let cmd = build_pty_command(
wt_bin.to_str().unwrap(),
@@ -3924,7 +3924,7 @@ mod windows_tests {
cmd.arg("-Command");
cmd.arg("Write-Host 'POWERSHELL_WORKS'; exit 42");
- let tmp = tempfile::tempdir().unwrap();
+ let tmp = worktrunk::testing::tempdir().unwrap();
cmd.cwd(tmp.path());
crate::common::pass_coverage_env_to_pty_cmd(&mut cmd);
diff --git a/tests/integration_tests/step_copy_ignored.rs b/tests/integration_tests/step_copy_ignored.rs
index c0283c742..21fd09a50 100644
--- a/tests/integration_tests/step_copy_ignored.rs
+++ b/tests/integration_tests/step_copy_ignored.rs
@@ -988,7 +988,7 @@ fn setup_copy_ignored_symlinked_dest_dir(repo: &mut TestRepo) -> (PathBuf, tempf
fs::write(repo.root_path().join(".gitignore"), "target/\n").unwrap();
fs::write(repo.root_path().join(".worktreeinclude"), "target/\n").unwrap();
- let outside = tempfile::tempdir().unwrap();
+ let outside = worktrunk::testing::tempdir().unwrap();
let outside_target = outside.path().join("target");
fs::create_dir_all(&outside_target).unwrap();
fs::write(outside_target.join("sentinel"), "keep me").unwrap();
diff --git a/tests/integration_tests/step_promote.rs b/tests/integration_tests/step_promote.rs
index ef7763ad4..4b1d2d731 100644
--- a/tests/integration_tests/step_promote.rs
+++ b/tests/integration_tests/step_promote.rs
@@ -346,7 +346,7 @@ fn test_promote_bare_repo_no_worktrees() {
/// Test error when run in a bare repository with worktrees
#[test]
fn test_promote_bare_repo_with_worktrees() {
- let temp_dir = tempfile::tempdir().unwrap();
+ let temp_dir = worktrunk::testing::tempdir().unwrap();
let bare_repo = temp_dir.path().join("bare.git");
let worktree_path = temp_dir.path().join("worktree");
let temp_clone = temp_dir.path().join("temp");
diff --git a/tests/integration_tests/step_relocate.rs b/tests/integration_tests/step_relocate.rs
index 0b175c8d4..1d4bfff73 100644
--- a/tests/integration_tests/step_relocate.rs
+++ b/tests/integration_tests/step_relocate.rs
@@ -1695,7 +1695,7 @@ fn test_relocate_current_with_retired_wrapper_warns(repo: TestRepo) {
wrong_path.to_str().unwrap(),
]);
- let directive_dir = tempfile::TempDir::new().unwrap();
+ let directive_dir = worktrunk::testing::tempdir().unwrap();
let retired_path = directive_dir.path().join("directive");
fs::write(&retired_path, "").unwrap();
diff --git a/tests/integration_tests/switch.rs b/tests/integration_tests/switch.rs
index 65d9f11d0..5773c15fd 100644
--- a/tests/integration_tests/switch.rs
+++ b/tests/integration_tests/switch.rs
@@ -2527,7 +2527,7 @@ fn test_switch_execute_stdin_inheritance(repo: TestRepo) {
#[rstest]
fn test_switch_outside_git_repo(temp_home: TempDir) {
- let temp_dir = tempfile::tempdir().unwrap();
+ let temp_dir = worktrunk::testing::tempdir().unwrap();
// Run wt switch --create outside a git repo - should show "Failed to switch worktree" context
let settings = setup_home_snapshot_settings(&temp_home);
@@ -3038,7 +3038,7 @@ worktree-path = "{{ repo_path }}/../from-project-{{ branch | sanitize }}"
// The rule is the same one layer down, where no invocation is involved:
// with the entry moved to the system file, the user file's global key
// answers for this repo. Written last because it rewrites the user config.
- let system_dir = tempfile::tempdir().unwrap();
+ let system_dir = worktrunk::testing::tempdir().unwrap();
let system_config = system_dir.path().join("config.toml");
fs::write(
&system_config,
@@ -3913,7 +3913,7 @@ fn test_switch_pr_fork(#[from(repo_with_remote)] repo: TestRepo) {
.command("config get git_protocol", MockResponse::output("ssh\n"))
.command("_default", MockResponse::exit(1))
.write(&mock_bin);
- let call_log = tempfile::tempdir().unwrap();
+ let call_log = worktrunk::testing::tempdir().unwrap();
let settings = setup_snapshot_settings(&repo);
settings.bind(|| {
@@ -6429,7 +6429,7 @@ fn test_switch_pr_self_hosted_tea_authed_dispatches_to_gitea(
)
.command("_default", MockResponse::exit(1))
.write(&mock_bin);
- let call_log = tempfile::tempdir().unwrap();
+ let call_log = worktrunk::testing::tempdir().unwrap();
let settings = setup_snapshot_settings(&repo);
settings.bind(|| {
@@ -6512,7 +6512,7 @@ fn test_switch_pr_self_hosted_defaults_to_github(
}
#[cfg(unix)]
std::os::unix::fs::symlink(which::which("git").unwrap(), mock_bin.join("git")).unwrap();
- let call_log = tempfile::tempdir().unwrap();
+ let call_log = worktrunk::testing::tempdir().unwrap();
let settings = setup_snapshot_settings(&repo);
settings.bind(|| {
@@ -6558,7 +6558,7 @@ fn test_switch_pr_tea_login_matches_distinct_ssh_host(repo: TestRepo) {
MockConfig::new("gh")
.command("_default", MockResponse::exit(1))
.write(&mock_bin);
- let call_log = tempfile::tempdir().unwrap();
+ let call_log = worktrunk::testing::tempdir().unwrap();
let mut cmd = repo.wt_command();
configure_mock_cli_env(&mut cmd, &mock_bin);
let output = cmd
@@ -6615,7 +6615,7 @@ fn test_switch_pr_tea_login_native_interruption(
MockConfig::new("gh")
.command("_default", MockResponse::exit(1))
.write(&mock_bin);
- let call_log = tempfile::tempdir().unwrap();
+ let call_log = worktrunk::testing::tempdir().unwrap();
let mut cmd = repo.wt_command();
configure_mock_cli_env(&mut cmd, &mock_bin);
let output = cmd
@@ -8072,7 +8072,7 @@ fn test_switch_mr_fork(#[from(repo_with_remote)] repo: TestRepo) {
.command("_default", MockResponse::exit(1))
.write(&mock_bin);
- let call_log = tempfile::tempdir().unwrap();
+ let call_log = worktrunk::testing::tempdir().unwrap();
let settings = setup_snapshot_settings(&repo);
settings.bind(|| {
let mut cmd = make_snapshot_cmd(&repo, "switch", &["mr:42"], None);
diff --git a/tests/integration_tests/switch_picker.rs b/tests/integration_tests/switch_picker.rs
index e8bfb43fe..328e5a27d 100644
--- a/tests/integration_tests/switch_picker.rs
+++ b/tests/integration_tests/switch_picker.rs
@@ -1317,7 +1317,7 @@ fn test_switch_picker_open_url_keeps_launcher_output_out_of_terminal(
)
.write(&mock_bin);
}
- let call_log = tempfile::tempdir().unwrap();
+ let call_log = worktrunk::testing::tempdir().unwrap();
let mut env_vars = forge_mock_env_vars(&repo, &mock_bin);
env_vars.push((
"WORKTRUNK_TEST_MOCK_CALL_LOG_DIR".into(),
@@ -1703,7 +1703,7 @@ fn test_switch_picker_preview_auto_refreshes_when_compute_lands(repo: TestRepo)
.command("_default", MockResponse::exit(1))
.write(&mock_bin);
let release = MockReleaseGate::new(mock_bin.join("comments.release"));
- let call_log = tempfile::tempdir().unwrap();
+ let call_log = worktrunk::testing::tempdir().unwrap();
let mut env_vars = forge_mock_env_vars(&repo, &mock_bin);
env_vars.push((
"WORKTRUNK_TEST_MOCK_CALL_LOG_DIR".to_string(),
@@ -2043,7 +2043,7 @@ fn test_switch_picker_pre_switch_hook_requires_approval(mut repo: TestRepo) {
// Project `pre-switch` hook (in `.config/wt.toml`, so it routes through the
// approval gate) that touches a marker outside the worktree if it runs.
- let marker_dir = tempfile::tempdir().unwrap();
+ let marker_dir = worktrunk::testing::tempdir().unwrap();
let marker = marker_dir.path().join("pre-switch-ran");
repo.write_project_config(&format!(
"pre-switch = {:?}\n",
diff --git a/tests/integration_tests/switch_picker_dry_run.rs b/tests/integration_tests/switch_picker_dry_run.rs
index 8fc0d9158..ada0c0f6b 100644
--- a/tests/integration_tests/switch_picker_dry_run.rs
+++ b/tests/integration_tests/switch_picker_dry_run.rs
@@ -65,7 +65,7 @@ fn test_picker_dry_run_emits_configured_rows_and_cache_json(
repo.write_test_config("[list]\nbranches = true\n");
install_summary_probe(&mut repo);
- let call_log = tempfile::tempdir().unwrap();
+ let call_log = worktrunk::testing::tempdir().unwrap();
let mut cmd = repo.wt_command();
// No `--branches`: the config setting must drive branch collection.
@@ -352,7 +352,7 @@ fn test_picker_dry_run_prs_routes_to_gitlab(#[from(main_only_repo)] mut repo: Te
// Keep observability outside the repository: writing the call log into the
// worktree would perturb the status being collected by the picker.
- let call_log = tempfile::tempdir().unwrap();
+ let call_log = worktrunk::testing::tempdir().unwrap();
let output = repo
.wt_command()
.args(["switch", "--prs"])
@@ -515,7 +515,7 @@ fn test_picker_dry_run_drains_stashed_warnings(mut repo: TestRepo) {
fn test_picker_dry_run_with_summary(mut repo: TestRepo) {
repo.add_worktree("feature-a");
install_summary_probe(&mut repo);
- let call_log = tempfile::tempdir().unwrap();
+ let call_log = worktrunk::testing::tempdir().unwrap();
let output = repo
.wt_command()
diff --git a/tests/integration_tests/version_build.rs b/tests/integration_tests/version_build.rs
index ab8a7c40e..d66423c13 100644
--- a/tests/integration_tests/version_build.rs
+++ b/tests/integration_tests/version_build.rs
@@ -114,7 +114,7 @@ fn crate_io_archive_builds_and_versions_without_git() {
assert!(crate_file.exists(), "expected archive at {crate_file:?}");
// 2. Extract into a temp dir that has no ancestor `.git`.
- let temp = tempfile::tempdir().expect("create tempdir");
+ let temp = worktrunk::testing::tempdir().expect("create tempdir");
let untar = Command::new("tar")
.arg("xzf")
.arg(&crate_file)