Skip to content

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

test(list_config): fix isolation bug — tests now actually exercise the config they write (#2063)

Maximilian Roos992f0ae299f3
diff --git a/tests/integration_tests/list_config.rs b/tests/integration_tests/list_config.rs
index 6f6bc040c..23fd6c174 100644
--- a/tests/integration_tests/list_config.rs
+++ b/tests/integration_tests/list_config.rs
@@ -1,34 +1,24 @@
//! Tests for `wt list` command with user config
-use crate::common::{
- TestRepo, repo, set_temp_home_env, setup_snapshot_settings, setup_snapshot_settings_with_home,
- temp_home, wt_command,
-};
+use crate::common::{TestRepo, repo, setup_snapshot_settings, wt_command};
use insta_cmd::assert_cmd_snapshot;
use rstest::rstest;
use std::fs;
-use tempfile::TempDir;
#[rstest]
-fn test_list_config_full_enabled(repo: TestRepo, temp_home: TempDir) {
- // Create user config with list.full = true
- let global_config_dir = temp_home.path().join(".config").join("worktrunk");
- fs::create_dir_all(&global_config_dir).unwrap();
+fn test_list_config_full_enabled(repo: TestRepo) {
fs::write(
- global_config_dir.join("config.toml"),
- r#"worktree-path = "../{{ repo }}.{{ branch }}"
-
-[projects."repo".list]
+ repo.test_config_path(),
+ r#"[list]
full = true
"#,
)
.unwrap();
- let settings = setup_snapshot_settings_with_home(&repo, &temp_home);
+ let settings = setup_snapshot_settings(&repo);
settings.bind(|| {
let mut cmd = wt_command();
repo.configure_wt_cmd(&mut cmd);
- set_temp_home_env(&mut cmd, temp_home.path());
cmd.arg("list").current_dir(repo.root_path());
assert_cmd_snapshot!(cmd);
@@ -36,28 +26,22 @@ full = true
}
#[rstest]
-fn test_list_config_branches_enabled(repo: TestRepo, temp_home: TempDir) {
+fn test_list_config_branches_enabled(repo: TestRepo) {
// Create a branch without a worktree
repo.run_git(&["branch", "feature"]);
- // Create user config with list.branches = true
- let global_config_dir = temp_home.path().join(".config").join("worktrunk");
- fs::create_dir_all(&global_config_dir).unwrap();
fs::write(
- global_config_dir.join("config.toml"),
- r#"worktree-path = "../{{ repo }}.{{ branch }}"
-
-[projects."repo".list]
+ repo.test_config_path(),
+ r#"[list]
branches = true
"#,
)
.unwrap();
- let settings = setup_snapshot_settings_with_home(&repo, &temp_home);
+ let settings = setup_snapshot_settings(&repo);
settings.bind(|| {
let mut cmd = wt_command();
repo.configure_wt_cmd(&mut cmd);
- set_temp_home_env(&mut cmd, temp_home.path());
cmd.arg("list").current_dir(repo.root_path());
assert_cmd_snapshot!(cmd);
@@ -65,28 +49,22 @@ branches = true
}
#[rstest]
-fn test_list_config_cli_override(repo: TestRepo, temp_home: TempDir) {
+fn test_list_config_cli_override(repo: TestRepo) {
// Create a branch without a worktree
repo.run_git(&["branch", "feature"]);
- // Create user config with list.branches = false (default)
- let global_config_dir = temp_home.path().join(".config").join("worktrunk");
- fs::create_dir_all(&global_config_dir).unwrap();
fs::write(
- global_config_dir.join("config.toml"),
- r#"worktree-path = "../{{ repo }}.{{ branch }}"
-
-[projects."repo".list]
+ repo.test_config_path(),
+ r#"[list]
branches = false
"#,
)
.unwrap();
- let settings = setup_snapshot_settings_with_home(&repo, &temp_home);
+ let settings = setup_snapshot_settings(&repo);
settings.bind(|| {
let mut cmd = wt_command();
repo.configure_wt_cmd(&mut cmd);
- set_temp_home_env(&mut cmd, temp_home.path());
// CLI flag --branches should override config
cmd.arg("list")
.arg("--branches")
@@ -97,29 +75,23 @@ branches = false
}
#[rstest]
-fn test_list_config_full_and_branches(repo: TestRepo, temp_home: TempDir) {
+fn test_list_config_full_and_branches(repo: TestRepo) {
// Create a branch without a worktree
repo.run_git(&["branch", "feature"]);
- // Create user config with both full and branches enabled
- let global_config_dir = temp_home.path().join(".config").join("worktrunk");
- fs::create_dir_all(&global_config_dir).unwrap();
fs::write(
- global_config_dir.join("config.toml"),
- r#"worktree-path = "../{{ repo }}.{{ branch }}"
-
-[projects."repo".list]
+ repo.test_config_path(),
+ r#"[list]
full = true
branches = true
"#,
)
.unwrap();
- let settings = setup_snapshot_settings_with_home(&repo, &temp_home);
+ let settings = setup_snapshot_settings(&repo);
settings.bind(|| {
let mut cmd = wt_command();
repo.configure_wt_cmd(&mut cmd);
- set_temp_home_env(&mut cmd, temp_home.path());
cmd.arg("list").current_dir(repo.root_path());
assert_cmd_snapshot!(cmd);
@@ -127,25 +99,16 @@ branches = true
}
#[rstest]
-fn test_list_no_config(repo: TestRepo, temp_home: TempDir) {
+fn test_list_no_config(repo: TestRepo) {
// Create a branch without a worktree
repo.run_git(&["branch", "feature"]);
- // Create minimal user config without list settings
- let global_config_dir = temp_home.path().join(".config").join("worktrunk");
- fs::create_dir_all(&global_config_dir).unwrap();
- fs::write(
- global_config_dir.join("config.toml"),
- r#"worktree-path = "../{{ repo }}.{{ branch }}"
-"#,
- )
- .unwrap();
+ // No user config — verify defaults are used (branches not shown).
- let settings = setup_snapshot_settings_with_home(&repo, &temp_home);
+ let settings = setup_snapshot_settings(&repo);
settings.bind(|| {
let mut cmd = wt_command();
repo.configure_wt_cmd(&mut cmd);
- set_temp_home_env(&mut cmd, temp_home.path());
cmd.arg("list").current_dir(repo.root_path());
assert_cmd_snapshot!(cmd);
@@ -153,7 +116,7 @@ fn test_list_no_config(repo: TestRepo, temp_home: TempDir) {
}
#[rstest]
-fn test_list_project_url_column(repo: TestRepo, temp_home: TempDir) {
+fn test_list_project_url_column(repo: TestRepo) {
// Create project config with URL template
repo.write_project_config(
r#"[list]
@@ -161,21 +124,10 @@ url = "http://localhost:{{ branch | hash_port }}"
"#,
);
- // Create user config
- let global_config_dir = temp_home.path().join(".config").join("worktrunk");
- fs::create_dir_all(&global_config_dir).unwrap();
- fs::write(
- global_config_dir.join("config.toml"),
- r#"worktree-path = "../{{ repo }}.{{ branch }}"
-"#,
- )
- .unwrap();
-
- let settings = setup_snapshot_settings_with_home(&repo, &temp_home);
+ let settings = setup_snapshot_settings(&repo);
settings.bind(|| {
let mut cmd = wt_command();
repo.configure_wt_cmd(&mut cmd);
- set_temp_home_env(&mut cmd, temp_home.path());
cmd.arg("list").current_dir(repo.root_path());
assert_cmd_snapshot!(cmd);
@@ -183,7 +135,7 @@ url = "http://localhost:{{ branch | hash_port }}"
}
#[rstest]
-fn test_list_json_url_fields(repo: TestRepo, temp_home: TempDir) {
+fn test_list_json_url_fields(repo: TestRepo) {
// Create project config with URL template
repo.write_project_config(
r#"[list]
@@ -191,19 +143,8 @@ url = "http://localhost:{{ branch | hash_port }}"
"#,
);
- // Create user config
- let global_config_dir = temp_home.path().join(".config").join("worktrunk");
- fs::create_dir_all(&global_config_dir).unwrap();
- fs::write(
- global_config_dir.join("config.toml"),
- r#"worktree-path = "../{{ repo }}.{{ branch }}"
-"#,
- )
- .unwrap();
-
let mut cmd = wt_command();
repo.configure_wt_cmd(&mut cmd);
- set_temp_home_env(&mut cmd, temp_home.path());
cmd.args(["list", "--format=json"])
.current_dir(repo.root_path());
@@ -228,20 +169,11 @@ url = "http://localhost:{{ branch | hash_port }}"
}
#[rstest]
-fn test_list_json_no_url_without_template(repo: TestRepo, temp_home: TempDir) {
- // Create user config WITHOUT URL template
- let global_config_dir = temp_home.path().join(".config").join("worktrunk");
- fs::create_dir_all(&global_config_dir).unwrap();
- fs::write(
- global_config_dir.join("config.toml"),
- r#"worktree-path = "../{{ repo }}.{{ branch }}"
-"#,
- )
- .unwrap();
+fn test_list_json_no_url_without_template(repo: TestRepo) {
+ // No project config means no URL template configured.
let mut cmd = wt_command();
repo.configure_wt_cmd(&mut cmd);
- set_temp_home_env(&mut cmd, temp_home.path());
cmd.args(["list", "--format=json"])
.current_dir(repo.root_path());
@@ -262,7 +194,7 @@ fn test_list_json_no_url_without_template(repo: TestRepo, temp_home: TempDir) {
///
/// Only worktrees should have URLs - branches without worktrees can't have running dev servers.
#[rstest]
-fn test_list_url_with_branches_flag(repo: TestRepo, temp_home: TempDir) {
+fn test_list_url_with_branches_flag(repo: TestRepo) {
// Remove fixture worktrees and their branches to isolate test (keep only main worktree)
for branch in &["feature-a", "feature-b", "feature-c"] {
let worktree_path = repo
@@ -295,19 +227,8 @@ url = "http://localhost:{{ branch | hash_port }}"
"#,
);
- // Create user config
- let global_config_dir = temp_home.path().join(".config").join("worktrunk");
- fs::create_dir_all(&global_config_dir).unwrap();
- fs::write(
- global_config_dir.join("config.toml"),
- r#"worktree-path = "../{{ repo }}.{{ branch }}"
-"#,
- )
- .unwrap();
-
let mut cmd = wt_command();
repo.configure_wt_cmd(&mut cmd);
- set_temp_home_env(&mut cmd, temp_home.path());
cmd.args(["list", "--branches", "--format=json"])
.current_dir(repo.root_path());
@@ -341,7 +262,7 @@ url = "http://localhost:{{ branch | hash_port }}"
}
#[rstest]
-fn test_list_url_with_branch_variable(repo: TestRepo, temp_home: TempDir) {
+fn test_list_url_with_branch_variable(repo: TestRepo) {
// Create project config with {{ branch }} in URL
repo.write_project_config(
r#"[list]
@@ -349,19 +270,8 @@ url = "http://localhost:8080/{{ branch }}"
"#,
);
- // Create user config
- let global_config_dir = temp_home.path().join(".config").join("worktrunk");
- fs::create_dir_all(&global_config_dir).unwrap();
- fs::write(
- global_config_dir.join("config.toml"),
- r#"worktree-path = "../{{ repo }}.{{ branch }}"
-"#,
- )
- .unwrap();
-
let mut cmd = wt_command();
repo.configure_wt_cmd(&mut cmd);
- set_temp_home_env(&mut cmd, temp_home.path());
cmd.args(["list", "--format=json"])
.current_dir(repo.root_path());
@@ -380,15 +290,10 @@ url = "http://localhost:8080/{{ branch }}"
/// Test that task-timeout-ms config option is parsed correctly.
/// We use a very short timeout (1ms) to trigger timeouts.
#[rstest]
-fn test_list_config_timeout_triggers_timeouts(repo: TestRepo, temp_home: TempDir) {
- // Create user config with a very short per-task timeout
- let global_config_dir = temp_home.path().join(".config").join("worktrunk");
- fs::create_dir_all(&global_config_dir).unwrap();
+fn test_list_config_timeout_triggers_timeouts(repo: TestRepo) {
fs::write(
- global_config_dir.join("config.toml"),
- r#"worktree-path = "../{{ repo }}.{{ branch }}"
-
-[projects."repo".list]
+ repo.test_config_path(),
+ r#"[list]
task-timeout-ms = 1
"#,
)
@@ -396,7 +301,6 @@ task-timeout-ms = 1
let mut cmd = wt_command();
repo.configure_wt_cmd(&mut cmd);
- set_temp_home_env(&mut cmd, temp_home.path());
cmd.arg("list").current_dir(repo.root_path());
let output = cmd.output().unwrap();
@@ -412,15 +316,10 @@ task-timeout-ms = 1
/// Test that task-timeout-ms = 0 explicitly disables timeout.
#[rstest]
-fn test_list_config_timeout_zero_means_no_timeout(repo: TestRepo, temp_home: TempDir) {
- // Create user config with task-timeout-ms = 0
- let global_config_dir = temp_home.path().join(".config").join("worktrunk");
- fs::create_dir_all(&global_config_dir).unwrap();
+fn test_list_config_timeout_zero_means_no_timeout(repo: TestRepo) {
fs::write(
- global_config_dir.join("config.toml"),
- r#"worktree-path = "../{{ repo }}.{{ branch }}"
-
-[projects."repo".list]
+ repo.test_config_path(),
+ r#"[list]
task-timeout-ms = 0
"#,
)
@@ -428,7 +327,6 @@ task-timeout-ms = 0
let mut cmd = wt_command();
repo.configure_wt_cmd(&mut cmd);
- set_temp_home_env(&mut cmd, temp_home.path());
cmd.arg("list").current_dir(repo.root_path());
let output = cmd.output().unwrap();
@@ -521,15 +419,10 @@ branches = "not-a-bool"
/// Test that --full disables the task timeout.
#[rstest]
-fn test_list_config_timeout_disabled_with_full(repo: TestRepo, temp_home: TempDir) {
- // Create user config with a very short per-task timeout
- let global_config_dir = temp_home.path().join(".config").join("worktrunk");
- fs::create_dir_all(&global_config_dir).unwrap();
+fn test_list_config_timeout_disabled_with_full(repo: TestRepo) {
fs::write(
- global_config_dir.join("config.toml"),
- r#"worktree-path = "../{{ repo }}.{{ branch }}"
-
-[projects."repo".list]
+ repo.test_config_path(),
+ r#"[list]
task-timeout-ms = 1
"#,
)
@@ -537,7 +430,6 @@ task-timeout-ms = 1
let mut cmd = wt_command();
repo.configure_wt_cmd(&mut cmd);
- set_temp_home_env(&mut cmd, temp_home.path());
cmd.args(["list", "--full"]).current_dir(repo.root_path());
let output = cmd.output().unwrap();
diff --git a/tests/snapshots/integration__integration_tests__list_config__list_config_branches_enabled.snap b/tests/snapshots/integration__integration_tests__list_config__list_config_branches_enabled.snap
index 797e39209..73580f631 100644
--- a/tests/snapshots/integration__integration_tests__list_config__list_config_branches_enabled.snap
+++ b/tests/snapshots/integration__integration_tests__list_config__list_config_branches_enabled.snap
@@ -46,7 +46,8 @@ exit_code: 0
+ feature-a ↑ ↑1 ../repo.feature-a 1b87d473 16h Add feature-a file
+ feature-b ↑ ↑1 ../repo.feature-b f62940fc 16h Add feature-b file
+ feature-c ↑ ↑1 ../repo.feature-c 345c7c93 16h Add feature-c file
+ feature /_ 05a4a45d 16h Initial commit
-○ Showing 4 worktrees, 3 ahead
+○ Showing 4 worktrees, 1 branches, 3 ahead
----- stderr -----
diff --git a/tests/snapshots/integration__integration_tests__list_config__list_config_full_and_branches.snap b/tests/snapshots/integration__integration_tests__list_config__list_config_full_and_branches.snap
index 797e39209..0bdf5df4e 100644
--- a/tests/snapshots/integration__integration_tests__list_config__list_config_full_and_branches.snap
+++ b/tests/snapshots/integration__integration_tests__list_config__list_config_full_and_branches.snap
@@ -41,12 +41,13 @@ info:
success: true
exit_code: 0
----- stdout -----
- Branch Status HEAD± main↕ Remote⇅ Path Commit Age Message
-@ main ^| | . 05a4a45d 16h Initial commit
-+ feature-a ↑ ↑1 ../repo.feature-a 1b87d473 16h Add feature-a file
-+ feature-b ↑ ↑1 ../repo.feature-b f62940fc 16h Add feature-b file
-+ feature-c ↑ ↑1 ../repo.feature-c 345c7c93 16h Add feature-c file
+ Branch Status HEAD± main↕ main…± Remote⇅ CI Path Commit Age Message
+@ main ^| | . 05a4a45d 16h Initial commit
++ feature-a ↑ ↑1 +1 ../repo.feature-a 1b87d473 16h Add feature-a file
++ feature-b ↑ ↑1 +1 ../repo.feature-b f62940fc 16h Add feature-b file
++ feature-c ↑ ↑1 +1 ../repo.feature-c 345c7c93 16h Add feature-c file
+ feature /_ 05a4a45d 16h Initial commit
-○ Showing 4 worktrees, 3 ahead
+○ Showing 4 worktrees, 1 branches, 3 ahead
----- stderr -----
diff --git a/tests/snapshots/integration__integration_tests__list_config__list_config_full_enabled.snap b/tests/snapshots/integration__integration_tests__list_config__list_config_full_enabled.snap
index 797e39209..4ad00b786 100644
--- a/tests/snapshots/integration__integration_tests__list_config__list_config_full_enabled.snap
+++ b/tests/snapshots/integration__integration_tests__list_config__list_config_full_enabled.snap
@@ -41,11 +41,11 @@ info:
success: true
exit_code: 0
----- stdout -----
- Branch Status HEAD± main↕ Remote⇅ Path Commit Age Message
-@ main ^| | . 05a4a45d 16h Initial commit
-+ feature-a ↑ ↑1 ../repo.feature-a 1b87d473 16h Add feature-a file
-+ feature-b ↑ ↑1 ../repo.feature-b f62940fc 16h Add feature-b file
-+ feature-c ↑ ↑1 ../repo.feature-c 345c7c93 16h Add feature-c file
+ Branch Status HEAD± main↕ main…± Remote⇅ CI Path Commit Age Message
+@ main ^| | . 05a4a45d 16h Initial commit
++ feature-a ↑ ↑1 +1 ../repo.feature-a 1b87d473 16h Add feature-a file
++ feature-b ↑ ↑1 +1 ../repo.feature-b f62940fc 16h Add feature-b file
++ feature-c ↑ ↑1 +1 ../repo.feature-c 345c7c93 16h Add feature-c file
○ Showing 4 worktrees, 3 ahead