Skip to content

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

refactor: Standardize CLI command setup for tests

Maximilian Roos81ace9ff039c
diff --git a/tests/common/mod.rs b/tests/common/mod.rs
index 4b1e487e9..18d499cc9 100644
--- a/tests/common/mod.rs
+++ b/tests/common/mod.rs
@@ -25,11 +25,47 @@
// Test utilities are Unix-only since integration tests are Unix-only
#![cfg(unix)]
+use insta_cmd::get_cargo_bin;
use std::collections::HashMap;
use std::path::{Path, PathBuf};
use std::process::Command;
use tempfile::TempDir;
+/// Create a `wt` CLI command with standardized test environment settings.
+///
+/// The command has the following guarantees:
+/// - All host `GIT_*` and `WORKTRUNK_*` variables are cleared
+/// - Color output is forced (`CLICOLOR_FORCE=1`) so ANSI styling appears in snapshots
+/// - Terminal width defaults to 150 columns when `COLUMNS` is not already set
+pub fn wt_command() -> Command {
+ let mut cmd = Command::new(get_cargo_bin("wt"));
+ configure_cli_command(&mut cmd);
+ cmd
+}
+
+/// Configure an existing command with the standardized worktrunk CLI environment.
+///
+/// This helper mirrors the environment preparation performed by `wt_command`
+/// and is intended for cases where tests need to construct the command manually
+/// (e.g., to execute shell pipelines).
+pub fn configure_cli_command(cmd: &mut Command) {
+ for (key, _) in std::env::vars() {
+ if key.starts_with("GIT_") || key.starts_with("WORKTRUNK_") {
+ cmd.env_remove(&key);
+ }
+ }
+ cmd.env("CLICOLOR_FORCE", "1");
+ if std::env::var("COLUMNS").is_err() {
+ cmd.env("COLUMNS", "150");
+ }
+}
+
+/// Set `HOME` and `XDG_CONFIG_HOME` for commands that rely on isolated temp homes.
+pub fn set_temp_home_env(cmd: &mut Command, home: &Path) {
+ cmd.env("HOME", home);
+ cmd.env("XDG_CONFIG_HOME", home.join(".config"));
+}
+
pub struct TestRepo {
temp_dir: TempDir, // Must keep to ensure cleanup on drop
root: PathBuf,
@@ -134,23 +170,12 @@ impl TestRepo {
/// This also sets `WORKTRUNK_CONFIG_PATH` to an isolated test config
/// to prevent tests from polluting the user's real config file.
pub fn clean_cli_env(&self, cmd: &mut Command) {
- // Remove git-related env vars that might interfere
- for (key, _) in std::env::vars() {
- if key.starts_with("GIT_") || key.starts_with("WORKTRUNK_") {
- cmd.env_remove(&key);
- }
- }
- // Set deterministic environment for git
+ configure_cli_command(cmd);
self.configure_git_cmd(cmd);
- // Force color output for snapshot testing (captures ANSI codes)
- cmd.env("CLICOLOR_FORCE", "1");
// Set isolated config path to prevent polluting user's config
cmd.env("WORKTRUNK_CONFIG_PATH", &self.test_config_path);
// Set consistent terminal width for stable snapshot output
// (can be overridden by individual tests that want to test specific widths)
- if std::env::var("COLUMNS").is_err() {
- cmd.env("COLUMNS", "150");
- }
// NOTE: We don't set PATH here. Tests inherit PATH from the test runner,
// which allows them to find git, shells, etc. Since we don't explicitly set it,
// insta-cmd won't capture it in snapshots, avoiding privacy leaks.
diff --git a/tests/integration_tests/bare_repository.rs b/tests/integration_tests/bare_repository.rs
index 05f2e91d3..8bf144a1e 100644
--- a/tests/integration_tests/bare_repository.rs
+++ b/tests/integration_tests/bare_repository.rs
@@ -1,5 +1,5 @@
-use crate::common::TestRepo;
-use insta_cmd::{assert_cmd_snapshot, get_cargo_bin};
+use crate::common::{TestRepo, wt_command};
+use insta_cmd::assert_cmd_snapshot;
use std::fs;
use std::path::PathBuf;
use std::process::Command;
@@ -168,7 +168,7 @@ fn test_bare_repo_list_worktrees() {
test.commit_in_worktree(&feature_worktree, "Work on feature");
// Run wt list from the main worktree
- let mut cmd = Command::new(get_cargo_bin("wt"));
+ let mut cmd = wt_command();
test.configure_wt_cmd(&mut cmd);
cmd.arg("list").current_dir(&main_worktree);
@@ -184,7 +184,7 @@ fn test_bare_repo_list_shows_no_bare_entry() {
test.commit_in_worktree(&main_worktree, "Initial commit");
// Run wt list and verify bare repo is NOT shown
- let mut cmd = Command::new(get_cargo_bin("wt"));
+ let mut cmd = wt_command();
test.configure_wt_cmd(&mut cmd);
cmd.arg("list").current_dir(&main_worktree);
@@ -212,7 +212,7 @@ worktree-path = "{branch}"
fs::write(test.config_path(), config).expect("Failed to write config");
// Run wt switch --create to create a new worktree
- let mut cmd = Command::new(get_cargo_bin("wt"));
+ let mut cmd = wt_command();
test.configure_wt_cmd(&mut cmd);
cmd.args(["switch", "--create", "feature", "--internal"])
.current_dir(&main_worktree);
@@ -283,7 +283,7 @@ fn test_bare_repo_switch_with_default_naming() {
// Use default naming pattern (should still work with bare repos)
// Default is "../{main-worktree}.{branch}" which becomes "test-repo.git.feature"
- let mut cmd = Command::new(get_cargo_bin("wt"));
+ let mut cmd = wt_command();
test.configure_wt_cmd(&mut cmd);
cmd.args(["switch", "--create", "feature", "--internal"])
.current_dir(&main_worktree);
@@ -320,7 +320,7 @@ fn test_bare_repo_remove_worktree() {
test.commit_in_worktree(&feature_worktree, "Feature work");
// Remove feature worktree from main worktree
- let mut cmd = Command::new(get_cargo_bin("wt"));
+ let mut cmd = wt_command();
test.configure_wt_cmd(&mut cmd);
cmd.args(["remove", "feature", "--internal"])
.current_dir(&main_worktree);
@@ -357,7 +357,7 @@ fn test_bare_repo_identifies_primary_correctly() {
let _feature2 = test.create_worktree("feature2", "test-repo.feature2");
// Run wt list to see which is marked as primary
- let mut cmd = Command::new(get_cargo_bin("wt"));
+ let mut cmd = wt_command();
test.configure_wt_cmd(&mut cmd);
cmd.arg("list").current_dir(&main_worktree);
@@ -384,7 +384,7 @@ worktree-path = "{branch}"
fs::write(test.config_path(), config).expect("Failed to write config");
// Create new worktree - should be created relative to bare repo root
- let mut cmd = Command::new(get_cargo_bin("wt"));
+ let mut cmd = wt_command();
test.configure_wt_cmd(&mut cmd);
cmd.args(["switch", "--create", "dev", "--internal"])
.current_dir(&main_worktree);
@@ -430,11 +430,11 @@ worktree-path = "{branch}"
fs::write(normal_test.test_config_path(), config).expect("Failed to write normal config");
// List worktrees in both - should show similar structure
- let mut bare_list = Command::new(get_cargo_bin("wt"));
+ let mut bare_list = wt_command();
bare_test.configure_wt_cmd(&mut bare_list);
bare_list.arg("list").current_dir(&bare_main);
- let mut normal_list = Command::new(get_cargo_bin("wt"));
+ let mut normal_list = wt_command();
normal_test.clean_cli_env(&mut normal_list);
normal_list.arg("list").current_dir(normal_test.root_path());
diff --git a/tests/integration_tests/column_alignment_verification.rs b/tests/integration_tests/column_alignment_verification.rs
index a2003a98b..cc3bf800b 100644
--- a/tests/integration_tests/column_alignment_verification.rs
+++ b/tests/integration_tests/column_alignment_verification.rs
@@ -11,9 +11,7 @@
//!
//! The detailed verification logic here catches alignment bugs that would slip through snapshot review.
-use crate::common::TestRepo;
-use insta_cmd::get_cargo_bin;
-use std::process::Command;
+use crate::common::{TestRepo, wt_command};
use unicode_width::UnicodeWidthStr;
/// Strip ANSI escape codes from a string
@@ -334,12 +332,9 @@ fn test_alignment_verification_with_varying_content() {
std::fs::write(short_path.join("single.txt"), "x").unwrap();
// Run wt list and capture output
- let mut cmd = Command::new(get_cargo_bin("wt"));
+ let mut cmd = wt_command();
repo.clean_cli_env(&mut cmd);
- cmd.arg("list")
- .current_dir(repo.root_path())
- .env("COLUMNS", "200")
- .env("CLICOLOR_FORCE", "1");
+ cmd.arg("list").current_dir(repo.root_path());
let output = cmd.output().expect("Failed to run wt list");
let stdout = String::from_utf8_lossy(&output.stdout);
@@ -366,12 +361,9 @@ fn test_alignment_with_unicode_content() {
repo.add_worktree("résumé-feature", "resume");
// Run wt list
- let mut cmd = Command::new(get_cargo_bin("wt"));
+ let mut cmd = wt_command();
repo.clean_cli_env(&mut cmd);
- cmd.arg("list")
- .current_dir(repo.root_path())
- .env("COLUMNS", "200")
- .env("CLICOLOR_FORCE", "1");
+ cmd.arg("list").current_dir(repo.root_path());
let output = cmd.output().expect("Failed to run wt list");
let stdout = String::from_utf8_lossy(&output.stdout);
@@ -408,12 +400,9 @@ fn test_alignment_with_sparse_columns() {
std::fs::write(small_path.join("one.txt"), "x").unwrap();
// Run wt list
- let mut cmd = Command::new(get_cargo_bin("wt"));
+ let mut cmd = wt_command();
repo.clean_cli_env(&mut cmd);
- cmd.arg("list")
- .current_dir(repo.root_path())
- .env("COLUMNS", "200")
- .env("CLICOLOR_FORCE", "1");
+ cmd.arg("list").current_dir(repo.root_path());
let output = cmd.output().expect("Failed to run wt list");
let stdout = String::from_utf8_lossy(&output.stdout);
@@ -462,12 +451,9 @@ fn test_alignment_real_world_scenario() {
// No changes on this one
// Run wt list at a width where Dirty column is visible
- let mut cmd = Command::new(get_cargo_bin("wt"));
+ let mut cmd = wt_command();
repo.clean_cli_env(&mut cmd);
- cmd.arg("list")
- .current_dir(repo.root_path())
- .env("COLUMNS", "200")
- .env("CLICOLOR_FORCE", "1");
+ cmd.arg("list").current_dir(repo.root_path());
let output = cmd.output().expect("Failed to run wt list");
let stdout = String::from_utf8_lossy(&output.stdout);
@@ -498,12 +484,11 @@ fn test_alignment_at_different_terminal_widths() {
for width in [80, 120, 150, 200] {
println!("\n### Testing at width {} ###", width);
- let mut cmd = Command::new(get_cargo_bin("wt"));
+ let mut cmd = wt_command();
repo.clean_cli_env(&mut cmd);
cmd.arg("list")
.current_dir(repo.root_path())
- .env("COLUMNS", width.to_string())
- .env("CLICOLOR_FORCE", "1");
+ .env("COLUMNS", width.to_string());
let output = cmd.output().expect("Failed to run wt list");
let stdout = String::from_utf8_lossy(&output.stdout);
diff --git a/tests/integration_tests/completion.rs b/tests/integration_tests/completion.rs
index 3d405a095..b68dce01c 100644
--- a/tests/integration_tests/completion.rs
+++ b/tests/integration_tests/completion.rs
@@ -1,6 +1,6 @@
-use crate::common::TestRepo;
+use crate::common::{TestRepo, wt_command};
use insta::Settings;
-use insta_cmd::{assert_cmd_snapshot, get_cargo_bin};
+use insta_cmd::assert_cmd_snapshot;
use std::process::Command;
#[test]
@@ -25,7 +25,8 @@ fn test_complete_switch_shows_branches() {
let mut settings = Settings::clone_current();
settings.set_snapshot_path("../snapshots");
settings.bind(|| {
- let mut cmd = Command::new(get_cargo_bin("wt"));
+ let mut cmd = wt_command();
+ temp.clean_cli_env(&mut cmd);
cmd.current_dir(temp.root_path())
.args(["complete", "wt", "switch", ""]);
assert_cmd_snapshot!(cmd, @r"
@@ -60,7 +61,8 @@ fn test_complete_switch_shows_all_branches_including_worktrees() {
let mut settings = Settings::clone_current();
settings.set_snapshot_path("../snapshots");
settings.bind(|| {
- let mut cmd = Command::new(get_cargo_bin("wt"));
+ let mut cmd = wt_command();
+ temp.clean_cli_env(&mut cmd);
cmd.current_dir(temp.root_path())
.args(["complete", "wt", "switch", ""]);
assert_cmd_snapshot!(cmd, @r"
@@ -95,7 +97,8 @@ fn test_complete_push_shows_all_branches() {
let mut settings = Settings::clone_current();
settings.set_snapshot_path("../snapshots");
settings.bind(|| {
- let mut cmd = Command::new(get_cargo_bin("wt"));
+ let mut cmd = wt_command();
+ temp.clean_cli_env(&mut cmd);
cmd.current_dir(temp.root_path())
.args(["complete", "wt", "dev", "push", ""]);
assert_cmd_snapshot!(cmd, @r"
@@ -127,7 +130,8 @@ fn test_complete_base_flag_shows_all_branches() {
.unwrap();
// Test completion for --base flag (long form)
- let mut cmd = Command::new(assert_cmd::cargo::cargo_bin!("wt"));
+ let mut cmd = wt_command();
+ temp.clean_cli_env(&mut cmd);
let output = cmd
.current_dir(temp.root_path())
.args([
@@ -151,7 +155,8 @@ fn test_complete_base_flag_shows_all_branches() {
assert!(branches.iter().any(|b| b.contains("feature/existing")));
// Test completion for -b flag (short form)
- let mut cmd = Command::new(assert_cmd::cargo::cargo_bin!("wt"));
+ let mut cmd = wt_command();
+ temp.clean_cli_env(&mut cmd);
let output = cmd
.current_dir(temp.root_path())
.args([
@@ -181,7 +186,7 @@ fn test_complete_outside_git_repo() {
settings.set_snapshot_path("../snapshots");
settings.bind(|| {
- let mut cmd = Command::new(get_cargo_bin("wt"));
+ let mut cmd = wt_command();
cmd.current_dir(temp.path())
.args(["complete", "wt", "switch", ""]);
@@ -202,7 +207,8 @@ fn test_complete_empty_repo() {
settings.set_snapshot_path("../snapshots");
settings.bind(|| {
- let mut cmd = Command::new(get_cargo_bin("wt"));
+ let mut cmd = wt_command();
+ repo.clean_cli_env(&mut cmd);
cmd.current_dir(repo.root_path())
.args(["complete", "wt", "switch", ""]);
@@ -224,7 +230,8 @@ fn test_complete_unknown_command() {
settings.set_snapshot_path("../snapshots");
settings.bind(|| {
- let mut cmd = Command::new(get_cargo_bin("wt"));
+ let mut cmd = wt_command();
+ repo.clean_cli_env(&mut cmd);
cmd.current_dir(repo.root_path())
.args(["complete", "wt", "unknown-command", ""]);
@@ -246,7 +253,8 @@ fn test_complete_list_command() {
settings.set_snapshot_path("../snapshots");
settings.bind(|| {
- let mut cmd = Command::new(get_cargo_bin("wt"));
+ let mut cmd = wt_command();
+ repo.clean_cli_env(&mut cmd);
cmd.current_dir(repo.root_path())
.args(["complete", "wt", "list", ""]);
@@ -263,7 +271,7 @@ fn test_complete_list_command() {
#[test]
fn test_init_fish_includes_no_file_flag() {
// Test that fish init includes -f flag to disable file completion
- let mut cmd = Command::new(assert_cmd::cargo::cargo_bin!("wt"));
+ let mut cmd = wt_command();
let output = cmd.arg("init").arg("fish").output().unwrap();
assert!(output.status.success());
@@ -302,7 +310,8 @@ fn test_complete_with_partial_prefix() {
let mut settings = Settings::clone_current();
settings.set_snapshot_path("../snapshots");
settings.bind(|| {
- let mut cmd = Command::new(get_cargo_bin("wt"));
+ let mut cmd = wt_command();
+ temp.clean_cli_env(&mut cmd);
cmd.current_dir(temp.root_path())
.args(["complete", "wt", "switch", "feat"]);
assert_cmd_snapshot!(cmd, @r"
@@ -329,7 +338,8 @@ fn test_complete_switch_shows_all_branches_even_with_worktrees() {
temp.add_worktree("hotfix-worktree", "hotfix/bug");
// From the main worktree, test completion - should show all branches
- let mut cmd = Command::new(assert_cmd::cargo::cargo_bin!("wt"));
+ let mut cmd = wt_command();
+ temp.clean_cli_env(&mut cmd);
let output = cmd
.current_dir(temp.root_path())
.args(["complete", "wt", "switch", ""])
@@ -399,7 +409,8 @@ fn test_complete_excludes_remote_branches() {
.unwrap();
// Test completion
- let mut cmd = Command::new(assert_cmd::cargo::cargo_bin!("wt"));
+ let mut cmd = wt_command();
+ temp.clean_cli_env(&mut cmd);
let output = cmd
.current_dir(temp.root_path())
.args(["complete", "wt", "switch", ""])
@@ -443,7 +454,8 @@ fn test_complete_merge_shows_branches() {
.unwrap();
// Test completion for merge (should show ALL branches, including those with worktrees)
- let mut cmd = Command::new(assert_cmd::cargo::cargo_bin!("wt"));
+ let mut cmd = wt_command();
+ temp.clean_cli_env(&mut cmd);
let output = cmd
.current_dir(temp.root_path())
.args(["complete", "wt", "merge", ""])
@@ -481,7 +493,8 @@ fn test_complete_with_special_characters_in_branch_names() {
}
// Test completion
- let mut cmd = Command::new(assert_cmd::cargo::cargo_bin!("wt"));
+ let mut cmd = wt_command();
+ temp.clean_cli_env(&mut cmd);
let output = cmd
.current_dir(temp.root_path())
.args(["complete", "wt", "switch", ""])
@@ -523,7 +536,8 @@ fn test_complete_stops_after_branch_provided() {
let mut settings = Settings::clone_current();
settings.set_snapshot_path("../snapshots");
settings.bind(|| {
- let mut cmd = Command::new(get_cargo_bin("wt"));
+ let mut cmd = wt_command();
+ temp.clean_cli_env(&mut cmd);
cmd.current_dir(temp.root_path())
.args(["complete", "wt", "switch", "feature/one", ""]);
assert_cmd_snapshot!(cmd, @r"
@@ -539,7 +553,8 @@ fn test_complete_stops_after_branch_provided() {
let mut settings = Settings::clone_current();
settings.set_snapshot_path("../snapshots");
settings.bind(|| {
- let mut cmd = Command::new(get_cargo_bin("wt"));
+ let mut cmd = wt_command();
+ temp.clean_cli_env(&mut cmd);
cmd.current_dir(temp.root_path()).args([
"complete",
"wt",
@@ -561,7 +576,8 @@ fn test_complete_stops_after_branch_provided() {
let mut settings = Settings::clone_current();
settings.set_snapshot_path("../snapshots");
settings.bind(|| {
- let mut cmd = Command::new(get_cargo_bin("wt"));
+ let mut cmd = wt_command();
+ temp.clean_cli_env(&mut cmd);
cmd.current_dir(temp.root_path())
.args(["complete", "wt", "merge", "feature/one", ""]);
assert_cmd_snapshot!(cmd, @r"
@@ -589,7 +605,8 @@ fn test_complete_switch_with_create_flag_no_completion() {
let mut settings = Settings::clone_current();
settings.set_snapshot_path("../snapshots");
settings.bind(|| {
- let mut cmd = Command::new(get_cargo_bin("wt"));
+ let mut cmd = wt_command();
+ temp.clean_cli_env(&mut cmd);
cmd.current_dir(temp.root_path())
.args(["complete", "wt", "switch", "--create", ""]);
assert_cmd_snapshot!(cmd, @r"
@@ -605,7 +622,8 @@ fn test_complete_switch_with_create_flag_no_completion() {
let mut settings = Settings::clone_current();
settings.set_snapshot_path("../snapshots");
settings.bind(|| {
- let mut cmd = Command::new(get_cargo_bin("wt"));
+ let mut cmd = wt_command();
+ temp.clean_cli_env(&mut cmd);
cmd.current_dir(temp.root_path())
.args(["complete", "wt", "switch", "-c", ""]);
assert_cmd_snapshot!(cmd, @r"
@@ -631,7 +649,8 @@ fn test_complete_switch_base_flag_after_branch() {
.unwrap();
// Test completion for --base even after --create and branch name
- let mut cmd = Command::new(assert_cmd::cargo::cargo_bin!("wt"));
+ let mut cmd = wt_command();
+ temp.clean_cli_env(&mut cmd);
let output = cmd
.current_dir(temp.root_path())
.args([
@@ -669,7 +688,8 @@ fn test_complete_remove_shows_branches() {
.unwrap();
// Test completion for remove (should show ALL branches)
- let mut cmd = Command::new(assert_cmd::cargo::cargo_bin!("wt"));
+ let mut cmd = wt_command();
+ temp.clean_cli_env(&mut cmd);
let output = cmd
.current_dir(temp.root_path())
.args(["complete", "wt", "remove", ""])
@@ -691,7 +711,8 @@ fn test_complete_dev_run_hook_shows_hook_types() {
temp.commit("initial");
// Test completion for dev run-hook
- let mut cmd = Command::new(get_cargo_bin("wt"));
+ let mut cmd = wt_command();
+ temp.clean_cli_env(&mut cmd);
let output = cmd
.current_dir(temp.root_path())
.args(["complete", "wt", "dev", "run-hook", ""])
@@ -717,7 +738,8 @@ fn test_complete_dev_run_hook_with_partial_input() {
temp.commit("initial");
// Test completion with partial input
- let mut cmd = Command::new(get_cargo_bin("wt"));
+ let mut cmd = wt_command();
+ temp.clean_cli_env(&mut cmd);
let output = cmd
.current_dir(temp.root_path())
.args(["complete", "wt", "dev", "run-hook", "po"])
diff --git a/tests/integration_tests/completion_validation.rs b/tests/integration_tests/completion_validation.rs
index 24b3d3b35..fbfad4c4b 100644
--- a/tests/integration_tests/completion_validation.rs
+++ b/tests/integration_tests/completion_validation.rs
@@ -1,5 +1,5 @@
+use crate::common::wt_command;
use std::collections::HashSet;
-use std::process::Command;
use worktrunk::styling::SUCCESS_EMOJI;
/// Issue found during validation
@@ -239,19 +239,19 @@ fn validate_cross_shell(fish_content: &str, bash_content: &str, zsh_content: &st
#[test]
fn test_completion_validation() {
// Generate completions
- let fish_output = Command::new(assert_cmd::cargo::cargo_bin!("wt"))
+ let fish_output = wt_command()
.arg("init")
.arg("fish")
.output()
.expect("Failed to generate fish completion");
- let bash_output = Command::new(assert_cmd::cargo::cargo_bin!("wt"))
+ let bash_output = wt_command()
.arg("init")
.arg("bash")
.output()
.expect("Failed to generate bash completion");
- let zsh_output = Command::new(assert_cmd::cargo::cargo_bin!("wt"))
+ let zsh_output = wt_command()
.arg("init")
.arg("zsh")
.output()
diff --git a/tests/integration_tests/config_list.rs b/tests/integration_tests/config_list.rs
index f84ebda81..dc928c502 100644
--- a/tests/integration_tests/config_list.rs
+++ b/tests/integration_tests/config_list.rs
@@ -1,8 +1,7 @@
-use crate::common::TestRepo;
+use crate::common::{TestRepo, set_temp_home_env, wt_command};
use insta::Settings;
-use insta_cmd::{assert_cmd_snapshot, get_cargo_bin};
+use insta_cmd::assert_cmd_snapshot;
use std::fs;
-use std::process::Command;
use tempfile::TempDir;
/// Test `wt config list` with both global and project configs present
@@ -48,13 +47,10 @@ server = "npm run dev"
settings.add_filter(r"\\", "/");
settings.bind(|| {
- let mut cmd = Command::new(get_cargo_bin("wt"));
+ let mut cmd = wt_command();
repo.clean_cli_env(&mut cmd);
- cmd.arg("config")
- .arg("list")
- .env("HOME", temp_home.path())
- .env("XDG_CONFIG_HOME", temp_home.path().join(".config"))
- .current_dir(repo.root_path());
+ cmd.arg("config").arg("list").current_dir(repo.root_path());
+ set_temp_home_env(&mut cmd, temp_home.path());
assert_cmd_snapshot!(cmd, @r#"
success: true
@@ -103,13 +99,10 @@ fn test_config_list_no_project_config() {
settings.add_filter(r"\\", "/");
settings.bind(|| {
- let mut cmd = Command::new(get_cargo_bin("wt"));
+ let mut cmd = wt_command();
repo.clean_cli_env(&mut cmd);
- cmd.arg("config")
- .arg("list")
- .env("HOME", temp_home.path())
- .env("XDG_CONFIG_HOME", temp_home.path().join(".config"))
- .current_dir(repo.root_path());
+ cmd.arg("config").arg("list").current_dir(repo.root_path());
+ set_temp_home_env(&mut cmd, temp_home.path());
assert_cmd_snapshot!(cmd, @r#"
success: true
@@ -150,13 +143,9 @@ fn test_config_list_outside_git_repo() {
settings.add_filter(r"\\", "/");
settings.bind(|| {
- let mut cmd = Command::new(get_cargo_bin("wt"));
- cmd.arg("config")
- .arg("list")
- .env("HOME", temp_home.path())
- .env("XDG_CONFIG_HOME", temp_home.path().join(".config"))
- .env("CLICOLOR_FORCE", "1")
- .current_dir(temp_dir.path());
+ let mut cmd = wt_command();
+ cmd.arg("config").arg("list").current_dir(temp_dir.path());
+ set_temp_home_env(&mut cmd, temp_home.path());
assert_cmd_snapshot!(cmd, @r#"
success: true
diff --git a/tests/integration_tests/configure_shell.rs b/tests/integration_tests/configure_shell.rs
index d7254b3f4..eba4ede33 100644
--- a/tests/integration_tests/configure_shell.rs
+++ b/tests/integration_tests/configure_shell.rs
@@ -1,8 +1,7 @@
-use crate::common::TestRepo;
+use crate::common::{TestRepo, set_temp_home_env, wt_command};
use insta::Settings;
-use insta_cmd::{assert_cmd_snapshot, get_cargo_bin};
+use insta_cmd::assert_cmd_snapshot;
use std::fs;
-use std::process::Command;
use tempfile::TempDir;
/// Test configure-shell with --force flag (skips confirmation)
@@ -20,12 +19,12 @@ fn test_configure_shell_with_yes() {
settings.add_filter(&temp_home.path().to_string_lossy(), "[TEMP_HOME]");
settings.bind(|| {
- let mut cmd = Command::new(get_cargo_bin("wt"));
+ let mut cmd = wt_command();
repo.clean_cli_env(&mut cmd);
+ set_temp_home_env(&mut cmd, temp_home.path());
cmd.arg("config")
.arg("shell")
.arg("--force")
- .env("HOME", temp_home.path())
.current_dir(repo.root_path());
assert_cmd_snapshot!(cmd, @r#"
@@ -63,14 +62,14 @@ fn test_configure_shell_specific_shell() {
settings.add_filter(&temp_home.path().to_string_lossy(), "[TEMP_HOME]");
settings.bind(|| {
- let mut cmd = Command::new(get_cargo_bin("wt"));
+ let mut cmd = wt_command();
repo.clean_cli_env(&mut cmd);
+ set_temp_home_env(&mut cmd, temp_home.path());
cmd.arg("config")
.arg("shell")
.arg("--shell")
.arg("zsh")
.arg("--force")
- .env("HOME", temp_home.path())
.current_dir(repo.root_path());
assert_cmd_snapshot!(cmd, @r#"
@@ -112,14 +111,14 @@ fn test_configure_shell_already_exists() {
settings.add_filter(&temp_home.path().to_string_lossy(), "[TEMP_HOME]");
settings.bind(|| {
- let mut cmd = Command::new(get_cargo_bin("wt"));
+ let mut cmd = wt_command();
repo.clean_cli_env(&mut cmd);
+ set_temp_home_env(&mut cmd, temp_home.path());
cmd.arg("config")
.arg("shell")
.arg("--shell")
.arg("zsh")
.arg("--force")
- .env("HOME", temp_home.path())
.current_dir(repo.root_path());
assert_cmd_snapshot!(cmd, @r"
@@ -149,14 +148,14 @@ fn test_configure_shell_fish() {
settings.add_filter(&temp_home.path().to_string_lossy(), "[TEMP_HOME]");
settings.bind(|| {
- let mut cmd = Command::new(get_cargo_bin("wt"));
+ let mut cmd = wt_command();
repo.clean_cli_env(&mut cmd);
+ set_temp_home_env(&mut cmd, temp_home.path());
cmd.arg("config")
.arg("shell")
.arg("--shell")
.arg("fish")
.arg("--force")
- .env("HOME", temp_home.path())
.current_dir(repo.root_path());
assert_cmd_snapshot!(cmd, @r"
@@ -202,12 +201,12 @@ fn test_configure_shell_no_files() {
settings.add_filter(r", \[TEMP_HOME\]/\.profile", "");
settings.bind(|| {
- let mut cmd = Command::new(get_cargo_bin("wt"));
+ let mut cmd = wt_command();
repo.clean_cli_env(&mut cmd);
+ set_temp_home_env(&mut cmd, temp_home.path());
cmd.arg("config")
.arg("shell")
.arg("--force")
- .env("HOME", temp_home.path())
.current_dir(repo.root_path());
assert_cmd_snapshot!(cmd, @r"
@@ -239,12 +238,12 @@ fn test_configure_shell_multiple_configs() {
settings.add_filter(&temp_home.path().to_string_lossy(), "[TEMP_HOME]");
settings.bind(|| {
- let mut cmd = Command::new(get_cargo_bin("wt"));
+ let mut cmd = wt_command();
repo.clean_cli_env(&mut cmd);
+ set_temp_home_env(&mut cmd, temp_home.path());
cmd.arg("config")
.arg("shell")
.arg("--force")
- .env("HOME", temp_home.path())
.current_dir(repo.root_path());
assert_cmd_snapshot!(cmd, @r#"
@@ -301,12 +300,12 @@ fn test_configure_shell_mixed_states() {
settings.add_filter(&temp_home.path().to_string_lossy(), "[TEMP_HOME]");
settings.bind(|| {
- let mut cmd = Command::new(get_cargo_bin("wt"));
+ let mut cmd = wt_command();
repo.clean_cli_env(&mut cmd);
+ set_temp_home_env(&mut cmd, temp_home.path());
cmd.arg("config")
.arg("shell")
.arg("--force")
- .env("HOME", temp_home.path())
.current_dir(repo.root_path());
assert_cmd_snapshot!(cmd, @r#"
diff --git a/tests/integration_tests/directives.rs b/tests/integration_tests/directives.rs
index 4289b37bf..8ff2a6ee6 100644
--- a/tests/integration_tests/directives.rs
+++ b/tests/integration_tests/directives.rs
@@ -1,6 +1,6 @@
-use crate::common::TestRepo;
+use crate::common::{TestRepo, wt_command};
use insta::Settings;
-use insta_cmd::{assert_cmd_snapshot, get_cargo_bin};
+use insta_cmd::assert_cmd_snapshot;
use std::process::Command;
/// Test the directive protocol for switch command
@@ -16,7 +16,7 @@ fn test_switch_internal_directive() {
settings.add_filter(r"__WORKTRUNK_CD__[^\n]+", "__WORKTRUNK_CD__[PATH]");
settings.bind(|| {
- let mut cmd = Command::new(get_cargo_bin("wt"));
+ let mut cmd = wt_command();
repo.clean_cli_env(&mut cmd);
cmd.arg("--internal")
.arg("switch")
@@ -45,7 +45,7 @@ fn test_switch_without_internal() {
settings.set_snapshot_path("../snapshots");
settings.bind(|| {
- let mut cmd = Command::new(get_cargo_bin("wt"));
+ let mut cmd = wt_command();
repo.clean_cli_env(&mut cmd);
cmd.arg("switch")
.arg("my-feature")
@@ -76,7 +76,7 @@ fn test_remove_internal_directive() {
settings.add_filter(r"__WORKTRUNK_CD__[^\n]+", "__WORKTRUNK_CD__[PATH]");
settings.bind(|| {
- let mut cmd = Command::new(get_cargo_bin("wt"));
+ let mut cmd = wt_command();
repo.clean_cli_env(&mut cmd);
cmd.arg("--internal")
.arg("remove")
@@ -96,7 +96,7 @@ fn test_remove_without_internal() {
settings.set_snapshot_path("../snapshots");
settings.bind(|| {
- let mut cmd = Command::new(get_cargo_bin("wt"));
+ let mut cmd = wt_command();
repo.clean_cli_env(&mut cmd);
cmd.arg("remove").current_dir(repo.root_path());
@@ -153,7 +153,7 @@ fn test_merge_internal_no_remove() {
settings.add_filter(r"@ [a-f0-9]{7}", "@ [SHA]");
settings.bind(|| {
- let mut cmd = Command::new(get_cargo_bin("wt"));
+ let mut cmd = wt_command();
repo.clean_cli_env(&mut cmd);
cmd.arg("--internal")
.arg("merge")
@@ -214,7 +214,7 @@ fn test_merge_internal_remove() {
settings.add_filter(r"/tmp/\.tmp[^\s]+/test-repo", "[REPO]");
settings.bind(|| {
- let mut cmd = Command::new(get_cargo_bin("wt"));
+ let mut cmd = wt_command();
repo.clean_cli_env(&mut cmd);
cmd.arg("--internal")
.arg("merge")
diff --git a/tests/integration_tests/e2e_shell.rs b/tests/integration_tests/e2e_shell.rs
index 276bb5fed..7e7d953f4 100644
--- a/tests/integration_tests/e2e_shell.rs
+++ b/tests/integration_tests/e2e_shell.rs
@@ -1,4 +1,4 @@
-use crate::common::TestRepo;
+use crate::common::{TestRepo, wt_command};
use insta_cmd::get_cargo_bin;
use rstest::rstest;
use std::process::Command;
@@ -63,7 +63,7 @@ fn execute_shell_script(repo: &TestRepo, shell: &str, script: &str) -> String {
/// Generate shell integration code for the given shell
fn generate_init_code(repo: &TestRepo, shell: &str) -> String {
- let mut cmd = Command::new(get_cargo_bin("wt"));
+ let mut cmd = wt_command();
repo.clean_cli_env(&mut cmd);
let output = cmd
diff --git a/tests/integration_tests/e2e_shell_post_start.rs b/tests/integration_tests/e2e_shell_post_start.rs
index ca948b05e..487d4fadb 100644
--- a/tests/integration_tests/e2e_shell_post_start.rs
+++ b/tests/integration_tests/e2e_shell_post_start.rs
@@ -1,4 +1,4 @@
-use crate::common::TestRepo;
+use crate::common::{TestRepo, wt_command};
use insta_cmd::get_cargo_bin;
use rstest::rstest;
use std::fs;
@@ -66,7 +66,7 @@ fn execute_shell_script(repo: &TestRepo, shell: &str, script: &str) -> String {
/// Generate shell integration code for the given shell
fn generate_init_code(repo: &TestRepo, shell: &str) -> String {
- let mut cmd = Command::new(get_cargo_bin("wt"));
+ let mut cmd = wt_command();
repo.clean_cli_env(&mut cmd);
let output = cmd
diff --git a/tests/integration_tests/init.rs b/tests/integration_tests/init.rs
index f1526d3a1..b822118bc 100644
--- a/tests/integration_tests/init.rs
+++ b/tests/integration_tests/init.rs
@@ -1,8 +1,7 @@
-use crate::common::TestRepo;
+use crate::common::{TestRepo, wt_command};
use insta::Settings;
-use insta_cmd::{assert_cmd_snapshot, get_cargo_bin};
+use insta_cmd::assert_cmd_snapshot;
use rstest::rstest;
-use std::process::Command;
/// Helper to create snapshot for init command
fn snapshot_init(test_name: &str, shell: &str, extra_args: &[&str]) {
@@ -11,7 +10,7 @@ fn snapshot_init(test_name: &str, shell: &str, extra_args: &[&str]) {
settings.set_snapshot_path("../snapshots");
settings.bind(|| {
- let mut cmd = Command::new(get_cargo_bin("wt"));
+ let mut cmd = wt_command();
repo.clean_cli_env(&mut cmd);
cmd.arg("init").arg(shell);
@@ -48,7 +47,7 @@ fn test_init_invalid_shell() {
settings.set_snapshot_path("../snapshots");
settings.bind(|| {
- let mut cmd = Command::new(get_cargo_bin("wt"));
+ let mut cmd = wt_command();
repo.clean_cli_env(&mut cmd);
cmd.arg("init")
.arg("invalid-shell")
@@ -73,7 +72,7 @@ fn test_init_invalid_shell() {
fn test_fish_no_duplicate_base_completion() {
// Verify that the fish completion doesn't have duplicate entries for --base
let repo = TestRepo::new();
- let mut cmd = Command::new(get_cargo_bin("wt"));
+ let mut cmd = wt_command();
repo.clean_cli_env(&mut cmd);
cmd.arg("init").arg("fish").current_dir(repo.root_path());
diff --git a/tests/integration_tests/internal_flag.rs b/tests/integration_tests/internal_flag.rs
index a3da805b5..90d481c9b 100644
--- a/tests/integration_tests/internal_flag.rs
+++ b/tests/integration_tests/internal_flag.rs
@@ -5,11 +5,10 @@
//! 2. Commands that DON'T emit directives work correctly with --internal
//! 3. The --internal flag can be safely passed to all commands
-use crate::common::TestRepo;
+use crate::common::{TestRepo, set_temp_home_env, wt_command};
use insta::Settings;
-use insta_cmd::{assert_cmd_snapshot, get_cargo_bin};
+use insta_cmd::assert_cmd_snapshot;
use std::fs;
-use std::process::Command;
use tempfile::TempDir;
/// Test that `list` command works with --internal flag
@@ -28,7 +27,7 @@ fn test_list_with_internal_flag() {
settings.add_filter(r"/tmp/\.tmp[^\s]+/test-repo", "[REPO]");
settings.bind(|| {
- let mut cmd = Command::new(get_cargo_bin("wt"));
+ let mut cmd = wt_command();
repo.clean_cli_env(&mut cmd);
cmd.arg("--internal")
.arg("list")
@@ -65,13 +64,12 @@ fn test_config_list_with_internal_flag() {
settings.add_filter(r"\\", "/");
settings.bind(|| {
- let mut cmd = Command::new(get_cargo_bin("wt"));
+ let mut cmd = wt_command();
repo.clean_cli_env(&mut cmd);
+ set_temp_home_env(&mut cmd, temp_home.path());
cmd.arg("--internal")
.arg("config")
.arg("list")
- .env("HOME", temp_home.path())
- .env("XDG_CONFIG_HOME", temp_home.path().join(".config"))
.current_dir(repo.root_path());
assert_cmd_snapshot!(cmd);
@@ -93,7 +91,7 @@ fn test_complete_with_internal_flag() {
settings.set_snapshot_path("../snapshots");
settings.bind(|| {
- let mut cmd = Command::new(get_cargo_bin("wt"));
+ let mut cmd = wt_command();
repo.clean_cli_env(&mut cmd);
cmd.arg("--internal")
.arg("complete")
diff --git a/tests/integration_tests/list.rs b/tests/integration_tests/list.rs
index 98973de82..fcb02d57a 100644
--- a/tests/integration_tests/list.rs
+++ b/tests/integration_tests/list.rs
@@ -1,6 +1,6 @@
-use crate::common::TestRepo;
+use crate::common::{TestRepo, wt_command};
use insta::Settings;
-use insta_cmd::{assert_cmd_snapshot, get_cargo_bin};
+use insta_cmd::assert_cmd_snapshot;
use std::process::Command;
/// Helper to create snapshot with normalized paths and SHAs
@@ -29,7 +29,7 @@ fn snapshot_list_from_dir(test_name: &str, repo: &TestRepo, cwd: &std::path::Pat
settings.add_filter(r"\\", "/");
settings.bind(|| {
- let mut cmd = Command::new(get_cargo_bin("wt"));
+ let mut cmd = wt_command();
// Clean environment to avoid interference from global git config
repo.clean_cli_env(&mut cmd);
cmd.arg("list").current_dir(cwd);
@@ -68,7 +68,7 @@ fn snapshot_list_json(test_name: &str, repo: &TestRepo) {
settings.add_filter(r"\\\\", "/");
settings.bind(|| {
- let mut cmd = Command::new(get_cargo_bin("wt"));
+ let mut cmd = wt_command();
// Clean environment to avoid interference from global git config
repo.clean_cli_env(&mut cmd);
cmd.arg("list")
@@ -100,7 +100,7 @@ fn snapshot_list_with_branches(test_name: &str, repo: &TestRepo) {
settings.add_filter(r"\\", "/");
settings.bind(|| {
- let mut cmd = Command::new(get_cargo_bin("wt"));
+ let mut cmd = wt_command();
// Clean environment to avoid interference from global git config
repo.clean_cli_env(&mut cmd);
cmd.arg("list")
@@ -588,7 +588,7 @@ fn test_list_with_upstream_tracking() {
settings.add_filter(r"\\", "/");
settings.bind(|| {
- let mut cmd = Command::new(get_cargo_bin("wt"));
+ let mut cmd = wt_command();
repo.clean_cli_env(&mut cmd);
cmd.arg("list")
.arg("--branches")
diff --git a/tests/integration_tests/security.rs b/tests/integration_tests/security.rs
index c7c5ae94b..2ba92dd85 100644
--- a/tests/integration_tests/security.rs
+++ b/tests/integration_tests/security.rs
@@ -145,9 +145,9 @@
//! For comprehensive security testing, see `tests/integration_tests/shell_wrapper.rs` which
//! tests the full shell integration pipeline.
-use crate::common::TestRepo;
+use crate::common::{TestRepo, wt_command};
use insta::Settings;
-use insta_cmd::{assert_cmd_snapshot, get_cargo_bin};
+use insta_cmd::assert_cmd_snapshot;
use std::process::Command;
/// Test that Git rejects NUL bytes in commit messages
@@ -273,7 +273,7 @@ fn test_branch_name_is_directive_not_executed() {
settings.add_filter(r"__WORKTRUNK_CD__[^\x00]+", "__WORKTRUNK_CD__[PATH]");
settings.bind(|| {
- let mut cmd = Command::new(get_cargo_bin("wt"));
+ let mut cmd = wt_command();
repo.clean_cli_env(&mut cmd);
cmd.arg("--internal")
.arg("switch")
@@ -315,7 +315,7 @@ fn test_branch_name_with_newline_directive_not_executed() {
settings.add_filter(r"__WORKTRUNK_CD__[^\x00]+", "__WORKTRUNK_CD__[PATH]");
settings.bind(|| {
- let mut cmd = Command::new(get_cargo_bin("wt"));
+ let mut cmd = wt_command();
repo.clean_cli_env(&mut cmd);
cmd.arg("--internal")
.arg("switch")
@@ -352,7 +352,7 @@ fn test_commit_message_with_directive_not_executed() {
// Run 'wt list' which might show commit messages
settings.bind(|| {
- let mut cmd = Command::new(get_cargo_bin("wt"));
+ let mut cmd = wt_command();
repo.clean_cli_env(&mut cmd);
cmd.arg("list").current_dir(repo.root_path());
@@ -387,7 +387,7 @@ fn test_path_with_directive_not_executed() {
// Run a command that might display this path
settings.bind(|| {
- let mut cmd = Command::new(get_cargo_bin("wt"));
+ let mut cmd = wt_command();
repo.clean_cli_env(&mut cmd);
cmd.arg("list").current_dir(repo.root_path());
@@ -428,7 +428,7 @@ fn test_branch_name_with_cd_directive_not_executed() {
settings.add_filter(r"__WORKTRUNK_CD__[^\x00]+", "__WORKTRUNK_CD__[PATH]");
settings.bind(|| {
- let mut cmd = Command::new(get_cargo_bin("wt"));
+ let mut cmd = wt_command();
repo.clean_cli_env(&mut cmd);
cmd.arg("--internal")
.arg("switch")
@@ -456,7 +456,7 @@ fn test_error_message_with_directive_not_executed() {
settings.set_snapshot_path("../snapshots");
settings.bind(|| {
- let mut cmd = Command::new(get_cargo_bin("wt"));
+ let mut cmd = wt_command();
repo.clean_cli_env(&mut cmd);
cmd.arg("--internal")
.arg("switch")
@@ -503,7 +503,7 @@ fn test_execute_flag_with_directive_like_branch_name() {
settings.add_filter(r"__WORKTRUNK_CD__[^\x00]+", "__WORKTRUNK_CD__[PATH]");
settings.bind(|| {
- let mut cmd = Command::new(get_cargo_bin("wt"));
+ let mut cmd = wt_command();
repo.clean_cli_env(&mut cmd);
cmd.arg("--internal")
.arg("switch")
diff --git a/tests/integration_tests/snapshots/integration__integration_tests__bare_repository__bare_repo_list_worktrees.snap b/tests/integration_tests/snapshots/integration__integration_tests__bare_repository__bare_repo_list_worktrees.snap
index cf0670545..db16d2ad9 100644
--- a/tests/integration_tests/snapshots/integration__integration_tests__bare_repository__bare_repo_list_worktrees.snap
+++ b/tests/integration_tests/snapshots/integration__integration_tests__bare_repository__bare_repo_list_worktrees.snap
@@ -1,26 +1,28 @@
---
source: tests/integration_tests/bare_repository.rs
+assertion_line: 175
info:
program: wt
args:
- list
env:
CLICOLOR_FORCE: ""
+ COLUMNS: "150"
GIT_CONFIG_GLOBAL: /dev/null
GIT_CONFIG_SYSTEM: /dev/null
LANG: C
LC_ALL: C
NO_COLOR: ""
SOURCE_DATE_EPOCH: "1761609600"
- WORKTRUNK_CONFIG: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmp0ZlKZA/test-config.toml
+ WORKTRUNK_CONFIG: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpsBQ6VP/test-config.toml
---
success: true
exit_code: 0
----- stdout -----
-Branch Status HEAD± main↕ Path Commit Age
-feature ./test-repo.feature 72413a3b 10 months ago
-main ∅ ↓ ↓1 ./test-repo.main 6c3da842 10 months ago
+Branch Status HEAD± main↕ Path Remote↕ Commit Age Message
+feature ./test-repo.feature 72413a3b 10 months ago Work on feature
+main ∅ ↓ ↓1 ./test-repo.main 6c3da842 10 months ago Initial commit on main
-⚪ Showing 2 worktrees, 1 behind, 1 column hidden
+⚪ Showing 2 worktrees, 1 behind
----- stderr -----
diff --git a/tests/integration_tests/spacing_edge_cases.rs b/tests/integration_tests/spacing_edge_cases.rs
index f5b55b28c..aa7228774 100644
--- a/tests/integration_tests/spacing_edge_cases.rs
+++ b/tests/integration_tests/spacing_edge_cases.rs
@@ -1,7 +1,6 @@
-use crate::common::TestRepo;
+use crate::common::{TestRepo, wt_command};
use insta::Settings;
-use insta_cmd::{assert_cmd_snapshot, get_cargo_bin};
-use std::process::Command;
+use insta_cmd::assert_cmd_snapshot;
/// Helper to create snapshot with normalized paths and SHAs
fn snapshot_list(test_name: &str, repo: &TestRepo) {
@@ -22,7 +21,7 @@ fn snapshot_list(test_name: &str, repo: &TestRepo) {
settings.add_filter(r"\\", "/");
settings.bind(|| {
- let mut cmd = Command::new(get_cargo_bin("wt"));
+ let mut cmd = wt_command();
repo.clean_cli_env(&mut cmd);
cmd.arg("list").current_dir(repo.root_path());
assert_cmd_snapshot!(test_name, cmd);
@@ -110,7 +109,7 @@ fn snapshot_list_with_width(test_name: &str, repo: &TestRepo, width: usize) {
settings.add_filter(r"\\", "/");
settings.bind(|| {
- let mut cmd = Command::new(get_cargo_bin("wt"));
+ let mut cmd = wt_command();
repo.clean_cli_env(&mut cmd);
cmd.arg("list")
.current_dir(repo.root_path())