compact report output
This commit is contained in:
+57
-32
@@ -153,9 +153,10 @@ function Get-SystemCleanupOS {
|
||||
}
|
||||
|
||||
function Write-SystemCleanupMessage {
|
||||
param([string]$Message)
|
||||
param([string]$Message, [switch]$Detail)
|
||||
# Host/information stream keeps logs out of helper return values, even with Tools loaded.
|
||||
Write-Host "[SystemCleanup] $Message"
|
||||
if ($Detail) { Write-Verbose "[SystemCleanup] $Message" }
|
||||
else { Write-Host "[SystemCleanup] $Message" }
|
||||
}
|
||||
|
||||
function Test-SystemCleanupPath {
|
||||
@@ -263,21 +264,21 @@ function Invoke-SystemCleanupCategory {
|
||||
if ($blocked) {
|
||||
$Context.Stats[$Name].Status = 'Blocked on server'
|
||||
$Context.Stats[$Name].EstimateStatus = 'Not assessed'
|
||||
Write-SystemCleanupMessage "BLOCKED on server OS: $Name ($setting)"
|
||||
Write-SystemCleanupMessage "BLOCKED on server OS: $Name ($setting)" -Detail:$Context.Options.ReportOnly
|
||||
return
|
||||
}
|
||||
if ($Context.Options.ReportOnly) {
|
||||
if (-not $Context.ContainsKey('Candidates')) { $Context.Candidates = @{} }
|
||||
$Context.Candidates[$Name] = New-Object 'System.Collections.Generic.Dictionary[string,long]' ([StringComparer]::OrdinalIgnoreCase)
|
||||
$selection = if ($enabled) { 'enabled for apply' } else { 'disabled; assessment only' }
|
||||
Write-SystemCleanupMessage "Assessing $Name ($selection)."
|
||||
Write-SystemCleanupMessage "Assessing $Name ($selection)." -Detail
|
||||
}
|
||||
try { & $Action } catch {
|
||||
$Context.Stats[$Name].Status = 'Failed'
|
||||
$Context.Stats[$Name].EstimateStatus = 'Incomplete'
|
||||
$Context.Stats[$Name].Notes = $_.Exception.Message
|
||||
$Context.Errors++
|
||||
Write-SystemCleanupMessage "$Name failed: $($_.Exception.Message)"
|
||||
Write-SystemCleanupMessage "$Name failed: $($_.Exception.Message)" -Detail:$Context.Options.ReportOnly
|
||||
}
|
||||
if (-not $Context.Options.ReportOnly) {
|
||||
$s = $Context.Stats[$Name]
|
||||
@@ -291,7 +292,7 @@ function Set-SystemCleanupSkipped {
|
||||
$Context.Stats[$Category].Status = $Status
|
||||
$Context.Stats[$Category].EstimateStatus = 'Not assessed'
|
||||
$Context.Stats[$Category].Notes = $Reason
|
||||
Write-SystemCleanupMessage $Reason
|
||||
Write-SystemCleanupMessage $Reason -Detail:$Context.Options.ReportOnly
|
||||
}
|
||||
|
||||
function Get-SystemCleanupReportTotals {
|
||||
@@ -316,36 +317,55 @@ function Get-SystemCleanupReportTotals {
|
||||
|
||||
function Write-SystemCleanupReport {
|
||||
param($Context)
|
||||
Write-SystemCleanupMessage 'REPORT ONLY: no cleanup performed. Category estimates use the configured retention periods.'
|
||||
Write-SystemCleanupMessage 'REPORT ONLY - no cleanup performed.'
|
||||
$totals = Get-SystemCleanupReportTotals $Context
|
||||
Write-SystemCleanupMessage ('Known savings: ENABLED {0:N2} MiB ({1:N0} files); additional DISABLED {2:N2} MiB ({3:N0} files).' -f ($totals.EnabledBytes / 1MB), $totals.EnabledFiles, ($totals.AdditionalDisabledBytes / 1MB), $totals.AdditionalDisabledFiles)
|
||||
Write-SystemCleanupMessage "Retention: temp $($Context.Options.TempDays)d; diagnostics $($Context.Options.DiagnosticDays)d; backups $($Context.Options.BackupDays)d."
|
||||
Write-SystemCleanupMessage ('{0,-25} {1,8} {2,11} {3}' -f 'Category', 'Files', 'MiB', 'Notes')
|
||||
foreach ($group in @('Enabled', 'Disabled', 'Blocked')) {
|
||||
$rows = @($Context.Stats.Values | Where-Object {
|
||||
if ($group -eq 'Blocked') { $_.Status -eq 'Blocked on server' }
|
||||
else { $_.Status -ne 'Blocked on server' -and $_.Enabled -eq ($group -eq 'Enabled') }
|
||||
} | Sort-Object Category)
|
||||
$heading = switch ($group) {
|
||||
Enabled { 'ENABLED - eligible for cleanup when CleanupReportOnly=false, subject to the listed conditions' }
|
||||
Disabled { 'DISABLED - potential savings only; these categories will not run until enabled' }
|
||||
Blocked { 'BLOCKED ON SERVER - not assessed and cannot be enabled on this OS' }
|
||||
Enabled { 'ENABLED - would run with current settings' }
|
||||
Disabled { 'DISABLED - potential only; will not run' }
|
||||
Blocked { 'BLOCKED ON SERVER - cannot run' }
|
||||
}
|
||||
Write-SystemCleanupMessage $heading
|
||||
if (-not $rows.Count) { Write-SystemCleanupMessage ' None.' }
|
||||
foreach ($row in $rows) {
|
||||
$estimate = switch ($row.EstimateStatus) {
|
||||
'Not estimated' { 'space savings not estimated' }
|
||||
'Not assessed' { 'space savings not assessed' }
|
||||
default {
|
||||
if ($null -eq $row.CandidateBytes) { 'space savings unavailable' }
|
||||
else { '{0} eligible files / {1:N2} MiB' -f $row.CandidateFiles, ($row.CandidateBytes / 1MB) }
|
||||
}
|
||||
$files = '-'; $size = '-'; $notes = @()
|
||||
if ($row.EstimateStatus -eq 'Not estimated') { $notes += 'not estimated' }
|
||||
elseif ($row.EstimateStatus -eq 'Not assessed') { $notes += 'not assessed' }
|
||||
elseif ($null -ne $row.CandidateBytes) {
|
||||
$files = '{0:N0}' -f $row.CandidateFiles
|
||||
$size = if ($row.CandidateBytes -gt 0 -and $row.CandidateBytes -lt (0.01 * 1MB)) { '<0.01' } else { '{0:N2}' -f ($row.CandidateBytes / 1MB) }
|
||||
} else { $notes += 'unavailable' }
|
||||
if ($row.Status -notin @('Preview', 'Blocked on server')) { $notes += $row.Status }
|
||||
if ($row.EstimateStatus -eq 'Incomplete') { $notes += 'incomplete' }
|
||||
if ($row.FailedFiles) { $notes += "$($row.FailedFiles) files skipped" }
|
||||
if ($row.Category -eq 'DiskCleanup') {
|
||||
$notes += "$($Context.Options.DiskCleanupPreset) ($(@($Context.Options.DiskCleanupItems).Count) handlers)"
|
||||
if (-not $row.Enabled) { $notes += 'will not run' }
|
||||
# The selected handler list is configuration detail, not a warning.
|
||||
if ($row.Status -eq 'Failed') { $notes += $row.Notes }
|
||||
else { Write-SystemCleanupMessage "Disk Cleanup: $($row.Notes)" -Detail }
|
||||
} elseif ($row.Category -eq 'ComponentStore') {
|
||||
$notes += 'background task on apply'
|
||||
if ($row.Notes) { $notes += $row.Notes }
|
||||
} elseif ($row.Notes) { $notes += $row.Notes }
|
||||
# Keep every category on one line, including multiline native errors.
|
||||
$noteText = ($notes -join '; ') -replace '\s+', ' '
|
||||
if ($noteText.Length -gt 180) {
|
||||
Write-SystemCleanupMessage "$($row.Category): $noteText" -Detail
|
||||
$noteText = $noteText.Substring(0, 163) + '... (see verbose)'
|
||||
}
|
||||
if ($row.EstimateStatus -eq 'Incomplete') { $estimate += ' (incomplete assessment)' }
|
||||
Write-SystemCleanupMessage " $($row.Category) [$($row.Setting)]: $estimate; $($row.Status). $($row.Notes)"
|
||||
Write-SystemCleanupMessage ('{0,-25} {1,8} {2,11} {3}' -f $row.Category, $files, $size, $noteText.Trim())
|
||||
}
|
||||
}
|
||||
$totals = Get-SystemCleanupReportTotals $Context
|
||||
Write-SystemCleanupMessage ('Known unique file estimates in ENABLED categories: {0} files / {1:N2} MiB.' -f $totals.EnabledFiles, ($totals.EnabledBytes / 1MB))
|
||||
Write-SystemCleanupMessage ('Additional unique file estimates in DISABLED categories, beyond enabled categories: {0} files / {1:N2} MiB.' -f $totals.AdditionalDisabledFiles, ($totals.AdditionalDisabledBytes / 1MB))
|
||||
Write-SystemCleanupMessage 'Category estimates can overlap; the totals count each path once. Native savings and unassessed data are excluded; actual freed disk space may differ.'
|
||||
Write-SystemCleanupMessage 'Totals count each path once; rows may overlap. Unknown/unassessed savings excluded; disk space freed may differ.'
|
||||
Write-SystemCleanupMessage 'Settings: Cleanup<Category>; DiskCleanup uses CleanupDiskCleanupItems. Full diagnostics: $VerbosePreference="Continue".'
|
||||
}
|
||||
|
||||
function Test-SystemCleanupAppRunning {
|
||||
@@ -359,7 +379,7 @@ function Invoke-SystemCleanupProcess {
|
||||
$nativeDir = if ([Environment]::Is64BitOperatingSystem -and -not [Environment]::Is64BitProcess) { 'Sysnative' } else { 'System32' }
|
||||
$executable = Join-Path $env:SystemRoot "$nativeDir\$FileName"
|
||||
if (-not (Test-Path -LiteralPath $executable -PathType Leaf)) { throw "Unavailable: $executable" }
|
||||
Write-SystemCleanupMessage "$FileName $Arguments (native operation; size not estimated)"
|
||||
Write-SystemCleanupMessage "$FileName $Arguments (native operation; size not estimated)" -Detail:$Context.Options.ReportOnly
|
||||
if ($Context.Options.ReportOnly) { return }
|
||||
$process = Start-Process -FilePath $executable -ArgumentList $Arguments -WindowStyle Hidden -Wait -PassThru -ErrorAction Stop
|
||||
if ($process.ExitCode -ne 0) { throw "$FileName returned exit code $($process.ExitCode)." }
|
||||
@@ -473,10 +493,10 @@ function Invoke-SystemCleanupDiskCleanup {
|
||||
# Defence in depth: even direct helper calls cannot run cleanmgr on a server.
|
||||
if ($Context.OS.IsServer) { throw 'Disk Cleanup is blocked on server OSes.' }
|
||||
$selected = @($Context.Options.DiskCleanupItems)
|
||||
Write-SystemCleanupMessage "Disk Cleanup selection: $($Context.Options.DiskCleanupPreset); selected items: $($selected -join ', '). Windows controls retention for these handlers."
|
||||
Write-SystemCleanupMessage "Disk Cleanup selection: $($Context.Options.DiskCleanupPreset); selected items: $($selected -join ', '). Windows controls retention for these handlers." -Detail
|
||||
if ($Context.Options.ReportOnly) {
|
||||
$unselected = @((Get-SystemCleanupHandlers) | Where-Object { $_ -notin $selected })
|
||||
Write-SystemCleanupMessage "Disk Cleanup items not selected (not run during apply): $($unselected -join ', '). Handler savings are not estimated."
|
||||
Write-SystemCleanupMessage "Disk Cleanup items not selected (not run during apply): $($unselected -join ', '). Handler savings are not estimated." -Detail
|
||||
return
|
||||
}
|
||||
if (-not $selected.Count) { return }
|
||||
@@ -535,7 +555,7 @@ function Invoke-SystemCleanupSearchCompaction {
|
||||
if (-not (Test-Path -LiteralPath $database -PathType Leaf)) { return }
|
||||
if (-not (Test-SystemCleanupPath $database (Split-Path -Parent $database))) { return }
|
||||
if ($Context.Options.ReportOnly) {
|
||||
Write-SystemCleanupMessage "Would compact $database; size savings cannot be estimated."
|
||||
Write-SystemCleanupMessage "Would compact $database; size savings cannot be estimated." -Detail
|
||||
return
|
||||
}
|
||||
$drive = New-Object IO.DriveInfo ([IO.Path]::GetPathRoot($database))
|
||||
@@ -619,7 +639,10 @@ function Invoke-SystemCleanup {
|
||||
# Do not stop Windows servicing to reclaim a log. Remove only when already idle.
|
||||
if ($total -ge 200MB -and (Get-Service -Name TrustedInstaller -ErrorAction Stop).Status -eq 'Stopped') {
|
||||
Clear-SystemCleanupTree $context 'ActiveCBSLog' $cbs $diagnosticCutoff -Include @('CBS.log')
|
||||
} else { Write-SystemCleanupMessage 'Active CBS.log retained: servicing is active or archives total less than 200 MiB.' }
|
||||
} else {
|
||||
$context.Stats.ActiveCBSLog.Notes = 'Retained: servicing active or CBS archives below 200 MiB.'
|
||||
Write-SystemCleanupMessage 'Active CBS.log retained: servicing is active or archives total less than 200 MiB.' -Detail:$Options.ReportOnly
|
||||
}
|
||||
}
|
||||
Invoke-SystemCleanupCategory $context 'CBSArchives' {
|
||||
Clear-SystemCleanupTree $context 'CBSArchives' (Join-Path $env:SystemRoot 'Logs\CBS') $diagnosticCutoff -Include @('CbsPersist_*.log', 'CbsPersist_*.cab')
|
||||
@@ -686,7 +709,7 @@ function Invoke-SystemCleanup {
|
||||
$context.Stats.BrowserCache.Status = 'Partial'
|
||||
$context.Stats.BrowserCache.EstimateStatus = 'Incomplete'
|
||||
$context.Stats.BrowserCache.Notes += "$($browser.Name) is running; its cache was not assessed. "
|
||||
Write-SystemCleanupMessage "$($browser.Name) is running; its caches retained."
|
||||
Write-SystemCleanupMessage "$($browser.Name) is running; its caches retained." -Detail:$Options.ReportOnly
|
||||
continue
|
||||
}
|
||||
foreach ($profile in $profiles) {
|
||||
@@ -716,12 +739,12 @@ function Invoke-SystemCleanup {
|
||||
if ($Options.ReportOnly) { Set-SystemCleanupSkipped $context 'DeliveryOptimization' 'Delivery Optimization cmdlet is not installed.' -Status 'Unavailable'; return }
|
||||
throw 'Delivery Optimization cmdlet is not installed.'
|
||||
}
|
||||
Write-SystemCleanupMessage 'Delivery Optimization: unpinned cache only; size not estimated.'
|
||||
Write-SystemCleanupMessage 'Delivery Optimization: unpinned cache only; size not estimated.' -Detail:$Options.ReportOnly
|
||||
if (-not $Options.ReportOnly) { Delete-DeliveryOptimizationCache -Force -ErrorAction Stop }
|
||||
}
|
||||
Invoke-SystemCleanupCategory $context 'ComponentStore' {
|
||||
Invoke-SystemCleanupProcess $context 'schtasks.exe' '/Run /TN "\Microsoft\Windows\Servicing\StartComponentCleanup"'
|
||||
Write-SystemCleanupMessage 'Component cleanup runs asynchronously under Task Scheduler; completion and reclaimed bytes are not measured here.'
|
||||
Write-SystemCleanupMessage 'Component cleanup runs asynchronously under Task Scheduler; completion and reclaimed bytes are not measured here.' -Detail:$Options.ReportOnly
|
||||
}
|
||||
Invoke-SystemCleanupCategory $context 'DiskCleanup' { Invoke-SystemCleanupDiskCleanup $context }
|
||||
if ($Options.ReportOnly) { Write-SystemCleanupReport $context }
|
||||
@@ -734,4 +757,6 @@ function Invoke-SystemCleanup {
|
||||
}
|
||||
|
||||
# Read inherited caller variables before entering the implementation's local scope.
|
||||
Invoke-SystemCleanup -Options (Get-SystemCleanupOptions)
|
||||
# The function returns structured results for programmatic callers/tests. Do not
|
||||
# let PowerShell auto-format a second, much longer report in the RMM output.
|
||||
Invoke-SystemCleanup -Options (Get-SystemCleanupOptions) | Out-Null
|
||||
|
||||
+25
-7
@@ -30,8 +30,9 @@ use. The core does not need to download Tools.ps1 itself.
|
||||
|
||||
Run once with `CleanupReportOnly=true`, then set it to `false` to apply. Report
|
||||
mode assesses **all categories regardless of their enablement**, using the current
|
||||
retention settings. It leaves the enablement variables unchanged. The final report
|
||||
has three sections:
|
||||
retention settings. It leaves the enablement variables unchanged. The compact
|
||||
report starts with the unique enabled savings and additional disabled savings,
|
||||
then lists every category once in three sections:
|
||||
|
||||
- **Enabled:** eligible for cleanup on an apply run, subject to the reported conditions.
|
||||
- **Disabled:** potential savings only; these categories will not run during apply
|
||||
@@ -48,16 +49,31 @@ These category estimates can overlap (for example, a duplicate downloaded EXE).
|
||||
The enabled total counts each file path once. The disabled total shows additional
|
||||
unique file bytes beyond those already counted in enabled categories. Native
|
||||
operations such as Disk Cleanup, VSS, Search compaction, Delivery Optimization,
|
||||
component cleanup, and disabling hibernation say **not estimated**, not zero.
|
||||
Disk Cleanup also lists its preset (or custom list), expanded selected handlers,
|
||||
and unselected handlers without running them. `None` places Disk Cleanup in the
|
||||
Disabled section; the report still lists the unselected handlers. Servers always
|
||||
place it in the Blocked section, regardless of the preset.
|
||||
component cleanup, and disabling hibernation show `-` and **not estimated**, not
|
||||
zero. Disk Cleanup shows its preset (or Custom) and selected handler count.
|
||||
`None` places Disk Cleanup in the Disabled section. Servers always place it in
|
||||
the Blocked section, regardless of the preset.
|
||||
Skipped/unavailable categories say **not assessed**; failed or partially assessed
|
||||
categories are labeled incomplete. In-use application checks remain enforced, so
|
||||
close those applications and rerun to obtain their estimates. Unknown savings are
|
||||
excluded from the totals, and file sizes do not guarantee physical space savings.
|
||||
|
||||
The default output is designed for Syncro's limited script output: one line per
|
||||
category, including zero results, without a second PowerShell object dump or
|
||||
per-category progress chatter. Column sizes are in MiB; positive sizes below
|
||||
0.01 MiB display as `<0.01`. The group identifies whether a category is enabled;
|
||||
its variable is `Cleanup<Category>`, except Disk Cleanup uses
|
||||
`CleanupDiskCleanupItems`. Skip, failure, and partial-assessment reasons remain
|
||||
visible. Long diagnostic notes are shortened to one line.
|
||||
|
||||
To troubleshoot, set `$VerbosePreference = 'Continue'` in the caller before
|
||||
`Run-Script`. Verbose output includes progress, full diagnostic notes, and the
|
||||
selected/unselected Disk Cleanup handler lists; it can exceed Syncro's output
|
||||
limit, so use a local PowerShell capture when full detail is needed. No additional
|
||||
Syncro variable is required. The `Invoke-SystemCleanup` function still returns
|
||||
structured results for programmatic callers; the script entry suppresses their
|
||||
automatic formatting after printing the human-readable report.
|
||||
|
||||
Report mode does not delete files, change registry settings, stop services,
|
||||
launch maintenance programs, or request scheduled maintenance. Acquiring a named
|
||||
mutex prevents overlapping runs; the RMM bootstrap still downloads Tools/core
|
||||
@@ -213,6 +229,8 @@ Coverage includes disabled-category estimates, separate report groups, unique
|
||||
totals for overlapping categories, and disabled categories remaining untouched in
|
||||
apply mode. Preset tests verify exact handler membership, cumulative selections,
|
||||
RMM scope preservation, None disabling native work, and the server exclusions.
|
||||
Output tests cover the duplicate-object regression, a 22-category preview under
|
||||
4 KiB, separate enabled/disabled sections, and preservation of diagnostic notes.
|
||||
|
||||
References: [OS ProductType](https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/win32-operatingsystem),
|
||||
[Disk Cleanup](https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/cleanmgr),
|
||||
|
||||
@@ -39,6 +39,9 @@
|
||||
# The main script parses the injected strings and supplies defaults for absent variables.
|
||||
# Every variable configured in Syncro needs a nonempty value.
|
||||
# Report-only assesses enabled AND disabled categories in separate report sections.
|
||||
# Compact output shows totals first and one row per category; no duplicate object dump.
|
||||
# For full diagnostics, set $VerbosePreference = 'Continue' before Run-Script.
|
||||
# Verbose output can exceed Syncro's output limit. No new Syncro variables are needed.
|
||||
# Server-blocked categories are listed without assessment. Native savings may be unknown.
|
||||
# Server exclusions cannot be overridden by these variables. No reboot is initiated.
|
||||
|
||||
|
||||
@@ -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