Skip to content

The agent that grows with you

test(install-e2e): Windows desktop checkpoints run outside the runner's job object

Tekniume36fa27ddc7a
diff --git a/tests/install/e2e-assets/desktop-smoke-windows.ps1 b/tests/install/e2e-assets/desktop-smoke-windows.ps1
index ced9ec91c85..3416b51d38b 100644
--- a/tests/install/e2e-assets/desktop-smoke-windows.ps1
+++ b/tests/install/e2e-assets/desktop-smoke-windows.ps1
@@ -29,6 +29,84 @@ function Start-DesktopJourneyMock([string]$Node, [string]$Assets, [string]$Work,
}
}
+# The Actions runner holds every step process in a job object that refuses
+# CREATE_BREAKAWAY_FROM_JOB (limit flags 0), and so does Task Scheduler for a task's
+# process; Hermes deliberately refuses to start a gateway it cannot detach
+# (gateway_runtime_start.py::spawn_unmanaged_gateway), so an app launched from either
+# reports "Gateway inaccessible (windows_breakaway_unavailable)". A user's
+# Explorer/Start-menu launch is in no job, and neither is a Win32_Process.Create child,
+# which WMI starts outside its caller's job (probed on hosted runners). A desktop
+# checkpoint therefore runs from such a child, with this step's environment, cwd and
+# arguments replayed from a spec file. Returns the exit code.
+$script:OutsideJobWrapper = @'
+param([string]$SpecPath)
+$ErrorActionPreference = 'Continue'
+$code = 99
+$spec = Get-Content -LiteralPath $SpecPath -Raw | ConvertFrom-Json
+# Node writes UTF-8 into a pipe; decode it as such, not as the OEM code page. Cosmetic,
+# and a session without a console rejects it, so a failure here must not fail the run.
+try { [Console]::OutputEncoding = New-Object System.Text.UTF8Encoding $false } catch { }
+try {
+ foreach ($entry in $spec.env.PSObject.Properties) { [Environment]::SetEnvironmentVariable($entry.Name, [string]$entry.Value, 'Process') }
+ Set-Location -LiteralPath $spec.cwd
+ & $spec.exe @($spec.args) 2>&1 | ForEach-Object { "$_" } | Set-Content -LiteralPath $spec.log -Encoding UTF8
+ $code = $LASTEXITCODE
+} catch {
+ "outside-job wrapper failed: $_" | Add-Content -LiteralPath $spec.log -Encoding UTF8
+} finally {
+ Set-Content -LiteralPath $spec.exit -Value $code -Encoding ascii
+}
+'@
+
+function Invoke-OutsideRunnerJob([string]$Name, [string]$Work, [string]$Exe, [string[]]$Arguments, [int]$TimeoutMinutes = 45) {
+ $dir = Join-Path $Work "outside-job-$Name"
+ New-Item -ItemType Directory -Path $dir -Force | Out-Null
+ $spec = Join-Path $dir 'spec.json'
+ $log = Join-Path $dir 'output.log'
+ $exitFile = Join-Path $dir 'exit-code'
+ $wrapper = Join-Path $dir 'run.ps1'
+ Remove-Item -LiteralPath $log, $exitFile -Force -ErrorAction SilentlyContinue
+ $environment = [ordered]@{}
+ Get-ChildItem Env: | ForEach-Object { $environment[$_.Name] = $_.Value }
+ $cwd = (Get-Location).ProviderPath
+ # -InputObject keeps a one-element argument list a JSON array.
+ ConvertTo-Json -Depth 4 -InputObject ([ordered]@{ exe = $Exe; args = [object[]]@($Arguments); cwd = $cwd; env = $environment; log = $log; exit = $exitFile }) |
+ Set-Content -LiteralPath $spec -Encoding UTF8
+ $script:OutsideJobWrapper | Set-Content -LiteralPath $wrapper -Encoding UTF8
+ # The same PowerShell as this step, so native argument passing matches a direct call.
+ $shell = (Get-Process -Id $PID).Path
+ $commandLine = "`"$shell`" -NoProfile -NonInteractive -ExecutionPolicy Bypass -File `"$wrapper`" -SpecPath `"$spec`""
+ $wrapperPid = 0
+ try {
+ $created = Invoke-CimMethod -ClassName Win32_Process -MethodName Create -Arguments @{ CommandLine = $commandLine; CurrentDirectory = $cwd }
+ if ($created.ReturnValue -ne 0) { throw "Outside-job run '$Name' could not start (Win32_Process.Create returned $($created.ReturnValue))" }
+ $wrapperPid = [int]$created.ProcessId
+ $deadline = (Get-Date).AddMinutes($TimeoutMinutes)
+ while (-not (Test-Path -LiteralPath $exitFile)) {
+ if ((Get-Date) -ge $deadline) { throw "Outside-job run '$Name' did not finish within $TimeoutMinutes minutes" }
+ if (-not (Get-Process -Id $wrapperPid -ErrorAction SilentlyContinue)) {
+ # The wrapper writes the exit file last; give a racing write a moment.
+ Start-Sleep -Seconds 2
+ if (-not (Test-Path -LiteralPath $exitFile)) { throw "Outside-job run '$Name' exited without an exit code" }
+ break
+ }
+ Start-Sleep -Seconds 2
+ }
+ } finally {
+ # Outside the runner's job, nothing reaps an unfinished run's tree. A finished run's
+ # detached gateway is meant to outlive it, so only a run without an exit code is killed.
+ if ($wrapperPid -and -not (Test-Path -LiteralPath $exitFile) -and (Get-Process -Id $wrapperPid -ErrorAction SilentlyContinue)) { & taskkill.exe /PID $wrapperPid /T /F | Out-Null }
+ Write-Host "--- outside-job '$Name' output ($log) ---"
+ if (Test-Path -LiteralPath $log) { Get-Content -LiteralPath $log -Encoding UTF8 | ForEach-Object { Write-Host $_ } }
+ Write-Host "--- end outside-job '$Name' output ---"
+ # The spec replays this step's environment, runner tokens included.
+ Remove-Item -LiteralPath $spec -Force -ErrorAction SilentlyContinue
+ }
+ $text = (Get-Content -LiteralPath $exitFile -Raw).Trim()
+ if ($text -notmatch '^-?\d+$') { throw "Outside-job run '$Name' wrote no exit code ('$text')" }
+ return [int]$text
+}
+
function Get-VerifiedDesktopWindows([string]$Exe) {
# The detached updater canonicalizes the WorkRoot path while the driver can
# retain ``..`` segments. Compare executable identity, not path spelling.
diff --git a/tests/install/windows-e2e.ps1 b/tests/install/windows-e2e.ps1
index 145b2e0aa73..39702f8cbb5 100644
--- a/tests/install/windows-e2e.ps1
+++ b/tests/install/windows-e2e.ps1
@@ -176,14 +176,11 @@ function Invoke-DesktopCheckpoint([string]$ChatPhase, [string]$Commit, [string]$
# the journey mock's URL file lets a later step's mock rebind the same port.
Start-JourneyChat
$script:ChatFailure = $true
- $prevEap = $ErrorActionPreference
- try {
- $ErrorActionPreference = 'Continue'
- & $DriverNode (Join-Path $AssetsDir 'source-desktop-smoke.mjs') `
- --root $InstallDir --home $HermesHome --user-data $env:HERMES_DESKTOP_USER_DATA_DIR `
- --out $ProofRoot --phase $ChatPhase --expect-commit $Commit --desktop $script:ExpectedDesktop --method $Method
- $chatExit = $LASTEXITCODE
- } finally { $ErrorActionPreference = $prevEap }
+ # The app must be able to detach its gateway, as from a user's launch (see Invoke-OutsideRunnerJob).
+ $chatExit = Invoke-OutsideRunnerJob "desktop-$ChatPhase" $WorkRoot $DriverNode @(
+ (Join-Path $AssetsDir 'source-desktop-smoke.mjs'),
+ '--root', $InstallDir, '--home', $HermesHome, '--user-data', $env:HERMES_DESKTOP_USER_DATA_DIR,
+ '--out', $ProofRoot, '--phase', $ChatPhase, '--expect-commit', $Commit, '--desktop', $script:ExpectedDesktop, '--method', $Method)
if ($chatExit -ne 0) { throw "Mandatory desktop chat $ChatPhase failed (exit $chatExit)" }
$script:ChatFailure = $false
}