Skip to content

fix(profile): skip profile work in non-interactive sessions - #15

Merged
BenjaminMichaelis merged 3 commits into
mainfrom
fix/profile-skip-noninteractive
Nov 14, 2026
Merged

BenjaminMichaelis merged 3 commits into
mainfrom
fix/profile-skip-noninteractive

Conversation

@BenjaminMichaelis

Copy link
Copy Markdown
Owner

Problem

Profile.ps1 prints a welcome banner and runs the GitHub update check (including an interactive PromptForChoice), module imports and oh-my-posh init in every PowerShell session, including ones launched by other programs.

The Vectorworks Install Manager verifies PowerShell by running powershell.exe Write-Output PSPresent and requires exactly PSPresent. 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

  • Add Test-InteractiveProfileSession and return early when stdin/stdout is redirected, or when -Command/-c/-File/-EncodedCommand/-NonInteractive was used.
  • Normal terminal sessions behave as before.

Tests

New tests/Profile.Tests.ps1 (Pester 5), run against both powershell.exe and pwsh.exe with an isolated HOME:

  • Output is exactly PSPresent via -Command, -File and piped stdin
  • Startup work (Check-ForUpdates) is not defined/run in scripted sessions
  • Decision-logic cases for interactive vs. non-interactive launches

Before the fix: 15 of 17 failed (banner printed: PowerShell profile loaded... PSPresent). After: 17/17 pass. PSScriptAnalyzer is clean on both files.

Notes

  • The profile self-updates from main, so merging rolls this out to every machine on the next update check.
  • Not covered here: Log-Message uses mutex name Local\PSProfileUpdateLogMutex_Benjamin (double backslash), which may make logging fail silently. Worth a separate look.

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.
@BenjaminMichaelis
BenjaminMichaelis merged commit 7120830 into main Nov 14, 2026
12 checks passed
@BenjaminMichaelis
BenjaminMichaelis deleted the fix/profile-skip-noninteractive branch November 14, 2026 09:20
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