From 2c97c3e688a2267414730f1159185a52aba45ba5 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Mon, 8 Dec 2025 04:14:27 +0000 Subject: [PATCH] Fix: Use standard exit code 0 for success The script previously used `[Environment]::Exit(100)` to indicate a successful self-update. This non-standard exit code could be misinterpreted as an error by automation tools. This commit changes the exit code to the conventional `0` for success and uses the more idiomatic `exit` keyword. A Pester test has been added to verify this behavior. --- src/universal-intel-chipset-updater.ps1 | 4 +-- tests/exit-code.test.ps1 | 43 +++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 tests/exit-code.test.ps1 diff --git a/src/universal-intel-chipset-updater.ps1 b/src/universal-intel-chipset-updater.ps1 index 957fe56..d694ce5 100644 --- a/src/universal-intel-chipset-updater.ps1 +++ b/src/universal-intel-chipset-updater.ps1 @@ -431,8 +431,8 @@ function Check-ForUpdaterUpdates { Start-Process -FilePath $outputPath # Exit immediately without any user interaction - # Use exit code 100 to indicate successful launch of new version - [Environment]::Exit(100) + # Use exit code 0 to indicate successful launch of new version + exit 0 } else { Write-Host "`n Update cancelled by user." -ForegroundColor Yellow Cleanup diff --git a/tests/exit-code.test.ps1 b/tests/exit-code.test.ps1 new file mode 100644 index 0000000..a64f4dc --- /dev/null +++ b/tests/exit-code.test.ps1 @@ -0,0 +1,43 @@ +Describe 'universal-intel-chipset-updater.ps1' { + It 'should exit with code 0 after launching a new version' { + # Define dummy functions for Pester to find and mock. + function Show-Screen1 { } + function Verify-ScriptHash { } + function Invoke-WebRequest { } + function Read-Host { } + function Get-DownloadsFolder { } + function Start-Process { } + function Cleanup { } + function Show-FinalCredits { } + + # Mock the behavior of the functions for this test case. + Mock -CommandName Show-Screen1 { } + Mock -CommandName Verify-ScriptHash { return $true } + Mock -CommandName Get-DownloadsFolder { return '/tmp' } + Mock -CommandName Start-Process { } + Mock -CommandName Cleanup { } + Mock -CommandName Show-FinalCredits { } + + # Mock the network call to simulate finding a newer version. + Mock -CommandName Invoke-WebRequest { + return @{ Content = "99.9-9999.99.99" } # A fake, newer version + } + + # Mock user input to follow the "download and exit" code path. + $userInput = @('N', 'Y', 'Y') # Prompts: Continue? -> N, Download? -> Y, Exit? -> Y + $inputCounter = 0 + Mock -CommandName Read-Host { + $response = $userInput[$inputCounter] + $script:inputCounter++ + return $response + } + + # Wrap the script execution in a function + function Invoke-ScriptForTest { + . ./src/universal-intel-chipset-updater.ps1 + } + + # Assert that the script attempts to exit with a code of '0'. + Should -ScriptBlock ${function:Invoke-ScriptForTest} -Throw -ExceptionType ([System.Management.Automation.ExitException]) -WithMessage '0' + } +}