Skip to content

fix(module): run the Dotfiles helper surface under StrictMode#100

Merged
Gerrrt merged 2 commits into
mainfrom
claude/win-strictmode
Jul 11, 2026
Merged

fix(module): run the Dotfiles helper surface under StrictMode#100
Gerrrt merged 2 commits into
mainfrom
claude/win-strictmode

Conversation

@Gerrrt

@Gerrrt Gerrrt commented Jul 11, 2026

Copy link
Copy Markdown
Collaborator

What

Set Set-StrictMode -Version Latest inside Dotfiles.psm1, so the non-interactive helper surface (core/05-lib.ps1 + the *.Helpers.ps1 files 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:

  • Not profile.ps1 or the core/os fragments — those are dot-sourced into the interactive session, so StrictMode there would change everyday shell behaviour (referencing an unset $var interactively would start throwing). The audit rated that "defensible as-is," and per-fragment try/catch already isolates load failures.
  • Yes the Dotfiles moduleSet-StrictMode inside a .psm1 is module-scoped. Even under Import-Module -Global (how profile.ps1 loads 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 / WslBridge suites already exercise the surface via Import-Module Dotfiles.psd1, so they now run those helpers under the module's StrictMode automatically. Lib.Tests.ps1 dot-sources core/05-lib.ps1 directly, so it now sets StrictMode in its BeforeAll to 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.psm1Set-StrictMode -Version Latest (module-scoped).
  • tests/Lib.Tests.ps1 — StrictMode in BeforeAll so the directly-dot-sourced helpers are covered.
  • CHANGELOG.md[Unreleased] → Fixed entry.

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

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
Copilot AI review requested due to automatic review settings July 11, 2026 14:55

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.psm1 so helper functions error on common latent issues (unbound vars / missing properties) instead of returning $null.
  • Update tests/Lib.Tests.ps1 to 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.

Comment thread tests/Lib.Tests.ps1 Outdated
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
@Gerrrt Gerrrt merged commit 3ce7522 into main Jul 11, 2026
6 checks passed
@Gerrrt Gerrrt deleted the claude/win-strictmode branch July 11, 2026 15:01
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.

3 participants