Skip to content

Commit 560edb3

Browse files
nohwndCopilot
andcommitted
Batch repro variants + real dbatools test for #2829
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 74305f6 commit 560edb3

5 files changed

Lines changed: 277 additions & 191 deletions

File tree

.github/workflows/repro-2829.yml

Lines changed: 55 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ on:
77
workflow_dispatch:
88

99
jobs:
10-
repro:
10+
synthetic:
1111
runs-on: windows-2022
1212
strategy:
1313
fail-fast: false
1414
matrix:
1515
pester: ['5.7.1', '6.0.0-rc1', '6.0.0-rc2', '6.0.0-rc3', '6.0.0-rc4']
16-
name: Pester ${{ matrix.pester }}
16+
name: synthetic ${{ matrix.pester }}
1717
steps:
1818
- uses: actions/checkout@v4
1919

@@ -32,14 +32,63 @@ jobs:
3232
if (-not (Test-Path $psd1)) { throw "psd1 not found at $psd1" }
3333
"PESTER_PSD1=$psd1" | Out-File -FilePath $env:GITHUB_ENV -Append -Encoding utf8
3434
35-
- name: Run repro on Windows PowerShell 5.1 (Desktop)
35+
- name: Variants on Windows PowerShell 5.1 (Desktop)
3636
shell: powershell
3737
continue-on-error: true
3838
run: |
39-
powershell -NoProfile -ExecutionPolicy Bypass -File .repro2829\run.ps1 -PesterPsd1 "$env:PESTER_PSD1" -Repro ".repro2829\repro.ps1"
39+
powershell -NoProfile -ExecutionPolicy Bypass -File .repro2829\variants.ps1 -PesterPsd1 "$env:PESTER_PSD1"
4040
41-
- name: Run repro on PowerShell 7 (Core)
41+
- name: Variants on PowerShell 7 (Core)
4242
shell: pwsh
4343
continue-on-error: true
4444
run: |
45-
pwsh -NoProfile -File .repro2829/run.ps1 -PesterPsd1 "$env:PESTER_PSD1" -Repro ".repro2829/repro.ps1"
45+
pwsh -NoProfile -File .repro2829/variants.ps1 -PesterPsd1 "$env:PESTER_PSD1"
46+
47+
real:
48+
runs-on: windows-2022
49+
strategy:
50+
fail-fast: false
51+
matrix:
52+
pester: ['5.7.1', '6.0.0-rc4']
53+
name: real dbatools ${{ matrix.pester }}
54+
steps:
55+
- uses: actions/checkout@v4
56+
57+
- name: Save Pester ${{ matrix.pester }} and dbatools.library
58+
shell: pwsh
59+
run: |
60+
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
61+
Get-PackageProvider -Name NuGet -ForceBootstrap | Out-Null
62+
63+
$ver = '${{ matrix.pester }}'
64+
$folder = ($ver -split '-')[0]
65+
$dest = Join-Path $env:RUNNER_TEMP "pmods_$ver"
66+
New-Item -ItemType Directory -Path $dest -Force | Out-Null
67+
$pre = $ver -like '*-*'
68+
Save-Module -Name Pester -RequiredVersion $ver -AllowPrerelease:$pre -Path $dest -Repository PSGallery -Force
69+
$psd1 = Join-Path $dest "Pester\$folder\Pester.psd1"
70+
if (-not (Test-Path $psd1)) { throw "psd1 not found at $psd1" }
71+
"PESTER_PSD1=$psd1" | Out-File -FilePath $env:GITHUB_ENV -Append -Encoding utf8
72+
73+
$libdest = Join-Path $env:RUNNER_TEMP "libmods"
74+
New-Item -ItemType Directory -Path $libdest -Force | Out-Null
75+
Save-Module -Name dbatools.library -RequiredVersion 2025.12.28 -Path $libdest -Repository PSGallery -Force
76+
"LIBMODS=$libdest" | Out-File -FilePath $env:GITHUB_ENV -Append -Encoding utf8
77+
78+
- name: Clone dbatools (PR 10405 head, commit 15c3981)
79+
shell: pwsh
80+
run: |
81+
git clone --branch pester-6-rc --depth 1 https://github.com/nohwnd/dbatools.git "$env:RUNNER_TEMP\dbatools_src"
82+
"DBATOOLS_SRC=$env:RUNNER_TEMP\dbatools_src" | Out-File -FilePath $env:GITHUB_ENV -Append -Encoding utf8
83+
84+
- name: Real negative test on Windows PowerShell 5.1 (Desktop)
85+
shell: powershell
86+
continue-on-error: true
87+
run: |
88+
powershell -NoProfile -ExecutionPolicy Bypass -File .repro2829\real-run.ps1 -PesterPsd1 "$env:PESTER_PSD1" -DbatoolsPath "$env:DBATOOLS_SRC" -LibraryModulePath "$env:LIBMODS"
89+
90+
- name: Real negative test on PowerShell 7 (Core)
91+
shell: pwsh
92+
continue-on-error: true
93+
run: |
94+
pwsh -NoProfile -File .repro2829/real-run.ps1 -PesterPsd1 "$env:PESTER_PSD1" -DbatoolsPath "$env:DBATOOLS_SRC" -LibraryModulePath "$env:LIBMODS"

.repro2829/real-run.ps1

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#
2+
# Definitive reproduction for pester/Pester#2829: run the real dbatools negative test
3+
# ("fails when update execution has failed") the same way tests/appveyor.pester.ps1 does.
4+
# Prints REPRO_RESULT_REAL with a PASS/FAIL verdict and whether the failure looks like a
5+
# mock-miss (the real Invoke-Program ran and hit WinRM).
6+
#
7+
[CmdletBinding()]
8+
param(
9+
[Parameter(Mandatory)][string] $PesterPsd1,
10+
[Parameter(Mandatory)][string] $DbatoolsPath,
11+
[string] $LibraryModulePath
12+
)
13+
$ErrorActionPreference = 'Stop'
14+
15+
if ($LibraryModulePath) {
16+
$env:PSModulePath = $LibraryModulePath + [IO.Path]::PathSeparator + $env:PSModulePath
17+
}
18+
19+
Get-Module Pester, dbatools, dbatools.library | Remove-Module -Force -ErrorAction SilentlyContinue
20+
Import-Module $PesterPsd1 -Force
21+
$pesterMod = Get-Module Pester
22+
$label = "$($PSVersionTable.PSEdition)/$($PSVersionTable.PSVersion) Pester $($pesterMod.Version) $($pesterMod.PrivateData.PSData.Prerelease)".Trim()
23+
Write-Host "== REAL $label =="
24+
25+
# Import dbatools exactly like tests/appveyor.pester.ps1 (dot-sourced module load).
26+
$global:dbatools_dotsourcemodule = $true
27+
Import-Module (Join-Path $DbatoolsPath 'dbatools.psm1') -Force
28+
Write-Host "dbatools imported: $((Get-Module dbatools).Version); nested: $((Get-Module dbatools).NestedModules.Name -join ',')"
29+
30+
# The test file's param default is $TestConfig.Defaults.
31+
try { $global:TestConfig = Get-TestConfig }
32+
catch {
33+
try { $global:TestConfig = & (Get-Module dbatools) { Get-TestConfig } }
34+
catch { $global:TestConfig = $null }
35+
}
36+
37+
$testFile = Join-Path $DbatoolsPath 'tests/Install-DbaInstance.Tests.ps1'
38+
$cfg = New-PesterConfiguration
39+
$cfg.Run.Path = $testFile
40+
$cfg.Run.PassThru = $true
41+
$cfg.Filter.FullName = '*fails when update execution has failed*'
42+
$cfg.Output.Verbosity = 'Detailed'
43+
$r = Invoke-Pester -Configuration $cfg
44+
45+
$failed = $r.FailedCount
46+
$errs = ''
47+
if ($failed -gt 0) {
48+
$errs = ($r.Tests | Where-Object Result -eq 'Failed' | ForEach-Object { "$($_.ErrorRecord)" }) -join ' || '
49+
}
50+
$mockMiss = [bool]($errs -match 'WinRM|remote server|cannot be resolved|Connecting to remote|Access is denied|exit code (?!12345)')
51+
$verdict = if ($failed -eq 0) { 'PASS' } else { 'FAIL' }
52+
Write-Host ("REPRO_RESULT_REAL :: {0} :: mockmiss={1} :: {2} :: failed={3} :: {4}" -f $verdict, $mockMiss, $label, $failed, $errs)
53+
exit 0

.repro2829/repro.ps1

Lines changed: 0 additions & 171 deletions
This file was deleted.

.repro2829/run.ps1

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)