Skip to content

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

test(config): cover .exe alias hints in config show (#2612)

Maximilian Rooseb7425a6a4f7
diff --git a/tests/integration_tests/config_show.rs b/tests/integration_tests/config_show.rs
index 9a7e8cd5d..1e06f6007 100644
--- a/tests/integration_tests/config_show.rs
+++ b/tests/integration_tests/config_show.rs
@@ -843,6 +843,60 @@ fn test_config_show_nushell_outdated_wrapper(mut repo: TestRepo, temp_home: Temp
});
}
+/// Cover the `.exe` alias hint inside `render_already_configured`. The hint
+/// fires when at least one matched integration line in the rc file uses
+/// `wt.exe` — common on Git Bash where the binary is `wt.exe` but POSIX
+/// aliases must still target `wt`. We pair the canonical line (so the row
+/// hits `AlreadyExists`) with an extra `wt.exe` line in the same file so
+/// `detection.matched_lines` carries the `.exe` content.
+#[rstest]
+fn test_config_show_bash_matched_exe_emits_alias_hint(mut repo: TestRepo, temp_home: TempDir) {
+ repo.setup_mock_ci_tools_unauthenticated();
+
+ 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"), "").unwrap();
+
+ fs::write(
+ temp_home.path().join(".bashrc"),
+ r#"# Canonical line so the row reports AlreadyExists.
+if command -v wt >/dev/null 2>&1; then eval "$(command wt config shell init bash)"; fi
+# Stale wt.exe form left over from a Windows install — scan_for_detection_details
+# still recognizes it as a matched integration line.
+eval "$(wt.exe config shell init bash)"
+"#,
+ )
+ .unwrap();
+
+ let settings = setup_snapshot_settings_with_home(&repo, &temp_home);
+ settings.bind(|| {
+ let mut cmd = wt_command();
+ repo.configure_wt_cmd(&mut cmd);
+ 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");
+ cmd.env("WORKTRUNK_TEST_BASH_INSTALLED", "1");
+ // SHELL=bash so current_shell() == Bash and the verify-wrapper hint
+ // appears under bash (not duplicated for other shells).
+ cmd.env("SHELL", "/bin/bash");
+
+ // Pre-snapshot guard: confirm the unredacted output really did emit
+ // the alias hint. The shared `wt\.exe` → `wt` redaction collapses
+ // both `<underline>wt</>` and `<underline>wt.exe</>` to the same
+ // visual `wt` in the snapshot, which would otherwise hide whether
+ // the .exe branch ran at all.
+ let raw = String::from_utf8_lossy(&cmd.output().unwrap().stdout).to_string();
+ assert!(
+ raw.contains("Creates shell function") && raw.contains("not ") && raw.contains(".exe"),
+ "Expected the .exe alias hint in unredacted output, got:\n{raw}"
+ );
+
+ assert_cmd_snapshot!(cmd);
+ });
+}
+
#[rstest]
fn test_config_show_zsh_compinit_correct_order(mut repo: TestRepo, temp_home: TempDir) {
// Setup mock gh/glab for deterministic BINARIES output
@@ -1538,6 +1592,56 @@ alias wt="git worktree"
});
}
+/// Cover the unmatched-candidate `.exe` hint in `render_shell_status`. When
+/// the detector finds a `wt`-mentioning line that doesn't look like a valid
+/// integration AND any of the unmatched candidates contains `.exe`, an
+/// extra hint explains the function-name vs alias-name distinction.
+#[rstest]
+fn test_config_show_unmatched_candidate_exe_emits_extra_hint(
+ mut repo: TestRepo,
+ temp_home: TempDir,
+) {
+ repo.setup_mock_ci_tools_unauthenticated();
+
+ 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"), "").unwrap();
+
+ // `.bashrc` line containing `wt` at a word boundary but not in a
+ // shell-integration shape — the detector flags it as an unmatched
+ // candidate, and the `.exe` token triggers the extra alias hint.
+ // Use `export` rather than `alias` so the line doesn't get classified
+ // as a bypass alias (which would emit a separate warning instead).
+ fs::write(
+ temp_home.path().join(".bashrc"),
+ r#"# Custom shim path pointing at a Windows binary
+export WT_BIN="/c/Program Files/wt.exe"
+"#,
+ )
+ .unwrap();
+
+ let settings = setup_snapshot_settings_with_home(&repo, &temp_home);
+ settings.bind(|| {
+ let mut cmd = wt_command();
+ repo.configure_wt_cmd(&mut cmd);
+ 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");
+
+ // Pre-snapshot guard: the shared `wt\.exe` → `wt` redaction would
+ // otherwise hide whether the unmatched-candidate `.exe` branch ran.
+ let raw = String::from_utf8_lossy(&cmd.output().unwrap().stdout).to_string();
+ assert!(
+ raw.contains("creates shell function") && raw.contains(".exe"),
+ "Expected the .exe alias hint in unredacted output, got:\n{raw}"
+ );
+
+ assert_cmd_snapshot!(cmd);
+ });
+}
+
/// Verify that the unmatched candidate warning fires for a bash alias while being suppressed
/// for a Fish wrapper file in the same `config show` run. This ensures wrapper-file suppression
/// is path-specific and doesn't accidentally silence all unmatched candidate warnings.
diff --git a/tests/snapshots/integration__integration_tests__config_show__config_show_bash_matched_exe_emits_alias_hint.snap b/tests/snapshots/integration__integration_tests__config_show__config_show_bash_matched_exe_emits_alias_hint.snap
new file mode 100644
index 000000000..593d5a4c8
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__config_show__config_show_bash_matched_exe_emits_alias_hint.snap
@@ -0,0 +1,78 @@
+---
+source: tests/integration_tests/config_show.rs
+assertion_line: 885
+info:
+ program: wt
+ args:
+ - config
+ - show
+ env:
+ APPDATA: "[TEST_CONFIG_HOME]"
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "500"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMON_DIR: ""
+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_DIR: ""
+ GIT_EDITOR: ""
+ GIT_INDEX_FILE: ""
+ GIT_OBJECT_DIRECTORY: ""
+ GIT_TERMINAL_PROMPT: "0"
+ GIT_WORK_TREE: ""
+ HOME: "[TEST_HOME]"
+ LANG: C
+ LC_ALL: C
+ MOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"
+ NO_COLOR: ""
+ OPENCODE_CONFIG_DIR: "[TEST_OPENCODE_CONFIG]"
+ PATH: "[PATH]"
+ PSModulePath: ""
+ RUST_LOG: warn
+ SHELL: /bin/bash
+ TERM: alacritty
+ USERPROFILE: "[TEST_HOME]"
+ WORKTRUNK_APPROVALS_PATH: "[TEST_APPROVALS]"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_SYSTEM_CONFIG_PATH: "[TEST_SYSTEM_CONFIG]"
+ WORKTRUNK_TEST_BASH_INSTALLED: "1"
+ WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"
+ WORKTRUNK_TEST_COMPINIT_CONFIGURED: "1"
+ WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"
+ WORKTRUNK_TEST_EPOCH: "1735776000"
+ WORKTRUNK_TEST_FISH_INSTALLED: "0"
+ WORKTRUNK_TEST_NUSHELL_ENV: "0"
+ WORKTRUNK_TEST_OPENCODE_INSTALLED: "0"
+ WORKTRUNK_TEST_POWERSHELL_ENV: "0"
+ WORKTRUNK_TEST_POWERSHELL_INSTALLED: "0"
+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
+ WORKTRUNK_TEST_ZSH_INSTALLED: "0"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
+---
+success: true
+exit_code: 0
+----- stdout -----
+USER CONFIG @ ~/.config/worktrunk/config.toml
+↳ Empty file (using defaults)
+
+PROJECT CONFIG @ _REPO_/.config/wt.toml
+↳ Not found
+
+SHELL INTEGRATION
+▲ Shell integration not active
+  Invoked as: [PROJECT_ROOT]/target/debug/wt
+  $SHELL: /bin/bash
+
+○ bash: Already configured shell extension & completions @ ~/.bashrc:2
+  if command -v wt >/dev/null 2>&1; then eval "$(command wt config shell init bash)"; fi
+  eval "$(wt config shell init bash)"
+↳ Creates shell function wt. Aliases should use wt, not wt
+↳ To verify wrapper loaded: type wt
+
+OTHER
+○ wt: [VERSION]
+○ git: [VERSION]
+○ Hyperlinks: inactive
+
+----- stderr -----
diff --git a/tests/snapshots/integration__integration_tests__config_show__config_show_unmatched_candidate_exe_emits_extra_hint.snap b/tests/snapshots/integration__integration_tests__config_show__config_show_unmatched_candidate_exe_emits_extra_hint.snap
new file mode 100644
index 000000000..666829e0a
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__config_show__config_show_unmatched_candidate_exe_emits_extra_hint.snap
@@ -0,0 +1,78 @@
+---
+source: tests/integration_tests/config_show.rs
+assertion_line: 1622
+info:
+ program: wt
+ args:
+ - config
+ - show
+ env:
+ APPDATA: "[TEST_CONFIG_HOME]"
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "500"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMON_DIR: ""
+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_DIR: ""
+ GIT_EDITOR: ""
+ GIT_INDEX_FILE: ""
+ GIT_OBJECT_DIRECTORY: ""
+ GIT_TERMINAL_PROMPT: "0"
+ GIT_WORK_TREE: ""
+ HOME: "[TEST_HOME]"
+ LANG: C
+ LC_ALL: C
+ MOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"
+ NO_COLOR: ""
+ OPENCODE_CONFIG_DIR: "[TEST_OPENCODE_CONFIG]"
+ PATH: "[PATH]"
+ PSModulePath: ""
+ RUST_LOG: warn
+ SHELL: ""
+ TERM: alacritty
+ USERPROFILE: "[TEST_HOME]"
+ WORKTRUNK_APPROVALS_PATH: "[TEST_APPROVALS]"
+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
+ WORKTRUNK_SYSTEM_CONFIG_PATH: "[TEST_SYSTEM_CONFIG]"
+ WORKTRUNK_TEST_BASH_INSTALLED: "0"
+ WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"
+ WORKTRUNK_TEST_COMPINIT_CONFIGURED: "1"
+ WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"
+ WORKTRUNK_TEST_EPOCH: "1735776000"
+ WORKTRUNK_TEST_FISH_INSTALLED: "0"
+ WORKTRUNK_TEST_NUSHELL_ENV: "0"
+ WORKTRUNK_TEST_OPENCODE_INSTALLED: "0"
+ WORKTRUNK_TEST_POWERSHELL_ENV: "0"
+ WORKTRUNK_TEST_POWERSHELL_INSTALLED: "0"
+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
+ WORKTRUNK_TEST_ZSH_INSTALLED: "0"
+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
+---
+success: true
+exit_code: 0
+----- stdout -----
+USER CONFIG @ ~/.config/worktrunk/config.toml
+↳ Empty file (using defaults)
+
+PROJECT CONFIG @ _REPO_/.config/wt.toml
+↳ Not found
+
+SHELL INTEGRATION
+▲ Shell integration not configured
+↳ To configure, run wt config shell install
+  Invoked as: [PROJECT_ROOT]/target/debug/wt
+
+○ bash: Not configured shell extension & completions
+▲ Found wt in ~/.bashrc:2 but not detected as integration:
+  export WT_BIN="/c/Program Files/wt"
+↳ Note: wt creates shell function wt. Aliases should use wt, not wt
+↳ If `export WT_BIN="/c/Program Files/wt"` is meant to load Worktrunk shell integration, report a false negative: https://github.com/max-sixty/worktrunk/issues/new?title=Shell%20integration%20detection%20false%20negative&body=Shell%20integration%20not%20detected%20despite%20config%20containing%20%60wt%60.%0A%0A%2A%2AUnmatched%20lines%3A%2A%2A%0A%60%60%60%0Aexport%20WT_BIN%3D%22%2Fc%2FProgram%20Files%2Fwt%22%0A%60%60%60%0A%0A%2A%2AExpected%20behavior%3A%2A%2A%20These%20lines%20should%20be%20detected%20as%20shell%20integration.
+
+OTHER
+○ wt: [VERSION]
+○ git: [VERSION]
+○ Hyperlinks: inactive
+
+----- stderr -----