make the cloud backup update script require powershell 4 and make that the repo default for new scripts

This commit is contained in:
2026-11-17 10:43:19 -05:00
parent 2bbb07c05e
commit 4e766357cc
5 changed files with 37 additions and 13 deletions
+21 -5
View File
@@ -1,4 +1,4 @@
#Requires -Version 5.1
#Requires -Version 4.0
# Run with Windows PowerShell. All downloads, plan checks and installs are fixtures.
$ErrorActionPreference = 'Stop'
$repo = Split-Path -Parent $PSScriptRoot
@@ -19,6 +19,10 @@ function Find-TestFunction($Tree, $Name) {
try {
$core = Read-TestAst (Join-Path $repo 'Update-EmberkomCloudBackup.ps1')
$shim = Read-TestAst (Join-Path $repo 'rmm/Update-EmberkomCloudBackup.ps1')
foreach ($entry in @($shim,$core)) {
if ($entry.ScriptRequirements.RequiredPSVersion -ne [version]'4.0') { throw "Expected #Requires -Version 4.0 in $($entry.Extent.File)" }
}
$windowFn = Find-TestFunction $core 'Test-CloudBackupUpdateWindow'
. ([scriptblock]::Create($windowFn.Extent.Text))
foreach ($case in @(
@@ -54,7 +58,10 @@ try {
return $path
}
function New-Object {
param($TypeName)
param($TypeName,[object[]]$ArgumentList)
if ($TypeName -eq 'System.Threading.Mutex') {
return (Microsoft.PowerShell.Utility\New-Object -TypeName $TypeName -ArgumentList $ArgumentList)
}
if ($TypeName -ne 'Net.WebClient') { throw "Unexpected construction of $TypeName" }
$client = [pscustomobject]@{}
$client | Add-Member ScriptMethod DownloadString { param($url)
@@ -77,9 +84,11 @@ try {
$record.Staged = $OutFile
[IO.File]::WriteAllBytes($OutFile, $fixtureBytes)
if ($scenario -eq 'corrupt') { [IO.File]::AppendAllText($OutFile,'x') }
if ($scenario -eq 'download failure') { throw [Net.WebException]::new('Certificate validation failed',[Net.WebExceptionStatus]::TrustFailure) }
if ($scenario -eq 'download failure') {
throw (Microsoft.PowerShell.Utility\New-Object Net.WebException -ArgumentList 'Certificate validation failed',([Net.WebExceptionStatus]::TrustFailure))
}
if ($scenario -eq 'persistent timeout' -or ($scenario -in @('timeout then success','plan during retry') -and $record.Downloads -eq 1)) {
throw [Net.WebException]::new('The operation has timed out',[Net.WebExceptionStatus]::Timeout)
throw (Microsoft.PowerShell.Utility\New-Object Net.WebException -ArgumentList 'The operation has timed out',([Net.WebExceptionStatus]::Timeout))
}
}
function Start-Sleep { param($Seconds) if ($Seconds -ne 3) { throw 'Unexpected retry delay' } }
@@ -146,7 +155,14 @@ try {
default { '' }
}
$record = @{ Downloads=0; Installs=0; Staged=$null; ManifestReads=0; CliCalls=0; PlanChecks=0 }
$messages = & (Join-Path $repo 'rmm/Update-EmberkomCloudBackup.ps1') *>&1
# PowerShell 4 writes Write-Host directly to the host. Capture it separately
# so log assertions work on 4.0 without mixing text into the core's return value.
$record.HostMessages = @()
$messages = & {
function Write-Host { param([string]$Object) $record.HostMessages += $Object }
& (Join-Path $repo 'rmm/Update-EmberkomCloudBackup.ps1') *>&1
}
$messages = @($messages) + $record.HostMessages
if ($LASTEXITCODE -ne $expected -or $record.Downloads -ne $expectedDownloads -or $record.Installs -ne $expectedInstalls) {
throw "$scenario failed. Exit=$LASTEXITCODE Downloads=$($record.Downloads) Installs=$($record.Installs). $messages"
}