Skip to content

test(scripts): add Pester tests for linting scripts#237

Merged
WilliamBerryiii merged 10 commits intomainfrom
test/231-linting-script-tests
Jan 22, 2026
Merged

test(scripts): add Pester tests for linting scripts#237
WilliamBerryiii merged 10 commits intomainfrom
test/231-linting-script-tests

Conversation

@WilliamBerryiii
Copy link
Copy Markdown
Member

@WilliamBerryiii WilliamBerryiii commented Jan 22, 2026

Pull Request

Description

Add comprehensive Pester tests for four linting PowerShell scripts. This PR provides complete test coverage for the linting infrastructure and fixes a discovered bug in Link-Lang-Check.ps1.

Changes

  • New test files (4 files, 1,156 lines total):

    • Invoke-LinkLanguageCheck.Tests.ps1 - Tests for link/language validation orchestration
    • Invoke-PSScriptAnalyzer.Tests.ps1 - Tests for PowerShell static analysis wrapper
    • Link-Lang-Check.Tests.ps1 - Tests for link language checking with npx integration
    • Markdown-Link-Check.Tests.ps1 - Tests for markdown link validation with npx integration
  • Test fixtures (5 files):

    • anchors-test.md - Internal anchor link scenarios
    • invalid-links.md - Broken URL test cases
    • link-check-config.json - Configuration fixture
    • mixed-links.md - Combined valid/invalid link scenarios
    • valid-links.md - Working URL test cases
  • Bug fix:

    • Link-Lang-Check.ps1 - Fixed array wrapping on Get-Content to handle single-file edge case
  • Test organization:

    • Reorganized test directory structure to mirror source layout (scripts/tests/linting/, scripts/tests/dev-tools/, scripts/tests/extension/, scripts/tests/lib/)

Test Results

  • 192 tests passing (Pester 5.7.1)
  • PSScriptAnalyzer clean (no warnings)

Related Issue(s)

Closes #231
Closes #190

Type of Change

Select all that apply:

Code & Documentation:

  • Bug fix (non-breaking change fixing an issue)
  • New feature (non-breaking change adding functionality)
  • Breaking change (fix or feature causing existing functionality to change)
  • Documentation update

Infrastructure & Configuration:

  • GitHub Actions workflow
  • Linting configuration (markdown, PowerShell, etc.)
  • Security configuration
  • DevContainer configuration
  • Dependency update

AI Artifacts:

  • Reviewed contribution with prompt-builder agent and addressed all feedback
  • Copilot instructions (.github/instructions/*.instructions.md)
  • Copilot prompt (.github/prompts/*.prompt.md)
  • Copilot agent (.github/agents/*.agent.md)

Other:

  • Script/automation (.ps1, .sh, .py)
  • Other (please describe):

Testing

All tests verified locally:

# Run Pester tests
Invoke-Pester -Path ./scripts/tests -Configuration (& ./scripts/tests/pester.config.ps1)
# Result: 192 tests passed

# Run PSScriptAnalyzer on test files
Invoke-PSScriptAnalyzer -Path ./scripts/tests -Recurse
# Result: No warnings

Test coverage includes:

Script Test Scenarios
Invoke-LinkLanguageCheck.ps1 Parameter validation, file discovery, results aggregation, exit codes
Invoke-PSScriptAnalyzer.ps1 Settings file handling, custom rules, verbose output, result formatting
Link-Lang-Check.ps1 npx integration, file processing, error handling, configuration
Markdown-Link-Check.ps1 npx integration, config file support, result parsing, concurrency

Checklist

Required Checks

  • Documentation is updated (if applicable)
  • Files follow existing naming conventions
  • Changes are backwards compatible (if applicable)

AI Artifact Contributions

N/A - This PR contains test files only.

Required Automated Checks

The following validation commands must pass before merging:

  • Markdown linting: npm run lint:md
  • Spell checking: npm run spell-check
  • Frontmatter validation: npm run lint:frontmatter
  • Link validation: npm run lint:md-links
  • PowerShell analysis: npm run lint:ps

Security Considerations

  • This PR does not contain any sensitive or NDA information
  • Any new dependencies have been reviewed for security issues
  • Security-related scripts follow the principle of least privilege

Additional Notes

Commits

  1. 12c17c2 - test(scripts): add Pester tests for linting scripts
  2. 0a2378f - fix(tests): update relative paths after reorganization (Related to [Issue]: Add unit tests for linting scripts to improve code coverage #231)
  3. c223639 - refactor(tests): reorganize test directory to mirror source structure (Related to [Issue]: Add unit tests for linting scripts to improve code coverage #231)

Files Changed (16 total)

File Change
scripts/linting/Link-Lang-Check.ps1 Bug fix
scripts/tests/Fixtures/Linting/*.md New fixtures (5 files)
scripts/tests/linting/*.Tests.ps1 New tests (4 files)
scripts/tests/dev-tools/ Relocated from root
scripts/tests/extension/ Relocated from root
scripts/tests/lib/ Relocated from root

- Move Generate-PrReference.Tests.ps1 to dev-tools/
- Move Get-VerifiedDownload.Tests.ps1 to lib/
- Move Package-Extension.Tests.ps1 to extension/
- Move Prepare-Extension.Tests.ps1 to extension/
- Move LintingHelpers.Tests.ps1 to linting/
- Move Validate-MarkdownFrontmatter.Tests.ps1 to linting/

Related to #231

🤖 - Generated by Copilot
Adjust PSScriptRoot-relative paths to source files after moving tests
into subdirectories.

Related to #231

🤖 - Generated by Copilot
- add unit tests for Invoke-LinkLanguageCheck, Invoke-PSScriptAnalyzer
- add unit tests for Link-Lang-Check, Markdown-Link-Check
- add test fixtures for markdown link validation scenarios
- fix array wrapping bug in Link-Lang-Check.ps1

🧪 - Generated by Copilot
@WilliamBerryiii WilliamBerryiii requested a review from a team as a code owner January 22, 2026 00:40
Copilot AI review requested due to automatic review settings January 22, 2026 00:40
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Jan 22, 2026

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

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

This PR adds comprehensive Pester tests around the linting PowerShell scripts, introduces markdown/link fixtures to exercise those tests, and fixes a single-file edge case in Link-Lang-Check.ps1. It also aligns test script paths with the reorganized scripts/tests/* directory layout.

Changes:

  • New unit and integration-style Pester suites for Validate-MarkdownFrontmatter.ps1, Markdown-Link-Check.ps1, Link-Lang-Check.ps1, Invoke-PSScriptAnalyzer.ps1, and Invoke-LinkLanguageCheck.ps1, plus shared LintingHelpers tests.
  • New markdown and JSON fixtures under scripts/tests/Fixtures/Linting/ for valid/invalid links and anchor scenarios.
  • Bug fix in Find-LinksInFile to always treat Get-Content results as an array, avoiding incorrect behavior on single-line files.
  • Updated existing tests under scripts/tests/{lib,extension,dev-tools} to match the new directory structure.

Reviewed changes

Copilot reviewed 14 out of 16 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
scripts/tests/linting/Validate-MarkdownFrontmatter.Tests.ps1 Adds unit and integration tests for frontmatter parsing, schema selection/validation, footer detection, git-changed-file grouping, and end-to-end validation behavior.
scripts/tests/linting/Markdown-Link-Check.Tests.ps1 Tests Get-MarkdownTarget (git-aware and non-git modes), Get-RelativePrefix, and validates the link-check JSON config fixture; contains one OS-specific path assertion that will fail on Linux.
scripts/tests/linting/LintingHelpers.Tests.ps1 Provides coverage for all exported helpers (changed-files discovery, recursive file enumeration, .gitignore parsing, and GitHub Actions output/env/summary helpers).
scripts/tests/linting/Link-Lang-Check.Tests.ps1 Exercises Get-GitTextFile, Find-LinksInFile, Repair-LinksInFile, Repair-AllLink, and ConvertTo-JsonOutput using temp files to validate detection and repair of en-us URLs.
scripts/tests/linting/Invoke-PSScriptAnalyzer.Tests.ps1 Adds tests around parameter validation, module-availability handling, file-discovery logic, GitHub Actions integration, JSON output, and exit-code behavior; current “module not installed” test will cause a real Install-Module call.
scripts/tests/linting/Invoke-LinkLanguageCheck.Tests.ps1 Verifies presence of Invoke-LinkLanguageCheck.ps1/Link-Lang-Check.ps1, JSON parsing expectations, GitHub Actions helper exports, and basic output/summary semantics.
scripts/tests/lib/Get-VerifiedDownload.Tests.ps1 Updates dot-source path to Get-VerifiedDownload.ps1 to account for the tests being moved under scripts/tests/lib/.
scripts/tests/extension/Prepare-Extension.Tests.ps1 Adjusts the relative dot-source path to Prepare-Extension.ps1 to match the new scripts/tests/extension layout.
scripts/tests/extension/Package-Extension.Tests.ps1 Adjusts the relative dot-source path to Package-Extension.ps1 after test directory reorganization.
scripts/tests/dev-tools/Generate-PrReference.Tests.ps1 Fixes the dot-source path to Generate-PrReference.ps1 for the new scripts/tests/dev-tools location.
scripts/tests/Fixtures/Linting/valid-links.md Fixture file containing only valid internal, external, and anchor links for link-check tests.
scripts/tests/Fixtures/Linting/mixed-links.md Fixture mixing valid and invalid links (missing file, bad anchor) to exercise failure detection.
scripts/tests/Fixtures/Linting/link-check-config.json JSON configuration fixture for markdown-link-check tests, including ignore/replacement patterns, headers, timeout, and retry options.
scripts/tests/Fixtures/Linting/invalid-links.md Fixture with broken internal/anchor/malformed links to test error reporting.
scripts/tests/Fixtures/Linting/anchors-test.md Fixture to validate anchor extraction and matching (including headings with dashes, underscores, and uppercase).
scripts/linting/Link-Lang-Check.ps1 Fixes Find-LinksInFile to wrap Get-Content in @() so single-line files are always processed as an array of lines.

- add ExcludePaths parameter to Link-Lang-Check.ps1
- pass ExcludePaths through Invoke-LinkLanguageCheck.ps1 wrapper
- update package.json to exclude scripts/tests/** from lint:links

🔧 - Generated by Copilot
- fix BeforeAll path in Generate-PrReference.Tests.ps1 from ../ to ../../
- use IsPathRooted() for cross-platform absolute path validation
- mock Install-Module to prevent network calls in unit tests

🔧 - Generated by Copilot
- workflow was calling script directly without exclusion parameter
- test files containing intentional 'en-us' URLs are now excluded

🔧 - Generated by Copilot
Copilot AI review requested due to automatic review settings January 22, 2026 00:54
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

Copilot reviewed 17 out of 19 changed files in this pull request and generated 2 comments.

…ity scripts

- add ExcludePaths filtering tests to Link-Lang-Check.Tests.ps1
- add ExcludePaths filtering tests to Validate-MarkdownFrontmatter.Tests.ps1
- add ExcludePaths filtering tests to Test-DependencyPinning.Tests.ps1

🧪 - Generated by Copilot
- add invocation guard to Test-DependencyPinning.ps1 main block
- simplify test file to use dot-source instead of AST extraction
- fixes 5 Export-ComplianceReport test failures

🔧 - Generated by Copilot
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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

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

Copilot reviewed 20 out of 21 changed files in this pull request and generated 2 comments.

- rename misleading test to match actual behavior
- rewrite GitHub Actions detection test to exercise env var

🧪 - Generated by Copilot
@WilliamBerryiii WilliamBerryiii merged commit 5b65923 into main Jan 22, 2026
15 checks passed
@WilliamBerryiii WilliamBerryiii deleted the test/231-linting-script-tests branch January 22, 2026 18:29
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.

[Issue]: Add unit tests for linting scripts to improve code coverage [Issue]: Add Pester unit testing framework for PowerShell scripts

3 participants