Skip to content

Add parameter capitalization guardrail for PowerShell tests#27677

Open
Pitchfork-and-Torch wants to merge 2 commits into
PowerShell:masterfrom
Pitchfork-and-Torch:fix/parameter-capitalization-tests-26614
Open

Add parameter capitalization guardrail for PowerShell tests#27677
Pitchfork-and-Torch wants to merge 2 commits into
PowerShell:masterfrom
Pitchfork-and-Torch:fix/parameter-capitalization-tests-26614

Conversation

@Pitchfork-and-Torch

Copy link
Copy Markdown

Summary

Addresses #26614.

Keep test scripts using PascalCase for common parameters (-Force, -ErrorAction, etc.).

Changes

  • Fixed a few lowercase -force call sites (including the Set-Alias example from the issue)
  • Added ParameterCapitalization.Tests.ps1 (CI) scanning test/powershell
  • Allowlisted intentional case-insensitivity fixtures

Testing

Dry-ran the scan over test/powershell after fixes (0 violations outside allowlist).

Fixes a handful of lowercase common parameters (-force, etc.) and adds a CI
test so we don't reintroduce them. Intentional case-insensitivity fixtures
stay allowlisted.

Addresses PowerShell#26614.
Copilot AI review requested due to automatic review settings July 11, 2026 21:06
@Pitchfork-and-Torch
Pitchfork-and-Torch requested a review from a team as a code owner July 11, 2026 21:06
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds a CI guardrail test to keep common PowerShell parameter switches in test scripts consistently capitalized (PascalCase), and fixes several existing lowercase -force call sites that triggered the issue (#26614).

Changes:

  • Fixed a handful of lowercase common-parameter usages (e.g., -force-Force) in existing tests.
  • Added a new Pester test that scans test/powershell for lowercase common parameters, with an allowlist for intentional fixtures.
  • Updated one cleanup call site in Encoding.Tests.ps1 to use -Force.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Alias.Tests.ps1 Fixes a lowercase -force usage in an alias test.
test/powershell/Modules/Microsoft.PowerShell.Management/Remove-Item.Tests.ps1 Fixes a lowercase -force usage when creating a test file.
test/powershell/Modules/Microsoft.PowerShell.Management/FileSystem.Tests.ps1 Normalizes New-Item parameter casing (-ItemType, -Path, -Force).
test/powershell/Modules/Microsoft.PowerShell.Core/PSSessionConfiguration.Tests.ps1 Fixes lowercase -force usages in pending remoting configuration tests.
test/powershell/engine/Basic/ParameterCapitalization.Tests.ps1 Introduces the new CI guardrail that scans for lowercase common parameters.
test/powershell/engine/Basic/Encoding.Tests.ps1 Fixes lowercase -force in test cleanup.

Comment on lines +10 to +11
$repoRoot = (Resolve-Path (Join-Path $PSScriptRoot "../../..")).Path
$scanRoot = Join-Path $repoRoot "test/powershell"
Comment on lines +36 to +37
$matches = Select-String -Path $file.FullName -Pattern $parameterPattern -CaseSensitive -AllMatches
foreach ($m in $matches) {
# High-frequency switches that should appear PascalCase in source.
# Intentional lowercase uses (binding case-insensitivity tests, stream fixtures)
# are allowlisted by relative path below.
$parameterPattern = '(?<=[\s|])-(force|erroraction|warningaction|verbose|debug|whatif|confirm)(?=[\s:\|]|$)'
Comment on lines +18 to +23
$allowlistRelativePaths = @(
"test/powershell/Language/Scripting/CommonParameters.Tests.ps1"
"test/powershell/Language/Parser/BNotOperator.Tests.ps1"
"test/powershell/Language/Parser/RedirectionOperator.Tests.ps1"
"test/powershell/engine/Basic/ParameterCapitalization.Tests.ps1"
)
)
}

It "Uses PascalCase for common parameters (no bare lowercase -force / -erroraction / etc.)" {
@Pitchfork-and-Torch

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

@Pitchfork-and-Torch

Copy link
Copy Markdown
Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Commenter does not have sufficient privileges for PR 27677 in repo PowerShell/PowerShell

- Fix repo root path (four levels up from engine/Basic, not three)
- Avoid overwriting automatic $matches variable
- Allow start-of-line matches via negative lookbehind
- Drop self-allowlist so the guardrail validates itself
- Align It description with lowercase-only detection
@Pitchfork-and-Torch

Copy link
Copy Markdown
Author

Addressed the Copilot review on the guardrail test:

  • Fixed $repoRoot to walk four levels up from engine/Basic (was resolving under test/)
  • Stopped assigning to automatic $matches
  • Switched to a negative lookbehind so start-of-line params are matched
  • Removed this test file from the allowlist so it validates itself
  • Renamed the It block to describe lowercase-only detection accurately

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