Prepare ms-private 0.0.1 release candidate
This commit is contained in:
1 parent
7aacc0b63f
commit
a515538438
75 files changed
+3957
-3484
No files matched your search
+102
-5
@@ -3,6 +3,7 @@ Set-StrictMode -Version Latest
|
||||
$ErrorActionPreference='Stop'
|
||||
Import-Module (Join-Path $PSScriptRoot '../src/Wind.Apps.psm1') -Force
|
||||
Import-Module (Join-Path $PSScriptRoot '../src/Wind.Tui.psm1') -Force
|
||||
Import-Module (Join-Path $PSScriptRoot '../src/MsPrivate.Presets.psm1') -Force
|
||||
$script:passed=0
|
||||
function Assert-True { param([bool]$Condition,[string]$Message) if (-not $Condition) { throw $Message } }
|
||||
function Assert-Throws { param([scriptblock]$Action) $threw=$false; try { & $Action | Out-Null } catch { $threw=$true }; Assert-True $threw 'Expected an exception.' }
|
||||
@@ -37,6 +38,29 @@ Run-Test 'Personal app opt-in and bundled exclusions' {
|
||||
Assert-True (($plan | Where-Object Id -eq 'editor').Status -eq 'Remove') 'Personal selection ignored.'
|
||||
Assert-True (($plan | Where-Object Id -eq 'app-1').Status -eq 'Keep') 'Exclusion ignored.'
|
||||
}
|
||||
Run-Test 'Aggressive presets select removable personal apps and Store' {
|
||||
$store=New-App 'Microsoft.WindowsStore' 'Appx' 'store';$store.Protected=$true
|
||||
$apps=@((New-App 'PersonalEditor' 'Desktop' 'editor'),(New-App 'Microsoft.WindowsNotepad' 'Appx' 'notepad'),$store,(New-App 'Bitdefender' 'Desktop' 'security'),(New-App 'Microsoft Edge WebView2 Runtime' 'Desktop' 'webview'))
|
||||
$plan=@(Get-WindAppPlan -Inventory $apps -RemovePersonal -RemoveStore)
|
||||
Assert-True (($plan|Where-Object {$_.Id -eq 'editor'}).Status-eq'Remove') 'Aggressive plan kept a removable personal app.'
|
||||
Assert-True (($plan|Where-Object {$_.Id -eq 'store'}).Status-eq'Remove') 'Explicit Store removal was ignored.'
|
||||
Assert-True (($plan|Where-Object {$_.Id -eq 'notepad'}).Status-eq'Remove') 'Removable Microsoft.Windows app was overprotected.'
|
||||
Assert-True (@($plan|Where-Object{$_.Id-in@('security','webview')-and$_.Status-ne'Keep'}).Count-eq0) 'Aggressive plan selected a protected dependency or security product.'
|
||||
}
|
||||
Run-Test 'Aggressive presets skip ambiguous desktop registrations without blocking the run' {
|
||||
$apps=@(New-App 'Duplicate Tool' 'Desktop' 'dup-a';New-App 'Duplicate Tool' 'Desktop' 'dup-b')
|
||||
$plan=@(Get-WindAppPlan -Inventory $apps -RemovePersonal)
|
||||
Assert-True (@($plan|Where-Object {$_.Status -ne 'Keep'}).Count-eq0) 'An ambiguous automatic selection was left actionable.'
|
||||
Assert-True (@($plan|Where-Object {$_.Protected -and $_.Reason -like 'Skipped:*'}).Count-eq2) 'Ambiguous entries were not reported as protected skips.'
|
||||
}
|
||||
Run-Test 'Fresh Install and aggressive presets carry the complete destructive selection' {
|
||||
$catalog=Get-MsPrivatePresetCatalog
|
||||
foreach($id in @('FreshInstall','Medium','Strong','Maximum')){$p=Get-MsPrivatePreset $id;Assert-True ($p.RemovePersonal-and$p.RemoveStore-and$p.RemoveOneDrive-and$p.RemoveEdge-and$p.Recall-and$p.Accounts-and$p.Services) "Incomplete aggressive preset: $id"}
|
||||
Assert-True ((Get-MsPrivatePreset 'Maximum').Network-eq'Isolate') 'Maximum preset lacks timed network isolation.'
|
||||
Assert-True (@($catalog.Presets).Count-eq6) 'Unexpected preset count.'
|
||||
$safe=Get-MsPrivatePreset 'EstablishedSafe'
|
||||
Assert-True (-not$safe.Services-and-not$safe.Accounts-and-not$safe.RemoveBundled-and-not$safe.RemovePersonal-and-not$safe.RemoveStore-and-not$safe.RemoveOneDrive-and-not$safe.RemoveEdge-and-not$safe.Recall-and$safe.Network-eq'Observe'-and-not@($safe.Browsers).Count) 'EstablishedSafe selected a destructive or installation action.'
|
||||
}
|
||||
Run-Test 'Protected dependencies cannot be opted into removal' {
|
||||
foreach ($name in @('Microsoft Edge WebView2 Runtime','Microsoft.DesktopAppInstaller','Microsoft.WindowsStore','Microsoft.VCLibs.140.00','Bitdefender','Microsoft.GamingServices','NVIDIA Display Driver','Mullvad VPN','VeraCrypt')) {
|
||||
$app=New-App $name
|
||||
@@ -116,10 +140,83 @@ Run-Test 'Forged protected plan is rejected before any action' {
|
||||
Assert-Throws {Run-Changes $h}
|
||||
Assert-True ($h.State.Events.Count -eq 0) 'Forged plan executed.'
|
||||
}
|
||||
Run-Test 'Menu selection rejects invalid input and supports combinations' {
|
||||
Assert-True ((@(ConvertFrom-WindChoice '1,3,1' 3) -join ',') -eq '0,2') 'Multi-selection incorrect.'
|
||||
Assert-True (@(ConvertFrom-WindChoice 'none' 3).Count -eq 0) 'None incorrect.'
|
||||
Assert-True (@(ConvertFrom-WindChoice 'all' 3).Count -eq 3) 'All incorrect.'
|
||||
foreach ($bad in @('0','4','-1','1;whoami','1.5')) {Assert-Throws {ConvertFrom-WindChoice $bad 3}}
|
||||
Run-Test 'Arrow navigation wraps and Space toggles independently of Enter' {
|
||||
$items=@((New-WindMenuItem 'zen' 'Zen'),(New-WindMenuItem 'tor' 'Tor'))
|
||||
$s=New-WindMenuState @('zen')
|
||||
Update-WindMenuState $s $items 'UpArrow' -Multiple
|
||||
Assert-True ($s.Cursor -eq 1) 'Up did not wrap.'
|
||||
Update-WindMenuState $s $items 'Spacebar' -Multiple
|
||||
Assert-True ($s.Checked.Count -eq 2 -and $s.Action -eq '') 'Space accepted prematurely.'
|
||||
Update-WindMenuState $s $items 'Enter' -Multiple
|
||||
Assert-True ($s.Action -eq 'Accept') 'Enter did not accept.'
|
||||
Update-WindMenuState $s $items 'Escape' -Multiple
|
||||
Assert-True ($s.Action -eq 'Cancel') 'Escape did not cancel.'
|
||||
}
|
||||
Run-Test 'Filtering preserves checked apps and supports empty results' {
|
||||
$items=@((New-WindMenuItem 'zen' 'Zen'),(New-WindMenuItem 'tor' 'Tor'))
|
||||
$s=New-WindMenuState @('zen')
|
||||
Update-WindMenuState $s $items 'T' ([char]'t') -Multiple -Searchable
|
||||
Assert-True (@(Get-WindVisibleItems $items $s).Count -eq 1) 'Filter did not narrow list.'
|
||||
Update-WindMenuState $s $items 'Spacebar' -Multiple
|
||||
Assert-True ($s.Checked.Count -eq 2) 'Filter lost prior selections.'
|
||||
Update-WindMenuState $s $items 'X' ([char]'x') -Searchable
|
||||
Update-WindMenuState $s $items 'Enter'
|
||||
Assert-True ($s.Action -eq '') 'Empty result accepted.'
|
||||
Update-WindMenuState $s $items 'Backspace' -Searchable
|
||||
Assert-True ($s.Filter -eq 't') 'Backspace failed.'
|
||||
}
|
||||
Run-Test 'Protected display rows never toggle or activate' {
|
||||
$items=@(New-WindMenuItem 'protected' 'System component' '' $true);$s=New-WindMenuState
|
||||
Update-WindMenuState $s $items 'Spacebar' -Multiple
|
||||
Update-WindMenuState $s $items 'Enter'
|
||||
Assert-True ($s.Checked.Count -eq 0 -and $s.Action -eq '') 'Disabled item activated.'
|
||||
}
|
||||
Run-Test 'Frames fit small terminals and page long app lists' {
|
||||
$items=@(1..80 | ForEach-Object {New-WindMenuItem "app-$_" ('Long application name '+('x'*80)) ('Detailed information '*20)})
|
||||
$s=New-WindMenuState; $s.Cursor=79
|
||||
foreach ($width in @(40,80,120)) {
|
||||
$frame=@(Get-WindMenuFrame -Title 'Apps' -Subtitle 'Select' -Items $items -State $s -Width $width -Height 24 -Multiple -Searchable)
|
||||
Assert-True ($frame.Count -lt 24 -and @($frame | Where-Object {$_.Text.Length -ge $width}).Count -eq 0) 'Frame overflow.'
|
||||
Assert-True (@($frame | Where-Object Active).Count -eq 1) 'Focus lost off-page.'
|
||||
}
|
||||
}
|
||||
Run-Test 'Empty inventory can still install selected browsers' {
|
||||
$h=New-Harness @();$r=Run-Changes $h
|
||||
Assert-True ($r.Status -eq 'Completed' -and $h.State.Browser) 'Empty inventory broke install.'
|
||||
}
|
||||
Run-Test 'JSON catalogs flatten correctly in Windows PowerShell 5.1' {
|
||||
$browsers=@(Get-WindBrowserCatalog)
|
||||
Assert-True ($browsers.Count -eq 5 -and @($browsers | Where-Object Name -eq 'Zen').Count -eq 1) 'Nested catalog array.'
|
||||
}
|
||||
Run-Test 'Bundle parents suppress duplicate child app rows' {
|
||||
$packages=@([pscustomobject]@{PackageFamilyName='family';IsBundle=$true;Name='parent'},[pscustomobject]@{PackageFamilyName='family';IsBundle=$false;Name='child'},[pscustomobject]@{PackageFamilyName='other';IsBundle=$false;Name='single'})
|
||||
$parents=@(Select-WindAppxParents $packages)
|
||||
Assert-True ($parents.Count -eq 2 -and $parents.Name -notcontains 'child') 'Bundle child duplicated.'
|
||||
}
|
||||
Run-Test 'Journal callback resolves inside nested module scopes' {
|
||||
$root=[IO.Path]::GetFullPath((Join-Path $PSScriptRoot '..'))
|
||||
$path=Join-Path $root ('reports/scope-'+[guid]::NewGuid().ToString('N')+'.json')
|
||||
[IO.Directory]::CreateDirectory([IO.Path]::GetDirectoryName($path)) | Out-Null
|
||||
$nested=New-Module -ScriptBlock {}
|
||||
try {
|
||||
$h=New-Harness
|
||||
& $nested {
|
||||
param($Root,$Path,$Harness)
|
||||
Import-Module (Join-Path $Root 'src/Wind.Core.psm1')
|
||||
Import-Module (Join-Path $Root 'src/Wind.Apps.psm1')
|
||||
$writer=Get-Command Save-WindJournal -CommandType Function
|
||||
$save={param($report) & $writer -Journal $report -Path $Path}.GetNewClosure()
|
||||
Invoke-WindAppChanges -Plan $Harness.Plan -Backend $Harness.Backend -Save $save -Confirm:$false | Out-Null
|
||||
} $root $path $h
|
||||
Assert-True ((Get-Content -LiteralPath $path -Raw | ConvertFrom-Json).Status -eq 'Completed') 'Nested journal writer failed.'
|
||||
} finally {if ([IO.File]::Exists($path)) {[IO.File]::Delete($path)};Remove-Module $nested -ErrorAction SilentlyContinue}
|
||||
}
|
||||
Run-Test 'Group changes override prior group checkboxes while preserving personal choices' {
|
||||
$inventory=@((New-App),(New-App 'PersonalEditor' 'Desktop' 'editor'))
|
||||
$options=@{ExtraId=@('app-1','editor');ExcludeId=@();SkipBundled=$false;KeepOneDrive=$false;KeepEdge=$false}
|
||||
Set-WindRemovalGroups -Options $options -Inventory $inventory -Bundled $false -OneDrive $true -Edge $true
|
||||
$plan=@(Get-WindAppPlan -Inventory $inventory @options)
|
||||
Assert-True (($plan | Where-Object Id -eq 'app-1').Status -eq 'Keep') 'Group removal toggle ignored.'
|
||||
Assert-True (($plan | Where-Object Id -eq 'editor').Status -eq 'Remove') 'Personal choice lost.'
|
||||
}
|
||||
Write-Output "$script:passed app/menu tests passed. Only synthetic inventories and backends were used."
|
||||
Reference in new issue
Block a user