fix(desktop-update): wait for rebuilt executable before relaunch

This commit is contained in:
konsisumer
2026-08-15 02:19:07 +02:00
committed by Teknium
parent 0cbc4ce83b
commit 4b0c1031db
2 changed files with 31 additions and 1 deletions

View File

@@ -447,7 +447,19 @@ function Start-DesktopRelaunch {
# the pid exists, or the fallback spawn returned a live process). The
# finally block downgrades the on-screen/on-disk outcome when it didn't
# — the sibling truth contract to posix.sh's launch acceptance.
if (-not ($RelaunchExe -and (Test-Path -LiteralPath $RelaunchExe))) { return $false }
if (-not $RelaunchExe) { return $false }
# electron-builder replaces win-unpacked in place. After a successful
# update it can remove the old Hermes.exe before writing the replacement,
# so a one-shot existence check races the rebuild and strands the user.
$relaunchDeadline = (Get-Date).AddSeconds(120)
while (-not (Test-Path -LiteralPath $RelaunchExe)) {
if ((Get-Date) -ge $relaunchDeadline) {
Write-HandoffLog "WARNING: desktop relaunch executable did not reappear within 120s: $RelaunchExe"
return $false
}
Start-Sleep -Milliseconds 500
if ($script:Ui) { [System.Windows.Forms.Application]::DoEvents() }
}
Write-HandoffLog "relaunching desktop: $RelaunchExe"
# DO NOT spawn Hermes.exe as our child: Electron/Chromium calls
# AttachConsole(ATTACH_PARENT_PROCESS) at boot, so a Desktop launched

View File

@@ -87,3 +87,21 @@ def test_update_no_longer_invokes_the_hermes_exe_shim() -> None:
"exact self-lock this fix removes -- route it through $pythonExe "
"instead."
)
def test_desktop_relaunch_waits_for_an_in_place_rebuild() -> None:
source = _read()
relaunch = re.search(
r"function Start-DesktopRelaunch \{(?P<body>.*?)\n\}\n\nfunction Invoke-HermesStep",
source,
re.DOTALL,
)
assert relaunch, "Expected Start-DesktopRelaunch in the Windows hand-off script."
body = relaunch.group("body")
assert "if (-not $RelaunchExe) { return $false }" in body
assert "$relaunchDeadline = (Get-Date).AddSeconds(120)" in body
assert "while (-not (Test-Path -LiteralPath $RelaunchExe))" in body
assert "if ((Get-Date) -ge $relaunchDeadline)" in body
assert "Start-Sleep -Milliseconds 500" in body
assert "[System.Windows.Forms.Application]::DoEvents()" in body