Skip to content

fix(shellenv): propagate failed exit codes on Linux; fix e2e exit-code leak - #119

Merged
timvw merged 2 commits into
mainfrom
fix/exit-code-propagation
Aug 10, 2026
Merged

fix(shellenv): propagate failed exit codes on Linux; fix e2e exit-code leak#119
timvw merged 2 commits into
mainfrom
fix/exit-code-propagation

Conversation

@timvw

@timvw timvw commented Aug 10, 2026

Copy link
Copy Markdown
Owner

Two pre-existing bugs found while working on #117.

1. The bash/zsh wrapper swallows failures on Linux

The wrapper runs commands under script(1) to give promptui a PTY. util-linux's script returns its own exit status unless --return is passed, so on Linux a failed command reported success to the shell:

wt co nonexistent-branch && echo "ok"   # printed ok

BSD/macOS script propagates the child's status, which is why this never showed up locally or in macOS CI. The fish integration already passes --return and even carries a comment explaining exactly this — bash and zsh were simply missed. Fix is the same one-flag change.

2. e2e/run.go leaks __exit_code between steps

${__exit_code:-0} only defaults when the variable is unset or empty, so a step expecting exit code 0 after a step expecting non-zero inherited the stale 1 and failed spuriously. This is why every non-zero assertion in the suite had to use skip_shellenv + $WT_BIN. Only the POSIX generator was affected — the fish and PowerShell generators assign the status unconditionally.

Regression coverage

Two new scenarios in shellenv.yaml, both exercised through the wrapper:

  • shellenv_propagates_failure_exit_code — a failing wt remove exits 1.
  • shellenv_success_after_failure_exit_code — a successful wt list after a failing command still reports 0.

Each fix is independently covered:

  • Reverting only the --return change in a Linux container (golang:1.25, util-linux 2.41): 4 failures (both scenarios × bash and zsh). With the fix: 213 passed, 0 failed.
  • Reverting only the run.go change on macOS: shellenv_success_after_failure_exit_code fails.

Full local suite on macOS: 316 passed, 0 failed. go vet and gofmt clean.

Note

--return is a util-linux long option. Busybox script does not support it, so a busybox-only environment would now error rather than silently return the wrong code — but the fish integration has already shipped this assumption, and environments without script at all (Git Bash, minimal containers) take the existing fallback branch, which captures $? correctly.

timvw added 2 commits August 10, 2026 17:47
On Linux the wrapper runs commands under util-linux script(1), which
returns its own exit status unless --return is passed. A failing command
therefore reported success to the shell: 'wt co nonexistent && echo ok'
printed ok. The fish integration already passes --return; bash and zsh
were missed.

Covered by two new shellenv scenarios; both fail on Linux without the
fix (verified in a container for bash and zsh) and pass with it.
"${__exit_code:-0}" only defaults when the variable is unset or empty, so
a step expecting exit code 0 inherited the previous step's non-zero code
and failed spuriously. Only the POSIX generator was affected; the fish
and PowerShell generators assign the status unconditionally.
@codecov

codecov Bot commented Aug 10, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 80.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 36.98%. Comparing base (a81a147) to head (84045a0).

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     #119      +/-   ##
==========================================
+ Coverage   36.82%   36.98%   +0.16%     
==========================================
  Files          28       28              
  Lines        3199     3201       +2     
==========================================
+ Hits         1178     1184       +6     
+ Misses       1935     1930       -5     
- Partials       86       87       +1     
Files with missing lines Coverage Δ
cmd/shellenv.go 78.69% <100.00%> (+0.18%) ⬆️
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
timvw merged commit 4984f16 into main Aug 10, 2026
16 checks passed
@timvw
timvw deleted the fix/exit-code-propagation branch August 10, 2026 18:29
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.

1 participant