validation check prereqs without staging/caching

This commit is contained in:
2026-10-23 12:23:42 -04:00
parent 08dbb3cdd5
commit f9daec0542
4 changed files with 155 additions and 278 deletions
+54 -100
View File
@@ -350,7 +350,7 @@ try {
if ([IO.Path]::GetFileName($Path) -eq 'odt-download-page.html') {
Assert-OfficeTest ($TimeoutSeconds -eq (Get-OfficeDeploymentDefinitions).OdtPageTimeoutSeconds) 'ODT page must use the retried downloader with its configured timeout.'
[IO.File]::WriteAllText($Path, 'https://download.microsoft.com/test/officedeploymenttool_test.exe')
} elseif ([IO.Path]::GetFileName($Path) -eq 'office-release-history.html') {
} elseif ($Uri -eq (Get-OfficeDeploymentDefinitions).OfficeReleaseHistory) {
Assert-OfficeTest ($Uri -eq (Get-OfficeDeploymentDefinitions).OfficeReleaseHistory) 'Windows 10 release lookup must use Microsoft history.'
[IO.File]::WriteAllText($Path, $script:mediaHistory)
} elseif ([IO.Path]::GetFileName($Path) -eq 'Office-UserCleanup.ps1') {
@@ -833,86 +833,27 @@ try {
Assert-OfficeTest ((Get-Content -LiteralPath $Global:LogFile -Raw) -match 'Error: User cleanup task registration failed for unmapped \(C:\\Users\\defaultuser100000\)') 'Registration failures must reach the Tools diagnostic log.'
}
# Real temporary files for cache reuse/completeness; no installer or network may run.
# Validation can resolve small release metadata without keeping it or staging media.
& {
$cacheRoot = Join-Path $testRoot 'cache-tests'; $null = [IO.Directory]::CreateDirectory($cacheRoot)
$source = Join-Path $cacheRoot ('a' * 32); $null = [IO.Directory]::CreateDirectory($source)
# LiteralPath matters: the staged fixture intentionally contains brackets.
foreach ($file in Get-ChildItem -LiteralPath (Join-Path $testRoot 'media [literal]')) { Copy-Item -LiteralPath $file.FullName -Destination $source -Recurse }
$target = Join-Path $cacheRoot ('b' * 32); $null = [IO.Directory]::CreateDirectory($target)
$options = Get-OfficeDeploymentOptions @{OfficeSubscription='Microsoft/Office 365 E3/E5 (no Teams)'; OfficeArchitecture='64'; COMPANY='New Company'; OfficeAppShutdown='Force'; ValidateBeforeChanges='false'}
$script:rejectCacheSignature = $false; $script:helperDownloads = 0
function Get-CimInstance { }
function Assert-OfficeDiskSpace { throw 'Cache reuse must not request fresh-download disk reserve; the main workflow checks installation space afterward.' }
function Assert-OfficeMicrosoftSignature { param($Path) if ($script:rejectCacheSignature) { throw 'Untrusted cache signature' }; Assert-OfficeTest (Test-Path -LiteralPath $Path) 'Cache signature target was missing.' }
function Save-OfficeDownload { param($Uri,$Path) if ([IO.Path]::GetFileName($Path) -ne 'Office-UserCleanup.ps1') { throw 'Unexpected network download on cache hit' }; $script:helperDownloads++; Set-Content -LiteralPath $Path -Value ('# ' + (Get-OfficeDeploymentDefinitions).HelperVersion) }
function Invoke-OfficeProcess { throw 'A cached deployment must not redownload Office.' }
$manifestPath = Join-Path $source 'media-cache.json'
$originalManifest = Get-Content -LiteralPath $manifestPath -Raw
Assert-OfficeTest (!($originalManifest | ConvertFrom-Json).Files[0].PSObject.Properties['Hash']) 'Cache manifests must not store file checksums.'
$different = Get-OfficeDeploymentOptions @{OfficeSubscription='Microsoft/Office 365 E3/E5'; OfficeArchitecture='64'}
Assert-OfficeTest (!(Restore-OfficeMediaCache $different $target)) 'Teams selection mismatch reused the wrong cache.'
$different = Get-OfficeDeploymentOptions @{OfficeSubscription='Microsoft/Office 365 E3/E5 (no Teams)'; OfficeArchitecture='64'; UpdateChannel='MonthlyEnterprise'}
Assert-OfficeTest (!(Restore-OfficeMediaCache $different $target)) 'Channel mismatch reused the wrong cache.'
$different = Get-OfficeDeploymentOptions @{OfficeSubscription='Microsoft/Office 365 E3/E5 (no Teams)'; OfficeArchitecture='64'}
$different.TargetOfficeVersion='16.0.20326.20158'
Assert-OfficeTest (!(Restore-OfficeMediaCache $different $target)) 'A Windows 10 target reused incompatible unpinned media.'
$manifest = $originalManifest | ConvertFrom-Json; $manifest.Key = Get-OfficeMediaCacheKey $different
$manifest | ConvertTo-Json -Depth 5 | Set-Content -LiteralPath $manifestPath
Assert-OfficeTest (!(Restore-OfficeMediaCache $different $target)) 'A matching cache key hid an incompatible Windows 10 payload version.'
$manifest = $originalManifest | ConvertFrom-Json; $manifest.Schema = 1
$manifest | ConvertTo-Json -Depth 5 | Set-Content -LiteralPath $manifestPath
Assert-OfficeTest (!(Restore-OfficeMediaCache $options $target)) 'Old cache manifests must be refreshed under the new version-selection contract.'
$manifest = $originalManifest | ConvertFrom-Json; $manifest.CreatedUtc = [DateTime]::UtcNow.AddDays(-8).ToString('o')
$manifest | ConvertTo-Json -Depth 5 | Set-Content -LiteralPath $manifestPath
Assert-OfficeTest (!(Restore-OfficeMediaCache $options $target)) 'Expired cache was reused.'
Set-Content -LiteralPath $manifestPath -Value $originalManifest
$stream = Join-Path $source 'ODT\Office\Data\16.0.12345.67890\stream.x64.x-none.dat'
$originalBytes = [IO.File]::ReadAllBytes($stream); [IO.File]::WriteAllText($stream, '')
Assert-OfficeTest (!(Restore-OfficeMediaCache $options $target)) 'Truncated cached media passed the basic size check.'
[IO.File]::WriteAllBytes($stream, $originalBytes)
$extra = Join-Path $source 'ODT\unexpected.dll'; Set-Content -LiteralPath $extra -Value 'unexpected dependency'
Assert-OfficeTest (!(Restore-OfficeMediaCache $options $target)) 'Unrecorded executable dependencies passed cache verification.'
Remove-OfficeManagedItem $cacheRoot $extra
function Get-CimInstance { [pscustomobject]@{CommandLine="setup.exe $source\install.xml"} }
Assert-OfficeThrows { Restore-OfficeMediaCache $options $target } 'previous Office deployment still has active processes'
Assert-OfficeTest (Test-Path -LiteralPath $stream) 'A live installer lost its cached media.'
function Get-CimInstance { }
$script:rejectCacheSignature = $true
Assert-OfficeTest (!(Restore-OfficeMediaCache $options $target)) 'Invalid Microsoft signature was reused.'
$script:rejectCacheSignature = $false
# Same-size contents are deliberately not hashed; ODT services the payload.
$changedBytes = $originalBytes.Clone(); $changedBytes[0] = $changedBytes[0] -bxor 1; [IO.File]::WriteAllBytes($stream, $changedBytes)
$media = Initialize-OfficeMedia $options $target
Assert-OfficeTest ($media.CachedMediaReused -and $media.Version -eq '16.0.12345.67890' -and $script:helperDownloads -eq 1) 'Deployment did not reuse the validated media and refresh the helper.'
Assert-OfficeTest (!(Test-Path -LiteralPath (Join-Path $source 'ODT')) -and (Test-Path -LiteralPath $media.Setup)) 'Cache transfer duplicated large files or lost setup.'
$config = [xml](Get-Content -LiteralPath $media.Config -Raw)
Assert-OfficeTest ($config.Configuration.AppSettings.Setup.Value -eq 'New Company' -and $config.Configuration.Add.SourcePath -eq (Join-Path $target 'ODT')) 'Reused media retained stale company/configuration paths.'
Assert-OfficeTest (!$config.Configuration.Add.HasAttribute('Version')) 'Reusing ordinary media must not pin the installation version.'
Assert-OfficeTest ((Get-Content -LiteralPath (Join-Path $target 'media-cache.json') -Raw | ConvertFrom-Json).CreatedUtc -eq ($originalManifest | ConvertFrom-Json).CreatedUtc) 'Reuse extended cache expiry.'
Assert-OfficeThrows { Remove-OfficeManagedItem $cacheRoot $testRoot } 'outside the Office deployment root'
Assert-OfficeThrows { Remove-OfficeManagedItem $cacheRoot $cacheRoot } 'outside the Office deployment root'
# Windows 10 refreshes only the small release history and helper on a compatible hit.
$win10Source = Join-Path $cacheRoot ('c' * 32); $null = [IO.Directory]::CreateDirectory($win10Source)
foreach ($file in Get-ChildItem -LiteralPath (Join-Path $testRoot 'win10')) { Copy-Item -LiteralPath $file.FullName -Destination $win10Source -Recurse }
$win10Target = Join-Path $cacheRoot ('d' * 32); $null = [IO.Directory]::CreateDirectory($win10Target)
$options = Get-OfficeDeploymentOptions @{OfficeSubscription='Microsoft 365 Business Standard'; OfficeArchitecture='64'}
$options.OfficeFeatureRelease = Get-OfficeFeatureRelease -Build 19045 -ProductType 1
$script:historyPaths=@()
function Save-OfficeDownload {
param($Uri,$Path)
switch ([IO.Path]::GetFileName($Path)) {
'office-release-history.html' { [IO.File]::WriteAllText($Path, $releaseHistory) }
'Office-UserCleanup.ps1' { [IO.File]::WriteAllText($Path, '# ' + (Get-OfficeDeploymentDefinitions).HelperVersion) }
default { throw 'Unexpected installer download on Windows 10 cache hit' }
}
Assert-OfficeTest ($Uri -eq (Get-OfficeDeploymentDefinitions).OfficeReleaseHistory) 'Preflight fetched installer media.'
$script:historyPaths += $Path
[IO.File]::WriteAllText($Path,$script:historyFixture)
}
$media = Initialize-OfficeMedia $options $win10Target
Assert-OfficeTest ($media.CachedMediaReused -and $media.Version -eq '16.0.20326.20158') 'Windows 10 did not reuse compatible validated media.'
Assert-OfficeTest (([xml](Get-Content -LiteralPath $media.Config -Raw)).Configuration.Add.Version -eq $media.Version) 'Reused Windows 10 media lost its compatible version constraint.'
$options=Get-OfficeDeploymentOptions @{OfficeSubscription='Microsoft 365 Business Premium'}
Resolve-OfficeTargetVersion $options
Assert-OfficeTest ($script:historyPaths.Count -eq 0 -and !$options.TargetOfficeVersion) 'Unpinned preflight must not download release metadata.'
$options.OfficeFeatureRelease='2608'; $script:historyFixture=$releaseHistory
Resolve-OfficeTargetVersion $options
Assert-OfficeTest ($options.TargetOfficeVersion -eq '16.0.20326.20158' -and !(Test-Path -LiteralPath $script:historyPaths[-1])) 'Resolved metadata must be removed after successful preflight.'
$script:historyFixture='<html>No build</html>'
Assert-OfficeThrows { Resolve-OfficeTargetVersion $options } 'did not identify'
Assert-OfficeTest (!(Test-Path -LiteralPath $script:historyPaths[-1])) 'Failed preflight retained release metadata.'
}
# Cleanup runs synchronously on success. Downloads are temporary; pending-user
# helpers have a separate durable folder and are never part of the media cache.
# Cleanup runs synchronously on every install exit. Downloads are temporary; pending-user
# helpers have a separate durable folder and are never part of disposable media.
& {
$root = Join-Path $testRoot 'temporary-downloads'; $null = [IO.Directory]::CreateDirectory($root)
$workspace = Join-Path $root ('c' * 32); $null = [IO.Directory]::CreateDirectory($workspace)
@@ -929,7 +870,7 @@ try {
}
$media = [pscustomobject]@{Helper=(Join-Path $workspace 'Office-UserCleanup.ps1')}
$userWorkspace = New-OfficeUserWorkspace $media $workspace
Assert-OfficeTest ($media.Helper -eq (Join-Path $userWorkspace 'Office-UserCleanup.ps1') -and (Test-Path -LiteralPath $media.Helper)) 'User helper was not separated from cached installers.'
Assert-OfficeTest ($media.Helper -eq (Join-Path $userWorkspace 'Office-UserCleanup.ps1') -and (Test-Path -LiteralPath $media.Helper)) 'User helper was not separated from staged installers.'
$script:cleanupTasks = $true; $script:cleanupProcess = $true
function Get-CimInstance { if ($script:cleanupProcess) { [pscustomobject]@{CommandLine="setup.exe $workspace\install.xml"} } }
function Get-ScheduledTask { if ($script:cleanupTasks) { [pscustomobject]@{TaskName="Emberkom-OfficeCleanup-$('c' * 32)-SID"; State='Ready'} } }
@@ -938,16 +879,24 @@ try {
Assert-OfficeTest ($warnings.Count -and (Test-Path -LiteralPath (Join-Path $workspace 'ODT'))) 'Cleanup deleted files referenced by a surviving installer.'
$script:cleanupProcess = $false
$warnings = Complete-OfficeDeploymentFiles $workspace $userWorkspace
Assert-OfficeTest (!$warnings.Count -and !(Test-Path -LiteralPath $workspace)) 'Successful deployment left its temporary workspace behind.'
Assert-OfficeTest (Test-Path -LiteralPath $media.Helper) 'Temporary cache cleanup deleted the pending-user helper.'
Assert-OfficeTest (!$warnings.Count -and !(Test-Path -LiteralPath (Join-Path $workspace 'ODT')) -and !(Test-Path -LiteralPath (Join-Path $workspace 'odt.exe')) -and (Test-Path -LiteralPath (Join-Path $workspace 'office-install.stdout.log'))) 'Completion must remove media and preserve diagnostics.'
Assert-OfficeTest (Test-Path -LiteralPath $media.Helper) 'Temporary media cleanup deleted the pending-user helper.'
$script:cleanupTasks = $false
$warnings = Complete-OfficeDeploymentFiles $workspace $userWorkspace
Assert-OfficeTest (!$warnings.Count -and !(Test-Path -LiteralPath $userWorkspace)) 'Completed user cleanup left its helper folder behind.'
# Older ProgramData stages lose only known downloads, never deferred-user files.
$legacy = Join-Path $userRoot ('d' * 32); $null = [IO.Directory]::CreateDirectory($legacy)
foreach ($name in @('options.json','odt.exe','Office-UserCleanup.ps1','user-cleanup.lock')) { Set-Content -LiteralPath (Join-Path $legacy $name) -Value 'fixture' }
$warnings = Complete-OfficeDeploymentFiles $workspace -PreviousRoot $userRoot
Assert-OfficeTest (!$warnings.Count -and !(Test-Path -LiteralPath (Join-Path $legacy 'odt.exe')) -and (Test-Path -LiteralPath (Join-Path $legacy 'Office-UserCleanup.ps1'))) 'Legacy download cleanup lost pending-user state or left old downloads.'
# An installer without a source path, locked media and links all defer cleanup.
Assert-OfficeTest (Test-OfficeStagingInUse $workspace @([pscustomobject]@{Name='OfficeC2RClient.exe'})) 'Surviving native installers must defer media cleanup.'
Assert-OfficeThrows { Remove-OfficeManagedItem $root $testRoot } 'outside the Office deployment root'
Assert-OfficeThrows { Remove-OfficeManagedItem $root $root } 'outside the Office deployment root'
$payload=Join-Path $workspace 'odt.exe'; [IO.File]::WriteAllText($payload,'locked')
$handle=[IO.File]::Open($payload,[IO.FileMode]::Open,[IO.FileAccess]::Read,[IO.FileShare]::None)
try {
$warnings=Complete-OfficeDeploymentFiles $workspace
Assert-OfficeTest ($warnings.Count -gt 0 -and (Test-Path -LiteralPath $payload)) 'In-use payload must survive final cleanup.'
} finally { $handle.Dispose() }
function Get-CimInstance { throw 'Synthetic process inventory failure' }
$warnings=Complete-OfficeDeploymentFiles $workspace
Assert-OfficeTest ($warnings.Count -gt 0 -and (Test-Path -LiteralPath $payload)) 'Unknown process state must retain media.'
}
# The legacy uninstaller must delete both successful and partial downloads.
& {
@@ -973,11 +922,12 @@ try {
throw "Unexpected object requested by orchestration fixture: $TypeName"
}
function Assert-OfficeDeploymentHost { }
function Assert-OfficeDiskSpace { param($Workspace,[switch]$DownloadingMedia) if ($script:mode -eq 'disk-space') { throw 'Insufficient disk space after staging' } }
function Complete-OfficeDeploymentFiles { param($Workspace,$UserWorkspace,$PreviousRoot) $script:artifactCleanupRuns++; if ($script:mode -eq 'cleanup-warning') { return ,@('Synthetic file in use') }; return ,@() }
function Assert-OfficeDiskSpace { param($Workspace,[switch]$DownloadingMedia) if ($script:mode -eq 'preflight-space') { throw 'Insufficient disk space before download' }; if ($script:mode -eq 'disk-space' -and !$DownloadingMedia) { throw 'Insufficient disk space after staging' } }
function Resolve-OfficeTargetVersion { if ($script:mode -eq 'release') { throw 'Release metadata unavailable' } }
function Complete-OfficeDeploymentFiles { param($Workspace,$UserWorkspace) $script:artifactCleanupRuns++; if ($script:mode -eq 'download-cleanup') { throw 'Synthetic cleanup failure' }; if ($script:mode -eq 'cleanup-warning') { return ,@('Synthetic file in use') }; return ,@() }
function New-OfficeUserWorkspace { param($Media,$Workspace) $Workspace }
function Register-ScheduledTask { throw 'Unexpected task registration in orchestration fixture.' }
function New-OfficeWorkspace { $path = Join-Path $testRoot ([guid]::NewGuid().ToString('N')); $null = New-Item -ItemType Directory -Path $path; $path }
function New-OfficeWorkspace { $script:workspaceCreates++; $path = Join-Path $testRoot ([guid]::NewGuid().ToString('N')); $null = New-Item -ItemType Directory -Path $path; $path }
function Start-Transcript { }
function Stop-Transcript { }
function Get-CimInstance { [pscustomobject]@{SID='S-1-5-21-test'; LocalPath=$profile; Special=$false} }
@@ -986,7 +936,7 @@ try {
function Get-OfficeRunningApps { }
function Get-OfficeSuiteInventory { if ($script:mode -ne 'office-reboot' -or $script:removalStillRegistered) { [pscustomobject]@{DisplayName='Synthetic Office'} } }
function Get-OfficeMachineCompanionEntries { if ($script:removalStillRegistered) { [pscustomobject]@{DisplayName='Synthetic OneDrive'} } }
function Initialize-OfficeMedia { param($Options,$Workspace) $script:events += 'download'; if ($script:mode -eq 'download') { throw 'download failure' }; [pscustomobject]@{Version='16.0.1.2'; Helper=(Join-Path $Workspace 'Office-UserCleanup.ps1')} }
function Initialize-OfficeMedia { param($Options,$Workspace) $script:events += 'download'; if ($script:mode -in @('download','download-cleanup')) { throw 'download failure' }; [pscustomobject]@{Version='16.0.1.2'; Helper=(Join-Path $Workspace 'Office-UserCleanup.ps1')} }
function Remove-OfficeCompanionApps { $script:events += 'companions'; if ($script:mode -eq 'companions') { throw 'companion failure' }; return ($script:mode -eq 'reboot') }
function Remove-OfficeSuite { $script:events += 'remove-office'; if ($script:mode -eq 'remove-office') { throw 'Office removal failure' }; if ($script:mode -eq 'office-reboot') { return 3010 }; return 0 }
function Clear-OfficeProfileIdentity { $script:events += 'identity'; if ($script:mode -eq 'identity') { throw 'identity failure' } }
@@ -1002,7 +952,7 @@ try {
function Install-OfficeCompanionApps { param($Media,$Workspace,[bool]$InstallTeams) $script:teamsRequested=$InstallTeams; $script:events += 'install-companions'; if ($script:mode -eq 'install-companions') { throw 'companion install failure' }; [pscustomobject]@{ExitCode=$(if ($script:mode -eq 'companion-reboot') {3010} else {0}); Versions=@{NewOutlook='1'; OneDrive='1'}} }
$script:removalStillRegistered=$false
$options = Get-OfficeDeploymentOptions @{OfficeSubscription='Microsoft 365 Business Premium'; OfficeAppShutdown='Force'; ValidateBeforeChanges='false'; DeferReboot='false'}
foreach ($script:mode in @('success','download','disk-space','companions','remove-office','identity','user','phase','install','install-companions','pending','reboot','office-reboot','companion-reboot')) {
foreach ($script:mode in @('success','download','download-cleanup','disk-space','companions','remove-office','identity','user','phase','install','install-companions','pending','reboot','office-reboot','companion-reboot')) {
$script:artifactCleanupRuns = 0
$script:events = @(); $errorResult = $null; $result = $null
try { $result = Invoke-OfficeDeployment $options } catch { $errorResult = $_ }
@@ -1013,15 +963,19 @@ try {
} else { Assert-OfficeTest ($null -ne $errorResult) "Failure swallowed in $script:mode" }
if ($script:mode -notin @('success','pending','install','install-companions','companion-reboot')) { Assert-OfficeTest ('install' -notin $script:events) "Install ran after $script:mode failure/reboot." }
if ($script:mode -notin @('success','pending','install-companions','companion-reboot')) { Assert-OfficeTest ('install-companions' -notin $script:events) "Companion install ran after $script:mode failure/reboot." }
if ($script:mode -eq 'download') { Assert-OfficeTest ('companions' -notin $script:events -and 'remove-office' -notin $script:events) 'Removal ran after download failed.' }
if ($script:mode -in @('download','download-cleanup')) { Assert-OfficeTest ('companions' -notin $script:events -and 'remove-office' -notin $script:events) 'Removal ran after download failed.' }
if ($script:mode -eq 'download-cleanup') { Assert-OfficeTest ($errorResult.Exception.Message -eq 'download failure') 'Cleanup replaced the original deployment failure.' }
if ($script:mode -eq 'disk-space') { Assert-OfficeTest (($script:events -join ',') -eq 'download') 'Low space after staging must stop before app shutdown, removal, identity cleanup, and installation.' }
Assert-OfficeTest ($script:artifactCleanupRuns -eq $(if ($script:mode -in @('success','pending','companion-reboot')) {1} else {0})) "Media cleanup ran before successful installation, or was skipped after success: $script:mode"
Assert-OfficeTest ($script:artifactCleanupRuns -eq 1) "Finally must attempt media cleanup on every install exit: $script:mode"
if ($script:mode -eq 'office-reboot') { Assert-OfficeTest ($result.OfficeDeploymentStatus -eq 'RestartRequiredBeforeInstall' -and 'identity' -notin $script:events -and 'user' -notin $script:events) 'Office removal restart must stop before user cleanup and replacement installation.' }
if ($script:mode -eq 'success') { Assert-OfficeTest (($script:events -join ',') -eq 'download,apps,companions,remove-office,identity,user,phase,install,install-companions') 'Deployment order changed.' }
}
$script:mode='disk-space'; $script:events=@(); $options.ValidateBeforeChanges=$true
Assert-OfficeThrows { Invoke-OfficeDeployment $options } 'Insufficient disk space after staging'
Assert-OfficeTest (($script:events -join ',') -eq 'download') 'Validation must not report success or mutate apps with insufficient installation space.'
$script:mode='preflight-space'; $script:events=@(); $options.ValidateBeforeChanges=$true; $script:workspaceCreates=0; $script:artifactCleanupRuns=0
Assert-OfficeThrows { Invoke-OfficeDeployment $options } 'Insufficient disk space before download'
Assert-OfficeTest ($script:events.Count -eq 0 -and $script:workspaceCreates -eq 0 -and $script:artifactCleanupRuns -eq 0) 'Low-space validation must stop without staging or housekeeping.'
$options.ValidateBeforeChanges=$false
Assert-OfficeThrows { Invoke-OfficeDeployment $options } 'Insufficient disk space before download'
Assert-OfficeTest ($script:events.Count -eq 0 -and $script:workspaceCreates -eq 0) 'Low-space install must stop before creating a workspace.'
$options.ValidateBeforeChanges=$false
$script:mode='cleanup-warning'; $script:events=@()
$result = @(Invoke-OfficeDeployment $options)
@@ -1056,12 +1010,12 @@ try {
Assert-OfficeTest (!$result.RestartRequired -and $result.ExitCode -eq 0) 'A clean deployment without restart requests must not demand a restart.'
foreach ($shutdown in @('Abort','Force')) {
foreach ($validate in @($null, '', 'true')) {
$script:events=@()
$script:events=@(); $script:workspaceCreates=0; $script:artifactCleanupRuns=0
$options = Get-OfficeDeploymentOptions @{OfficeSubscription='Microsoft/Office 365 E3/E5 (no Teams)'; OfficeAppShutdown=$shutdown; ValidateBeforeChanges=$validate}
$result = Invoke-OfficeDeployment $options
Assert-OfficeTest ($result.OfficeDeploymentStatus -eq 'ValidationPassed' -and $result.ExitCode -eq 0 -and $result.ValidateBeforeChanges) 'Validation did not produce a distinct result.'
Assert-OfficeTest ($result.OfficeRemovalMethod -eq 'SilentODT' -and $result.DeferReboot -is [bool] -and $result.DeferReboot) 'Validation must identify the silent removal method and Boolean restart selection.'
Assert-OfficeTest (($script:events -join ',') -eq 'download') 'Validation reached app shutdown, removal, identities, user tasks, phase changes, or installation.'
Assert-OfficeTest ($script:events.Count -eq 0 -and $script:workspaceCreates -eq 0 -and $script:artifactCleanupRuns -eq 0 -and !$result.MediaDownloaded -and !$result.Workspace) 'Validation downloaded media, created a workspace or reached a deployment action.'
Assert-OfficeTest (!$result.TeamsSelected -and $result.ProfileCount -eq 1 -and $result.ExistingOffice[0] -eq 'Synthetic Office') 'Validation report lost the deployment plan.'
}
}
@@ -1069,13 +1023,13 @@ try {
$script:events=@()
$options = Get-OfficeDeploymentOptions @{OfficeSubscription='Microsoft 365 Business Premium'; OfficeAppShutdown='Force'}
$result = Invoke-OfficeDeployment $options
Assert-OfficeTest (($script:events -join ',') -eq 'download' -and $result.RunningApps[0] -eq 'winword') 'Validation closed a running app with Force selected.'
Assert-OfficeTest ($script:events.Count -eq 0 -and $result.RunningApps[0] -eq 'winword') 'Validation downloaded media or closed a running app with Force selected.'
$options.OfficeAppShutdown='Abort'; $script:events=@()
Assert-OfficeThrows { Invoke-OfficeDeployment $options } 'Apps are running'
Assert-OfficeTest ($script:events.Count -eq 0) 'Validation did not stop on an Abort prerequisite failure.'
$options.OfficeAppShutdown='Force'; $script:mode='download'; $script:events=@()
Assert-OfficeThrows { Invoke-OfficeDeployment $options } 'download failure'
Assert-OfficeTest (($script:events -join ',') -eq 'download') 'Failed validation reached mutations.'
$options.OfficeAppShutdown='Force'; $script:mode='release'; $script:events=@()
Assert-OfficeThrows { Invoke-OfficeDeployment $options } 'Release metadata unavailable'
Assert-OfficeTest ($script:events.Count -eq 0) 'Failed validation reached media downloads or mutations.'
$options.ValidateBeforeChanges='false'
Assert-OfficeThrows { Invoke-OfficeDeployment $options } 'validated Boolean'
$options.ValidateBeforeChanges=$false; $options.DeferReboot='false'; $script:events=@()