@@ -468,6 +468,42 @@ function Invoke-TestRun {
468468 }
469469}
470470
471+ # ============================================================
472+ # Run test with retry on environment errors
473+ # ============================================================
474+ function Invoke-TestRunWithRetry {
475+ param (
476+ [hashtable ]$TestEntry ,
477+ [string ]$LogFile ,
478+ [int ]$MaxRetries = 3
479+ )
480+
481+ for ($attempt = 1 ; $attempt -le $MaxRetries ; $attempt ++ ) {
482+ $logFileAttempt = if ($attempt -gt 1 ) { " $LogFile .attempt$attempt " } else { $LogFile }
483+
484+ $testOutputLog = Invoke-TestRun `
485+ - DetectedTestType $TestEntry.Type `
486+ - Filter $TestEntry.Filter `
487+ - DetectedProject $TestEntry.Project `
488+ - DetectedProjectPath $TestEntry.ProjectPath `
489+ - LogFile $logFileAttempt
490+
491+ $result = Get-TestResultFromOutput - LogFile $testOutputLog - TestFilter $TestEntry.Filter
492+
493+ if (-not $result.EnvError ) {
494+ return $result
495+ }
496+
497+ if ($attempt -lt $MaxRetries ) {
498+ Write-Host " ⚠️ Environment error (attempt $attempt /$MaxRetries ): $ ( $result.Error ) — retrying..." - ForegroundColor Yellow
499+ Start-Sleep - Seconds 5
500+ } else {
501+ Write-Host " ⚠️ Environment error persisted after $MaxRetries attempts: $ ( $result.Error ) " - ForegroundColor Yellow
502+ return $result
503+ }
504+ }
505+ }
506+
471507# ============================================================
472508# Parse test results from output (supports all test types)
473509# ============================================================
@@ -877,14 +913,7 @@ if ($DetectedFixFiles.Count -eq 0) {
877913 if ($sanitizedName.Length -gt 60 ) { $sanitizedName = $sanitizedName.Substring (0 , 60 ) }
878914 $TestLog = Join-Path $OutputPath " test-failure-$sanitizedName .log"
879915
880- $testOutputLog = Invoke-TestRun `
881- - DetectedTestType $testEntry.Type `
882- - Filter $testEntry.Filter `
883- - DetectedProject $testEntry.Project `
884- - DetectedProjectPath $testEntry.ProjectPath `
885- - LogFile $TestLog
886-
887- $testResult = Get-TestResultFromOutput - LogFile $testOutputLog - TestFilter $testEntry.Filter
916+ $testResult = Invoke-TestRunWithRetry - TestEntry $testEntry - LogFile $TestLog
888917 $testResult.TestName = $testEntry.TestName
889918 $testResult.TestType = $testEntry.Type
890919 $allResults += $testResult
@@ -1239,19 +1268,14 @@ foreach ($testEntry in $AllDetectedTests) {
12391268 if ($sanitizedName.Length -gt 60 ) { $sanitizedName = $sanitizedName.Substring (0 , 60 ) }
12401269 $testLogFile = Join-Path $OutputPath " test-without-fix-$sanitizedName .log"
12411270
1242- $testOutputLog = Invoke-TestRun `
1243- - DetectedTestType $testEntry.Type `
1244- - Filter $testEntry.Filter `
1245- - DetectedProject $testEntry.Project `
1246- - DetectedProjectPath $testEntry.ProjectPath `
1247- - LogFile $testLogFile
1248-
1249- $result = Get-TestResultFromOutput - LogFile $testOutputLog - TestFilter $testEntry.Filter
1271+ $result = Invoke-TestRunWithRetry - TestEntry $testEntry - LogFile $testLogFile
12501272 $result.TestName = $testEntry.TestName
12511273 $result.TestType = $testEntry.Type
12521274 $withoutFixResults += $result
12531275
1254- if (-not $result.Passed ) {
1276+ if ($result.EnvError ) {
1277+ Write-Log " ⚠️ $ ( $testEntry.TestName ) ENV ERROR without fix: $ ( $result.Error ) "
1278+ } elseif (-not $result.Passed ) {
12551279 Write-Log " ✅ $ ( $testEntry.TestName ) FAILED without fix (expected)"
12561280 } else {
12571281 Write-Log " ❌ $ ( $testEntry.TestName ) PASSED without fix (unexpected!)"
@@ -1307,19 +1331,14 @@ foreach ($testEntry in $AllDetectedTests) {
13071331 if ($sanitizedName.Length -gt 60 ) { $sanitizedName = $sanitizedName.Substring (0 , 60 ) }
13081332 $testLogFile = Join-Path $OutputPath " test-with-fix-$sanitizedName .log"
13091333
1310- $testOutputLog = Invoke-TestRun `
1311- - DetectedTestType $testEntry.Type `
1312- - Filter $testEntry.Filter `
1313- - DetectedProject $testEntry.Project `
1314- - DetectedProjectPath $testEntry.ProjectPath `
1315- - LogFile $testLogFile
1316-
1317- $result = Get-TestResultFromOutput - LogFile $testOutputLog - TestFilter $testEntry.Filter
1334+ $result = Invoke-TestRunWithRetry - TestEntry $testEntry - LogFile $testLogFile
13181335 $result.TestName = $testEntry.TestName
13191336 $result.TestType = $testEntry.Type
13201337 $withFixResults += $result
13211338
1322- if ($result.Passed ) {
1339+ if ($result.EnvError ) {
1340+ Write-Log " ⚠️ $ ( $testEntry.TestName ) ENV ERROR with fix: $ ( $result.Error ) "
1341+ } elseif ($result.Passed ) {
13231342 Write-Log " ✅ $ ( $testEntry.TestName ) PASSED with fix (expected)"
13241343 } else {
13251344 Write-Log " ❌ $ ( $testEntry.TestName ) FAILED with fix (unexpected!)"
0 commit comments