Skip to content

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

Refactor: Isolate config for tests to prevent user config pollution

Maximilian Roos7877570dd938
diff --git a/.claude/settings.local.json b/.claude/settings.local.json
new file mode 100644
index 000000000..969d62002
--- /dev/null
+++ b/.claude/settings.local.json
@@ -0,0 +1,9 @@
+{
+ "permissions": {
+ "allow": [
+ "Read(//Users/maximilian/.config/worktrunk/**)"
+ ],
+ "deny": [],
+ "ask": []
+ }
+}
diff --git a/src/config.rs b/src/config.rs
index 7a7bfb398..fc036037e 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -1,9 +1,11 @@
use config::{Config, ConfigError, File};
-use etcetera::base_strategy::{BaseStrategy, choose_base_strategy};
use serde::{Deserialize, Serialize};
use std::path::PathBuf;
use toml;
+#[cfg(not(test))]
+use etcetera::base_strategy::choose_base_strategy;
+
/// Configuration for worktree path formatting and LLM integration.
///
/// The `worktree-path` template is relative to the repository root.
@@ -196,12 +198,28 @@ impl WorktrunkConfig {
}
fn get_config_path() -> Option<PathBuf> {
+ // Check for test override first (WORKTRUNK_CONFIG_PATH env var)
+ if let Ok(path) = std::env::var("WORKTRUNK_CONFIG_PATH") {
+ return Some(PathBuf::from(path));
+ }
+
+ // In test builds, WORKTRUNK_CONFIG_PATH must be set to prevent polluting user config
+ #[cfg(test)]
+ panic!(
+ "WORKTRUNK_CONFIG_PATH not set in test. Tests must use TestRepo which sets this automatically, \
+ or set it manually to an isolated test config path."
+ );
+
+ // Production: use standard config location
// choose_base_strategy uses:
// - XDG on Linux (respects XDG_CONFIG_HOME, falls back to ~/.config)
// - XDG on macOS (~/.config instead of ~/Library/Application Support)
// - Windows conventions on Windows (%APPDATA%)
- let strategy = choose_base_strategy().ok()?;
- Some(strategy.config_dir().join("worktrunk").join("config.toml"))
+ #[cfg(not(test))]
+ {
+ let strategy = choose_base_strategy().ok()?;
+ Some(strategy.config_dir().join("worktrunk").join("config.toml"))
+ }
}
/// Expand template variables in a string
@@ -401,12 +419,6 @@ impl WorktrunkConfig {
mod tests {
use super::*;
- #[test]
- fn test_default_config() {
- let config = WorktrunkConfig::default();
- assert_eq!(config.worktree_path, "../{main-worktree}.{branch}");
- }
-
#[test]
fn test_config_serialization() {
let config = WorktrunkConfig::default();
@@ -417,10 +429,11 @@ mod tests {
}
#[test]
- fn test_load_config_defaults() {
- // Without a config file or env vars, should return defaults
- let config = WorktrunkConfig::load().unwrap();
+ fn test_default_config() {
+ let config = WorktrunkConfig::default();
assert_eq!(config.worktree_path, "../{main-worktree}.{branch}");
+ assert_eq!(config.commit_generation.command, None);
+ assert!(config.approved_commands.is_empty());
}
#[test]
@@ -646,26 +659,32 @@ mod tests {
#[test]
fn test_approve_command() {
+ use tempfile::TempDir;
+
+ let temp_dir = TempDir::new().unwrap();
+ let config_path = temp_dir.path().join("test-config.toml");
let mut config = WorktrunkConfig::default();
// First approval
assert!(!config.is_command_approved("github.com/user/repo", "npm install"));
config
- .approve_command(
+ .approve_command_to(
"github.com/user/repo".to_string(),
"npm install".to_string(),
+ &config_path,
)
- .ok(); // Ignore save errors in tests
+ .unwrap();
assert!(config.is_command_approved("github.com/user/repo", "npm install"));
// Duplicate approval shouldn't add twice
let count_before = config.approved_commands.len();
config
- .approve_command(
+ .approve_command_to(
"github.com/user/repo".to_string(),
"npm install".to_string(),
+ &config_path,
)
- .ok();
+ .unwrap();
assert_eq!(config.approved_commands.len(), count_before);
}
diff --git a/tests/common/mod.rs b/tests/common/mod.rs
index 71c7894d9..559c8adba 100644
--- a/tests/common/mod.rs
+++ b/tests/common/mod.rs
@@ -32,6 +32,8 @@ pub struct TestRepo {
root: PathBuf,
pub worktrees: HashMap<String, PathBuf>,
remote: Option<PathBuf>, // Path to bare remote repo if created
+ /// Isolated config file for this test (prevents pollution of user's config)
+ test_config_path: PathBuf,
}
impl TestRepo {
@@ -46,11 +48,15 @@ impl TestRepo {
.canonicalize()
.expect("Failed to canonicalize temp path");
+ // Create isolated config path for this test
+ let test_config_path = temp_dir.path().join("test-config.toml");
+
let repo = Self {
temp_dir,
root,
worktrees: HashMap::new(),
remote: None,
+ test_config_path,
};
// Initialize git repo with isolated environment
@@ -98,6 +104,9 @@ impl TestRepo {
///
/// 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.
pub fn clean_cli_env(&self, cmd: &mut Command) {
// Remove git-related env vars that might interfere
for (key, _) in std::env::vars() {
@@ -109,6 +118,8 @@ impl TestRepo {
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);
}
/// Get the root path of the repository
@@ -116,6 +127,14 @@ impl TestRepo {
&self.root
}
+ /// Get the path to the isolated test config file
+ ///
+ /// This config path is automatically set via WORKTRUNK_CONFIG_PATH when using
+ /// `clean_cli_env()`, ensuring tests don't pollute the user's real config.
+ pub fn test_config_path(&self) -> &Path {
+ &self.test_config_path
+ }
+
/// Get the path to a named worktree
pub fn worktree_path(&self, name: &str) -> &Path {
self.worktrees
diff --git a/tests/integration_tests/e2e_shell_post_start.rs b/tests/integration_tests/e2e_shell_post_start.rs
index 7047957e3..8d1524ee1 100644
--- a/tests/integration_tests/e2e_shell_post_start.rs
+++ b/tests/integration_tests/e2e_shell_post_start.rs
@@ -5,7 +5,6 @@ use std::fs;
use std::process::Command;
use std::thread;
use std::time::Duration;
-use tempfile::TempDir;
/// Map shell display names to actual binary names
fn get_shell_binary(shell: &str) -> &str {
@@ -28,22 +27,11 @@ fn is_shell_available(shell: &str) -> bool {
}
/// Execute a shell script in the given shell and return stdout
-/// Optionally set a custom HOME directory
-fn execute_shell_script_with_home(
- repo: &TestRepo,
- shell: &str,
- script: &str,
- home: Option<&std::path::Path>,
-) -> String {
+fn execute_shell_script(repo: &TestRepo, shell: &str, script: &str) -> String {
let binary = get_shell_binary(shell);
let mut cmd = Command::new(binary);
repo.clean_cli_env(&mut cmd);
- // Set HOME if provided
- if let Some(home_path) = home {
- cmd.env("HOME", home_path);
- }
-
// Additional shell-specific isolation to prevent user config interference
cmd.env_remove("BASH_ENV");
cmd.env_remove("ENV"); // for sh/dash
@@ -136,7 +124,6 @@ fn test_e2e_post_start_background_command(#[case] shell: &str) {
return;
}
- let temp_home = TempDir::new().unwrap();
let repo = TestRepo::new();
repo.commit("Initial commit");
@@ -152,10 +139,8 @@ fn test_e2e_post_start_background_command(#[case] shell: &str) {
repo.commit("Add post-start config");
// Pre-approve the command
- let user_config_dir = temp_home.path().join(".config/worktrunk");
- fs::create_dir_all(&user_config_dir).expect("Failed to create user config dir");
fs::write(
- user_config_dir.join("config.toml"),
+ repo.test_config_path(),
r#"worktree-path = "../{main-worktree}.{branch}"
[[approved-commands]]
@@ -184,7 +169,7 @@ command = "sleep 0.5 && echo 'Background task done' > bg_marker.txt"
init_code
);
- let output = execute_shell_script_with_home(&repo, shell, &script, Some(temp_home.path()));
+ let output = execute_shell_script(&repo, shell, &script);
// Verify that:
// 1. The switch command completed (shell returned)
@@ -263,7 +248,6 @@ fn test_bash_post_start_multiple_parallel_commands() {
return;
}
- let temp_home = TempDir::new().unwrap();
let repo = TestRepo::new();
repo.commit("Initial commit");
@@ -282,10 +266,8 @@ task2 = "sleep 0.5 && echo 'Task 2' > task2.txt"
repo.commit("Add multiple post-start commands");
// Pre-approve commands
- let user_config_dir = temp_home.path().join(".config/worktrunk");
- fs::create_dir_all(&user_config_dir).expect("Failed to create user config dir");
fs::write(
- user_config_dir.join("config.toml"),
+ repo.test_config_path(),
r#"worktree-path = "../{main-worktree}.{branch}"
[[approved-commands]]
@@ -297,7 +279,7 @@ project = "test-repo"
command = "sleep 0.5 && echo 'Task 2' > task2.txt"
"#,
)
- .expect("Failed to write user config");
+ .expect("Failed to write test config");
let init_code = generate_init_code(&repo, "bash");
let bin_path = get_cargo_bin("wt")
@@ -316,7 +298,7 @@ command = "sleep 0.5 && echo 'Task 2' > task2.txt"
bin_path, init_code
);
- let output = execute_shell_script_with_home(&repo, "bash", &script, Some(temp_home.path()));
+ let output = execute_shell_script(&repo, "bash", &script);
// Verify shell returned immediately (didn't wait for background tasks)
assert!(
@@ -352,7 +334,6 @@ fn test_bash_post_create_blocks() {
return;
}
- let temp_home = TempDir::new().unwrap();
let repo = TestRepo::new();
repo.commit("Initial commit");
@@ -368,10 +349,8 @@ fn test_bash_post_create_blocks() {
repo.commit("Add post-create command");
// Pre-approve command
- let user_config_dir = temp_home.path().join(".config/worktrunk");
- fs::create_dir_all(&user_config_dir).expect("Failed to create user config dir");
fs::write(
- user_config_dir.join("config.toml"),
+ repo.test_config_path(),
r#"worktree-path = "../{main-worktree}.{branch}"
[[approved-commands]]
@@ -379,7 +358,7 @@ project = "test-repo"
command = "echo 'Setup done' > setup.txt"
"#,
)
- .expect("Failed to write user config");
+ .expect("Failed to write test config");
let init_code = generate_init_code(&repo, "bash");
let bin_path = get_cargo_bin("wt")
@@ -403,7 +382,7 @@ command = "echo 'Setup done' > setup.txt"
bin_path, init_code
);
- let output = execute_shell_script_with_home(&repo, "bash", &script, Some(temp_home.path()));
+ let output = execute_shell_script(&repo, "bash", &script);
// Verify we switched to the worktree
assert!(
@@ -436,7 +415,6 @@ fn test_fish_post_start_background() {
return;
}
- let temp_home = TempDir::new().unwrap();
let repo = TestRepo::new();
repo.commit("Initial commit");
@@ -454,10 +432,8 @@ fish_bg = "sleep 0.5 && echo 'Fish background done' > fish_bg.txt"
repo.commit("Add fish background command");
// Pre-approve command
- let user_config_dir = temp_home.path().join(".config/worktrunk");
- fs::create_dir_all(&user_config_dir).expect("Failed to create user config dir");
fs::write(
- user_config_dir.join("config.toml"),
+ repo.test_config_path(),
r#"worktree-path = "../{main-worktree}.{branch}"
[[approved-commands]]
@@ -465,7 +441,7 @@ project = "test-repo"
command = "sleep 0.5 && echo 'Fish background done' > fish_bg.txt"
"#,
)
- .expect("Failed to write user config");
+ .expect("Failed to write test config");
let init_code = generate_init_code(&repo, "fish");
let bin_path = get_cargo_bin("wt")
@@ -485,7 +461,7 @@ command = "sleep 0.5 && echo 'Fish background done' > fish_bg.txt"
bin_path, init_code
);
- let output = execute_shell_script_with_home(&repo, "fish", &script, Some(temp_home.path()));
+ let output = execute_shell_script(&repo, "fish", &script);
// Verify fish shell returned immediately
assert!(
diff --git a/tests/integration_tests/post_start_commands.rs b/tests/integration_tests/post_start_commands.rs
index 8420dd4d6..e2636324d 100644
--- a/tests/integration_tests/post_start_commands.rs
+++ b/tests/integration_tests/post_start_commands.rs
@@ -1,10 +1,8 @@
use crate::common::{TestRepo, make_snapshot_cmd, resolve_git_dir, setup_snapshot_settings};
use insta_cmd::assert_cmd_snapshot;
use std::fs;
-use std::path::Path;
use std::thread;
use std::time::Duration;
-use tempfile::TempDir;
// Sleep duration constants for background command tests
// These allow time for background processes to complete and write output files
@@ -19,14 +17,12 @@ const SLEEP_BACKGROUND_COMMAND: Duration = Duration::from_secs(1);
const SLEEP_EXTENDED: Duration = Duration::from_secs(2);
/// Helper to create snapshot with normalized paths and SHAs
-/// If temp_home is provided, sets HOME environment variable to that path
-fn snapshot_switch(test_name: &str, repo: &TestRepo, args: &[&str], temp_home: Option<&Path>) {
+///
+/// Tests should write to repo.test_config_path() to pre-approve commands.
+fn snapshot_switch(test_name: &str, repo: &TestRepo, args: &[&str]) {
let settings = setup_snapshot_settings(repo);
settings.bind(|| {
let mut cmd = make_snapshot_cmd(repo, "switch", args, None);
- if let Some(home) = temp_home {
- cmd.env("HOME", home);
- }
assert_cmd_snapshot!(test_name, cmd);
});
}
@@ -41,17 +37,11 @@ fn test_post_create_no_config() {
repo.commit("Initial commit");
// Switch without project config should work normally
- snapshot_switch(
- "post_create_no_config",
- &repo,
- &["--create", "feature"],
- None,
- );
+ snapshot_switch("post_create_no_config", &repo, &["--create", "feature"]);
}
#[test]
fn test_post_create_single_command() {
- let temp_home = TempDir::new().unwrap();
let repo = TestRepo::new();
repo.commit("Initial commit");
@@ -66,11 +56,9 @@ fn test_post_create_single_command() {
repo.commit("Add config");
- // Pre-approve the command by setting up the user config in temp HOME
- let user_config_dir = temp_home.path().join(".config/worktrunk");
- fs::create_dir_all(&user_config_dir).expect("Failed to create user config dir");
+ // Pre-approve the command by writing to the isolated test config
fs::write(
- user_config_dir.join("config.toml"),
+ repo.test_config_path(),
r#"worktree-path = "../{main-worktree}.{branch}"
[[approved-commands]]
@@ -78,20 +66,18 @@ project = "test-repo"
command = "echo 'Setup complete'"
"#,
)
- .expect("Failed to write user config");
+ .expect("Failed to write test config");
// Command should execute without prompting
snapshot_switch(
"post_create_single_command",
&repo,
&["--create", "feature"],
- Some(temp_home.path()),
);
}
#[test]
fn test_post_create_multiple_commands_array() {
- let temp_home = TempDir::new().unwrap();
let repo = TestRepo::new();
repo.commit("Initial commit");
@@ -107,10 +93,8 @@ fn test_post_create_multiple_commands_array() {
repo.commit("Add config with multiple commands");
// Pre-approve both commands in temp HOME
- let user_config_dir = temp_home.path().join(".config/worktrunk");
- fs::create_dir_all(&user_config_dir).expect("Failed to create user config dir");
fs::write(
- user_config_dir.join("config.toml"),
+ repo.test_config_path(),
r#"worktree-path = "../{main-worktree}.{branch}"
[[approved-commands]]
@@ -129,13 +113,11 @@ command = "echo 'Second'"
"post_create_multiple_commands_array",
&repo,
&["--create", "feature"],
- Some(temp_home.path()),
);
}
#[test]
fn test_post_create_named_commands() {
- let temp_home = TempDir::new().unwrap();
let repo = TestRepo::new();
repo.commit("Initial commit");
@@ -154,10 +136,8 @@ setup = "echo 'Running setup'"
repo.commit("Add config with named commands");
// Pre-approve both commands in temp HOME
- let user_config_dir = temp_home.path().join(".config/worktrunk");
- fs::create_dir_all(&user_config_dir).expect("Failed to create user config dir");
fs::write(
- user_config_dir.join("config.toml"),
+ repo.test_config_path(),
r#"worktree-path = "../{main-worktree}.{branch}"
[[approved-commands]]
@@ -176,13 +156,11 @@ command = "echo 'Running setup'"
"post_create_named_commands",
&repo,
&["--create", "feature"],
- Some(temp_home.path()),
);
}
#[test]
fn test_post_create_failing_command() {
- let temp_home = TempDir::new().unwrap();
let repo = TestRepo::new();
repo.commit("Initial commit");
@@ -198,10 +176,8 @@ fn test_post_create_failing_command() {
repo.commit("Add config with failing command");
// Pre-approve the command in temp HOME
- let user_config_dir = temp_home.path().join(".config/worktrunk");
- fs::create_dir_all(&user_config_dir).expect("Failed to create user config dir");
fs::write(
- user_config_dir.join("config.toml"),
+ repo.test_config_path(),
r#"worktree-path = "../{main-worktree}.{branch}"
[[approved-commands]]
@@ -216,13 +192,11 @@ command = "exit 1"
"post_create_failing_command",
&repo,
&["--create", "feature"],
- Some(temp_home.path()),
);
}
#[test]
fn test_post_create_template_expansion() {
- let temp_home = TempDir::new().unwrap();
let repo = TestRepo::new();
repo.commit("Initial commit");
@@ -242,12 +216,10 @@ fn test_post_create_template_expansion() {
repo.commit("Add config with templates");
- // Pre-approve all commands in temp HOME
- let user_config_dir = temp_home.path().join(".config/worktrunk");
- fs::create_dir_all(&user_config_dir).expect("Failed to create user config dir");
+ // Pre-approve all commands in isolated test config
let repo_name = "test-repo";
fs::write(
- user_config_dir.join("config.toml"),
+ repo.test_config_path(),
r#"worktree-path = "../{main-worktree}.{branch}"
[[approved-commands]]
@@ -267,14 +239,13 @@ project = "test-repo"
command = "echo 'Root: {repo_root}' >> info.txt"
"#,
)
- .expect("Failed to write user config");
+ .expect("Failed to write test config");
// Commands should execute with expanded templates
snapshot_switch(
"post_create_template_expansion",
&repo,
&["--create", "feature/test"],
- Some(temp_home.path()),
);
// Verify template expansion actually worked by checking the output file
@@ -311,7 +282,6 @@ command = "echo 'Root: {repo_root}' >> info.txt"
#[test]
fn test_post_start_single_background_command() {
- let temp_home = TempDir::new().unwrap();
let repo = TestRepo::new();
repo.commit("Initial commit");
@@ -327,10 +297,8 @@ fn test_post_start_single_background_command() {
repo.commit("Add background command");
// Pre-approve the command
- let user_config_dir = temp_home.path().join(".config/worktrunk");
- fs::create_dir_all(&user_config_dir).expect("Failed to create user config dir");
fs::write(
- user_config_dir.join("config.toml"),
+ repo.test_config_path(),
r#"worktree-path = "../{main-worktree}.{branch}"
[[approved-commands]]
@@ -345,7 +313,6 @@ command = "sleep 1 && echo 'Background task done' > background.txt"
"post_start_single_background",
&repo,
&["--create", "feature"],
- Some(temp_home.path()),
);
// Verify log file was created
@@ -367,7 +334,6 @@ command = "sleep 1 && echo 'Background task done' > background.txt"
#[test]
fn test_post_start_multiple_background_commands() {
- let temp_home = TempDir::new().unwrap();
let repo = TestRepo::new();
repo.commit("Initial commit");
@@ -386,10 +352,8 @@ task2 = "echo 'Task 2 running' > task2.txt"
repo.commit("Add multiple background commands");
// Pre-approve both commands
- let user_config_dir = temp_home.path().join(".config/worktrunk");
- fs::create_dir_all(&user_config_dir).expect("Failed to create user config dir");
fs::write(
- user_config_dir.join("config.toml"),
+ repo.test_config_path(),
r#"worktree-path = "../{main-worktree}.{branch}"
[[approved-commands]]
@@ -408,7 +372,6 @@ command = "echo 'Task 2 running' > task2.txt"
"post_start_multiple_background",
&repo,
&["--create", "feature"],
- Some(temp_home.path()),
);
// Wait for background commands
@@ -422,7 +385,6 @@ command = "echo 'Task 2 running' > task2.txt"
#[test]
fn test_both_post_create_and_post_start() {
- let temp_home = TempDir::new().unwrap();
let repo = TestRepo::new();
repo.commit("Initial commit");
@@ -442,10 +404,8 @@ server = "sleep 0.5 && echo 'Server running' > server.txt"
repo.commit("Add both command types");
// Pre-approve all commands
- let user_config_dir = temp_home.path().join(".config/worktrunk");
- fs::create_dir_all(&user_config_dir).expect("Failed to create user config dir");
fs::write(
- user_config_dir.join("config.toml"),
+ repo.test_config_path(),
r#"worktree-path = "../{main-worktree}.{branch}"
[[approved-commands]]
@@ -460,12 +420,7 @@ command = "sleep 0.5 && echo 'Server running' > server.txt"
.expect("Failed to write user config");
// Post-create should run first (blocking), then post-start (background)
- snapshot_switch(
- "both_create_and_start",
- &repo,
- &["--create", "feature"],
- Some(temp_home.path()),
- );
+ snapshot_switch("both_create_and_start", &repo, &["--create", "feature"]);
// Setup file should exist immediately (post-create is blocking)
let worktree_path = repo.root_path().parent().unwrap().join("test-repo.feature");
@@ -501,7 +456,7 @@ fn test_invalid_toml() {
repo.commit("Add invalid config");
// Should continue without executing commands, showing warning
- snapshot_switch("invalid_toml", &repo, &["--create", "feature"], None);
+ snapshot_switch("invalid_toml", &repo, &["--create", "feature"]);
}
// ============================================================================
@@ -510,7 +465,6 @@ fn test_invalid_toml() {
#[test]
fn test_post_start_log_file_captures_output() {
- let temp_home = TempDir::new().unwrap();
let repo = TestRepo::new();
repo.commit("Initial commit");
@@ -526,10 +480,8 @@ fn test_post_start_log_file_captures_output() {
repo.commit("Add command with stdout/stderr");
// Pre-approve the command
- let user_config_dir = temp_home.path().join(".config/worktrunk");
- fs::create_dir_all(&user_config_dir).expect("Failed to create user config dir");
fs::write(
- user_config_dir.join("config.toml"),
+ repo.test_config_path(),
r#"worktree-path = "../{main-worktree}.{branch}"
[[approved-commands]]
@@ -543,7 +495,6 @@ command = "echo 'stdout output' && echo 'stderr output' >&2"
"post_start_log_captures_output",
&repo,
&["--create", "feature"],
- Some(temp_home.path()),
);
// Give background command time to complete
@@ -587,7 +538,6 @@ command = "echo 'stdout output' && echo 'stderr output' >&2"
#[test]
fn test_post_start_invalid_command_handling() {
- let temp_home = TempDir::new().unwrap();
let repo = TestRepo::new();
repo.commit("Initial commit");
@@ -603,10 +553,8 @@ fn test_post_start_invalid_command_handling() {
repo.commit("Add invalid command");
// Pre-approve the command
- let user_config_dir = temp_home.path().join(".config/worktrunk");
- fs::create_dir_all(&user_config_dir).expect("Failed to create user config dir");
fs::write(
- user_config_dir.join("config.toml"),
+ repo.test_config_path(),
r#"worktree-path = "../{main-worktree}.{branch}"
[[approved-commands]]
@@ -621,7 +569,6 @@ command = "echo 'unclosed quote"
"post_start_invalid_command",
&repo,
&["--create", "feature"],
- Some(temp_home.path()),
);
// Verify worktree was created despite command error
@@ -634,7 +581,6 @@ command = "echo 'unclosed quote"
#[test]
fn test_post_start_multiple_commands_separate_logs() {
- let temp_home = TempDir::new().unwrap();
let repo = TestRepo::new();
repo.commit("Initial commit");
@@ -654,10 +600,8 @@ task3 = "echo 'TASK3_OUTPUT'"
repo.commit("Add three background commands");
// Pre-approve all commands
- let user_config_dir = temp_home.path().join(".config/worktrunk");
- fs::create_dir_all(&user_config_dir).expect("Failed to create user config dir");
fs::write(
- user_config_dir.join("config.toml"),
+ repo.test_config_path(),
r#"worktree-path = "../{main-worktree}.{branch}"
[[approved-commands]]
@@ -675,12 +619,7 @@ command = "echo 'TASK3_OUTPUT'"
)
.expect("Failed to write user config");
- snapshot_switch(
- "post_start_separate_logs",
- &repo,
- &["--create", "feature"],
- Some(temp_home.path()),
- );
+ snapshot_switch("post_start_separate_logs", &repo, &["--create", "feature"]);
// Give background commands time to complete
thread::sleep(SLEEP_FAST_COMMAND);
@@ -740,7 +679,6 @@ command = "echo 'TASK3_OUTPUT'"
#[test]
fn test_execute_flag_with_post_start_commands() {
- let temp_home = TempDir::new().unwrap();
let repo = TestRepo::new();
repo.commit("Initial commit");
@@ -756,10 +694,8 @@ fn test_execute_flag_with_post_start_commands() {
repo.commit("Add background command");
// Pre-approve the command
- let user_config_dir = temp_home.path().join(".config/worktrunk");
- fs::create_dir_all(&user_config_dir).expect("Failed to create user config dir");
fs::write(
- user_config_dir.join("config.toml"),
+ repo.test_config_path(),
r#"worktree-path = "../{main-worktree}.{branch}"
[[approved-commands]]
@@ -779,7 +715,6 @@ command = "echo 'Background task' > background.txt"
"--execute",
"echo 'Execute flag' > execute.txt",
],
- Some(temp_home.path()),
);
let worktree_path = repo.root_path().parent().unwrap().join("test-repo.feature");
@@ -802,7 +737,6 @@ command = "echo 'Background task' > background.txt"
#[test]
fn test_post_start_complex_shell_commands() {
- let temp_home = TempDir::new().unwrap();
let repo = TestRepo::new();
repo.commit("Initial commit");
@@ -818,10 +752,8 @@ fn test_post_start_complex_shell_commands() {
repo.commit("Add complex shell command");
// Pre-approve the command
- let user_config_dir = temp_home.path().join(".config/worktrunk");
- fs::create_dir_all(&user_config_dir).expect("Failed to create user config dir");
fs::write(
- user_config_dir.join("config.toml"),
+ repo.test_config_path(),
r#"worktree-path = "../{main-worktree}.{branch}"
[[approved-commands]]
@@ -831,12 +763,7 @@ command = "echo 'line1\nline2\nline3' | grep line2 > filtered.txt"
)
.expect("Failed to write user config");
- snapshot_switch(
- "post_start_complex_shell",
- &repo,
- &["--create", "feature"],
- Some(temp_home.path()),
- );
+ snapshot_switch("post_start_complex_shell", &repo, &["--create", "feature"]);
// Wait for background command
thread::sleep(SLEEP_FAST_COMMAND);
diff --git a/tests/snapshots/integration__integration_tests__list__detached_head.snap b/tests/snapshots/integration__integration_tests__list__detached_head.snap
index 84ca33b34..0641c1c13 100644
--- a/tests/snapshots/integration__integration_tests__list__detached_head.snap
+++ b/tests/snapshots/integration__integration_tests__list__detached_head.snap
@@ -10,10 +10,10 @@ info:
GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
GIT_CONFIG_GLOBAL: /dev/null
GIT_CONFIG_SYSTEM: /dev/null
- GIT_EDITOR: ""
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1704067200"
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmp0h7jsG/test-config.toml
---
success: true
exit_code: 0
diff --git a/tests/snapshots/integration__integration_tests__list__locked_no_reason.snap b/tests/snapshots/integration__integration_tests__list__locked_no_reason.snap
index 785012b4d..cb10eacd4 100644
--- a/tests/snapshots/integration__integration_tests__list__locked_no_reason.snap
+++ b/tests/snapshots/integration__integration_tests__list__locked_no_reason.snap
@@ -10,10 +10,10 @@ info:
GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
GIT_CONFIG_GLOBAL: /dev/null
GIT_CONFIG_SYSTEM: /dev/null
- GIT_EDITOR: ""
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1704067200"
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmphaM2j9/test-config.toml
---
success: true
exit_code: 0
diff --git a/tests/snapshots/integration__integration_tests__list__locked_worktree.snap b/tests/snapshots/integration__integration_tests__list__locked_worktree.snap
index b7f493746..08f4811f7 100644
--- a/tests/snapshots/integration__integration_tests__list__locked_worktree.snap
+++ b/tests/snapshots/integration__integration_tests__list__locked_worktree.snap
@@ -10,10 +10,10 @@ info:
GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
GIT_CONFIG_GLOBAL: /dev/null
GIT_CONFIG_SYSTEM: /dev/null
- GIT_EDITOR: ""
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1704067200"
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpSWfMyz/test-config.toml
---
success: true
exit_code: 0
diff --git a/tests/snapshots/integration__integration_tests__list__long_commit_message.snap b/tests/snapshots/integration__integration_tests__list__long_commit_message.snap
index 317e2f249..ce679cff4 100644
--- a/tests/snapshots/integration__integration_tests__list__long_commit_message.snap
+++ b/tests/snapshots/integration__integration_tests__list__long_commit_message.snap
@@ -10,10 +10,10 @@ info:
GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
GIT_CONFIG_GLOBAL: /dev/null
GIT_CONFIG_SYSTEM: /dev/null
- GIT_EDITOR: ""
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1704067200"
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpuz933g/test-config.toml
---
success: true
exit_code: 0
diff --git a/tests/snapshots/integration__integration_tests__list__many_worktrees_varied.snap b/tests/snapshots/integration__integration_tests__list__many_worktrees_varied.snap
index 0b2026b27..0f25f8c5c 100644
--- a/tests/snapshots/integration__integration_tests__list__many_worktrees_varied.snap
+++ b/tests/snapshots/integration__integration_tests__list__many_worktrees_varied.snap
@@ -10,10 +10,10 @@ info:
GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
GIT_CONFIG_GLOBAL: /dev/null
GIT_CONFIG_SYSTEM: /dev/null
- GIT_EDITOR: ""
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1704067200"
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmp9luuZQ/test-config.toml
---
success: true
exit_code: 0
diff --git a/tests/snapshots/integration__integration_tests__list__multiple_worktrees.snap b/tests/snapshots/integration__integration_tests__list__multiple_worktrees.snap
index ea04989b2..06e4c69a2 100644
--- a/tests/snapshots/integration__integration_tests__list__multiple_worktrees.snap
+++ b/tests/snapshots/integration__integration_tests__list__multiple_worktrees.snap
@@ -10,10 +10,10 @@ info:
GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
GIT_CONFIG_GLOBAL: /dev/null
GIT_CONFIG_SYSTEM: /dev/null
- GIT_EDITOR: ""
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1704067200"
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpE3UJMX/test-config.toml
---
success: true
exit_code: 0
diff --git a/tests/snapshots/integration__integration_tests__list__single_worktree.snap b/tests/snapshots/integration__integration_tests__list__single_worktree.snap
index 4e75a70be..c0c929b5c 100644
--- a/tests/snapshots/integration__integration_tests__list__single_worktree.snap
+++ b/tests/snapshots/integration__integration_tests__list__single_worktree.snap
@@ -10,10 +10,10 @@ info:
GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
GIT_CONFIG_GLOBAL: /dev/null
GIT_CONFIG_SYSTEM: /dev/null
- GIT_EDITOR: ""
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1704067200"
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpXWgFma/test-config.toml
---
success: true
exit_code: 0
diff --git a/tests/snapshots/integration__integration_tests__list__unicode_commit_message.snap b/tests/snapshots/integration__integration_tests__list__unicode_commit_message.snap
index 9389a896e..a55fd8b79 100644
--- a/tests/snapshots/integration__integration_tests__list__unicode_commit_message.snap
+++ b/tests/snapshots/integration__integration_tests__list__unicode_commit_message.snap
@@ -10,10 +10,10 @@ info:
GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
GIT_CONFIG_GLOBAL: /dev/null
GIT_CONFIG_SYSTEM: /dev/null
- GIT_EDITOR: ""
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1704067200"
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpKeJUhV/test-config.toml
---
success: true
exit_code: 0
diff --git a/tests/snapshots/integration__integration_tests__list__with_branches_flag.snap b/tests/snapshots/integration__integration_tests__list__with_branches_flag.snap
index f484eb072..ef5442b5c 100644
--- a/tests/snapshots/integration__integration_tests__list__with_branches_flag.snap
+++ b/tests/snapshots/integration__integration_tests__list__with_branches_flag.snap
@@ -11,10 +11,10 @@ info:
GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
GIT_CONFIG_GLOBAL: /dev/null
GIT_CONFIG_SYSTEM: /dev/null
- GIT_EDITOR: ""
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1704067200"
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpOVv8qe/test-config.toml
---
success: true
exit_code: 0
diff --git a/tests/snapshots/integration__integration_tests__list__with_branches_flag_none_available.snap b/tests/snapshots/integration__integration_tests__list__with_branches_flag_none_available.snap
index 55606ca12..95c8bbfa8 100644
--- a/tests/snapshots/integration__integration_tests__list__with_branches_flag_none_available.snap
+++ b/tests/snapshots/integration__integration_tests__list__with_branches_flag_none_available.snap
@@ -11,10 +11,10 @@ info:
GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
GIT_CONFIG_GLOBAL: /dev/null
GIT_CONFIG_SYSTEM: /dev/null
- GIT_EDITOR: ""
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1704067200"
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpZKdmA3/test-config.toml
---
success: true
exit_code: 0
diff --git a/tests/snapshots/integration__integration_tests__list__with_branches_flag_only_branches.snap b/tests/snapshots/integration__integration_tests__list__with_branches_flag_only_branches.snap
index 564bb0691..5bab45637 100644
--- a/tests/snapshots/integration__integration_tests__list__with_branches_flag_only_branches.snap
+++ b/tests/snapshots/integration__integration_tests__list__with_branches_flag_only_branches.snap
@@ -11,10 +11,10 @@ info:
GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
GIT_CONFIG_GLOBAL: /dev/null
GIT_CONFIG_SYSTEM: /dev/null
- GIT_EDITOR: ""
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1704067200"
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpZvOfq0/test-config.toml
---
success: true
exit_code: 0
diff --git a/tests/snapshots/integration__integration_tests__spacing_edge_cases__alignment_empty_diffs.snap b/tests/snapshots/integration__integration_tests__spacing_edge_cases__alignment_empty_diffs.snap
index 03b049805..8970f6bf1 100644
--- a/tests/snapshots/integration__integration_tests__spacing_edge_cases__alignment_empty_diffs.snap
+++ b/tests/snapshots/integration__integration_tests__spacing_edge_cases__alignment_empty_diffs.snap
@@ -11,10 +11,10 @@ info:
GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
GIT_CONFIG_GLOBAL: /dev/null
GIT_CONFIG_SYSTEM: /dev/null
- GIT_EDITOR: ""
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1704067200"
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpi6L5s3/test-config.toml
---
success: true
exit_code: 0
diff --git a/tests/snapshots/integration__integration_tests__spacing_edge_cases__alignment_extreme_diffs.snap b/tests/snapshots/integration__integration_tests__spacing_edge_cases__alignment_extreme_diffs.snap
index cd93868b6..21e420bd6 100644
--- a/tests/snapshots/integration__integration_tests__spacing_edge_cases__alignment_extreme_diffs.snap
+++ b/tests/snapshots/integration__integration_tests__spacing_edge_cases__alignment_extreme_diffs.snap
@@ -11,10 +11,10 @@ info:
GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
GIT_CONFIG_GLOBAL: /dev/null
GIT_CONFIG_SYSTEM: /dev/null
- GIT_EDITOR: ""
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1704067200"
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpgR9AdW/test-config.toml
---
success: true
exit_code: 0
diff --git a/tests/snapshots/integration__integration_tests__spacing_edge_cases__alignment_varying_diffs.snap b/tests/snapshots/integration__integration_tests__spacing_edge_cases__alignment_varying_diffs.snap
index 2afb905be..5bf1ad523 100644
--- a/tests/snapshots/integration__integration_tests__spacing_edge_cases__alignment_varying_diffs.snap
+++ b/tests/snapshots/integration__integration_tests__spacing_edge_cases__alignment_varying_diffs.snap
@@ -11,10 +11,10 @@ info:
GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
GIT_CONFIG_GLOBAL: /dev/null
GIT_CONFIG_SYSTEM: /dev/null
- GIT_EDITOR: ""
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1704067200"
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpFm3Hjo/test-config.toml
---
success: true
exit_code: 0
diff --git a/tests/snapshots/integration__integration_tests__spacing_edge_cases__short_branch_names.snap b/tests/snapshots/integration__integration_tests__spacing_edge_cases__short_branch_names.snap
index a9224e430..ce89a833d 100644
--- a/tests/snapshots/integration__integration_tests__spacing_edge_cases__short_branch_names.snap
+++ b/tests/snapshots/integration__integration_tests__spacing_edge_cases__short_branch_names.snap
@@ -10,10 +10,10 @@ info:
GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
GIT_CONFIG_GLOBAL: /dev/null
GIT_CONFIG_SYSTEM: /dev/null
- GIT_EDITOR: ""
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1704067200"
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmp0xFLTq/test-config.toml
---
success: true
exit_code: 0
diff --git a/tests/snapshots/integration__integration_tests__spacing_edge_cases__terminal_width_120.snap b/tests/snapshots/integration__integration_tests__spacing_edge_cases__terminal_width_120.snap
index 09a0a5b1e..94b0ba85d 100644
--- a/tests/snapshots/integration__integration_tests__spacing_edge_cases__terminal_width_120.snap
+++ b/tests/snapshots/integration__integration_tests__spacing_edge_cases__terminal_width_120.snap
@@ -11,10 +11,10 @@ info:
GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
GIT_CONFIG_GLOBAL: /dev/null
GIT_CONFIG_SYSTEM: /dev/null
- GIT_EDITOR: ""
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1704067200"
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmp6fxmiy/test-config.toml
---
success: true
exit_code: 0
diff --git a/tests/snapshots/integration__integration_tests__spacing_edge_cases__terminal_width_150.snap b/tests/snapshots/integration__integration_tests__spacing_edge_cases__terminal_width_150.snap
index 84b5a52e6..2fe3b319e 100644
--- a/tests/snapshots/integration__integration_tests__spacing_edge_cases__terminal_width_150.snap
+++ b/tests/snapshots/integration__integration_tests__spacing_edge_cases__terminal_width_150.snap
@@ -11,10 +11,10 @@ info:
GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
GIT_CONFIG_GLOBAL: /dev/null
GIT_CONFIG_SYSTEM: /dev/null
- GIT_EDITOR: ""
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1704067200"
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpWmXZ1M/test-config.toml
---
success: true
exit_code: 0
diff --git a/tests/snapshots/integration__integration_tests__spacing_edge_cases__terminal_width_80.snap b/tests/snapshots/integration__integration_tests__spacing_edge_cases__terminal_width_80.snap
index 92e6524e3..972b2a33d 100644
--- a/tests/snapshots/integration__integration_tests__spacing_edge_cases__terminal_width_80.snap
+++ b/tests/snapshots/integration__integration_tests__spacing_edge_cases__terminal_width_80.snap
@@ -11,10 +11,10 @@ info:
GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
GIT_CONFIG_GLOBAL: /dev/null
GIT_CONFIG_SYSTEM: /dev/null
- GIT_EDITOR: ""
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1704067200"
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpVcjKy4/test-config.toml
---
success: true
exit_code: 0
diff --git a/tests/snapshots/integration__integration_tests__spacing_edge_cases__unicode_branch_names.snap b/tests/snapshots/integration__integration_tests__spacing_edge_cases__unicode_branch_names.snap
index d5f978b76..ce4c4a211 100644
--- a/tests/snapshots/integration__integration_tests__spacing_edge_cases__unicode_branch_names.snap
+++ b/tests/snapshots/integration__integration_tests__spacing_edge_cases__unicode_branch_names.snap
@@ -10,10 +10,10 @@ info:
GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
GIT_CONFIG_GLOBAL: /dev/null
GIT_CONFIG_SYSTEM: /dev/null
- GIT_EDITOR: ""
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1704067200"
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpqb5kEC/test-config.toml
---
success: true
exit_code: 0