Skip to content

test(scripts): add Pester test infrastructure and GitMocks module#202

Merged
WilliamBerryiii merged 3 commits intomainfrom
feat/193-pester-infrastructure
Jan 17, 2026
Merged

test(scripts): add Pester test infrastructure and GitMocks module#202
WilliamBerryiii merged 3 commits intomainfrom
feat/193-pester-infrastructure

Conversation

@WilliamBerryiii
Copy link
Copy Markdown
Member

test(scripts): add Pester test infrastructure and GitMocks module

Description

Establishes the foundational Pester 5.x test infrastructure for PowerShell script validation in the HVE-Core repository. This adds a reusable configuration system with CI/local execution modes and a comprehensive mock helper module for Git CLI and GitHub Actions testing scenarios.

  • feat(scripts/tests): Added pester.config.ps1 with dual-mode execution support—CI mode enables exit codes, GithubActions output format, and NUnit XML test results; local mode provides detailed verbosity for interactive debugging
  • feat(scripts/tests/Mocks): Added GitMocks.psm1 module with 10 exported functions for test isolation:
    • Environment management: Save-GitHubEnvironment, Restore-GitHubEnvironment, Initialize-MockGitHubEnvironment, Clear-MockGitHubEnvironment, Remove-MockGitHubFiles
    • Git command mocking: Initialize-GitMocks, Set-GitMockChangedFiles, Set-GitMockMergeBaseFailure
    • Test data generators: New-MockFileList, Get-MockGitDiffScenario
  • chore(scripts/tests/Fixtures): Added .gitkeep placeholder for test fixtures directory

Related Issue(s)

Closes #193

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 chatmode and addressed all feedback
  • Copilot instructions (.github/instructions/*.instructions.md)
  • Copilot prompt (.github/prompts/*.prompt.md)
  • Copilot chatmode (.github/chatmodes/*.chatmode.md)

Note for AI Artifact Contributors:

  • Chatmodes: Research, indexing/referencing other project (using standard VS Code GitHub Copilot/MCP tools), planning, and general implementation chatmodes likely already exist. Review .github/chatmodes/ before creating new ones.
  • Model Versions: Only contributions targeting the latest Anthropic and OpenAI models will be accepted. Older model versions (e.g., GPT-3.5, Claude 3) will be rejected.
  • See Chatmodes Not Accepted and Model Version Requirements.

Other:

  • Script/automation (.ps1, .sh, .py)
  • Other (please describe):

Sample Prompts (for AI Artifact Contributions)

Testing

  • Verified pester.config.ps1 returns valid PesterConfiguration object
  • Verified pester.config.ps1 -CI enables exit codes and GithubActions format
  • Verified GitMocks.psm1 imports successfully and exports all 10 functions
  • All files passed PSScriptAnalyzer validation with repository settings

Checklist

Required Checks

  • Documentation is updated (if applicable)
  • Files follow existing naming conventions
  • Changes are backwards compatible (if applicable)

AI Artifact Contributions

  • Used prompt-builder chatmode 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

This PR is part of the broader Pester testing framework initiative tracked in GitHub issue #190. It establishes the infrastructure foundation (sub-issue #193) that subsequent PRs will build upon for actual test implementations.

🧪 - Generated by Copilot

Copilot AI review requested due to automatic review settings January 17, 2026 00:08
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Jan 17, 2026

Dependency Review

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

Scanned Files

None

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 establishes the foundational Pester 5.x test infrastructure for PowerShell scripts in the HVE-Core repository. It introduces a configurable test execution framework with CI/local modes and a comprehensive mock helper module for isolating Git CLI and GitHub Actions dependencies in tests.

Changes:

  • Added Pester configuration script with dual-mode execution (CI with exit codes and NUnit XML output vs. local with detailed verbosity)
  • Created GitMocks module with 10 helper functions for mocking Git commands, managing GitHub Actions environment state, and generating test data
  • Added fixtures directory placeholder for test data files

Reviewed changes

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

File Description
scripts/tests/pester.config.ps1 Pester 5.x configuration script with CI/local modes, test result output, and code coverage settings
scripts/tests/Mocks/GitMocks.psm1 Reusable mock helper module providing Git CLI mocks, GitHub Actions environment management, and test data generators
scripts/tests/Fixtures/.gitkeep Placeholder for test fixtures directory

WilliamBerryiii added a commit that referenced this pull request Jan 17, 2026
- add standard script header to pester.config.ps1
- add standard module header to GitMocks.psm1
- add .DESCRIPTION to Initialize-GitMocks and Initialize-MockGitHubEnvironment
- fix Test-Path mock filter to catch implicit Leaf checks

🔧 - Generated by Copilot
@WilliamBerryiii WilliamBerryiii requested a review from a team as a code owner January 17, 2026 01:13
- add pester.config.ps1 with CI and local execution support
- add GitMocks.psm1 with 10 exported mock helper functions
- create scripts/tests/ directory structure with Mocks and Fixtures

🧪 - Generated by Copilot
- add standard script header to pester.config.ps1
- add standard module header to GitMocks.psm1
- add .DESCRIPTION to Initialize-GitMocks and Initialize-MockGitHubEnvironment
- fix Test-Path mock filter to catch implicit Leaf checks

🔧 - Generated by Copilot
@WilliamBerryiii WilliamBerryiii force-pushed the feat/193-pester-infrastructure branch from cee34c5 to 03269a7 Compare January 17, 2026 01:14
Copilot AI review requested due to automatic review settings January 17, 2026 01:14
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 2 out of 3 changed files in this pull request and generated 4 comments.

- remove Created date from pester.config.ps1 header
- remove Created date from GitMocks.psm1 header
- remove Usage example comment from pester.config.ps1
- remove plan-phase marker from code coverage comment

🧹 - Generated by Copilot
@WilliamBerryiii WilliamBerryiii merged commit f79a405 into main Jan 17, 2026
14 checks passed
@WilliamBerryiii WilliamBerryiii deleted the feat/193-pester-infrastructure branch January 17, 2026 01:26
WilliamBerryiii added a commit that referenced this pull request Jan 17, 2026
…ntegration (#204)

# Pull Request

## Description

Adds a reusable GitHub Actions workflow for running Pester tests across
the repository and integrates it into the PR validation pipeline. This
provides standardized PowerShell testing infrastructure that blocks PRs
with failing tests.

Key features:

- **Reusable pester-tests.yml workflow**:
- `workflow_call` trigger enables reuse from other workflows via `uses:
./.github/workflows/pester-tests.yml`
- Configurable inputs: `soft-fail` (default: false),
`changed-files-only` (default: true)
  - Pester 5.x with `-CI` configuration for CI-optimized output
  - Artifact upload persists NUnit XML results for 30 days

- **PR validation integration**:
  - Adds `pester-tests` job to pr-validation.yml
  - Configured with `soft-fail: false` to block PRs with failing tests
  - Uses `changed-files-only: true` for efficiency

- **Security**:
  - All GitHub Actions are SHA-pinned to prevent supply chain attacks
  - Uses `persist-credentials: false` on checkout
  - Minimal `contents: read` permission scope

## Related Issue(s)

Closes #194
Closes #195

## 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:**

- [x] GitHub Actions workflow
- [ ] Linting configuration (markdown, PowerShell, etc.)
- [ ] Security configuration
- [ ] DevContainer configuration
- [ ] Dependency update

**AI Artifacts:**

- [ ] Reviewed contribution with `prompt-builder` chatmode and addressed
all feedback
- [ ] Copilot instructions (`.github/instructions/*.instructions.md`)
- [ ] Copilot prompt (`.github/prompts/*.prompt.md`)
- [ ] Copilot chatmode (`.github/chatmodes/*.chatmode.md`)

**Other:**

- [ ] Script/automation (`.ps1`, `.sh`, `.py`)
- [ ] Other (please describe):

## Testing

- Validated YAML syntax
- Confirmed workflow structure matches existing patterns
(ps-script-analyzer.yml)
- Verified SHA pins match approved versions in tool-checksums.json

## Checklist

### Required Checks

- [x] Documentation is updated (if applicable)
- [x] Files follow existing naming conventions
- [x] Changes are backwards compatible (if applicable)

### AI Artifact Contributions

N/A - This PR does not include AI artifacts.

### Required Automated Checks

The following validation commands must pass before merging:

- [x] Markdown linting: `npm run lint:md`
- [x] Spell checking: `npm run spell-check`
- [x] Frontmatter validation: `npm run lint:frontmatter`
- [x] 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

**Security notes:**

- Uses `persist-credentials: false` on checkout to prevent credential
leakage
- Minimal `contents: read` permission scope at both workflow and job
levels
- All GitHub Actions are SHA-pinned to prevent supply chain attacks:
  - `actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8` (v4.2.2)
- `actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f`
(v4.4.3)

## Additional Notes

This workflow builds on the Pester infrastructure established in #202
(pester.config.ps1, GitMocks.psm1). Future PRs will add actual test
files that leverage this workflow.
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]: Add Pester test infrastructure (config, directories, shared mocks)

3 participants