smoke-windows.ps1 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. $previousRunAsNode = $env:ELECTRON_RUN_AS_NODE
  18. try {
  19. $env:ELECTRON_RUN_AS_NODE = '1'
  20. Invoke-Checked $electron @((Join-Path $fixtureRoot 'owned-directory-smoke.mjs'))
  21. } finally { $env:ELECTRON_RUN_AS_NODE = $previousRunAsNode }
  22. $cleanupExe = Join-Path $scratch 'cleanup.exe'
  23. $cleanupResult = Join-Path $scratch 'cleanup.txt'
  24. Invoke-Checked $Makensis @('/V2', "/DOUTPUT_FILE=$cleanupExe", "/DRESULT_FILE=$cleanupResult", (Join-Path $fixtureRoot 'installer-cleanup-smoke.nsi'))
  25. Invoke-Checked $cleanupExe @('/S')
  26. if ((Get-Content -LiteralPath $cleanupResult -Raw) -ne 'scratch removed; archive, plugin, rollback, registers and error flags preserved') {
  27. throw 'NSIS cleanup did not preserve its sentinels'
  28. }
  29. $payload = Join-Path $scratch 'payload'
  30. New-Item -ItemType Directory -Path $payload | Out-Null
  31. [System.IO.File]::WriteAllText((Join-Path $payload 'locked.txt'), 'new runtime')
  32. [System.IO.File]::WriteAllText((Join-Path $payload 'asset.txt'), 'new asset')
  33. $archive = Join-Path $scratch 'payload.7z'
  34. Invoke-Checked $SevenZip @('a', '-bd', '-t7z', $archive, "$payload/*")
  35. foreach ($mode in @('copy', 'direct')) {
  36. $target = Join-Path $scratch $mode
  37. New-Item -ItemType Directory -Path $target | Out-Null
  38. $locked = Join-Path $target 'locked.txt'
  39. [System.IO.File]::WriteAllText($locked, 'old runtime')
  40. $probeExe = Join-Path $scratch "$mode.exe"
  41. $probeResult = Join-Path $scratch "$mode.txt"
  42. $compileArgs = @('/V2', "/DOUTPUT_FILE=$probeExe", "/DRESULT_FILE=$probeResult", "/DPAYLOAD_FILE=$archive", "/DTARGET_DIR=$target", "/DPLUGIN_DIR=$PluginDir")
  43. if ($mode -eq 'direct') { $compileArgs += '/DDIRECT' }
  44. $compileArgs += Join-Path $fixtureRoot 'installer-write-failure-smoke.nsi'
  45. Invoke-Checked $Makensis $compileArgs
  46. $handle = [System.IO.File]::Open($locked, 'Open', 'Read', 'Read')
  47. try { Invoke-Checked $probeExe @('/S') }
  48. finally { $handle.Dispose() }
  49. $flag = if ($mode -eq 'copy') { 'true' } else { 'false' }
  50. $expected = "errorFlag=$flag`nlocked=old runtime`nasset=new asset"
  51. if ((Get-Content -LiteralPath $probeResult -Raw).Replace("`r`n", "`n").TrimEnd() -ne $expected) {
  52. throw "Unexpected NSIS $mode replacement result"
  53. }
  54. }
  55. Write-Output 'Electron cleanup and NSIS cleanup/replacement smokes passed.'
  56. } finally {
  57. $tempRoot = [System.IO.Path]::GetFullPath([System.IO.Path]::GetTempPath())
  58. $resolvedScratch = [System.IO.Path]::GetFullPath($scratch)
  59. if (-not $resolvedScratch.StartsWith($tempRoot, [System.StringComparison]::OrdinalIgnoreCase)) {
  60. throw "Refusing cleanup outside the temporary root: $resolvedScratch"
  61. }
  62. Remove-Item -LiteralPath $resolvedScratch -Recurse -Force
  63. }