Repository navigation
Invoke-ManualPester - Run the tests from outside the module - #10830
Conversation
Pure rename. The next commit turns the function into a script, which re-indents every line of its body, so the move is kept apart to let the conversion show up as its own diff. (do Get-DbaBuild) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Invoke-ManualPester was a private function of dbatools, so the way the contributor guide documents it - Import-Module .\dbatools.psm1, then Invoke-ManualPester - ran it inside the module. Pester runs the test files in the scope of whoever calls Invoke-Pester, so the tests ran inside the module too, where Get-Module -Name dbatools also returns the binary module that dbatools.psm1 loads from dbatools.dll. Mock -ModuleName dbatools and every read of the module base broke. Its Import-Module -Force also removed the module it was running in, which took its begin-block helpers with it (the Pester header check silently did not run), and left no dbatools module in the session. The runner is now a script, tests\Invoke-ManualPester.ps1, started by its path like tests\appveyor.pester.ps1. Its code is unchanged apart from the function wrapper. ci-azure.yml already dot-sourced it from outside the module and now calls the script; the contributor guide, the pull request template and tests\CLAUDE.md show the new call. Get-DbaBuild.Tests.ps1 goes from 23 tests with 8 failures to 92 tests, 89 passed, 3 integration tests not run, on PowerShell 7.6 and 5.1. Part of #10827 (do Get-DbaBuild) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The tests read the module base from Get-Module -Name dbatools filtered by ModuleBase -NotMatch net (#8959). That no longer excludes the binary module of the same name, whose base is now core\lib or desktop\lib, and it drops the script module as well when the working copy sits below a path that contains "net": from a working copy below ...\dotnet\, the file ran 23 tests with 7 failures, with the fixed runner too. Filter on ModuleType -eq "Script" instead, as Invoke-DbaDbDecryptObject.Tests.ps1 does since #10581. From both paths the file now runs 92 tests, 89 passed. Fixes #10827 (do Get-DbaBuild) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
potatoqualitee
left a comment
There was a problem hiding this comment.
Reviewed head 4610625d311eaef28d72216224ce3fc18ca62e86.
Reviewed the script relocation, module-scope isolation, CI call site, and affected test/module detection. Running Pester from a standalone script addresses module-scope contamination without changing production commands. No material defect identified.
potatoqualitee
left a comment
There was a problem hiding this comment.
Fresh review of head 4610625d311eaef28d72216224ce3fc18ca62e86.
Reviewed all seven changed files, the module loader, complete runner flow, updated CI call site and result checks, module selection in the tests, discussion and CI. Independently normalized the old function body against the new script: the executable body is unchanged after removing the wrapper. No material regression found.
Executed the actual script in a disposable copy on PowerShell 7.6.7 with Pester 6.0.0: 89 passed, 0 failed, 3 integration cases not run. The first run hit the unchanged Get-DbaBuild cold-cache path, which bypasses its mocked update call when creating the writable index; the unchanged rerun passed after initialization. The script module remains available afterward. Current import/platform/security checks pass; main ci-azure is still pending.
|
thank you kindly |
Fixes #10827
Problem
Run the way the contributor guide documents it (
Import-Module .\dbatools.psm1, thenInvoke-ManualPester -Path Get-DbaBuild),Get-DbaBuild.Tests.ps1ran 23 tests with 8 failures and printed errors for every test file. Started from outside the module, the same file passes.Mechanism
Invoke-ManualPesterlived inprivate/testing, whichdbatools.psm1dot-sources into the module. Called as a module function:Invoke-Pesterruns the test files in the session state of its caller, so the tests ran inside the dbatools module. ThereGet-Module -Name dbatoolsalso returns the binary module thatdbatools.psm1:115loads fromdbatools.dll.Mock Update-DbaBuildReference -ModuleName dbatoolswas never hit, and$ModuleBaseinGet-DbaBuild.Tests.ps1became two paths joined by a space.Import-Module dbatools.psd1 -Forceremoved the module it was running in, and with it the functions defined in itsbeginblock.Write-DetailedMessageandTest-PesterTestHeaderfailed, so a test file without the Pester header was run instead of reported.CI was not affected:
appveyor.pester.ps1runs Pester from a script, and the Windows SSPI step inci-azure.ymlalready dot-sourced the file from outside the module.What changed
private/testing/Invoke-ManualPester.ps1moves totests/Invoke-ManualPester.ps1and becomes a script that is started by its path and needs noImport-Modulefirst. The first commit is the pure rename. The second removes the function wrapper, which re-indents the body (use "Hide whitespace"). The code is otherwise unchanged. The help says why it is a script, and its examples use the new call.ci-azure.ymlcalls the script instead of dot-sourcing the function.CONTRIBUTING-TESTING.md, the pull request template andtests/CLAUDE.mdshow.\tests\Invoke-ManualPester.ps1 -Path <command>.Get-DbaBuild.Tests.ps1(lines 31 and 193) finds the script module withModuleType -eq "Script"instead ofModuleBase -NotMatch net(Get/Test-DbaBuild, handle version "aliases" #8959), asInvoke-DbaDbDecryptObject.Tests.ps1does since Invoke-DbaDbDecryptObject - Add DataPages to decrypt without a dedicated admin connection #10581. The old filter no longer excludes the binary module, whose base is nowcore\libordesktop\lib. It also drops the script module when the working copy sits below a path that contains "net", for exampleC:\Users\Kenneth\...orD:\dotnet\....Deliberately not changed
Invoke-ManualPesteris no longer a command after importing dbatools, and no stub is left behind.Get-Module -Name dbatoolswithout a filter (Get-DbaWaitingTask,Import-DbaParquet,Find-DbaCommand,Set-DbatoolsConfig, and the manySelect-Object -First 1sites) only see two modules inside the module's scope, which the runner no longer enters.Invoke-DbaDbDecryptObject.Tests.ps1that name Invoke-ManualPester as the source of the two modules. The comment stays as written, and the workaround is harmless.Tests
Lab, PowerShell 7.6.3 and Windows PowerShell 5.1, dbatools.library 2026.9.14.
developmentis c8f2da6.developmentGet-DbaBuildthrough the runner, fresh sessionImport-Module .\dbatools.psm1ci-azure.ymlstep...\dotnet\(junction, 7.6 only), old vs newGet-DbaBuild.Tests.ps1.\tests\Invoke-ManualPester.ps1 -Path Get-DbaBuild -ScriptAnalyzer -Complianceon 7.6: Compliance 61 passed, 0 failed, and ScriptAnalyzer reports no findings.There is no new Pester test, because the change is in the test tooling and the runs above are its proof. The Windows SSPI step in
ci-azure.ymlruns only when its partition has tests selected, so it may be skipped on this pull request. The lab row "Same call as theci-azure.ymlstep" covers the call itself.🤖 Generated with Claude Code