Repository navigation
fix(shell): discover the Unix PowerShell profile from the installed pwsh - #4422
Conversation
On Unix, worktrunk hardcoded ~/.config/powershell/Microsoft.PowerShell_profile.ps1, but PowerShell resolves its profile under $XDG_CONFIG_HOME, so install could write a profile PowerShell never loads. The profile path now comes from `pwsh -NoProfile ... '$PROFILE.CurrentUserCurrentHost'`, queried once per process through Cmd with the shared local-probe timeout, and install, uninstall and detection all read that one answer. A missing, failing or timed-out runtime falls back to the conventional path; SIGINT/SIGTERM during the query cancels the command instead of falling back. Windows candidate discovery is unchanged. Closes #4419
|
@worktrunk-bot Independent runtime review found a cancellation defect at head ad6e194. Please fix it on this PR before merge. Reproducer: put an executable #!/bin/sh
sleep 15 &
kill -INT $$The same happens with The owning cause appears to be Other runtime review passed: real pwsh custom-XDG install/uninstall, NoProfile sentinel, current-host selection, and the five-second bound across fresh homes.
|
|
@worktrunk-bot Please also resolve the failed pre-commit check in the same repair: the new direct
|
…the pipes A timed child ended by SIGINT/SIGTERM whose descendant kept its stdout or stderr open made the bounded readers hit the deadline first, so run_with_timeout_impl tore the tree down and returned TimedOut. Callers then treated the cancellation as a slow command: shell install fell back to ~/.config/powershell and wrote a profile with exit 0. Read the leader's status before the teardown and return a native INT/TERM exit as the command's status; a live child still times out as before. Also switch the paths.rs unit tests to Cmd::run so the no-direct-cmd-output hook passes.
worktrunk-bot
left a comment
There was a problem hiding this comment.
At this head I confirmed both defects @max-sixty reported. A follow-up push to this PR fixes them.
- Cancellation is lost when a descendant holds the pipes. In
run_with_timeout_impl, the Unixcollect()error path tears down the tree and returns the reader'sTimedOutwithout checking how the leader exited. If the mockpwshrunssleep 60 &and thenkill -INT $$, install exits 0 and writes~/.config/powershell/Microsoft.PowerShell_profile.ps1. The fix reads the leader's status before the teardown. A native INT/TERM exit is returned as the command's status, so it goes through the same capture-mode classification as the no-descendant case. A child that's still alive at the deadline times out as before. This changes the shared primitive, so every timedCmdcaller now sees a cancelled child as cancelled whether or not a descendant held its pipes, including boundedgit ls-remote. - pre-commit fails. The
paths.rsunit tests callCommand::output()directly, which theno-direct-cmd-outputhook rejects. They now useCmd::run, and no exclusion is added.
New regressions: a shell_exec unit test (INT and TERM with a pipe-holding sleep) and a configure_shell integration case. The integration case checks for exit 130/143 and that no profile is written. Both fail on this head and pass with the fix.
|
@worktrunk-bot Please revise the timeout repair at head 0160182. The new unconditional Preserve the existing unreaped-leader guarantee while observing its native terminal status, rather than documenting away that guarantee. Check the installed nonreaping
|
…leader The previous repair read the leader's status with try_wait, which reaps any exited leader before kill_timed_out_tree signals its process group. Once reaped, a descendant exiting in that gap frees the numeric pgid for reuse before killpg. Probe with waitid(WEXITED | WNOWAIT | WNOHANG) instead — nix on Linux, libc on Darwin, where nix doesn't wrap it — so teardown still completes before the final wait reaps the leader. Signalling the zombie can't change its status, so that wait reports the native INT/TERM.
|
Fixed in 0550885.
Ordinary timeouts are unchanged: a child still alive at the deadline is torn down and returns |
|
@worktrunk-bot The shared timeout repair at 0550885 is now independently verified: nonreaping teardown is sound; 13 targeted tests and real-pwsh custom-XDG/NoProfile checks pass; descendant INT/TERM cancels without profile writes; numeric exit 130 and live timeout retain fallback. One remaining caller defect reproduces in Please preserve cancellation through shell-scan consumers before applying ordinary diagnostic fallback, checking the full call chain. Add a config-show regression asserting that the next forge probe is absent after native INT/TERM, and preserve ordinary failed-query fallback. Push the fix to this PR. Keep the now-verified shared timeout repair.
|
…query Consumers that treat a failed shell scan as "not configured" or a hint kept going after the pwsh query was cancelled: `wt config show --full` went on to probe `gh --version` and `gh auth status`, and the switch and merge/remove hint paths could reach their hooks. The scan's String errors can't carry the interruption, so expose the query's cached cancellation (`powershell_query_interruption`) and check it through `require_scan_not_cancelled` before each consumer's fallback or next step. An ordinary failed query still falls back.
|
Fixed in 59ce7ed. The scan errors are
The check reads only the query's own outcome, not the operation latch, so cancellations from other sources keep their existing handling. A query that fails without a signal, including a plain exit 130, still falls back. New
The switch and merge/remove sites have no dedicated tests. The shared timeout repair is unchanged. |
|
@worktrunk-bot At 59ce7ed, the config-show correction is verified: native INT/TERM exits -2/-15 with zero gh calls, ordinary exit 130 succeeds and probes gh, and all 16 focused regressions pass. One remaining switch consumer still starts work after cancellation. With current shell PowerShell, run Please fix this at the canonical error boundary: propagate a typed Result through
|
…n error Shell scans returned String errors, so consumers that read a failed scan as "not configured" swallowed the cancellation and went on: `wt switch` under PowerShell probed `nu` and printed hints after pwsh died of SIGINT. The late `require_scan_not_cancelled` guards caught some sites after the fact. The profile path helpers' `io::Error` now carries the cancelled query's signal as a typed payload, and `scan_shell_configs`, install, uninstall and `apply_confirmed_shell_config` return `ShellConfigError`, keeping `Interrupted` apart from ordinary failures. `current_shell_is_configured`, `compute_shell_warning_reason`, `should_show_explicit_path_hint`, `print_shell_activation_hint` and the switch output builders return `Result` and propagate it; ordinary failures still read as "not configured". The switch offer stays best-effort except for cancellation. The latch-reading guards are gone. Regressions: `wt switch --create` under PowerShell stops with 130/143 and no `nu` probe or later hints; under zsh, cancelling the offer's all-shell scan stops before `--execute`; `wt remove` stops before its change-directory warning.
|
@worktrunk-bot Please repair the failing patch coverage and one test-validity issue on head 4158036. Independent code/runtime review is otherwise clean; native interruption and the shared timeout primitive are verified. Exact Codecov base d4c147e → this head reports 216/225 changed lines covered (96.00%, target98.44%). All nine misses are classified:
A minimal meaningful test set was independently exercised with the exact pinned binary: A. A deterministic B. Test the typed error boundary directly: ProfileQueryInterrupted wrapped in io::Error for native INT/TERM retains its signal and readable message; an ordinary io::ErrorKind::Interrupted without that typed payload remains an ordinary failure. Test ShellConfigError::config_paths with an ordinary io error retains shell/context and is not classified as native cancellation. C. Correct the new offer-before-execute regression: it currently passes Run the relevant tests and pre-commit checks, then push the complete repair to this PR. Keep the now-verified production cancellation and timeout design.
|
worktrunk-bot
left a comment
There was a problem hiding this comment.
codecov/patch fails at this head: 96.00% of the diff is hit against a 98.44% target, which leaves 9 of 225 lines unhit. Most of the misses are the ordinary-failure fallbacks that sit beside the new cancellation arms: ShellConfigError::Failed in render_shell_status and current_shell_is_configured, the Failed message in ShellConfigError::config_paths, and the Display impl of ProfileQueryInterrupted. A follow-up push adds tests for these. Two integration tests run an argv0 that shell integration can't wrap (w@t), so the scan fails without a cancellation, and two unit tests cover the error classification. That should leave 2 misses, which clears the target. The remaining misses are the Failed(...) re-wrap in scan_shell_configs and the ? after handle_switch_created_output. The second can't fire, because build_switch_output_context already got the cached query result.
…on arms An rc path that can't be read as a file (`.bashrc` as a directory) is a deterministic ordinary scan failure: install reports the read error and leaves the path alone, `config show --full` reports the status as undetermined and still probes `gh`, and `switch` treats the shell as not configured and runs `--execute`. Unit tests pin the typed boundary: only the `ProfileQueryInterrupted` payload classifies as a cancellation, and an ordinary config-path error keeps its shell context. The offer-before-execute regression passed `touch <path>` as one program name, so the program could never run. It now passes `touch -- <path>`, with an ordinary-failure case showing the marker is created when execution is allowed.
|
Done in 165a942. My review above described an earlier draft that used an unwrappable argv0. This push follows your plan instead.
That covers 8 of the 9 lines Codecov reported. The one left is the |
Applies `AGENTS.md`'s **Other Tools Own Their Conventions** (#4435) to what #4106 left: where worktrunk refined how it handles a case outside standard use, stop handling the case. **CI status: a failed forge call shows the error indicator.** The classifier that searched `gh`/`glab`/`az`/`tea` output for English phrases ("rate limit", "403", "connection", …) to choose between ⚠ and a blank "no CI" cell is deleted. Any failed call now shows ⚠. Gitea reads only whether the HTTP status is an error, not which one. The two lookups by commit SHA (GitHub check runs, Gitea combined status) now run only when some remote-tracking ref contains the head, since the forge answers a commit it doesn't have with an error and ordinary unpushed work would otherwise show ⚠. GitLab and Azure look pipelines up by branch and are unchanged. **PowerShell on Unix.** When `pwsh` can't be queried there is no PowerShell profile, rather than a guessed `~/.config/powershell` one (left by #4422). **Nushell.** When `nu` can't be queried there are no autoload candidates, rather than a reconstruction of Nushell's data-dir rule. Install can't write into a legacy directory, since the candidate list is empty. Behavior changes: - `gh`/`glab`/`az` installed but not logged in now shows ⚠ under `wt list --full` instead of a blank cell. Detection checks that the tool is installed, and `wt config show` reports that it isn't logged in. The ⚠ legend now names "not logged in". - A Gitea 404 shows ⚠. - `wt config shell install powershell` (or `nu`) without the tool fails with "No shell config files found", and uninstall no longer finds a wrapper left behind after `nu` was removed. **Fish's completion path.** `Shell::completion_path` answered for every shell, but only fish installs a completion file; its other arms, including the Nushell one this change touched, were dead. `shell::fish_completion_path` replaces it. Tests: the retriable-classifier unit tests are gone, and the Gitea test that only distinguished a blanked 500 body. Mocks now answer for branches other than the one under test, since those would otherwise show ⚠. New tests: a failed `gh pr list` / `glab mr list` shows ⚠; an unpushed head skips the GitHub and Gitea lookups by SHA, each with a pushed control. Shell unit tests and the PowerShell integration tests no longer depend on a real `nu` or `pwsh`; they pass with only `/usr/bin:/bin` on `PATH`. Full integration and unit suites pass locally. Ref #4106. > _This was written by Claude Code on behalf of max-sixty_ --------- Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
…rompt (#4522) Since v0.80.0, every `wt switch` without an active shell wrapper spawns `pwsh` when PowerShell is installed, adding about 150-200 ms per call. That includes non-interactive calls such as `wt switch -c x --format json` from agents. #4422 made the shell config scan ask the installed `pwsh` for its profile path, and `prompt_shell_integration` ran that scan before checking whether it could prompt. When it can't prompt (no TTY, `--execute`, or a previously declined offer), both outcomes of the scan print the same install hint. The can't-prompt check now runs before the scan, so those calls spawn neither `pwsh` nor `nu`. Verified with logging `pwsh`/`nu` shims on PATH and the `-vv` trace: a non-TTY `wt switch b1` and `wt switch -c x1 --format json` spawned `nu` and `pwsh` on main and neither on this branch, and printed the same hint. Under `script` (a TTY), the switch still runs both probes and shows the install prompt. `test_switch_hint_skips_shell_config_scan` asserts through mock call logs that neither probe runs, and fails without the fix. It replaces `test_switch_offer_after_powershell_query`, which tested cancelling the scan's `pwsh` query in a non-TTY switch, a query that no longer happens there. That cancellation coverage moves to a PTY test, `test_offer_stops_on_cancelled_powershell_query`: on a terminal, SIGINT or SIGTERM in the query stops the switch with no offer, and an ordinary exit 130 still falls back to the offer. > _This was written by Claude Code on behalf of max-sixty_ Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
On Unix, shell installation now asks the installed PowerShell runtime for
$PROFILE.CurrentUserCurrentHost, so a customXDG_CONFIG_HOMEselects the profile PowerShell actually loads. Install, uninstall and configuration detection share the cached result. The local query uses-NoProfile, disables telemetry and update checks, and uses the existing five-second probe timeout. Missing, failing or invalid runtime output retains the conventional fallback. Windows continues to use the known Documents folder candidates for both PowerShell editions.Native SIGINT/SIGTERM cancels installation before profile writes, including when descendants keep the probe's output pipes open. The shared timed-command primitive now observes the child's native terminal status without reaping its leader until process-group teardown completes, preserving the existing process-ID safety guarantee. Typed interruption also propagates through diagnostics, switch/remove warnings, and installation offers before another probe or hint mutation starts.
Validation covers custom-XDG installation and removal, malformed/unavailable runtime fallback, native interruption versus ordinary exit 130, pipe-holding descendants, bounded timeouts, and real pwsh profile discovery without executing user profiles. Regression tests exercise both the shell-installation flow and the shared timeout primitive.
An obsolete profile previously written under
~/.configwhile a custom XDG location was active is no longer an install/uninstall candidate; PowerShell did not load it, and treating it as configured would preserve the original bug.Closes #4419.