Skip to content

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

fix: unify config path resolution so config create matches config load (#1135)

worktrunk-botf3ae9a8ac6c9
diff --git a/src/commands/config/mod.rs b/src/commands/config/mod.rs
index 8596c8171..fff04eba2 100644
--- a/src/commands/config/mod.rs
+++ b/src/commands/config/mod.rs
@@ -21,13 +21,12 @@ pub use update::handle_config_update;
#[cfg(test)]
mod tests {
use std::collections::HashMap;
- use std::path::PathBuf;
use worktrunk::config::{ProjectConfig, UserConfig};
use super::create::comment_out_config;
use super::show::{render_ci_tool_status, warn_unknown_keys};
- use super::state::{get_user_config_path, require_user_config_path, resolve_user_config_path};
+ use super::state::require_user_config_path;
// ==================== comment_out_config tests ====================
@@ -227,46 +226,6 @@ mod tests {
assert!(out.contains("authenticated"));
}
- // ==================== resolve_user_config_path tests ====================
-
- #[test]
- fn test_resolve_user_config_path_xdg_takes_priority() {
- let path = resolve_user_config_path(Some("/custom/xdg"), Some("/home/user"));
- assert_eq!(
- path,
- Some(PathBuf::from("/custom/xdg/worktrunk/config.toml"))
- );
- }
-
- #[test]
- fn test_resolve_user_config_path_home_fallback() {
- let path = resolve_user_config_path(None, Some("/home/testuser"));
- assert_eq!(
- path,
- Some(PathBuf::from(
- "/home/testuser/.config/worktrunk/config.toml"
- ))
- );
- }
-
- #[test]
- fn test_resolve_user_config_path_none_when_no_env() {
- let path = resolve_user_config_path(None, None);
- assert_eq!(path, None);
- }
-
- // ==================== get_user_config_path tests ====================
-
- #[test]
- fn test_get_user_config_path_returns_some() {
- // In a normal environment, get_user_config_path should return Some
- // (either from env vars or etcetera fallback)
- let path = get_user_config_path();
- assert!(path.is_some());
- let path = path.unwrap();
- assert!(path.ends_with("worktrunk/config.toml"));
- }
-
// ==================== require_user_config_path tests ====================
#[test]
@@ -277,4 +236,18 @@ mod tests {
let path = result.unwrap();
assert!(path.ends_with("worktrunk/config.toml"));
}
+
+ #[test]
+ fn test_require_user_config_path_matches_get_config_path() {
+ // Verify that config create/show path matches config loading path.
+ // This was the root cause of #1134: the two paths diverged on Windows
+ // when XDG_CONFIG_HOME was set because config create had its own
+ // XDG/HOME resolution that differed from config loading.
+ let create_path = require_user_config_path().unwrap();
+ let load_path = worktrunk::config::get_config_path().unwrap();
+ assert_eq!(
+ create_path, load_path,
+ "config create path and config loading path must be identical"
+ );
+ }
}
diff --git a/src/commands/config/state.rs b/src/commands/config/state.rs
index bd4cd6f9c..f23debda2 100644
--- a/src/commands/config/state.rs
+++ b/src/commands/config/state.rs
@@ -6,8 +6,9 @@
use std::fmt::Write as _;
use std::path::PathBuf;
+use anyhow::Context;
use color_print::cformat;
-use etcetera::base_strategy::{BaseStrategy, choose_base_strategy};
+use worktrunk::config::get_config_path;
use worktrunk::git::Repository;
use worktrunk::path::{format_path_for_display, sanitize_for_filename};
use worktrunk::styling::{
@@ -25,49 +26,13 @@ use crate::help_pager::show_help_in_pager;
// ==================== Path Helpers ====================
-/// Core logic for determining user config path from env var values
-pub(super) fn resolve_user_config_path(
- xdg_config_home: Option<&str>,
- home: Option<&str>,
-) -> Option<PathBuf> {
- // Respect XDG_CONFIG_HOME environment variable (Linux)
- if let Some(xdg_config) = xdg_config_home {
- let config_path = PathBuf::from(xdg_config);
- return Some(config_path.join("worktrunk").join("config.toml"));
- }
-
- // Respect HOME environment variable (fallback)
- if let Some(home) = home {
- let home_path = PathBuf::from(home);
- return Some(
- home_path
- .join(".config")
- .join("worktrunk")
- .join("config.toml"),
- );
- }
-
- None
-}
-
-pub(super) fn get_user_config_path() -> Option<PathBuf> {
- // Try env vars first, then fall back to etcetera
- resolve_user_config_path(
- std::env::var("XDG_CONFIG_HOME").ok().as_deref(),
- std::env::var("HOME").ok().as_deref(),
- )
- .or_else(|| {
- let strategy = choose_base_strategy().ok()?;
- Some(strategy.config_dir().join("worktrunk").join("config.toml"))
- })
-}
-
+/// Get the user config path, or error if it cannot be determined.
+///
+/// Delegates to `get_config_path()` so that `config create` and `config show`
+/// resolve the same path that config loading uses — including any CLI
+/// (`--config`) or environment variable (`WORKTRUNK_CONFIG_PATH`) overrides.
pub fn require_user_config_path() -> anyhow::Result<PathBuf> {
- get_user_config_path().ok_or_else(|| {
- anyhow::anyhow!(
- "Cannot determine config directory. Set $HOME or $XDG_CONFIG_HOME environment variable"
- )
- })
+ get_config_path().context("Cannot determine config directory")
}
// ==================== Log Management ====================
diff --git a/src/config/mod.rs b/src/config/mod.rs
index e6e06162a..90ad42e52 100644
--- a/src/config/mod.rs
+++ b/src/config/mod.rs
@@ -96,8 +96,9 @@ pub use project::{
pub use user::{
CommitConfig, CommitGenerationConfig, ListConfig, MergeConfig, OverridableConfig,
ResolvedConfig, SelectConfig, StageMode, SwitchConfig, SwitchPickerConfig, UserConfig,
- UserProjectOverrides, default_system_config_path, find_unknown_keys as find_unknown_user_keys,
- get_config_path, get_system_config_path, set_config_path,
+ UserProjectOverrides, default_config_path, default_system_config_path,
+ find_unknown_keys as find_unknown_user_keys, get_config_path, get_system_config_path,
+ set_config_path,
};
#[cfg(test)]
diff --git a/src/config/user/mod.rs b/src/config/user/mod.rs
index 43178a6ff..ecc5d579c 100644
--- a/src/config/user/mod.rs
+++ b/src/config/user/mod.rs
@@ -20,7 +20,8 @@ use serde::{Deserialize, Serialize};
// Re-export public types
pub use merge::Merge;
pub use path::{
- default_system_config_path, get_config_path, get_system_config_path, set_config_path,
+ default_config_path, default_system_config_path, get_config_path, get_system_config_path,
+ set_config_path,
};
pub use resolved::ResolvedConfig;
pub use schema::{find_unknown_keys, valid_user_config_keys};
diff --git a/src/config/user/path.rs b/src/config/user/path.rs
index c3e13ceaf..83d55e2a0 100644
--- a/src/config/user/path.rs
+++ b/src/config/user/path.rs
@@ -30,7 +30,7 @@ pub fn is_config_path_explicit() -> bool {
/// Priority:
/// 1. CLI --config flag (set via `set_config_path`)
/// 2. WORKTRUNK_CONFIG_PATH environment variable
-/// 3. Platform-specific default location
+/// 3. Platform-specific default location (via `default_config_path`)
pub fn get_config_path() -> Option<PathBuf> {
// Priority 1: CLI --config flag
if let Some(path) = CONFIG_PATH.get() {
@@ -43,6 +43,20 @@ pub fn get_config_path() -> Option<PathBuf> {
}
// Priority 3: Platform-specific default location
+ default_config_path()
+}
+
+/// Platform-specific default config path, without CLI or env var overrides.
+///
+/// Returns the etcetera-based platform default. Called by `get_config_path()`
+/// as the final fallback when no CLI or env var override is set.
+///
+///
+/// Uses the `etcetera` crate which returns:
+/// - Linux: `$XDG_CONFIG_HOME/worktrunk/config.toml` (default `~/.config/...`)
+/// - macOS: `~/Library/Application Support/worktrunk/config.toml`
+/// - Windows: `%APPDATA%\worktrunk\config.toml`
+pub fn default_config_path() -> Option<PathBuf> {
let strategy = choose_base_strategy().ok()?;
Some(strategy.config_dir().join("worktrunk").join("config.toml"))
}
diff --git a/src/config/user/tests.rs b/src/config/user/tests.rs
index b08533798..ffbc77836 100644
--- a/src/config/user/tests.rs
+++ b/src/config/user/tests.rs
@@ -25,6 +25,32 @@ fn test_repo() -> TestRepo {
TestRepo::new()
}
+#[test]
+fn test_default_config_path_returns_platform_path() {
+ // default_config_path() returns the platform-specific path without
+ // CLI or env var overrides. Verify it returns a valid path.
+ let path = default_config_path();
+ assert!(path.is_some(), "default_config_path should return Some");
+ let path = path.unwrap();
+ assert!(
+ path.ends_with("worktrunk/config.toml") || path.ends_with("worktrunk\\config.toml"),
+ "Expected path ending in worktrunk/config.toml, got: {path:?}"
+ );
+}
+
+#[test]
+fn test_get_config_path_falls_through_to_default() {
+ // When no CLI override or WORKTRUNK_CONFIG_PATH env var is set,
+ // get_config_path() should fall through to default_config_path().
+ // This also verifies both functions return the same path.
+ let default = default_config_path().unwrap();
+ let resolved = get_config_path().unwrap();
+ assert_eq!(
+ resolved, default,
+ "get_config_path() should match default_config_path() when no overrides are set"
+ );
+}
+
#[test]
fn test_find_unknown_keys_empty() {
// Valid config with no unknown keys
diff --git a/tests/common/mod.rs b/tests/common/mod.rs
index 36237df13..2614b79b7 100644
--- a/tests/common/mod.rs
+++ b/tests/common/mod.rs
@@ -993,6 +993,17 @@ pub fn set_temp_home_env(cmd: &mut Command, home: &Path) {
cmd.env("APPDATA", home.join(".config"));
}
+/// Override `WORKTRUNK_CONFIG_PATH` to point to the XDG-derived user config path
+/// under `home`. Use this after `set_temp_home_env` in tests that write user
+/// config at the XDG path and need `config create`/`config show` to find it.
+pub fn set_xdg_config_path(cmd: &mut Command, home: &Path) {
+ let home = canonicalize(home).unwrap_or_else(|_| home.to_path_buf());
+ cmd.env(
+ "WORKTRUNK_CONFIG_PATH",
+ home.join(".config").join("worktrunk").join("config.toml"),
+ );
+}
+
/// Check that a git command succeeded, panicking with diagnostics if not.
///
/// Use this after `git_command().output()` to ensure the command succeeded.
diff --git a/tests/integration_tests/config_init.rs b/tests/integration_tests/config_init.rs
index 52fb9f5f5..2ebf78bed 100644
--- a/tests/integration_tests/config_init.rs
+++ b/tests/integration_tests/config_init.rs
@@ -1,6 +1,6 @@
use crate::common::{
- TestRepo, make_snapshot_cmd, repo, set_temp_home_env, setup_home_snapshot_settings,
- setup_snapshot_settings, temp_home, wt_command,
+ TestRepo, make_snapshot_cmd, repo, set_temp_home_env, set_xdg_config_path,
+ setup_home_snapshot_settings, setup_snapshot_settings, temp_home, wt_command,
};
use insta_cmd::assert_cmd_snapshot;
use rstest::rstest;
@@ -24,6 +24,7 @@ fn test_config_init_already_exists(temp_home: TempDir) {
let mut cmd = wt_command();
cmd.arg("config").arg("create");
set_temp_home_env(&mut cmd, temp_home.path());
+ set_xdg_config_path(&mut cmd, temp_home.path());
assert_cmd_snapshot!(cmd, @"
success: true
@@ -48,6 +49,7 @@ fn test_config_init_creates_file(temp_home: TempDir) {
let mut cmd = wt_command();
cmd.arg("config").arg("create");
set_temp_home_env(&mut cmd, temp_home.path());
+ set_xdg_config_path(&mut cmd, temp_home.path());
assert_cmd_snapshot!(cmd, @"
success: true
diff --git a/tests/integration_tests/config_show.rs b/tests/integration_tests/config_show.rs
index 1715f0071..51a4e5b13 100644
--- a/tests/integration_tests/config_show.rs
+++ b/tests/integration_tests/config_show.rs
@@ -1,6 +1,6 @@
use crate::common::{
- TestRepo, repo, set_temp_home_env, setup_snapshot_settings, setup_snapshot_settings_with_home,
- temp_home, wt_command,
+ TestRepo, repo, set_temp_home_env, set_xdg_config_path, setup_snapshot_settings,
+ setup_snapshot_settings_with_home, temp_home, wt_command,
};
use insta_cmd::assert_cmd_snapshot;
use rstest::rstest;
@@ -49,6 +49,7 @@ server = "npm run dev"
repo.configure_mock_commands(&mut cmd);
cmd.arg("config").arg("show").current_dir(repo.root_path());
set_temp_home_env(&mut cmd, temp_home.path());
+ set_xdg_config_path(&mut cmd, temp_home.path());
assert_cmd_snapshot!(cmd);
});
@@ -76,6 +77,7 @@ fn test_config_show_no_project_config(mut repo: TestRepo, temp_home: TempDir) {
repo.configure_mock_commands(&mut cmd);
cmd.arg("config").arg("show").current_dir(repo.root_path());
set_temp_home_env(&mut cmd, temp_home.path());
+ set_xdg_config_path(&mut cmd, temp_home.path());
assert_cmd_snapshot!(cmd);
});
@@ -120,6 +122,7 @@ command = "company-llm-tool"
cmd.env("WORKTRUNK_SYSTEM_CONFIG_PATH", &system_config_path);
cmd.arg("config").arg("show").current_dir(repo.root_path());
set_temp_home_env(&mut cmd, temp_home.path());
+ set_xdg_config_path(&mut cmd, temp_home.path());
assert_cmd_snapshot!(cmd);
});
@@ -374,6 +377,7 @@ fn test_config_show_system_config_hint_under_user_config(repo: TestRepo, temp_ho
let mut cmd = wt_command();
repo.configure_wt_cmd(&mut cmd);
set_temp_home_env(&mut cmd, temp_home.path());
+ set_xdg_config_path(&mut cmd, temp_home.path());
cmd.env_remove("WORKTRUNK_SYSTEM_CONFIG_PATH");
cmd.arg("config").arg("show").current_dir(repo.root_path());
@@ -489,6 +493,7 @@ fn test_config_show_empty_system_config(mut repo: TestRepo, temp_home: TempDir)
cmd.env("WORKTRUNK_SYSTEM_CONFIG_PATH", &system_config_path);
cmd.arg("config").arg("show").current_dir(repo.root_path());
set_temp_home_env(&mut cmd, temp_home.path());
+ set_xdg_config_path(&mut cmd, temp_home.path());
assert_cmd_snapshot!(cmd);
});
@@ -517,6 +522,7 @@ fn test_config_show_invalid_system_config(mut repo: TestRepo, temp_home: TempDir
cmd.env("WORKTRUNK_SYSTEM_CONFIG_PATH", &system_config_path);
cmd.arg("config").arg("show").current_dir(repo.root_path());
set_temp_home_env(&mut cmd, temp_home.path());
+ set_xdg_config_path(&mut cmd, temp_home.path());
assert_cmd_snapshot!(cmd);
});
@@ -575,6 +581,7 @@ fn test_config_show_outside_git_repo(mut repo: TestRepo, temp_home: TempDir) {
repo.configure_mock_commands(&mut cmd);
cmd.arg("config").arg("show").current_dir(temp_dir.path());
set_temp_home_env(&mut cmd, temp_home.path());
+ set_xdg_config_path(&mut cmd, temp_home.path());
assert_cmd_snapshot!(cmd);
});
@@ -608,6 +615,7 @@ if command -v wt >/dev/null 2>&1; then eval "$(command wt config shell init zsh)
cmd.env("WORKTRUNK_TEST_COMPINIT_MISSING", "1");
cmd.arg("config").arg("show").current_dir(repo.root_path());
set_temp_home_env(&mut cmd, temp_home.path());
+ set_xdg_config_path(&mut cmd, temp_home.path());
assert_cmd_snapshot!(cmd);
});
@@ -648,6 +656,7 @@ if command -v wt >/dev/null 2>&1; then eval "$(command wt config shell init zsh)
repo.configure_mock_commands(&mut cmd);
cmd.arg("config").arg("show").current_dir(repo.root_path());
set_temp_home_env(&mut cmd, temp_home.path());
+ set_xdg_config_path(&mut cmd, temp_home.path());
cmd.env("WORKTRUNK_TEST_COMPINIT_CONFIGURED", "1"); // Bypass zsh subprocess check
assert_cmd_snapshot!(cmd);
@@ -687,6 +696,7 @@ fn test_config_show_fish_with_completions(mut repo: TestRepo, temp_home: TempDir
repo.configure_mock_commands(&mut cmd);
cmd.arg("config").arg("show").current_dir(repo.root_path());
set_temp_home_env(&mut cmd, temp_home.path());
+ set_xdg_config_path(&mut cmd, temp_home.path());
assert_cmd_snapshot!(cmd);
});
@@ -722,6 +732,7 @@ fn test_config_show_fish_without_completions(mut repo: TestRepo, temp_home: Temp
repo.configure_mock_commands(&mut cmd);
cmd.arg("config").arg("show").current_dir(repo.root_path());
set_temp_home_env(&mut cmd, temp_home.path());
+ set_xdg_config_path(&mut cmd, temp_home.path());
assert_cmd_snapshot!(cmd);
});
@@ -752,6 +763,7 @@ fn test_config_show_fish_outdated_wrapper(mut repo: TestRepo, temp_home: TempDir
repo.configure_mock_commands(&mut cmd);
cmd.arg("config").arg("show").current_dir(repo.root_path());
set_temp_home_env(&mut cmd, temp_home.path());
+ set_xdg_config_path(&mut cmd, temp_home.path());
assert_cmd_snapshot!(cmd);
});
@@ -786,6 +798,7 @@ if command -v wt >/dev/null 2>&1; then eval "$(command wt config shell init zsh)
repo.configure_mock_commands(&mut cmd);
cmd.arg("config").arg("show").current_dir(repo.root_path());
set_temp_home_env(&mut cmd, temp_home.path());
+ set_xdg_config_path(&mut cmd, temp_home.path());
cmd.env("WORKTRUNK_TEST_COMPINIT_CONFIGURED", "1"); // Bypass zsh subprocess check (unreliable on CI)
assert_cmd_snapshot!(cmd);
@@ -832,6 +845,7 @@ if command -v wt >/dev/null 2>&1; then eval "$(command wt config shell init zsh)
);
cmd.arg("config").arg("show").current_dir(repo.root_path());
set_temp_home_env(&mut cmd, temp_home.path());
+ set_xdg_config_path(&mut cmd, temp_home.path());
let output = cmd.output().unwrap();
assert!(output.status.success());
@@ -880,6 +894,7 @@ if command -v wt >/dev/null 2>&1; then eval "$(command wt config shell init zsh)
);
cmd.arg("config").arg("show").current_dir(repo.root_path());
set_temp_home_env(&mut cmd, temp_home.path());
+ set_xdg_config_path(&mut cmd, temp_home.path());
let output = cmd.output().unwrap();
assert!(output.status.success());
@@ -921,6 +936,7 @@ fn test_config_show_warns_unknown_project_keys(mut repo: TestRepo, temp_home: Te
repo.configure_mock_commands(&mut cmd);
cmd.arg("config").arg("show").current_dir(repo.root_path());
set_temp_home_env(&mut cmd, temp_home.path());
+ set_xdg_config_path(&mut cmd, temp_home.path());
assert_cmd_snapshot!(cmd);
});
@@ -947,6 +963,7 @@ fn test_config_show_warns_unknown_user_keys(mut repo: TestRepo, temp_home: TempD
repo.configure_mock_commands(&mut cmd);
cmd.arg("config").arg("show").current_dir(repo.root_path());
set_temp_home_env(&mut cmd, temp_home.path());
+ set_xdg_config_path(&mut cmd, temp_home.path());
assert_cmd_snapshot!(cmd);
});
@@ -1018,6 +1035,7 @@ fn test_config_show_suggests_user_config_for_commit_generation(
repo.configure_mock_commands(&mut cmd);
cmd.arg("config").arg("show").current_dir(repo.root_path());
set_temp_home_env(&mut cmd, temp_home.path());
+ set_xdg_config_path(&mut cmd, temp_home.path());
assert_cmd_snapshot!(cmd);
});
@@ -1045,6 +1063,7 @@ fn test_config_show_suggests_project_config_for_ci(mut repo: TestRepo, temp_home
repo.configure_mock_commands(&mut cmd);
cmd.arg("config").arg("show").current_dir(repo.root_path());
set_temp_home_env(&mut cmd, temp_home.path());
+ set_xdg_config_path(&mut cmd, temp_home.path());
assert_cmd_snapshot!(cmd);
});
@@ -1070,6 +1089,7 @@ fn test_config_show_invalid_user_toml(mut repo: TestRepo, temp_home: TempDir) {
repo.configure_mock_commands(&mut cmd);
cmd.arg("config").arg("show").current_dir(repo.root_path());
set_temp_home_env(&mut cmd, temp_home.path());
+ set_xdg_config_path(&mut cmd, temp_home.path());
assert_cmd_snapshot!(cmd);
});
@@ -1100,6 +1120,7 @@ fn test_config_show_invalid_project_toml(mut repo: TestRepo, temp_home: TempDir)
repo.configure_mock_commands(&mut cmd);
cmd.arg("config").arg("show").current_dir(repo.root_path());
set_temp_home_env(&mut cmd, temp_home.path());
+ set_xdg_config_path(&mut cmd, temp_home.path());
assert_cmd_snapshot!(cmd);
});
@@ -1125,8 +1146,6 @@ fn test_config_show_full_not_configured(mut repo: TestRepo, temp_home: TempDir)
let mut cmd = wt_command();
repo.configure_wt_cmd(&mut cmd);
repo.configure_mock_commands(&mut cmd);
- // Override WORKTRUNK_CONFIG_PATH to point to our test config
- cmd.env("WORKTRUNK_CONFIG_PATH", &config_path);
// Inject current version for deterministic version check output
cmd.env("WORKTRUNK_TEST_LATEST_VERSION", env!("CARGO_PKG_VERSION"));
cmd.arg("config")
@@ -1134,6 +1153,7 @@ fn test_config_show_full_not_configured(mut repo: TestRepo, temp_home: TempDir)
.arg("--full")
.current_dir(repo.root_path());
set_temp_home_env(&mut cmd, temp_home.path());
+ set_xdg_config_path(&mut cmd, temp_home.path());
assert_cmd_snapshot!(cmd);
});
@@ -1163,8 +1183,6 @@ command = "nonexistent-llm-command-12345 -m test-model"
let mut cmd = wt_command();
repo.configure_wt_cmd(&mut cmd);
repo.configure_mock_commands(&mut cmd);
- // Override WORKTRUNK_CONFIG_PATH to point to our test config
- cmd.env("WORKTRUNK_CONFIG_PATH", &config_path);
// Inject current version for deterministic version check output
cmd.env("WORKTRUNK_TEST_LATEST_VERSION", env!("CARGO_PKG_VERSION"));
cmd.arg("config")
@@ -1172,6 +1190,7 @@ command = "nonexistent-llm-command-12345 -m test-model"
.arg("--full")
.current_dir(repo.root_path());
set_temp_home_env(&mut cmd, temp_home.path());
+ set_xdg_config_path(&mut cmd, temp_home.path());
assert_cmd_snapshot!(cmd);
});
@@ -1197,7 +1216,6 @@ fn test_config_show_full_update_available(mut repo: TestRepo, temp_home: TempDir
let mut cmd = wt_command();
repo.configure_wt_cmd(&mut cmd);
repo.configure_mock_commands(&mut cmd);
- cmd.env("WORKTRUNK_CONFIG_PATH", &config_path);
// Inject a higher version to trigger update-available message
cmd.env("WORKTRUNK_TEST_LATEST_VERSION", "99.0.0");
cmd.arg("config")
@@ -1205,6 +1223,7 @@ fn test_config_show_full_update_available(mut repo: TestRepo, temp_home: TempDir
.arg("--full")
.current_dir(repo.root_path());
set_temp_home_env(&mut cmd, temp_home.path());
+ set_xdg_config_path(&mut cmd, temp_home.path());
assert_cmd_snapshot!(cmd);
});
@@ -1228,7 +1247,6 @@ fn test_config_show_full_version_check_unavailable(mut repo: TestRepo, temp_home
let mut cmd = wt_command();
repo.configure_wt_cmd(&mut cmd);
repo.configure_mock_commands(&mut cmd);
- cmd.env("WORKTRUNK_CONFIG_PATH", &config_path);
// Simulate a fetch failure
cmd.env("WORKTRUNK_TEST_LATEST_VERSION", "error");
cmd.arg("config")
@@ -1236,6 +1254,7 @@ fn test_config_show_full_version_check_unavailable(mut repo: TestRepo, temp_home
.arg("--full")
.current_dir(repo.root_path());
set_temp_home_env(&mut cmd, temp_home.path());
+ set_xdg_config_path(&mut cmd, temp_home.path());
assert_cmd_snapshot!(cmd);
});
@@ -1274,6 +1293,7 @@ fn test_config_show_github_remote(mut repo: TestRepo, temp_home: TempDir) {
repo.configure_mock_commands(&mut cmd);
cmd.arg("config").arg("show").current_dir(repo.root_path());
set_temp_home_env(&mut cmd, temp_home.path());
+ set_xdg_config_path(&mut cmd, temp_home.path());
assert_cmd_snapshot!(cmd);
});
@@ -1312,6 +1332,7 @@ fn test_config_show_gitlab_remote(mut repo: TestRepo, temp_home: TempDir) {
repo.configure_mock_commands(&mut cmd);
cmd.arg("config").arg("show").current_dir(repo.root_path());
set_temp_home_env(&mut cmd, temp_home.path());
+ set_xdg_config_path(&mut cmd, temp_home.path());
assert_cmd_snapshot!(cmd);
});
@@ -1344,6 +1365,7 @@ fn test_config_show_empty_project_config(mut repo: TestRepo, temp_home: TempDir)
repo.configure_mock_commands(&mut cmd);
cmd.arg("config").arg("show").current_dir(repo.root_path());
set_temp_home_env(&mut cmd, temp_home.path());
+ set_xdg_config_path(&mut cmd, temp_home.path());
assert_cmd_snapshot!(cmd);
});
@@ -1376,6 +1398,7 @@ fn test_config_show_whitespace_only_project_config(mut repo: TestRepo, temp_home
repo.configure_mock_commands(&mut cmd);
cmd.arg("config").arg("show").current_dir(repo.root_path());
set_temp_home_env(&mut cmd, temp_home.path());
+ set_xdg_config_path(&mut cmd, temp_home.path());
assert_cmd_snapshot!(cmd);
});
@@ -1397,6 +1420,7 @@ fn test_config_show_no_user_config(mut repo: TestRepo, temp_home: TempDir) {
repo.configure_mock_commands(&mut cmd);
cmd.arg("config").arg("show").current_dir(repo.root_path());
set_temp_home_env(&mut cmd, temp_home.path());
+ set_xdg_config_path(&mut cmd, temp_home.path());
assert_cmd_snapshot!(cmd);
});
@@ -1433,6 +1457,7 @@ alias wt="git worktree"
repo.configure_mock_commands(&mut cmd);
cmd.arg("config").arg("show").current_dir(repo.root_path());
set_temp_home_env(&mut cmd, temp_home.path());
+ set_xdg_config_path(&mut cmd, temp_home.path());
cmd.env("WORKTRUNK_TEST_COMPINIT_CONFIGURED", "1");
assert_cmd_snapshot!(cmd);
@@ -1465,6 +1490,7 @@ post-create = "ln -sf {{ repo_root }}/node_modules {{ worktree }}/node_modules"
repo.configure_wt_cmd(&mut cmd);
cmd.arg("list").current_dir(repo.root_path());
set_temp_home_env(&mut cmd, temp_home.path());
+ cmd.env("WORKTRUNK_CONFIG_PATH", config_path);
assert_cmd_snapshot!(cmd);
});
@@ -1513,6 +1539,7 @@ post-create = "ln -sf {{ repo_root }}/node_modules {{ worktree }}/node_modules"
repo.configure_wt_cmd(&mut cmd);
cmd.args(["-v", "list"]).current_dir(repo.root_path());
set_temp_home_env(&mut cmd, temp_home.path());
+ cmd.env("WORKTRUNK_CONFIG_PATH", config_path);
assert_cmd_snapshot!(cmd);
});
@@ -1860,6 +1887,7 @@ fn test_user_config_deprecated_variables_deduplication(repo: TestRepo, temp_home
let mut cmd = repo.wt_command();
cmd.arg("list").current_dir(repo.root_path());
set_temp_home_env(&mut cmd, temp_home.path());
+ cmd.env("WORKTRUNK_CONFIG_PATH", &user_config_path);
let output = cmd.output().unwrap();
assert!(
output.status.success(),
@@ -1880,6 +1908,7 @@ fn test_user_config_deprecated_variables_deduplication(repo: TestRepo, temp_home
let mut cmd = repo.wt_command();
cmd.arg("list").current_dir(repo.root_path());
set_temp_home_env(&mut cmd, temp_home.path());
+ cmd.env("WORKTRUNK_CONFIG_PATH", &user_config_path);
let output = cmd.output().unwrap();
let stderr = String::from_utf8_lossy(&output.stderr);
assert!(
@@ -1928,6 +1957,7 @@ fn test_config_show_shell_integration_active(mut repo: TestRepo, temp_home: Temp
repo.configure_mock_commands(&mut cmd);
cmd.arg("config").arg("show").current_dir(repo.root_path());
set_temp_home_env(&mut cmd, temp_home.path());
+ set_xdg_config_path(&mut cmd, temp_home.path());
// Set WORKTRUNK_DIRECTIVE_FILE to simulate shell integration being active
cmd.env("WORKTRUNK_DIRECTIVE_FILE", &directive_file);
@@ -1960,6 +1990,7 @@ fn test_config_show_plugin_installed(mut repo: TestRepo, temp_home: TempDir) {
repo.configure_mock_commands(&mut cmd);
cmd.arg("config").arg("show").current_dir(repo.root_path());
set_temp_home_env(&mut cmd, temp_home.path());
+ set_xdg_config_path(&mut cmd, temp_home.path());
assert_cmd_snapshot!(cmd);
});
@@ -1989,6 +2020,7 @@ fn test_config_show_claude_available_plugin_not_installed(mut repo: TestRepo, te
repo.configure_mock_commands(&mut cmd);
cmd.arg("config").arg("show").current_dir(repo.root_path());
set_temp_home_env(&mut cmd, temp_home.path());
+ set_xdg_config_path(&mut cmd, temp_home.path());
assert_cmd_snapshot!(cmd);
});
@@ -2020,6 +2052,7 @@ fn test_config_show_statusline_configured(mut repo: TestRepo, temp_home: TempDir
repo.configure_mock_commands(&mut cmd);
cmd.arg("config").arg("show").current_dir(repo.root_path());
set_temp_home_env(&mut cmd, temp_home.path());
+ set_xdg_config_path(&mut cmd, temp_home.path());
assert_cmd_snapshot!(cmd);
});
@@ -2069,6 +2102,7 @@ fn test_config_show_powershell_detected_via_psmodulepath(mut repo: TestRepo, tem
repo.configure_mock_commands(&mut cmd);
cmd.arg("config").arg("show").current_dir(repo.root_path());
set_temp_home_env(&mut cmd, temp_home.path());
+ set_xdg_config_path(&mut cmd, temp_home.path());
// Enable PowerShell scanning so the profile above is detected
cmd.env("WORKTRUNK_TEST_POWERSHELL_ENV", "1");
// Ensure SHELL is NOT set (already removed by configure_cli_command)
@@ -2106,6 +2140,7 @@ args = ["-m", "haiku"]
repo.configure_wt_cmd(&mut cmd);
cmd.arg("list").current_dir(repo.root_path());
set_temp_home_env(&mut cmd, temp_home.path());
+ cmd.env("WORKTRUNK_CONFIG_PATH", config_path);
assert_cmd_snapshot!(cmd);
});
@@ -2163,6 +2198,7 @@ command = "llm -m gpt-4"
repo.configure_wt_cmd(&mut cmd);
cmd.arg("list").current_dir(repo.root_path());
set_temp_home_env(&mut cmd, temp_home.path());
+ cmd.env("WORKTRUNK_CONFIG_PATH", config_path);
assert_cmd_snapshot!(cmd);
});
@@ -2206,6 +2242,7 @@ post-create = "ln -sf {{ repo_root }}/node_modules"
repo.configure_mock_commands(&mut cmd);
cmd.arg("config").arg("show").current_dir(repo.root_path());
set_temp_home_env(&mut cmd, temp_home.path());
+ set_xdg_config_path(&mut cmd, temp_home.path());
assert_cmd_snapshot!(cmd);
});
@@ -2266,6 +2303,7 @@ fn test_config_show_always_regenerates_migration_file(mut repo: TestRepo, temp_h
repo.configure_mock_commands(&mut cmd);
cmd.arg("config").arg("show").current_dir(repo.root_path());
set_temp_home_env(&mut cmd, temp_home.path());
+ set_xdg_config_path(&mut cmd, temp_home.path());
assert_cmd_snapshot!(cmd);
});
@@ -2325,6 +2363,7 @@ fn test_config_show_from_linked_worktree_shows_main_worktree_hint(
repo.configure_mock_commands(&mut cmd);
cmd.arg("config").arg("show").current_dir(&feature_path);
set_temp_home_env(&mut cmd, temp_home.path());
+ set_xdg_config_path(&mut cmd, temp_home.path());
assert_cmd_snapshot!(cmd);
});
@@ -2359,6 +2398,7 @@ command = "llm -m gpt-4"
repo.configure_mock_commands(&mut cmd);
cmd.arg("config").arg("show").current_dir(repo.root_path());
set_temp_home_env(&mut cmd, temp_home.path());
+ set_xdg_config_path(&mut cmd, temp_home.path());
assert_cmd_snapshot!(cmd);
});
@@ -2394,6 +2434,7 @@ approved-commands = ["npm install", "npm test"]
repo.configure_wt_cmd(&mut cmd);
cmd.arg("list").current_dir(repo.root_path());
set_temp_home_env(&mut cmd, temp_home.path());
+ cmd.env("WORKTRUNK_CONFIG_PATH", config_path);
assert_cmd_snapshot!(cmd);
});
diff --git a/tests/integration_tests/configure_shell.rs b/tests/integration_tests/configure_shell.rs
index 13abd67a5..ac3c7cfc1 100644
--- a/tests/integration_tests/configure_shell.rs
+++ b/tests/integration_tests/configure_shell.rs
@@ -1,5 +1,6 @@
use crate::common::{
- TestRepo, repo, set_temp_home_env, setup_home_snapshot_settings, temp_home, wt_command,
+ TestRepo, repo, set_temp_home_env, set_xdg_config_path, setup_home_snapshot_settings,
+ temp_home, wt_command,
};
use insta_cmd::assert_cmd_snapshot;
use rstest::rstest;
@@ -545,6 +546,7 @@ fn test_config_show_detects_fish_legacy_conf_d(mut repo: TestRepo, temp_home: Te
settings.bind(|| {
let mut cmd = repo.wt_command();
set_temp_home_env(&mut cmd, temp_home.path());
+ set_xdg_config_path(&mut cmd, temp_home.path());
cmd.env("SHELL", "/bin/fish");
cmd.arg("config").arg("show").current_dir(repo.root_path());
@@ -578,6 +580,7 @@ fn test_config_show_fish_legacy_with_functions_dir(mut repo: TestRepo, temp_home
settings.bind(|| {
let mut cmd = repo.wt_command();
set_temp_home_env(&mut cmd, temp_home.path());
+ set_xdg_config_path(&mut cmd, temp_home.path());
cmd.env("SHELL", "/bin/fish");
cmd.arg("config").arg("show").current_dir(repo.root_path());