BeforeAll { Import-Module "$PSScriptRoot/../src/Elevation.psm1" -Force } Describe 'Elevation host selection' { It 'uses the current PowerShell installation instead of PATH' { InModuleScope Elevation -Parameters @{ Working = $TestDrive } { Mock Test-IsAdministrator { $false } Mock Protect-ElevationFile {} Mock Start-Process { $script:startedFile = $FilePath $match = [regex]::Match($ArgumentList, '-ResultPath\s+"([^"]+)"') '{"succeeded":true,"results":[]}' | Set-Content -LiteralPath $match.Groups[1].Value [pscustomobject]@{ ExitCode = 0 } } $paths = [pscustomobject]@{ Root = $Working } $operation = [pscustomobject]@{ kind = 'package'; name = 'Example.App'; action = 'Install'; reason = 'Missing' package = [pscustomobject]@{ id = 'Example.App'; source = 'winget'; scope = 'machine'; update = 'latest' } } [void](Invoke-ElevatedPackageBatch -Operations @($operation) -RepositoryRoot $Working -Paths $paths) $script:startedFile | Should -Be (Join-Path $PSHOME 'pwsh.exe') } } }