fix: skip features that the running Windows build does not support (#832)

This commit is contained in:
HetCreep
2026-10-18 22:23:18 +02:00
committed by GitHub
parent 94dd603da4
commit 73834839ff
13 changed files with 240 additions and 5 deletions
+1
View File
@@ -2,6 +2,7 @@ BeforeAll {
. (Join-Path $PSScriptRoot '..\Scripts\FileIO\Import-JsonFile.ps1')
. (Join-Path $PSScriptRoot '..\Scripts\FileIO\Import-LanguageFile.ps1')
. (Join-Path $PSScriptRoot '..\Scripts\Helpers\Add-Parameter.ps1')
. (Join-Path $PSScriptRoot '..\Scripts\Helpers\Windows-BuildHelpers.ps1')
. (Join-Path $PSScriptRoot '..\Scripts\Helpers\Import-ConfigToParams.ps1')
. (Join-Path $PSScriptRoot '..\Scripts\Helpers\Test-ConfigConsistency.ps1')
$script:ConfigFixturePath = Join-Path $PSScriptRoot 'TestData\JsonFileLoading\ExportedConfig.WithSettings.json'
+119
View File
@@ -21,6 +21,8 @@ BeforeAll {
function Set-StoreSearchSuggestionsDisabled { param($StoreAppsDatabase) $true }
. (Join-Path $PSScriptRoot '..\Scripts\FileIO\Import-LanguageFile.ps1')
. (Join-Path $PSScriptRoot '..\Scripts\Helpers\Windows-BuildHelpers.ps1')
. (Join-Path $PSScriptRoot '..\Scripts\Helpers\Get-RebootFeatureLabels.ps1')
. (Join-Path $PSScriptRoot '..\Scripts\Features\Invoke-Changes.ps1')
# Builds a $script:Lang fixture whose Features section mirrors $script:Features exactly,
@@ -425,6 +427,7 @@ Describe 'Invoke-AllChanges' {
$script:CancelRequested = $false
$script:ApplyProgressCallback = $null
Mock Test-RunningAsSystem { $false }
Mock Get-CurrentWindowsBuild { 26100 }
Mock Resolve-UndoRegFilePath { param($FileName) "Undo\$FileName" }
Mock New-RegistrySettingsBackup {}
Mock Invoke-SystemRestorePoint { $true }
@@ -540,3 +543,119 @@ Describe 'Invoke-AllChanges' {
}
}
Describe 'Invoke-AllChanges build gate' {
BeforeEach {
$script:Params = @{ Modern = $true; Legacy = $true; Anyone = $true }
$script:UndoParams = @{ ModernUndo = $true }
$script:ControlParams = @('WhatIf', 'Silent', 'User', 'Sysprep')
$script:Features = @{
Modern = [PSCustomObject]@{ RegistryKey = 'modern.reg'; MinVersion = 22621; MaxVersion = $null }
Legacy = [PSCustomObject]@{ RegistryKey = 'legacy.reg'; MinVersion = $null; MaxVersion = 21999 }
Anyone = [PSCustomObject]@{ RegistryKey = 'anyone.reg' }
ModernUndo = [PSCustomObject]@{ RegistryUndoKey = 'undo.reg'; MinVersion = 22621; MaxVersion = $null }
}
$script:CancelRequested = $false
$script:ApplyProgressCallback = $null
$warnings = [System.Collections.Generic.List[string]]::new()
Mock Test-RunningAsSystem { $false }
Mock Resolve-UndoRegFilePath { param($FileName) "Undo\$FileName" }
Mock New-RegistrySettingsBackup {}
Mock Invoke-SystemRestorePoint { $true }
Mock Invoke-ApplyFeatures {}
Mock Invoke-UndoFeatures {}
Mock Write-Host {}
Mock Write-Warning { $warnings.Add([string]$Message) }
}
It 'skips features that need a newer build and keeps the rest' {
Mock Get-CurrentWindowsBuild { 19045 }
Invoke-AllChanges
Should -Invoke Invoke-ApplyFeatures -Times 1 -Exactly -ParameterFilter {
@($FeatureIds).Count -eq 2 -and $FeatureIds -contains 'Legacy' -and $FeatureIds -contains 'Anyone'
}
$warnings | Should -HaveCount 1
$warnings[0] | Should -BeLike 'Skipping Modern: * build 22621 or newer*build 19045*'
}
It 'skips features that are only supported on an older build' {
Mock Get-CurrentWindowsBuild { 26100 }
Invoke-AllChanges
Should -Invoke Invoke-ApplyFeatures -Times 1 -Exactly -ParameterFilter {
@($FeatureIds).Count -eq 2 -and $FeatureIds -contains 'Modern' -and $FeatureIds -contains 'Anyone'
}
$warnings | Should -HaveCount 1
$warnings[0] | Should -BeLike 'Skipping Legacy: * build 21999 or older*build 26100*'
}
It 'does not back up the registry keys of skipped features' {
Mock Get-CurrentWindowsBuild { 19045 }
Invoke-AllChanges
Should -Invoke New-RegistrySettingsBackup -Times 1 -Exactly -ParameterFilter {
$ActionableKeys -notcontains 'Modern' -and $ActionableKeys -contains 'Legacy'
}
}
It 'does not apply anything gated when every selected feature is skipped' {
Mock Get-CurrentWindowsBuild { 19045 }
$script:Params = @{ Modern = $true }
$script:UndoParams = @{}
Invoke-AllChanges
Should -Invoke Invoke-ApplyFeatures -Times 0 -Exactly
Should -Invoke New-RegistrySettingsBackup -Times 0 -Exactly
$warnings | Should -HaveCount 1
}
It 'applies every feature when the build cannot be read' {
Mock Get-CurrentWindowsBuild { $null }
Invoke-AllChanges
Should -Invoke Invoke-ApplyFeatures -Times 1 -Exactly -ParameterFilter { @($FeatureIds).Count -eq 3 }
$warnings | Should -HaveCount 0
}
It 'drops skipped features from the parameters so that they are not part of the reboot advice' {
Mock Get-CurrentWindowsBuild { 19045 }
Mock Get-Translation { $Key }
$script:Features['Modern'] | Add-Member -NotePropertyName RequiresReboot -NotePropertyValue $true
$script:Features['Legacy'] | Add-Member -NotePropertyName RequiresReboot -NotePropertyValue $true
Invoke-AllChanges
$script:Params.ContainsKey('Modern') | Should -BeFalse
$script:Params.ContainsKey('Legacy') | Should -BeTrue
$labels = @(Get-RebootFeatureLabels)
$labels | Should -Contain 'Legacy'
$labels | Should -Not -Contain 'Modern'
}
It 'does not write anything to the output when it skips a feature' {
Mock Get-CurrentWindowsBuild { 19045 }
# $PSBoundParameters is a generic dictionary whose Remove() returns a Boolean, unlike Hashtable.Remove()
$script:Params = [System.Collections.Generic.Dictionary[string, object]]::new()
$script:Params['Modern'] = $true
$script:Params['Anyone'] = $true
@(Invoke-AllChanges) | Should -HaveCount 0
$script:Params.ContainsKey('Modern') | Should -BeFalse
}
It 'leaves undo selections alone' {
Mock Get-CurrentWindowsBuild { 19045 }
Invoke-AllChanges
Should -Invoke Invoke-UndoFeatures -Times 1 -Exactly -ParameterFilter {
@($FeatureIds).Count -eq 1 -and $FeatureIds[0] -eq 'ModernUndo'
}
}
}
+1
View File
@@ -8,6 +8,7 @@ BeforeAll {
. (Join-Path $PSScriptRoot '..\Scripts\GUI\MainWindow-AppSelection.ps1')
. (Join-Path $PSScriptRoot '..\Scripts\GUI\MainWindow-Deployment.ps1')
. (Join-Path $PSScriptRoot '..\Scripts\GUI\MainWindow-Navigation.ps1')
. (Join-Path $PSScriptRoot '..\Scripts\Helpers\Windows-BuildHelpers.ps1')
. (Join-Path $PSScriptRoot '..\Scripts\GUI\MainWindow-TweaksBuilder.ps1')
. (Join-Path $PSScriptRoot '..\Scripts\GUI\Set-WindowThemeResources.ps1')
$script:LanguagesPath = Join-Path $PSScriptRoot '..\Config\Languages'
+1 -1
View File
@@ -5,7 +5,7 @@ BeforeAll {
foreach ($file in @('FileIO/Import-JsonFile', 'FileIO/Import-LanguageFile',
'GUI/Ui-Preferences', 'GUI/Show-SettingsDialog', 'GUI/Set-WindowThemeResources',
'GUI/MainWindow-Localization', 'GUI/MainWindow-TweaksBuilder', 'GUI/MainWindow-AppSelection',
'GUI/MainWindow-Deployment', 'GUI/Show-Bubble', 'Helpers/Get-UserName')) {
'GUI/MainWindow-Deployment', 'GUI/Show-Bubble', 'Helpers/Get-UserName', 'Helpers/Windows-BuildHelpers')) {
. "$script:RepoRoot/Scripts/$file.ps1"
}
$script:LanguagesPath = Join-Path $script:RepoRoot 'Config/Languages'
+1
View File
@@ -2,6 +2,7 @@ BeforeAll {
. (Join-Path $PSScriptRoot '..\Scripts\Helpers\Registry-PathHelpers.ps1')
. (Join-Path $PSScriptRoot '..\Scripts\Helpers\Get-RegFileOperations.ps1')
. (Join-Path $PSScriptRoot '..\Scripts\Helpers\User-HiveHelpers.ps1')
. (Join-Path $PSScriptRoot '..\Scripts\Helpers\Windows-BuildHelpers.ps1')
. (Join-Path $PSScriptRoot '..\Scripts\Features\Invoke-Changes.ps1')
. (Join-Path $PSScriptRoot '..\Scripts\Features\Backup-RegistryFeatureSelection.ps1')
. (Join-Path $PSScriptRoot '..\Scripts\FileIO\Save-ToFile.ps1')
+1
View File
@@ -6,6 +6,7 @@ BeforeAll {
. (Join-Path $PSScriptRoot '..\Scripts\FileIO\Import-LanguageFile.ps1')
. (Join-Path $PSScriptRoot '..\Scripts\Helpers\Add-Parameter.ps1')
. (Join-Path $PSScriptRoot '..\Scripts\FileIO\Save-ToFile.ps1')
. (Join-Path $PSScriptRoot '..\Scripts\Helpers\Windows-BuildHelpers.ps1')
. (Join-Path $PSScriptRoot '..\Scripts\FileIO\Import-Settings.ps1')
. (Join-Path $PSScriptRoot '..\Scripts\FileIO\Save-Settings.ps1')
. (Join-Path $PSScriptRoot '..\Scripts\FileIO\Import-AppsFromFile.ps1')
+68
View File
@@ -0,0 +1,68 @@
BeforeAll {
. (Join-Path $PSScriptRoot '..\Scripts\Helpers\Windows-BuildHelpers.ps1')
}
Describe 'Get-CurrentWindowsBuild' {
It 'returns the build number as a number' {
Mock Get-ItemPropertyValue { '26100' }
Get-CurrentWindowsBuild | Should -Be 26100
Get-CurrentWindowsBuild | Should -BeOfType [int]
}
It 'returns nothing when the value is not a number' {
Mock Get-ItemPropertyValue { 'unknown' }
Get-CurrentWindowsBuild | Should -BeNullOrEmpty
}
It 'returns nothing instead of failing when reading the registry throws' {
Mock Get-ItemPropertyValue { throw 'Property CurrentBuild does not exist' }
{ Get-CurrentWindowsBuild } | Should -Not -Throw
Get-CurrentWindowsBuild | Should -BeNullOrEmpty
}
It 'asks for a terminating error so that a missing value is caught' {
Mock Get-ItemPropertyValue { '19045' }
Get-CurrentWindowsBuild | Out-Null
Should -Invoke Get-ItemPropertyValue -Times 1 -Exactly -ParameterFilter { $ErrorAction -eq 'Stop' }
}
}
Describe 'Test-FeatureSupportedOnBuild' {
It 'returns <Expected> for MinVersion <Min>, MaxVersion <Max> on build <Build>' -ForEach @(
@{ Min = 22621; Max = $null; Build = 19045; Expected = $false }
@{ Min = 22621; Max = $null; Build = 22620; Expected = $false }
@{ Min = 22621; Max = $null; Build = 22621; Expected = $true }
@{ Min = 22621; Max = $null; Build = 26100; Expected = $true }
@{ Min = $null; Max = 21999; Build = 19045; Expected = $true }
@{ Min = $null; Max = 21999; Build = 21999; Expected = $true }
@{ Min = $null; Max = 21999; Build = 22000; Expected = $false }
@{ Min = 22000; Max = 22631; Build = 22631; Expected = $true }
@{ Min = 22000; Max = 22631; Build = 26100; Expected = $false }
@{ Min = $null; Max = $null; Build = 10240; Expected = $true }
) {
$feature = [PSCustomObject]@{ MinVersion = $Min; MaxVersion = $Max }
Test-FeatureSupportedOnBuild -Feature $feature -Build $Build | Should -Be $Expected
}
It 'does not limit a feature when the build is not known' {
$feature = [PSCustomObject]@{ MinVersion = 22621; MaxVersion = $null }
Test-FeatureSupportedOnBuild -Feature $feature -Build $null | Should -BeTrue
}
It 'does not limit an unknown feature' {
Test-FeatureSupportedOnBuild -Feature $null -Build 19045 | Should -BeTrue
}
It 'compares build numbers as numbers when the build is a string' {
$feature = [PSCustomObject]@{ MinVersion = 22621; MaxVersion = $null }
Test-FeatureSupportedOnBuild -Feature $feature -Build '9600' | Should -BeFalse
}
}