Skip to content

fix(powershell): source shellenv via Out-String so the profile line loads - #135

Merged
timvw merged 2 commits into
mainfrom
fix/130-powershell-shellenv
Aug 19, 2026
Merged

fix(powershell): source shellenv via Out-String so the profile line loads#135
timvw merged 2 commits into
mainfrom
fix/130-powershell-shellenv

Conversation

@timvw

@timvw timvw commented Aug 19, 2026

Copy link
Copy Markdown
Owner

Fixes #130.

The bug

The $PROFILE line wt init powershell writes (and the docs tell users to add
by hand) does not work:

Invoke-Expression (& wt shellenv powershell)

shellenv emits many lines, so the subexpression evaluates to Object[], and
Invoke-Expression's -Command parameter is [string]. The call is rejected,
the wt function is never defined, and auto-cd, tab completion and the
interactive menus are all silently absent — wt keeps working because wt.exe
is on PATH, so the failure is easy to miss once the error scrolls away.

I reproduced the exact error on PowerShell 7 as well, so this is not limited to
Windows PowerShell 5.1.

The fix

wt shellenv powershell | Out-String | Invoke-Expression

Hoisted into a single powershellSetupLine constant so wt init, the
shellenv help text and docs/installation.md cannot drift apart again.

Checked the obvious objection to Out-String: it does not wrap the 220-char
completer line even at host width 80, so nothing is truncated.

Why CI missed it

e2e/run.go sourced shellenv through a harness-only variant that pre-joined the
lines, so the PowerShell legs exercised an invocation no user is ever told to
write while the shipped one stayed broken and green.

  • The harness now uses the documented pipeline verbatim (modulo $env:WT_BIN).
  • It also passes the shell explicitly, matching what the bash leg already did —
    previously a stray MSYSTEM/SHELL could have made it auto-detect bash and
    feed bash code into Invoke-Expression.
  • TestPowerShellSetupLineHasNoDrift pins docs/installation.md and
    e2e/run.go to the constant and fails if either regresses to the
    subexpression form. I verified the guard actually fires by reintroducing the
    old line in a scratch copy.

Verification

Dispatched CI on this branch before opening the PR: run 32257055607 — all green.

The E2E (windows, powershell) leg is Windows PowerShell 5.1, the environment
from the issue: 77 scenarios passed, 0 failed. Those scenarios assert
cwd_ends_with, which only passes if the wt function performed
Set-Locationwt.exe alone cannot change its parent shell's directory. So
this is real evidence the integration loaded, not the false pass the issue
warned about.

Known gap, not addressed here

The five PowerShell PTY tests in cmd/e2e_interactive_test.go are aligned to
the documented form too, but they never run in CI: they are guarded by
testing.Short() and both unit-test jobs run go test -short. Worth a separate
issue; out of scope for this fix. The real coverage comes from e2e/run.go.

@timvw
timvw enabled auto-merge (squash) August 19, 2026 16:39
@codecov

codecov Bot commented Aug 19, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 50.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 37.82%. Comparing base (8161a2f) to head (d139e17).

Files with missing lines Patch % Lines
e2e/run.go 0.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #135      +/-   ##
==========================================
+ Coverage   37.76%   37.82%   +0.06%     
==========================================
  Files          33       33              
  Lines        3509     3506       -3     
==========================================
+ Hits         1325     1326       +1     
+ Misses       2090     2085       -5     
- Partials       94       95       +1     
Files with missing lines Coverage Δ
cmd/init.go 49.09% <100.00%> (-0.46%) ⬇️
cmd/shellenv.go 80.05% <ø> (ø)
e2e/run.go 0.00% <0.00%> (ø)

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

timvw added 2 commits August 19, 2026 18:56
…oads

The documented $PROFILE line, Invoke-Expression (& wt shellenv powershell),
fails on Windows PowerShell 5.1. shellenv emits many lines, so the
subexpression evaluates to an Object[] and Invoke-Expression's -Command
parameter ([string]) rejects it. The wt function is never defined, so auto-cd,
completion and the interactive menus are silently absent while wt.exe on PATH
keeps plain commands working.

Pipe through Out-String instead, and hoist the line into a shared
powershellSetupLine constant used by wt init and the shellenv help.

CI missed this because the E2E harness sourced shellenv via its own
pre-joined variant rather than the documented form; it now uses the documented
pipeline, and a test pins docs/installation.md and e2e/run.go to it.

Fixes #130
… e2e

The bash leg already names its shell; the PowerShell legs relied on
auto-detection, so a stray MSYSTEM/SHELL in the runner environment could
have fed the bash integration into Invoke-Expression. Naming powershell
also makes the harness match the documented $PROFILE line exactly.
@timvw
timvw force-pushed the fix/130-powershell-shellenv branch from 9bfe965 to d139e17 Compare August 19, 2026 16:56
@timvw
timvw merged commit 3d1f2c1 into main Aug 19, 2026
19 of 22 checks passed
@timvw
timvw deleted the fix/130-powershell-shellenv branch August 19, 2026 17:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PowerShell integration fails to load: Invoke-Expression (& wt shellenv powershell) errors on multi-line output

1 participant