smoke-windows.ps1 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. # Run native Electron cleanup and NSIS replacement checks against the prepared Windows target.
  2. param(
  3. [Parameter(Mandatory)][string]$Electron,
  4. [Parameter(Mandatory)][string]$Makensis,
  5. [Parameter(Mandatory)][string]$SevenZip,
  6. [Parameter(Mandatory)][string]$PluginDir
  7. )
  8. $ErrorActionPreference = 'Stop'
  9. $desktopRoot = Split-Path $PSScriptRoot -Parent
  10. $scratch = [System.IO.Directory]::CreateTempSubdirectory('dsh-desktop-native-').FullName
  11. $fixtureRoot = Join-Path $desktopRoot 'tests/fixtures'
  12. function Invoke-Checked([string]$Executable, [string[]]$Arguments) {
  13. & $Executable @Arguments | Out-Host
  14. if ($LASTEXITCODE -ne 0) { throw "$Executable exited with $LASTEXITCODE" }
  15. }
  16. try {
  17. & (Join-Path $PSScriptRoot 'smoke-installer-directories.ps1') -Makensis $Makensis -SevenZip $SevenZip
  18. $previousRunAsNode = $env:ELECTRON_RUN_AS_NODE
  19. try {
  20. $env:ELECTRON_RUN_AS_NODE = '1'
  21. Invoke-Checked $electron @((Join-Path $fixtureRoot 'owned-directory-smoke.mjs'))
  22. } finally { $env:ELECTRON_RUN_AS_NODE = $previousRunAsNode }
  23. $payload = Join-Path $scratch 'payload'
  24. New-Item -ItemType Directory -Path $payload | Out-Null
  25. [System.IO.File]::WriteAllText((Join-Path $payload 'locked.txt'), 'new runtime')
  26. [System.IO.File]::WriteAllText((Join-Path $payload 'asset.txt'), 'new asset')
  27. $archive = Join-Path $scratch 'payload.7z'
  28. Invoke-Checked $SevenZip @('a', '-bd', '-t7z', $archive, "$payload/*")
  29. foreach ($mode in @('copy', 'direct')) {
  30. $target = Join-Path $scratch $mode
  31. New-Item -ItemType Directory -Path $target | Out-Null
  32. $locked = Join-Path $target 'locked.txt'
  33. [System.IO.File]::WriteAllText($locked, 'old runtime')
  34. $probeExe = Join-Path $scratch "$mode.exe"
  35. $probeResult = Join-Path $scratch "$mode.txt"
  36. $compileArgs = @('/V2', "/DOUTPUT_FILE=$probeExe", "/DRESULT_FILE=$probeResult", "/DPAYLOAD_FILE=$archive", "/DTARGET_DIR=$target", "/DPLUGIN_DIR=$PluginDir")
  37. if ($mode -eq 'direct') { $compileArgs += '/DDIRECT' }
  38. $compileArgs += Join-Path $fixtureRoot 'installer-write-failure-smoke.nsi'
  39. Invoke-Checked $Makensis $compileArgs
  40. $handle = [System.IO.File]::Open($locked, 'Open', 'Read', 'Read')
  41. try { Invoke-Checked $probeExe @('/S') }
  42. finally { $handle.Dispose() }
  43. $flag = if ($mode -eq 'copy') { 'true' } else { 'false' }
  44. $expected = "errorFlag=$flag`nlocked=old runtime`nasset=new asset"
  45. if ((Get-Content -LiteralPath $probeResult -Raw).Replace("`r`n", "`n").TrimEnd() -ne $expected) {
  46. throw "Unexpected NSIS $mode replacement result"
  47. }
  48. }
  49. Write-Output 'Electron cleanup and NSIS directory/replacement smokes passed.'
  50. } finally {
  51. $tempRoot = [System.IO.Path]::GetFullPath([System.IO.Path]::GetTempPath())
  52. $resolvedScratch = [System.IO.Path]::GetFullPath($scratch)
  53. if (-not $resolvedScratch.StartsWith($tempRoot, [System.StringComparison]::OrdinalIgnoreCase)) {
  54. throw "Refusing cleanup outside the temporary root: $resolvedScratch"
  55. }
  56. Remove-Item -LiteralPath $resolvedScratch -Recurse -Force
  57. }