Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve E2E Test Fixtures to be less flaky #2208

Merged
merged 21 commits into from
Mar 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/ci-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ jobs:
shell: pwsh
run: ./pwsh/tools/install-powershell.ps1 -Daily

- name: If Debugging, start upterm for interactive pipeline troubleshooting
if: ${{ runner.debug == 1 }}
uses: lhotari/action-upterm@v1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well that's cool...I need to share with Steve. He's been asking for something exactly like this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm working on a version that lets you vscode remote into the github action, the tricky part is the authentication but it's definitely doable :)

with:
wait-timeout-minutes: 1

- name: Build and test
shell: pwsh
run: Invoke-Build -Configuration Release ${{ github.event_name == 'merge_group' && 'TestFull' || 'Test' }}
Expand Down
84 changes: 82 additions & 2 deletions PowerShellEditorServices.build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,88 @@ Task BuildCmdletHelp -After AssembleModule {
}

Task SetupHelpForTests {
Write-Build DarkMagenta 'Updating help (for tests)'
Update-Help -Module Microsoft.PowerShell.Management, Microsoft.PowerShell.Utility -Force -Scope CurrentUser -UICulture en-US
# Some CI do not ship with help included, and the secure devops pipeline also does not allow internet access, so we must update help from our local repository source.

# Only commands in Microsoft.PowerShell.Archive can be tested for help so as to minimize the repository storage.
# This requires admin rights for PS5.1

# NOTE: You can run this task once as admin or update help separately, and continue to run tests as non-admin, if for instance developing locally.

$installHelpScript = {
param(
[Parameter(Position = 0)][string]$helpPath
)
$PSVersion = $PSVersionTable.PSVersion
$ErrorActionPreference = 'Stop'
$helpPath = Resolve-Path $helpPath
if ($PSEdition -ne 'Desktop') {
$helpPath = Join-Path $helpPath '7'
}

if ((Get-Help Expand-Archive).remarks -notlike 'Get-Help cannot find the Help files*') {
Write-Host -ForegroundColor Green "PowerShell $PSVersion Archive help is already installed"
return
}

if ($PSEdition -eq 'Desktop') {
# Cant use requires RunAsAdministrator because PS isn't smart enough to know this is a subscript.
if (-not [Security.Principal.WindowsPrincipal]::new(
[Security.Principal.WindowsIdentity]::GetCurrent()
).IsInRole(
[Security.Principal.WindowsBuiltInRole]::Administrator
)) {
throw 'Windows PowerShell Update-Help requires admin rights. Please re-run the script in an elevated PowerShell session!'
}
}

Write-Host -ForegroundColor Magenta "PowerShell $PSVersion Archive help is not installed, installing from $helpPath"

$updateHelpParams = @{
Module = 'Microsoft.PowerShell.Archive'
SourcePath = $helpPath
UICulture = 'en-US'
Force = $true
Verbose = $true
}

# PS7+ does not require admin rights if CurrentUser is used for scope. PS5.1 does not have this option.
if ($PSEdition -ne 'Desktop') {
$updateHelpParams.'Scope' = 'CurrentUser'
}
# Update the help and capture verbose output
$updateHelpOutput = Update-Help @updateHelpParams *>&1

if ((Get-Help Expand-Archive).remarks -like 'Get-Help cannot find the Help files*') {
throw "Failed to install PowerShell $PSVersion Help: $updateHelpOutput"
} else {
Write-Host -ForegroundColor Green "PowerShell $PSVersion Archive help installed successfully"
}
}

# Need this to inject the help file path since PSScriptRoot won't work inside the script
$helpPath = Resolve-Path "$PSScriptRoot\test\PowerShellEditorServices.Test.Shared\PSHelp" -ErrorAction Stop
Write-Build DarkMagenta "Runner help located at $helpPath"

if (Get-Command powershell.exe -CommandType Application -ea 0) {
Write-Build DarkMagenta 'Checking PowerShell 5.1 help'
& powershell.exe -NoProfile -NonInteractive -Command $installHelpScript -args $helpPath
if ($LASTEXITCODE -ne 0) {
throw 'Failed to install PowerShell 5.1 help!'
}
}

if ($PwshDaily -and (Get-Command $PwshDaily -ea 0)) {
Write-Build DarkMagenta "Checking PowerShell Daily help at $PwshDaily"
Invoke-BuildExec { & $PwshDaily -NoProfile -NonInteractive -Command $installHelpScript -args $helpPath }
if ($LASTEXITCODE -ne 0) {
throw 'Failed to install PowerShell Daily help!'
}
}

if ($PSEdition -eq 'Core') {
Write-Build DarkMagenta "Checking this PowerShell process's help"
& $installHelpScript $helpPath
}
}

Task TestPS74 Build, SetupHelpForTests, {
Expand Down
3 changes: 2 additions & 1 deletion src/PowerShellEditorServices/Server/PsesDebugServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ public async Task StartAsync()
response.SupportsDelayedStackTraceLoading = true;

return Task.CompletedTask;
});
})
;
}).ConfigureAwait(false);
}

Expand Down
Loading