From 43fc6214e2ab7c32be485f341ab3e9e07822842a Mon Sep 17 00:00:00 2001 From: mstrhakr Date: Fri, 16 Oct 2026 11:53:20 -0400 Subject: [PATCH] fix(setup): exit gracefully when initial setup is canceled Return exit code zero when Cancel or window close dismisses the initial setup dialog so the verified loader does not report an expected cancellation as a startup failure. Add subprocess regression coverage for both dismissal results and document cancellation behavior. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- README.md | 2 ++ src/scans.ps1 | 2 +- tests/Scans.Tests.ps1 | 24 ++++++++++++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e0320f0..9f7673a 100644 --- a/README.md +++ b/README.md @@ -78,6 +78,8 @@ App windows use the PrintMaster logo and attribution. The scan-folder desktop sh Click the gear icon to enable/disable individual steps. +Choosing **Cancel** or closing the initial setup window exits normally without running the selected setup steps or displaying a loader error. + ![Settings](img/scans-settings.png) Wait for the utility to complete all changes. diff --git a/src/scans.ps1 b/src/scans.ps1 index 4084a50..e4d9b18 100644 --- a/src/scans.ps1 +++ b/src/scans.ps1 @@ -735,7 +735,7 @@ if ($setupResult -eq $true) { } else { Write-Verbose "User canceled scanning setup" - Exit 1 + Exit 0 } $details = New-Object System.Collections.ArrayList $script:progressMax = 2 diff --git a/tests/Scans.Tests.ps1 b/tests/Scans.Tests.ps1 index 40dbba4..8065391 100644 --- a/tests/Scans.Tests.ps1 +++ b/tests/Scans.Tests.ps1 @@ -201,6 +201,30 @@ Describe 'Scan account password errors' { } } +Describe 'Setup cancellation' { + It 'exits successfully without continuing setup when Cancel or window close dismisses the dialog' { + $decision = $ast.Find({ + param($node) + $node -is [System.Management.Automation.Language.IfStatementAst] -and + $node.Clauses[0].Item1.Extent.Text -eq '$setupResult -eq $true' + }, $true) + $decision | Should Not BeNullOrEmpty + foreach ($result in @('$false', '$null')) { + $childScript = @( + '$ErrorActionPreference = "Stop"' + "`$setupResult = $result" + $decision.Extent.Text + 'throw "Canceled setup must not continue."' + ) -join "`n" + $encoded = [Convert]::ToBase64String([Text.Encoding]::Unicode.GetBytes($childScript)) + $executable = (Get-Process -Id $PID).Path + $output = & $executable -NoProfile -NonInteractive -STA -EncodedCommand $encoded 2>&1 + $LASTEXITCODE | Should Be 0 + ($output | Out-String).Trim() | Should BeNullOrEmpty + } + } +} + Describe 'Account-dependent setup steps' { BeforeEach { $source = Get-Content $sourcePath -Raw