smoke-windows.ps1 2.6 KB

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