Skip to content

Update Pester to 6.0.0#2464

Merged
johlju merged 4 commits into
dsccommunity:mainfrom
nohwnd:pester-6-rc
Jul 8, 2026
Merged

Update Pester to 6.0.0#2464
johlju merged 4 commits into
dsccommunity:mainfrom
nohwnd:pester-6-rc

Conversation

@nohwnd

@nohwnd nohwnd commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

Pester 6.0.0 is now released 🎉 — thanks for letting me pilot the release candidates against your suite.

This updates the earlier release-candidate pin to the final 6.0.0 and keeps the test changes needed to run on Pester 6 (already in this PR). It's the same migration you'd make yourself, so you're welcome to merge it, cherry-pick just the compatibility changes, or use it purely as a reference.

Your unit + HQRM + full integration matrix all pass on 6.0.0 in this PR. 🟢

The real-world CI signal from this pilot was genuinely valuable in getting 6.0.0 right. Thanks for the CI time this used, and for maintaining a suite I could test against.

This PR was co-authored by GitHub Copilot.

— Jakub & Copilot


This change is Reviewable

@coderabbitai

coderabbitai Bot commented Jun 28, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

Pins Pester to version 6.0.0 in RequiredModules.psd1 and updates unit test files across the repository to add forwarding/default mocks for cmdlets like New-Object, Test-Path, Get-PrimaryReplicaServerObject, and Get-RegistryPropertyValue to accommodate Pester 6's no-fallthrough mocking behavior, plus consolidates duplicate cleanup logic and adds a changelog entry.

Changes

Pester 6 Test Mock Compatibility

Layer / File(s) Summary
Pin Pester version
RequiredModules.psd1
Pester dependency changed from 'latest' with prerelease to fixed version 6.0.0.
New-Object forwarding mocks and assertions
tests/Unit/DSC_SqlDatabaseObjectPermission.Tests.ps1, tests/Unit/DSC_SqlLogin.Tests.ps1, tests/Unit/SqlServerDsc.Common/Public/Connect-Sql.Tests.ps1
Default New-Object mocks forward unmatched calls to the real cmdlet, and DSC_SqlLogin assertions now check TypeName via ParameterFilter.
Test-Path forwarding mocks
tests/Unit/Private/Invoke-ReportServerSetupAction.Tests.ps1, tests/Unit/Public/Save-SqlDscSqlServerMediaFile.Tests.ps1
Default Test-Path mocks forward unmatched calls to the real cmdlet using bound parameters.
Other default mock additions and cleanup
tests/Unit/DSC_SqlAG.Tests.ps1, tests/Unit/DSC_SqlSetup.Tests.ps1, tests/Unit/Public/Get-SqlDscConfigurationOption.Tests.ps1
Adds default mocks for Get-PrimaryReplicaServerObject and Get-RegistryPropertyValue, and consolidates duplicate AfterAll global variable cleanup.
Changelog entry
CHANGELOG.md
Documents the Pester 6 compatibility fixes.

Estimated code review effort: 2 (Simple) | ~15 minutes

Possibly related PRs

  • dsccommunity/SqlServerDsc#2433: Both PRs modify tests/Unit/SqlServerDsc.Common/Public/Connect-Sql.Tests.ps1 mocking of New-Object for Connect-Sql's Server/ServerConnection construction.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: bumping Pester to 6.0.0.
Description check ✅ Passed The description is directly related to the PR and accurately explains the Pester 6.0.0 migration and compatibility updates.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Jun 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94%. Comparing base (9400ebf) to head (65d2861).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@          Coverage Diff           @@
##           main   #2464     +/-   ##
======================================
+ Coverage    91%     94%     +2%     
======================================
  Files        32     227    +195     
  Lines      5353   10871   +5518     
======================================
+ Hits       4904   10235   +5331     
- Misses      449     636    +187     
Flag Coverage Δ
unit 94% <ø> (+2%) ⬆️
see 197 files with indirect coverage changes
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@johlju

johlju commented Jun 28, 2026

Copy link
Copy Markdown
Member

@nohwnd

nohwnd commented Jun 28, 2026

Copy link
Copy Markdown
Contributor Author

Yup. This pipeline is being fixed, was just waiting for release of rc2 which reverts another issue that impacts this repo.

nohwnd and others added 2 commits June 28, 2026 20:14
Update the existing RequiredModules Pester prerelease pin from latest to 6.0.0-rc1.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
….0.0-rc2

Pester 6 no longer falls through to the real command when a mock with a
-ParameterFilter does not match, removed Assert-* helpers, and throws on
duplicate AfterAll blocks. Update the affected unit tests:

- Add forwarding default mocks (-> real cmdlet via Get-Command -CommandType
  Cmdlet) for Test-Path and New-Object where mock bodies or validation call
  the cmdlet with arguments not covered by an existing -ParameterFilter
  (Save-SqlDscSqlServerMediaFile, Invoke-ReportServerSetupAction,
  DSC_SqlDatabaseObjectPermission, Connect-SQL, DSC_SqlLogin).
- Add a $null default mock for Get-RegistryPropertyValue in
  SqlSetup\Get-TargetResource so registry lookups other than ImagePath resolve
  to $null as the real function does on a build agent.
- Add a default Get-PrimaryReplicaServerObject mock returning the passed
  ServerObject in SqlAG\Set-TargetResource.
- Filter the two New-Object Should -Invoke assertions in DSC_SqlLogin to the
  SMO Login type so the forwarding default does not change the counts.
- Merge a duplicate AfterAll block in Get-SqlDscConfigurationOption.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
nohwnd and others added 2 commits July 1, 2026 09:33
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@nohwnd nohwnd changed the title [DO NOT MERGE] Pester 6.0.0 release candidate update Update Pester to 6.0.0 Jul 7, 2026
@nohwnd
nohwnd marked this pull request as ready for review July 8, 2026 07:17
@nohwnd
nohwnd requested review from a team and johlju as code owners July 8, 2026 07:17
@nohwnd

nohwnd commented Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

Something shifted, build was green on rc4, and now there is test failure. Leaving this in your hands to fix or close.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
RequiredModules.psd1 (1)

14-20: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Pester pin to 6.0.0 looks correct.

Stale comment: the note above the block says "Add a default Mock for commands where some calls don't match a -ParameterFilter — mocks no longer fall through to the real command" is actually the migration fix applied elsewhere in this PR — the comment at lines 14-17 in this file refers to a different, now-outdated concern ("if preview release of Pester prevents release we should temporary shift back to stable"). Since this is now pinned to the final 6.0.0 release rather than a preview, consider updating or removing this comment.

✏️ Suggested comment update
-    <#
-        If preview release of Pester prevents release we should temporary shift
-        back to stable.
-    #>
     Pester                         = @{
         Version = '6.0.0'
     }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@RequiredModules.psd1` around lines 14 - 20, The comment above the Pester
dependency block is stale and refers to an outdated preview-release fallback
that no longer matches the pinned 6.0.0 version. Update or remove the note in
RequiredModules.psd1 near the Pester entry so it accurately reflects the current
fixed release, keeping the comment aligned with the dependency version and the
migration context in this file.
tests/Unit/DSC_SqlDatabaseObjectPermission.Tests.ps1 (1)

92-99: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Correct fix for Pester 6 no-fallthrough behavior.

The forwarding default mock correctly routes unmatched New-Object calls to the real cmdlet via Get-Command -CommandType Cmdlet, avoiding recursion into the mock itself. Registration order (generic default first, specific ParameterFilter mock afterward in the nested Context) is correct since Pester matches the most-recently-registered matching mock first.

This exact snippet is duplicated verbatim in tests/Unit/DSC_SqlLogin.Tests.ps1 (twice) and tests/Unit/SqlServerDsc.Common/Public/Connect-Sql.Tests.ps1. Consider extracting it into a shared helper (e.g. in CommonTestHelper.psm1) to avoid maintaining four copies of the same Pester-6-compatibility workaround.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/Unit/DSC_SqlDatabaseObjectPermission.Tests.ps1` around lines 92 - 99,
The Pester 6 forwarding mock for New-Object is duplicated across multiple test
files, so consolidate this workaround into a shared test helper instead of
maintaining several identical copies. Move the generic forwarding mock logic
into a reusable helper in CommonTestHelper.psm1 (or an equivalent shared test
utility), then call that helper from DSC_SqlDatabaseObjectPermission.Tests.ps1,
DSC_SqlLogin.Tests.ps1, and Connect-Sql.Tests.ps1. Keep the existing
registration order and behavior intact so the default New-Object fallback still
forwards unmatched calls to the real cmdlet without recursion.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@RequiredModules.psd1`:
- Around line 14-20: The comment above the Pester dependency block is stale and
refers to an outdated preview-release fallback that no longer matches the pinned
6.0.0 version. Update or remove the note in RequiredModules.psd1 near the Pester
entry so it accurately reflects the current fixed release, keeping the comment
aligned with the dependency version and the migration context in this file.

In `@tests/Unit/DSC_SqlDatabaseObjectPermission.Tests.ps1`:
- Around line 92-99: The Pester 6 forwarding mock for New-Object is duplicated
across multiple test files, so consolidate this workaround into a shared test
helper instead of maintaining several identical copies. Move the generic
forwarding mock logic into a reusable helper in CommonTestHelper.psm1 (or an
equivalent shared test utility), then call that helper from
DSC_SqlDatabaseObjectPermission.Tests.ps1, DSC_SqlLogin.Tests.ps1, and
Connect-Sql.Tests.ps1. Keep the existing registration order and behavior intact
so the default New-Object fallback still forwards unmatched calls to the real
cmdlet without recursion.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 5c6b084d-f55e-4d85-9bee-62468f3fa455

📥 Commits

Reviewing files that changed from the base of the PR and between 1be7d60 and 65d2861.

📒 Files selected for processing (10)
  • CHANGELOG.md
  • RequiredModules.psd1
  • tests/Unit/DSC_SqlAG.Tests.ps1
  • tests/Unit/DSC_SqlDatabaseObjectPermission.Tests.ps1
  • tests/Unit/DSC_SqlLogin.Tests.ps1
  • tests/Unit/DSC_SqlSetup.Tests.ps1
  • tests/Unit/Private/Invoke-ReportServerSetupAction.Tests.ps1
  • tests/Unit/Public/Get-SqlDscConfigurationOption.Tests.ps1
  • tests/Unit/Public/Save-SqlDscSqlServerMediaFile.Tests.ps1
  • tests/Unit/SqlServerDsc.Common/Public/Connect-Sql.Tests.ps1

@johlju

johlju commented Jul 8, 2026

Copy link
Copy Markdown
Member

Something shifted, build was green on rc4, and now there is test failure. Leaving this in your hands to fix or close.

Yeah, there are intermittent error due to resources on build workers (certain times during the day are worse that others). It is normal for me to have to restart the jobs unfortunately.

@johlju johlju left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

@johlju reviewed 10 files and all commit messages, and made 1 comment.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on nohwnd).

@johlju
johlju merged commit c1e5855 into dsccommunity:main Jul 8, 2026
40 checks passed
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