Commit 9fd4bd1
authored
refactor(scripts): extract orchestration function for Prepare-Extension testability (#344)
## 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:**
- [x] Script/automation (`.ps1`, `.sh`, `.py`)
- [ ] Other (please describe):
## Sample Prompts (for AI Artifact Contributions)
<!-- Not applicable - no AI artifacts in this PR -->
## 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)
- [x] Files follow existing naming conventions
- [x] Changes are backwards compatible (if applicable)
- [x] Tests added for new functionality (if applicable)
### AI Artifact Contributions
<!-- Not applicable -->
- [ ] 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`
- [x] PowerShell analysis: `npm run lint:ps`
## Security Considerations
- [x] This PR does not contain any sensitive or NDA information
- [x] Any new dependencies have been reviewed for security issues
- [x] 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 Copilot1 parent 4612929 commit 9fd4bd1
File tree
2 files changed
+487
-216
lines changed- scripts
- extension
- tests/extension
2 files changed
+487
-216
lines changed
0 commit comments