From ebbda6e321b6814f75a1cc5b5fed298c06540d4c Mon Sep 17 00:00:00 2001 From: "Bingxi Zhao (Frank)" <13051345080@163.com> Date: Fri, 30 Oct 2026 07:23:57 +0800 Subject: [PATCH] test(desktop): verify Windows installer lifecycle and preserve user files --- .github/workflows/desktop-release.yml | 6 ++ apps/desktop/README.md | 8 ++- .../platforms/windows-x64/installer.nsi | 21 ++++-- .../platforms/windows-x64/smoke-installer.ps1 | 71 +++++++++++++++++++ 4 files changed, 98 insertions(+), 8 deletions(-) create mode 100644 apps/desktop/platforms/windows-x64/smoke-installer.ps1 diff --git a/.github/workflows/desktop-release.yml b/.github/workflows/desktop-release.yml index 062a47a65..ddd32890b 100644 --- a/.github/workflows/desktop-release.yml +++ b/.github/workflows/desktop-release.yml @@ -144,6 +144,11 @@ jobs: APPLE_SIGNING_IDENTITY: ${{ env.PUBLISH == 'true' && secrets.APPLE_SIGNING_IDENTITY || '' }} run: npm run package -- --target ${{ matrix.target }} + - name: Verify Windows installation and app lifecycle + if: runner.os == 'Windows' + shell: pwsh + run: ./platforms/windows-x64/smoke-installer.ps1 + - name: Notarize the DMG if: runner.os == 'macOS' && env.HAS_NOTARY == 'true' && env.PUBLISH == 'true' env: @@ -180,3 +185,4 @@ jobs: apps/desktop/out/*-Portable.zip apps/desktop/.local/${{ matrix.target }}/smoke.log apps/desktop/.local/${{ matrix.target }}/smoke-result.json + apps/desktop/.local/${{ matrix.target }}/installed-app.log diff --git a/apps/desktop/README.md b/apps/desktop/README.md index e8cd3628f..dec998ff4 100644 --- a/apps/desktop/README.md +++ b/apps/desktop/README.md @@ -132,5 +132,9 @@ signature and platform rejection, process shutdown, cancellation and local service behaviour; CI runs it on Linux and Windows. `npm run smoke` boots the real bundled core in a fresh temporary workspace, checks backend, frontend and API proxy, then verifies both ports close. It does not call a paid model or -test optional external renderers. `OPEN_DEEPTUTOR_TEST_HOME` selects a -disposable desktop home for UI checks. +test optional external renderers. Windows CI also runs +`platforms/windows-x64/smoke-installer.ps1`: it silently installs the app, +opens the actual Electron window with a fresh data path containing spaces and +Chinese characters, checks UI/API readiness and service shutdown on window +close, then verifies uninstall preserves learning data and unrelated files. +`OPEN_DEEPTUTOR_TEST_HOME` selects a disposable desktop home for UI checks. diff --git a/apps/desktop/platforms/windows-x64/installer.nsi b/apps/desktop/platforms/windows-x64/installer.nsi index 0769d7dc9..28073495b 100644 --- a/apps/desktop/platforms/windows-x64/installer.nsi +++ b/apps/desktop/platforms/windows-x64/installer.nsi @@ -44,12 +44,21 @@ VIAddVersionKey "FileVersion" "${FILEVERSION}" RMDir /r "$INSTDIR\resources" RMDir /r "$INSTDIR\locales" Delete "$INSTDIR\${EXE}" - Delete "$INSTDIR\*.dll" - Delete "$INSTDIR\*.pak" - Delete "$INSTDIR\*.bin" - Delete "$INSTDIR\*.dat" - Delete "$INSTDIR\*.json" - Delete "$INSTDIR\LICENSE*" + Delete "$INSTDIR\d3dcompiler_47.dll" + Delete "$INSTDIR\dxcompiler.dll" + Delete "$INSTDIR\electron_wer.dll" + Delete "$INSTDIR\ffmpeg.dll" + Delete "$INSTDIR\vk_swiftshader.dll" + Delete "$INSTDIR\vulkan-1.dll" + Delete "$INSTDIR\chrome_100_percent.pak" + Delete "$INSTDIR\chrome_200_percent.pak" + Delete "$INSTDIR\resources.pak" + Delete "$INSTDIR\snapshot_blob.bin" + Delete "$INSTDIR\v8_context_snapshot.bin" + Delete "$INSTDIR\icudtl.dat" + Delete "$INSTDIR\vk_swiftshader_icd.json" + Delete "$INSTDIR\LICENSE" + Delete "$INSTDIR\LICENSES.chromium.html" Delete "$INSTDIR\version" !macroend diff --git a/apps/desktop/platforms/windows-x64/smoke-installer.ps1 b/apps/desktop/platforms/windows-x64/smoke-installer.ps1 new file mode 100644 index 000000000..1ec8ee3cd --- /dev/null +++ b/apps/desktop/platforms/windows-x64/smoke-installer.ps1 @@ -0,0 +1,71 @@ +# Run the actual installed Electron app with a fresh, non-ASCII user path. +$ErrorActionPreference = 'Stop' +$desktop = (Resolve-Path "$PSScriptRoot/../..").Path +$installer = @(Get-ChildItem "$desktop/out/*-Setup.exe") +if ($installer.Count -ne 1) { throw 'Expected exactly one Windows installer' } +$root = Join-Path $env:TEMP "DeepTutor 安装 smoke $([guid]::NewGuid())" +$install = Join-Path $root 'installed app' +$userRoot = Join-Path $root 'user data' +New-Item -ItemType Directory -Path $install, $userRoot -Force | Out-Null +# A custom destination may already contain unrelated files of the same types. +$sentinel = Join-Path $install 'keep-user-file.dll' +Set-Content $sentinel 'unrelated user file' +$oldPath = $env:PATH +$oldHome = $env:OPEN_DEEPTUTOR_TEST_HOME +$appProcess = $null +$log = Join-Path $userRoot 'logs/runtime.log' +try { + $setup = Start-Process $installer[0].FullName -ArgumentList @('/S', "/D=$install") -Wait -PassThru + if ($setup.ExitCode -ne 0) { throw "Installer exited with $($setup.ExitCode)" } + $exe = Join-Path $install 'Open DeepTutor.exe' + if (!(Test-Path $exe) -or !(Test-Path $sentinel)) { throw 'Install did not preserve the destination' } + $env:OPEN_DEEPTUTOR_TEST_HOME = $userRoot + $env:PATH = "$env:SystemRoot\System32;$env:SystemRoot;$env:SystemRoot\System32\Wbem" + $appProcess = Start-Process $exe -PassThru + $deadline = (Get-Date).AddMinutes(10) + $backend = $null + $frontend = $null + do { + if ($appProcess.HasExited) { throw "App exited early: $($appProcess.ExitCode)" } + if (Test-Path $log) { + $text = Get-Content $log -Raw + if ($text -match 'Uvicorn running on (http://127\.0\.0\.1:\d+)') { $backend = $Matches[1] } + if ($text -match 'Local:\s+(http://127\.0\.0\.1:\d+)') { $frontend = $Matches[1] } + } + if ($backend -and $frontend) { + try { + $health = Invoke-WebRequest "$backend/health/ready" -TimeoutSec 5 + $page = Invoke-WebRequest $frontend -TimeoutSec 5 + $proxy = Invoke-WebRequest "$frontend/api/settings/ui" -TimeoutSec 5 + if ($health.StatusCode -eq 200 -and $page.Content -match 'DeepTutor' -and $proxy.StatusCode -eq 200) { break } + } catch { } + } + if ((Get-Date) -gt $deadline) { throw 'Installed app did not become ready' } + Start-Sleep -Seconds 2 + } while ($true) + + # Closing the real window must stop both services, not just Electron. + $appProcess.Refresh() + if (!$appProcess.CloseMainWindow()) { throw 'App did not expose a main window' } + if (!$appProcess.WaitForExit(30000)) { throw 'App did not quit after closing its window' } + foreach ($url in @($frontend, "$backend/health/ready")) { + $responded = $false + try { Invoke-WebRequest $url -TimeoutSec 3 | Out-Null; $responded = $true } catch { } + if ($responded) { throw "Service survived app exit: $url" } + } + $data = Join-Path $userRoot 'workspace/data/user/settings/interface.json' + if (!(Test-Path $data)) { throw 'App did not initialize its user data' } + Start-Process (Join-Path $install 'Uninstall Open DeepTutor.exe') -ArgumentList '/S' -Wait | Out-Null + $deadline = (Get-Date).AddSeconds(30) + while ((Test-Path $exe) -and (Get-Date) -lt $deadline) { Start-Sleep -Seconds 1 } + if (Test-Path $exe) { throw 'Uninstall left the app executable behind' } + if (!(Test-Path $sentinel) -or !(Test-Path $data)) { throw 'Uninstall removed user files or learning data' } + Write-Host 'PASS: Windows install, first launch, UI/API, window close, and uninstall preserve user data.' +} finally { + if ($appProcess -and !$appProcess.HasExited) { + & "$env:SystemRoot/System32/taskkill.exe" /PID $appProcess.Id /T /F | Out-Null + } + $env:PATH = $oldPath + $env:OPEN_DEEPTUTOR_TEST_HOME = $oldHome + if (Test-Path $log) { Copy-Item $log "$desktop/.local/windows-x64/installed-app.log" -Force } +}