From 83a4ad15c6c73df2da7a328e94821b86cdd01f03 Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Mon, 19 Oct 2026 12:11:38 +0200 Subject: [PATCH] Preserve signed WinGet exit code bits --- TASKS.md | 2 ++ src/Packages.psm1 | 2 +- tests/Packages.Tests.ps1 | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/TASKS.md b/TASKS.md index eac62bb..5542fc8 100644 --- a/TASKS.md +++ b/TASKS.md @@ -121,3 +121,5 @@ open until it is run on disposable machines with the required account setups. - [x] Add a one-command config-only updater using the saved machine and a fresh repository revision, with failure and cleanup tests. - [x] Simplify the README around setup and web config updates; move detailed CLI workflows into an advanced guide. + +- [x] Preserve signed WinGet HRESULT bits without UInt32 overflow and test diagnostic capture. diff --git a/src/Packages.psm1 b/src/Packages.psm1 index ba996ae..1b67918 100644 --- a/src/Packages.psm1 +++ b/src/Packages.psm1 @@ -20,7 +20,7 @@ function Invoke-WingetCapture { $process = Start-Process -FilePath 'winget.exe' -ArgumentList $Arguments -Wait -PassThru -NoNewWindow -RedirectStandardOutput $outputPath -RedirectStandardError $errorPath $output = ((Get-Content -LiteralPath $outputPath -Raw -ErrorAction SilentlyContinue), (Get-Content -LiteralPath $errorPath -Raw -ErrorAction SilentlyContinue) -join [Environment]::NewLine).Trim() if ($LogPath) { $output | Add-Content -LiteralPath $LogPath -Encoding utf8 } - [pscustomobject]@{ exitCode = $process.ExitCode; unsignedExitCode = [uint32]$process.ExitCode; output = $output } + [pscustomobject]@{ exitCode = $process.ExitCode; unsignedExitCode = [BitConverter]::ToUInt32([BitConverter]::GetBytes([int32]$process.ExitCode), 0); output = $output } } finally { Remove-Item -LiteralPath $outputPath, $errorPath -Force -ErrorAction SilentlyContinue diff --git a/tests/Packages.Tests.ps1 b/tests/Packages.Tests.ps1 index c637ae2..a24ccdd 100644 --- a/tests/Packages.Tests.ps1 +++ b/tests/Packages.Tests.ps1 @@ -34,3 +34,36 @@ Describe 'Package planning' { } } } + +Describe 'WinGet signed process exit codes' { + It 'preserves the HRESULT bits and diagnostics for a negative exit code' { + InModuleScope Packages { + Mock Start-Process { + 'WinGet diagnostic' | Set-Content -LiteralPath $RedirectStandardError + [pscustomobject]@{ ExitCode = -1978335189 } + } + $result = Invoke-WingetCapture -Arguments @('export') + $result.exitCode | Should -Be -1978335189 + $result.unsignedExitCode | Should -Be 2316632107 + $result.output | Should -Match 'WinGet diagnostic' + { $result | ConvertTo-Json } | Should -Not -Throw + } + } + It 'recognizes a signed no-applicable-upgrade result' { + InModuleScope Packages { + Mock Start-Process { [pscustomobject]@{ ExitCode = -1978335189 } } + $operation = [pscustomobject]@{ + action = 'Upgrade'; name = 'Test.App' + package = [pscustomobject]@{ id = 'Test.App'; source = 'winget' } + } + (Invoke-PackageOperation -Operation $operation).status | Should -Be 'Unchanged' + } + } + It 'preserves ordinary reboot exit codes' { + InModuleScope Packages { + Mock Start-Process { [pscustomobject]@{ ExitCode = 3010 } } + $result = Invoke-WingetCapture -Arguments @('install') + $result.unsignedExitCode | Should -Be 3010 + } + } +}