-
Notifications
You must be signed in to change notification settings - Fork 35
refactor(scripts): standardize entry point guard pattern #346
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
- 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 please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.
Contributor License AgreementContribution License AgreementThis Contribution License Agreement (“Agreement”) is agreed to by the party signing below (“You”),
|
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ 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
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
There was a problem hiding this 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-scriptexitcalls into integer return codes propagated by the guard. - Simplified
Test-SHAStalenessPester 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` | |
Copilot
AI
Jan 29, 2026
There was a problem hiding this comment.
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.
| | `Validate-*.ps1` | `Test-*Validation` | | |
| | `Validate-*.ps1` | `Invoke-*Validation` | |
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:
Infrastructure & Configuration:
AI Artifacts:
prompt-builderagent and addressed all feedback.github/instructions/*.instructions.md).github/prompts/*.prompt.md).github/agents/*.agent.md)Other:
.ps1,.sh,.py)Testing
Checklist
Required Checks
AI Artifact Contributions
/prompt-analyzeto review contributionprompt-builderreviewRequired Automated Checks
The following validation commands must pass before merging:
npm run lint:mdnpm run spell-checknpm run lint:frontmatternpm run lint:md-linksnpm run lint:psSecurity Considerations
Additional Notes