improve summary display

This commit is contained in:
2026-10-23 11:33:03 -04:00
parent c5ef81dfca
commit 08dbb3cdd5
4 changed files with 78 additions and 41 deletions
+27 -13
View File
@@ -285,31 +285,45 @@ try {
Invoke-SystemCleanupCategory $c $name {}
}
$c.Diagnostics=Get-SystemCleanupDiagnostics $c
Assert-Cleanup ($c.Diagnostics.Hibernation -match '4.00 GiB file size' -and $c.Diagnostics.ShadowStorage -match '2.00 GiB used / 3.00 GiB allocated' -and $c.Diagnostics.ComponentStore -match 'not analyzed;.*superseded updates.*substantial.*little/none') 'Disabled options must still receive usage diagnostics and an honest note about potential component-store savings.'
Assert-Cleanup ($c.Diagnostics.ShadowStorage -notmatch '99.00|100.00' -and $c.Diagnostics.ShadowStorage.EndsWith("stored on $env:SystemDrive")) 'VSS must select the system volume and report its actual storage location.'
Assert-Cleanup ($c.Stats.DisableHibernation.UsageBytes -eq 4GB -and $c.Stats.ShadowCopies.UsageBytes -eq 2GB -and $c.Diagnostics.ComponentStore -match 'not analyzed;.*superseded updates.*substantial.*little/none') 'Disabled options must still receive usage measurements and an honest note about potential component-store savings.'
Assert-Cleanup ($c.Stats.ShadowCopies.UsageNote.EndsWith("stored on $env:SystemDrive") -and ($script:details -join "`n") -match '3,072.00 MiB allocated') 'VSS must select the system volume, label its storage location and leave allocation details in verbose output.'
$totals=Get-SystemCleanupReportTotals $c
Assert-Cleanup ($totals.EnabledBytes -eq 0 -and $totals.AdditionalDisabledBytes -eq 0 -and -not $c.Options.ShadowCopies -and $c.Errors -eq 0) 'Diagnostic usage is not reclaimable savings and must not enable cleanup.'
$script:messages=@()
Write-SystemCleanupReport $c
$report=$script:messages -join "`n"
Assert-Cleanup ($report -match 'DIAGNOSTICS - current usage/potential, excluded from savings totals' -and [regex]::Matches($report,'(?m)^ (Hibernation|ShadowStorage|ComponentStore):').Count -eq 3) 'Diagnostics must occupy three compact lines outside category totals.'
Assert-Cleanup ($report -notmatch '\bHibernation:|ShadowStorage:' -and [regex]::Matches($report,'(?m)^ ComponentStore:').Count -eq 1) 'Hibernation and VSS must not produce separate diagnostic lines.'
Assert-Cleanup ($report -match 'DisableHibernation\s+-\s+4,096.00\s+file size; excluded from totals' -and $report -match 'ShadowCopies\s+-\s+2,048.00\s+VSS used; excluded from totals; newest retained') 'Measured usage must appear in the category MiB column with its meaning and exclusion from totals.'
Assert-Cleanup ($report -notmatch '(DisableHibernation|ShadowCopies).*not estimated|GiB|MiB allocated') 'Measured rows must not say not estimated or repeat allocation diagnostics.'
$c.Options.ComponentStore=$true
$d=Get-SystemCleanupDiagnostics $c
Assert-Cleanup ($script:diagnosticProcesses -eq 0 -and $d.ComponentStore -eq $c.Diagnostics.ComponentStore) 'Enabling component cleanup must not launch analysis or fabricate a measured recommendation in report mode.'
$script:storageTarget=$otherId
Assert-Cleanup ((Get-SystemCleanupShadowStorageDiagnostic) -match 'stored on Z:') 'Shadow storage on another drive must not be attributed to the system drive.'
$null=Get-SystemCleanupDiagnostics $c
Assert-Cleanup ($c.Stats.ShadowCopies.UsageBytes -eq 2GB -and $c.Stats.ShadowCopies.UsageNote -match 'stored on Z:') 'Shadow storage on another drive must not be attributed to the system drive.'
$script:storageState='empty'; $script:hiberState='missing'
$d=Get-SystemCleanupDiagnostics $c
Assert-Cleanup ($d.Hibernation -eq 'hiberfil.sys not present' -and $d.ShadowStorage -match 'no shadow-storage association') 'Absent hibernation or VSS data must be reported explicitly.'
Assert-Cleanup ($c.Stats.DisableHibernation.UsageBytes -eq 0 -and $c.Stats.ShadowCopies.UsageBytes -eq 0) 'Absent hibernation or a missing shadow-storage association must measure zero bytes.'
$script:messages=@(); Write-SystemCleanupReport $c
$report=$script:messages -join "`n"
Assert-Cleanup ($report -match 'DisableHibernation\s+-\s+0.00\s' -and $report -match 'ShadowCopies\s+-\s+0.00\s' -and $report -notmatch 'hiberfil.sys not present|no shadow-storage association|\bHibernation:|ShadowStorage:') 'Absent usage must appear as zero MiB in the two rows without separate absence messages.'
$script:storageState='invalid'
Assert-Cleanup ((Get-SystemCleanupDiagnostics $c).ShadowStorage -match 'unavailable') 'Missing VSS measurements must not become zero.'
$null=Get-SystemCleanupDiagnostics $c
Assert-Cleanup ($null -eq $c.Stats.ShadowCopies.UsageBytes -and $c.Stats.ShadowCopies.UsageNote -match 'unavailable') 'Missing VSS measurements must not become zero.'
$script:storageState='denied'; $script:hiberState='denied'
$d=Get-SystemCleanupDiagnostics $c
Assert-Cleanup ($d.Hibernation -match 'unavailable' -and $d.ShadowStorage -match 'unavailable' -and $d.ComponentStore -match 'not analyzed' -and $c.Errors -eq 0) 'A diagnostic failure must not prevent the other diagnostics or fail cleanup reporting.'
Assert-Cleanup ($null -eq $c.Stats.DisableHibernation.UsageBytes -and $null -eq $c.Stats.ShadowCopies.UsageBytes -and $c.Stats.DisableHibernation.UsageNote -match 'unavailable' -and $c.Stats.ShadowCopies.UsageNote -match 'unavailable' -and $d.ComponentStore -match 'not analyzed' -and $c.Errors -eq 0) 'Diagnostic failures must clear old measurements, preserve the component note and not fail reporting.'
$script:messages=@(); Write-SystemCleanupReport $c
$report=$script:messages -join "`n"
Assert-Cleanup ($report -match 'DisableHibernation\s+-\s+-\s+unavailable' -and $report -match 'ShadowCopies\s+-\s+-\s+unavailable') 'Failed inspections must display unknown size rather than zero MiB.'
$script:fileReads=0; $script:storageReads=0
$c.OS.IsServer=$true
$c=New-CleanupContext -Server $true
foreach ($name in @('DisableHibernation','ShadowCopies')) { Invoke-SystemCleanupCategory $c $name {} }
$d=Get-SystemCleanupDiagnostics $c
Assert-Cleanup ($script:fileReads -eq 0 -and $script:storageReads -eq 0 -and $script:diagnosticProcesses -eq 0 -and $d.Hibernation -match 'server policy' -and $d.ShadowStorage -match 'server policy' -and $d.ComponentStore -match 'not analyzed') 'Server reports must block hibernation/VSS assessment and only note potential component-store savings.'
Assert-Cleanup ($script:fileReads -eq 0 -and $script:storageReads -eq 0 -and $script:diagnosticProcesses -eq 0 -and $null -eq $c.Stats.DisableHibernation.UsageBytes -and $null -eq $c.Stats.ShadowCopies.UsageBytes -and $d.Count -eq 1 -and $d.ComponentStore -match 'not analyzed') 'Server reports must block hibernation/VSS assessment and only note potential component-store savings.'
$script:messages=@(); Write-SystemCleanupReport $c
$report=$script:messages -join "`n"
Assert-Cleanup ($report -match 'DisableHibernation\s+-\s+-\s+not assessed' -and $report -match 'ShadowCopies\s+-\s+-\s+not assessed') 'Server-blocked rows must remain unassessed rather than showing zero usage.'
$c.Options.ReportOnly=$false
$d=Get-SystemCleanupDiagnostics $c
Assert-Cleanup ($d.Count -eq 0 -and $script:fileReads -eq 0 -and $script:storageReads -eq 0 -and $script:diagnosticProcesses -eq 0) 'Apply mode must not run report diagnostics.'
@@ -536,10 +550,10 @@ try {
switch ($ClassName) {
Win32_OperatingSystem { [pscustomobject]@{ProductType=1; Caption='Fixture Client'} }
Win32_UserProfile { [pscustomobject]@{Special=$false; LocalPath=(Join-Path $previewRoot 'Users\Alice')} }
Win32_Volume { [pscustomobject]@{DriveLetter=$env:SystemDrive; DeviceID='volume1'} }
Win32_Volume { [pscustomobject]@{DriveLetter=$env:SystemDrive; DeviceID='\\?\Volume{11111111-1111-1111-1111-111111111111}\'} }
Win32_ShadowCopy {
[pscustomobject]@{VolumeName='volume1'; InstallDate=[datetime]'2026-10-01'; ID='{11111111-1111-1111-1111-111111111111}'}
[pscustomobject]@{VolumeName='volume1'; InstallDate=[datetime]'2026-10-02'; ID='{22222222-2222-2222-2222-222222222222}'}
[pscustomobject]@{VolumeName='\\?\Volume{11111111-1111-1111-1111-111111111111}\'; InstallDate=[datetime]'2026-10-01'; ID='{11111111-1111-1111-1111-111111111111}'}
[pscustomobject]@{VolumeName='\\?\Volume{11111111-1111-1111-1111-111111111111}\'; InstallDate=[datetime]'2026-10-02'; ID='{22222222-2222-2222-2222-222222222222}'}
}
}
}
@@ -567,7 +581,7 @@ try {
}
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.'
Assert-Cleanup ($compactOutput -match 'Hibernation: .*file size' -and $compactOutput -match 'ShadowStorage:' -and $compactOutput -match 'ComponentStore: not analyzed;.*superseded updates.*substantial.*little/none') 'Full entry-point report must include usage and potential savings notes even with cleanup disabled.'
Assert-Cleanup ($compactOutput -match 'DisableHibernation\s+-\s+<0.01\s+file size' -and $compactOutput -match 'ShadowCopies\s+-\s+0.00\s+VSS used' -and $compactOutput -notmatch '\bHibernation:|ShadowStorage:' -and $compactOutput -match 'ComponentStore: not analyzed;.*superseded updates.*substantial.*little/none') 'Full entry-point report must show usage in category rows and retain the component note even with cleanup disabled.'
function Test-SystemCleanupAppRunning { return $true }
function Get-Command { return $null }
$o.DiskCleanupItems=@(); $o.DiskCleanupPreset='None'