clean up redundant/problematic tests

This commit is contained in:
Jeffrey
2026-10-28 17:28:39 +01:00
parent 7cb6e6ade4
commit d2cb97a4ef
6 changed files with 46 additions and 66 deletions
+3 -3
View File
@@ -3,7 +3,7 @@ BeforeAll {
$buildScript = Join-Path $repositoryRoot 'Scripts/Build-Release.ps1' $buildScript = Join-Path $repositoryRoot 'Scripts/Build-Release.ps1'
$releasePath = Join-Path $TestDrive 'release' $releasePath = Join-Path $TestDrive 'release'
$version = '2026.10.22-r2' $version = '2026.10.22-r2'
$originalScript = [IO.File]::ReadAllBytes((Join-Path $repositoryRoot 'Win11Debloat.ps1')) $originalScript = [IO.File]::ReadAllText((Join-Path $repositoryRoot 'Win11Debloat.ps1'))
Push-Location $TestDrive Push-Location $TestDrive
try { & $buildScript -SourcePath $repositoryRoot -Version $version -OutputDirectory 'release' } try { & $buildScript -SourcePath $repositoryRoot -Version $version -OutputDirectory 'release' }
finally { Pop-Location } finally { Pop-Location }
@@ -15,8 +15,8 @@ BeforeAll {
Describe 'Release packaging' { Describe 'Release packaging' {
It 'stamps only the packaged version and preserves runtime resources' { It 'stamps only the packaged version and preserves runtime resources' {
[IO.File]::ReadAllText((Join-Path $packagePath 'Win11Debloat.ps1')) | Should -Match '\$script:Version = "2026\.10\.22-r2"' [IO.File]::ReadAllText((Join-Path $packagePath 'Win11Debloat.ps1')) | Should -Match '\$script:Version = "2026\.10\.22-r2"'
[Convert]::ToBase64String([IO.File]::ReadAllBytes((Join-Path $repositoryRoot 'Win11Debloat.ps1'))) | [IO.File]::ReadAllText((Join-Path $repositoryRoot 'Win11Debloat.ps1')) |
Should -BeExactly ([Convert]::ToBase64String($originalScript)) Should -BeExactly $originalScript
foreach ($directory in 'Assets', 'Config', 'Regfiles', 'Schemas') { foreach ($directory in 'Assets', 'Config', 'Regfiles', 'Schemas') {
foreach ($file in Get-ChildItem -LiteralPath (Join-Path $repositoryRoot $directory) -File -Recurse) { foreach ($file in Get-ChildItem -LiteralPath (Join-Path $repositoryRoot $directory) -File -Recurse) {
$relativePath = $file.FullName.Substring($repositoryRoot.Length + 1) $relativePath = $file.FullName.Substring($repositoryRoot.Length + 1)
-6
View File
@@ -71,12 +71,6 @@ Describe 'Test-FileHashMatch' {
Test-FileHashMatch $script:AbcFile $script:OtherHash | Should -BeFalse Test-FileHashMatch $script:AbcFile $script:OtherHash | Should -BeFalse
} }
It 'rejects a file whose content changed' {
$changedFile = Join-Path $TestDrive 'changed.bin'
[System.IO.File]::WriteAllBytes($changedFile, [System.Text.Encoding]::ASCII.GetBytes('abd'))
Test-FileHashMatch $changedFile $script:AbcHash | Should -BeFalse
}
} }
Describe 'Launcher archive verification flow' { Describe 'Launcher archive verification flow' {
@@ -51,13 +51,6 @@ Describe 'Invoke-SystemRestorePoint' {
Should -Invoke Read-Host -Times 0 -Exactly Should -Invoke Read-Host -Times 0 -Exactly
} }
It 'is loaded by the main entry point' {
$entryPoint = Get-Content -LiteralPath (Join-Path $PSScriptRoot '..\Win11Debloat.ps1') -Raw
$expectedImport = [regex]::Escape('Scripts/Features/Invoke-SystemRestorePoint.ps1')
$entryPoint | Should -Match $expectedImport
}
It 'enables disabled System Restore before creating the point in silent mode' { It 'enables disabled System Restore before creating the point in silent mode' {
$script:Silent = $true $script:Silent = $true
Mock Get-ItemProperty { [PSCustomObject]@{ RPSessionInterval = 0 } } Mock Get-ItemProperty { [PSCustomObject]@{ RPSessionInterval = 0 } }
+43 -12
View File
@@ -7,6 +7,49 @@ BeforeAll {
}) })
} }
Describe 'Release workflow version validation' {
BeforeEach {
$locationPushed = $false
$originalTag = $env:RELEASE_TAG
$checkoutPath = Join-Path $TestDrive ([guid]::NewGuid().ToString('N'))
New-Item -ItemType Directory -Path $checkoutPath -Force | Out-Null
$scriptPath = Join-Path $checkoutPath 'Win11Debloat.ps1'
$originalSource = '$script:Version = "2026.08.24"'
[IO.File]::WriteAllText($scriptPath, $originalSource)
# Version validation needs no repository or external authentication.
function git {}
function gh {}
Mock git { $global:LASTEXITCODE = 0 }
Mock gh { $global:LASTEXITCODE = 0 }
Push-Location $checkoutPath
$locationPushed = $true
}
AfterEach {
if ($locationPushed) { Pop-Location }
$env:RELEASE_TAG = $originalTag
}
It 'rejects invalid release version <InvalidVersion> before changing the source or calling external tools' -ForEach @(
@{ InvalidVersion = '2026.02.30-r2' }
@{ InvalidVersion = '2026.10.23-r0' }
@{ InvalidVersion = '2026.10.23-r' }
@{ InvalidVersion = '2026.10.23-r2-extra' }
) {
$env:RELEASE_TAG = $InvalidVersion
{ & $workflowBlocks[0] } | Should -Throw
[IO.File]::ReadAllText($scriptPath) | Should -BeExactly $originalSource
Should -Invoke git -Times 0 -Exactly
Should -Invoke gh -Times 0 -Exactly
}
It 'accepts a single-digit revision and updates the source version' {
$env:RELEASE_TAG = '2026.10.23-r2'
& $workflowBlocks[0]
[IO.File]::ReadAllText($scriptPath) | Should -BeExactly '$script:Version = "2026.10.23-r2"'
}
}
Describe 'Release workflow version commit' { Describe 'Release workflow version commit' {
BeforeEach { BeforeEach {
$locationPushed = $false $locationPushed = $false
@@ -94,7 +137,6 @@ if ($text -notmatch [regex]::Escape($env:RELEASE_TAG)) { throw 'Tests did not se
It 'commits and packages release version <ReleaseVersion> from the same tagged commit' -ForEach @( It 'commits and packages release version <ReleaseVersion> from the same tagged commit' -ForEach @(
@{ ReleaseVersion = '2026.10.23' } @{ ReleaseVersion = '2026.10.23' }
@{ ReleaseVersion = '2026.10.23-r2' }
@{ ReleaseVersion = '2026.10.23-r10' } @{ ReleaseVersion = '2026.10.23-r10' }
) { ) {
$env:RELEASE_TAG = $ReleaseVersion $env:RELEASE_TAG = $ReleaseVersion
@@ -115,17 +157,6 @@ if ($text -notmatch [regex]::Escape($env:RELEASE_TAG)) { throw 'Tests did not se
Should -Match $versionPattern Should -Match $versionPattern
} }
It 'rejects invalid release version <InvalidVersion> before changing the source' -ForEach @(
@{ InvalidVersion = '2026.02.30-r2' }
@{ InvalidVersion = '2026.10.23-r0' }
@{ InvalidVersion = '2026.10.23-r' }
@{ InvalidVersion = '2026.10.23-r2-extra' }
) {
$env:RELEASE_TAG = $InvalidVersion
{ & $workflowBlocks[0] } | Should -Throw
[IO.File]::ReadAllText((Join-Path $checkoutPath 'Win11Debloat.ps1')) | Should -Match '2026\.08\.24'
}
It 'does not commit or push a release when tests fail' { It 'does not commit or push a release when tests fail' {
[IO.File]::WriteAllText((Join-Path $checkoutPath 'Scripts/Run-Tests.ps1'), 'exit 1') [IO.File]::WriteAllText((Join-Path $checkoutPath 'Scripts/Run-Tests.ps1'), 'exit 1')
{ foreach ($block in $workflowBlocks) { & $block } } | Should -Throw '*Release tests failed*' { foreach ($block in $workflowBlocks) { & $block } } | Should -Throw '*Release tests failed*'
-21
View File
@@ -1,21 +0,0 @@
Describe 'Wait-ForKeyPress' {
It 'exits cleanly without prompting when Silent is enabled' {
$scriptPath = Join-Path $PSScriptRoot '..\Scripts\CLI\Wait-ForKeyPress.ps1'
$command = "function Stop-Transcript {}; `$global:Silent = `$true; . '$scriptPath'; Wait-ForKeyPress"
$encodedCommand = [Convert]::ToBase64String([Text.Encoding]::Unicode.GetBytes($command))
& powershell.exe -NoProfile -EncodedCommand $encodedCommand
$LASTEXITCODE | Should -Be 0
}
It 'uses the requested exit code' {
$scriptPath = Join-Path $PSScriptRoot '..\Scripts\CLI\Wait-ForKeyPress.ps1'
$command = "function Stop-Transcript {}; `$global:Silent = `$true; . '$scriptPath'; Wait-ForKeyPress -ExitCode 1"
$encodedCommand = [Convert]::ToBase64String([Text.Encoding]::Unicode.GetBytes($command))
& powershell.exe -NoProfile -EncodedCommand $encodedCommand
$LASTEXITCODE | Should -Be 1
}
}
-17
View File
@@ -100,23 +100,6 @@ Describe 'XAML UI contracts' {
$failures | Should -BeNullOrEmpty $failures | Should -BeNullOrEmpty
} }
It 'keeps the main window navigation and deployment controls available' {
$mainWindow = Get-Content -LiteralPath (Join-Path $script:SchemaPath 'MainWindow.xaml') -Raw
$requiredNames = @(
'MainTabControl'
'HomeTab'
'DeploymentSettingsTab'
'DeploymentApplyBtn'
'UserSelectionCombo'
'AppSelectionPanel'
'AppSelectionStatus'
)
foreach ($name in $requiredNames) {
$mainWindow | Should -Match ('(?:x:Name|\bName)\s*=\s*"{0}"' -f [regex]::Escape($name))
}
}
It 'exposes <Schema> links as keyboard-accessible hyperlinks with automation names' -TestCases @( It 'exposes <Schema> links as keyboard-accessible hyperlinks with automation names' -TestCases @(
@{ Schema = 'AboutWindow.xaml'; LinkNames = @('ProjectLink', 'KofiLink') } @{ Schema = 'AboutWindow.xaml'; LinkNames = @('ProjectLink', 'KofiLink') }
@{ Schema = 'RestoreBackupWindow.xaml'; LinkNames = @('NonRevertibleWikiLink') } @{ Schema = 'RestoreBackupWindow.xaml'; LinkNames = @('NonRevertibleWikiLink') }