Fix the PATH test for MSIX installed PowerShell (#28068)

This commit is contained in:
Dongbo Wang authored and GitHub committed 2026-09-25 11:04:21 -07:00
1 parent 78c98a120a
commit 5f9fcddc28
1 file changed
+14 -2
+14 -2
View File
@@ -1190,11 +1190,23 @@ Describe 'Pwsh startup and PATH' -Tag CI {
$version | Should -BeExactly "PowerShell $($PSVersionTable.GitCommitId)"
}
It 'pwsh starts even if PATH is not defined' {
It 'pwsh updates PATH correctly even if PATH is not defined' {
$pwsh = Join-Path -Path $PSHOME -ChildPath "pwsh"
Remove-Item Env:\PATH
$path = & $pwsh -noprofile -command '$env:PATH'
$path | Should -BeExactly ($PSHOME + [System.IO.Path]::PathSeparator)
$ExpectedPath = $PSHOME
if ($PSHOME.StartsWith("$env:ProgramFiles\WindowsApps\Microsoft.PowerShell")) {
# MSIX installed PowerShell uses the stable path instead of PSHOME.
$ExpectedPath = $PSHOME.Replace($env:ProgramFiles, "$env:LOCALAPPDATA\Microsoft")
# Remove the version-specific part from the expected path.
$version = $PSVersionTable.PSVersion
$verStrRegex = "$($version.Major)\.$($version.Minor)\.$($version.Build).+__"
$ExpectedPath = $ExpectedPath -replace $verStrRegex, ''
}
$path | Should -BeExactly ($ExpectedPath + [System.IO.Path]::PathSeparator)
}
}