Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
fix: suppress false positive shell integration warning for wrapper files (#1736)
Sascha Brattonbda6d33ac718
diff --git a/src/commands/config/show.rs b/src/commands/config/show.rsindex ee80e72e8..68b121ca2 100644--- a/src/commands/config/show.rs+++ b/src/commands/config/show.rs@@ -3,9 +3,9 @@//! Functions for displaying user config, project config, shell status,//! diagnostics, and runtime info.-use std::collections::HashMap;+use std::collections::{HashMap, HashSet};use std::fmt::Write as _;-use std::path::PathBuf;+use std::path::{Path, PathBuf};use anyhow::Context;use color_print::cformat;@@ -807,7 +807,7 @@ fn render_shell_status(out: &mut String) -> anyhow::Result<()> {"To migrate to <underline>{canonical_path}</>, run <underline>{cmd} config shell install fish</>")))?;- } else if matches!(shell, Shell::Fish | Shell::Nushell)+ } else if shell.is_wrapper_based()&& matches!(result.action, ConfigAction::WouldAdd){// File exists but has different content (e.g. outdated version)@@ -885,8 +885,24 @@ fn render_shell_status(out: &mut String) -> anyhow::Result<()> {// Show potential false negatives (lines containing cmd but not detected)// Skip files that have valid integration detected (matched_lines) - those are fine,// and the other lines containing cmd are just part of the integration script.+ // Also skip files already confirmed as integration by scan_shell_configs (e.g., Nushell/Fish+ // wrapper files that ARE the integration, not config files that source it).+ let confirmed_paths: HashSet<&Path> = scan_result+ .configured+ .iter()+ .filter(|r| {+ // For wrapper-based shells, the file at the path IS the integration — any+ // action means it was recognized. For eval-based shells, only AlreadyExists+ // means the config line was found.+ r.shell.is_wrapper_based() || matches!(r.action, ConfigAction::AlreadyExists)+ })+ .map(|r| r.path.as_path())+ .collect();for detection in &detection_results {- if !detection.unmatched_candidates.is_empty() && detection.matched_lines.is_empty() {+ if !detection.unmatched_candidates.is_empty()+ && detection.matched_lines.is_empty()+ && !confirmed_paths.contains(detection.path.as_path())+ {has_any_unmatched = true;let path = format_path_for_display(&detection.path);@@ -957,10 +973,15 @@ fn render_shell_status(out: &mut String) -> anyhow::Result<()> {.any(|r| matches!(r.action, ConfigAction::AlreadyExists));// If we have unmatched candidates but no configured shells, suggest raising an issue+ // Apply the same confirmed_paths filter used above to avoid including wrapper filesif has_any_unmatched && !has_any_configured {let unmatched_summary: Vec<_> = detection_results.iter()- .filter(|r| !r.unmatched_candidates.is_empty())+ .filter(|r| {+ !r.unmatched_candidates.is_empty()+ && r.matched_lines.is_empty()+ && !confirmed_paths.contains(r.path.as_path())+ }).flat_map(|r| {r.unmatched_candidates.iter()diff --git a/src/commands/configure_shell.rs b/src/commands/configure_shell.rsindex d4d235018..701aab4aa 100644--- a/src/commands/configure_shell.rs+++ b/src/commands/configure_shell.rs@@ -374,7 +374,7 @@ pub fn scan_shell_configs(// For Fish/Nushell, also check if any candidate's parent directory exists// since we create the file there rather than modifying an existing one- let has_config_location = if matches!(shell, Shell::Fish | Shell::Nushell) {+ let has_config_location = if shell.is_wrapper_based() {paths.iter().any(|p| p.parent().is_some_and(|d| d.exists())) || target_path.is_some()} else {target_path.is_some()@@ -411,7 +411,7 @@ pub fn scan_shell_configs(} else if shell_filter.is_none() {// Track skipped shells (only when not explicitly filtering)// For Fish/Nushell, we check for parent directory; for others, the config file- let skipped_path = if matches!(shell, Shell::Fish | Shell::Nushell) {+ let skipped_path = if shell.is_wrapper_based() {paths.first().and_then(|p| p.parent())@@ -452,7 +452,7 @@ fn configure_shell_file(// For Fish and Nushell, we write the full wrapper to a file that gets autoloaded.// This allows updates to worktrunk to automatically provide the latest wrapper logic// without requiring reinstall.- if matches!(shell, Shell::Fish | Shell::Nushell) {+ if shell.is_wrapper_based() {let init = shell::ShellInit::with_prefix(shell, cmd.to_string());let wrapper = if matches!(shell, Shell::Fish) {init.generate_fish_wrapper()diff --git a/src/shell/mod.rs b/src/shell/mod.rsindex 5e3bfb9b7..a02bdffed 100644--- a/src/shell/mod.rs+++ b/src/shell/mod.rs@@ -42,6 +42,19 @@ pub enum Shell {}impl Shell {+ /// Whether this shell uses a standalone wrapper file as integration.+ ///+ /// Wrapper-based shells (Fish, Nushell) install a complete function file that the shell+ /// autoloads. The file itself IS the integration. Eval-based shells (Bash, Zsh, PowerShell)+ /// add an `eval`/`source` line to an existing config file like `.bashrc`.+ ///+ /// This distinction matters for:+ /// - Installation: wrapper files are written whole; eval lines are appended+ /// - Detection: wrapper file presence = confirmed integration, even if outdated+ pub fn is_wrapper_based(&self) -> bool {+ matches!(self, Self::Fish | Self::Nushell)+ }+/// Returns the config file paths for this shell.////// The `cmd` parameter affects the Fish functions filename (e.g., `wt.fish` or `git-wt.fish`).diff --git a/tests/integration_tests/config_show.rs b/tests/integration_tests/config_show.rsindex 962d1cea3..16c9417d6 100644--- a/tests/integration_tests/config_show.rs+++ b/tests/integration_tests/config_show.rs@@ -738,7 +738,13 @@ fn test_config_show_fish_without_completions(mut repo: TestRepo, temp_home: Temp});}-/// Test that config show displays "Outdated" when fish wrapper exists but has different code+/// Test that config show displays "Outdated" when fish wrapper exists but has different code.+///+/// The wrapper file contains `function wt` which matches the command name at a word boundary,+/// but `is_shell_integration_line()` won't match it (it looks for eval/source patterns).+/// This should NOT trigger a "Found wt ... but not detected as integration" warning because+/// the wrapper file IS the integration — `scan_shell_configs` already identified it (as+/// outdated). Only the "Outdated shell extension" warning should appear.#[rstest]fn test_config_show_fish_outdated_wrapper(mut repo: TestRepo, temp_home: TempDir) {repo.setup_mock_ci_tools_unauthenticated();@@ -769,7 +775,12 @@ fn test_config_show_fish_outdated_wrapper(mut repo: TestRepo, temp_home: TempDir});}-/// Test that config show displays "Outdated" when nushell wrapper exists but has different code+/// Test that config show displays "Outdated" when nushell wrapper exists but has different code.+///+/// Same false-positive suppression as the fish variant: the wrapper file contains `def --wrapped wt`+/// which matches the command name, but `scan_shell_configs` already recognized the file as+/// integration (outdated). Only the "Outdated" warning should appear, not the generic+/// "not detected as integration" warning.#[rstest]fn test_config_show_nushell_outdated_wrapper(mut repo: TestRepo, temp_home: TempDir) {repo.setup_mock_ci_tools_unauthenticated();@@ -1495,6 +1506,52 @@ alias wt="git worktree"});}+/// 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.+#[rstest]+fn test_config_show_unmatched_candidate_not_suppressed_by_wrapper(+ 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();++ // Fish wrapper (outdated) — should NOT trigger "not detected" warning+ let functions = temp_home.path().join(".config/fish/functions");+ fs::create_dir_all(&functions).unwrap();+ fs::write(+ functions.join("wt.fish"),+ "# worktrunk shell integration for fish\nfunction wt\n command wt-old $argv\nend\n",+ )+ .unwrap();++ // Bash alias — SHOULD trigger "not detected" warning+ fs::write(+ temp_home.path().join(".bashrc"),+ r#"# Some bash config+alias wt="git worktree"+"#,+ )+ .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");++ assert_cmd_snapshot!(cmd);+ });+}+/// When a config uses deprecated variables (repo_root, worktree, main_worktree),/// the CLI should:/// 1. Show a warning pointing to `wt config show` and `wt config update`diff --git a/tests/integration_tests/snapshot_formatting_guard.rs b/tests/integration_tests/snapshot_formatting_guard.rsindex 018ae6d40..cacd69923 100644--- a/tests/integration_tests/snapshot_formatting_guard.rs+++ b/tests/integration_tests/snapshot_formatting_guard.rs@@ -25,6 +25,7 @@ const BLANK_BEFORE_HINT_ALLOWED: &[&str] = &[// from per-shell status section. The `↳` here is a status item, not a hint."config_show__config_show_partial_shell_config_shows_hint","config_show__config_show_unmatched_candidate_warning",+ "config_show__config_show_unmatched_candidate_not_suppressed_by_wrapper",];#[test]diff --git a/tests/snapshots/integration__integration_tests__config_show__config_show_fish_outdated_wrapper.snap b/tests/snapshots/integration__integration_tests__config_show__config_show_fish_outdated_wrapper.snapindex 6072775d1..6c5478325 100644--- a/tests/snapshots/integration__integration_tests__config_show__config_show_fish_outdated_wrapper.snap+++ b/tests/snapshots/integration__integration_tests__config_show__config_show_fish_outdated_wrapper.snap@@ -1,5 +1,6 @@---source: tests/integration_tests/config_show.rs+assertion_line: 768info:program: wtargs:@@ -58,9 +59,6 @@ exit_code: 0[2m○[22m [2mzsh: Skipped; ~/.zshrc not found[22m[2m○[22m [2mnu: Skipped; ~/.config/nushell/vendor/autoload not found[22m[2m↳[22m [2mTo configure, run [4mwt config shell install[24m[22m-[33m▲[39m [33mFound [1mwt[22m in [1m~/.config/fish/functions/wt.fish:2[22m but not detected as integration:[39m-[107m [0m [2m[0m[2m[35mfunction[0m[2m wt-[2m↳[22m [2mIf `function wt` is 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%0Afunction%20wt%0A%60%60%60%0A%0A%2A%2AExpected%20behavior%3A%2A%2A%20These%20lines%20should%20be%20detected%20as%20shell%20integration.[22m[36mCLAUDE CODE[39m[2m○[22m [1mclaude[22m CLI not installeddiff --git a/tests/snapshots/integration__integration_tests__config_show__config_show_nushell_outdated_wrapper.snap b/tests/snapshots/integration__integration_tests__config_show__config_show_nushell_outdated_wrapper.snapindex 4b76048ff..74ec867d2 100644--- a/tests/snapshots/integration__integration_tests__config_show__config_show_nushell_outdated_wrapper.snap+++ b/tests/snapshots/integration__integration_tests__config_show__config_show_nushell_outdated_wrapper.snap@@ -1,5 +1,6 @@---source: tests/integration_tests/config_show.rs+assertion_line: 799info:program: wtargs:@@ -58,9 +59,6 @@ exit_code: 0[2m○[22m [2mzsh: Skipped; ~/.zshrc not found[22m[2m○[22m [2mfish: Skipped; ~/.config/fish/functions not found[22m[2m↳[22m [2mTo configure, run [4mwt config shell install[24m[22m-[33m▲[39m [33mFound [1mwt[22m in [1m~/.config/nushell/vendor/autoload/wt.nu:2[22m but not detected as integration:[39m-[107m [0m [2m[0m[2m[34mdef[0m[2m [0m[2m[36m--wrapped[0m[2m wt [...args] {-[2m↳[22m [2mIf `def --wrapped wt [...args] {` is 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%0Adef%20--wrapped%20wt%20%5B...args%5D%20%7B%0A%60%60%60%0A%0A%2A%2AExpected%20behavior%3A%2A%2A%20These%20lines%20should%20be%20detected%20as%20shell%20integration.[22m[36mCLAUDE CODE[39m[2m○[22m [1mclaude[22m CLI not installeddiff --git a/tests/snapshots/integration__integration_tests__config_show__config_show_unmatched_candidate_not_suppressed_by_wrapper.snap b/tests/snapshots/integration__integration_tests__config_show__config_show_unmatched_candidate_not_suppressed_by_wrapper.snapnew file mode 100644index 000000000..7dbb4bafd--- /dev/null+++ b/tests/snapshots/integration__integration_tests__config_show__config_show_unmatched_candidate_not_suppressed_by_wrapper.snap@@ -0,0 +1,72 @@+---+source: tests/integration_tests/config_show.rs+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_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"+ GIT_CONFIG_SYSTEM: /dev/null+ GIT_EDITOR: ""+ GIT_TERMINAL_PROMPT: "0"+ HOME: "[TEST_HOME]"+ LANG: C+ LC_ALL: C+ MOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"+ NO_COLOR: ""+ 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_CLAUDE_INSTALLED: "0"+ WORKTRUNK_TEST_COMPINIT_CONFIGURED: "1"+ WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"+ WORKTRUNK_TEST_EPOCH: "1735776000"+ WORKTRUNK_TEST_NUSHELL_ENV: "0"+ WORKTRUNK_TEST_POWERSHELL_ENV: "0"+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"+---+success: true+exit_code: 0+----- stdout -----++----- stderr -----+[36mUSER CONFIG[39m @ ~/.config/worktrunk/config.toml+[2m↳[22m [2mEmpty file (using defaults)[22m++[36mPROJECT CONFIG[39m @ _REPO_/.config/wt.toml+[2m↳[22m [2mNot found[22m++[36mSHELL INTEGRATION[39m+[33m▲[39m [33mShell integration not active[39m+[107m [0m Invoked as: [1m[PROJECT_ROOT]/target/debug/wt[22m++[2m↳[22m [2mbash: Not configured shell extension & completions[22m+[33m▲[39m [33m[1mfish[22m: Outdated shell extension @ ~/.config/fish/functions/wt.fish[39m+[2m↳[22m [2mTo update, run [4mwt config shell install fish[24m[22m+[2m○[22m [2mzsh: Skipped; ~/.zshrc not found[22m+[2m○[22m [2mnu: Skipped; ~/.config/nushell/vendor/autoload not found[22m+[2m↳[22m [2mTo configure, run [4mwt config shell install[24m[22m+[33m▲[39m [33mFound [1mwt[22m in [1m~/.bashrc:2[22m but not detected as integration:[39m+[107m [0m [2m[0m[2m[34malias[0m[2m wt=[0m[2m[32m"git worktree"[0m[2m+[2m↳[22m [2mIf `alias wt="git worktree"` is 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%0Aalias%20wt%3D%22git%20worktree%22%0A%60%60%60%0A%0A%2A%2AExpected%20behavior%3A%2A%2A%20These%20lines%20should%20be%20detected%20as%20shell%20integration.[22m++[36mCLAUDE CODE[39m+[2m○[22m [1mclaude[22m CLI not installed++[36mOTHER[39m+[2m○[22m wt: [1m[VERSION][22m+[2m○[22m git: [1m[VERSION][22m+[2m○[22m Hyperlinks: [1minactive[22m