Skip to content

Fix Pester 5 TagFilter, Health tests invoke actual functions, update Pattern C docs - #607

Closed
arudell with Copilot wants to merge 15 commits into
mainfrom
copilot/fix-code-for-comments
Closed

Fix Pester 5 TagFilter, Health tests invoke actual functions, update Pattern C docs#607
arudell with Copilot wants to merge 15 commits into
mainfrom
copilot/fix-code-for-comments

Conversation

Copilot AI commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Fixes three open review comments from PR #606's review thread.

Description

Summary of changes:

  • tests/offline/RunTests.ps1: Changed $pesterParams.Tag$pesterParams.TagFilter. Pester 5 uses TagFilter; the old key silently added an unsupported parameter to Invoke-Pester, causing tag-filtered runs to fail before executing any tests.
  • tests/offline/Health.Tests.ps1: Replaced fixture-only validation tests with tests that actually invoke Test-SdnResourceProvisioningState and Test-SdnResourceConfigurationState inside InModuleScope SdnDiag.Health with Mock Get-SdnResource. The old tests would remain green if the health functions were removed or broken. Get-SdnResource is mockable in Health's scope because SdnDiag.Health.psm1 explicitly imports SdnDiag.NetworkController.psm1. Tests now cover FAIL/PASS/WARNING branches and the guard clause that skips config-state checks when provisioningState is not Succeeded.
  • tests/CONTRIBUTING_TESTS.md: Updated Pattern C from "validate fixture data structures" to the correct InModuleScope SdnDiag.Health + Mock Get-SdnResource invocation pattern with explanation.
# New Health.Tests.ps1 pattern
Describe 'Health - Test-SdnResourceProvisioningState' {
    It "Returns FAIL when resource has Failed provisioning state" {
        InModuleScope SdnDiag.Health {
            Mock Get-SdnResource {
                return $Global:PesterOfflineTests.SdnApiResourcesByRef['/servers/DVLAB-S1-N04']
            }
            $result = Test-SdnResourceProvisioningState -Resource 'Servers' -ResourceId 'DVLAB-S1-N04' -NcUri 'https://dvlab-nc.dvlab.contoso.local'
            $result.Result | Should -Be 'FAIL'
        }
    }
}

Change type

  • Bug fix (non-breaking change)
  • Code style update (formatting, local variables)
  • New Feature (non-breaking change that adds new functionality without impacting existing)
  • Breaking change (fix or feature that may cause functionality impact)
  • Other

Checklist:

  • My code follows the style and contribution guidelines of this project.
  • I have tested and validated my code changes.

arudell and others added 13 commits July 15, 2026 10:28
- Add Utilities.Tests.ps1: Format-* and Confirm-IpAddress* unit tests
- Add Health.Tests.ps1: provisioning/configuration state, MAC duplicate detection
- Expand NetworkController.Tests.ps1: Get-SdnGateway, Get-SdnLoadBalancerMux, Get-SdnResource
- Replace all mock data with consistent DVLAB-prefixed randomized names
- Update RunTests.ps1: add -Tag and -TestFile parameters, handle wrapped JSON
- Add CONTRIBUTING_TESTS.md: instructions for adding new Pester tests
- Update README.md: document new runner options, link to CONTRIBUTING_TESTS.md

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: d38da7cf-014a-4a03-950b-4ba39152b58d
- Add 'Pester Tests' workflow (pester-tests.yml): runs offline tests on
  every push to main and every PR targeting main
- Add 'Run Offline Pester Tests' step to build-pipeline.yml so tests
  gate the publish step

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: d38da7cf-014a-4a03-950b-4ba39152b58d
Online tests required a live SDN environment on a self-hosted runner
and are no longer maintained. All validation is now covered by the
offline mock-based Pester tests.

Removed:
- .github/workflows/server2019-sdntest.yml
- .github/workflows/server2019-sdntest-pr.yml
- tests/online/ (RunTests.ps1, config sample, wave1/, waveAll/)

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: d38da7cf-014a-4a03-950b-4ba39152b58d
- Create .github/instructions/pester-tests.instructions.md with full
  skill guide (patterns, mock data, naming, CI, running tests)
- Add Pester Testing section to .github/copilot-instructions.md
- Remove online test references from CONTRIBUTING_TESTS.md (online tests
  were deleted in prior commit)

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: d38da7cf-014a-4a03-950b-4ba39152b58d
- .github/prompts/create-pester-test.prompt.md: reusable slash command
  to generate offline Pester tests for any function
- .github/instructions/pester-review.instructions.md: code review rule
  that flags PRs adding/modifying functions without corresponding tests

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: d38da7cf-014a-4a03-950b-4ba39152b58d
Single prompt that creates a new function following project conventions
AND generates its corresponding offline Pester tests in one invocation.
Instructions files remain separate for passive context loading.

- Remove: .github/prompts/create-pester-test.prompt.md
- Add: .github/prompts/add-sdn-function.prompt.md

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: d38da7cf-014a-4a03-950b-4ba39152b58d
- Use InModuleScope SdnDiagnostics for private utility functions
- Use InModuleScope SdnDiag.NetworkController with Mock Invoke-RestMethodWithRetry
  for NC REST functions (nested module session state requires this pattern)
- Fix MAC duplicate test @() wrapper for Group-Object single-result
- Add outboundNatRules back-reference to LB mock data
- Update instruction docs with correct mock patterns

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: d38da7cf-014a-4a03-950b-4ba39152b58d
- RunTests.ps1: add -PassThru and failure propagation
- Workflows: route through RunTests.ps1 for consistent exit codes
- Health.Tests.ps1: rewrite as data structure validation tests
  (direct invocation blocked by [TraceLevel] cross-module limitation)
- CONTRIBUTING_TESTS.md: rewrite with accurate patterns and limitation docs
- README.md: remove online test references, offline-only layout
- add-sdn-function.prompt.md: fix module location table
- pester-review.instructions.md: add manifest export check

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: d38da7cf-014a-4a03-950b-4ba39152b58d
- pester-tests.instructions.md: add applyTo frontmatter for scope targeting
- pester-tests.instructions.md: document singleton fixture exception (no wrapper)
- add-sdn-function.prompt.md: note singleton format for config endpoints
- copilot-instructions.md: fix Pattern B to correctly reference Invoke-RestMethodWithRetry
- Utilities.Tests.ps1: add /0 CIDR edge case (documents known bit-shift limitation)

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: d38da7cf-014a-4a03-950b-4ba39152b58d
Resolve modify/delete conflicts: online test workflows were intentionally
removed in this branch. Accept our deletion over main's modifications.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: d38da7cf-014a-4a03-950b-4ba39152b58d
- Fix Confirm-IpAddressInCidrRange: special-case prefix length 0 to avoid
  32-bit shift wrap (modulo 32 made /0 behave like /32)
- Update test to assert correct /0 behavior (Should -BeTrue)
- Fix 'one assertion per It' rule to 'one behavior per It' in both
  pester-tests.instructions.md and CONTRIBUTING_TESTS.md
- Fix BeforeAll mock guidance: mocks must live inside InModuleScope blocks,
  not in BeforeAll outside them

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: d38da7cf-014a-4a03-950b-4ba39152b58d
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot July 15, 2026 21:57
Copilot AI requested review from Copilot and removed request for Copilot July 15, 2026 22:06
Copilot AI requested review from Copilot and removed request for Copilot July 15, 2026 22:07
Copilot AI changed the title [WIP] Fix code based on review comments Fix Pester 5 TagFilter, Health tests invoke actual functions, update Pattern C docs Jul 15, 2026
Copilot AI requested a review from arudell July 15, 2026 22:08
@arudell arudell closed this Jul 17, 2026
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.

2 participants