Preserve cleanup previews and changed files
Windows tests / test-and-build (push) Canceled after 0s

This commit is contained in:
0x000 committed 2026-09-26 20:40:23 -04:00
1 parent 0274e7b398
commit b9a3308214
9 files changed
+93 -6

No files matched your search

+1 -1
View File
@@ -8,5 +8,5 @@ foreach ($file in $files) {
[System.Management.Automation.Language.Parser]::ParseFile($file.FullName,[ref]$tokens,[ref]$errors) | Out-Null
if ($errors.Count) {throw ($errors | Out-String)}
}
foreach ($suite in @('Run-Tests.ps1','Run-AppTests.ps1','Run-OfflineUpdateTests.ps1','Run-FeatureTests.ps1')) {& (Join-Path $PSScriptRoot $suite)}
foreach ($suite in @('Run-Tests.ps1','Run-AppTests.ps1','Run-OfflineUpdateTests.ps1','Run-FeatureTests.ps1','Run-CleanupTests.ps1')) {& (Join-Path $PSScriptRoot $suite)}
Write-Output 'All checks passed. No live policy or application mutations were performed.'
+70
View File
@@ -0,0 +1,70 @@
#Requires -Version 5.1
Set-StrictMode -Version Latest
$ErrorActionPreference='Stop'
$root=[IO.Path]::GetFullPath((Join-Path $PSScriptRoot '..'))
$scratch=Join-Path ([IO.Path]::GetTempPath()) ('ms-private-cleanup-test-'+[guid]::NewGuid().ToString('N'))
$module=Import-Module (Join-Path $root 'src/Wind.Cleanup.psm1') -Force -PassThru
$script:passed=0
function Assert-Cleanup([bool]$Condition,[string]$Message){if(-not$Condition){throw $Message};$script:passed++}
try{
$files=Join-Path $scratch 'files';[IO.Directory]::CreateDirectory($files)|Out-Null
# Replace only the catalog in this module instance: all deletions stay in this test's directory.
& $module {
param($TestRoot)
$script:cleanupTestRoot=$TestRoot
function script:Get-WindPrivacyCleanupCatalog {
[pscustomobject]@{Category='Temp';Root=$script:cleanupTestRoot;Patterns=@('*');Recurse=$true}
}
} $files
$file=Join-Path $files 'sample.txt';$report=Join-Path $scratch 'report.json'
function New-TestCleanupPlan {
[IO.File]::WriteAllText($file,'original')
[IO.File]::SetLastWriteTimeUtc($file,[DateTime]::UtcNow.AddDays(-30))
Get-WindCleanupPlan -AgeDays 7 -Category Temp
}
$plan=New-TestCleanupPlan
$result=Invoke-WindCleanup -Plan $plan -ReportPath $report -WhatIf
Assert-Cleanup ($result.Status-eq'Preview'-and(Test-Path -LiteralPath $file)-and-not(Test-Path -LiteralPath $report)) 'WhatIf changed files or wrote a cleanup report.'
$result=Invoke-WindCleanup -Plan $plan -ReportPath $report -Confirm:$false
Assert-Cleanup ($result.Deleted-eq1-and$result.FreedBytes-eq8-and-not(Test-Path -LiteralPath $file)) 'Unchanged planned file was not deleted and accounted for.'
$plan=New-TestCleanupPlan
[IO.File]::SetLastWriteTimeUtc($file,[DateTime]::UtcNow.AddDays(-20))
$result=Invoke-WindCleanup -Plan $plan -ReportPath $report -Confirm:$false
Assert-Cleanup ($result.Skipped-eq1-and$result.Deleted-eq0-and(Test-Path -LiteralPath $file)) 'File changed after planning was deleted because it was still older than the cutoff.'
$plan=New-TestCleanupPlan;$originalWrite=[IO.File]::GetLastWriteTimeUtc($file)
[IO.File]::WriteAllText($file,'different size');[IO.File]::SetLastWriteTimeUtc($file,$originalWrite)
$result=Invoke-WindCleanup -Plan $plan -ReportPath $report -Confirm:$false
Assert-Cleanup ($result.Skipped-eq1-and(Test-Path -LiteralPath $file)) 'Changed file size was ignored when the timestamp was preserved.'
$plan=New-TestCleanupPlan;$handle=[IO.File]::Open($file,[IO.FileMode]::Open,[IO.FileAccess]::ReadWrite,[IO.FileShare]::None)
try{$result=Invoke-WindCleanup -Plan $plan -ReportPath $report -Confirm:$false}finally{$handle.Dispose()}
Assert-Cleanup ($result.Skipped-eq1-and$result.Deleted-eq0-and(Test-Path -LiteralPath $file)) 'Locked file was not recorded as skipped.'
$plan=New-TestCleanupPlan;$plan.Files[0].LastWriteUtc='invalid'
$result=Invoke-WindCleanup -Plan $plan -ReportPath $report -Confirm:$false
Assert-Cleanup ($result.Skipped-eq1-and(Test-Path -LiteralPath $file)) 'Invalid planned timestamp did not preserve the file.'
# Exercise the real entry script with mock dependencies; never read or clear the real clipboard.
$wrapper=Join-Path $scratch 'wrapper';$src=Join-Path $wrapper 'src';[IO.Directory]::CreateDirectory($src)|Out-Null
Copy-Item -LiteralPath (Join-Path $root 'Cleanup.ps1') -Destination $wrapper
[IO.File]::WriteAllText((Join-Path $src 'Wind.Core.psm1'),'function Assert-WindMutationAllowed {}')
$mock=@'
function Get-WindCleanupPlan { [pscustomobject]@{Files=@()} }
function Invoke-WindCleanup { throw 'Unexpected cleanup mutation during WhatIf.' }
function Clear-WindCurrentClipboard { throw 'Unexpected clipboard mutation during WhatIf.' }
'@
[IO.File]::WriteAllText((Join-Path $src 'Wind.Cleanup.psm1'),$mock)
& (Join-Path $wrapper 'Cleanup.ps1') -Mode Run -ClearClipboard -WhatIf
Assert-Cleanup $true 'Cleanup entry script WhatIf did not return before mutations.'
}finally{
Remove-Module $module -ErrorAction SilentlyContinue
$resolved=[IO.Path]::GetFullPath($scratch)
$temp=[IO.Path]::GetFullPath([IO.Path]::GetTempPath()).TrimEnd('\')+'\'
if(-not$resolved.StartsWith($temp,[StringComparison]::OrdinalIgnoreCase)){throw 'Unsafe test cleanup directory.'}
if([IO.Directory]::Exists($resolved)){[IO.Directory]::Delete($resolved,$true)}
}
Write-Output "$script:passed cleanup tests passed. Only disposable files and a mocked clipboard were used."
+5
View File
@@ -87,6 +87,11 @@ $run=Invoke-MsPrivateGroupPlan -Groups $groups
Assert-True ($run.Status-eq'PartialFailure'-and($run.Entries | Where-Object { $_.Id -eq 'First' }).Status-eq'Failed') 'Operation runner did not record a failed group.'
Assert-True (($run.Entries | Where-Object { $_.Id -eq 'Dependent' }).Status-eq'SkippedDependency'-and$events-notcontains'dependent') 'Operation runner executed a blocked dependency.'
Assert-True (($run.Entries | Where-Object { $_.Id -eq 'Independent' }).Status-eq'Succeeded'-and$events-contains'independent') 'Operation runner did not continue with an independent group.'
$caseRun=Invoke-MsPrivateGroupPlan -Groups @(
[pscustomobject]@{Id='First';Label='First';DependsOn=@();Action={}},
[pscustomobject]@{Id='Second';Label='Second';DependsOn=@('first');Action={}}
)
Assert-True ($caseRun.Status-eq'Completed'-and$caseRun.Entries[1].Status-eq'Succeeded') 'A dependency accepted during validation was incorrectly skipped due to capitalization.'
$runReportRoot=Join-Path ([IO.Path]::GetTempPath()) ('ms-private-run-report-'+[guid]::NewGuid().ToString('N'))
try{
$runReportPath=Join-Path $runReportRoot 'run.json'