Skip to content

style: re-sync test scaffolding to canonical template (post-#36)#55

Merged
tablackburn merged 5 commits into
mainfrom
style/align-test-scaffolding-with-template
May 29, 2026
Merged

style: re-sync test scaffolding to canonical template (post-#36)#55
tablackburn merged 5 commits into
mainfrom
style/align-test-scaffolding-with-template

Conversation

@tablackburn
Copy link
Copy Markdown
Owner

@tablackburn tablackburn commented May 12, 2026

Summary

Re-syncs this repo's inherited test scaffolding to the current canonical template — specifically PowerShellModuleTemplate#36, which scoped the named-parameter rule after this branch was first opened.

Background: the rule changed under us

Template PR Date Effect
#23 2026-05-10 Named parameters everywhere + validators
this PR opened 2026-05-12 Applied #23's "name everything" style
#36 2026-05-27 Scoped it back: name parameters only on calls passing two or more arguments (a trailing switch counts); single-argument calls stay positional

#36 explicitly names this PR as a consumer to re-sync. This revision does that.

Changes

File Result vs. upstream main
tests/MetaFixers.psm1 Byte-identical to upstream
tests/Meta.tests.ps1 Byte-identical to upstream
tests/Help.tests.ps1 Matches upstream except this repo's local divergences (the Set-BuildEnvironment bootstrap, the FilterOutCommonParameters comment-based help, and the mandatory-value note)

What went back to positional (single-argument calls)

  • Help.tests.ps1: Import-PowerShellDataFile, Test-Path, Import-Module, Get-Help, global:FilterOutCommonParameters
  • Meta.tests.ps1: Import-Module
  • MetaFixers.psm1: the Test-FileUnicode call inside Get-UnicodeFilesList

This includes pre-existing over-naming the branch carried beyond the original style sweep (e.g. Get-Help -Name, global:FilterOutCommonParameters -Parameters), so the files are now genuinely canonical rather than "the old sweep minus its mistakes."

What stays named (intentionally)

The $parameterNames$commandParameterNames fix from the original version of this PR is no longer in the diff: it has since landed on main independently (via #60).

Behavior

Unchanged — every reverted call's positional binding is equivalent to the named form.

Test plan

  • All three files parse with no syntax errors
  • PSScriptAnalyzer: clean on all three files (also fixes a pre-existing PSUseBOMForUnicodeEncodedFile warning on Help.tests.ps1 by replacing two em-dashes in a comment with ASCII hyphens)
  • CI passes on Linux / macOS / Windows runners

🤖 Generated with Claude Code

Apply the three style rules from PowerShellModuleTemplate#23 to the
Help/Meta/MetaFixers test files this repo inherited from the template:

- Named parameters on multi-arg cmdlet calls (Split-Path, Join-Path,
  Test-Path, Get-Module, Get-Content, Select-String, Get-TextFilesList,
  Test-FileUnicode)
- ValidateNotNull / ValidateNotNullOrEmpty validators on mandatory
  param entries in tests/MetaFixers.psm1
- Test-FileUnicode call inside Get-UnicodeFilesList now uses named
  -FileInfo parameter

Also fixes a stale $parameterNames reference in the last Context block
of Help.tests.ps1 (should be $commandParameterNames). Bug bundled in
per the cross-repo audit.

tests/Manifest.tests.ps1 is the older Module Dependency variant
(no Test-VersionConstraint helper, -Child typo on Join-Path) and is
deferred to a separate uplift PR.

Behavior is unchanged.
Copilot AI review requested due to automatic review settings May 12, 2026 04:25
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 12, 2026

📝 Walkthrough

Walkthrough

Adds parameter validation to test helper cmdlets, changes test callers to use explicit parameters, and refines Help test setup to compute build paths from PSScriptRoot parent, guard type-folder recursion, and simplify module unloading.

Changes

Test Infrastructure Robustness

Layer / File(s) Summary
Test helper parameter validation
tests/MetaFixers.psm1
ConvertTo-UTF8 and ConvertTo-SpaceIndentation add [ValidateNotNull()] to FileInfo; Get-TextFilesList and Get-UnicodeFilesList add [ValidateNotNullOrEmpty()] to Root; Get-UnicodeFilesList calls Test-FileUnicode -FileInfo $_.
Help test environment initialization
tests/Help.tests.ps1
Set-BuildEnvironment now computes path with Split-Path -Path $PSScriptRoot -Parent in BeforeDiscovery and BeforeAll; when BHBuildOutput is unset, $projectRoot is derived from that parent, $sourceManifest is located at "$Env:BHProjectName/$Env:BHProjectName.psd1", ModuleVersion is read, and BHBuildOutput set to Output/<ModuleName>/<ModuleVersion>; custom type enumeration guards with Test-Path; module removal uses Get-Module -Name.
Test caller updates for helper compatibility
tests/Meta.tests.ps1, tests/Help.tests.ps1
Get-TextFilesList is invoked with explicit -Root $projectRoot; tab-detection uses Select-String -Pattern "t"; help-parameter assertion verifies membership in $commandParameterNames`.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

Poem

🐰 Hop, hop, the tests refine their art,

Params guarded close, no nulls to start,
Paths computed neat from PSScriptRoot's tree,
Tabs found by pattern, explicit as can be,
A little rabbit clap for robust TDD!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title accurately summarizes the main objective: aligning test scaffolding with the canonical template through style rule application, with reference to the preceding PR that established those rules.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch style/align-test-scaffolding-with-template

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Aligns this repository’s inherited test scaffolding with the canonical PowerShellModuleTemplate style rules (named parameters for multi-arg cmdlets, mandatory-parameter validators), and fixes a stale variable reference that previously made part of the help-parameter verification effectively a no-op.

Changes:

  • Standardize named-parameter usage across Help/Meta tests (e.g., Split-Path, Join-Path, Get-Module, Get-Content, Select-String).
  • Add parameter validators in tests/MetaFixers.psm1 for mandatory parameters ([ValidateNotNull()], [ValidateNotNullOrEmpty()]).
  • Fix $parameterNames$commandParameterNames in the help tests so the “extra help parameters” check actually evaluates.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
tests/Help.tests.ps1 Uses named parameters for several cmdlet calls and fixes a stale variable reference so the relevant Context block is no longer a no-op.
tests/Meta.tests.ps1 Applies named parameters to calls into MetaFixers and standard cmdlets (Get-Content, Select-String).
tests/MetaFixers.psm1 Adds validators for mandatory params and updates Test-FileUnicode invocation to use the explicit -FileInfo parameter.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

tablackburn and others added 3 commits May 25, 2026 11:16
PowerShellModuleTemplate#36 (merged after this branch opened) scoped the
named-parameter rule: name parameters only on calls passing two or more
arguments (a trailing switch counts); single-argument calls stay
positional. #36 explicitly calls out this PR as a consumer to re-sync.

Revert the over-naming on single-argument calls so these files match the
current canonical template:

- Help.tests.ps1: Import-PowerShellDataFile, Test-Path, Import-Module,
  Get-Help, and global:FilterOutCommonParameters back to positional.
  Split-Path -Path .. -Parent and Join-Path -Path .. -ChildPath stay
  named (two-plus arguments).
- Meta.tests.ps1: Import-Module back to positional; Get-Content -Path
  .. -Raw stays named (switch counts as an argument).
- MetaFixers.psm1: Test-FileUnicode call in Get-UnicodeFilesList back to
  positional.

Kept: the four ValidateNotNull/ValidateNotNullOrEmpty validators (added
by template #23, not reverted by #36) and the comment-based-help
.EXAMPLE calls (#36 leaves these named for teaching clarity).

MetaFixers.psm1 and Meta.tests.ps1 are now byte-identical to upstream;
Help.tests.ps1 differs only in this repo's local divergences (the
Set-BuildEnvironment bootstrap and comment-based help). Behavior
unchanged.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@tablackburn tablackburn changed the title style: align test scaffolding with canonical PSMTplt style: re-sync test scaffolding to canonical template (post-#36) May 29, 2026
The two em-dashes (U+2014) in the local Set-BuildEnvironment comment
block were the sole non-ASCII content in the file, tripping
PSScriptAnalyzer's PSUseBOMForUnicodeEncodedFile rule. Replace them with
ASCII hyphens so the file is pure ASCII (matching the canonical template
files) and PSSA is clean without adding a BOM or a suppression.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@tablackburn tablackburn merged commit 58d18d8 into main May 29, 2026
15 checks passed
@tablackburn tablackburn deleted the style/align-test-scaffolding-with-template branch May 29, 2026 01:13
tablackburn added a commit that referenced this pull request May 29, 2026
* ci: pin PSScriptAnalyzer version in the lint job

The PSScriptAnalyzer Lint job installed PSScriptAnalyzer unpinned and
called Invoke-ScriptAnalyzer without an explicit Import-Module, so it
ignored the 1.24.0 pin in build.depend.psd1 (which only the build/test
jobs honor via PSDepend). On a cache hit the install step was skipped
entirely, letting the runner image's bundled copy load alongside the
cached one and crash with "You cannot have more than one dynamic module
in each dynamic assembly in this version of the runtime" (seen on main
after #55, while the identical PR tree had passed minutes earlier).

Read the pinned version from build.depend.psd1, install that exact
version (verified present even on a cache hit), and import it explicitly
with -RequiredVersion before Invoke-ScriptAnalyzer so exactly one
assembly version loads. The cache key already hashes build.depend.psd1,
so the installed version and cache stay coupled with a single source of
truth.

Verified in a pwsh 7.5 / ubuntu-24.04 container: with a polluted module
path (1.25.0 pre-installed), the step still installs and loads exactly
1.24.0 and analyzes cleanly.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* ci: fail fast on PSScriptAnalyzer install/import errors

Add -ErrorAction 'Stop' to Install-Module and Import-Module in the lint
job. In PowerShell 7 these emit non-terminating errors by default, so a
failed install or import would not stop the step and Invoke-ScriptAnalyzer
could run with a missing or wrong module version - the exact condition
this job pins against. Addresses CodeRabbit review feedback on #62.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.

2 participants