Skip to content

Commit be0d3d4

Browse files
bolenscursoragent
andcommitted
fix(ci): handle empty Pester shard lists in matrix build
Workflow-only changes produced @('') from Resolve-PesterCiShards, which failed Mandatory [string[]] binding in Get-PesterCiShardMatrix. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent b2ce58c commit be0d3d4

3 files changed

Lines changed: 30 additions & 5 deletions

File tree

.github/workflows/test-pester.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,10 @@ jobs:
5757
}
5858
}
5959
60-
$include = @(Get-PesterCiShardMatrix -Shards $shards)
60+
# Coerce to [string[]] so empty "no matching shards" stays an empty array
61+
# (bare @() / $null can bind as '' and fail Mandatory [string[]]).
62+
$shardList = [string[]]@($shards | Where-Object { -not [string]::IsNullOrWhiteSpace($_) })
63+
$include = @(Get-PesterCiShardMatrix -Shards $shardList)
6164
$any = $include.Count -gt 0
6265
$matrix = if ($any) {
6366
@{ include = @($include) } | ConvertTo-Json -Compress -Depth 5

scripts/utils/code-quality/modules/PesterCiShardFilter.psm1

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -380,8 +380,9 @@ function Resolve-PesterCiShards {
380380
})
381381

382382
if ($files.Count -eq 0) {
383-
# Unary comma preserves empty [string[]] (bare `return @()` unwraps to $null).
384-
return , [string[]]@()
383+
# Emit nothing so call-site `@()` is a true empty array (Count 0).
384+
# Unary-comma / -NoEnumerate empty [string[]] still becomes @('') under `@()`.
385+
return
385386
}
386387

387388
foreach ($ruleName in $rules.Keys) {
@@ -406,7 +407,7 @@ function Resolve-PesterCiShards {
406407

407408
$ordered = [string[]]@($shards | Sort-Object)
408409
if ($ordered.Count -eq 0) {
409-
return , [string[]]@()
410+
return
410411
}
411412
return $ordered
412413
}
@@ -421,14 +422,22 @@ function Get-PesterCiShardMatrix {
421422
param(
422423
[Parameter(Mandatory)]
423424
[AllowEmptyCollection()]
425+
[AllowEmptyString()]
426+
[AllowNull()]
424427
[string[]]$Shards
425428
)
426429

427430
$windowsShards = @(Get-PesterCiWindowsShards)
428431
$archShards = @(Get-PesterCiArchShards)
429432
$include = [System.Collections.Generic.List[object]]::new()
430433

431-
foreach ($shard in ($Shards | Sort-Object -Unique)) {
434+
# Empty `@()` / `$null` / `''` can arrive from GHA when no shards match changed paths.
435+
$shardNames = @(
436+
$Shards |
437+
Where-Object { -not [string]::IsNullOrWhiteSpace($_) } |
438+
Sort-Object -Unique
439+
)
440+
foreach ($shard in $shardNames) {
432441
# Performance shards are Windows-only (historically flaky / slow on Ubuntu).
433442
if ($shard -notlike 'performance*') {
434443
$include.Add([pscustomobject]@{

tests/unit/test-runner/ci/test-runner-pester-ci-shard-filter.tests.ps1

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,19 @@ Describe 'PesterCiShardFilter' {
7777
$matrix | Where-Object { $_.label -eq 'arch-latest' -and $_.shard -eq 'coverage-smoke' } | Should -Not -BeNullOrEmpty
7878
}
7979

80+
It 'Accepts empty or blank shard lists without throwing' {
81+
@(Get-PesterCiShardMatrix -Shards @()) | Should -HaveCount 0
82+
@(Get-PesterCiShardMatrix -Shards @('')) | Should -HaveCount 0
83+
@(Get-PesterCiShardMatrix -Shards $null) | Should -HaveCount 0
84+
}
85+
86+
It 'Returns a true empty array for workflow-only changes with no Pester shards' {
87+
$shards = @(Resolve-PesterCiShards -ChangedFiles @('.github/workflows/codeql.yml'))
88+
$shards.Count | Should -Be 0
89+
@($shards | Where-Object { -not [string]::IsNullOrWhiteSpace($_) }) | Should -HaveCount 0
90+
@(Get-PesterCiShardMatrix -Shards ([string[]]@($shards))) | Should -HaveCount 0
91+
}
92+
8093
It 'Exposes a curated Arch shard set' {
8194
$arch = Get-PesterCiArchShards
8295
$arch | Should -Contain 'unit-library'

0 commit comments

Comments
 (0)