Skip to content

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

Setup mock gh/glab commands in TestRepo::new()

Maximilian Roosa76f710d363e
diff --git a/tests/common/mod.rs b/tests/common/mod.rs
index 2adc0d86c..bd529bff3 100644
--- a/tests/common/mod.rs
+++ b/tests/common/mod.rs
@@ -298,6 +298,9 @@ impl TestRepo {
/// Uses a fixture template for fast initialization - copies a pre-initialized
/// git repo from `tests/fixtures/template-repo/` instead of running `git init`.
/// This saves ~10ms per test by avoiding process spawns.
+ ///
+ /// Also sets up mock gh/glab commands that appear authenticated to prevent
+ /// CI status hints from appearing in test output.
pub fn new() -> Self {
let temp_dir = TempDir::new().unwrap();
@@ -311,7 +314,7 @@ impl TestRepo {
let test_config_path = temp_dir.path().join("test-config.toml");
let git_config_path = temp_dir.path().join("test-gitconfig");
- Self {
+ let mut repo = Self {
temp_dir,
root,
worktrees: HashMap::new(),
@@ -319,7 +322,12 @@ impl TestRepo {
test_config_path,
git_config_path,
mock_bin_path: None,
- }
+ };
+
+ // Mock gh/glab as authenticated to prevent CI hints in test output
+ repo.setup_mock_gh();
+
+ repo
}
/// Create an empty test repository (no commits, no branches).
@@ -435,23 +443,33 @@ impl TestRepo {
cmd
}
- /// Clean environment for worktrunk CLI commands
+ /// Configure command for CLI tests with isolated environment.
///
- /// Removes potentially interfering environment variables and sets
- /// deterministic git environment for CLI tests.
- ///
- /// This also sets `WORKTRUNK_CONFIG_PATH` to an isolated test config
- /// to prevent tests from polluting the user's real config file.
+ /// Sets `WORKTRUNK_CONFIG_PATH`, `HOME`, and mock gh/glab commands.
pub fn clean_cli_env(&self, cmd: &mut Command) {
configure_cli_command(cmd);
self.configure_git_cmd(cmd);
- // 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)
- // 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.
+ set_temp_home_env(cmd, self.home_path());
+ self.configure_mock_commands(cmd);
+ }
+
+ /// Get the isolated HOME directory for this test.
+ ///
+ /// This is the temp directory containing the repo and can be used to set up
+ /// user config files before running commands:
+ /// - `.zshrc`, `.bashrc` - shell integration config
+ /// - `.config/worktrunk/config.toml` - user config (note: overridden by WORKTRUNK_CONFIG_PATH)
+ ///
+ /// The directory structure is:
+ /// ```text
+ /// home_path()/
+ /// ├── repo/ # The git repository (root_path())
+ /// ├── test-config.toml # WORKTRUNK_CONFIG_PATH target
+ /// └── test-gitconfig # GIT_CONFIG_GLOBAL target
+ /// ```
+ pub fn home_path(&self) -> &Path {
+ self.temp_dir.path()
}
/// Prepare a `wt` command configured for shell completions within this repo.
@@ -825,7 +843,7 @@ impl TestRepo {
/// This prevents CI detection from blocking tests with network calls.
pub fn setup_mock_gh(&mut self) {
let mock_bin = self.temp_dir.path().join("mock-bin");
- std::fs::create_dir(&mock_bin).unwrap();
+ std::fs::create_dir_all(&mock_bin).unwrap();
// Create mock gh script
let gh_script = mock_bin.join("gh");
diff --git a/tests/integration_tests/list.rs b/tests/integration_tests/list.rs
index 9d78753f7..d18fef678 100644
--- a/tests/integration_tests/list.rs
+++ b/tests/integration_tests/list.rs
@@ -617,9 +617,6 @@ fn test_list_with_upstream_tracking() {
let mut repo = TestRepo::new();
repo.commit("Initial commit on main");
- // Setup mock gh/glab to avoid network calls
- repo.setup_mock_gh();
-
// Set up remote - this already pushes main
repo.setup_remote("main");
diff --git a/tests/integration_tests/switch.rs b/tests/integration_tests/switch.rs
index ca13a704f..32670434b 100644
--- a/tests/integration_tests/switch.rs
+++ b/tests/integration_tests/switch.rs
@@ -1,65 +1,61 @@
use crate::common::{TestRepo, make_snapshot_cmd_with_global_flags, setup_snapshot_settings};
use insta_cmd::assert_cmd_snapshot;
+use rstest::{fixture, rstest};
use std::path::Path;
-use tempfile::TempDir;
-/// Common setup for switch tests - creates repo with initial commit
-fn setup_switch_repo() -> TestRepo {
+// Fixtures
+
+#[fixture]
+fn repo() -> TestRepo {
TestRepo::new()
}
-/// Helper to create snapshot with normalized paths and SHAs
+#[fixture]
+fn repo_with_remote(mut repo: TestRepo) -> TestRepo {
+ repo.setup_remote("main");
+ repo
+}
+
+// Snapshot helpers
+
fn snapshot_switch(test_name: &str, repo: &TestRepo, args: &[&str]) {
- snapshot_switch_with_home(test_name, repo, args, None, &[]);
+ snapshot_switch_impl(test_name, repo, args, &[], None);
}
-/// Helper to create snapshot with global flags (e.g., --internal)
fn snapshot_switch_with_global_flags(
test_name: &str,
repo: &TestRepo,
args: &[&str],
global_flags: &[&str],
) {
- snapshot_switch_with_home(test_name, repo, args, None, global_flags);
+ snapshot_switch_impl(test_name, repo, args, global_flags, None);
}
-/// Helper that also allows setting a custom HOME directory and global flags
-///
-/// IMPORTANT: Always uses an isolated HOME to prevent tests from being affected
-/// by the developer's real shell configuration (e.g., shell integration in ~/.zshrc).
-/// Pass `temp_home` to use a specific HOME (e.g., with shell integration configured).
-fn snapshot_switch_with_home(
+fn snapshot_switch_from_dir(test_name: &str, repo: &TestRepo, args: &[&str], cwd: &Path) {
+ snapshot_switch_impl(test_name, repo, args, &[], Some(cwd));
+}
+
+fn snapshot_switch_impl(
test_name: &str,
repo: &TestRepo,
args: &[&str],
- temp_home: Option<&Path>,
global_flags: &[&str],
+ cwd: Option<&Path>,
) {
- // Create isolated HOME if not provided to ensure test determinism
- let default_home = TempDir::new().unwrap();
- let home = temp_home.unwrap_or_else(|| default_home.path());
-
let settings = setup_snapshot_settings(repo);
settings.bind(|| {
- let mut cmd = make_snapshot_cmd_with_global_flags(repo, "switch", args, None, global_flags);
- cmd.env("HOME", home);
- // Windows: the `home` crate uses USERPROFILE for home_dir()
- cmd.env("USERPROFILE", home);
+ let mut cmd = make_snapshot_cmd_with_global_flags(repo, "switch", args, cwd, global_flags);
assert_cmd_snapshot!(test_name, cmd);
});
}
-
-#[test]
-fn test_switch_create_new_branch() {
- let repo = setup_switch_repo();
-
+// Basic switch tests
+#[rstest]
+fn test_switch_create_new_branch(repo: TestRepo) {
snapshot_switch("switch_create_new", &repo, &["--create", "feature-x"]);
}
-#[test]
-fn test_switch_create_existing_branch_error() {
- let mut repo = setup_switch_repo();
-
+#[rstest]
+fn test_switch_create_existing_branch_error(mut repo: TestRepo) {
// Create a branch first
repo.add_worktree("feature-y");
@@ -71,15 +67,10 @@ fn test_switch_create_existing_branch_error() {
);
}
-#[test]
-fn test_switch_create_with_remote_branch_only() {
+#[rstest]
+fn test_switch_create_with_remote_branch_only(#[from(repo_with_remote)] repo: TestRepo) {
use std::process::Command;
- let mut repo = setup_switch_repo();
-
- // Set up a remote
- repo.setup_remote("main");
-
// Create a branch on the remote only (no local branch)
let mut cmd = Command::new("git");
repo.configure_git_cmd(&mut cmd);
@@ -112,11 +103,8 @@ fn test_switch_create_with_remote_branch_only() {
);
}
-#[test]
-fn test_switch_existing_branch() {
- let mut repo = setup_switch_repo();
-
- // Create a worktree for a branch
+#[rstest]
+fn test_switch_existing_branch(mut repo: TestRepo) {
repo.add_worktree("feature-z");
// Switch to it (should find existing worktree)
@@ -128,38 +116,33 @@ fn test_switch_existing_branch() {
/// When shell integration is configured in user's rc files (e.g., .zshrc) but the user
/// runs `wt switch` directly (not through the shell wrapper), we should show success
/// with a hint to use `wt switch` for cd, not a warning about missing shell integration.
-#[test]
-fn test_switch_existing_with_shell_integration_configured() {
+#[rstest]
+fn test_switch_existing_with_shell_integration_configured(mut repo: TestRepo) {
use std::fs;
- let temp_home = TempDir::new().unwrap();
- let mut repo = setup_switch_repo();
+ // Create a worktree first
+ repo.add_worktree("shell-configured");
// Simulate shell integration configured in user's shell rc files
- let zshrc_path = temp_home.path().join(".zshrc");
+ // (repo.home_path() is automatically set as HOME by clean_cli_env)
+ let zshrc_path = repo.home_path().join(".zshrc");
fs::write(
&zshrc_path,
"# Existing user zsh config\nif command -v wt >/dev/null 2>&1; then eval \"$(command wt config shell init zsh)\"; fi\n",
)
.unwrap();
- // Create a worktree first
- repo.add_worktree("shell-configured");
-
// Switch to existing worktree - should show success + "cd with: wt switch" hint
// NOT the warning about "cannot cd (no shell integration)"
- snapshot_switch_with_home(
+ snapshot_switch(
"switch_existing_with_shell_configured",
&repo,
&["shell-configured"],
- Some(temp_home.path()),
- &[],
);
}
-#[test]
-fn test_switch_with_base_branch() {
- let repo = TestRepo::new();
+#[rstest]
+fn test_switch_with_base_branch(repo: TestRepo) {
repo.commit("Initial commit on main");
snapshot_switch(
@@ -169,21 +152,17 @@ fn test_switch_with_base_branch() {
);
}
-#[test]
-fn test_switch_base_without_create_warning() {
- let repo = setup_switch_repo();
-
+#[rstest]
+fn test_switch_base_without_create_warning(repo: TestRepo) {
snapshot_switch(
"switch_base_without_create",
&repo,
&["--base", "main", "main"],
);
}
-
-#[test]
-fn test_switch_internal_mode() {
- let repo = setup_switch_repo();
-
+// Internal mode tests
+#[rstest]
+fn test_switch_internal_mode(repo: TestRepo) {
snapshot_switch_with_global_flags(
"switch_internal_mode",
&repo,
@@ -192,10 +171,8 @@ fn test_switch_internal_mode() {
);
}
-#[test]
-fn test_switch_existing_worktree_internal() {
- let mut repo = setup_switch_repo();
-
+#[rstest]
+fn test_switch_existing_worktree_internal(mut repo: TestRepo) {
repo.add_worktree("existing-wt");
snapshot_switch_with_global_flags(
@@ -206,10 +183,8 @@ fn test_switch_existing_worktree_internal() {
);
}
-#[test]
-fn test_switch_internal_with_execute() {
- let repo = setup_switch_repo();
-
+#[rstest]
+fn test_switch_internal_with_execute(repo: TestRepo) {
let execute_cmd = "echo 'line1'\necho 'line2'";
snapshot_switch_with_global_flags(
@@ -219,12 +194,9 @@ fn test_switch_internal_with_execute() {
&["--internal"],
);
}
-
-#[test]
-fn test_switch_error_missing_worktree_directory() {
- let mut repo = setup_switch_repo();
-
- // Create a worktree
+// Error tests
+#[rstest]
+fn test_switch_error_missing_worktree_directory(mut repo: TestRepo) {
let wt_path = repo.add_worktree("missing-wt");
// Remove the worktree directory (but leave it registered in git)
@@ -234,12 +206,38 @@ fn test_switch_error_missing_worktree_directory() {
snapshot_switch("switch_error_missing_directory", &repo, &["missing-wt"]);
}
+/// Test the `worktree_path_occupied` error when target path exists but isn't a worktree
+#[rstest]
+fn test_switch_error_path_occupied(repo: TestRepo) {
+ // Calculate where the worktree would be created
+ // Default path pattern is {repo_name}.{branch}
+ let repo_name = repo.root_path().file_name().unwrap().to_str().unwrap();
+ let expected_path = repo
+ .root_path()
+ .parent()
+ .unwrap()
+ .join(format!("{}.occupied-branch", repo_name));
+
+ // Create a non-worktree directory at that path
+ std::fs::create_dir_all(&expected_path).unwrap();
+ std::fs::write(expected_path.join("some_file.txt"), "occupant content").unwrap();
+
+ // Try to create a worktree with a branch that would use that path
+ // Should fail with worktree_path_occupied error
+ snapshot_switch(
+ "switch_error_path_occupied",
+ &repo,
+ &["--create", "occupied-branch"],
+ );
+
+ // Cleanup
+ std::fs::remove_dir_all(&expected_path).ok();
+}
+// Execute flag tests (Unix only due to shell differences)
/// Skipped on Windows: snapshot output differs due to shell/path differences.
+#[rstest]
#[cfg_attr(windows, ignore)]
-#[test]
-fn test_switch_execute_success() {
- let repo = setup_switch_repo();
-
+fn test_switch_execute_success(repo: TestRepo) {
snapshot_switch(
"switch_execute_success",
&repo,
@@ -248,11 +246,9 @@ fn test_switch_execute_success() {
}
/// Skipped on Windows: snapshot output differs due to shell/path differences.
+#[rstest]
#[cfg_attr(windows, ignore)]
-#[test]
-fn test_switch_execute_creates_file() {
- let repo = setup_switch_repo();
-
+fn test_switch_execute_creates_file(repo: TestRepo) {
let create_file_cmd = "echo 'test content' > test.txt";
snapshot_switch(
@@ -263,11 +259,9 @@ fn test_switch_execute_creates_file() {
}
/// Skipped on Windows: Uses Unix shell command `exit 1`.
-#[test]
+#[rstest]
#[cfg_attr(windows, ignore)]
-fn test_switch_execute_failure() {
- let repo = setup_switch_repo();
-
+fn test_switch_execute_failure(repo: TestRepo) {
snapshot_switch(
"switch_execute_failure",
&repo,
@@ -276,12 +270,9 @@ fn test_switch_execute_failure() {
}
/// Skipped on Windows: snapshot output differs due to shell/path differences.
+#[rstest]
#[cfg_attr(windows, ignore)]
-#[test]
-fn test_switch_execute_with_existing_worktree() {
- let mut repo = setup_switch_repo();
-
- // Create a worktree first
+fn test_switch_execute_with_existing_worktree(mut repo: TestRepo) {
repo.add_worktree("existing-exec");
let create_file_cmd = "echo 'existing worktree' > existing.txt";
@@ -294,11 +285,9 @@ fn test_switch_execute_with_existing_worktree() {
}
/// Skipped on Windows: snapshot output differs due to shell/path differences.
+#[rstest]
#[cfg_attr(windows, ignore)]
-#[test]
-fn test_switch_execute_multiline() {
- let repo = setup_switch_repo();
-
+fn test_switch_execute_multiline(repo: TestRepo) {
let multiline_cmd = "echo 'line1'\necho 'line2'\necho 'line3'";
snapshot_switch(
@@ -307,13 +296,11 @@ fn test_switch_execute_multiline() {
&["--create", "multiline-test", "--execute", multiline_cmd],
);
}
-
+// --no-verify flag tests
/// Skipped on Windows: snapshot output differs due to shell/path differences.
+#[rstest]
#[cfg_attr(windows, ignore)]
-#[test]
-fn test_switch_no_config_commands_execute_still_runs() {
- let repo = setup_switch_repo();
-
+fn test_switch_no_config_commands_execute_still_runs(repo: TestRepo) {
snapshot_switch(
"switch_no_hooks_execute_still_runs",
&repo,
@@ -327,13 +314,9 @@ fn test_switch_no_config_commands_execute_still_runs() {
);
}
-#[test]
-fn test_switch_no_config_commands_skips_post_start_commands() {
+#[rstest]
+fn test_switch_no_config_commands_skips_post_start_commands(repo: TestRepo) {
use std::fs;
- use tempfile::TempDir;
-
- let temp_home = TempDir::new().unwrap();
- let repo = setup_switch_repo();
// Create project config with a command that would create a file
let config_dir = repo.root_path().join(".config");
@@ -349,8 +332,8 @@ fn test_switch_no_config_commands_skips_post_start_commands() {
repo.commit("Add config");
- // Pre-approve the command
- let user_config_dir = temp_home.path().join(".config/worktrunk");
+ // Pre-approve the command (repo.home_path() is automatically set as HOME)
+ let user_config_dir = repo.home_path().join(".config/worktrunk");
fs::create_dir_all(&user_config_dir).unwrap();
fs::write(
user_config_dir.join("config.toml"),
@@ -366,22 +349,17 @@ approved-commands = ["{}"]
.unwrap();
// With --no-verify, the post-start command should be skipped
- snapshot_switch_with_home(
+ snapshot_switch(
"switch_no_hooks_skips_post_start",
&repo,
&["--create", "no-post-start", "--no-verify"],
- Some(temp_home.path()),
- &[],
);
}
/// Skipped on Windows: snapshot output differs due to shell/path differences.
+#[rstest]
#[cfg_attr(windows, ignore)]
-#[test]
-fn test_switch_no_config_commands_with_existing_worktree() {
- let mut repo = setup_switch_repo();
-
- // Create a worktree first
+fn test_switch_no_config_commands_with_existing_worktree(mut repo: TestRepo) {
repo.add_worktree("existing-no-hooks");
// With --no-verify, the --execute command should still run
@@ -397,13 +375,9 @@ fn test_switch_no_config_commands_with_existing_worktree() {
);
}
-#[test]
-fn test_switch_no_config_commands_with_force() {
+#[rstest]
+fn test_switch_no_config_commands_with_force(repo: TestRepo) {
use std::fs;
- use tempfile::TempDir;
-
- let temp_home = TempDir::new().unwrap();
- let repo = setup_switch_repo();
// Create project config with a command
let config_dir = repo.root_path().join(".config");
@@ -417,28 +391,23 @@ fn test_switch_no_config_commands_with_force() {
repo.commit("Add config");
// With --no-verify, even --force shouldn't execute config commands
- snapshot_switch_with_home(
+ // (HOME is automatically set to repo.home_path() by clean_cli_env)
+ snapshot_switch(
"switch_no_hooks_with_force",
&repo,
&["--create", "force-no-hooks", "--force", "--no-verify"],
- Some(temp_home.path()),
- &[],
);
}
-
-#[test]
-fn test_switch_create_no_remote() {
- let repo = setup_switch_repo();
+// Branch inference and special branch tests
+#[rstest]
+fn test_switch_create_no_remote(repo: TestRepo) {
// Deliberately NOT calling setup_remote to test local branch inference
-
// Create a branch without specifying base - should infer default branch locally
snapshot_switch("switch_create_no_remote", &repo, &["--create", "feature"]);
}
-#[test]
-fn test_switch_primary_on_different_branch() {
- let mut repo = setup_switch_repo();
-
+#[rstest]
+fn test_switch_primary_on_different_branch(mut repo: TestRepo) {
repo.switch_primary_to("develop");
assert_eq!(repo.current_branch(), "develop");
@@ -459,20 +428,16 @@ fn test_switch_primary_on_different_branch() {
);
}
-#[test]
-fn test_switch_previous_branch_no_history() {
- let repo = setup_switch_repo();
-
+#[rstest]
+fn test_switch_previous_branch_no_history(repo: TestRepo) {
// No checkout history, so wt switch - should fail with helpful error
snapshot_switch("switch_previous_branch_no_history", &repo, &["-"]);
}
-#[test]
-fn test_switch_main_branch() {
+#[rstest]
+fn test_switch_main_branch(repo: TestRepo) {
use std::process::Command;
- let repo = setup_switch_repo();
-
// Create a feature branch
let mut cmd = Command::new("git");
repo.configure_git_cmd(&mut cmd);
@@ -488,10 +453,8 @@ fn test_switch_main_branch() {
snapshot_switch("switch_main_branch", &repo, &["^"]);
}
-#[test]
-fn test_create_with_base_main() {
- let repo = setup_switch_repo();
-
+#[rstest]
+fn test_create_with_base_main(repo: TestRepo) {
// Create new branch from main using ^
snapshot_switch(
"create_with_base_main",
@@ -500,22 +463,18 @@ fn test_create_with_base_main() {
);
}
-#[test]
-fn test_switch_default_branch_missing_worktree() {
- let repo = setup_switch_repo();
-
+#[rstest]
+fn test_switch_default_branch_missing_worktree(repo: TestRepo) {
// Move the primary worktree off the default branch so no worktree holds it
repo.switch_primary_to("develop");
snapshot_switch("switch_default_branch_missing_worktree", &repo, &["main"]);
}
-
+// Internal mode with execute tests
/// Test that --execute with exit code is emitted in directive mode shell script.
/// The shell wrapper will eval this script and propagate the exit code.
-#[test]
-fn test_switch_internal_execute_exit_code() {
- let repo = setup_switch_repo();
-
+#[rstest]
+fn test_switch_internal_execute_exit_code(repo: TestRepo) {
// wt succeeds (exit 0), but shell script contains "exit 42"
// Shell wrapper will eval and return 42
snapshot_switch_with_global_flags(
@@ -529,10 +488,8 @@ fn test_switch_internal_execute_exit_code() {
/// Test execute command failure propagation in directive mode.
/// When wt succeeds but the execute script would fail, wt still exits 0.
/// The shell wrapper handles the execute command's exit code.
-#[test]
-fn test_switch_internal_execute_with_output_before_exit() {
- let repo = setup_switch_repo();
-
+#[rstest]
+fn test_switch_internal_execute_with_output_before_exit(repo: TestRepo) {
// Execute command outputs then exits with code
let cmd = "echo 'doing work'\nexit 7";
@@ -543,52 +500,16 @@ fn test_switch_internal_execute_with_output_before_exit() {
&["--internal"],
);
}
-
-// =============================================================================
-// Error message snapshot tests
-// =============================================================================
-
-/// Test the `worktree_path_occupied` error when target path exists but isn't a worktree
-#[test]
-fn test_switch_error_path_occupied() {
- let repo = setup_switch_repo();
-
- // Calculate where the worktree would be created
- // Default path pattern is {repo_name}.{branch}
- let repo_name = repo.root_path().file_name().unwrap().to_str().unwrap();
- let expected_path = repo
- .root_path()
- .parent()
- .unwrap()
- .join(format!("{}.occupied-branch", repo_name));
-
- // Create a non-worktree directory at that path
- std::fs::create_dir_all(&expected_path).unwrap();
- std::fs::write(expected_path.join("some_file.txt"), "occupant content").unwrap();
-
- // Try to create a worktree with a branch that would use that path
- // Should fail with worktree_path_occupied error
- snapshot_switch(
- "switch_error_path_occupied",
- &repo,
- &["--create", "occupied-branch"],
- );
-
- // Cleanup
- std::fs::remove_dir_all(&expected_path).ok();
-}
-
+// History and ping-pong tests
/// Test that `wt switch -` uses actual current branch for recording history.
///
/// Bug scenario: If user changes worktrees without using `wt switch` (e.g., cd directly),
/// history becomes stale. The fix ensures we always use the actual current branch
/// when recording new history, not any previously stored value.
-#[test]
-fn test_switch_previous_with_stale_history() {
+#[rstest]
+fn test_switch_previous_with_stale_history(repo: TestRepo) {
use std::process::Command;
- let repo = setup_switch_repo();
-
// Create branches with worktrees
for branch in ["branch-a", "branch-b", "branch-c"] {
let mut cmd = Command::new("git");
@@ -622,29 +543,14 @@ fn test_switch_previous_with_stale_history() {
snapshot_switch("switch_stale_history_second_dash", &repo, &["-"]);
}
-/// Helper to run switch from a specific working directory (simulating actual worktree location)
-fn snapshot_switch_from_dir(test_name: &str, repo: &TestRepo, args: &[&str], cwd: &Path) {
- let default_home = TempDir::new().unwrap();
- let settings = setup_snapshot_settings(repo);
- settings.bind(|| {
- let mut cmd = make_snapshot_cmd_with_global_flags(repo, "switch", args, Some(cwd), &[]);
- cmd.env("HOME", default_home.path());
- // Windows: the `home` crate uses USERPROFILE for home_dir()
- cmd.env("USERPROFILE", default_home.path());
- assert_cmd_snapshot!(test_name, cmd);
- });
-}
-
/// Test realistic ping-pong behavior where we actually run from the correct worktree.
///
/// This simulates real usage with shell integration, where each `wt switch` actually
/// changes the working directory before the next command runs.
-#[test]
-fn test_switch_ping_pong_realistic() {
+#[rstest]
+fn test_switch_ping_pong_realistic(repo: TestRepo) {
use std::process::Command;
- let repo = setup_switch_repo();
-
// Create feature-a branch
let mut cmd = Command::new("git");
repo.configure_git_cmd(&mut cmd);
@@ -703,11 +609,9 @@ fn test_switch_ping_pong_realistic() {
/// Test that `wt switch` without arguments shows helpful hints about shortcuts.
///
/// Skipped on Windows: Hints display differently on Windows.
-#[test]
+#[rstest]
#[cfg_attr(windows, ignore)]
-fn test_switch_missing_argument_shows_hints() {
- let repo = setup_switch_repo();
-
+fn test_switch_missing_argument_shows_hints(repo: TestRepo) {
// Run switch with no arguments - should show clap error plus hints
snapshot_switch("switch_missing_argument_hints", &repo, &[]);
}
diff --git a/tests/snapshots/integration__integration_tests__list__maximum_status_symbols.snap b/tests/snapshots/integration__integration_tests__list__maximum_status_symbols.snap
index d972eb6c8..2f9dd0294 100644
--- a/tests/snapshots/integration__integration_tests__list__maximum_status_symbols.snap
+++ b/tests/snapshots/integration__integration_tests__list__maximum_status_symbols.snap
@@ -6,6 +6,7 @@ info:
- list
- "--full"
env:
+ APPDATA: "[TEST_CONFIG_HOME]"
CLICOLOR_FORCE: "1"
COLUMNS: "150"
GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
@@ -13,10 +14,14 @@ info:
GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
GIT_CONFIG_SYSTEM: /dev/null
GIT_EDITOR: ""
+ HOME: "[TEST_HOME]"
LANG: C
LC_ALL: C
+ PATH: "[PATH]"
SOURCE_DATE_EPOCH: "1735776000"
+ USERPROFILE: "[TEST_HOME]"
WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
---
success: true
exit_code: 0
diff --git a/tests/snapshots/integration__integration_tests__list__maximum_status_with_git_operation.snap b/tests/snapshots/integration__integration_tests__list__maximum_status_with_git_operation.snap
index d679c386d..9af7e54db 100644
--- a/tests/snapshots/integration__integration_tests__list__maximum_status_with_git_operation.snap
+++ b/tests/snapshots/integration__integration_tests__list__maximum_status_with_git_operation.snap
@@ -6,6 +6,7 @@ info:
- list
- "--full"
env:
+ APPDATA: "[TEST_CONFIG_HOME]"
CLICOLOR_FORCE: "1"
COLUMNS: "150"
GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
@@ -13,10 +14,14 @@ info:
GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
GIT_CONFIG_SYSTEM: /dev/null
GIT_EDITOR: ""
+ HOME: "[TEST_HOME]"
LANG: C
LC_ALL: C
+ PATH: "[PATH]"
SOURCE_DATE_EPOCH: "1735776000"
+ USERPROFILE: "[TEST_HOME]"
WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
---
success: true
exit_code: 0
diff --git a/tests/snapshots/integration__integration_tests__list__readme_example_list_branches.snap b/tests/snapshots/integration__integration_tests__list__readme_example_list_branches.snap
index bf8af55c0..8f6f2f0c5 100644
--- a/tests/snapshots/integration__integration_tests__list__readme_example_list_branches.snap
+++ b/tests/snapshots/integration__integration_tests__list__readme_example_list_branches.snap
@@ -7,6 +7,7 @@ info:
- "--branches"
- "--full"
env:
+ APPDATA: "[TEST_CONFIG_HOME]"
CLICOLOR_FORCE: "1"
COLUMNS: "115"
GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
@@ -14,10 +15,14 @@ info:
GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
GIT_CONFIG_SYSTEM: /dev/null
GIT_EDITOR: ""
+ HOME: "[TEST_HOME]"
LANG: C
LC_ALL: C
+ PATH: "[PATH]"
SOURCE_DATE_EPOCH: "1735776000"
+ USERPROFILE: "[TEST_HOME]"
WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
---
success: true
exit_code: 0
diff --git a/tests/snapshots/integration__integration_tests__list__readme_example_list_full.snap b/tests/snapshots/integration__integration_tests__list__readme_example_list_full.snap
index 76f94b130..895937a26 100644
--- a/tests/snapshots/integration__integration_tests__list__readme_example_list_full.snap
+++ b/tests/snapshots/integration__integration_tests__list__readme_example_list_full.snap
@@ -6,6 +6,7 @@ info:
- list
- "--full"
env:
+ APPDATA: "[TEST_CONFIG_HOME]"
CLICOLOR_FORCE: "1"
COLUMNS: "115"
GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
@@ -13,10 +14,14 @@ info:
GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
GIT_CONFIG_SYSTEM: /dev/null
GIT_EDITOR: ""
+ HOME: "[TEST_HOME]"
LANG: C
LC_ALL: C
+ PATH: "[PATH]"
SOURCE_DATE_EPOCH: "1735776000"
+ USERPROFILE: "[TEST_HOME]"
WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
---
success: true
exit_code: 0
diff --git a/tests/snapshots/integration__integration_tests__list__task_dag_full_with_diffs.snap b/tests/snapshots/integration__integration_tests__list__task_dag_full_with_diffs.snap
index aeb11d8e9..c004c4a0c 100644
--- a/tests/snapshots/integration__integration_tests__list__task_dag_full_with_diffs.snap
+++ b/tests/snapshots/integration__integration_tests__list__task_dag_full_with_diffs.snap
@@ -7,6 +7,7 @@ info:
- "--progressive"
- "--full"
env:
+ APPDATA: "[TEST_CONFIG_HOME]"
CLICOLOR_FORCE: "1"
COLUMNS: "150"
GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
@@ -14,10 +15,14 @@ info:
GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
GIT_CONFIG_SYSTEM: /dev/null
GIT_EDITOR: ""
+ HOME: "[TEST_HOME]"
LANG: C
LC_ALL: C
+ PATH: "[PATH]"
SOURCE_DATE_EPOCH: "1735776000"
+ USERPROFILE: "[TEST_HOME]"
WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
---
success: true
exit_code: 0
diff --git a/tests/snapshots/integration__integration_tests__list__task_dag_with_upstream.snap b/tests/snapshots/integration__integration_tests__list__task_dag_with_upstream.snap
index 45d350883..4a73fc2fd 100644
--- a/tests/snapshots/integration__integration_tests__list__task_dag_with_upstream.snap
+++ b/tests/snapshots/integration__integration_tests__list__task_dag_with_upstream.snap
@@ -7,6 +7,7 @@ info:
- "--progressive"
- "--full"
env:
+ APPDATA: "[TEST_CONFIG_HOME]"
CLICOLOR_FORCE: "1"
COLUMNS: "150"
GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
@@ -14,10 +15,14 @@ info:
GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
GIT_CONFIG_SYSTEM: /dev/null
GIT_EDITOR: ""
+ HOME: "[TEST_HOME]"
LANG: C
LC_ALL: C
+ PATH: "[PATH]"
SOURCE_DATE_EPOCH: "1735776000"
+ USERPROFILE: "[TEST_HOME]"
WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
---
success: true
exit_code: 0