Files
max-sixty__worktrunk/tests
Worktrunk Bot d41ba2b1e5 fix(switch): name the directory the --execute program runs in in its header (#4043)
## Problem

The `Executing (--execute) @ …` header rendered `hooks_display_path` —
the worktree the *background hooks* run in. The program runs wherever
the switch cd'd, which is that worktree only when the user was at the
source worktree's root. Two cases break the claim:

- `--no-cd` deliberately starts the program in the invoking directory,
so `output::execute` gets no `target_dir` at all. `wt switch --create
test --no-cd -x pwd` announced `Executing (--execute) @ ~/repo.test` and
then printed `~/repo`.
- A switch from a subdirectory keeps the user's position:
`handle_switch_output` passes `resolve_subdir_in_target(...)` to
`change_directory`, so the program starts in `<worktree>/<subdir>` while
the header named the worktree root — the same wrong-directory shape one
level out.

The header is the only signal a user gets about where the program runs,
so a wrong one sends them looking in the wrong place. In
[#4042](https://github.com/max-sixty/worktrunk/issues/4042) the reporter
concluded the `--execute` template variables were broken and enumerated
all of them, when the variables were correct and the directory was the
thing `--no-cd` had moved.

## Solution

`handle_switch_output` now returns both annotations as
`SwitchDisplayPaths` — `hooks`, the worktree root the hooks really do
run in, and `execute`, derived from the `cd_target` it hands
`change_directory`. The header therefore names the directory
`output::execute` will use, and cannot drift from it: there is one
value, computed where the `cd` is decided rather than reconstructed at
the call site.

The path is still annotated only when the user's shell won't be there.
Under `--no-cd` there is no `cd_target` and the header reads `Executing
(--execute):`; with shell integration active the shell follows the
program to the same directory, so nothing is annotated then either.

## Testing

Two integration tests in `tests/integration_tests/switch.rs`, both
failing on `main`:

- `test_switch_no_cd_execute_header_omits_worktree_path` — `wt switch
feature --no-cd --execute pwd` asserts the header names no path (fails
with `Executing (--execute) @ ~/repo.feature`).
- `test_switch_execute_header_names_preserved_subdirectory` — switches
from `apps/gateway/`, asserts `pwd` prints the target's `apps/gateway`
and the header names it (fails with `Executing (--execute) @
~/repo.feature`).

The existing `switch_no_cd_execute_does_not_emit_cd` snapshot pinned the
old header — its stdout was already `_REPO_` while its stderr claimed
`_REPO_.exec-test` — and is updated. The 336 tests matching `switch`,
`execute`, and `directives` pass, as do `cargo test --lib --bins`,
`cargo clippy --all-targets`, and `cargo fmt --check`.

Closes #4042 — automated triage

---------

Co-authored-by: worktrunk-bot <254187624+worktrunk-bot@users.noreply.github.com>
2026-09-08 13:03:57 -07:00
..