Skip to content

refactor(scripts): extract orchestration function for Prepare-Extension testability#344

Merged
WilliamBerryiii merged 2 commits intomainfrom
fix/262-prepare-extension-testability
Jan 29, 2026
Merged

refactor(scripts): extract orchestration function for Prepare-Extension testability#344
WilliamBerryiii merged 2 commits intomainfrom
fix/262-prepare-extension-testability

Conversation

@WilliamBerryiii
Copy link
Copy Markdown
Member

Description

Refactored Prepare-Extension.ps1 to extract a testable orchestration function, enabling comprehensive unit testing of extension preparation logic without relying on $MyInvocation context.

  • Added New-PrepareResult factory function returning standardized result hashtables with Success, Version, AgentCount, PromptCount, InstructionCount, and ErrorMessage properties
  • Added Invoke-PrepareExtension orchestration function that coordinates path validation, package.json parsing, artifact discovery, and changelog handling
  • Replaced ~200-line Main Execution region with ~55-line entry point that resolves $MyInvocation-dependent paths then delegates to Invoke-PrepareExtension
  • Added 13 new Pester tests covering success paths, error handling (invalid JSON, missing version, bad version format), channel filtering, and maturity filtering
  • Achieved 83.59% code coverage (exceeds 80% target)

Related Issue(s)

Closes #262

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):

Sample Prompts (for AI Artifact Contributions)

Testing

  • Ran PSScriptAnalyzer with no issues found
  • Executed 30 Pester tests (all passing)
  • Verified 83.59% code coverage on Prepare-Extension.ps1
  • Tested DryRun and non-DryRun modes
  • Validated channel filtering behavior (Stable vs PreRelease)

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

The refactoring preserves existing behavior while improving testability. The new Invoke-PrepareExtension function can be called directly in tests with controlled inputs, bypassing $MyInvocation dependencies that previously required integration-style testing.

🧪 - Generated by Copilot

…on testability

- add New-PrepareResult standardized result factory function
- add Invoke-PrepareExtension testable orchestration entry point
- replace Main Execution region with streamlined entry point
- add 13 tests achieving 83.59% code coverage

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

github-actions bot commented Jan 29, 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 29, 2026

Codecov Report

❌ Patch coverage is 67.36842% with 31 lines in your changes missing coverage. Please review.
✅ Project coverage is 44.24%. Comparing base (4612929) to head (9c21056).

Files with missing lines Patch % Lines
scripts/extension/Prepare-Extension.ps1 67.36% 31 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #344      +/-   ##
==========================================
+ Coverage   41.08%   44.24%   +3.16%     
==========================================
  Files          15       15              
  Lines        2870     2825      -45     
==========================================
+ Hits         1179     1250      +71     
+ Misses       1691     1575     -116     
Flag Coverage Δ
pester 44.24% <67.36%> (+3.16%) ⬆️

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

Files with missing lines Coverage Δ
scripts/extension/Prepare-Extension.ps1 82.85% <67.36%> (+42.85%) ⬆️

... 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
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

Refactors Prepare-Extension.ps1 by extracting a testable orchestration function and adding Pester coverage for the prepare workflow and related helpers.

Changes:

  • Added New-PrepareResult and Invoke-PrepareExtension to encapsulate prepare orchestration and return structured results.
  • Replaced the large entry-point block with a smaller $MyInvocation-based path resolver that delegates to Invoke-PrepareExtension.
  • Added Pester tests covering success paths, error handling, and channel/maturity filtering.

Reviewed changes

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

File Description
scripts/extension/Prepare-Extension.ps1 Extracts orchestration + standardized result object; simplifies entry point.
scripts/tests/extension/Prepare-Extension.Tests.ps1 Adds unit tests for new result/orchestration functions and additional scenarios.

- use Write-Warning instead of Write-Host for missing changelog
- anchor version regex to reject 1.2.3-beta and 1.2.3.4 formats
- add -Encoding UTF8NoBOM for package.json write consistency
- include file path in JSON parse error message
- wrap entry point in try/catch with GitHub Actions ::error:: annotation

🔧 - Generated by Copilot
@WilliamBerryiii WilliamBerryiii merged commit 9fd4bd1 into main Jan 29, 2026
16 checks passed
@WilliamBerryiii WilliamBerryiii deleted the fix/262-prepare-extension-testability branch January 29, 2026 17:44
WilliamBerryiii added a commit that referenced this pull request Feb 4, 2026
🤖 I have created a release *beep* *boop*
---


##
[2.1.0](hve-core-v2.0.1...hve-core-v2.1.0)
(2026-02-04)


### ✨ Features

* add PowerShell script to validate copyright headers
([#370](#370))
([92fce72](92fce72))
* **docs:** Replace deprecated chat.modeFilesLocations with
chat.agentFilesLocations
([#413](#413))
([67fb2ab](67fb2ab))
* **scripts:** add CIHelpers module for CI platform abstraction
([#348](#348))
([23e7a7e](23e7a7e))
* **scripts:** add SecurityHelpers and CIHelpers modules
([#354](#354))
([b93d990](b93d990))
* **workflow:** add copilot-setup-steps.yml for Coding Agent environment
([#398](#398))
([085a38b](085a38b))


### 🐛 Bug Fixes

* **build:** increase release-please search depths to prevent 250-commit
window issue ([#342](#342))
([4bb857d](4bb857d))
* **build:** patch @isaacs/brace-expansion critical vulnerability
([#404](#404))
([292ef51](292ef51))
* **ci:** disable errexit during spell check exit code capture
([#356](#356))
([ed6ed46](ed6ed46))
* **ci:** exclude extension/README.md from frontmatter validation
([#362](#362))
([e0d7378](e0d7378))
* exclude test fixtures from markdown link checker
([#345](#345))
([58147f9](58147f9))
* **extension:** resolve path resolution issues in Windows/WSL
environments ([#407](#407))
([8529725](8529725))
* **linting:** use Write-Error instead of Write-Host for error output
([#377](#377))
([2ca766b](2ca766b))
* **scripts:** apply CI output escaping to infrastructure scripts
([#369](#369))
([251021e](251021e))
* **scripts:** apply CI output escaping to linting scripts
([#367](#367))
([fdd75ed](fdd75ed))
* **scripts:** apply CI output escaping to security scripts
([#368](#368))
([1237c9a](1237c9a))
* **scripts:** ensure reliable array count operations in linting and
security scripts
([#395](#395))
([de43e73](de43e73))
* **scripts:** standardize PowerShell requirements header block
([#385](#385))
([6e26282](6e26282))


### 📚 Documentation

* add doc-ops agent to CUSTOM-AGENTS reference
([#358](#358))
([15f7185](15f7185))
* add memory agent to CUSTOM-AGENTS.md
([#359](#359))
([d92c4e1](d92c4e1))
* add missing agents to extension README
([#357](#357))
([d58541c](d58541c))
* add task-reviewer agent to CUSTOM-AGENTS.md
([#363](#363))
([0efb722](0efb722))
* **contributing:** add copyright header guidelines
([#382](#382))
([881a567](881a567))
* **scripts:** update README.md with missing directory sections
([#355](#355))
([ac2966f](ac2966f))


### ♻️ Refactoring

* **scripts:** align linting and tests with CIHelpers
([#401](#401))
([3587e6a](3587e6a))
* **scripts:** extract Invoke-PackageExtension for testability
([#343](#343))
([858a1be](858a1be))
* **scripts:** extract orchestration function for Prepare-Extension
testability ([#344](#344))
([9fd4bd1](9fd4bd1))
* **scripts:** replace raw GITHUB_OUTPUT with Set-CIOutput in
Package-Extension
([#391](#391))
([74a30bb](74a30bb))
* **security:** move DependencyViolation and ComplianceReport to shared
module ([#378](#378))
([1dd31ad](1dd31ad))


### 🔧 Maintenance

* add copyright headers to PowerShell scripts
([#381](#381))
([d19c9b3](d19c9b3))
* add copyright headers to shell scripts
([#380](#380))
([284b456](284b456))
* **deps-dev:** bump cspell from 9.6.1 to 9.6.2 in the npm-dependencies
group ([#387](#387))
([23c2b9f](23c2b9f))
* **workflows:** simplify Copilot setup steps workflow triggers
([#414](#414))
([492a7b1](492a7b1))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

---------

Co-authored-by: hve-core-release-please[bot] <254602402+hve-core-release-please[bot]@users.noreply.github.com>
Co-authored-by: Bill Berry <wberry@microsoft.com>
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]: Refactor Prepare-Extension.ps1 entry point for testability

4 participants