fix(module): run the Dotfiles helper surface under StrictMode#100
Merged
Conversation
The non-interactive helper surface (Dotfiles.psm1 -> core/05-lib.ps1 + the *.Helpers.ps1 files) ran without Set-StrictMode, so an unbound variable, a missing property, or a bad array index silently yielded $null instead of an error. Set Set-StrictMode -Version Latest inside the module. Scoped to the module on purpose: even under `Import-Module -Global` (how profile.ps1 loads it) this does NOT touch the interactive session, which stays lenient — a blanket StrictMode on the dot-sourced interactive layer would change everyday shell behaviour, so it deliberately stays off there. Validation: the Serve/Doctor/Help/WslBridge suites already exercise the surface via Import-Module (so they now run it under the module's StrictMode), and Lib.Tests.ps1 sets StrictMode in its BeforeAll so the directly-dot-sourced 05-lib helpers are covered too. Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01MbS29qHuYaG2AUnmXkKD96
There was a problem hiding this comment.
Pull request overview
This PR hardens the repository’s non-interactive PowerShell helper surface by enabling Set-StrictMode -Version Latest at the Dotfiles module scope, and adjusts test coverage so CI validates those helpers under StrictMode.
Changes:
- Enable module-scoped StrictMode in
powershell/Dotfiles/Dotfiles.psm1so helper functions error on common latent issues (unbound vars / missing properties) instead of returning$null. - Update
tests/Lib.Tests.ps1to run the dot-sourced helper library under StrictMode as well. - Document the behavior change in
CHANGELOG.md.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| powershell/Dotfiles/Dotfiles.psm1 | Sets module-scoped StrictMode before dot-sourcing helper surfaces. |
| tests/Lib.Tests.ps1 | Adjusts StrictMode setup for helper tests to align with module behavior. |
| CHANGELOG.md | Adds an Unreleased “Fixed” entry documenting the StrictMode hardening. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Match the Dotfiles module (which sets StrictMode before it dot-sources the helpers) so the file is loaded and exercised under the same strict mode — and so the intent comment holds even if a helper file ever grows top-level code. Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01MbS29qHuYaG2AUnmXkKD96
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.
What
Set
Set-StrictMode -Version LatestinsideDotfiles.psm1, so the non-interactive helper surface (core/05-lib.ps1+ the*.Helpers.ps1files it re-exports) runs strict — an unbound variable, a missing property, or a bad array index now errors instead of silently returning$null.Why this placement (and not the interactive profile)
The static-analysis audit flagged that the PowerShell surface never sets StrictMode. The subtlety is where it's safe:
profile.ps1or thecore/osfragments — those are dot-sourced into the interactive session, so StrictMode there would change everyday shell behaviour (referencing an unset$varinteractively would start throwing). The audit rated that "defensible as-is," and per-fragmenttry/catchalready isolates load failures.Dotfilesmodule —Set-StrictModeinside a.psm1is module-scoped. Even underImport-Module -Global(howprofile.ps1loads it), it hardens the module's own functions without touching the interactive session. That's exactly the "module surface" the audit pointed at.Validation (the part that was missing)
A hardening you can't test isn't worth much. The
Serve/Doctor/Help/WslBridgesuites already exercise the surface viaImport-Module Dotfiles.psd1, so they now run those helpers under the module's StrictMode automatically.Lib.Tests.ps1dot-sourcescore/05-lib.ps1directly, so it now sets StrictMode in itsBeforeAllto cover the remaining pure helpers. CI's Pester run (Invoke-Validation.ps1) therefore validates the whole surface under strict mode — if any helper has a latent unbound-var/property/index bug, the suite fails here rather than in a real session.Changes
powershell/Dotfiles/Dotfiles.psm1—Set-StrictMode -Version Latest(module-scoped).tests/Lib.Tests.ps1— StrictMode inBeforeAllso the directly-dot-sourced helpers are covered.CHANGELOG.md—[Unreleased] → Fixedentry.Note
I authored this without a local PowerShell/Pester runner, so I'm relying on this repo's CI Pester suite as the validation gate. If it surfaces a latent StrictMode violation in a helper, that's the guard doing its job — I'll follow up with the fix.
🤖 Generated with Claude Code
Generated by Claude Code