From d238a23f605f9b7e8b800ad47e43939420407ce3 Mon Sep 17 00:00:00 2001 From: ajn142 <5253718+ajn142@users.noreply.github.com> Date: Mon, 27 Apr 2026 21:34:06 -0500 Subject: [PATCH 1/8] Add MaximumVersion to prevent loading latest installed Pester --- PSKoans/PSKoans.psd1 | 1 + 1 file changed, 1 insertion(+) diff --git a/PSKoans/PSKoans.psd1 b/PSKoans/PSKoans.psd1 index df3e9e77a..ea25792f9 100644 --- a/PSKoans/PSKoans.psd1 +++ b/PSKoans/PSKoans.psd1 @@ -55,6 +55,7 @@ @{ ModuleName = 'Pester' ModuleVersion = '5.0.2' + MaximumVersion = '5.1.1' } ) From 92378a5854e6f7527fb18ac25623c1212a1bcdb2 Mon Sep 17 00:00:00 2001 From: Gilbert Sanchez Date: Sun, 20 Sep 2026 12:18:23 -0700 Subject: [PATCH 2/8] Update PSKoans/PSKoans.psd1 --- PSKoans/PSKoans.psd1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PSKoans/PSKoans.psd1 b/PSKoans/PSKoans.psd1 index ea25792f9..b971d1ef6 100644 --- a/PSKoans/PSKoans.psd1 +++ b/PSKoans/PSKoans.psd1 @@ -55,7 +55,7 @@ @{ ModuleName = 'Pester' ModuleVersion = '5.0.2' - MaximumVersion = '5.1.1' + MaximumVersion = '5.999.999' } ) From 4af6f1a580f91298f3762d0873cf221b7e4ba86f Mon Sep 17 00:00:00 2001 From: Gilbert Sanchez Date: Wed, 30 Sep 2026 00:42:45 +0000 Subject: [PATCH 3/8] Pin Pester dependency to v5 --- requirements.psd1 | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.psd1 b/requirements.psd1 index e8741d4e5..0d8c5f5db 100644 --- a/requirements.psd1 +++ b/requirements.psd1 @@ -9,6 +9,7 @@ Version = '0.7.3' } 'Pester' = @{ + Version = '5.9.0' Parameters = @{ SkipPublisherCheck = $true } From 6d17d91561ce08755aa64b7f3b9f432134e210f2 Mon Sep 17 00:00:00 2001 From: Gilbert Sanchez Date: Wed, 30 Sep 2026 00:46:25 +0000 Subject: [PATCH 4/8] Update PowerShellBuild to 0.8.2 --- requirements.psd1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.psd1 b/requirements.psd1 index 0d8c5f5db..544f0e8dd 100644 --- a/requirements.psd1 +++ b/requirements.psd1 @@ -6,7 +6,7 @@ Version = '4.9.1' } 'PowerShellBuild' = @{ - Version = '0.7.3' + Version = '0.8.2' } 'Pester' = @{ Version = '5.9.0' From 5fe2b981536553fc3872a3468eebc9394d0a87b6 Mon Sep 17 00:00:00 2001 From: Gilbert Sanchez Date: Wed, 30 Sep 2026 00:56:11 +0000 Subject: [PATCH 5/8] Load Pester 5 before PowerShellBuild --- build.ps1 | 27 ++++++++++++++++++++++++--- requirements.psd1 | 6 +++--- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/build.ps1 b/build.ps1 index 55f87b50c..afea248ea 100644 --- a/build.ps1 +++ b/build.ps1 @@ -62,7 +62,28 @@ if ($PSCmdlet.ParameterSetName -eq 'Help') { Format-Table -Property Name, Description, Alias, DependsOn } else { - Set-BuildEnvironment -Force - Invoke-Psake -BuildFile $psakeFile -TaskList $Task -NoLogo - exit ([int](-not $psake.build_success)) + $originalPSModulePath = $env:PSModulePath + $userModulePath = $originalPSModulePath -split [IO.Path]::PathSeparator | + Where-Object { $_ -like "$HOME$([IO.Path]::DirectorySeparatorChar)*" } | + Select-Object -First 1 + + if (-not $userModulePath) { + throw 'Unable to determine the current-user PowerShell module path.' + } + + try { + # PowerShellBuild imports Pester with only a minimum version. Exclude a + # runner-provided Pester 6 so it retains the Pester 5 dependency imported above. + $env:PSModulePath = @( + $userModulePath + (Join-Path -Path $PSHOME -ChildPath 'Modules') + ) -join [IO.Path]::PathSeparator + + Set-BuildEnvironment -Force + Invoke-Psake -BuildFile $psakeFile -TaskList $Task -NoLogo + exit ([int](-not $psake.build_success)) + } + finally { + $env:PSModulePath = $originalPSModulePath + } } diff --git a/requirements.psd1 b/requirements.psd1 index 544f0e8dd..9db2be6a3 100644 --- a/requirements.psd1 +++ b/requirements.psd1 @@ -5,15 +5,15 @@ 'psake' = @{ Version = '4.9.1' } - 'PowerShellBuild' = @{ - Version = '0.8.2' - } 'Pester' = @{ Version = '5.9.0' Parameters = @{ SkipPublisherCheck = $true } } + 'PowerShellBuild' = @{ + Version = '0.8.2' + } 'PSScriptAnalyzer' = @{ Version = '1.19.1' } From 1035dacb7e25af863d060222106e1166ce598f40 Mon Sep 17 00:00:00 2001 From: Gilbert Sanchez Date: Wed, 30 Sep 2026 00:59:44 +0000 Subject: [PATCH 6/8] Import pinned Pester before build dependencies --- build.ps1 | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/build.ps1 b/build.ps1 index afea248ea..9502bf229 100644 --- a/build.ps1 +++ b/build.ps1 @@ -42,6 +42,10 @@ $ErrorActionPreference = 'Stop' $requirementsFile = Join-Path $PSScriptRoot 'requirements.psd1' $psakeFile = Join-Path $PSScriptRoot 'psakeFile.ps1' +$requirements = Import-PowerShellDataFile -Path $requirementsFile +$pesterRequirement = $requirements.Pester +$requirements.Remove('Pester') + if ($Bootstrap) { if (-not (Get-PackageProvider -Name NuGet -ErrorAction SilentlyContinue)) { Install-PackageProvider -Name NuGet -Force -Scope CurrentUser | Out-Null @@ -50,13 +54,18 @@ if ($Bootstrap) { if (-not (Get-Module -Name PSDepend -ListAvailable)) { Install-Module -Name PSDepend -Repository PSGallery -Scope CurrentUser -Force -RequiredVersion '0.3.8' } - Import-Module -Name PSDepend -Verbose:$false - Invoke-PSDepend -Path $requirementsFile -Install -Import -Force -WarningAction SilentlyContinue } -else { - Invoke-PSDepend -Path $requirementsFile -Import -Force -WarningAction SilentlyContinue + +Import-Module -Name PSDepend -Verbose:$false +if ($Bootstrap) { + Invoke-PSDepend -Path $requirementsFile -Install -Force -WarningAction SilentlyContinue } +# PowerShellBuild requires Pester without an upper bound. Load the pinned version +# first, then import the remaining dependencies without re-importing Pester. +Import-Module -Name Pester -RequiredVersion $pesterRequirement.Version +Invoke-PSDepend -InputObject $requirements -Import -Force -WarningAction SilentlyContinue + if ($PSCmdlet.ParameterSetName -eq 'Help') { Get-PSakeScriptTasks -BuildFile $psakeFile | Format-Table -Property Name, Description, Alias, DependsOn From 799b7cea62031826ef3ab317d5438cbf0227c1d1 Mon Sep 17 00:00:00 2001 From: Gilbert Sanchez Date: Wed, 30 Sep 2026 01:03:49 +0000 Subject: [PATCH 7/8] Restrict test Pester module lookup --- build.ps1 | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/build.ps1 b/build.ps1 index 9502bf229..c66577b65 100644 --- a/build.ps1 +++ b/build.ps1 @@ -81,12 +81,9 @@ else { } try { - # PowerShellBuild imports Pester with only a minimum version. Exclude a - # runner-provided Pester 6 so it retains the Pester 5 dependency imported above. - $env:PSModulePath = @( - $userModulePath - (Join-Path -Path $PSHOME -ChildPath 'Modules') - ) -join [IO.Path]::PathSeparator + # PowerShellBuild imports Pester with only a minimum version. Exclude + # runner-provided module paths so it retains the Pester 5 dependency imported above. + $env:PSModulePath = $userModulePath Set-BuildEnvironment -Force Invoke-Psake -BuildFile $psakeFile -TaskList $Task -NoLogo From aabefbffc884f0e3099292961d85f5d9bfb857cb Mon Sep 17 00:00:00 2001 From: Gilbert Sanchez Date: Wed, 30 Sep 2026 01:08:11 +0000 Subject: [PATCH 8/8] Run Pester 5 without PowerShellBuild reload --- build.ps1 | 24 +++--------------------- psakeFile.ps1 | 26 ++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 21 deletions(-) diff --git a/build.ps1 b/build.ps1 index c66577b65..5de615d68 100644 --- a/build.ps1 +++ b/build.ps1 @@ -71,25 +71,7 @@ if ($PSCmdlet.ParameterSetName -eq 'Help') { Format-Table -Property Name, Description, Alias, DependsOn } else { - $originalPSModulePath = $env:PSModulePath - $userModulePath = $originalPSModulePath -split [IO.Path]::PathSeparator | - Where-Object { $_ -like "$HOME$([IO.Path]::DirectorySeparatorChar)*" } | - Select-Object -First 1 - - if (-not $userModulePath) { - throw 'Unable to determine the current-user PowerShell module path.' - } - - try { - # PowerShellBuild imports Pester with only a minimum version. Exclude - # runner-provided module paths so it retains the Pester 5 dependency imported above. - $env:PSModulePath = $userModulePath - - Set-BuildEnvironment -Force - Invoke-Psake -BuildFile $psakeFile -TaskList $Task -NoLogo - exit ([int](-not $psake.build_success)) - } - finally { - $env:PSModulePath = $originalPSModulePath - } + Set-BuildEnvironment -Force + Invoke-Psake -BuildFile $psakeFile -TaskList $Task -NoLogo + exit ([int](-not $psake.build_success)) } diff --git a/psakeFile.ps1 b/psakeFile.ps1 index c33fa5aed..f357956b9 100644 --- a/psakeFile.ps1 +++ b/psakeFile.ps1 @@ -27,6 +27,32 @@ Task GenerateFormatData -Depends Clean { $PSBStageFilesDependency = @('Clean', 'GenerateFormatData') $PSBBuildDependency = @('StageFiles') +$PSBTestDependency = @('Pester5', 'Analyze') + +Task Pester5 -Depends $PSBBuildDependency { + $moduleManifest = Join-Path $PSBPreference.Build.ModuleOutDir "$($PSBPreference.General.ModuleName).psd1" + + Import-Module -Name $moduleManifest -Force + Push-Location -LiteralPath $PSBPreference.Test.RootDir + try { + $configuration = [PesterConfiguration]::Default + $configuration.Output.Verbosity = 'Detailed' + $configuration.Run.PassThru = $true + $configuration.TestResult.Enabled = $true + $configuration.TestResult.OutputPath = $PSBPreference.Test.OutputFile + $configuration.TestResult.OutputFormat = $PSBPreference.Test.OutputFormat + + $testResult = Invoke-Pester -Configuration $configuration + if ($testResult.Result -eq 'Failed') { + throw 'One or more Pester tests failed.' + } + } + finally { + Pop-Location + Remove-Module -Name $PSBPreference.General.ModuleName -ErrorAction SilentlyContinue + } +} -Description 'Executes Pester 5 tests' + Task Default -Depends Test