Expand Pester coverage across install, tweaks, and UI workflows (#4792)

* Harden Pester CI and discard runspace return values

* Add prioritized test backlog

* Add WinUtil action logging

* Add config integrity tests

* Add XAML control wiring tests

* Add registry and service helper tests

* Add package manager tests

* Add runspace behavior tests

* Add tweak orchestration tests

* Add install workflow tests

* Add update profile tests

* Add AppX removal tests

* Log package installer output

* Add UI state helper tests

* Pin Pester test runner version

* Expand Win11 Creator tests

* Add preferences and theme tests

* Add search filter tests

* Add compile contract tests

* Use single WinUtil session log

* Remove installer output logging helper

* Handle locked WinUtil transcript log

* Avoid appending to active transcript log

* Log install uninstall package identities
This commit is contained in:
Chris Titus
2026-07-01 21:49:15 -05:00
committed by GitHub
parent c3b4f85fce
commit 2cb20893fc
44 changed files with 4586 additions and 36 deletions
+9 -2
View File
@@ -1,6 +1,6 @@
function Invoke-WPFAppxRemoval {
if (-not ($sync.selectedAppx)) {
[System.Windows.Forms.MessageBox]::Show("No AppX Package selected","Error","OK","Error")
if ($null -eq $sync.selectedAppx -or $sync.selectedAppx.Count -eq 0) {
Show-WinUtilMessage -Message "No AppX Package selected" -Title "Error" -Button "OK" -Icon "Error"
return
}
@@ -11,26 +11,32 @@ function Invoke-WPFAppxRemoval {
param($selected, $apps)
$sync.ProcessRunning = $true
Write-WinUtilLog -Component "AppX" -Message "Starting AppX removal for $(@($selected).Count) selected package(s)."
foreach ($key in $selected) {
if ($key -eq "WPFAppxMicrosoft_XboxGamingOverlay") {
# Making sure Game Bar isn't running
Write-WinUtilLog -Component "AppX" -Message "Stopping GameBarFTServer before removing Xbox Gaming Overlay."
Stop-Process -Name GameBarFTServer
# This stops annoying ms-gamebar popup when launching games.
Write-WinUtilLog -Component "AppX" -Message "Disabling Game DVR capture before removing Xbox Gaming Overlay."
Set-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\GameDVR -Name AppCaptureEnabled -Value 0
}
if ($key -eq "WPFAppxMicrosoft_WindowsNotepad") {
# i hope your having fun reading this
Write-WinUtilLog -Component "AppX" -Message "Stopping dllhost before removing Notepad."
Stop-Process -Name dllhost
}
Write-Host "Removing $($apps[$key].Content)"
Write-WinUtilLog -Component "AppX" -Message "Removing $($apps[$key].Content) ($($apps[$key].PackageId))."
Get-AppxPackage -Name $apps[$key].PackageId -AllUsers | Remove-AppxPackage -AllUsers
if ($key -eq "WPFAppxMSTeams") {
# Uninstalls Microsoft Teams Meeting Add-in for Microsoft Office
Write-WinUtilLog -Component "AppX" -Message "Uninstalling Microsoft Teams meeting add-in package."
Get-Package -Name "Microsoft Teams*" -ErrorAction SilentlyContinue | Uninstall-Package -Force
}
}
@@ -38,6 +44,7 @@ function Invoke-WPFAppxRemoval {
Write-Host "================================="
Write-Host "-- AppX Removal Finished ---"
Write-Host "================================="
Write-WinUtilLog -Component "AppX" -Message "AppX removal finished."
$sync.ProcessRunning = $false
}
+11 -3
View File
@@ -9,17 +9,20 @@ function Invoke-WPFInstall {
if($sync.ProcessRunning) {
$msg = "[Invoke-WPFInstall] An Install process is currently running."
[System.Windows.MessageBox]::Show($msg, "Winutil", [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Warning)
Show-WinUtilMessage -Message $msg -Title "Winutil" -Button "OK" -Icon "Warning"
return
}
if ($PackagesToInstall.Count -eq 0) {
$WarningMsg = "Please select the program(s) to install or upgrade."
[System.Windows.MessageBox]::Show($WarningMsg, $AppTitle, [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Warning)
Show-WinUtilMessage -Message $WarningMsg -Title $AppTitle -Button "OK" -Icon "Warning"
return
}
$ManagerPreference = $sync.preferences.packagemanager
Write-WinUtilLog -Component "Install" -Message "Install requested for $(@($PackagesToInstall).Count) selected package(s) using preference: $ManagerPreference"
$packageSummary = Get-WinUtilPackageLogSummary -Packages $PackagesToInstall -Preference $ManagerPreference
Write-WinUtilLog -Component "Install" -Message "Install selected package(s): $($packageSummary -join '; ')"
$handle = Invoke-WPFRunspace -ParameterList @(("PackagesToInstall", $PackagesToInstall),("ManagerPreference", $ManagerPreference)) -ScriptBlock {
param($PackagesToInstall, $ManagerPreference)
@@ -28,6 +31,7 @@ function Invoke-WPFInstall {
$packagesWinget = $packagesSorted[[PackageManagers]::Winget]
$packagesChoco = $packagesSorted[[PackageManagers]::Choco]
Write-WinUtilLog -Component "Install" -Message "Install package manager split: winget=$(@($packagesWinget).Count), choco=$(@($packagesChoco).Count)"
try {
$sync.ProcessRunning = $true
@@ -44,13 +48,17 @@ function Invoke-WPFInstall {
Write-Host "==========================================="
Write-Host "-- Installs have finished ---"
Write-Host "==========================================="
Write-WinUtilLog -Component "Install" -Message "Install workflow completed."
Invoke-WPFUIThread -ScriptBlock { Set-WinUtilTaskbaritem -state "None" -overlay "checkmark" }
} catch {
Hide-WPFInstallAppBusy
Write-Host "==========================================="
Write-Host "Error: $_"
Write-Host "==========================================="
Write-WinUtilLog -Level "ERROR" -Component "Install" -Message "Install workflow failed: $($_.Exception.Message)"
Invoke-WPFUIThread -ScriptBlock { Set-WinUtilTaskbaritem -state "Error" -overlay "warning" }
} finally {
$sync.ProcessRunning = $False
}
$sync.ProcessRunning = $False
}
}
+3 -3
View File
@@ -34,11 +34,11 @@ function Invoke-WPFRunspace {
$script:powershell = [powershell]::Create()
# Add Scriptblock and Arguments to runspace
$script:powershell.AddScript($ScriptBlock)
$script:powershell.AddArgument($ArgumentList)
[void]$script:powershell.AddScript($ScriptBlock)
[void]$script:powershell.AddArgument($ArgumentList)
foreach ($parameter in $ParameterList) {
$script:powershell.AddParameter($parameter[0], $parameter[1])
[void]$script:powershell.AddParameter($parameter[0], $parameter[1])
}
$script:powershell.RunspacePool = $sync.runspace
+14 -6
View File
@@ -11,26 +11,29 @@ function Invoke-WPFUnInstall {
if($sync.ProcessRunning) {
$msg = "[Invoke-WPFUnInstall] Install process is currently running"
[System.Windows.MessageBox]::Show($msg, "Winutil", [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Warning)
Show-WinUtilMessage -Message $msg -Title "Winutil" -Button "OK" -Icon "Warning"
return
}
if ($PackagesToUninstall.Count -eq 0) {
$WarningMsg = "Please select the program(s) to uninstall"
[System.Windows.MessageBox]::Show($WarningMsg, $AppTitle, [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Warning)
Show-WinUtilMessage -Message $WarningMsg -Title $AppTitle -Button "OK" -Icon "Warning"
return
}
$ButtonType = [System.Windows.MessageBoxButton]::YesNo
$ButtonType = "YesNo"
$MessageboxTitle = "Are you sure?"
$Messageboxbody = ("This will uninstall the following applications: `n $($PackagesToUninstall | Select-Object Name, Description| Out-String)")
$MessageIcon = [System.Windows.MessageBoxImage]::Information
$MessageIcon = "Information"
$confirm = [System.Windows.MessageBox]::Show($Messageboxbody, $MessageboxTitle, $ButtonType, $MessageIcon)
$confirm = Show-WinUtilMessage -Message $Messageboxbody -Title $MessageboxTitle -Button $ButtonType -Icon $MessageIcon
if($confirm -eq "No") {return}
$ManagerPreference = $sync.preferences.packagemanager
Write-WinUtilLog -Component "Uninstall" -Message "Uninstall requested for $(@($PackagesToUninstall).Count) selected package(s) using preference: $ManagerPreference"
$packageSummary = Get-WinUtilPackageLogSummary -Packages $PackagesToUninstall -Preference $ManagerPreference
Write-WinUtilLog -Component "Uninstall" -Message "Uninstall selected package(s): $($packageSummary -join '; ')"
Invoke-WPFRunspace -ParameterList @(("PackagesToUninstall", $PackagesToUninstall),("ManagerPreference", $ManagerPreference)) -ScriptBlock {
param($PackagesToUninstall, $ManagerPreference)
@@ -38,6 +41,7 @@ function Invoke-WPFUnInstall {
$packagesSorted = Get-WinUtilSelectedPackages -PackageList $PackagesToUninstall -Preference $ManagerPreference
$packagesWinget = $packagesSorted[[PackageManagers]::Winget]
$packagesChoco = $packagesSorted[[PackageManagers]::Choco]
Write-WinUtilLog -Component "Uninstall" -Message "Uninstall package manager split: winget=$(@($packagesWinget).Count), choco=$(@($packagesChoco).Count)"
try {
$sync.ProcessRunning = $true
@@ -58,14 +62,18 @@ function Invoke-WPFUnInstall {
Write-Host "==========================================="
Write-Host "-- Uninstalls have finished ---"
Write-Host "==========================================="
Write-WinUtilLog -Component "Uninstall" -Message "Uninstall workflow completed."
Invoke-WPFUIThread -ScriptBlock { Set-WinUtilTaskbaritem -state "None" -overlay "checkmark" }
} catch {
Hide-WPFInstallAppBusy
Write-Host "==========================================="
Write-Host "Error: $_"
Write-Host "==========================================="
Write-WinUtilLog -Level "ERROR" -Component "Uninstall" -Message "Uninstall workflow failed: $($_.Exception.Message)"
Invoke-WPFUIThread -ScriptBlock { Set-WinUtilTaskbaritem -state "Error" -overlay "warning" }
} finally {
$sync.ProcessRunning = $False
}
$sync.ProcessRunning = $False
}
}
@@ -6,8 +6,10 @@ function Invoke-WPFUpdatesdefault {
#>
$ErrorActionPreference = 'SilentlyContinue'
Write-WinUtilLog -Component "Updates" -Message "Resetting Windows Update settings to default."
Write-Host "Removing Windows Update policy settings..." -ForegroundColor Green
Write-WinUtilLog -Component "Updates" -Message "Removing Windows Update policy registry paths."
Remove-Item -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU" -Recurse -Force
Remove-Item -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\DeliveryOptimization" -Recurse -Force
@@ -17,24 +19,31 @@ function Invoke-WPFUpdatesdefault {
Remove-Item -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate" -Recurse -Force
Write-Host "Showing Windows Updates in settings..."
Write-WinUtilLog -Component "Updates" -Message "Showing Windows Update settings page."
Remove-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer -Name SettingsPageVisibility
Write-Host "Reenabling Windows Update Services..." -ForegroundColor Green
Write-WinUtilLog -Component "Updates" -Message "Restoring Windows Update service startup types."
Write-Host "Restored BITS to Manual."
Write-WinUtilLog -Component "Updates" -Message "Restoring BITS service to Manual."
Set-Service -Name BITS -StartupType Manual
Write-Host "Restored wuauserv to Manual."
Write-WinUtilLog -Component "Updates" -Message "Restoring wuauserv service to Manual."
Set-Service -Name wuauserv -StartupType Manual
Write-Host "Restored UsoSvc to Automatic."
Write-WinUtilLog -Component "Updates" -Message "Starting UsoSvc service and restoring startup type to Automatic."
Start-Service -Name UsoSvc
Set-Service -Name UsoSvc -StartupType Automatic
Write-Host "Restored WaaSMedicSvc to Manual."
Write-WinUtilLog -Component "Updates" -Message "Restoring WaaSMedicSvc service to Manual."
Set-Service -Name WaaSMedicSvc -StartupType Manual
Write-Host "Enabling update related scheduled tasks..." -ForegroundColor Green
Write-WinUtilLog -Component "Updates" -Message "Enabling update related scheduled tasks."
$Tasks =
'\Microsoft\Windows\InstallService\*',
@@ -49,6 +58,7 @@ function Invoke-WPFUpdatesdefault {
}
Write-Host "Windows Local Policies Reset to Default."
Write-WinUtilLog -Component "Updates" -Message "Resetting local security policy to defaults with secedit."
secedit /configure /cfg "$Env:SystemRoot\inf\defltbase.inf" /db defltbase.sdb
Write-Host "===================================================" -ForegroundColor Green
@@ -56,4 +66,5 @@ function Invoke-WPFUpdatesdefault {
Write-Host "===================================================" -ForegroundColor Green
Write-Host "Note: You must restart your system in order for all changes to take effect." -ForegroundColor Yellow
Write-WinUtilLog -Component "Updates" -Message "Windows Update default workflow completed. Restart required."
}
@@ -9,8 +9,10 @@ function Invoke-WPFUpdatesdisable {
#>
$ErrorActionPreference = 'SilentlyContinue'
Write-WinUtilLog -Component "Updates" -Message "Disabling Windows Update settings."
Write-Host "Configuring registry settings..." -ForegroundColor Yellow
Write-WinUtilLog -Component "Updates" -Message "Configuring Windows Update registry policy values for disable mode."
New-Item -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU" -Force
Set-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU" -Name "NoAutoUpdate" -Type DWord -Value 1
@@ -20,22 +22,28 @@ function Invoke-WPFUpdatesdisable {
Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\DeliveryOptimization\Config" -Name "DODownloadMode" -Type DWord -Value 0
Write-Host "Hiding Windows Updates from settings..."
Write-WinUtilLog -Component "Updates" -Message "Hiding Windows Update settings page."
Set-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer -Name SettingsPageVisibility -Value hide:windowsupdate
Write-Host "Disabled BITS Service."
Write-WinUtilLog -Component "Updates" -Message "Disabling BITS service."
Set-Service -Name BITS -StartupType Disabled
Write-Host "Disabled wuauserv Service."
Write-WinUtilLog -Component "Updates" -Message "Disabling wuauserv service."
Set-Service -Name wuauserv -StartupType Disabled
Write-Host "Disabled UsoSvc Service."
Write-WinUtilLog -Component "Updates" -Message "Stopping and disabling UsoSvc service."
Stop-Service -Name UsoSvc -Force
Set-Service -Name UsoSvc -StartupType Disabled
Remove-Item "C:\Windows\SoftwareDistribution\*" -Recurse -Force
Write-Host "Cleared SoftwareDistribution folder."
Write-WinUtilLog -Component "Updates" -Message "Cleared SoftwareDistribution folder."
Write-Host "Disabling update related scheduled tasks..." -ForegroundColor Yellow
Write-WinUtilLog -Component "Updates" -Message "Disabling update related scheduled tasks."
$Tasks =
'\Microsoft\Windows\InstallService\*',
@@ -54,4 +62,5 @@ function Invoke-WPFUpdatesdisable {
Write-Host "=================================" -ForegroundColor Green
Write-Host "Note: You must restart your system in order for all changes to take effect." -ForegroundColor Yellow
Write-WinUtilLog -Component "Updates" -Message "Windows Update disable workflow completed. Restart required."
}
@@ -14,6 +14,8 @@ function Invoke-WPFUpdatessecurity {
#>
Write-Host "Disabling driver offering through Windows Update..."
Write-WinUtilLog -Component "Updates" -Message "Applying recommended Windows Update settings."
Write-WinUtilLog -Component "Updates" -Message "Disabling driver offering through Windows Update."
New-Item -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\Device Metadata" -Force
Set-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\Device Metadata" -Name "PreventDeviceMetadataFromNetwork" -Type DWord -Value 1
@@ -28,6 +30,7 @@ function Invoke-WPFUpdatessecurity {
Set-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate" -Name "ExcludeWUDriversInQualityUpdate" -Type DWord -Value 1
Write-Host "Setting cumulative updates back by 1 year and security updates by 4 days..."
Write-WinUtilLog -Component "Updates" -Message "Deferring feature updates by 365 days and quality updates by 4 days."
New-Item -Path "HKLM:\SOFTWARE\Microsoft\WindowsUpdate\UX\Settings" -Force
@@ -36,6 +39,7 @@ function Invoke-WPFUpdatessecurity {
Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\WindowsUpdate\UX\Settings" -Name "DeferQualityUpdatesPeriodInDays" -Type DWord -Value 4
Write-Host "Disabling Windows Update automatic restart..."
Write-WinUtilLog -Component "Updates" -Message "Disabling Windows Update automatic restart while users are logged in."
New-Item -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU" -Force
Set-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU" -Name "NoAutoRebootWithLoggedOnUsers" -Type DWord -Value 1
@@ -44,4 +48,5 @@ function Invoke-WPFUpdatessecurity {
Write-Host "================================="
Write-Host "-- Updates Set to Recommended ---"
Write-Host "================================="
Write-WinUtilLog -Component "Updates" -Message "Recommended Windows Update settings workflow completed."
}
@@ -22,6 +22,7 @@ function Invoke-WPFtweaksbutton {
$tweaksToRun = @($Tweaks | Where-Object { $_ -ne $restorePointTweak })
$totalSteps = [Math]::Max($Tweaks.Count, 1)
$completedSteps = 0
Write-WinUtilLog -Component "Tweaks" -Message "Tweaks requested: $(@($Tweaks).Count) selected tweak(s), DNS provider: $dnsProvider"
if ($tweaks.count -eq 0 -and $dnsProvider -eq "Default") {
$msg = "Please check the tweaks you wish to perform."
@@ -39,6 +40,7 @@ function Invoke-WPFtweaksbutton {
}
Set-WinUtilProgressBar -Label "Creating restore point" -Percent 0
Write-WinUtilLog -Component "Tweaks" -Message "Creating restore point before applying selected tweaks."
Invoke-WinUtilTweaks $restorePointTweak
$completedSteps = 1
@@ -49,6 +51,7 @@ function Invoke-WPFtweaksbutton {
Write-Host "================================="
Write-Host "-- Tweaks are Finished ---"
Write-Host "================================="
Write-WinUtilLog -Component "Tweaks" -Message "Tweaks workflow completed after restore point."
return
}
}
@@ -82,5 +85,6 @@ function Invoke-WPFtweaksbutton {
Write-Host "================================="
Write-Host "-- Tweaks are Finished ---"
Write-Host "================================="
Write-WinUtilLog -Component "Tweaks" -Message "Tweaks workflow completed."
}
}
+2
View File
@@ -24,6 +24,7 @@ function Invoke-WPFundoall {
param($tweaks)
$sync.ProcessRunning = $true
Write-WinUtilLog -Component "Tweaks" -Message "Undo tweaks requested: $(@($tweaks).Count) selected tweak(s)."
if ($tweaks.count -eq 1) {
Invoke-WPFUIThread -ScriptBlock { Set-WinUtilTaskbaritem -state "Indeterminate" -value 0.01 -overlay "logo" }
} else {
@@ -43,6 +44,7 @@ function Invoke-WPFundoall {
Write-Host "=================================="
Write-Host "--- Undo Tweaks are Finished ---"
Write-Host "=================================="
Write-WinUtilLog -Component "Tweaks" -Message "Undo tweaks workflow completed."
}
}