worktrunk 0.36.0

A CLI for Git worktree management, designed for parallel AI agent workflows
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
//! Shell integration warnings and prompts.
//!
//! # Shell Integration Warning Messages (Complete Spec)
//!
//! When shell integration is not active, warn that cd won't happen.
//!
//! ## Switch to Existing Worktree (`wt switch X` where X exists)
//!
//! | Condition | Warning | Hint |
//! |-----------|---------|------|
//! | Not installed | `Worktree for X @ path, but cannot change directory — shell integration not installed` | `To enable automatic cd, run wt config shell install` |
//! | Needs restart | `Worktree for X @ path, but cannot change directory — shell requires restart` | `Restart shell to activate shell integration` |
//! | Explicit path | `Worktree for X @ path, but cannot change directory — ran ./wt; shell integration wraps wt` | `To change directory, run wt switch X` |
//! | Git subcommand | `Worktree for X @ path, but cannot change directory — ran git wt; running through git prevents cd` | `Use git-wt directly (via shell function) for automatic cd` |
//!
//! ## Switch to New Worktree (`wt switch --create X`)
//!
//! Success message shown first, then warning if shell won't cd:
//!
//! | Condition | Success | Warning | Hint |
//! |-----------|---------|---------|------|
//! | Shell active | `Created new worktree for X from base @ path` | (none) | (none) |
//! | Not installed | `Created new worktree for X from base @ path` | `Cannot change directory — shell integration not installed` | `To enable automatic cd, run wt config shell install` |
//! | Explicit path | `Created new worktree for X from base @ path` | `Cannot change directory — ran ./wt; shell integration wraps wt` | `To change directory, run wt switch X` |
//! | Git subcommand | `Created new worktree for X from base @ path` | `Cannot change directory — ran git wt; running through git prevents cd` | `Use git-wt directly (via shell function) for automatic cd` |
//!
//! ## After Merge/Remove (switching to main worktree)
//!
//! | Condition | Warning | Hint |
//! |-----------|---------|------|
//! | Shell active | (info) `Switched to worktree for main @ path` | (none) |
//! | Git subcommand | `Cannot change directory — ran git wt; running through git prevents cd` | `Use git-wt directly (via shell function) for automatic cd` |
//! | Explicit path | `Cannot change directory — ran ./wt; shell integration wraps wt` | `To change directory, run wt switch main` |
//! | Other | `Cannot change directory — {reason}` | `To enable automatic cd, run wt config shell install` |
//!
//! ## Prompt Decision Flow
//!
//! When shell integration is not active, [`prompt_shell_integration`] decides what to show:
//!
//! | Condition | Action |
//! |-----------|--------|
//! | Git subcommand | Return early (warning already shown) |
//! | Unsupported shell | Hint: `Shell integration not yet supported for <shell>` |
//! | $SHELL not set | Hint: `To enable automatic cd, run wt config shell install` |
//! | Current shell already installed | Hint: `Restart shell to activate shell integration` |
//! | `skip-shell-integration-prompt` / Non-TTY | Hint: `To enable automatic cd, run wt config shell install` |
//! | TTY | Prompt: `Install shell integration? [y/N/?]` |
//!
//! # Reason Values
//!
//! The [`compute_shell_warning_reason`] function returns these reason strings:
//!
//! | Reason | Meaning |
//! |--------|---------|
//! | `shell integration not installed` | Shell config doesn't have the `eval` line |
//! | `shell requires restart` | Shell config has `eval` line but wrapper not active |
//! | `ran X; shell integration wraps Y` | Invoked with explicit path (e.g., `./target/debug/wt`) |
//!
//! Note: The git subcommand case (`ran git wt; ...`) is handled separately via [`crate::is_git_subcommand`].

use std::io::IsTerminal;

use color_print::cformat;
use worktrunk::config::UserConfig;
use worktrunk::path::format_path_for_display;
use worktrunk::shell::{Shell, current_shell, extract_filename_from_path};
use worktrunk::styling::{
    eprintln, format_bash_with_gutter, hint_message, info_message, success_message, warning_message,
};

use crate::commands::configure_shell::{
    ConfigAction, UninstallScanResult, handle_configure_shell, prompt_for_install,
    scan_shell_configs,
};

/// Shell integration install hint message.
// TODO(hints-count): After showing this hint 5+ times, suggest `wt config show` for diagnostics.
// This requires changing the hints infrastructure to track counts rather than booleans.
// See `Repository::mark_hint_shown()` and `list_shown_hints()` in src/git/repository/mod.rs.
pub(crate) fn shell_integration_hint() -> String {
    cformat!("To enable automatic cd, run <underline>wt config shell install</>")
}

/// Hint when shell integration is installed but shell needs restart.
pub(crate) fn shell_restart_hint() -> &'static str {
    "Restart shell to activate shell integration"
}

/// Shell integration hint for unknown/unsupported shell.
fn shell_integration_unsupported_shell(shell_path: &str) -> String {
    // Extract shell name from path, handling both Unix and Windows paths
    // e.g., "/bin/tcsh" -> "tcsh", "C:\...\tcsh.exe" -> "tcsh"
    let shell_name = extract_filename_from_path(shell_path).unwrap_or(shell_path);
    format!(
        "Shell integration not yet supported for {shell_name} (supports bash, zsh, fish, nu, PowerShell)"
    )
}

/// Warning message when running as git subcommand (cd cannot work).
pub(crate) fn git_subcommand_warning() -> String {
    cformat!("For automatic cd, invoke directly (with the <underline>-</>): <underline>git-wt</>")
}

/// Hint when shell integration IS configured but user ran an explicit path.
/// Suggests using the shell-wrapped command for automatic cd.
pub(crate) fn explicit_path_hint(branch: &str) -> String {
    let wraps = crate::binary_name();
    cformat!("To change directory, run <underline>{wraps} switch {branch}</>")
}

/// Check if we should show the explicit path hint.
/// True when: explicit path invocation AND current shell has integration configured.
pub(crate) fn should_show_explicit_path_hint() -> bool {
    crate::was_invoked_with_explicit_path()
        && current_shell()
            .and_then(|shell| shell.is_shell_configured(&crate::binary_name()).ok())
            .unwrap_or(false)
}

/// Compute the shell warning reason for display in messages.
///
/// Returns a reason string explaining why shell integration isn't working.
/// See the module documentation for the complete spec of warning messages.
///
/// Checks specifically if the CURRENT shell (detected via $SHELL or PSModulePath
/// fallback) has integration configured, not just any shell. This prevents misleading
/// "shell requires restart" messages when e.g. bash has integration but the user is
/// running fish.
pub(crate) fn compute_shell_warning_reason() -> String {
    // Check if the CURRENT shell has integration configured, not just ANY shell
    let is_configured = current_shell()
        .and_then(|shell| shell.is_shell_configured(&crate::binary_name()).ok())
        .unwrap_or(false);
    let explicit_path = crate::was_invoked_with_explicit_path();
    let invoked = crate::invocation_path();
    let wraps = crate::binary_name();

    compute_shell_warning_reason_inner(is_configured, explicit_path, &invoked, &wraps)
}

/// Inner logic for computing shell warning reason.
/// Separated for testability - the outer function handles environment queries.
fn compute_shell_warning_reason_inner(
    is_configured: bool,
    explicit_path: bool,
    invoked: &str,
    wraps: &str,
) -> String {
    if is_configured {
        if explicit_path {
            // Invoked with explicit path - shell wrapper won't intercept this binary.
            let invoked_name = std::path::Path::new(invoked)
                .file_name()
                .and_then(|s| s.to_str())
                .unwrap_or(invoked);

            // Windows: check if the only difference is .exe suffix (case-insensitive)
            #[cfg(windows)]
            {
                let invoked_lower = invoked_name.to_lowercase();
                let wraps_lower = wraps.to_lowercase();
                if invoked_lower == format!("{wraps_lower}.exe") {
                    // Windows .exe mismatch - give targeted advice
                    return cformat!(
                        "ran <bold>{invoked_name}</>; use <bold>{wraps}</> (without .exe) for auto-cd"
                    );
                }
            }

            if invoked_name == wraps {
                // Filename matches but full path differs - show full path for clarity
                // (e.g., "./target/debug/wt" vs "wt" - the path IS the useful info)
                cformat!("ran <bold>{invoked}</>; shell integration wraps <bold>{wraps}</>")
            } else {
                // Different binary name - show just the filename
                cformat!("ran <bold>{invoked_name}</>; shell integration wraps <bold>{wraps}</>")
            }
        } else {
            "shell requires restart".to_string()
        }
    } else {
        "shell integration not installed".to_string()
    }
}

/// Print skipped shells (config file not found).
pub fn print_skipped_shells(
    skipped: &[(worktrunk::shell::Shell, std::path::PathBuf)],
) -> anyhow::Result<()> {
    for (shell, path) in skipped {
        let path = format_path_for_display(path);
        eprintln!(
            "{}",
            hint_message(cformat!(
                "Skipped <underline>{shell}</>; <underline>{path}</> not found"
            ))
        );
    }
    Ok(())
}

fn shell_extension_label(shell: Shell) -> &'static str {
    // For bash/zsh, completions are inline in the init script.
    if matches!(shell, Shell::Bash | Shell::Zsh) {
        "shell extension & completions"
    } else {
        "shell extension"
    }
}

fn print_config_action_result(action: &ConfigAction, message: String) {
    match action {
        ConfigAction::Added | ConfigAction::Created => {
            eprintln!("{}", success_message(message));
        }
        ConfigAction::AlreadyExists => {
            eprintln!("{}", info_message(message));
        }
        ConfigAction::WouldAdd | ConfigAction::WouldCreate => {
            unreachable!("Preview actions handled by confirmation prompt")
        }
    }
}

/// Print the result of shell integration installation.
///
/// Shows:
/// - Configured shells with their paths
/// - Completion results (for fish)
/// - Skipped shells
/// - Summary count
/// - Zsh compinit warning if needed
/// - Restart hint for current shell
///
/// Used by both `wt config shell install` and the interactive prompt after `wt switch`.
pub fn print_shell_install_result(
    scan_result: &crate::commands::configure_shell::ScanResult,
) -> anyhow::Result<()> {
    // Count shells that became (more) configured
    let shells_configured_count = scan_result
        .configured
        .iter()
        .filter(|ext_result| {
            let ext_changed = !matches!(ext_result.action, ConfigAction::AlreadyExists);
            let comp_changed = scan_result
                .completion_results
                .iter()
                .find(|c| c.shell == ext_result.shell)
                .is_some_and(|c| !matches!(c.action, ConfigAction::AlreadyExists));
            ext_changed || comp_changed
        })
        .count();

    // Show configured shells grouped with their completions
    for result in &scan_result.configured {
        let shell = result.shell;
        let path = format_path_for_display(&result.path);
        let what = shell_extension_label(shell);
        let message = cformat!(
            "{} {what} for <bold>{shell}</> @ <bold>{path}</>",
            result.action.description()
        );
        print_config_action_result(&result.action, message);

        if matches!(shell, Shell::Nushell) && !matches!(result.action, ConfigAction::AlreadyExists)
        {
            eprintln!("{}", hint_message("Nushell support is experimental"));
        }

        // Show completion result for this shell (fish has separate completion files)
        if let Some(comp_result) = scan_result
            .completion_results
            .iter()
            .find(|r| r.shell == shell)
        {
            let comp_path = format_path_for_display(&comp_result.path);
            let comp_message = cformat!(
                "{} completions for <bold>{shell}</> @ <bold>{comp_path}</>",
                comp_result.action.description()
            );
            print_config_action_result(&comp_result.action, comp_message);
        }
    }

    // Show legacy file cleanups (migration from conf.d to functions)
    for legacy_path in &scan_result.legacy_cleanups {
        let old_path = format_path_for_display(legacy_path);
        // Find the new canonical path from the configured results
        let new_path = scan_result
            .configured
            .iter()
            .find(|r| r.shell == Shell::Fish)
            .map(|r| format_path_for_display(&r.path))
            .unwrap_or_else(|| "~/.config/fish/functions/".to_string());
        eprintln!(
            "{}",
            info_message(cformat!(
                "Removed <bold>{old_path}</> (deprecated; now using <bold>{new_path}</>)"
            ))
        );
    }

    // Show skipped shells
    print_skipped_shells(&scan_result.skipped)?;

    // Summary
    if shells_configured_count > 0 {
        eprintln!();
        let plural = if shells_configured_count == 1 {
            ""
        } else {
            "s"
        };
        eprintln!(
            "{}",
            success_message(format!(
                "Configured {shells_configured_count} shell{plural}"
            ))
        );
    } else {
        eprintln!("{}", success_message("All shells already configured"));
    }

    // Zsh compinit advisory
    if scan_result.zsh_needs_compinit {
        eprintln!(
            "{}",
            warning_message("Completions require compinit; add to ~/.zshrc before the wt line:",)
        );
        eprintln!(
            "{}",
            format_bash_with_gutter("autoload -Uz compinit && compinit")
        );
    }

    // Restart hint for current shell
    if shells_configured_count > 0 {
        let current_shell = std::env::var("SHELL")
            .ok()
            .and_then(|s| extract_filename_from_path(&s).map(String::from));

        let current_shell_result = current_shell.as_ref().and_then(|shell_name| {
            scan_result
                .configured
                .iter()
                .filter(|r| !matches!(r.action, ConfigAction::AlreadyExists))
                .find(|r| r.shell.to_string().eq_ignore_ascii_case(shell_name))
        });

        if current_shell_result.is_some() {
            eprintln!("{}", hint_message(shell_restart_hint()));
        }
    }

    Ok(())
}

/// Handle shell integration prompt/hint after switch when shell integration is not active.
///
/// Called after `wt switch` when shell integration is NOT active.
/// See module documentation for the complete decision flow.
///
/// Returns `Ok(true)` if installed, `Ok(false)` otherwise.
pub fn prompt_shell_integration(
    config: &mut UserConfig,
    binary_name: &str,
    skip_prompt: bool,
) -> anyhow::Result<bool> {
    // Skip when running as git subcommand - shell integration can't help there
    // (running through git prevents cd, so the shell wrapper won't intercept)
    // The git subcommand warning is already shown by the caller
    if crate::is_git_subcommand() {
        return Ok(false);
    }

    let is_tty = std::io::stdin().is_terminal() && std::io::stderr().is_terminal();

    // Check the current shell (via $SHELL or PSModulePath fallback)
    // Only prompt if current shell is supported (so they benefit immediately)
    let shell_env = std::env::var("SHELL").ok();
    if current_shell().is_none() {
        let msg = match &shell_env {
            Some(path) => shell_integration_unsupported_shell(path),
            // $SHELL not set: could be Windows PowerShell, or unusual Unix setup
            // Point them to manual installation
            None => shell_integration_hint(),
        };
        eprintln!("{}", hint_message(msg));
        return Ok(false);
    };

    // Scan ALL shells (same as `wt config shell install`)
    // Only includes shells where config files already exist
    let scan = scan_shell_configs(None, true, binary_name)
        .map_err(|e| anyhow::anyhow!("Failed to scan shell configs: {e}"))?;

    // No config files exist - show install hint
    if scan.configured.is_empty() {
        eprintln!("{}", hint_message(shell_integration_hint()));
        return Ok(false);
    }

    // Check if current shell is already configured (user just needs to restart)
    let current_shell_installed = scan
        .configured
        .iter()
        .filter(|r| Some(r.shell) == current_shell())
        .any(|r| matches!(r.action, ConfigAction::AlreadyExists));

    if current_shell_installed {
        // Shell integration is configured but not active for this invocation
        if !crate::was_invoked_with_explicit_path() {
            // Invoked via PATH but wrapper isn't active - needs shell restart
            eprintln!("{}", hint_message(shell_restart_hint()));
        }
        // For explicit paths: no hint needed - handle_switch_output() warning already explains
        return Ok(false);
    }

    // Can't or shouldn't prompt - show install hint
    if config.skip_shell_integration_prompt || !is_tty || skip_prompt {
        eprintln!("{}", hint_message(shell_integration_hint()));
        return Ok(false);
    }

    // TTY + first time: Show interactive prompt
    // Accepting installs for all shells with config files (same as `wt config shell install`)
    let confirmed = prompt_for_install(
        &scan.configured,
        &scan.completion_results,
        binary_name,
        "Install shell integration?",
    )
    .map_err(|e| anyhow::anyhow!("{e}"))?;

    if !confirmed {
        // Only skip future prompts after explicit decline (not Ctrl+C)
        let _ = config.set_skip_shell_integration_prompt(None);
        eprintln!("{}", hint_message(shell_integration_hint()));
        return Ok(false);
    }

    // Install for all shells with config files (same as `wt config shell install`)
    let install_result = handle_configure_shell(None, true, false, binary_name.to_string())
        .map_err(|e| anyhow::anyhow!("Failed to configure shell integration: {e}"))?;

    print_shell_install_result(&install_result)?;

    Ok(true)
}

/// Print the result of shell integration uninstallation.
///
/// Shows removed extensions/completions, not-found warnings, summary, and restart hint.
pub fn print_shell_uninstall_result(scan_result: &UninstallScanResult, explicit_shell: bool) {
    // Count unique shells, not file results (fish may have 2 files: functions/ and legacy conf.d/)
    let mut shells: Vec<_> = scan_result.results.iter().map(|r| r.shell).collect();
    shells.sort_by_key(|s| s.to_string());
    shells.dedup();
    let shell_count = shells.len();
    let completion_count = scan_result.completion_results.len();
    let total_changes = shell_count + completion_count;

    // Show shell extension results
    for result in &scan_result.results {
        let shell = result.shell;
        let path = format_path_for_display(&result.path);
        let what = shell_extension_label(shell);

        eprintln!(
            "{}",
            success_message(cformat!(
                "{} {what} for <bold>{shell}</> @ <bold>{path}</>",
                result.action.description(),
            ))
        );
    }

    // Show completion results
    for result in &scan_result.completion_results {
        let shell = result.shell;
        let path = format_path_for_display(&result.path);

        eprintln!(
            "{}",
            success_message(cformat!(
                "{} completions for <bold>{shell}</> @ <bold>{path}</>",
                result.action.description(),
            ))
        );
    }

    // Show not found - warning if explicit shell, hint if auto-scan
    for (shell, path) in &scan_result.not_found {
        let path = format_path_for_display(path);
        let what = shell_extension_label(*shell);
        if explicit_shell {
            eprintln!("{}", warning_message(format!("No {what} found in {path}")));
        } else {
            eprintln!(
                "{}",
                hint_message(cformat!("No <underline>{shell}</> {what} in {path}"))
            );
        }
    }

    // Show completion files not found (only fish has separate completion files)
    // Only show this if the shell extension was ALSO not found - if we removed
    // the shell extension, no need to warn about missing completions
    for (shell, path) in &scan_result.completion_not_found {
        let shell_was_removed = scan_result.results.iter().any(|r| r.shell == *shell);
        if shell_was_removed {
            continue; // Shell extension was removed, don't warn about completions
        }
        let path = format_path_for_display(path);
        if explicit_shell {
            eprintln!(
                "{}",
                warning_message(format!("No completions found in {path}"))
            );
        } else {
            eprintln!(
                "{}",
                hint_message(cformat!("No <underline>{shell}</> completions in {path}"))
            );
        }
    }

    // Exit with info if nothing was found
    let all_not_found = scan_result.not_found.len() + scan_result.completion_not_found.len();
    if total_changes == 0 {
        if all_not_found == 0 {
            eprintln!();
            eprintln!("{}", hint_message("No shell integration found to remove"));
        }
        return;
    }

    // Summary
    eprintln!();
    let plural = if shell_count == 1 { "" } else { "s" };
    eprintln!(
        "{}",
        success_message(format!(
            "Removed integration from {shell_count} shell{plural}"
        ))
    );

    // Hint about restarting shell (only if current shell was affected)
    let current_shell = std::env::var("SHELL")
        .ok()
        .and_then(|s| extract_filename_from_path(&s).map(String::from));

    let current_shell_affected = current_shell.as_ref().is_some_and(|shell_name| {
        scan_result
            .results
            .iter()
            .any(|r| r.shell.to_string().eq_ignore_ascii_case(shell_name))
    });

    if current_shell_affected {
        eprintln!("{}", hint_message("Restart shell to complete uninstall"));
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use insta::assert_snapshot;

    #[test]
    fn test_shell_integration_hint() {
        let hint = shell_integration_hint();
        assert_snapshot!(hint, @"To enable automatic cd, run wt config shell install");
    }

    #[test]
    fn test_git_subcommand_warning() {
        let warning = git_subcommand_warning();
        assert_snapshot!(warning, @"For automatic cd, invoke directly (with the -): git-wt");
    }

    #[test]
    fn test_compute_shell_warning_reason() {
        // Shell integration not configured -> "not installed"
        let reason = compute_shell_warning_reason_inner(false, false, "wt", "wt");
        assert_eq!(reason, "shell integration not installed");

        // When filename matches wraps, show full path (the path IS the useful info)
        let reason = compute_shell_warning_reason_inner(true, true, "./target/debug/wt", "wt");
        assert_snapshot!(reason, @"ran ./target/debug/wt; shell integration wraps wt");

        // When invoked binary differs from wrapped binary, show both
        let reason = compute_shell_warning_reason_inner(true, true, "/usr/local/bin/git-wt", "wt");
        assert_snapshot!(reason, @"ran git-wt; shell integration wraps wt");

        // Shell integration configured + NOT explicit path -> "shell requires restart"
        let reason = compute_shell_warning_reason_inner(true, false, "wt", "wt");
        assert_eq!(reason, "shell requires restart");
    }

    #[test]
    #[cfg(windows)]
    fn test_compute_shell_warning_reason_windows() {
        // Windows: invoked as git-wt.exe, wraps git-wt -> targeted .exe message
        let reason = compute_shell_warning_reason_inner(
            true,
            true,
            r"C:\Users\user\AppData\Local\Microsoft\WinGet\Packages\git-wt.exe",
            "git-wt",
        );
        // Should extract filename and give targeted advice
        assert!(!reason.contains(r"C:\Users")); // No full path
        assert!(reason.contains("git-wt.exe"), "{reason}");
        assert!(reason.contains("without .exe"), "{reason}");

        // Windows paths are case-insensitive
        let reason = compute_shell_warning_reason_inner(true, true, r"C:\path\to\WT.EXE", "wt");
        assert!(
            reason.contains("WT.EXE") || reason.contains(".exe"),
            "{reason}"
        );
    }

    #[test]
    fn test_explicit_path_hint_format() {
        let hint = explicit_path_hint("feature-branch");
        // binary_name() returns the test binary hash in test context; normalize it
        let mut settings = insta::Settings::clone_current();
        settings.add_filter(r"wt-[0-9a-f]+", "wt");
        settings.bind(|| {
            assert_snapshot!(hint, @"To change directory, run wt switch feature-branch");
        });
    }
}