style: re-sync test scaffolding to canonical template (post-#36)#55
Conversation
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.
📝 WalkthroughWalkthroughAdds 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. ChangesTest Infrastructure Robustness
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related issues
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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.psm1for mandatory parameters ([ValidateNotNull()],[ValidateNotNullOrEmpty()]). - Fix
$parameterNames→$commandParameterNamesin 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.
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>
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>
* 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>
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
#36 explicitly names this PR as a consumer to re-sync. This revision does that.
Changes
maintests/MetaFixers.psm1tests/Meta.tests.ps1tests/Help.tests.ps1Set-BuildEnvironmentbootstrap, theFilterOutCommonParameterscomment-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:FilterOutCommonParametersMeta.tests.ps1:Import-ModuleMetaFixers.psm1: theTest-FileUnicodecall insideGet-UnicodeFilesListThis 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)
Split-Path -Path … -Parent,Join-Path -Path … -ChildPath …,Get-Content -Path … -Raw(a trailing switch counts as an argument).[ValidateNotNull()]/[ValidateNotNullOrEmpty()]inMetaFixers.psm1. Added by template feat: add extended media details to Search-PatMedia output #23, not reverted by fix: Validate PSScriptAnalyzer availability and harden WhatIf tests #36..EXAMPLEcalls — left named for teaching clarity, matching fix: Validate PSScriptAnalyzer availability and harden WhatIf tests #36.The
$parameterNames→$commandParameterNamesfix from the original version of this PR is no longer in the diff: it has since landed onmainindependently (via #60).Behavior
Unchanged — every reverted call's positional binding is equivalent to the named form.
Test plan
PSUseBOMForUnicodeEncodedFilewarning onHelp.tests.ps1by replacing two em-dashes in a comment with ASCII hyphens)🤖 Generated with Claude Code