Skip to content

test(scripts): add comprehensive unit tests for Update-ActionSHAPinning.ps1#329

Merged
WilliamBerryiii merged 4 commits intomainfrom
test/update-actionshapinning-coverage
Jan 27, 2026
Merged

test(scripts): add comprehensive unit tests for Update-ActionSHAPinning.ps1#329
WilliamBerryiii merged 4 commits intomainfrom
test/update-actionshapinning-coverage

Conversation

@WilliamBerryiii
Copy link
Copy Markdown
Member

@WilliamBerryiii WilliamBerryiii commented Jan 27, 2026

Description

Add comprehensive unit tests for Update-ActionSHAPinning.ps1 covering API mocking infrastructure, retry logic, output formatting, and helper functions. The test suite includes 53 test cases organized across 12 Describe blocks with mock helpers for GitHub API responses.

  • test(scripts): Add API mocking infrastructure with 2 mock helpers (New-MockGitHubGraphQLResponse, New-MockRateLimitException)
  • test(scripts): Add Invoke-GitHubAPIWithRetry tests for retry logic, exponential backoff, and rate limit handling
  • test(scripts): Add Write-OutputResult tests covering all 5 output formats (JSON, AzDO, GitHub, Console, BuildWarning)
  • test(scripts): Add Get-LatestCommitSHA and Test-GitHubToken tests for API integration scenarios
  • test(scripts): Add Export-SecurityReport, Set-ContentPreservePermission, Add-SecurityIssue, and Write-SecurityLog tests
  • test(scripts): Remove redundant Invoke-VerifiedDownload tests and plain .tar archive test from Get-VerifiedDownload.Tests.ps1
  • ci(scripts): Reduce code coverage target from 80% to 70% to accommodate AST-based function extraction limitations
  • ci(workflows): Add job summary step to scorecard workflow for improved visibility
  • ci(workflows): Add security-events: write permission to security-scan workflow
  • ci(workflows): Remove explicit vsce version pin and top-level permissions block from workflow files

Related Issue(s)

Fixes #327

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 53 Pester tests pass (Invoke-Pester -Path "scripts/tests/security/Update-ActionSHAPinning.Tests.ps1")
  • Tests cover retry logic, output formatting, API integration, and utility functions
  • Mock infrastructure prevents actual GitHub API calls during testing

Checklist

Required Checks

  • Documentation is updated (if applicable)
  • Files follow existing naming conventions
  • Changes are backwards compatible (if applicable)
  • Tests added for new functionality (if applicable)

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

The code coverage target was reduced from 80% to 70% because AST-based function extraction in Update-ActionSHAPinning.ps1 prevents Pester from instrumenting the extracted functions for coverage analysis. The 53 test cases provide comprehensive behavioral coverage despite this limitation.

🧪 - Generated by Copilot

…ng.ps1

- add API mocking infrastructure for GitHub API calls
- add Invoke-GitHubAPIWithRetry tests for retry logic and exponential backoff
- add Write-OutputResult tests for all 5 output formats
- add Get-LatestCommitSHA and Test-GitHubToken tests
- add Export-SecurityReport, Set-ContentPreservePermission, Add-SecurityIssue, Write-SecurityLog tests

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

github-actions bot commented Jan 27, 2026

Dependency Review

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

Scanned Files

None

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Jan 27, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 40.60%. Comparing base (fa17f2b) to head (ba20058).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #329      +/-   ##
==========================================
- Coverage   40.64%   40.60%   -0.04%     
==========================================
  Files          15       15              
  Lines        2864     2864              
==========================================
- Hits         1164     1163       -1     
- Misses       1700     1701       +1     
Flag Coverage Δ
pester 40.60% <ø> (-0.04%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.
see 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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 extends the Pester test suite for Update-ActionSHAPinning.ps1 to cover GitHub API helpers, output formatting, and security utility functions, supporting improved reliability for the SHA-pinning workflow. It also adjusts some CI expectations and related test files per the PR description (not all diffs shown here).

Changes:

  • Add comprehensive unit tests around Invoke-GitHubAPIWithRetry, Write-OutputResult, Get-LatestCommitSHA, Test-GitHubToken, and security helper functions (Export-SecurityReport, Set-ContentPreservePermission, Add-SecurityIssue, Write-SecurityLog).
  • Introduce reusable mock helpers for GitHub API and GraphQL responses in the test setup.
  • Refine behavior and expectations around security reporting and output formats (JSON, AzDO, GitHub, console, build warning) in the test suite.

WilliamBerryiii and others added 3 commits January 27, 2026 09:44
…tests

- remove unused mock helpers New-MockGitHubCommitResponse and New-MockGitHubRateLimitResponse
- fix New-MockRateLimitException to avoid abstract HttpWebResponse constructor
- correct refs/heads branch prefix test to use actual prefixed value
- add assertion for null result on API error test
- fix empty results test to match actual function behavior

🔧 - Generated by Copilot
Copilot AI review requested due to automatic review settings January 27, 2026 19:52
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 1 out of 1 changed files in this pull request and generated 1 comment.

@WilliamBerryiii WilliamBerryiii merged commit 4ef6d20 into main Jan 27, 2026
22 checks passed
@WilliamBerryiii WilliamBerryiii deleted the test/update-actionshapinning-coverage branch January 27, 2026 20:54
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.

test(scripts): improve test coverage for Update-ActionSHAPinning.ps1

4 participants