fixed an issue with the cli args for the scrubber tool

This commit is contained in:
2026-10-14 17:43:32 -04:00
parent b07e132b3c
commit e3fe378b41
3 changed files with 203 additions and 13 deletions
+117 -1
View File
@@ -37,6 +37,32 @@ try {
# Exercise the real bounded retry loops without delaying offline tests.
function Start-Sleep { param([int]$Seconds) $script:testSleeps += $Seconds }
$script:testSleeps = @()
# Captured from signed GetHelpCmd 1.0.0+d28f675 on 2026-10-14 using only -?.
$currentGetHelpUsage = @'
Starting Microsoft GetHelp Command Line Tool
Usage: GetHelpCmd.exe [options]
Options:
-S <scenario> Run the specified scenario.
-RemoveSCA Remove Shared Computer Activation.
-IsOrgId Is OrgId account.
-P <profile> Specify Outlook profile name.
-LogFolder <folder> Specify log folder.
-AcceptEula Accept the End-User License Agreement.
-DisplayEULA Display the EULA URL.
-Help Display online help.
-? Display this help message.
Examples:
GetHelpCmd.exe -S OfficeSharedComputerScenario -AcceptEula
GetHelpCmd.exe -S OfficeActivationScenario -AcceptEula
GetHelpCmd.exe -S OfficeScrubScenario -AcceptEula
GetHelpCmd.exe -S ExpertExperienceAdminTask -AcceptEula
GetHelpCmd.exe -S OutlookCalendarCheckTask -AcceptEula
GetHelpCmd.exe -S OutlookEmailSetupScenario -AcceptEula
GetHelpCmd.exe -S ResetOfficeActivation -AcceptEula
GetHelpCmd.exe -S TeamsAddinScenario -AcceptEula
'@
$currentGetHelpSuccess = "Scenario completed successfully.`r`nExecutionResultDetails: Uninstall office is running in the background."
& {
$script:probeCalls=0; $script:testSleeps=@()
$result = Wait-OfficeResult { $script:probeCalls++; if ($script:probeCalls -eq 3) { [pscustomobject]@{Version='ready'} } } 'delayed fixture registration'
@@ -237,6 +263,9 @@ try {
$script:mediaProcesses += [IO.Path]::GetFileName($FilePath)
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 'GetHelpCmd.exe' -and $Arguments -eq '-?') {
[IO.File]::WriteAllText("$LogPrefix.stdout.log", $currentGetHelpUsage)
[IO.File]::WriteAllText("$LogPrefix.stderr.log", '')
} elseif ([IO.Path]::GetFileName($FilePath) -eq 'setup.exe' -and $Arguments -like '/download *') {
$script:mediaDownloadCalls++
if ($script:mediaDownloadCalls -eq 1) { return 12029 }
@@ -252,7 +281,8 @@ 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,setup.exe') 'Staging must retry the failed download without launching a scrubber or companion installer.'
Assert-OfficeTest (($script:mediaProcesses -join ',') -eq 'odt.exe,GetHelpCmd.exe,setup.exe,setup.exe') 'Staging must probe Get Help usage and retry the failed download without starting a scrub scenario or companion installation.'
Assert-OfficeTest ($media.ScrubArguments -eq '-S OfficeScrubScenario -AcceptEula') 'Staging must select the syntax supported by the downloaded scrubber.'
}
& {
$script:staged = @(); $script:verified = @()
@@ -369,6 +399,92 @@ try {
Assert-OfficeThrows { Assert-OfficeScrubResult 0 'Starting scenario...' @() } 'no recognizable'
Assert-OfficeThrows { Assert-OfficeScrubResult 1 '00: Success.' @() } 'removal failed'
Assert-OfficeThrows { Assert-OfficeScrubResult 0 '68: No product.' @([pscustomobject]@{DisplayName='Office 2016'}) } 'Office remains'
Assert-OfficeTest ((Get-OfficeScrubArguments 0 $currentGetHelpUsage) -eq '-S OfficeScrubScenario -AcceptEula') 'Current Get Help must not receive the rejected OfficeVersion switch.'
Assert-OfficeTest ((Get-OfficeScrubArguments 0 ($currentGetHelpUsage + "`n -OfficeVersion <version> Specify version to remove.")) -eq '-S OfficeScrubScenario -AcceptEula -OfficeVersion All') 'Get Help builds advertising OfficeVersion must explicitly select All.'
Assert-OfficeTest ((Get-OfficeScrubArguments 0 " -OfficeVersion <version>`nGetHelpCmd.exe -S OfficeScrubScenario -AcceptEula -OfficeVersion All") -eq '-S OfficeScrubScenario -AcceptEula -OfficeVersion All') 'A usage example with an optional version argument must also validate.'
Assert-OfficeThrows { Get-OfficeScrubArguments 1 $currentGetHelpUsage } 'command syntax'
Assert-OfficeThrows { Get-OfficeScrubArguments 0 'Usage: unrecognized executable' } 'command syntax'
Assert-OfficeThrows { Get-OfficeScrubArguments 0 ("Error: Invalid command line arguments`n" + $currentGetHelpUsage) } 'command syntax'
Assert-OfficeScrubResult 0 $currentGetHelpSuccess @()
Assert-OfficeScrubResult 0 'Scenario completed successfully.' @()
Assert-OfficeThrows { Assert-OfficeScrubResult 0 ("Error: Invalid command line arguments`n" + $currentGetHelpUsage) @() } 'removal failed.*Invalid command line arguments'
Assert-OfficeThrows { Assert-OfficeScrubResult 0 " - Uninstall Office Scenario failed.`nAccess denied." @() } 'removal failed.*Access denied'
Assert-OfficeThrows { Assert-OfficeScrubResult 0 ($currentGetHelpSuccess + "`nError: failed after launch") @() } 'removal failed'
Assert-OfficeThrows { Assert-OfficeScrubResult 0 ($currentGetHelpSuccess + "`n09: Failure to remove Office.") @() } 'removal failed'
Assert-OfficeThrows { Assert-OfficeScrubResult 0 "09: Failed`n00: Completed" @() } 'removal failed'
Assert-OfficeThrows { Assert-OfficeScrubResult 1 $currentGetHelpSuccess @() } 'no recognizable successful'
Assert-OfficeThrows { Assert-OfficeScrubResult 0 'Diagnostic action completed.' @() } 'no recognizable successful'
Assert-OfficeThrows { Assert-OfficeScrubResult 0 $currentGetHelpSuccess @([pscustomobject]@{DisplayName='Office 2021'}) } 'Office remains'
& {
function Get-CimInstance {
param($ClassName,$Filter)
Assert-OfficeTest ($ClassName -eq 'Win32_Process' -and $Filter -match 'powershell.exe') 'Background scrub checks must query process state, not MSI product repair inventory.'
[pscustomobject]@{ProcessId=$PID; Name='powershell.exe'; CommandLine='deployment host'}
[pscustomobject]@{ProcessId=101; Name='msiexec.exe'; CommandLine='C:\Windows\System32\msiexec.exe /V'}
[pscustomobject]@{ProcessId=102; Name='msiexec.exe'; CommandLine='msiexec.exe /Embedding guid'}
[pscustomobject]@{ProcessId=103; Name='OfficeClickToRun.exe'; CommandLine='OfficeClickToRun.exe /service'}
[pscustomobject]@{ProcessId=104; Name='msiexec.exe'; CommandLine='msiexec.exe /x fixture /qn'}
[pscustomobject]@{ProcessId=105; Name='powershell.exe'; CommandLine='powershell.exe -File OfficeUninstall.ps1'}
}
$workers = @(Get-OfficeScrubWorkers)
Assert-OfficeTest (($workers.ProcessId -join ',') -eq '104,105') 'Only client/script workers should block background completion; exclude this host and idle service hosts.'
}
$realOfficeDefinitions = ${function:Get-OfficeDeploymentDefinitions}
& {
function Get-OfficeDeploymentDefinitions {
$values = & $realOfficeDefinitions
$values.ScrubBackgroundCheckAttempts=10; $values.ScrubBackgroundQuietChecks=3
$values
}
function Get-OfficeSuiteInventory {
$script:scrubChecks++
if ($script:scrubMode -eq 'read-error') { throw 'Office inventory is unreadable' }
if ($script:scrubMode -eq 'remaining' -or ($script:scrubMode -eq 'delayed' -and $script:scrubChecks -le 2) -or ($script:scrubMode -eq 'reappears' -and $script:scrubChecks -eq 3)) { [pscustomobject]@{DisplayName='Fixture Office 2021'} }
}
function Get-OfficeScrubWorkers {
[pscustomobject]@{ProcessId=200; CreationDate='old'; Name='powershell.exe'; CommandLine='existing console'}
if ($script:scrubMode -eq 'worker' -or ($script:scrubMode -eq 'delayed' -and $script:scrubChecks -le 4)) {
# Reused PID with a new creation time must not be mistaken for a baseline process.
[pscustomobject]@{ProcessId=201; CreationDate='new'; Name='powershell.exe'; CommandLine='detached cleanup'}
}
}
$baseline = @([pscustomobject]@{ProcessId=200; CreationDate='old'},[pscustomobject]@{ProcessId=201; CreationDate='old'})
foreach ($script:scrubMode in @('empty','delayed','reappears','remaining','worker','read-error')) {
$script:scrubChecks=0
if ($script:scrubMode -in @('remaining','worker')) {
Assert-OfficeThrows { Wait-OfficeScrubRemoval $baseline } 'background removal did not finish'
Assert-OfficeTest ($script:scrubChecks -eq 10) 'Background removal must stop at its configured bound.'
} elseif ($script:scrubMode -eq 'read-error') {
Assert-OfficeThrows { Wait-OfficeScrubRemoval $baseline } 'Office inventory is unreadable'
} else {
$output = @(Wait-OfficeScrubRemoval $baseline)
$expectedChecks = switch ($script:scrubMode) { 'empty' {3}; 'delayed' {7}; 'reappears' {6} }
Assert-OfficeTest ($output.Count -eq 0 -and $script:scrubChecks -eq $expectedChecks) "Background removal skipped worker completion or its quiet interval: $script:scrubMode."
}
}
}
& {
function Get-OfficeScrubWorkers { }
function Get-OfficeSuiteInventory { }
function Wait-OfficeScrubRemoval { $script:backgroundWaits++ }
function Invoke-OfficeProcess {
param($FilePath,$Arguments,$LogPrefix)
Assert-OfficeTest ($Arguments -eq '-S OfficeScrubScenario -AcceptEula') 'Removal must use the command validated during staging.'
[IO.File]::WriteAllText("$LogPrefix.stdout.log", $script:scrubOutput)
[IO.File]::WriteAllText("$LogPrefix.stderr.log", '')
0
}
$media = [pscustomobject]@{Scrubber='inert.exe'; ScrubArguments='-S OfficeScrubScenario -AcceptEula'}
$script:backgroundWaits=0; $script:scrubOutput=$currentGetHelpSuccess
Remove-OfficeSuite $media $testRoot
Assert-OfficeTest ($script:backgroundWaits -eq 1) 'Background acknowledgement must trigger the extended completion check.'
$script:scrubOutput='00: Successfully completed this scenario.'
Remove-OfficeSuite $media $testRoot
Assert-OfficeTest ($script:backgroundWaits -eq 1) 'A synchronous result should use ordinary removal verification.'
$script:scrubOutput="Error: Invalid command line arguments`n$currentGetHelpUsage"
Assert-OfficeThrows { Remove-OfficeSuite $media $testRoot } 'Invalid command line arguments'
Assert-OfficeTest ($script:backgroundWaits -eq 1) 'A failed launch must fail before background waiting or installation.'
}
Assert-OfficeTest (Test-OfficeCredentialTarget 'MicrosoftOffice16_Data:ADAL:example') 'Office ADAL credential should be cleared.'
foreach ($target in @('WindowsLive:target', 'MicrosoftAccount:user', 'OneDrive:user', 'AzureAD:user', 'TERMSRV/server', 'MicrosoftOffice16_DataEvil')) { Assert-OfficeTest (!(Test-OfficeCredentialTarget $target)) "Unrelated credential matched: $target" }
Assert-OfficeTest ('Microsoft.AAD.BrokerPlugin' -notin (Get-OfficeAppxNames)) 'Must preserve Windows work-account broker.'