Skip to content

style: scope named parameters to multi-arg calls in test scaffolding#18

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

style: scope named parameters to multi-arg calls in test scaffolding#18
tablackburn merged 3 commits into
mainfrom
style/align-test-scaffolding-with-template

Conversation

@tablackburn
Copy link
Copy Markdown
Owner

@tablackburn tablackburn commented May 12, 2026

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:

Name parameters only on calls that pass two or more arguments; a single-argument call stays positional.

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.

File Change
tests/Help.tests.ps1 Single-argument calls go positional to match the template: Test-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.ps1 Import-Module (Join-Path …), Get-TextFilesList $projectRoot, Test-FileUnicode $textFile, Select-String "<tab>" go positional. Get-Content -Path $f -Raw keeps its names (two args).
tests/MetaFixers.psm1 [ValidateNotNull()] on $FileInfo in ConvertTo-UTF8/ConvertTo-SpaceIndentation; [ValidateNotNullOrEmpty()] on $Root in Get-TextFilesList/Get-UnicodeFilesList (matches template). Test-FileUnicode $_ stays positional inside Get-UnicodeFilesList.

Why

PowerShellModuleTemplate#36 is 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/-Parent counts; common parameters like -Verbose/-ErrorAction do 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):

  1. Multi-paramset mandatory-skip block — the 'Has correct [mandatory] value' It now skips parameters whose IsMandatory status varies across parameter sets (with a clear reason) and normalizes case before comparing. Behavior is unchanged for parameters with consistent IsMandatory.
  2. $parameterNames$commandParameterNames — stale reference in the last Context block was silently passing nothing; the fix activates a previously no-op Context.

Out of scope

tests/Manifest.tests.ps1 is the older Module Dependency variant (no Test-VersionConstraint helper, no $isTemplate skip, -Child typo on Join-Path, positional Join-Path where the template now wants it named) — deferred to a separate uplift PR.

Test plan

  • ./build.ps1 passes (build + Pester) on the local branch
  • CI passes on Linux / macOS / Windows runners
  • PSScriptAnalyzer remains clean

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Tests

    • Improved test suite: stricter input validation for utilities, more robust help/parameter assertions (handles varying parameter requirements across contexts), and enhanced discovery/setup behavior to reduce false positives.
  • Chores

    • Adjusted test setup and path handling for more reliable module loading and content checks; standardized invocation styles for test helpers.

Review Change Stack

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.
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

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 91b46ad0-59a9-4392-8c6c-89867645d4ab

📥 Commits

Reviewing files that changed from the base of the PR and between 025e417 and 26db59f.

📒 Files selected for processing (3)
  • tests/Help.tests.ps1
  • tests/Meta.tests.ps1
  • tests/MetaFixers.psm1

📝 Walkthrough

Walkthrough

Adds parameter validation attributes to test helper functions; updates tests/Meta.tests.ps1 call sites; and refines tests/Help.tests.ps1 bootstrap (path/BHBuildOutput), module import, help discovery calls, and per-parameter mandatory/presence assertions.

Changes

Test Infrastructure Parameter Validation and Help-Test Refinements

Layer / File(s) Summary
Test helper parameter validation
tests/MetaFixers.psm1
Adds [ValidateNotNull()] to FileInfo parameters of ConvertTo-UTF8 and ConvertTo-SpaceIndentation, and [ValidateNotNullOrEmpty()] to Root parameters of Get-TextFilesList and Get-UnicodeFilesList.
Meta tests call-site updates
tests/Meta.tests.ps1
Import-Module now receives the module path positionally; Get-Content is invoked with -Path $fileName -Raw in the tabs/indentation check.
Help tests bootstrap, import, discovery, and assertions
tests/Help.tests.ps1
When BHBuildOutput is unset recompute project root with Split-Path -Path $PSScriptRoot -Parent, rebuild $Env:BHBuildOutput via Join-Path, call Import-Module $moduleManifestPath positionally, use positional args for Get-Help/FilterOutCommonParameters in BeforeDiscovery/BeforeAll, aggregate IsMandatory across parameter sets and skip mismatched cases, compare mandatory/required as lowercased strings, and assert help parameters against $commandParameterNames.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

Possibly related PRs

  • tablackburn/ReScenePS#11: Overlaps in tests/Help.tests.ps1 bootstrap logic and use of Split-Path -Parent for build environment setup.

Poem

🐰 I nudge the params to be non-null and neat,
Tests hop in line with paths that repeat.
Imports now tidy, help checks more wise,
A rabbit-approved patch — trimmed, clean, and precise. 🥕

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the primary change: applying style conventions to test scaffolding files by properly scoping named parameters to multi-argument calls, which is the core pattern throughout the changeset.
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.

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

✨ Finishing Touches
🧪 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

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

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.ps1 and Meta.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.psm1 and ensure Test-FileUnicode is 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.

Comment thread tests/Help.tests.ps1
@codecov
Copy link
Copy Markdown

codecov Bot commented May 12, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

tablackburn and others added 2 commits May 25, 2026 11:16
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>
@tablackburn tablackburn changed the title style: align test scaffolding with canonical PSMTplt style: scope named parameters to multi-arg calls in test scaffolding May 27, 2026
@tablackburn tablackburn merged commit 5398591 into main May 28, 2026
12 checks passed
@tablackburn tablackburn deleted the style/align-test-scaffolding-with-template branch May 28, 2026 23:30
tablackburn added a commit that referenced this pull request May 29, 2026
… 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>
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