fix(install): add Set-StrictMode to install.ps1#33
Merged
Conversation
rules/powershell/powershell-strict-mode.md, shipped by this repo, opens its "What you do not do" list with: "Ship a .ps1 without `Set-StrictMode -Version Latest` and `$ErrorActionPreference = 'Stop'`." install.ps1 had the second and not the first. It matters here specifically. The script resolves destination paths from variables and then removes and copies directories under them. Without strict mode a misspelled variable expands to $null rather than erroring, and a $null path is exactly the input those Remove-Item / Copy-Item calls must never receive. The existing guards -- Test-Path, -LiteralPath, Join-Path -- are good; strict mode is the one that catches the typo before it reaches them. Its sibling scripts/install.sh already carries `set -euo pipefail` and quotes every expansion, so the shell installer was compliant and the PowerShell one was not. Behavior-preserving. Verified by running both the original and the modified script from the same path with the same arguments in a throwaway worktree: -Target claude/cursor/codex/opencode with -Project, then -Uninstall, all exit 0 under both, with no StrictMode terminating errors. -Help exits 0 and a missing -Target still errors with exit 1.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The repo violates its own rule
rules/powershell/powershell-strict-mode.md— shipped by this repo, synced to four harnesses — opens its "What you do not do" list with:It had the second and not the first. Meanwhile
scripts/install.shcarriesset -euo pipefailand quotes every expansion — the shell installer was compliant, the PowerShell one was not.Why it matters here specifically
install.ps1resolves destination paths from variables and then removes and copies directories under them:Without strict mode a misspelled variable expands to
$nullinstead of erroring — and a$nullpath is precisely what thoseRemove-Itemcalls must never receive. The existing guards (Test-Path,-LiteralPath,Join-Path) are all correct; strict mode is the one that catches the typo before it reaches them. That is the rule's own argument, quoted back at the script.Behavior-preserving — verified, not assumed
Strict mode turns a non-existent property access into a terminating error, so this could plausibly break the script. It doesn't. Both the original and the modified script were run from the same path with the same arguments in a throwaway worktree — the only difference being the one added line:
Full matrix on the modified script:
-Target claude|cursor|codex|opencodewith-Project, then again with-Uninstall— all eight runs exit 0, noVariableIsUndefined/PropertyNotFoundStricterrors.-Helpexits 0; a missing-Targetstill errors with exit 1.Verification
install.ps1is not synced into any harness output, so no generated file changes.