Repository navigation
fix(tests): give the picker's directive files a temp directory of their own, and make a PTY failure explain itself - #3619
Merged
Conversation
The Windows flake in `test_switch_picker_runs_execute_command` reported only `left: 1, right: 0` — wt's own error line, which explains why it exited 1, was never in the captured frame. Two harness gaps hid it: - The post-exit drain was a single non-blocking sweep taken the moment `try_wait` reported the child reaped, so the child's final writes could still be in the PTY. Drain until the output goes quiet instead. - `child.kill()` ran unconditionally after the exit poll. On Windows that is `TerminateProcess(proc, 1)`, so a hung picker and a picker that failed on its own both report 1. A hang now panics as a hang, and every exit code a caller asserts on is one the child chose. Also dumps the screen in the four directive tests' exit-code assertions, the one place they asserted an exit code without showing what was on screen. Includes a temporary Windows stress workflow to reproduce the flake; it goes before merge.
Whether wt got as far as writing the EXEC directive splits the failure space in two: an empty file means it failed before `execute_user_command`, a populated one means the write landed and something after it failed. Also folds `PtyResult::screen`'s body into a free `screen_text` so the hang-path panic can render a frame it doesn't own, and points the stress workflow at realistic test neighbours (a full-suite run alongside the loop) rather than CPU starvation — the observed failure ran at normal speed.
`change_directory` and `execute` propagated the raw `io::Error` from their
directive-file write, so a failure rendered as
✗ No such file or directory (os error 2)
with nothing to attach it to. On the `--execute` path it lands *after* the
switch has already happened and after `◎ Executing (--execute):`, so it reads
as if the command were missing — the last thing on screen it could refer to.
Both writes now say which file and which write:
✗ Failed to write the command to the exec directive file /tmp/tmp.aBc
No such file or directory (os error 2)
The files belong to the shell wrapper, so a reader who sees this knows to look
at the wrapper's temp files rather than at their own arguments. `.context()` on
wrapped I/O is what CLAUDE.md's Error Handling section asks for; these two were
the exceptions.
The four directive tests typed `target` and waited for `target-branch`'s preview pane before pressing Enter. That gate can only assert what skim *painted*: the filtered item list is swapped into `ItemList` during a render, while `Accept` reads `item_list.selected()` — the cursor's slot in whatever list is current at that moment. The list-pane `>` pointer comes from the same render state the accept reads, which is why this file's `wait_for_cursor_on_row` already calls it the race-free signal. So navigate instead of filtering: the picker sorts the current worktree first, so one Down lands on `target-branch`, and the arrow is re-issued until the pointer settles there (absorbing an async row refresh that resets the cursor). No query means no matcher in the accept path at all. It's also less to wait on — the tests no longer block on the preview pane rendering.
`directive_files()` and `legacy_directive_file()` called
`NamedTempFile::new()` in the shared temp directory. `tempfile` retries a name
collision only when it surfaces as `AlreadyExists`, and on Windows a
`create_new` against a name already held by a *directory* — or by a file in
delete-pending state — comes back `PermissionDenied`, which it hands straight to
the caller. A full suite run leaves the temp directory full of `.tmpXXXXXX`
entries (every `TestRepo` makes one), and under that load the call panics:
thread '…switch_picker::test_switch_picker_emits_cd_directive_by_default'
panicked at tests\integration_tests\switch_picker.rs:2531:45:
failed to create cd temp file: … PathError { path: "D:\\tmp\\.tmp3XI9wb",
err: Os { code: 5, kind: PermissionDenied, message: "Access is denied." } }
Reproduced on Windows CI in 4 of 80 runs of the five directive tests while the
full suite ran alongside — a 1% chance per test that any of the ~65 callers of
these helpers fails for reasons that have nothing to do with what it asserts.
Both helpers now take a `TempDir` and put fixed-named files inside it.
`TempDir::new` isn't exposed to the same problem (a directory collision
surfaces as `AlreadyExists`, which tempfile retries), and fixed names inside a
private directory can't collide with anything. The switch_picker copy of the
helper is gone — it existed only to duplicate this.
The file had three copies of "poll for exit, kill on timeout, drain once". `wait_for_exit` replaces them, so the invariant holds everywhere: a hang panics with its frame instead of being killed into an exit code, and the final output is drained to quiet before any caller reads it.
The rule that fell out of the picker flake: a file a test needs by name goes in a `TempDir`, not in the shared temp directory under a random name, because `NamedTempFile::new()` surfaces the collision as an unretried `PermissionDenied` on Windows.
Neighbours, not starvation: loop the suspect tests on a Windows runner with a full suite running alongside. Starving the CPU models the wrong thing whenever the failing run's own timing was normal, and the duration is in the log.
It did its job: 4 failures in 80 runs of the five directive tests before the temp-directory fix, 0 after, both with a full suite running alongside. The recipe is recorded in tests/CLAUDE.md; the workflow itself doesn't need to live in the repo.
Two beliefs, one test each: an unwritable EXEC file fails the command and names the write, and so does an unwritable CD file. Both point the reader at the shell wrapper's temp file, which is the whole reason the context was added — and these are the paths a real failure takes, so they were worth a test rather than a manual check.
… file The context was at the four call sites, so two of the four closures (the legacy arms) had no test that could reach them, and each site repeated the wording. `append_line` and `write_cd_path` now own the message and return `anyhow::Result`, with `append_line` taking the payload's name — one closure per helper, both on paths the new tests exercise, and the legacy arms get the same message rather than the bare `io::Error`.
max-sixty
marked this pull request as ready for review
July 26, 2026 22:34
worktrunk-bot
approved these changes
Jul 26, 2026
This was referenced Nov 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Chasing the Windows-only failure of
test_switch_picker_runs_execute_commandthat @max-sixty flagged after #3607 merged: it failed the advisoryaffected tests (windows)leg while the requiredtest (windows)leg passed the same test on the same SHA in the same run.The failure message was the whole problem
That is everything CI had. wt prints an error before exiting non-zero, so there was a message — it just never reached the captured frame, because of two harness gaps:
try_waitreported the child reaped. The child's last writes can still be in the PTY at that moment, so the tail — wt's✗line — was dropped. This is also why test(switch_picker): tolerate Windows self-exit-1 on successful picker-create #3427 concluded a picker-create "self-exited 1 after fully-correct work with no error on screen": the error was there, just not drained.child.kill()ran unconditionally after the exit poll. On Windows that isTerminateProcess(proc, 1), so a hung picker and a picker that failed on its own both report exit 1 — the ambiguity that made test(switch_picker): tolerate Windows self-exit-1 on successful picker-create #3427 reason from wall-clock time to rule out a kill.Both are fixed here: drain until the output goes quiet, and panic on a hang rather than killing silently, so every exit code a caller asserts on is one the child chose. The four directive tests now also dump the screen (and the EXEC file) in their exit-code assertions.
What reproducing it turned up
Loop-based reproduction of the reported symptom is hopeless by the numbers: across the last 38 PR runs, exactly one advisory job failed — this one — i.e. ~1 failure per 160,000 test executions. What did reproduce was a different Windows failure in the same five tests, at a rate 1000× higher, once the loop ran with realistic neighbours (the full suite running alongside, as the failing leg had at test 3111/4204):
4 of 80 runs of the five directive tests.
directive_files()calledNamedTempFile::new()in the shared temp directory;tempfileretries a name collision only when it surfaces asAlreadyExists, and on Windowscreate_newagainst a name held by a directory — or by a file in delete-pending state — returnsPermissionDenied, which it hands back to the caller. A full suite run fills that directory with.tmpXXXXXXentries (everyTestRepomakes one), so the collision is routine rather than astronomical.The helpers now take a
TempDirand put fixed-named files inside it.TempDir::newisn't exposed to the same problem — a directory collision surfaces asAlreadyExists, which tempfile retries — and fixed names inside a private directory can't collide with anything. That covers all 75 call sites ofdirective_files()/legacy_directive_file(), not just the picker's five, and the switch_picker copy of the helper is gone.The reported exit-1 is not proven fixed
Stated plainly: the panic above is a different symptom from the reported exit 1, so this PR does not prove that failure is gone. What the evidence does say, and what a reader should check first if it recurs:
--executetakes 2.42s. The--executetail —build_hook_context's git lookups, ~0.7s of the difference — had therefore run, so the failure was at the end of the pipeline, not in the picker or the switch..ok()-swallowed.wtrendered✗ No such file or directory (os error 2)— no file, no operation, and positioned right under◎ Executing (--execute):, where it reads as if the command were missing. It now reads:The message lives in
append_line/write_cd_pathrather than at their four call sites, so every directive write says which file and what didn't get written — including the legacy-protocol arms, which no test can drive to failure.So the next occurrence prints its own diagnosis, in one look, instead of
left: 1, right: 0.Also here
The four directive tests select their row by cursor, not by a typed query. They typed
targetand waited fortarget-branch's preview pane before Enter. That gate can only assert what skim painted: the filtered item list is swapped intoItemListduring a render, whileAcceptreadsitem_list.selected()— the cursor's slot in whatever list is current at that moment. The list-pane>pointer comes from the same render state the accept reads, which is why this file's ownwait_for_cursor_on_rowcalls it the race-free signal. One Down reachestarget-branch(the picker sorts the current worktree first) and the arrow is re-issued until the pointer settles, so no query — and no matcher — is in the accept path at all. It also drops the wait on the preview pane rendering.Testing
switch_picker(68), plus every suite that calls these helpers —directives,switch,remove,security,bare_repository,step_alias,user_hooks,step_relocate(861 tests) — green, plus clippy-Dwarningson all targets with--features shell-integration-tests.test_exec_directive_write_failure_names_the_file,test_cd_directive_write_failure_names_the_file): an unwritable directive path fails the same way on every platform, so the paths that produce these messages are covered rather than checked by hand.Follow-ups, not in here
build_hook_contextis called withreferenced: Noneon the--executepath, so a-x 'echo hi'with no template variables still runs thedefault_branch,primary_worktree,commit,short_commit,remote, andupstreamlookups — roughly doubling the command's subprocess count (30ms → 60ms locally, 2.42s → 3.11s in the Windows test timings). The alias path already passes its referenced set; a--executecommand receives no JSON context, so the reason hooks passNonedoesn't apply to it.cancel_background_commands()is a no-op on Windows (signal_background_pid), so the picker's "the picker's exit cancels the unfinished request" promise isn't kept there: preview git children keep reading.git/configwhile the accept path writesworktrunk.historyandworktrunk.default-branchto it. Issue Flaky:test_prune_skips_unmergedon Windows —Permission deniedreading.git/configfrom background subprocess #2564 is the same shape of concurrent-config-access failure on Windows.assert_valid_create_exit_code's Windows tolerance (test(switch_picker): tolerate Windows self-exit-1 on successful picker-create #3427) andassert_valid_abort_exit_code's acceptance of1both rest on the kill-vs-self-exit ambiguity this PR removes; they can be tightened once a Windows run confirms nothing else produces a stray 1.