improved resiliency during Office uninstall/install operations

This commit is contained in:
2026-10-14 17:33:23 -04:00
parent 11bc57e665
commit b07e132b3c
4 changed files with 437 additions and 43 deletions
+210 -8
View File
@@ -34,6 +34,95 @@ try {
. ([scriptblock]::Create($definition.Extent.Text))
}
}
# Exercise the real bounded retry loops without delaying offline tests.
function Start-Sleep { param([int]$Seconds) $script:testSleeps += $Seconds }
$script:testSleeps = @()
& {
$script:probeCalls=0; $script:testSleeps=@()
$result = Wait-OfficeResult { $script:probeCalls++; if ($script:probeCalls -eq 3) { [pscustomobject]@{Version='ready'} } } 'delayed fixture registration'
Assert-OfficeTest ($result.Version -eq 'ready' -and $script:probeCalls -eq 3 -and $script:testSleeps.Count -eq 2) 'Delayed registration must return the verified value without leaking log text.'
$script:probeCalls=0; $script:testSleeps=@()
$result = Wait-OfficeResult { $script:probeCalls++; $false } 'missing fixture registration'
Assert-OfficeTest ($null -eq $result -and $script:probeCalls -eq (Get-OfficeDeploymentDefinitions).RegistrationCheckAttempts -and $script:testSleeps.Count -eq ($script:probeCalls - 1)) 'Registration waits must stop at the configured bound.'
$script:probeCalls=0
Assert-OfficeThrows { Wait-OfficeResult { $script:probeCalls++; throw 'Registry access denied' } 'unreadable fixture' } 'Registry access denied'
Assert-OfficeTest ($script:probeCalls -eq 1) 'Failed inventory reads must not be treated as absent installations.'
}
& {
function Start-Process {
param($FilePath,$ArgumentList,$WorkingDirectory,[switch]$Wait,[switch]$PassThru,$WindowStyle,$RedirectStandardOutput,$RedirectStandardError)
$script:processCalls++; $script:processLogs += $RedirectStandardOutput
if ($script:processExit -eq 1618 -and $script:processRecovers -and $script:processCalls -eq 3) { return [pscustomobject]@{ExitCode=0} }
[pscustomobject]@{ExitCode=$script:processExit}
}
foreach ($mode in @('recovers','busy','fatal','reboot','not-msi','null-code')) {
$script:processCalls=0; $script:processLogs=@(); $script:testSleeps=@(); $script:processRecovers=$mode -eq 'recovers'
$script:processExit = switch ($mode) { 'fatal' {1603}; 'reboot' {3010}; 'null-code' {$null}; default {1618} }
$executable = if ($mode -eq 'not-msi') { 'bootstrapper.exe' } else { 'msiexec.exe' }
$file = Join-Path $testRoot $executable
if ($mode -eq 'null-code') { Assert-OfficeThrows { Invoke-OfficeProcess $file '/x fixture' (Join-Path $testRoot 'msi') } 'No exit code'; continue }
$code = Invoke-OfficeProcess $file '/x fixture' (Join-Path $testRoot 'msi')
$expectedCalls = if ($mode -eq 'recovers') {3} elseif ($mode -eq 'busy') {(Get-OfficeDeploymentDefinitions).MsiBusyAttempts} else {1}
$expectedCode = if ($mode -eq 'recovers') {0} else {$script:processExit}
Assert-OfficeTest ($code -eq $expectedCode -and $script:processCalls -eq $expectedCalls -and $script:testSleeps.Count -eq ($expectedCalls - 1)) "Incorrect retry behavior for $mode."
Assert-OfficeTest (@($script:processLogs | Select-Object -Unique).Count -eq $expectedCalls) 'MSI retry output logs must not overwrite earlier attempts.'
}
}
& {
function Invoke-WebRequest {
[CmdletBinding()]
param([switch]$UseBasicParsing,$Uri,$OutFile,$TimeoutSec)
$script:downloadCalls++
if (!$script:downloadRecovers -or $script:downloadCalls -eq 1) { throw 'Temporary network failure' }
[IO.File]::WriteAllText($OutFile, 'downloaded fixture')
}
$script:downloadCalls=0; $script:downloadRecovers=$true
Save-OfficeDownload 'https://fixture.invalid/' (Join-Path $testRoot 'download') 2>$null
Assert-OfficeTest ($script:downloadCalls -eq 2 -and (Get-Content -LiteralPath (Join-Path $testRoot 'download') -Raw) -eq 'downloaded fixture') 'A transient download error should recover.'
$script:downloadCalls=0; $script:downloadRecovers=$false
Assert-OfficeThrows { Save-OfficeDownload 'https://fixture.invalid/' (Join-Path $testRoot 'download') 2>$null } 'Temporary network failure'
Assert-OfficeTest ($script:downloadCalls -eq (Get-OfficeDeploymentDefinitions).DownloadAttempts) 'Persistent download failure must remain bounded.'
}
& {
function Remove-AppxPackage {
param($Package,[switch]$AllUsers)
$script:appxCalls++
if ($script:appxMode -eq 'already-gone') { $script:appxPresent=$false; throw 'Package already removed by another operation' }
if ($script:appxMode -eq 'failure' -or ($script:appxMode -eq 'recovers' -and $script:appxCalls -eq 1)) { throw 'Transient package in use' }
$script:appxPresent=$false
}
function Remove-AppxProvisionedPackage { param($PackageName,[switch]$Online,[switch]$AllUsers) Remove-AppxPackage -Package $PackageName -AllUsers }
function Get-AppxPackage {
param([switch]$AllUsers)
if ($script:appxMode -eq 'query-failure') { throw 'Appx inventory access denied' }
if ($script:appxPresent) { [pscustomobject]@{PackageFullName='fixture'; PackageName='fixture'} }
}
function Get-AppxProvisionedPackage { param([switch]$Online) Get-AppxPackage -AllUsers }
foreach ($provisioned in @($false,$true)) {
foreach ($script:appxMode in @('success','already-gone','recovers','failure','query-failure')) {
$script:appxPresent=$true; $script:appxCalls=0
if ($script:appxMode -eq 'failure') {
Assert-OfficeThrows { Remove-OfficeAppxEntry 'fixture' -Provisioned:$provisioned } 'Appx package remains'
Assert-OfficeTest ($script:appxCalls -eq (Get-OfficeDeploymentDefinitions).AppxRemovalAttempts) 'Persistent Appx removal failure must be bounded.'
} elseif ($script:appxMode -eq 'query-failure') {
Assert-OfficeThrows { Remove-OfficeAppxEntry 'fixture' -Provisioned:$provisioned } 'Appx inventory access denied'
Assert-OfficeTest ($script:appxCalls -eq 1) 'Appx read errors must propagate instead of passing verification.'
} else {
$output = @(Remove-OfficeAppxEntry 'fixture' -Provisioned:$provisioned)
$expectedCalls = if ($script:appxMode -eq 'recovers') {2} else {1}
Assert-OfficeTest (!$script:appxPresent -and $script:appxCalls -eq $expectedCalls -and $output.Count -eq 0) "Appx removal did not recover cleanly: $script:appxMode, provisioned=$provisioned."
}
}
}
}
& {
function Get-OfficeRunningApps { [pscustomobject]@{Id=123; HasExited=$script:appHasExited} }
function Stop-Process { throw 'Process is gone or access was denied.' }
$script:appHasExited=$true
Stop-OfficeDeploymentApps ([pscustomobject]@{OfficeAppShutdown='Force'})
$script:appHasExited=$false
Assert-OfficeThrows { Stop-OfficeDeploymentApps ([pscustomobject]@{OfficeAppShutdown='Force'}) } 'Process is gone or access was denied'
}
foreach ($value in @($null, '', ' ', 'true', ' TRUE ', '$true', '1', 'yes')) {
$options = Get-OfficeDeploymentOptions @{OfficeSubscription='Microsoft 365 Business Premium'; ValidateBeforeChanges=$value}
Assert-OfficeTest ($options.ValidateBeforeChanges -is [bool] -and $options.ValidateBeforeChanges) "Validation must be on for '$value'."
@@ -119,15 +208,18 @@ try {
$mediaFixtureZip = Join-Path $testRoot 'gethelp-fixture.zip'
Add-Type -AssemblyName System.IO.Compression.FileSystem
[IO.Compression.ZipFile]::CreateFromDirectory($zipSource, $mediaFixtureZip)
$script:mediaSignatures = @(); $script:mediaProcesses = @()
$script:mediaSignatures = @(); $script:mediaProcesses = @(); $script:mediaDownloadCalls = 0
function Invoke-WebRequest {
[CmdletBinding()]
param([switch]$UseBasicParsing, [string]$Uri, [int]$TimeoutSec)
[pscustomobject]@{Content='https://download.microsoft.com/test/officedeploymenttool_test.exe'}
}
function Save-OfficeDownload {
param([string]$Uri, [string]$Path)
if ([IO.Path]::GetFileName($Path) -eq 'GetHelp.zip') {
param([string]$Uri, [string]$Path, [int]$TimeoutSeconds)
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 'GetHelp.zip') {
[IO.File]::Copy($mediaFixtureZip, $Path)
} elseif ([IO.Path]::GetFileName($Path) -eq 'Office-UserCleanup.ps1') {
[IO.File]::WriteAllText($Path, '# ' + (Get-OfficeDeploymentDefinitions).HelperVersion)
@@ -146,6 +238,8 @@ try {
if ([IO.Path]::GetFileName($FilePath) -eq 'odt.exe' -and $Arguments -like '/quiet /extract:*') {
[IO.File]::WriteAllText((Join-Path $mediaWorkspace 'ODT\setup.exe'), 'Inert ODT fixture; never executed.')
} elseif ([IO.Path]::GetFileName($FilePath) -eq 'setup.exe' -and $Arguments -like '/download *') {
$script:mediaDownloadCalls++
if ($script:mediaDownloadCalls -eq 1) { return 12029 }
$payload = Join-Path $mediaWorkspace 'ODT\Office\Data\16.0.12345.67890'
$null = [IO.Directory]::CreateDirectory($payload)
foreach ($name in @('stream.x64.x-none.dat', 'stream.x64.en-us.dat')) { [IO.File]::WriteAllText((Join-Path $payload $name), 'Inert Office payload.') }
@@ -158,7 +252,7 @@ try {
Assert-OfficeTest ($media.Scrubber -in $script:mediaSignatures -and $media.Setup -in $script:mediaSignatures) 'Extracted Get Help and ODT must still pass signature checks.'
Assert-OfficeTest ($media.Version -eq '16.0.12345.67890' -and $media.Companions.Count -eq 3 -and !$media.Companions.ContainsKey('Teams')) 'Media staging lost its build or no-Teams selection.'
Assert-OfficeTest (([xml](Get-Content -LiteralPath $media.Config -Raw)).Configuration.Add.Version -eq $media.Version) 'Staged configuration must pin the downloaded build.'
Assert-OfficeTest (($script:mediaProcesses -join ',') -eq 'odt.exe,setup.exe') 'Staging attempted to run a scrubber or companion installer.'
Assert-OfficeTest (($script:mediaProcesses -join ',') -eq 'odt.exe,setup.exe,setup.exe') 'Staging must retry the failed download without launching a scrubber or companion installer.'
}
& {
$script:staged = @(); $script:verified = @()
@@ -178,10 +272,16 @@ try {
Assert-OfficeThrows { Initialize-OfficeCompanionMedia $testRoot } 'Untrusted companion'
}
& {
function Get-OfficeMachineWebViewVersion { if ($script:webViewPresent) { '140.0.0.1' } }
function Get-OfficeMachineWebViewVersion {
if ($script:webViewPresent) {
if ($script:appMode -eq 'delayed-success') { $script:webViewChecks++; if ($script:webViewChecks -lt 3) { return } }
'140.0.0.1'
}
}
function Invoke-OfficeProcess {
param($FilePath,$Arguments,$LogPrefix)
$script:appCalls += "$FilePath $Arguments"
$script:lastInstalledApp=$FilePath
if ($script:appMode -eq "fail-$FilePath") { return 42 }
if ($FilePath -eq 'WebView2') { $script:webViewPresent = $true }
if ($script:appMode -eq 'reboot' -and $FilePath -eq 'OneDrive') { return 3010 }
@@ -189,16 +289,21 @@ try {
}
function Get-AppxProvisionedPackage {
param([switch]$Online,$ErrorAction)
if ($script:appMode -eq 'delayed-success') { $script:packageChecks[$script:lastInstalledApp]++; if ($script:packageChecks[$script:lastInstalledApp] -lt 3) { return } }
if ($script:appMode -ne 'missing-Teams') { [pscustomobject]@{DisplayName='MSTeams'; PackageName='MSTeams_1.0.0.0_neutral_~_8wekyb3d8bbwe'; Version='1.0.0.0'} }
if ($script:appMode -ne 'missing-NewOutlook') { [pscustomobject]@{DisplayName='Microsoft.OutlookForWindows'; PackageName='Microsoft.OutlookForWindows_1.0.0.0_neutral_~_8wekyb3d8bbwe'; Version='1.0.0.0'} }
}
function Get-OfficeMachineOneDrive { if ($script:appMode -ne 'missing-OneDrive') { [pscustomobject]@{Path='inert.exe'; Version='26.1.2.3'} } }
function Get-OfficeMachineOneDrive {
if ($script:appMode -eq 'delayed-success') { $script:oneDriveChecks++; if ($script:oneDriveChecks -lt 3) { return } }
if ($script:appMode -ne 'missing-OneDrive') { [pscustomobject]@{Path='inert.exe'; Version='26.1.2.3'} }
}
function Assert-OfficeMicrosoftSignature { }
$media = @{WebView2='WebView2'; OneDrive='OneDrive'; Teams='Teams'; NewOutlook='NewOutlook'}
foreach ($script:appMode in @('success','reboot','fail-WebView2','fail-OneDrive','fail-Teams','fail-NewOutlook','missing-OneDrive','missing-Teams','missing-NewOutlook')) {
foreach ($script:appMode in @('success','delayed-success','reboot','fail-WebView2','fail-OneDrive','fail-Teams','fail-NewOutlook','missing-OneDrive','missing-Teams','missing-NewOutlook')) {
$script:webViewPresent = $false; $script:appCalls = @(); $failure = $null; $result = $null
$script:webViewChecks=0; $script:oneDriveChecks=0; $script:packageChecks=@{}
try { $result = Install-OfficeCompanionApps $media $testRoot -InstallTeams $true } catch { $failure = $_ }
if ($script:appMode -in @('success','reboot')) {
if ($script:appMode -in @('success','delayed-success','reboot')) {
$expectedCode = if ($script:appMode -eq 'reboot') { 3010 } else { 0 }
Assert-OfficeTest ($null -eq $failure -and $result.ExitCode -eq $expectedCode) "Unexpected companion result for $script:appMode : $failure"
Assert-OfficeTest ($result.Versions.OneDrive -eq '26.1.2.3' -and $result.Versions.Teams -eq '1.0.0.0' -and $result.Versions.NewOutlook -eq '1.0.0.0') 'Companion verification receipt is incomplete.'
@@ -275,6 +380,96 @@ try {
Assert-OfficeThrows { Get-OfficeOneDriveCommand '"C:\Users\someone\OneDriveSetup.exe" /uninstall' @('C:\Program Files\Microsoft OneDrive') } 'allowlist'
Assert-OfficeThrows { Get-OfficeOneDriveCommand '"C:\Program Files\Microsoft OneDrive\OneDriveSetup.exe" /uninstall & calc.exe' @('C:\Program Files\Microsoft OneDrive') } 'allowlist'
# Compile and exercise the real read-only MSI queries for a nonexistent product.
$absentProduct = '{' + [guid]::NewGuid().ToString() + '}'
Assert-OfficeTest (!(Test-OfficeMachineMsiProduct $absentProduct)) 'An unknown product must not be classified as a machine MSI.'
Assert-OfficeTest (!(Test-OfficeUserMsiProduct $absentProduct)) 'An unknown product must not be classified as a current-user MSI.'
Assert-OfficeThrows { Test-OfficeMachineMsiProduct 'not-a-guid' } 'ProductCode'
Assert-OfficeThrows { Test-OfficeUserMsiProduct 'not-a-guid' } 'ProductCode'
Assert-OfficeTest ($helperAst.Extent.Text.Contains((Get-OfficeDeploymentDefinitions).HelperVersion)) 'The staged helper version contract must match the checked-in helper.'
# HKLM can contain a per-user Teams add-in registration. Never run its MSI as SYSTEM.
& {
$addin = [pscustomobject]@{DisplayName='Microsoft Teams Meeting Add-in for Microsoft Office'; DisplayVersion='1.26.25904'; PSChildName='{11111111-2222-3333-4444-555555555555}'; PSPath='Registry::HKEY_LOCAL_MACHINE\Software\Fixture\Addin'}
$script:companionEntries=@($addin); $script:machineRegistered=$false; $script:removalCalls=@()
function Get-OfficeUninstallEntries { $script:companionEntries }
function Test-OfficeMachineMsiProduct { $script:machineRegistered }
function Get-AppxProvisionedPackage { param([switch]$Online) }
function Get-AppxPackage { param([switch]$AllUsers) }
function Assert-OfficeMicrosoftSignature { }
function Invoke-OfficeProcess {
param($FilePath,$Arguments,$LogPrefix)
$script:removalCalls += $Arguments
if ($script:removalMode -eq 'success') { $script:machineRegistered=$false }
if ($script:removalMode -eq 'unknown') { return 1605 }
if ($script:removalMode -eq 'reboot') { return 3010 }
if ($script:removalMode -eq 'failure') { return 1603 }
return 0
}
$reboot = Remove-OfficeCompanionApps $testRoot
Assert-OfficeTest (!$reboot -and $script:removalCalls.Count -eq 0) 'An HKLM entry without machine MSI registration must be left to user cleanup.'
foreach ($mode in @('success','remaining','unknown','failure','reboot')) {
$script:machineRegistered=$true; $script:removalMode=$mode; $script:removalCalls=@()
if ($mode -in @('remaining','unknown')) {
Assert-OfficeThrows { Remove-OfficeCompanionApps $testRoot } 'registrations remain.*Microsoft Teams Meeting Add-in.*1\.26\.25904.*Fixture'
} elseif ($mode -eq 'failure') {
Assert-OfficeThrows { Remove-OfficeCompanionApps $testRoot } 'Could not remove.*1603'
} else {
$reboot=Remove-OfficeCompanionApps $testRoot
Assert-OfficeTest ($reboot -eq ($mode -eq 'reboot')) "Incorrect reboot result for machine MSI mode $mode."
}
Assert-OfficeTest ($script:removalCalls.Count -eq 1 -and $script:removalCalls[0] -like ('/x ' + $addin.PSChildName + ' /qn /norestart*')) 'A real machine add-in must still be uninstalled silently.'
}
$script:companionEntries=@([pscustomobject]@{DisplayName='Microsoft OneDrive'; DisplayVersion='26.1'; PSPath='Registry::HKEY_LOCAL_MACHINE\Software\Fixture\OneDrive'; UninstallString=('"' + $env:ProgramFiles + '\Microsoft OneDrive\OneDriveSetup.exe" /uninstall /allusers')})
$script:removalMode='remaining'
Assert-OfficeThrows { Remove-OfficeCompanionApps $testRoot } 'registrations remain.*Microsoft OneDrive.*26\.1'
$script:companionEntries=@($addin)
function Test-OfficeMachineMsiProduct { throw 'MSI registration query failed' }
Assert-OfficeThrows { Remove-OfficeCompanionApps $testRoot } 'MSI registration query failed'
}
& {
$mine = [pscustomobject]@{DisplayName='Microsoft Teams Meeting Add-in for Microsoft Office'; Publisher='Microsoft'; DisplayVersion='1.26.25904'; PSChildName='{11111111-2222-3333-4444-555555555555}'}
$other = [pscustomobject]@{DisplayName=$mine.DisplayName; Publisher='Microsoft'; PSChildName='{22222222-2222-3333-4444-555555555555}'}
function Test-Path { param($LiteralPath) $true }
function Get-ItemProperty { param($Path) if ($Path -like 'HKLM:*') { $mine; $other } }
function Test-OfficeUserMsiProduct { param($ProductCode) $ProductCode -eq $mine.PSChildName }
$found=@(Get-OfficeUserTeamsAddinEntries)
Assert-OfficeTest ($found.Count -eq 1 -and $found[0].PSChildName -eq $mine.PSChildName) 'User cleanup must discover its HKLM-advertised add-in, deduplicate registry views, and exclude other contexts.'
function Test-OfficeUserMsiProduct { $false }
Assert-OfficeTest (@(Get-OfficeUserTeamsAddinEntries).Count -eq 0) 'User cleanup must not claim products registered only for another user or machine.'
}
& {
function Remove-OfficeUserLegacyTeams { }
function Get-OfficeUserTeamsAddinEntries { [pscustomobject]@{DisplayVersion='1.26.25904'; PSChildName='{11111111-2222-3333-4444-555555555555}'} }
function Test-Path { $false }
function Test-OfficeUserMsiProduct { $script:userMsiRemains }
function Start-Process {
param($FilePath,$ArgumentList,$WindowStyle,[switch]$Wait,[switch]$PassThru)
Assert-OfficeTest ($FilePath -like '*\msiexec.exe' -and $ArgumentList -like '/x * /qn /norestart' -and $Wait -and $WindowStyle -eq 'Hidden') 'User MSI uninstall must remain silent and synchronous.'
[pscustomobject]@{ExitCode=$script:userMsiExit}
}
$script:userMsiRemains=$false; $script:userMsiExit=0
Remove-OfficeUserCompanions
$script:userMsiRemains=$true
Assert-OfficeThrows { Remove-OfficeUserCompanions } 'remains registered for this user'
$script:userMsiExit=1605
Assert-OfficeThrows { Remove-OfficeUserCompanions } 'remains registered for this user'
$script:userMsiExit=1603
Assert-OfficeThrows { Remove-OfficeUserCompanions } 'removal needs attention.*1603'
function Start-Process {
$script:userMsiStarts++
$code = if ($script:userMsiRecovers -and $script:userMsiStarts -eq 3) {0} else {1618}
[pscustomobject]@{ExitCode=$code}
}
function Test-OfficeUserMsiProduct { $script:userMsiChecks++; $script:userMsiChecks -lt 3 }
$script:userMsiStarts=0; $script:userMsiChecks=0; $script:userMsiRecovers=$true
Remove-OfficeUserCompanions
Assert-OfficeTest ($script:userMsiStarts -eq 3 -and $script:userMsiChecks -eq 3) 'User MSI cleanup must recover from busy MSI and delayed registration removal.'
$script:userMsiStarts=0; $script:userMsiRecovers=$false
Assert-OfficeThrows { Remove-OfficeUserCompanions } 'removal needs attention.*1618'
Assert-OfficeTest ($script:userMsiStarts -eq (Get-OfficeUserCleanupDefinitions).MsiBusyAttempts) 'User MSI busy retries must be bounded.'
}
# Exercise real cache deletion against synthetic profiles only. Documents/SSO stay intact.
$profile = Join-Path $testRoot 'profile'
$cache = Join-Path $profile 'AppData\Local\Microsoft\Office\Licenses'
@@ -298,6 +493,7 @@ try {
& {
function Invoke-OfficeProcess { return $script:installCode }
function Get-ItemProperty { return $script:installed }
function Test-Path { $true }
$options = Get-OfficeDeploymentOptions @{OfficeSubscription='Microsoft 365 Business Standard'; OfficeArchitecture='64'}
$media = [pscustomobject]@{Setup='inert.exe'; Config='inert.xml'; Version='16.0.1.2'}
$script:installed = [pscustomobject]@{ProductReleaseIds='O365BusinessRetail'; Platform='x64'; VersionToReport='16.0.1.2'}
@@ -311,6 +507,9 @@ try {
Assert-OfficeThrows { Install-OfficeMedia $options $media $testRoot } 'did not match'
$script:installCode=42
Assert-OfficeThrows { Install-OfficeMedia $options $media $testRoot } 'installation failed'
$script:installCode=0; $script:installed.VersionToReport='16.0.1.2'; $script:officeChecks=0
function Get-ItemProperty { $script:officeChecks++; if ($script:officeChecks -ge 3) { $script:installed } }
Assert-OfficeTest ((Install-OfficeMedia $options $media $testRoot) -eq 0 -and $script:officeChecks -eq 3) 'Office verification must tolerate delayed Click-to-Run registration.'
}
& {
$script:registered = @(); $script:started = @(); $script:removed = @()
@@ -327,6 +526,9 @@ try {
$pending = Start-OfficeUserCleanup $profiles ([pscustomobject]@{Helper='C:\secure\helper.ps1'}) (Join-Path $testRoot ('a'*32))
Assert-OfficeTest ($script:registered.Count -eq 2 -and $script:started.Count -eq 1 -and $script:removed.Count -eq 1) 'User scheduling or completed task cleanup is incorrect.'
Assert-OfficeTest ($pending.Count -eq 1 -and $pending[0] -eq 'logged-off') 'Logged-off user cleanup was reported complete.'
function Unregister-ScheduledTask { throw 'Task Scheduler is temporarily unavailable.' }
$pending = Start-OfficeUserCleanup $profiles ([pscustomobject]@{Helper='C:\secure\helper.ps1'}) (Join-Path $testRoot ('a'*32))
Assert-OfficeTest ($pending.Count -eq 1 -and $pending[0] -eq 'logged-off') 'Completed task housekeeping must not fail deployment or mark completed cleanup pending.'
}
# Test orchestration with every machine mutation mocked.