-
Notifications
You must be signed in to change notification settings - Fork 25
Open
Labels
Description
Issue Description
The repository contains 12 PowerShell scripts with approximately 50+ exported and internal functions that lack unit test coverage. While PSScriptAnalyzer runs on every PR for static analysis/linting, there are no Pester tests to validate the actual behavior of these functions.
Current State:
- 12 PowerShell scripts across
scripts/subdirectories - 1 PowerShell module (
LintingHelpers.psm1) with 7 exported functions - 50+ internal functions with testable logic
- PSScriptAnalyzer runs on PRs (linting only)
- No Pester tests exist
- No Pester workflow exists
Requested Implementation:
-
Create test infrastructure
- Add
scripts/tests/directory for Pester test files - Create
*.Tests.ps1files following Pester naming conventions - Add Pester configuration file (
pester.config.ps1orPesterConfiguration)
- Add
-
Create reusable Pester workflow (
.github/workflows/pester-tests.yml)- Run on PR when
*.ps1or*.psm1files change - Support
changed-files-onlyinput for targeted testing - Output test results in NUnit/JUnit format for GitHub annotations
- Support
soft-failinput for gradual rollout
- Run on PR when
-
Add Pester job to PR validation (
.github/workflows/pr-validation.yml)- New job:
PowerShell Testsusing the reusable workflow - Trigger only when PowerShell files change (path filter)
- New job:
-
Priority test coverage for high-value functions:
Script Functions to Test Priority LintingHelpers.psm1Get-ChangedFilesFromGit,Get-FilesRecursive,Get-GitIgnorePatternsHigh Validate-MarkdownFrontmatter.ps1Get-MarkdownFrontmatter,Test-MarkdownFooter,Test-FrontmatterValidationHigh Test-DependencyPinning.ps1Test-SHAPinning,Get-DependencyViolation,Get-RemediationSuggestionHigh Test-SHAStaleness.ps1Compare-ToolVersion,Get-ToolStalenessMedium Link-Lang-Check.ps1Find-LinksInFile,Repair-LinksInFileMedium Get-VerifiedDownload.ps1Hash verification logic, extraction paths Medium Generate-PrReference.ps1Resolve-ComparisonReference,Get-CommitEntryLow
Acceptance Criteria:
- Pester 5.x installed and configured
- At least one
*.Tests.ps1file per script directory - Reusable workflow for Pester tests
- PR validation includes PowerShell test job
- Tests run only when PowerShell files change
- Code coverage reporting (optional, stretch goal)
Benefits:
- Catch regressions before they reach
main - Enable confident refactoring of PowerShell utilities
- Validate edge cases (e.g., malformed frontmatter, missing git context)
- Align with industry standard PowerShell testing practices
Additional Context
Testable Artifacts Inventory:
scripts/
├── dev-tools/
│ └── Generate-PrReference.ps1 # 5 functions
├── extension/
│ ├── Package-Extension.ps1 # Script logic
│ └── Prepare-Extension.ps1 # 1 function
├── lib/
│ └── Get-VerifiedDownload.ps1 # Verification + extraction logic
├── linting/
│ ├── Invoke-LinkLanguageCheck.ps1 # Orchestration script
│ ├── Invoke-PSScriptAnalyzer.ps1 # Orchestration script
│ ├── Link-Lang-Check.ps1 # 5 functions
│ ├── Markdown-Link-Check.ps1 # 2 functions
│ ├── Validate-MarkdownFrontmatter.ps1 # 8 functions
│ └── Modules/
│ └── LintingHelpers.psm1 # 7 exported functions
└── security/
├── Test-DependencyPinning.ps1 # 9 functions
├── Test-SHAStaleness.ps1 # 10 functions
└── Update-ActionSHAPinning.ps1 # 12 functions
Example Pester Test Structure:
# scripts/tests/LintingHelpers.Tests.ps1
BeforeAll {
Import-Module "$PSScriptRoot/../linting/Modules/LintingHelpers.psm1" -Force
}
Describe 'Get-GitIgnorePatterns' {
Context 'when .gitignore exists' {
It 'should parse comment lines correctly' {
# Test implementation
}
It 'should handle directory patterns with trailing slash' {
# Test implementation
}
}
Context 'when .gitignore does not exist' {
It 'should return empty array' {
# Test implementation
}
}
}References:
- Pester Documentation
- Pester v5 Migration Guide
- Existing PSScriptAnalyzer workflow:
.github/workflows/ps-script-analyzer.yml