diff --git a/Tests/FeatureParameterContracts.Tests.ps1 b/Tests/FeatureParameterContracts.Tests.ps1 index 167f354..49a4910 100644 --- a/Tests/FeatureParameterContracts.Tests.ps1 +++ b/Tests/FeatureParameterContracts.Tests.ps1 @@ -30,13 +30,6 @@ Describe 'FeatureId parameter contracts' { $missing | Should -HaveCount 0 -Because ($missing -join ', ') } - It 'declares every FeatureId as a parameter on Scripts/Get.ps1' { - $parameterNames = Get-ScriptParameterNames -Path $script:GetScriptPath - $missing = @($script:Features.FeatureId | Where-Object { $parameterNames -notcontains $_ }) - - $missing | Should -HaveCount 0 -Because ($missing -join ', ') - } - It 'keeps Scripts/Get.ps1 aligned with Win11Debloat.ps1 plus launcher-only switches' { $win11DebloatParameters = Get-ScriptParameterNames -Path $script:Win11DebloatPath $getParameters = Get-ScriptParameterNames -Path $script:GetScriptPath diff --git a/Tests/Import-JsonFile.Tests.ps1 b/Tests/Import-JsonFile.Tests.ps1 index fe26273..8e37862 100644 --- a/Tests/Import-JsonFile.Tests.ps1 +++ b/Tests/Import-JsonFile.Tests.ps1 @@ -15,16 +15,23 @@ Describe 'Import-JsonFile' { $result.Name | Should -Be 'Example configuration' } - It 'parses the settings fixture' -ForEach @( - @{ Kind = 'default'; FileName = 'DefaultSettings.Valid.json' } - @{ Kind = 'last-used'; FileName = 'LastUsedSettings.Valid.json' } - ) { - $result = Import-JsonFile -filePath (Join-Path $script:FixturePath $FileName) -expectedVersion '1.0' + It 'parses the default settings fixture' { + $result = Import-JsonFile -filePath (Join-Path $script:FixturePath 'DefaultSettings.Valid.json') -expectedVersion '1.0' $result.Settings | Should -Not -BeNullOrEmpty $result.Settings[0].Name | Should -Be 'Supported' } + It 'parses a single last-used setting and preserves its Boolean value' { + $result = Import-JsonFile -filePath (Join-Path $script:FixturePath 'LastUsedSettings.Valid.json') -expectedVersion '1.0' + + $result.Settings | Should -HaveCount 1 + $result.Settings[0].Name | Should -Be 'Supported' + $result.Settings[0].Value | Should -BeOfType ([bool]) + $result.Settings[0].Value | Should -BeTrue + Should -Invoke Write-Error -Times 0 -Exactly + } + It 'returns null and reports an error for ' -ForEach @( @{ Case = 'a version mismatch'; FileName = 'Config.VersionMismatch.json'; ExpectedVersion = '1.0'; Optional = $false; Error = 'version mismatch' } @{ Case = 'invalid JSON'; FileName = 'Config.Invalid.json'; ExpectedVersion = $null; Optional = $false; Error = 'Failed to parse JSON file' } diff --git a/Tests/Invoke-Changes.Tests.ps1 b/Tests/Invoke-Changes.Tests.ps1 index c20c9e1..7f4ae61 100644 --- a/Tests/Invoke-Changes.Tests.ps1 +++ b/Tests/Invoke-Changes.Tests.ps1 @@ -106,6 +106,7 @@ Describe 'Invoke-FeatureApply' { Mock Get-Process { @() } Mock Stop-Process { param($InputObject) } Mock Write-Host {} + Mock Write-Warning {} } It 'imports a registry-backed feature' { @@ -164,7 +165,6 @@ Describe 'Invoke-FeatureApply' { It 'returns false when applying a feature throws' { Mock Invoke-ForceRemoveEdge { throw 'access denied' } - Mock Write-Warning {} Invoke-FeatureApply -FeatureId 'ForceRemoveEdge' | Should -BeFalse @@ -172,8 +172,6 @@ Describe 'Invoke-FeatureApply' { } It 'returns false for an unknown feature' { - Mock Write-Warning {} - Invoke-FeatureApply -FeatureId 'Unknown' | Should -BeFalse Should -Invoke Write-Warning -Times 1 -Exactly -ParameterFilter { $Message -match "Unknown feature 'Unknown'.*could not be applied" } @@ -195,21 +193,16 @@ Describe 'Invoke-FeatureApply' { Should -Invoke Stop-Process -Times 0 -Exactly } - It 'stops widget processes before removing widget packages' { - $widget = [PSCustomObject]@{ Name = 'WidgetService' } - Mock Get-Process { $widget } - - Invoke-FeatureApply -FeatureId 'DisableWidgets' - - Should -Invoke Stop-Process -Times 1 -Exactly - } - - It 'stops widget processes without a confirmation prompt' { + It 'stops widget processes without a confirmation prompt before removing widget packages' { + $calls = [System.Collections.Generic.List[string]]::new() Mock Get-Process { [PSCustomObject]@{ Name = 'Widgets' } } + Mock Stop-Process { $calls.Add('Stop') } + Mock Remove-SelectedApps { $calls.Add('Remove'); $true } Invoke-FeatureApply -FeatureId 'DisableWidgets' Should -Invoke Stop-Process -Times 1 -Exactly -ParameterFilter { $Force -and $ErrorAction -eq 'SilentlyContinue' } + @($calls) | Should -Be @('Stop', 'Remove') } It 'enables the expected optional Windows features' { @@ -535,7 +528,6 @@ Describe 'Invoke-AllChanges' { $script:Params = @{ CustomApply = $true } $script:UndoParams = @{} Mock Invoke-ApplyFeatures { $script:AppRemovalVerificationUnavailable = $true } - Mock Write-Warning {} Invoke-AllChanges diff --git a/Tests/Invoke-NonBlocking.Tests.ps1 b/Tests/Invoke-NonBlocking.Tests.ps1 index 10b737c..c22da10 100644 --- a/Tests/Invoke-NonBlocking.Tests.ps1 +++ b/Tests/Invoke-NonBlocking.Tests.ps1 @@ -15,11 +15,6 @@ Describe 'Invoke-NonBlocking' { $result | Should -Be @(1, 2, 3) } - It 'stops a timed CLI operation and reports a timeout' { - { Invoke-NonBlocking -ScriptBlock { Start-Sleep -Seconds 3 } -TimeoutSeconds 1 } | - Should -Throw 'Operation timed out after 1 seconds' - } - It 'stops a timed GUI operation and reports a timeout' { $script:GuiWindow = [PSCustomObject]@{} Mock Invoke-DoEvents {} @@ -30,11 +25,23 @@ Describe 'Invoke-NonBlocking' { It 'uses a runspace and pumps UI events when a GUI window is present' { $script:GuiWindow = [PSCustomObject]@{} - Mock Invoke-DoEvents {} + $gate = [System.Threading.ManualResetEventSlim]::new($false) + Mock Invoke-DoEvents { $gate.Set() } - $result = Invoke-NonBlocking -ScriptBlock { 'done' } - $result | Should -Be 'done' + try { + $result = Invoke-NonBlocking -ScriptBlock { + param($Event) + if (-not $Event.Wait(5000)) { throw 'UI events were not pumped' } + [System.Threading.Thread]::CurrentThread.ManagedThreadId + } -ArgumentList @($gate) -TimeoutSeconds 5 + $result | Should -BeOfType ([int]) + $result | Should -Not -Be ([System.Threading.Thread]::CurrentThread.ManagedThreadId) + Should -Invoke Invoke-DoEvents -Times 1 + } + finally { + $gate.Dispose() + } } It 'surfaces non-terminating errors from a runspace' { @@ -47,10 +54,10 @@ Describe 'Invoke-NonBlocking' { Should -Invoke Write-Error -Times 1 -Exactly -ParameterFilter { $ErrorRecord.Exception.Message -match 'runspace failure' } } - It 'remains usable after a timed operation is stopped' { + It 'stops a timed CLI operation, reports a timeout, and remains usable afterward' { { Invoke-NonBlocking -ScriptBlock { Start-Sleep -Seconds 3 } -TimeoutSeconds 1 } | Should -Throw 'Operation timed out after 1 seconds' - Invoke-NonBlocking -ScriptBlock { 'next operation' } | Should -Be 'next operation' + Invoke-NonBlocking -ScriptBlock { 'next operation' } -TimeoutSeconds 5 | Should -Be 'next operation' } } diff --git a/Tests/Invoke-SystemRestorePoint.Tests.ps1 b/Tests/Invoke-SystemRestorePoint.Tests.ps1 index 664d1bd..eac190b 100644 --- a/Tests/Invoke-SystemRestorePoint.Tests.ps1 +++ b/Tests/Invoke-SystemRestorePoint.Tests.ps1 @@ -56,7 +56,6 @@ Describe 'Invoke-SystemRestorePoint' { $expectedImport = [regex]::Escape('Scripts/Features/Invoke-SystemRestorePoint.ps1') $entryPoint | Should -Match $expectedImport - Get-Command Invoke-SystemRestorePoint | Should -Not -BeNullOrEmpty } It 'enables disabled System Restore before creating the point in silent mode' { diff --git a/Tests/MainWindow-AppSelection.Tests.ps1 b/Tests/MainWindow-AppSelection.Tests.ps1 index 415ac21..e7ee2d0 100644 --- a/Tests/MainWindow-AppSelection.Tests.ps1 +++ b/Tests/MainWindow-AppSelection.Tests.ps1 @@ -163,19 +163,6 @@ Describe 'Get-PendingTweakActions' { $map['DisableTelemetryCheckBox'].DesiredValue | Should -BeTrue } - It 'matches a mapping whose CategoryId fell back to its Name, for a category missing CategoryId' { - $window = New-TestWindow - $checkBox = New-Object System.Windows.Controls.CheckBox - $checkBox.Visibility = 'Visible' - $window.RegisterName('LegacyCheckBox', $checkBox) - # New-DynamicTweakControls falls back to Name when a category has no CategoryId of its own. - $script:UiControlMappings = @{ LegacyCheckBox = [PSCustomObject]@{ CategoryId = 'Legacy Category'; Type = 'feature'; FeatureId = 'SomeFeature' } } - - $map = Get-CategoryTweakPresetMap -Window $window -CategoryId 'Legacy Category' - - $map['LegacyCheckBox'].ControlType | Should -Be 'CheckBox' - } - It 'updates navigation visibility and progress indicators for an interior tab' { $window = New-TestWindow $tabControl = New-Object System.Windows.Controls.TabControl @@ -250,6 +237,7 @@ Describe 'Get-AppRemovalScopeTarget' { } It 'returns null for an unrecognized ComboBoxItem Name' { + Mock Write-Warning {} $combo = New-Object System.Windows.Controls.ComboBox $item = New-Object System.Windows.Controls.ComboBoxItem $item.Name = 'SomeUnrelatedControl' diff --git a/Tests/MainWindow-Localization.Tests.ps1 b/Tests/MainWindow-Localization.Tests.ps1 index 2bdfe4d..ed57981 100644 --- a/Tests/MainWindow-Localization.Tests.ps1 +++ b/Tests/MainWindow-Localization.Tests.ps1 @@ -43,6 +43,30 @@ BeforeAll { } } +Describe 'Legacy tweak categories' { + It 'uses the category Name as CategoryId when building controls without a CategoryId' { + $script:Lang = Import-LanguageFile -LanguageCode 'en-US' + $feature = $script:Features['DisableTelemetry'] | Select-Object * + $feature.Category = 'Legacy Category' + $legacyCatalog = [PSCustomObject]@{ + Categories = @([PSCustomObject]@{ Name = 'Legacy Category'; Icon = '' }) + Features = @($feature) + } + Mock Import-JsonFile { $legacyCatalog } -ParameterFilter { $filePath -eq $script:FeaturesFilePath } + $window = New-LanguageTestWindow + + New-DynamicTweakControls -Window $window -WinVersion 26100 + + $controlName = 'Feature_DisableTelemetry_Combo' + $script:UiControlMappings.Count | Should -Be 1 + $script:UiControlMappings[$controlName].CategoryId | Should -Be 'Legacy Category' + $map = Get-CategoryTweakPresetMap -Window $window -CategoryId 'Legacy Category' + $map.Count | Should -Be 1 + $map[$controlName].Control | Should -Be ($window.FindName($controlName)) + $map[$controlName].DesiredValue | Should -BeTrue + } +} + Describe 'Language changes on existing controls' { BeforeEach { $script:Lang = Import-LanguageFile -LanguageCode 'en-US' diff --git a/Tests/Registry-BackupDeletion.Tests.ps1 b/Tests/Registry-BackupDeletion.Tests.ps1 index 9b98de3..517c2ac 100644 --- a/Tests/Registry-BackupDeletion.Tests.ps1 +++ b/Tests/Registry-BackupDeletion.Tests.ps1 @@ -231,6 +231,7 @@ Describe 'Registry backup deletion permissions' { Describe 'Executable registry backup values' { BeforeEach { + Mock Write-Host {} $script:Params = @{} $script:RegfilesPath = Join-Path $PSScriptRoot '..\Regfiles' $script:Features = @{} @@ -638,6 +639,7 @@ Describe 'Executable registry restore confirmation' { $script:Features = @{} foreach ($feature in $script:FeatureCatalog.Features) { $script:Features[$feature.FeatureId] = $feature } Mock Write-Error {} + Mock Write-Host {} Mock Restore-RegistryKeySnapshot {} Mock Invoke-WithLoadedRestoreHive { param($Target, $ScriptBlock, $ArgumentObject) @@ -678,7 +680,6 @@ Describe 'Executable registry restore confirmation' { @{ Response = $null } @{ Response = 'true' } ) { - Mock Write-Host {} $backup = New-ExecutableTestBackup (Restore-RegistryBackupState -Backup $backup -ConfirmUntrustedValues { $Response }).Result | Should -BeFalse Should -Invoke Write-Host -Times 1 -Exactly -ParameterFilter { $Object -like 'Registry restore canceled:*' } @@ -687,7 +688,6 @@ Describe 'Executable registry restore confirmation' { } It 'shows all mismatches before writes and restores only after explicit approval' { - Mock Write-Host {} $backup = New-ExecutableTestBackup $backup.RegistryKeys += (New-ExecutableTestBackup -Path 'HKEY_CLASSES_ROOT\ms-gamebarservices\shell\open\command' -Data 'custom.exe').RegistryKeys $script:confirmationCount = 0 diff --git a/Tests/Registry-BackupValidation.Tests.ps1 b/Tests/Registry-BackupValidation.Tests.ps1 index f2ca823..b6ca744 100644 --- a/Tests/Registry-BackupValidation.Tests.ps1 +++ b/Tests/Registry-BackupValidation.Tests.ps1 @@ -100,26 +100,6 @@ Describe 'Get-SelectedRegistryFeaturesForBackupValidation' { } } -Describe 'Test-RegistryValueKindNameSupported' { - It 'accepts supported registry value kind ' -ForEach @( - @{ KindName = 'dword' } - @{ KindName = 'QWord' } - @{ KindName = 'MultiString' } - ) { - Test-RegistryValueKindNameSupported -KindName $KindName | Should -BeTrue - } - - It 'rejects ' -ForEach @( - @{ Case = 'a null kind name'; KindName = $null } - @{ Case = 'an empty kind name'; KindName = '' } - @{ Case = 'the Unknown registry kind'; KindName = 'Unknown' } - @{ Case = 'the unsupported None registry kind'; KindName = 'None' } - @{ Case = 'an invalid registry kind name'; KindName = 'NotARegistryValueKind' } - ) { - Test-RegistryValueKindNameSupported -KindName $KindName | Should -BeFalse - } -} - Describe 'Test-RegistryValueDataMatchesKind' { It 'accepts ' -ForEach @( @{ Case = 'the largest DWord'; Kind = 'DWord'; Data = [uint32]::MaxValue } @@ -156,11 +136,11 @@ Describe 'Get-NormalizedRegistryValueName' { } Describe 'Test-RegistryValueKindNameSupported' { - It 'rejects unsupported kind ' -ForEach @('99', '-2', 'Unknown', 'None', '') { + It 'rejects unsupported kind ' -ForEach @('99', '-2', 'Unknown', 'None', '', $null, 'NotARegistryValueKind') { Test-RegistryValueKindNameSupported -KindName $_ | Should -BeFalse } - It 'accepts defined kind ' -ForEach @('String', 'expandstring', 'Binary', 'DWord', 'QWord', 'MultiString', '1') { + It 'accepts defined kind ' -ForEach @('String', 'expandstring', 'Binary', 'DWord', 'dword', 'QWord', 'MultiString', '1') { Test-RegistryValueKindNameSupported -KindName $_ | Should -BeTrue } } diff --git a/Tests/Remove-SelectedApps.Tests.ps1 b/Tests/Remove-SelectedApps.Tests.ps1 index 785a7d2..2cde2c4 100644 --- a/Tests/Remove-SelectedApps.Tests.ps1 +++ b/Tests/Remove-SelectedApps.Tests.ps1 @@ -370,7 +370,7 @@ Describe 'Remove-AppxApp' { Mock Invoke-NonBlocking { param($ScriptBlock, $ArgumentList) & $ScriptBlock @ArgumentList } Mock Get-AppxPackage { Write-Error 'access denied' } - Remove-AppxApp -app 'One.App' -targetUser 'CurrentUser' | Should -BeFalse + Remove-AppxApp -app 'One.App' -targetUser 'CurrentUser' 2>$null | Should -BeFalse } It 'returns false when package removal reports a non-terminating error' { @@ -378,7 +378,7 @@ Describe 'Remove-AppxApp' { Mock Get-AppxPackage { [PSCustomObject]@{ PackageFullName = 'One.App_1.0' } } Mock Remove-AppxPackage { Write-Error 'access denied' } - Remove-AppxApp -app 'One.App' -targetUser 'CurrentUser' | Should -BeFalse + Remove-AppxApp -app 'One.App' -targetUser 'CurrentUser' 2>$null | Should -BeFalse } It 'returns false and reports a terminating Appx failure' { diff --git a/Tests/Replace-StartMenu.Tests.ps1 b/Tests/Replace-StartMenu.Tests.ps1 index 593e1d8..390dde0 100644 --- a/Tests/Replace-StartMenu.Tests.ps1 +++ b/Tests/Replace-StartMenu.Tests.ps1 @@ -10,6 +10,7 @@ BeforeAll { Describe 'Get-StartMenuUserNameFromPath' { BeforeEach { + Mock Write-Host {} # Restore copies are named to the second; clear them so tests sharing $TestDrive cannot see each other's copy Get-ChildItem -LiteralPath $TestDrive -Filter 'Win11Debloat-StartRestore-*.bak' | Remove-Item -Force } diff --git a/Tests/Show-ImportExportConfigWindow.Tests.ps1 b/Tests/Show-ImportExportConfigWindow.Tests.ps1 index 7687b72..4520351 100644 --- a/Tests/Show-ImportExportConfigWindow.Tests.ps1 +++ b/Tests/Show-ImportExportConfigWindow.Tests.ps1 @@ -165,14 +165,6 @@ Describe 'Get-DeploymentCategoryDetailString' { Get-DeploymentCategoryDetailString -DeploymentSettings $settings | Should -Not -Match 'ImportExportOptionRegistryBackup' } -} - -Describe 'Get-DeploymentCategoryDetailString with unsupported values' { - BeforeEach { - $warnings = [System.Collections.Generic.List[string]]::new() - Mock Write-Warning { $warnings.Add([string]$Message) } - } - It 'does not list the registry backup for an unsupported SkipRegistryBackup value, and does not warn' { $settings = @([PSCustomObject]@{ Name = 'SkipRegistryBackup'; Value = 'yes' }) @@ -180,11 +172,9 @@ Describe 'Get-DeploymentCategoryDetailString with unsupported values' { $warnings | Should -HaveCount 0 } - It 'lists the registry backup when SkipRegistryBackup is false or missing' -ForEach @( - @{ Settings = @([PSCustomObject]@{ Name = 'SkipRegistryBackup'; Value = $false }) } - @{ Settings = @([PSCustomObject]@{ Name = 'SkipRegistryBackup'; Value = 'false' }) } - @{ Settings = @([PSCustomObject]@{ Name = 'RestartExplorer'; Value = $true }) } - ) { - Get-DeploymentCategoryDetailString -DeploymentSettings $Settings | Should -Match 'ImportExportOptionRegistryBackup' + It 'lists the registry backup when SkipRegistryBackup is missing' { + $settings = @([PSCustomObject]@{ Name = 'RestartExplorer'; Value = $true }) + + Get-DeploymentCategoryDetailString -DeploymentSettings $settings | Should -Match 'ImportExportOptionRegistryBackup' } } diff --git a/Tests/Telemetry-ScheduledTasks.Tests.ps1 b/Tests/Telemetry-ScheduledTasks.Tests.ps1 index 2375fad..4728e95 100644 --- a/Tests/Telemetry-ScheduledTasks.Tests.ps1 +++ b/Tests/Telemetry-ScheduledTasks.Tests.ps1 @@ -34,6 +34,7 @@ Describe 'Disable-TelemetryScheduledTasks' { } Mock Invoke-NonBlocking { @{ Success = $true; Status = 'Disabled' } } Mock Write-Host {} + Mock Write-Warning {} } It 'dispatches every task to the non-blocking scheduler' { @@ -175,7 +176,6 @@ Describe 'Disable-TelemetryScheduledTasks' { It 'returns false for an unknown scheduler result' { Mock Get-TelemetryScheduledTasks { @(@{ Path = '\Microsoft\Windows\Test\'; Name = 'Telemetry' }) } Mock Invoke-NonBlocking { $null } - Mock Write-Warning {} Disable-TelemetryScheduledTasks | Should -BeFalse Should -Invoke Write-Warning -Times 1 -Exactly @@ -194,6 +194,7 @@ Describe 'Enable-TelemetryScheduledTasks' { } Mock Invoke-NonBlocking { @{ Success = $true; Status = 'Enabled' } } Mock Write-Host {} + Mock Write-Warning {} } It 'dispatches every task to the non-blocking scheduler' { @@ -305,7 +306,6 @@ Describe 'Enable-TelemetryScheduledTasks' { It 'returns false when the scheduler throws' { Mock Get-TelemetryScheduledTasks { @(@{ Path = '\Microsoft\Windows\Test\'; Name = 'Telemetry' }) } Mock Invoke-NonBlocking { throw 'scheduler unavailable' } - Mock Write-Warning {} Enable-TelemetryScheduledTasks | Should -BeFalse Should -Invoke Write-Warning -Times 1 -Exactly -ParameterFilter { $Message -match 'scheduler unavailable' } diff --git a/Tests/Windows-OptionalFeatures.Tests.ps1 b/Tests/Windows-OptionalFeatures.Tests.ps1 index 551733d..166cf2a 100644 --- a/Tests/Windows-OptionalFeatures.Tests.ps1 +++ b/Tests/Windows-OptionalFeatures.Tests.ps1 @@ -22,6 +22,7 @@ BeforeAll { Describe 'Enable-WindowsFeature' { BeforeEach { + Mock Write-Warning {} $script:Params = @{} Mock Invoke-NonBlocking { [PSCustomObject]@{ Success = $true; Output = $null; Error = $null } } Mock Write-Host {} @@ -65,7 +66,6 @@ Describe 'Enable-WindowsFeature' { It 'reports the worker error and returns false' { Mock Invoke-NonBlocking { [PSCustomObject]@{ Success = $false; Output = $null; Error = 'feature servicing failed' } } - Mock Write-Warning {} Enable-WindowsFeature -FeatureName 'Feature.One' | Should -BeFalse @@ -96,6 +96,7 @@ Describe 'Enable-WindowsFeature' { Describe 'Disable-WindowsFeature' { BeforeEach { + Mock Write-Warning {} $script:Params = @{} Mock Invoke-NonBlocking { [PSCustomObject]@{ Success = $true; Output = $null; Error = $null } } Mock Write-Host {} @@ -139,7 +140,6 @@ Describe 'Disable-WindowsFeature' { It 'reports the worker error and returns false' { Mock Invoke-NonBlocking { [PSCustomObject]@{ Success = $false; Output = $null; Error = 'feature servicing failed' } } - Mock Write-Warning {} Disable-WindowsFeature -FeatureName 'Feature.One' | Should -BeFalse