Repository navigation
fix(profile): skip profile work in non-interactive sessions - #15
Merged
Merged
Conversation
The welcome banner, update prompt and network calls ran in every shell, including ones launched by other programs. The Vectorworks Install Manager runs 'powershell.exe Write-Output PSPresent' and requires that exact output, so the banner made it fail with 'Could not get admin privileges'. Add Test-InteractiveProfileSession and return early when stdin/stdout is redirected or -Command/-File/-EncodedCommand/-NonInteractive was used. Add Pester regression tests for Windows PowerShell and PowerShell 7.
…acOS pwsh.exe/powershell.exe don't exist off Windows, so the helper tests failed and the scripted-session tests were silently skipped in CI.
pwsh on Linux emits ESC[?1h/ESC[?1l around piped-stdin sessions, which failed the stdin test and broke Pester's XML report.
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
Profile.ps1prints a welcome banner and runs the GitHub update check (including an interactivePromptForChoice), module imports andoh-my-posh initin every PowerShell session, including ones launched by other programs.The Vectorworks Install Manager verifies PowerShell by running
powershell.exe Write-Output PSPresentand requires exactlyPSPresent. With this profile it got the banner first, so installs failed with "Installation has failed due to not being granted administrator privileges" (log:Could not get admin privileges).Fix
Test-InteractiveProfileSessionandreturnearly when stdin/stdout is redirected, or when-Command/-c/-File/-EncodedCommand/-NonInteractivewas used.Tests
New
tests/Profile.Tests.ps1(Pester 5), run against bothpowershell.exeandpwsh.exewith an isolatedHOME:PSPresentvia-Command,-Fileand piped stdinCheck-ForUpdates) is not defined/run in scripted sessionsBefore the fix: 15 of 17 failed (banner printed:
PowerShell profile loaded... PSPresent). After: 17/17 pass. PSScriptAnalyzer is clean on both files.Notes
main, so merging rolls this out to every machine on the next update check.Log-Messageuses mutex nameLocal\PSProfileUpdateLogMutex_Benjamin(double backslash), which may make logging fail silently. Worth a separate look.