Skip to content

style: align test scaffolding with canonical PSMTplt#55

Open
tablackburn wants to merge 1 commit into
mainfrom
style/align-test-scaffolding-with-template
Open

style: align test scaffolding with canonical PSMTplt#55
tablackburn wants to merge 1 commit into
mainfrom
style/align-test-scaffolding-with-template

Conversation

@tablackburn
Copy link
Copy Markdown
Owner

@tablackburn tablackburn commented May 12, 2026

Summary

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

File Change
tests/Help.tests.ps1 Named-parameter cleanup on Split-Path, Join-Path, Test-Path, Get-Module (3 call sites of Split-Path -Parent; 2 each of Join-Path and Get-Module; 1 Test-Path). Plus fixes a stale $parameterNames reference in the last Context block — should be $commandParameterNames.
tests/Meta.tests.ps1 Named parameters on Get-TextFilesList -Root, Test-FileUnicode -FileInfo, Get-Content -Path, Select-String -Pattern.
tests/MetaFixers.psm1 [ValidateNotNull()] on $FileInfo in ConvertTo-UTF8 and ConvertTo-SpaceIndentation; [ValidateNotNullOrEmpty()] on $Root in Get-TextFilesList and Get-UnicodeFilesList. Plus Test-FileUnicode $_Test-FileUnicode -FileInfo $_ inside Get-UnicodeFilesList.

Why

PR #23 brought the template's first-party test files into compliance with the three rules in instructions/powershell.instructions.md (quoted string literals, named multi-arg cmdlet calls, mandatory-param validators). The scaffolds this repo inherited were carrying the pre-#23 shape; this PR closes the gap.

The $parameterNames$commandParameterNames fix bundled into this PR is an adjacent bug found during the cross-repo audit (the stale reference was silently passing nothing — the test as written was effectively a no-op). JsmOps and YouTubeMusicPS already have the correct form.

Behavior is unchanged for the style sweep; the $parameterNames fix activates a Context block that was previously a no-op.

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 at line 163) — deferred to a separate uplift PR that brings the manifest test up to current canonical.

Test plan

  • ./build.ps1 runs the same assertion count as before (or more — the previously-no-op Context block will now execute its It for each $helpParameterNames entry)
  • CI passes on Linux / macOS / Windows runners
  • PSScriptAnalyzer remains clean

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Tests

    • Fixed test setup and environment initialization logic
    • Corrected test assertions for parameter validation
    • Enhanced robustness of file detection tests
  • Chores

    • Added parameter validation to utility functions for improved reliability

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

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: bb81822f-36b9-466a-a254-2e1b27cffe85

📥 Commits

Reviewing files that changed from the base of the PR and between b7cfa16 and fdc19ff.

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

📝 Walkthrough

Walkthrough

The pull request hardens test infrastructure by adding parameter validation to helper functions, updating test callers to use explicit named parameters, and refining build environment initialization in the Help test file.

Changes

Test Infrastructure Robustness

Layer / File(s) Summary
Test helper parameter validation
tests/MetaFixers.psm1
ConvertTo-UTF8 and ConvertTo-SpaceIndentation add [ValidateNotNull()] on FileInfo; Get-TextFilesList and Get-UnicodeFilesList add [ValidateNotNullOrEmpty()] on Root; Get-UnicodeFilesList calls Test-FileUnicode using the named -FileInfo parameter.
Help test environment initialization
tests/Help.tests.ps1
Build environment path derivation in BeforeDiscovery and BeforeAll now computes $projectRoot from $PSScriptRoot parent and derives $sourceManifest under "$Env:BHProjectName" folder; custom type enumeration guards on directory existence; module unloading uses direct Get-Module -Name lookup.
Test caller updates for helper compatibility
tests/Meta.tests.ps1, tests/Help.tests.ps1
Get-TextFilesList is called with explicit -Root $projectRoot parameter; help-parameter assertion checks membership in $commandParameterNames; tab detection in Meta test uses escaped tab literal "`t" in Select-String pattern.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related issues

  • PlexAutomationToolkit#50: Parameter validation attributes and named-parameter usage directly implement the style rules described in the issue.

Poem

🐰 Hop along with param guards so tight,
Path computations bright and right,
Named parameters dance in the tests,
Validation attributes pass the quests,
Polish and robustness—what a delight!

🚥 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 'style: align test scaffolding with canonical PSMTplt' accurately and concisely describes the main objective of the PR: applying style rule changes to align test files with the PowerShellModuleTemplate standard.
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
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.

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