compact report output
This commit is contained in:
@@ -33,8 +33,33 @@ try {
|
||||
foreach ($definition in $core.FindAll({param($n) $n -is [Management.Automation.Language.FunctionDefinitionAst]}, $false)) {
|
||||
. ([scriptblock]::Create($definition.Extent.Text))
|
||||
}
|
||||
$script:messages = @()
|
||||
function Write-SystemCleanupMessage { param($Message) $script:messages += $Message }
|
||||
$messageWriter = ${function:Write-SystemCleanupMessage}
|
||||
$script:messages = @(); $script:details = @()
|
||||
function Write-SystemCleanupMessage {
|
||||
param($Message, [switch]$Detail)
|
||||
if ($Detail) { $script:details += $Message } else { $script:messages += $Message }
|
||||
}
|
||||
& {
|
||||
$VerbosePreference = 'SilentlyContinue'
|
||||
$visible = @(& $messageWriter 'compact output' 6>&1)
|
||||
$hidden = @(& $messageWriter 'handler inventory' -Detail 4>&1 6>&1)
|
||||
Assert-Cleanup ($visible.Count -eq 1 -and [string]$visible[0] -match 'compact output' -and $hidden.Count -eq 0) 'Verbose diagnostics must not consume the normal RMM output budget.'
|
||||
$VerbosePreference = 'Continue'
|
||||
$verbose = @(& $messageWriter 'handler inventory' -Detail 4>&1)
|
||||
Assert-Cleanup ($verbose.Count -eq 1 -and $verbose[0] -is [Management.Automation.VerboseRecord]) 'Full diagnostics must remain available on the verbose stream.'
|
||||
}
|
||||
& {
|
||||
# Run the actual entry statement with an inert function. The host summary
|
||||
# must survive, while success-stream objects must not become a second report.
|
||||
function Invoke-SystemCleanup {
|
||||
param($Options)
|
||||
Write-SystemCleanupMessage 'entry summary'
|
||||
[pscustomobject]@{Category='Fixture'; Enabled=$true; CandidateFiles=1}
|
||||
}
|
||||
$script:messages = @()
|
||||
$output = @(& ([scriptblock]::Create($core.EndBlock.Statements[-1].Extent.Text)))
|
||||
Assert-Cleanup ($output.Count -eq 0 -and $script:messages -contains 'entry summary') 'Core entry must suppress the duplicate object dump without suppressing the summary.'
|
||||
}
|
||||
function New-CleanupContext {
|
||||
param([bool]$ReportOnly = $true, [bool]$Server = $false)
|
||||
return @{
|
||||
@@ -214,12 +239,12 @@ try {
|
||||
function Get-ChildItem { throw 'None must not access the registry.' }
|
||||
function Test-SystemCleanupAppRunning { throw 'None must not probe native cleanup.' }
|
||||
function Invoke-SystemCleanupProcess { throw 'None must not launch cleanmgr.' }
|
||||
$script:messages = @()
|
||||
$script:messages = @(); $script:details = @()
|
||||
Invoke-SystemCleanupCategory $c 'DiskCleanup' { Invoke-SystemCleanupDiskCleanup $c }
|
||||
Write-SystemCleanupReport $c
|
||||
$report = $script:messages -join "`n"
|
||||
Assert-Cleanup ($report -match '(?s)DISABLED -.*DiskCleanup \[CleanupDiskCleanupItems=None\].*No handlers selected') 'None must appear in the disabled report section with a clear explanation.'
|
||||
Assert-Cleanup ($report -match 'items not selected.*Previous Installations' -and $report -notmatch 'CleanupDiskCleanup=') 'None should report unselected handlers without advertising the removed boolean.'
|
||||
Assert-Cleanup ($report -match '(?s)DISABLED -.*DiskCleanup\s+-\s+-\s+.*None \(0 handlers\); will not run') 'None must appear in the disabled report section with a clear explanation.'
|
||||
Assert-Cleanup (($script:details -join "`n") -match 'items not selected.*Previous Installations' -and $report -notmatch 'Previous Installations|CleanupDiskCleanup=') 'Unselected handler inventories belong in verbose diagnostics, not the compact report.'
|
||||
$c.Options.ReportOnly = $false
|
||||
Invoke-SystemCleanupDiskCleanup $c
|
||||
Assert-Cleanup ($c.Errors -eq 0) 'None must not attempt native cleanup, even through the helper directly.'
|
||||
@@ -259,7 +284,8 @@ try {
|
||||
$script:messages=@()
|
||||
Write-SystemCleanupReport $c
|
||||
$report=$script:messages -join "`n"
|
||||
Assert-Cleanup ($report.IndexOf('ENABLED -') -lt $report.IndexOf('DISABLED -') -and $report.IndexOf('DuplicateDownloads [CleanupDuplicateDownloads=true]') -lt $report.IndexOf('DISABLED -') -and $report.IndexOf('DownloadedExecutables [CleanupDownloadedExecutables=false]') -gt $report.IndexOf('DISABLED -')) 'Enabled and disabled report groups are unclear or misplaced.'
|
||||
Assert-Cleanup ($report.IndexOf('ENABLED -') -lt $report.IndexOf('DISABLED -') -and $report.IndexOf('DuplicateDownloads') -lt $report.IndexOf('DISABLED -') -and $report.IndexOf('DownloadedExecutables') -gt $report.IndexOf('DISABLED -')) 'Enabled and disabled report groups are unclear or misplaced.'
|
||||
Assert-Cleanup ($report.IndexOf('Known savings:') -lt $report.IndexOf('ENABLED -') -and $report -match 'Additional DISABLED' -and $report -match '<0.01') 'Unique totals must appear first and small nonzero candidates must remain visible.'
|
||||
$c=New-CleanupContext -ReportOnly $false
|
||||
$script:disabledRan=$false
|
||||
Invoke-SystemCleanupCategory $c 'DownloadedExecutables' { $script:disabledRan=$true; Clear-SystemCleanupTree $c 'DownloadedExecutables' $potentialRoot $cutoff -Include @('*.exe') }
|
||||
@@ -462,21 +488,43 @@ try {
|
||||
function Delete-DeliveryOptimizationCache { throw 'PREVIEW MUTATION: delivery cache' }
|
||||
function Start-Process { throw 'PREVIEW MUTATION: native program' }
|
||||
$o=Get-SystemCleanupOptions
|
||||
$script:messages=@(); $script:details=@()
|
||||
$result=@(Invoke-SystemCleanup $o)
|
||||
Assert-Cleanup ($result.Count -eq 22 -and @($result | Where-Object Status -ne 'Preview').Count -eq 0) "Full preview did not cover every category (count=$($result.Count))."
|
||||
Assert-Cleanup (@($result | Where-Object { $_.Category -eq 'DownloadedExecutables' -and -not $_.Enabled -and $_.CandidateFiles -eq 1 }).Count -eq 1) 'Default-disabled downloads were not assessed by the entry point.'
|
||||
Assert-Cleanup (@($result | Where-Object { $_.Category -eq 'ComponentStore' -and -not $_.Enabled -and $null -eq $_.CandidateBytes -and $_.EstimateStatus -eq 'Not estimated' }).Count -eq 1) 'Unknown native savings must not be reported as zero.'
|
||||
Assert-Cleanup (Test-Path -LiteralPath (Join-Path $env:SystemRoot 'Temp\old.tmp')) 'Full preview removed a fixture.'
|
||||
$compactOutput = ($script:messages | ForEach-Object { '[SystemCleanup] ' + $_ }) -join "`r`n"
|
||||
$script:compactReportBytes = [Text.Encoding]::UTF8.GetByteCount($compactOutput)
|
||||
Assert-Cleanup ($script:compactReportBytes -lt 4096) "22-category preview exceeded the 4 KiB regression budget ($script:compactReportBytes bytes)."
|
||||
foreach ($row in $result) {
|
||||
Assert-Cleanup ([regex]::Matches($compactOutput, ('(?m)^\[SystemCleanup\] ' + [regex]::Escape($row.Category) + '\s')).Count -eq 1) "Compact report lost or repeated category $($row.Category)."
|
||||
}
|
||||
Assert-Cleanup ($compactOutput -notmatch 'Assessing |selected items:|items not selected|CandidateFiles\s*:' -and $compactOutput -match 'Standard \(7 handlers\)') 'Default output must show the preset without progress chatter, handler inventories, or object dumps.'
|
||||
Assert-Cleanup (($script:details -join "`n") -match 'items not selected.*Previous Installations') 'Full handler details must remain available in verbose output.'
|
||||
function Test-SystemCleanupAppRunning { return $true }
|
||||
function Get-Command { return $null }
|
||||
$o.DiskCleanupItems=@(); $o.DiskCleanupPreset='None'
|
||||
$script:messages=@()
|
||||
$result=@(Invoke-SystemCleanup $o)
|
||||
Assert-Cleanup (@($result | Where-Object { $_.Category -eq 'RevitJournals' -and $_.Status -eq 'Skipped' }).Count -eq 1) 'An active application should skip cleanup, not fail the whole run.'
|
||||
Assert-Cleanup (@($result | Where-Object { $_.Category -eq 'DeliveryOptimization' -and -not $_.Enabled -and $_.Status -eq 'Unavailable' -and $null -eq $_.CandidateBytes }).Count -eq 1) 'A missing optional feature must be reported as unavailable, not zero savings or a failed report.'
|
||||
$compactOutput=$script:messages -join "`n"
|
||||
Assert-Cleanup ($compactOutput -match 'BrowserCache.*Partial; incomplete.*chrome.*msedge' -and $compactOutput -match 'RevitJournals.*Skipped.*Revit is running' -and $compactOutput -match 'DeliveryOptimization.*Unavailable.*not installed') 'Compacting output must preserve partial, skipped and unavailable reasons.'
|
||||
} finally {
|
||||
$env:SystemRoot=$savedEnvironment.SystemRoot; $env:SystemDrive=$savedEnvironment.SystemDrive; $env:ProgramData=$savedEnvironment.ProgramData
|
||||
}
|
||||
}
|
||||
& {
|
||||
$c=New-CleanupContext
|
||||
$script:messages=@(); $script:details=@()
|
||||
Invoke-SystemCleanupCategory $c 'CrashDumps' { throw ("Synthetic failure`r`n" + ('long diagnostic ' * 300)) }
|
||||
Write-SystemCleanupReport $c
|
||||
$report=$script:messages -join "`n"
|
||||
Assert-Cleanup ($c.Errors -eq 1 -and $report -match 'CrashDumps.*Failed; incomplete.*Synthetic failure.*see verbose' -and $report.Length -lt 1600) 'A long multiline error must retain its failure status without flooding the summary.'
|
||||
Assert-Cleanup (($script:details -join "`n").Contains(('long diagnostic ' * 300))) 'Compacted errors must remain complete in verbose diagnostics.'
|
||||
}
|
||||
Write-Host "Compact 22-category preview: $script:compactReportBytes UTF-8 bytes."
|
||||
Write-Host "PASS: $script:assertions offline cleanup assertions ($($PSVersionTable.PSVersion))."
|
||||
} finally {
|
||||
# Only this test's generated directory; links are removed non-recursively above.
|
||||
|
||||
Reference in New Issue
Block a user