Skip to content

Commit 2d92cba

Browse files
committed
fix(test): clear stub leaks and stabilize remaining CI shards
Export missing TestSupport helpers, stop Read-FileContent/Write-* stub pollution, fix Chocolatey Get-Command mocks, and treat conversion batch success from Pester counts rather than noisy child exit codes.
1 parent fe86a64 commit 2d92cba

20 files changed

Lines changed: 224 additions & 87 deletions

scripts/lib/fragment/FragmentLoading.psm1

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ function Invoke-ParallelDependencyParsing {
337337
}
338338
}
339339
else {
340-
Write-Error "[Invoke-ParallelDependencyParsing] Failed to create PowerShell instance for: ${filePath}"
340+
Write-Error "[Invoke-ParallelDependencyParsing] Failed to create PowerShell instance for: ${filePath}" -ErrorAction Continue
341341
}
342342
}
343343
continue
@@ -365,7 +365,7 @@ function Invoke-ParallelDependencyParsing {
365365
}
366366
}
367367
else {
368-
Write-Error "[Invoke-ParallelDependencyParsing] Error adding script for ${filePath}: $($_.Exception.Message) | Type: $typeName"
368+
Write-Error "[Invoke-ParallelDependencyParsing] Error adding script for ${filePath}: $($_.Exception.Message) | Type: $typeName" -ErrorAction Continue
369369
}
370370
}
371371
# Level 3: Log detailed error information
@@ -397,7 +397,7 @@ function Invoke-ParallelDependencyParsing {
397397
}
398398
}
399399
else {
400-
Write-Error "[Invoke-ParallelDependencyParsing] Error adding argument for ${filePath}: $($_.Exception.Message) | Type: $typeName"
400+
Write-Error "[Invoke-ParallelDependencyParsing] Error adding argument for ${filePath}: $($_.Exception.Message) | Type: $typeName" -ErrorAction Continue
401401
}
402402
}
403403
# Level 3: Log detailed error information
@@ -439,7 +439,7 @@ function Invoke-ParallelDependencyParsing {
439439
}
440440
}
441441
else {
442-
Write-Error "[Invoke-ParallelDependencyParsing] BeginInvoke returned null for: ${filePath}"
442+
Write-Error "[Invoke-ParallelDependencyParsing] BeginInvoke returned null for: ${filePath}" -ErrorAction Continue
443443
}
444444
}
445445
$powershell.Dispose()
@@ -457,7 +457,7 @@ function Invoke-ParallelDependencyParsing {
457457
}
458458
}
459459
else {
460-
Write-Error "[Invoke-ParallelDependencyParsing] Error in BeginInvoke for ${filePath}: $($_.Exception.Message) | Type: $typeName"
460+
Write-Error "[Invoke-ParallelDependencyParsing] Error in BeginInvoke for ${filePath}: $($_.Exception.Message) | Type: $typeName" -ErrorAction Continue
461461
}
462462
}
463463
# Level 3: Log detailed error information
@@ -494,7 +494,7 @@ function Invoke-ParallelDependencyParsing {
494494
}
495495
}
496496
else {
497-
Write-Error "[Invoke-ParallelDependencyParsing] Error adding to runspaces list: $($_.Exception.Message) | Type: $typeName"
497+
Write-Error "[Invoke-ParallelDependencyParsing] Error adding to runspaces list: $($_.Exception.Message) | Type: $typeName" -ErrorAction Continue
498498
}
499499
}
500500
# Level 3: Log detailed error information
@@ -516,7 +516,7 @@ function Invoke-ParallelDependencyParsing {
516516
}
517517
}
518518
else {
519-
Write-Error "[Invoke-ParallelDependencyParsing] Unexpected error setting up runspace for ${filePath}: $($_.Exception.Message) | Type: $typeName"
519+
Write-Error "[Invoke-ParallelDependencyParsing] Unexpected error setting up runspace for ${filePath}: $($_.Exception.Message) | Type: $typeName" -ErrorAction Continue
520520
}
521521
}
522522
# Level 3: Log detailed error information
@@ -676,7 +676,7 @@ function Invoke-ParallelDependencyParsing {
676676
}
677677
}
678678
else {
679-
Write-Error "[Invoke-ParallelDependencyParsing] PowerShell error for $($rs.FilePath): $($error.Exception.Message) | Type: $errorType | Category: $($error.CategoryInfo.Category)"
679+
Write-Error "[Invoke-ParallelDependencyParsing] PowerShell error for $($rs.FilePath): $($error.Exception.Message) | Type: $errorType | Category: $($error.CategoryInfo.Category)" -ErrorAction Continue
680680
}
681681
}
682682
else {
@@ -693,7 +693,7 @@ function Invoke-ParallelDependencyParsing {
693693
}
694694
}
695695
else {
696-
Write-Error "[Invoke-ParallelDependencyParsing] PowerShell error for $($rs.FilePath): $($error.Exception.Message) | Type: $errorType | Category: $($error.CategoryInfo.Category)"
696+
Write-Error "[Invoke-ParallelDependencyParsing] PowerShell error for $($rs.FilePath): $($error.Exception.Message) | Type: $errorType | Category: $($error.CategoryInfo.Category)" -ErrorAction Continue
697697
}
698698
}
699699
# Level 3: Log detailed PowerShell error information
@@ -736,7 +736,7 @@ function Invoke-ParallelDependencyParsing {
736736
}
737737
}
738738
else {
739-
Write-Error "[Invoke-ParallelDependencyParsing] Error adding result to list: $($_.Exception.Message) | Type: $typeName | Result type: $resultType"
739+
Write-Error "[Invoke-ParallelDependencyParsing] Error adding result to list: $($_.Exception.Message) | Type: $typeName | Result type: $resultType" -ErrorAction Continue
740740
}
741741
}
742742
# Level 3: Log detailed error information
@@ -795,7 +795,7 @@ function Invoke-ParallelDependencyParsing {
795795
}
796796
}
797797
else {
798-
Write-Error "[Invoke-ParallelDependencyParsing] Error in EndInvoke for $($rs.FilePath): $($_.Exception.Message) | Type: $typeName"
798+
Write-Error "[Invoke-ParallelDependencyParsing] Error in EndInvoke for $($rs.FilePath): $($_.Exception.Message) | Type: $typeName" -ErrorAction Continue
799799
}
800800
}
801801
# Level 3: Log detailed error information
@@ -873,7 +873,7 @@ function Invoke-ParallelDependencyParsing {
873873
}
874874
}
875875
else {
876-
Write-Error "[Invoke-ParallelDependencyParsing] Error adding timeout result: $($_.Exception.Message)"
876+
Write-Error "[Invoke-ParallelDependencyParsing] Error adding timeout result: $($_.Exception.Message)" -ErrorAction Continue
877877
}
878878
}
879879
}
@@ -890,7 +890,7 @@ function Invoke-ParallelDependencyParsing {
890890
}
891891
}
892892
else {
893-
Write-Error "[Invoke-ParallelDependencyParsing] Error processing runspace for $($rs.FilePath): $($_.Exception.Message) | Type: $typeName"
893+
Write-Error "[Invoke-ParallelDependencyParsing] Error processing runspace for $($rs.FilePath): $($_.Exception.Message) | Type: $typeName" -ErrorAction Continue
894894
}
895895
}
896896
# Level 3: Log detailed error information
@@ -917,7 +917,7 @@ function Invoke-ParallelDependencyParsing {
917917
}
918918
}
919919
else {
920-
Write-Error "[Invoke-ParallelDependencyParsing] Error adding error result: $($_.Exception.Message)"
920+
Write-Error "[Invoke-ParallelDependencyParsing] Error adding error result: $($_.Exception.Message)" -ErrorAction Continue
921921
}
922922
}
923923
else {
@@ -935,7 +935,7 @@ function Invoke-ParallelDependencyParsing {
935935
}
936936
}
937937
else {
938-
Write-Error "[Invoke-ParallelDependencyParsing] Error adding error result: $($_.Exception.Message)"
938+
Write-Error "[Invoke-ParallelDependencyParsing] Error adding error result: $($_.Exception.Message)" -ErrorAction Continue
939939
}
940940
}
941941
}
@@ -988,7 +988,7 @@ function Invoke-ParallelDependencyParsing {
988988
}
989989
}
990990
else {
991-
Write-Error "[Invoke-ParallelDependencyParsing] Error in parallel parsing: $($_.Exception.Message)"
991+
Write-Error "[Invoke-ParallelDependencyParsing] Error in parallel parsing: $($_.Exception.Message)" -ErrorAction Continue
992992
}
993993
}
994994
# Level 3: Log detailed error information
@@ -1110,7 +1110,7 @@ function Invoke-ParallelDependencyParsing {
11101110
}
11111111
}
11121112
else {
1113-
Write-Error "[Invoke-ParallelDependencyParsing] Error processing result: $($_.Exception.Message) | Type: $typeName"
1113+
Write-Error "[Invoke-ParallelDependencyParsing] Error processing result: $($_.Exception.Message) | Type: $typeName" -ErrorAction Continue
11141114
}
11151115
}
11161116
# Level 3: Log detailed error information

scripts/utils/code-quality/run-conversion-all-batch.ps1

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,13 @@ param(
4646
$expectedRepoRoot = Split-Path -Parent (Split-Path -Parent (Split-Path -Parent $PSScriptRoot))
4747
$conversionRootCheck = Join-Path $RepoRoot 'tests' 'integration' 'conversion'
4848
if (-not (Test-Path -LiteralPath $conversionRootCheck)) {
49-
if (Test-Path -LiteralPath (Join-Path $expectedRepoRoot 'tests' 'integration' 'conversion')) {
49+
# Remap only when RepoRoot looks like a RelativePath binding mistake (e.g. pwsh -File
50+
# with a bare data/foo arg). Do not remap intentional alternate/fake roots.
51+
$repoRootIsRelativePathMistake = $RepoRoot -match '^(data|document|media)(/|\\|$)'
52+
if ($repoRootIsRelativePathMistake -and (Test-Path -LiteralPath (Join-Path $expectedRepoRoot 'tests' 'integration' 'conversion'))) {
53+
if ($RelativePath.Count -eq 0) {
54+
$RelativePath = @($RepoRoot)
55+
}
5056
$RepoRoot = $expectedRepoRoot
5157
$conversionRootCheck = Join-Path $RepoRoot 'tests' 'integration' 'conversion'
5258
}
@@ -136,7 +142,12 @@ foreach ($rel in $paths) {
136142
$skipped = [int]$Matches[3]
137143
}
138144

139-
$batchFailed = $exitCode -ne 0 -or $failed -gt 0
145+
$batchFailed = if ($failed -ge 0) {
146+
$failed -gt 0
147+
}
148+
else {
149+
$exitCode -ne 0
150+
}
140151
$results += [pscustomobject]@{
141152
Path = $rel
142153
Passed = $passed
@@ -154,7 +165,14 @@ foreach ($rel in $paths) {
154165
Write-Host '--- Summary (conversion all) ---' -ForegroundColor Cyan
155166
$results | Format-Table -AutoSize
156167

157-
$bad = @($results | Where-Object { $_.Failed -gt 0 -or $_.ExitCode -ne 0 })
168+
$bad = @($results | Where-Object {
169+
if ($_.Failed -ge 0) {
170+
$_.Failed -gt 0
171+
}
172+
else {
173+
$_.ExitCode -ne 0
174+
}
175+
})
158176
if ($bad.Count -gt 0) {
159177
Write-Host "Sub-batches with failures: $($bad.Count)" -ForegroundColor Red
160178
exit 1

scripts/utils/code-quality/run-conversion-integration-batch.ps1

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,14 @@ if (-not $PerFile) {
169169

170170
$stats = Get-PesterRunStats -Output $run.Output -ResultXmlPath $resultXml
171171
$failLines = @(Get-PesterFailureLines -Output $run.Output)
172-
$batchFailed = $run.ExitCode -ne 0 -or ($stats.Failed -gt 0)
172+
# Prefer parsed Pester counts when available; child exit codes can be non-zero
173+
# from non-terminating warnings even when FailedCount is 0.
174+
$batchFailed = if ($stats.Failed -ge 0) {
175+
$stats.Failed -gt 0
176+
}
177+
else {
178+
$run.ExitCode -ne 0
179+
}
173180

174181
$color = if ($batchFailed) { 'Red' } elseif ($stats.Passed -ge 0) { 'Green' } else { 'Yellow' }
175182
Write-Host " $($stats.Passed)P / $($stats.Failed)F / $($stats.Skipped)S in $([math]::Round($sw.Elapsed.TotalSeconds, 1))s" -ForegroundColor $color

scripts/utils/docs/modules/DocParser.psm1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ function Get-DeduplicatedDocumentedCommands {
4747
[OutputType([System.Collections.Generic.List[PSCustomObject]])]
4848
param(
4949
[Parameter(Mandatory)]
50+
[AllowEmptyCollection()]
5051
[System.Collections.Generic.List[PSCustomObject]]$Commands,
5152

5253
[Parameter(Mandatory)]

tests/TestSupport/TestExecution.ps1

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,3 +207,11 @@ function Initialize-FragmentPerformanceThresholds {
207207
$script:MaxLookupTimeMs = Get-PerformanceThreshold -EnvironmentVariable "PS_PROFILE_${key}_MAX_LOOKUP_MS" -Default $LookupMs
208208
}
209209

210+
# Promote execution helpers globally for integration tests that call them without re-dotting TestSupport.
211+
foreach ($testExecHelperName in @('Invoke-TestPwshScript', 'Invoke-TestScriptFile')) {
212+
$testExecHelper = Get-Command -Name $testExecHelperName -ErrorAction SilentlyContinue
213+
if ($testExecHelper -and $testExecHelper.CommandType -eq 'Function') {
214+
Set-Item -Path "Function:\global:$testExecHelperName" -Value $testExecHelper.ScriptBlock -Force
215+
}
216+
}
217+

tests/TestSupport/TestPaths.ps1

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,11 +578,23 @@ foreach ($testPathHelperName in @(
578578
'Get-TestRepoRoot'
579579
'Get-TestPath'
580580
'Get-TestSuitePath'
581+
'Get-TestSuiteFiles'
581582
'Get-TestArtifactPath'
583+
'Get-TestArtifactsPath'
584+
'Get-TestDataPath'
585+
'Get-TestScriptPath'
586+
'Get-TestRepoRelativePath'
582587
'New-TestTempDirectory'
588+
'New-TestExternalTempDirectory'
583589
'New-TestTempFile'
584590
'Remove-TestArtifacts'
585-
'Get-TestScriptPath'
591+
'Register-TestCleanupPath'
592+
'Clear-RegisteredTestCleanupPaths'
593+
'Clear-TestTransientStorage'
594+
'Initialize-TestCleanupRegistry'
595+
'Backup-TestFileBytes'
596+
'Restore-TestFileBytes'
597+
'Write-TestFileLiteralContent'
586598
)) {
587599
$testPathHelper = Get-Command -Name $testPathHelperName -ErrorAction SilentlyContinue
588600
if ($testPathHelper -and $testPathHelper.CommandType -eq 'Function') {

tests/TestSupport/TestSupportCoreFunctions.ps1

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,19 +234,43 @@ function Export-TestSupportGlobalFunctions {
234234
'Get-TestPath'
235235
'Get-TestRepoRoot'
236236
'Get-TestSuitePath'
237+
'Get-TestSuiteFiles'
237238
'Get-TestArtifactPath'
239+
'Get-TestArtifactsPath'
240+
'Get-TestDataPath'
241+
'Get-TestScriptPath'
242+
'Get-TestRepoRelativePath'
243+
'Get-TestProfileDir'
238244
'New-TestTempDirectory'
245+
'New-TestExternalTempDirectory'
239246
'New-TestTempFile'
240247
'Remove-TestArtifacts'
248+
'Register-TestCleanupPath'
249+
'Clear-RegisteredTestCleanupPaths'
250+
'Clear-TestTransientStorage'
251+
'Initialize-TestCleanupRegistry'
252+
'Backup-TestFileBytes'
253+
'Restore-TestFileBytes'
254+
'Write-TestFileLiteralContent'
241255
'Import-TestLibraryModule'
242256
'Initialize-TestProfile'
243-
'Get-TestProfileDir'
244257
'Reset-TestIsolationState'
245258
'Restore-TestSupportHelperFunctions'
259+
'Restore-TestSupportFunctions'
246260
'Get-PythonPackageInstallRecommendation'
247261
'Invoke-MakeGenericTypeWrapper'
248262
'Invoke-CreateInstanceWrapper'
249263
'Invoke-TypeConstructorWrapper'
264+
'Invoke-TestPwshScript'
265+
'Invoke-TestScriptFile'
266+
'Initialize-ConversionIntegrationForTestFile'
267+
'Initialize-ConversionIntegration'
268+
'Enable-TestStructuredLogging'
269+
'Disable-TestStructuredLogging'
270+
'Remove-TestFunction'
271+
'Setup-CapturingCommandMock'
272+
'Mock-EnvironmentVariable'
273+
'Restore-EnvironmentVariable'
250274
)
251275

252276
foreach ($functionName in $globalFunctionNames) {
@@ -274,6 +298,7 @@ function Restore-TestSupportHelperFunctions {
274298
$helperFiles = @(
275299
'TestSupportCoreFunctions.ps1'
276300
'TestPaths.ps1'
301+
'TestExecution.ps1'
277302
'TestPythonHelpers.ps1'
278303
'TestReflectionHelpers.ps1'
279304
)
@@ -308,6 +333,7 @@ function Clear-CommandTestStubs {
308333
'Test-FailingCommand'
309334
'Test-ThrowingCommand'
310335
'Test-ThrowingCommand2'
336+
'Read-FileContent'
311337
)
312338
}
313339

tests/integration/filesystem/file-navigation.tests.ps1

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,18 @@ Describe 'File Navigation Functions Integration Tests' {
4141
It '.. function navigates up one directory' {
4242
$testDir = $null
4343
$originalLocation = Get-Location
44-
44+
4545
try {
4646
$testDir = Join-Path $TestDrive 'level1\level2'
4747
New-Item -ItemType Directory -Path $testDir -Force | Out-Null
4848

4949
Push-Location $testDir
50-
$before = Get-Location
50+
$before = Get-Location
5151
if (-not (Get-Command '..' -CommandType Function -ErrorAction SilentlyContinue)) {
5252
Set-ItResult -Skipped -Because ".. function not available"
5353
return
5454
}
55-
55+
5656
..
5757
$after = Get-Location
5858
$after.Path | Should -Match ([regex]::Escape((Split-Path $before.Path))) -Because ".. should navigate up one directory"
@@ -67,11 +67,8 @@ Describe 'File Navigation Functions Integration Tests' {
6767
throw
6868
}
6969
finally {
70-
Pop-Location
71-
}
72-
catch {
70+
Pop-Location -ErrorAction SilentlyContinue
7371
Set-Location $originalLocation -ErrorAction SilentlyContinue
74-
throw
7572
}
7673
}
7774

tests/integration/utilities/utility-functions.tests.ps1

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -140,29 +140,30 @@ Describe 'Utility Functions Integration Tests' {
140140
$result = ConvertFrom-Epoch -epoch $timestamp
141141
$result | Should -Not -Be $null
142142
$result.GetType().Name | Should -Be 'DateTimeOffset'
143-
$result.Year | Should -Be 2020 # Local time year
144-
$result.Month | Should -Be 12
145-
$result.Day | Should -Be 31
143+
$utc = $result.ToUniversalTime()
144+
$utc.Year | Should -Be 2021
145+
$utc.Month | Should -Be 1
146+
$utc.Day | Should -Be 1
146147
}
147148

148149
It 'ConvertFrom-Epoch handles null timestamp' {
149150
$result = ConvertFrom-Epoch -epoch 0
150151
$result | Should -Not -Be $null
151152
$result.GetType().Name | Should -Be 'DateTimeOffset'
152-
# Unix epoch is 1970-01-01 UTC, but converted to local time
153-
$result.Year | Should -Be 1969
154-
$result.Month | Should -Be 12
155-
$result.Day | Should -Be 31
153+
$utc = $result.ToUniversalTime()
154+
$utc.Year | Should -Be 1970
155+
$utc.Month | Should -Be 1
156+
$utc.Day | Should -Be 1
156157
}
157158

158159
It 'ConvertFrom-Epoch handles zero timestamp' {
159160
$result = ConvertFrom-Epoch -epoch 0
160161
$result | Should -Not -Be $null
161162
$result.GetType().Name | Should -Be 'DateTimeOffset'
162-
# Unix epoch is 1970-01-01 UTC, but converted to local time
163-
$result.Year | Should -Be 1969
164-
$result.Month | Should -Be 12
165-
$result.Day | Should -Be 31
163+
$utc = $result.ToUniversalTime()
164+
$utc.Year | Should -Be 1970
165+
$utc.Month | Should -Be 1
166+
$utc.Day | Should -Be 1
166167
}
167168

168169
It 'ConvertTo-Epoch handles valid DateTime' {

0 commit comments

Comments
 (0)