fix: report real command exit codes from the PowerShell prompt wrapper - #39
Merged
Conversation
The prompt wrapper ran Get-Module before Invoke-WinTermPrompt could read $?, so LastSuccess was always true and Get-WinTermExitCode returned 0 for every finished command. The Command Timeline therefore showed Succeeded for failing cmdlets and for native commands with non-zero exit codes. The wrapper now captures $? as its first statement and hands it to Invoke-WinTermPrompt through a -LastSuccess parameter. Direct invocations without the parameter keep the previous behavior of reading $? at entry. The shell integration suite gains an installed-wrapper regression test that drives the global prompt function exactly like the console host: the first prompt must not emit a finished mark, a successful command must report 133;D;0, a failed cmdlet 133;D;1, a native exit code 133;D;5, and a later success must recover to 133;D;0.
HelloThisWorld
added a commit
that referenced
this pull request
Aug 4, 2026
Second beta of the Command Timeline release. It carries the prompt wrapper exit code fix from #39 and is otherwise identical to beta1. - Application version 1.3.0-beta2, package/file version 1.3.0.5, PowerShell module 1.3.0 with prerelease suffix beta2, channel beta. - Version literals moved across the branding metadata, manifests, resource scripts, and the six verification scripts that pin them. - README source version and build examples advanced to 1.3.0-beta2; the stable download reference stays at 1.2.0. - CHANGELOG, current progress, and docs/releases/1.3.0-beta2.md record the beta1 finding and the fix.
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.
Problem
Every Command Timeline entry in 1.3.0-beta1 shows
Succeeded, including commands that clearly failed (node src\broken.js, missing-path cmdlet errors). Failure marks can never appear.Root cause
Enable-WinTermShellIntegrationinstalls a prompt wrapper whose first statement isGet-Module -Name 'winTerm.Shell'. That statement succeeds and resets$?beforeInvoke-WinTermPromptreads it, soGet-WinTermExitCode -LastSuccess $trueshort-circuits to0on every prompt. The133;Dmark therefore always reports exit code 0 and the timeline renders every finished command as Succeeded.Fix
$?as its first statement and passes it into the module call:& $module { param($s) Invoke-WinTermPrompt -LastSuccess $s } $winTermLastSuccess.Invoke-WinTermPromptgains an optional-LastSuccessparameter; when omitted it still reads$?at entry, preserving direct-invocation behavior.Tests
scripts/winterm/test-shell-integration.ps1gainsTest-PowerShellPromptExitCodes, which enables integration and drives the installed globalpromptfunction the same way the console host does:133;Aand no133;D133;D;0Get-Itemon a missing path) →133;D;1cmd /c exit 5) →133;D;5133;D;0Verified red on the unfixed module (fails with "A failed cmdlet was not reported as exit code 1.") and green with the fix. Full suite (
WindowsPowerShell+PowerShell7+CMD) passes, and the privacy gate passes.