Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
fix(fish): detect outdated shell wrapper instead of showing "Not configured" (#1009)
Maximilian Roos09b1f5899999
diff --git a/src/commands/config/show.rs b/src/commands/config/show.rsindex a72672773..d8f834b2d 100644--- a/src/commands/config/show.rs+++ b/src/commands/config/show.rs@@ -737,6 +737,18 @@ fn render_shell_status(out: &mut String) -> anyhow::Result<()> {"To migrate to <bright-black>{canonical_path}</>, run <bright-black>{cmd} config shell install fish</>")))?;+ } else if matches!(shell, Shell::Fish)+ && matches!(result.action, ConfigAction::WouldAdd)+ {+ // Fish file exists but has different content (e.g. outdated version)+ any_not_configured = true;+ let warning = warning_message(cformat!(+ "<bold>{shell}</>: Outdated shell extension @ {path}"+ ));+ let hint = hint_message(cformat!(+ "To update, run <bright-black>{cmd} config shell install fish</>"+ ));+ writeln!(out, "{warning}\n{hint}")?;} else {any_not_configured = true;writeln!(diff --git a/src/commands/configure_shell.rs b/src/commands/configure_shell.rsindex 24a95ca13..886d204a6 100644--- a/src/commands/configure_shell.rs+++ b/src/commands/configure_shell.rs@@ -563,6 +563,18 @@ fn configure_shell_file(}}+/// Extract non-comment, non-blank lines from fish source for comparison.+///+/// This lets us detect existing installations even when comment text has changed+/// between versions (e.g. updated documentation URLs).+fn fish_code_lines(source: &str) -> Vec<&str> {+ source+ .lines()+ .map(|l| l.trim())+ .filter(|l| !l.is_empty() && !l.starts_with('#'))+ .collect()+}+fn configure_fish_file(shell: Shell,path: &Path,@@ -582,9 +594,9 @@ fn configure_fish_file(.then(|| fs::read_to_string(path).ok()).flatten(){- // Canonical detection: check if the file matches exactly what we write- // Trim both sides to handle trailing newlines consistently across platforms- if existing_content.trim() == content.trim() {+ // Compare only non-comment lines so that comment changes (e.g. updated+ // URLs) don't cause existing installations to appear unconfigured.+ if fish_code_lines(&existing_content) == fish_code_lines(content) {return Ok(Some(ConfigureResult {shell,path: path.to_path_buf(),@@ -1376,4 +1388,20 @@ mod tests {// Note: should_auto_configure_powershell() is tested via WORKTRUNK_TEST_POWERSHELL_ENV// override in tests/integration_tests/configure_shell.rs.++ #[test]+ fn test_fish_code_lines_strips_comments_and_blanks() {+ let source = "# comment\n\nfunction wt\n command wt $argv\nend\n";+ assert_eq!(+ fish_code_lines(source),+ vec!["function wt", "command wt $argv", "end"]+ );+ }++ #[test]+ fn test_fish_code_lines_matches_despite_different_comments() {+ let old = "# Docs: https://worktrunk.dev/docs/shell-integration\nfunction wt\n command wt $argv\nend";+ let new = "# Docs: https://worktrunk.dev/config/#shell-integration\nfunction wt\n command wt $argv\nend";+ assert_eq!(fish_code_lines(old), fish_code_lines(new));+ }}diff --git a/tests/common/mod.rs b/tests/common/mod.rsindex 2872e9c87..510dfbca1 100644--- a/tests/common/mod.rs+++ b/tests/common/mod.rs@@ -2762,10 +2762,12 @@ fn setup_snapshot_settings_for_paths_with_home(// Format: "* " + yellow code + 7-char hex hash + resetsettings.add_filter(r"\* \x1b\[33m[a-f0-9]{7}\x1b\[m", "* \x1b[33m[HASH]\x1b[m");- // Filter out CARGO_LLVM_COV env variables from snapshot YAML headers.+ // Filter out cargo-llvm-cov env variables from snapshot YAML headers.// These are only present during coverage runs and cause snapshot mismatches.- settings.add_filter(r#" CARGO_LLVM_COV: "1"\n"#, "");- settings.add_filter(r#" CARGO_LLVM_COV_TARGET_DIR: "[^"]+"\n"#, "");+ // Note: YAML indentation in the info.env section is 4 spaces.+ settings.add_filter(r#" CARGO_LLVM_COV: "1"\n"#, "");+ settings.add_filter(r#" CARGO_LLVM_COV_TARGET_DIR: "[^"]+"\n"#, "");+ settings.add_filter(r#" LLVM_PROFILE_FILE: "[^"]+"\n"#, "");settings}diff --git a/tests/integration_tests/config_show.rs b/tests/integration_tests/config_show.rsindex 542fbdc78..41d9261f1 100644--- a/tests/integration_tests/config_show.rs+++ b/tests/integration_tests/config_show.rs@@ -252,6 +252,36 @@ 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+#[rstest]+fn test_config_show_fish_outdated_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();++ // Create fish functions directory with an outdated wt.fish (different functional code)+ 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();++ 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());++ 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 outputdiff --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.snapnew file mode 100644index 000000000..bdaf4dcaf--- /dev/null+++ b/tests/snapshots/integration__integration_tests__config_show__config_show_fish_outdated_wrapper.snap@@ -0,0 +1,66 @@+---+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]"+ PATH: "[PATH]"+ PSModulePath: ""+ RUST_LOG: warn+ SHELL: ""+ TERM: alacritty+ USERPROFILE: "[TEST_HOME]"+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"+ WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"+ WORKTRUNK_TEST_POWERSHELL_ENV: "0"+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"+ WT_TEST_DELAYED_STREAM_MS: "-1"+ WT_TEST_EPOCH: "1735776000"+ 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++[33m▲[39m [33m[1mfish[22m: Outdated shell extension @ ~/.config/fish/functions/wt.fish[39m+[2m↳[22m [2mTo update, run [90mwt config shell install fish[39m[22m+[2m○[22m [2mbash: Skipped; ~/.bashrc not found[22m+[2m○[22m [2mzsh: Skipped; ~/.zshrc not found[22m+[2m↳[22m [2mTo configure, run [90mwt config shell install[39m[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 installed++[36mOTHER[39m+[2m○[22m wt: [1m[VERSION][22m+[2m○[22m git: [1m[VERSION][22m+[2m○[22m Hyperlinks: [1minactive[22m