fix scrubber call

This commit is contained in:
2026-10-29 15:24:01 -04:00
parent 52aa59a70c
commit a8b8429b58
3 changed files with 65 additions and 8 deletions
+24 -3
View File
@@ -899,6 +899,25 @@ try {
else { Assert-OfficeThrows { Initialize-OfficeScrubMedia $workspace } 'exactly one GetHelpCmd.exe' }
}
}
# Scrub console details must reach the management log even when no recognizable
# scenario code is emitted; excerpts are bounded without altering parser input.
& {
$prefix=Join-Path $testRoot 'scrub-output'
$stdout="Tool startup message without scenario code`n" + (('x' * 2100) + "`n") + ((1..25 | ForEach-Object { "progress $_" }) -join "`n")
$stderr='A diagnostic from stderr'
[IO.File]::WriteAllText("$prefix.stdout.log", $stdout)
[IO.File]::WriteAllText("$prefix.stderr.log", $stderr)
$output=@(Read-OfficeScrubOutput $prefix)
Assert-OfficeTest ($output.Count -eq 1 -and $output[0] -ceq ($stdout + "`n" + $stderr)) 'Diagnostic excerpts must not change the complete scrub output used for result parsing.'
$log=Get-Content -LiteralPath $Global:LogFile -Raw
Assert-OfficeTest ($log.Contains('Get Help stderr detail: A diagnostic from stderr') -and $log.Contains('Get Help stdout: ')) 'Both stream sizes and captured text must reach the main management log.'
Assert-OfficeTest ($log.Contains('Get Help stdout detail: Tool startup message without scenario code') -and $log.Contains('Get Help stdout detail: progress 25') -and !$log.Contains('Get Help stdout detail: progress 14' + [Environment]::NewLine) -and $log.Contains('[middle output omitted; see full stream log]')) 'Bounded scrub excerpts must retain initial failures and final results.'
[IO.File]::WriteAllText("$prefix.stdout.log", 'x' * 2100)
[IO.File]::WriteAllText("$prefix.stderr.log", '')
$null=Read-OfficeScrubOutput $prefix
$log=Get-Content -LiteralPath $Global:LogFile -Raw
Assert-OfficeTest ($log.Contains('[truncated; see full stream log]') -and $log.Contains('Get Help stderr: no text captured.')) 'Oversized lines and empty streams must be explicit in the management log.'
}
# A scrub requires both a successful scenario/process result and independently
# verified removal. Every attempt is bounded to one and cleanup retains its logs.
& {
@@ -912,7 +931,7 @@ try {
function Invoke-OfficeProcess {
param($FilePath,$Arguments,$LogPrefix)
$script:scrubLaunches++
Assert-OfficeTest ($Arguments -eq '-S OfficeScrubScenario -AcceptEula -OfficeVersion All' -and (Split-Path -Leaf $LogPrefix) -eq 'office-scrub') 'Scrub must use documented unattended arguments with separate logs.'
Assert-OfficeTest ($Arguments -eq '-S OfficeScrubScenario -AcceptEula' -and (Split-Path -Leaf $LogPrefix) -eq 'office-scrub') 'Scrub must use the current tool-supported arguments, omitting the rejected OfficeVersion option.'
Set-Content -LiteralPath "$LogPrefix.stdout.log" -Value $script:scrubOutput
Set-Content -LiteralPath "$LogPrefix.stderr.log" -Value ''
$script:scrubExit
@@ -923,7 +942,7 @@ try {
if ($script:scrubMode -eq 'inventory-error') { throw 'Registry unreadable' }
}
function Assert-OfficeFreshInstallState { if ($script:scrubMode -eq 'stale') { throw 'Previous Click-to-Run state remains' } }
foreach ($script:scrubMode in @('success','restart','download','failure','not-found-66','not-found-68','empty','contradictory','bad-exit','running','remaining','inventory-error','stale')) {
foreach ($script:scrubMode in @('success','restart','download','failure','not-found-66','not-found-68','empty','invalid-arguments','usage','contradictory','bad-exit','running','remaining','inventory-error','stale')) {
$workspace=Join-Path $testRoot ('scrub-result-' + $script:scrubMode); $null=[IO.Directory]::CreateDirectory($workspace)
$media=[pscustomobject]@{}; $script:scrubExit=0; $script:scrubOutput='00: Successfully completed this scenario.'
switch ($script:scrubMode) {
@@ -932,6 +951,8 @@ try {
'not-found-66' { $script:scrubOutput='66: We could not find the specified Office version.'; $script:scrubExit=66 }
'not-found-68' { $script:scrubOutput='68: We could not find any Office version.' }
'empty' { $script:scrubOutput='' }
'invalid-arguments' { $script:scrubOutput="Starting Microsoft GetHelp Command Line Tool`nError: Invalid command line arguments`nUsage: GetHelpCmd.exe [options]`nExamples:`nGetHelpCmd.exe -S OfficeScrubScenario -AcceptEula" }
'usage' { $script:scrubOutput="Usage: GetHelpCmd.exe [options]`n00: Success" }
'contradictory' { $script:scrubOutput="09: Failure`n00: Success" }
'bad-exit' { $script:scrubExit=1 }
}
@@ -939,7 +960,7 @@ try {
$result=@(Invoke-OfficeScrubRecovery $media $workspace 'fixture corruption')
Assert-OfficeTest ($result.Count -eq 1 -and $result[0] -eq 3010 -and $media.ScrubAttempted -and $media.ScrubReason -eq 'fixture corruption') 'Verified scrub must surface its use and restart requirement without leaking log messages.'
} else {
$pattern=switch ($script:scrubMode) { 'download' {'Scrub download failed'}; 'running' {'processes are still running'}; 'remaining' {'Office remains.*Leftover MSI Office'}; 'inventory-error' {'Registry unreadable'}; 'stale' {'Click-to-Run state remains'}; default {'failed or returned an unverified result'} }
$pattern=switch ($script:scrubMode) { 'download' {'Scrub download failed'}; 'invalid-arguments' {'rejected its command line.*process 0'}; 'usage' {'rejected its command line.*process 0'}; 'running' {'processes are still running'}; 'remaining' {'Office remains.*Leftover MSI Office'}; 'inventory-error' {'Registry unreadable'}; 'stale' {'Click-to-Run state remains'}; default {'failed or returned an unverified result'} }
Assert-OfficeThrows { Invoke-OfficeScrubRecovery $media $workspace 'fixture corruption' } $pattern
}
$before=$script:scrubLaunches