style: scope named parameters to multi-arg calls in test scaffolding#18
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 restores the PR #23-era multi-paramset mandatory-skip block on the 'Has correct [mandatory] value' It in Help.tests.ps1 (this repo was carrying the pre-#23 version that doesn't handle parameters with varying IsMandatory status across parameter sets), and fixes a stale $parameterNames reference in the last Context block (should be $commandParameterNames). Both 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 for parameters with consistent IsMandatory across sets; previously-failing-or-flaky tests on multi-paramset parameters will now skip with a clear reason.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughAdds parameter validation attributes to test helper functions; updates ChangesTest Infrastructure Parameter Validation and Help-Test Refinements
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related issues
Possibly related PRs
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 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
This pull request aligns the repository’s inherited test scaffolding and meta-fixer utilities with the canonical PowerShellModuleTemplate conventions (notably named-parameter usage) and includes two audit-driven correctness fixes in the help tests and meta fixers.
Changes:
- Standardize named-parameter usage across
Help.tests.ps1andMeta.tests.ps1(e.g.,Split-Path -Path ... -Parent,Get-Content -Path,Select-String -Pattern,Get-Module -Name). - Reinstate/introduce a skip path in help tests for parameters whose mandatory status differs across parameter sets.
- Strengthen parameter validation in
MetaFixers.psm1and ensureTest-FileUnicodeis invoked with-FileInfo.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| tests/Help.tests.ps1 | Style cleanup + parameter-set-aware mandatory check; fixes a stale variable reference. |
| tests/Meta.tests.ps1 | Style cleanup to use named parameters for consistency. |
| tests/MetaFixers.psm1 | Add validation attributes and align helper calls with named parameters. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Align tests/Help.tests.ps1, tests/Meta.tests.ps1, and tests/MetaFixers.psm1 with the scoped named-parameter rule the template adopted in PowerShellModuleTemplate#36 (ai-agent-instruction-modules#25): name parameters only on calls passing two or more arguments; single-argument calls stay positional. Reverts the over-naming an earlier revision of this branch had added. Test-Path, Get-Module, Get-Help, Get-TextFilesList, Test-FileUnicode, Select-String, Import-Module, Import-PowerShellDataFile, and FilterOutCommonParameters single-argument calls go back to positional, matching the canonical template line-for-line. Multi-argument and trailing-switch calls keep their names (Split-Path -Path $x -Parent, Join-Path, Get-ChildItem -Path $x -Recurse, Get-Content -Path $x -Raw). The MetaFixers validation attributes and the multi-paramset mandatory-skip block are unchanged. Build + Pester pass locally: 785 passed, 0 failed. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
… checks + ManifestHelpers) (#22) * test: align Manifest test with canonical template Bring tests/Manifest.tests.ps1 up to the current PowerShellModuleTemplate shape and add tests/ManifestHelpers.psm1 (copied verbatim) for SemVer-aware version-constraint checks. Replaces the single-version Module Dependency context with the canonical five-test version that validates the manifest's RequiredModules against the dependency file via Test-VersionConstraint (ModuleVersion/RequiredVersion/MaximumVersion -> LessOrEqual/Equal/ GreaterOrEqual), with clear skips for plain-string references and missing/empty versions. Adds $manifestRawData, and carries over the template-only $isTemplate skip plus the skipped 'Git tagging' Describe for fidelity. ReScenePS adaptations: - Reads runtime.depend.psd1 (this repo's renamed requirements file) instead of requirements.psd1. - Preserves the psake Set-BuildEnvironment bootstrap (repo-wide isolation pattern), corrected to the scoped named-parameter rule. - Preserves the foreach changelog parse over the template's ForEach-Object { ... break } (break is unreliable in ForEach-Object). Deferred follow-up to #18. Build + Pester pass locally: 786 passed, 0 failed, 23 skipped. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * test(manifest): parse changelog version with Select-String instead of foreach Replace the foreach-over-Get-Content changelog-version parse with Select-String, which returns the first matching line's named capture group directly — no loop and no break. The foreach existed only to avoid the canonical template's unreliable `ForEach-Object { ... break }`; Select-String removes the need for either form. Mirrors the upstream fix in tablackburn/PowerShellModuleTemplate#37. Build + Pester pass locally: 786 passed, 0 failed, 23 skipped. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Summary
Aligns the test scaffolding this repo inherited from the template (
tests/Help.tests.ps1,tests/Meta.tests.ps1,tests/MetaFixers.psm1) with the scoped named-parameter rule, plus two behavioral fixes the cross-repo audit surfaced.The named-parameter rule was narrowed in ai-agent-instruction-modules#25 and applied to the template's own scaffolding in PowerShellModuleTemplate#36:
An earlier revision of this PR predated that scoping and added names to single-argument calls. This revision matches the canonical template (the source of truth) line-for-line on every shared call site.
tests/Help.tests.ps1Test-Path $path,Get-Module $Env:BHProjectName(×2),Import-Module $moduleManifestPath,Import-PowerShellDataFile $sourceManifest,Get-Help $command.Name,global:FilterOutCommonParameters …. Multi-argument / trailing-switch calls keep their names (Split-Path -Path $x -Parent,Join-Path -Path … -ChildPath …,Get-ChildItem -Path $x -Recurse). Plus the multi-paramset mandatory-skip fix (below).tests/Meta.tests.ps1Import-Module (Join-Path …),Get-TextFilesList $projectRoot,Test-FileUnicode $textFile,Select-String "<tab>"go positional.Get-Content -Path $f -Rawkeeps its names (two args).tests/MetaFixers.psm1[ValidateNotNull()]on$FileInfoinConvertTo-UTF8/ConvertTo-SpaceIndentation;[ValidateNotNullOrEmpty()]on$RootinGet-TextFilesList/Get-UnicodeFilesList(matches template).Test-FileUnicode $_stays positional insideGet-UnicodeFilesList.Why
PowerShellModuleTemplate#36is the source of truth and reverses the "name everything" shape an earlier rule (template #23) had introduced. Naming the only argument of a call adds noise without removing ambiguity, so the scoped rule names parameters only when 2+ arguments are passed (a trailing switch such as-Raw/-Recurse/-Parentcounts; common parameters like-Verbose/-ErrorActiondo not). This PR brings the inherited scaffolds in line with the template's post-#36 files.Two adjacent fixes bundled in per the cross-repo audit (these match the template and are unchanged from the prior revision):
'Has correct [mandatory] value'Itnow skips parameters whoseIsMandatorystatus varies across parameter sets (with a clear reason) and normalizes case before comparing. Behavior is unchanged for parameters with consistentIsMandatory.$parameterNames→$commandParameterNames— stale reference in the lastContextblock was silently passing nothing; the fix activates a previously no-opContext.Out of scope
tests/Manifest.tests.ps1is the older Module Dependency variant (noTest-VersionConstrainthelper, no$isTemplateskip,-Childtypo onJoin-Path, positionalJoin-Pathwhere the template now wants it named) — deferred to a separate uplift PR.Test plan
./build.ps1passes (build + Pester) on the local branch🤖 Generated with Claude Code
Summary by CodeRabbit
Tests
Chores