Skip to content

fix(install): add Set-StrictMode to install.ps1#33

Merged
MANVENDRA-github merged 1 commit into
mainfrom
fix/install-ps1-strict-mode
Jul 8, 2026
Merged

fix(install): add Set-StrictMode to install.ps1#33
MANVENDRA-github merged 1 commit into
mainfrom
fix/install-ps1-strict-mode

Conversation

@MANVENDRA-github

Copy link
Copy Markdown
Owner

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:

Ship a .ps1 without Set-StrictMode -Version Latest and $ErrorActionPreference = 'Stop'.

$ grep -c 'Set-StrictMode'        scripts/install.ps1   →  0
$ grep -c 'ErrorActionPreference' scripts/install.ps1   →  1

It had the second and not the first. Meanwhile scripts/install.sh carries set -euo pipefail and quotes every expansion — the shell installer was compliant, the PowerShell one was not.

Why it matters here specifically

install.ps1 resolves destination paths from variables and then removes and copies directories under them:

$targetPath = Join-Path $destSub $entry.Name
if (Test-Path -LiteralPath $targetPath) {
    Remove-Item -LiteralPath $targetPath -Recurse -Force
}

Without strict mode a misspelled variable expands to $null instead of erroring — and a $null path is precisely what those Remove-Item calls 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:

             target     exit
no-strict    claude      0
no-strict    opencode    0
STRICT       claude      0
STRICT       opencode    0

Full matrix on the modified script: -Target claude|cursor|codex|opencode with -Project, then again with -Uninstallall eight runs exit 0, no VariableIsUndefined / PropertyNotFoundStrict errors. -Help exits 0; a missing -Target still errors with exit 1.

Verification

$ npm run sync   # clean, no drift
$ npm run lint   # PASS
$ npm test       # 239 pass, 0 fail

install.ps1 is not synced into any harness output, so no generated file changes.

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.
@MANVENDRA-github
MANVENDRA-github merged commit cff8e5d into main Jul 8, 2026
3 checks passed
@MANVENDRA-github
MANVENDRA-github deleted the fix/install-ps1-strict-mode branch July 8, 2026 18:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant