Deleted Test-WinUtilPackageManager.ps1 + custom winget and choco installs + remove winget/choco enums and exeptions (#4606)

* Update Invoke-WPFGetInstalled.ps1

* Update Install-WinUtilWinget.ps1

* Update Install-WinUtilChoco.ps1

* Update Install-WinUtilChoco.ps1

* Update Install-WinUtilWinget.ps1

* Delete functions/private/Test-WinUtilPackageManager.ps1

* Update Install-WinUtilChoco.ps1

* Update Install-WinUtilWinget.ps1

* Update Install-WinUtilChoco.ps1

* Update Invoke-WPFGetInstalled.ps1

* Update Invoke-WPFGetInstalled.ps1

* Update Install-WinUtilChoco.ps1

* Update Install-WinUtilWinget.ps1

* Update Install-WinUtilWinget.ps1

* Update Install-WinUtilChoco.ps1

* Update Install-WinUtilWinget.ps1

* Update Install-WinUtilChoco.ps1

* Update Install-WinUtilWinget.ps1

* Update Install-WinUtilChoco.ps1

* Update Install-WinUtilChoco.ps1

* Update Install-WinUtilChoco.ps1

* Update Install-WinUtilChoco.ps1

* Update Install-WinUtilWinget.ps1

* Fixed lastrun.json

* refactor: remove PackageManagers enum and unused custom exception classes

* Update Invoke-WPFUIElements.ps1

* Update Get-WinUtilSelectedPackages.ps1

* Update Set-Preferences.ps1

* Update main.ps1

* Complete package manager enum removal

Use string package-manager preferences throughout the remaining helpers and focused tests. Restore the existing Winget install flow and package-manager probe helper so PR 4606 keeps the current WinGet repair method.

* Fix string keyed package split

---------

Co-authored-by: Chris Titus <contact@christitus.com>
This commit is contained in:
Gabi
2026-07-02 12:50:57 -05:00
committed by GitHub
co-authored by Chris Titus
parent d45c62e470
commit 727ba52a4d
11 changed files with 52 additions and 124 deletions
+14 -24
View File
@@ -5,16 +5,6 @@
BeforeAll {
$script:repoRoot = (Resolve-Path (Join-Path $PSScriptRoot "..")).Path
if (-not ("PackageManagers" -as [type])) {
Add-Type @"
public enum PackageManagers
{
Winget,
Choco
}
"@
}
. (Join-Path $script:repoRoot "functions\private\Get-WinUtilPackageLogSummary.ps1")
. (Join-Path $script:repoRoot "functions\public\Invoke-WPFInstall.ps1")
. (Join-Path $script:repoRoot "functions\public\Invoke-WPFUnInstall.ps1")
@@ -26,7 +16,7 @@ public enum PackageManagers
param($ArgumentList, $ParameterList, [scriptblock]$ScriptBlock)
}
function Get-WinUtilSelectedPackages {
param($PackageList, [PackageManagers]$Preference)
param($PackageList, [string]$Preference)
}
function Show-WPFInstallAppBusy {
param($text)
@@ -82,7 +72,7 @@ public enum PackageManagers
ProcessRunning = $ProcessRunning
selectedApps = $selectedApps
preferences = [pscustomobject]@{
packagemanager = [PackageManagers]::Winget
packagemanager = "Winget"
}
configs = @{
applicationsHashtable = $applications
@@ -97,15 +87,15 @@ public enum PackageManagers
)
$packages = @{}
$packages[[PackageManagers]::Winget] = [System.Collections.Generic.List[string]]::new()
$packages[[PackageManagers]::Choco] = [System.Collections.Generic.List[string]]::new()
$packages["Winget"] = [System.Collections.Generic.List[string]]::new()
$packages["Choco"] = [System.Collections.Generic.List[string]]::new()
foreach ($package in $Winget) {
$null = $packages[[PackageManagers]::Winget].Add($package)
$null = $packages["Winget"].Add($package)
}
foreach ($package in $Choco) {
$null = $packages[[PackageManagers]::Choco].Add($package)
$null = $packages["Choco"].Add($package)
}
$packages
@@ -145,7 +135,7 @@ Describe "Invoke-WPFInstall entrypoint" {
@($ParameterList[0][1]).Count -eq 1 -and
@($ParameterList[0][1])[0].winget -eq "Git.Git" -and
$ParameterList[1][0] -eq "ManagerPreference" -and
$ParameterList[1][1] -eq [PackageManagers]::Winget
$ParameterList[1][1] -eq "Winget"
}
Should -Invoke -CommandName Show-WinUtilMessage -Times 0 -Exactly
Should -Invoke -CommandName Write-WinUtilLog -Times 1 -Exactly -ParameterFilter {
@@ -217,10 +207,10 @@ Describe "Invoke-WPFInstall runspace body" {
It "installs split winget and choco packages and cleans up on success" {
Invoke-WPFInstall
& $script:capturedInstallScriptBlock -PackagesToInstall @($script:package) -ManagerPreference ([PackageManagers]::Winget)
& $script:capturedInstallScriptBlock -PackagesToInstall @($script:package) -ManagerPreference "Winget"
Should -Invoke -CommandName Get-WinUtilSelectedPackages -Times 1 -Exactly -ParameterFilter {
@($PackageList).Count -eq 1 -and $Preference -eq [PackageManagers]::Winget
@($PackageList).Count -eq 1 -and $Preference -eq "Winget"
}
Should -Invoke -CommandName Show-WPFInstallAppBusy -Times 1 -Exactly -ParameterFilter {
$text -eq "Installing apps..."
@@ -245,7 +235,7 @@ Describe "Invoke-WPFInstall runspace body" {
Invoke-WPFInstall
& $script:capturedInstallScriptBlock -PackagesToInstall @($script:package) -ManagerPreference ([PackageManagers]::Winget)
& $script:capturedInstallScriptBlock -PackagesToInstall @($script:package) -ManagerPreference "Winget"
Should -Invoke -CommandName Hide-WPFInstallAppBusy -Times 1 -Exactly
Should -Invoke -CommandName Invoke-WPFUIThread -Times 1 -Exactly -ParameterFilter {
@@ -298,7 +288,7 @@ Describe "Invoke-WPFUnInstall entrypoint" {
@($ParameterList[0][1]).Count -eq 1 -and
@($ParameterList[0][1])[0].winget -eq "Git.Git" -and
$ParameterList[1][0] -eq "ManagerPreference" -and
$ParameterList[1][1] -eq [PackageManagers]::Winget
$ParameterList[1][1] -eq "Winget"
}
Should -Invoke -CommandName Write-WinUtilLog -Times 1 -Exactly -ParameterFilter {
$Component -eq "Uninstall" -and
@@ -374,10 +364,10 @@ Describe "Invoke-WPFUnInstall runspace body" {
It "uninstalls split winget and choco packages and cleans up on success" {
Invoke-WPFUnInstall -PackagesToUninstall @($script:package)
& $script:capturedUninstallScriptBlock -PackagesToUninstall @($script:package) -ManagerPreference ([PackageManagers]::Winget)
& $script:capturedUninstallScriptBlock -PackagesToUninstall @($script:package) -ManagerPreference "Winget"
Should -Invoke -CommandName Get-WinUtilSelectedPackages -Times 1 -Exactly -ParameterFilter {
@($PackageList).Count -eq 1 -and $Preference -eq [PackageManagers]::Winget
@($PackageList).Count -eq 1 -and $Preference -eq "Winget"
}
Should -Invoke -CommandName Show-WPFInstallAppBusy -Times 1 -Exactly -ParameterFilter {
$text -eq "Uninstalling apps..."
@@ -400,7 +390,7 @@ Describe "Invoke-WPFUnInstall runspace body" {
Invoke-WPFUnInstall -PackagesToUninstall @($script:package)
& $script:capturedUninstallScriptBlock -PackagesToUninstall @($script:package) -ManagerPreference ([PackageManagers]::Winget)
& $script:capturedUninstallScriptBlock -PackagesToUninstall @($script:package) -ManagerPreference "Winget"
Should -Invoke -CommandName Hide-WPFInstallAppBusy -Times 1 -Exactly
Should -Invoke -CommandName Invoke-WPFUIThread -Times 1 -Exactly -ParameterFilter {
+15 -25
View File
@@ -5,16 +5,6 @@
BeforeAll {
$script:repoRoot = (Resolve-Path (Join-Path $PSScriptRoot "..")).Path
if (-not ("PackageManagers" -as [type])) {
Add-Type @"
public enum PackageManagers
{
Winget,
Choco
}
"@
}
. (Join-Path $script:repoRoot "functions\private\Get-WinUtilSelectedPackages.ps1")
. (Join-Path $script:repoRoot "functions\private\Test-WinUtilPackageManager.ps1")
. (Join-Path $script:repoRoot "functions\private\Install-WinUtilProgramWinget.ps1")
@@ -35,10 +25,10 @@ Describe "Get-WinUtilSelectedPackages" {
[pscustomobject]@{ winget = "VideoLAN.VLC"; choco = "vlc" }
)
$result = Get-WinUtilSelectedPackages -PackageList $packages -Preference ([PackageManagers]::Winget)
$result = Get-WinUtilSelectedPackages -PackageList $packages -Preference "Winget"
(@($result[[PackageManagers]::Winget]) -join "|") | Should -Be "Git.Git|VideoLAN.VLC"
@($result[[PackageManagers]::Choco]).Count | Should -Be 0
(@($result["Winget"]) -join "|") | Should -Be "Git.Git|VideoLAN.VLC"
@($result["Choco"]).Count | Should -Be 0
}
It "uses choco IDs and falls back to winget for na or missing choco IDs" {
@@ -48,10 +38,10 @@ Describe "Get-WinUtilSelectedPackages" {
[pscustomobject]@{ winget = "Mozilla.Firefox" }
)
$result = Get-WinUtilSelectedPackages -PackageList $packages -Preference ([PackageManagers]::Choco)
$result = Get-WinUtilSelectedPackages -PackageList $packages -Preference "Choco"
(@($result[[PackageManagers]::Choco]) -join "|") | Should -Be "git"
(@($result[[PackageManagers]::Winget]) -join "|") | Should -Be "VideoLAN.VLC|Mozilla.Firefox"
(@($result["Choco"]) -join "|") | Should -Be "git"
(@($result["Winget"]) -join "|") | Should -Be "VideoLAN.VLC|Mozilla.Firefox"
}
It "skips blank, na, and missing package IDs" {
@@ -62,10 +52,10 @@ Describe "Get-WinUtilSelectedPackages" {
[pscustomobject]@{ winget = " " }
)
$result = Get-WinUtilSelectedPackages -PackageList $packages -Preference ([PackageManagers]::Winget)
$result = Get-WinUtilSelectedPackages -PackageList $packages -Preference "Winget"
@($result[[PackageManagers]::Winget]).Count | Should -Be 0
@($result[[PackageManagers]::Choco]).Count | Should -Be 0
@($result["Winget"]).Count | Should -Be 0
@($result["Choco"]).Count | Should -Be 0
}
It "deduplicates package IDs" {
@@ -75,17 +65,17 @@ Describe "Get-WinUtilSelectedPackages" {
[pscustomobject]@{ winget = "VideoLAN.VLC"; choco = "vlc" }
)
$result = Get-WinUtilSelectedPackages -PackageList $packages -Preference ([PackageManagers]::Choco)
$result = Get-WinUtilSelectedPackages -PackageList $packages -Preference "Choco"
(@($result[[PackageManagers]::Choco]) -join "|") | Should -Be "git|vlc"
@($result[[PackageManagers]::Winget]).Count | Should -Be 0
(@($result["Choco"]) -join "|") | Should -Be "git|vlc"
@($result["Winget"]).Count | Should -Be 0
}
It "returns empty package lists for an empty selection" {
$result = Get-WinUtilSelectedPackages -PackageList @() -Preference ([PackageManagers]::Winget)
$result = Get-WinUtilSelectedPackages -PackageList @() -Preference "Winget"
@($result[[PackageManagers]::Winget]).Count | Should -Be 0
@($result[[PackageManagers]::Choco]).Count | Should -Be 0
@($result["Winget"]).Count | Should -Be 0
@($result["Choco"]).Count | Should -Be 0
}
}
+6 -16
View File
@@ -5,16 +5,6 @@
BeforeAll {
$script:repoRoot = (Resolve-Path (Join-Path $PSScriptRoot "..")).Path
if (-not ("PackageManagers" -as [type])) {
Add-Type @"
public enum PackageManagers
{
Winget,
Choco
}
"@
}
if (-not ("Windows.Media.SolidColorBrush" -as [type])) {
Add-Type @"
namespace Windows.Media
@@ -213,10 +203,10 @@ Describe "Set-Preferences" {
Set-Preferences
$script:sync.preferences.theme | Should -Be "Auto"
$script:sync.preferences.packagemanager | Should -Be ([PackageManagers]::Winget)
$script:sync.preferences.packagemanager | Should -Be "Winget"
}
It "loads saved preferences and converts the package manager to an enum" {
It "loads saved preferences and keeps the package manager as a string" {
$script:testRoot = New-WinUtilPreferencesTestRoot
$global:winutildir = $script:testRoot
New-WinUtilPreferenceSync
@@ -228,7 +218,7 @@ Describe "Set-Preferences" {
Set-Preferences
$script:sync.preferences.theme | Should -Be "Dark"
$script:sync.preferences.packagemanager | Should -Be ([PackageManagers]::Choco)
$script:sync.preferences.packagemanager | Should -Be "Choco"
}
It "saves current preferences to preferences.ini" {
@@ -236,7 +226,7 @@ Describe "Set-Preferences" {
$global:winutildir = $script:testRoot
New-WinUtilPreferenceSync -Preferences @{
theme = "Light"
packagemanager = [PackageManagers]::Winget
packagemanager = "Winget"
}
Set-Preferences -save
@@ -256,7 +246,7 @@ Describe "Set-Preferences" {
Set-Preferences
$script:sync.preferences.theme | Should -Be "Light"
$script:sync.preferences.packagemanager | Should -Be ([PackageManagers]::Choco)
$script:sync.preferences.packagemanager | Should -Be "Choco"
Test-Path (Join-Path $script:testRoot "LightTheme.ini") | Should -BeFalse
Test-Path (Join-Path $script:testRoot "preferChocolatey.ini") | Should -BeFalse
}
@@ -270,7 +260,7 @@ Describe "Set-Preferences" {
Set-Preferences
$script:sync.preferences.theme | Should -Be "Auto"
$script:sync.preferences.packagemanager | Should -Be ([PackageManagers]::Choco)
$script:sync.preferences.packagemanager | Should -Be "Choco"
}
}