fix: avoid exiting interactive PowerShell in install script#48983
fix: avoid exiting interactive PowerShell in install script#48983Angrycain wants to merge 2 commits intoopenclaw:mainfrom
Conversation
Greptile SummaryThis PR fixes a UX bug where running the Windows install script via Key changes:
Minor concern: The PR description is entirely blank — all template sections (Problem, Why it matters, Security Impact, Evidence, Human Verification, etc.) are unfilled. Per the template this repository uses, these sections are required. Confidence Score: 4/5
Prompt To Fix All With AIThis is a comment left during a code review.
Path: test/scripts/install.ps1.test.ts
Line: 5-29
Comment:
**Brace parser is fragile to `{`/`}` in string literals**
`extractFunctionBody` counts `{` and `}` characters unconditionally. If a future change adds a PowerShell string literal containing a bare brace inside `Main` (e.g., `Write-Host "See docs at https://example.com/{path}"`) the brace counter will go out of sync and either return a truncated body or throw, causing the test to fail in a confusing way.
Consider anchoring on PowerShell's actual block boundaries (e.g. split on lines and track `function`/`if`/`else` nesting) or, at minimum, add a comment warning future editors that string-literal braces inside `Main` will break this parser.
How can I resolve this? If you propose a fix, please make it concise.Last reviewed commit: 8ccfaa2 |
test/scripts/install.ps1.test.ts
Outdated
| function extractFunctionBody(source: string, name: string): string { | ||
| const signature = `function ${name} {`; | ||
| const start = source.indexOf(signature); | ||
| expect(start).toBeGreaterThanOrEqual(0); | ||
|
|
||
| let depth = 0; | ||
| let bodyStart = -1; | ||
| for (let i = start; i < source.length; i += 1) { | ||
| const char = source[i]; | ||
| if (char === "{") { | ||
| depth += 1; | ||
| if (bodyStart === -1) { | ||
| bodyStart = i + 1; | ||
| } | ||
| continue; | ||
| } | ||
| if (char === "}") { | ||
| depth -= 1; | ||
| if (depth === 0 && bodyStart !== -1) { | ||
| return source.slice(bodyStart, i); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| throw new Error(`Could not extract body for ${name}`); |
There was a problem hiding this comment.
Brace parser is fragile to
{/} in string literals
extractFunctionBody counts { and } characters unconditionally. If a future change adds a PowerShell string literal containing a bare brace inside Main (e.g., Write-Host "See docs at https://example.com/{path}") the brace counter will go out of sync and either return a truncated body or throw, causing the test to fail in a confusing way.
Consider anchoring on PowerShell's actual block boundaries (e.g. split on lines and track function/if/else nesting) or, at minimum, add a comment warning future editors that string-literal braces inside Main will break this parser.
Prompt To Fix With AI
This is a comment left during a code review.
Path: test/scripts/install.ps1.test.ts
Line: 5-29
Comment:
**Brace parser is fragile to `{`/`}` in string literals**
`extractFunctionBody` counts `{` and `}` characters unconditionally. If a future change adds a PowerShell string literal containing a bare brace inside `Main` (e.g., `Write-Host "See docs at https://example.com/{path}"`) the brace counter will go out of sync and either return a truncated body or throw, causing the test to fail in a confusing way.
Consider anchoring on PowerShell's actual block boundaries (e.g. split on lines and track `function`/`if`/`else` nesting) or, at minimum, add a comment warning future editors that string-literal braces inside `Main` will break this parser.
How can I resolve this? If you propose a fix, please make it concise.There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8ccfaa2c11
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
scripts/install.ps1
Outdated
| if (-not $installSucceeded -and $PSCommandPath) { | ||
| exit $script:InstallExitCode |
There was a problem hiding this comment.
Preserve non-zero status for scriptblock installs
The new top-level guard only calls exit when $PSCommandPath is set, but $PSCommandPath is empty when this installer is executed as a scriptblock (for example the documented iwr ... | iex flow), so failed installs now return from Main without a terminating error or process exit code. In non-interactive contexts that invoke the script this way, a failed install can be reported as success (exit code 0), which breaks automation that depends on shell status.
Useful? React with 👍 / 👎.
ReviewGood fix. Replacing The new test ( LGTM. |
Summary
scripts/install.ps1calledexit 1insideMain, which can terminate an interactive PowerShell session when the installer is run viaiexor a downloaded scriptblock.Main; top-level non-zero exit is preserved only for direct script-file execution.Change Type (select all)
Scope (select all touched areas)
Linked Issue/PR
User-visible / Behavior Changes
Failed Windows installs no longer terminate the user's interactive PowerShell session when the installer is run via
iexor a downloaded scriptblock. Direct script-file execution still returns a non-zero exit code on failure.Security Impact (required)
NoNoNoNoNoYes, explain risk + mitigation:Repro + Verification
Environment
Steps
iex/ downloaded scriptblock.Main(for example missing install prerequisites or npm install failure).Expected
Actual
Maincould terminate the current interactive PowerShell session.Evidence
Human Verification (required)
Maindoes not callexitdirectly and that top-level exit remains guarded by direct script execution.Review Conversations
Compatibility / Migration
YesNoNoFailure Recovery (if this breaks)
scripts/install.ps1Risks and Mitigations
exitpath remains in place.AI-assisted: yes
Tested:
corepack pnpm vitest --run test/scripts/install.ps1.test.ts test/scripts/ui.test.ts