Skip to content

Conversation

@azurecloudkevin
Copy link

  • Add Invoke-* orchestration functions to all scripts
  • Apply guard pattern: $MyInvocation.InvocationName -ne '.'
  • Document pattern in scripts/README.md
  • Simplify test dot-sourcing (removes AST workaround)
  • Scripts: 12 files updated across security, linting, extension

Pull Request

Description

This PR standardizes the "direct invocation vs dot-sourced" guard pattern across all PowerShell scripts in the repository. This improves testability by allowing scripts to be dot-sourced without executing their main logic, enabling Pester tests to directly call individual functions.

Related Issue(s)

Closes issue 325

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

  • PSScriptAnalyzer: 32/33 files passed (1 warning about unused parameter - pre-existing issue)
  • Pester Tests: tests invoked successfully
  • Dot-sourcing verification: Functions load without executing main logic
  • Direct invocation verification: Scripts execute correctly

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)

AI Artifact Contributions

  • Used /prompt-analyze to review contribution
  • Addressed all feedback from prompt-builder review
  • Verified contribution follows common standards and type-specific requirements

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

- Add Invoke-* orchestration functions to all scripts
- Apply guard pattern: $MyInvocation.InvocationName -ne '.'
- Document pattern in scripts/README.md
- Simplify test dot-sourcing (removes AST workaround)
- Scripts: 12 files updated across security, linting, extension
@azurecloudkevin azurecloudkevin requested a review from a team as a code owner January 29, 2026 15:56
Copilot AI review requested due to automatic review settings January 29, 2026 15:56
@microsoft-github-policy-service

@azurecloudkevin please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.

@microsoft-github-policy-service agree [company="{your company}"]

Options:

  • (default - no company specified) I have sole ownership of intellectual property rights to my Submissions and I am not making Submissions in the course of work for my employer.
@microsoft-github-policy-service agree
  • (when company given) I am making Submissions in the course of work for my employer (or my employer has intellectual property rights in my Submissions by contract or applicable law). I have permission from my employer to make Submissions and enter into this Agreement on behalf of my employer. By signing below, the defined term “You” includes me and my employer.
@microsoft-github-policy-service agree company="Microsoft"
Contributor License Agreement

Contribution License Agreement

This Contribution License Agreement (“Agreement”) is agreed to by the party signing below (“You”),
and conveys certain license rights to Microsoft Corporation and its affiliates (“Microsoft”) for Your
contributions to Microsoft open source projects. This Agreement is effective as of the latest signature
date below.

  1. Definitions.
    “Code” means the computer software code, whether in human-readable or machine-executable form,
    that is delivered by You to Microsoft under this Agreement.
    “Project” means any of the projects owned or managed by Microsoft and offered under a license
    approved by the Open Source Initiative (www.opensource.org).
    “Submit” is the act of uploading, submitting, transmitting, or distributing code or other content to any
    Project, including but not limited to communication on electronic mailing lists, source code control
    systems, and issue tracking systems that are managed by, or on behalf of, the Project for the purpose of
    discussing and improving that Project, but excluding communication that is conspicuously marked or
    otherwise designated in writing by You as “Not a Submission.”
    “Submission” means the Code and any other copyrightable material Submitted by You, including any
    associated comments and documentation.
  2. Your Submission. You must agree to the terms of this Agreement before making a Submission to any
    Project. This Agreement covers any and all Submissions that You, now or in the future (except as
    described in Section 4 below), Submit to any Project.
  3. Originality of Work. You represent that each of Your Submissions is entirely Your original work.
    Should You wish to Submit materials that are not Your original work, You may Submit them separately
    to the Project if You (a) retain all copyright and license information that was in the materials as You
    received them, (b) in the description accompanying Your Submission, include the phrase “Submission
    containing materials of a third party:” followed by the names of the third party and any licenses or other
    restrictions of which You are aware, and (c) follow any other instructions in the Project’s written
    guidelines concerning Submissions.
  4. Your Employer. References to “employer” in this Agreement include Your employer or anyone else
    for whom You are acting in making Your Submission, e.g. as a contractor, vendor, or agent. If Your
    Submission is made in the course of Your work for an employer or Your employer has intellectual
    property rights in Your Submission by contract or applicable law, You must secure permission from Your
    employer to make the Submission before signing this Agreement. In that case, the term “You” in this
    Agreement will refer to You and the employer collectively. If You change employers in the future and
    desire to Submit additional Submissions for the new employer, then You agree to sign a new Agreement
    and secure permission from the new employer before Submitting those Submissions.
  5. Licenses.
  • Copyright License. You grant Microsoft, and those who receive the Submission directly or
    indirectly from Microsoft, a perpetual, worldwide, non-exclusive, royalty-free, irrevocable license in the
    Submission to reproduce, prepare derivative works of, publicly display, publicly perform, and distribute
    the Submission and such derivative works, and to sublicense any or all of the foregoing rights to third
    parties.
  • Patent License. You grant Microsoft, and those who receive the Submission directly or
    indirectly from Microsoft, a perpetual, worldwide, non-exclusive, royalty-free, irrevocable license under
    Your patent claims that are necessarily infringed by the Submission or the combination of the
    Submission with the Project to which it was Submitted to make, have made, use, offer to sell, sell and
    import or otherwise dispose of the Submission alone or with the Project.
  • Other Rights Reserved. Each party reserves all rights not expressly granted in this Agreement.
    No additional licenses or rights whatsoever (including, without limitation, any implied licenses) are
    granted by implication, exhaustion, estoppel or otherwise.
  1. Representations and Warranties. You represent that You are legally entitled to grant the above
    licenses. You represent that each of Your Submissions is entirely Your original work (except as You may
    have disclosed under Section 3). You represent that You have secured permission from Your employer to
    make the Submission in cases where Your Submission is made in the course of Your work for Your
    employer or Your employer has intellectual property rights in Your Submission by contract or applicable
    law. If You are signing this Agreement on behalf of Your employer, You represent and warrant that You
    have the necessary authority to bind the listed employer to the obligations contained in this Agreement.
    You are not expected to provide support for Your Submission, unless You choose to do so. UNLESS
    REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING, AND EXCEPT FOR THE WARRANTIES
    EXPRESSLY STATED IN SECTIONS 3, 4, AND 6, THE SUBMISSION PROVIDED UNDER THIS AGREEMENT IS
    PROVIDED WITHOUT WARRANTY OF ANY KIND, INCLUDING, BUT NOT LIMITED TO, ANY WARRANTY OF
    NONINFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
  2. Notice to Microsoft. You agree to notify Microsoft in writing of any facts or circumstances of which
    You later become aware that would make Your representations in this Agreement inaccurate in any
    respect.
  3. Information about Submissions. You agree that contributions to Projects and information about
    contributions may be maintained indefinitely and disclosed publicly, including Your name and other
    information that You submit with Your Submission.
  4. Governing Law/Jurisdiction. This Agreement is governed by the laws of the State of Washington, and
    the parties consent to exclusive jurisdiction and venue in the federal courts sitting in King County,
    Washington, unless no federal subject matter jurisdiction exists, in which case the parties consent to
    exclusive jurisdiction and venue in the Superior Court of King County, Washington. The parties waive all
    defenses of lack of personal jurisdiction and forum non-conveniens.
  5. Entire Agreement/Assignment. This Agreement is the entire agreement between the parties, and
    supersedes any and all prior agreements, understandings or communications, written or oral, between
    the parties relating to the subject matter hereof. This Agreement may be assigned by Microsoft.

@github-actions
Copy link

Dependency Review

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

Scanned Files

None

@codecov-commenter
Copy link

Codecov Report

❌ Patch coverage is 12.85141% with 217 lines in your changes missing coverage. Please review.
✅ Project coverage is 42.87%. Comparing base (f1d3ac6) to head (7f3a5b5).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
scripts/extension/Package-Extension.ps1 0.76% 129 Missing ⚠️
scripts/security/Test-DependencyPinning.ps1 2.56% 38 Missing ⚠️
scripts/extension/Prepare-Extension.ps1 5.88% 16 Missing ⚠️
scripts/linting/Invoke-LinkLanguageCheck.ps1 0.00% 12 Missing ⚠️
scripts/linting/Markdown-Link-Check.ps1 0.00% 8 Missing ⚠️
scripts/security/Test-SHAStaleness.ps1 16.66% 5 Missing ⚠️
scripts/security/Update-ActionSHAPinning.ps1 0.00% 5 Missing ⚠️
scripts/linting/Link-Lang-Check.ps1 0.00% 4 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #346      +/-   ##
==========================================
+ Coverage   41.08%   42.87%   +1.79%     
==========================================
  Files          15       15              
  Lines        2870     2904      +34     
==========================================
+ Hits         1179     1245      +66     
+ Misses       1691     1659      -32     
Flag Coverage Δ
pester 42.87% <12.85%> (+1.79%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
scripts/linting/Invoke-PSScriptAnalyzer.ps1 93.33% <100.00%> (+0.27%) ⬆️
scripts/linting/Invoke-YamlLint.ps1 94.59% <100.00%> (+0.22%) ⬆️
scripts/linting/Link-Lang-Check.ps1 0.00% <0.00%> (ø)
scripts/security/Test-SHAStaleness.ps1 16.04% <16.66%> (+16.04%) ⬆️
scripts/security/Update-ActionSHAPinning.ps1 0.00% <0.00%> (ø)
scripts/linting/Markdown-Link-Check.ps1 0.00% <0.00%> (ø)
scripts/linting/Invoke-LinkLanguageCheck.ps1 0.00% <0.00%> (ø)
scripts/extension/Prepare-Extension.ps1 39.68% <5.88%> (-0.32%) ⬇️
scripts/security/Test-DependencyPinning.ps1 54.06% <2.56%> (-1.46%) ⬇️
scripts/extension/Package-Extension.ps1 26.19% <0.76%> (-0.26%) ⬇️

... and 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
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 standardizes a PowerShell script entry-point pattern across the repo, adding Invoke-* orchestration functions and a guard that distinguishes direct invocation from dot-sourcing, plus documentation for the pattern. The changes improve testability, make exit-code behavior more consistent, and clean up the SHA staleness tests by removing the AST-based workaround.

Changes:

  • Added Invoke-* orchestration functions and $MyInvocation.InvocationName -ne '.' guards to security, linting, and extension scripts, converting in-script exit calls into integer return codes propagated by the guard.
  • Simplified Test-SHAStaleness Pester tests by switching from AST-based function extraction to simple dot-sourcing now that scripts can be safely imported without executing main logic.
  • Documented the standard entry-point pattern and naming conventions for scripts in scripts/README.md.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
scripts/tests/security/Test-SHAStaleness.Tests.ps1 Updates tests to dot-source Test-SHAStaleness.ps1 directly, relying on the new guard pattern to prevent main execution during testing.
scripts/security/Update-ActionSHAPinning.ps1 Introduces Invoke-ActionSHAUpdate as the main orchestration function, returns integer exit codes, and guards main execution behind the $MyInvocation.InvocationName -ne '.' check.
scripts/security/Test-SHAStaleness.ps1 Adds Invoke-SHAStalenessTest orchestration, converts inline exits to integer returns, and uses a guarded main section that calls the orchestrator and exits with its code.
scripts/security/Test-DependencyPinning.ps1 Extracts the main dependency-pinning logic into Invoke-DependencyPinningTest, replaces direct exits with returns, and adds a guard so dot-sourcing no longer fails the script.
scripts/linting/Markdown-Link-Check.ps1 Wraps existing markdown link checking logic in Invoke-MarkdownLinkCheck with integer return codes and a guarded main execution path.
scripts/linting/Link-Lang-Check.ps1 Adds Invoke-LinkLanguageCheck as the orchestration function, returning 0 consistently while the top-level guard handles exit behavior.
scripts/linting/Invoke-YamlLint.ps1 Refactors main YAML linting logic into Invoke-YamlLintValidation with structured return codes and creates a guarded main section that exits with the function’s result.
scripts/linting/Invoke-PSScriptAnalyzer.ps1 Moves PSScriptAnalyzer execution into Invoke-PSScriptAnalysis, returning an integer summary result and wiring it through a guarded main block.
scripts/linting/Invoke-LinkLanguageCheck.ps1 Wraps Link-Lang-Check.ps1 with Invoke-LinkLanguageCheckWrapper, returning explicit exit codes and guarding the main entry for dot-sourcing scenarios.
scripts/extension/Prepare-Extension.ps1 Extracts the extension preparation workflow into Invoke-ExtensionPreparation, uses $PSScriptRoot for path resolution, and returns integer codes that the guarded main section converts into process exits.
scripts/extension/Package-Extension.ps1 Refactors packaging logic into Invoke-ExtensionPackaging, ensures all paths return explicit exit codes, and adds a guard-based main entry that calls the orchestrator and exits accordingly.
scripts/README.md Documents the new script entry-point pattern, including structure, guard usage, and naming conventions, with a minor inconsistency in the naming table noted separately.

| `Package-*.ps1` | `Invoke-*Packaging` |
| `Prepare-*.ps1` | `Invoke-*Preparation` |
| `Update-*.ps1` | `Invoke-*Update` |
| `Validate-*.ps1` | `Test-*Validation` |
Copy link

Copilot AI Jan 29, 2026

Choose a reason for hiding this comment

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

In the naming convention table, the last row lists Test-*Validation as the "Invoke Function" for Validate-*.ps1 scripts, which is inconsistent with the preceding description that orchestration entrypoints follow the Invoke-* pattern and with new functions like Invoke-YamlLintValidation. To avoid confusion for future contributors, this row should be updated to use an Invoke-*Validation name to match the documented pattern and actual script implementations.

Suggested change
| `Validate-*.ps1` | `Test-*Validation` |
| `Validate-*.ps1` | `Invoke-*Validation` |

Copilot uses AI. Check for mistakes.
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.

3 participants