Skip to content

Commit b596515

Browse files
Improve test file formatting after PR test repair
Refactors the logic to collect and format only the relevant test files that failed and were processed during PR test repair. Ensures that Invoke-DbatoolsFormatter is run on the correct set of files by tracking their paths, and moves the formatter invocation to after the commit step if needed.
1 parent dcdf21a commit b596515

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

.aitools/module/Repair-PullRequestTest.ps1

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,10 @@ function Repair-PullRequestTest {
265265
Write-Verbose "All relevant test files across PRs - $($allRelevantTestFiles -join ', ')"
266266

267267
# Create hash table to group ALL errors by unique file name
268-
$fileErrorMap = @{}
268+
$fileErrorMap = @{}
269+
$fileErrorPath = @()
270+
$testdirectory = Join-Path $script:ModulePath "tests"
271+
269272
foreach ($test in $allFailedTestsAcrossPRs) {
270273
$fileName = [System.IO.Path]::GetFileName($test.TestFile)
271274
# ONLY include files that are actually in the PR changes
@@ -274,12 +277,17 @@ function Repair-PullRequestTest {
274277
$fileErrorMap[$fileName] = @()
275278
}
276279
$fileErrorMap[$fileName] += $test
280+
281+
if ($test.TestFile) {
282+
$fileErrorPath += (Join-Path $testdirectory $test.TestFile)
283+
}
277284
}
278285
}
279-
286+
$fileErrorPath = $fileErrorPath | Sort-Object -Unique
280287
Write-Verbose "Found failures in $($fileErrorMap.Keys.Count) unique test files (filtered to PR changes only)"
281288
foreach ($fileName in $fileErrorMap.Keys) {
282289
Write-Verbose " ${fileName} - $($fileErrorMap[$fileName].Count) failures"
290+
Write-Verbose " Paths: $fileErrorPath"
283291
}
284292

285293
# If no relevant failures after filtering, exit
@@ -524,9 +532,6 @@ function Repair-PullRequestTest {
524532
Write-Verbose "All $($updateJobs.Count) Update-PesterTest parallel jobs completed"
525533
Write-Progress -Activity "Running Update-PesterTest (Parallel)" -Completed -Id 1
526534

527-
# Collect successfully processed files and run formatter
528-
Get-ChildItem $jobInfo.TestPath | Invoke-DbatoolsFormatter
529-
530535
# Commit changes if requested
531536
if ($AutoCommit) {
532537
Write-Progress -Activity "Repairing Pull Request Tests" -Status "Committing fixes..." -PercentComplete 90 -Id 0
@@ -539,6 +544,11 @@ function Repair-PullRequestTest {
539544
}
540545
}
541546

547+
# Collect successfully processed files and run formatter
548+
if ($fileErrorPath) {
549+
$null = Get-ChildItem $fileErrorPath -File | Invoke-DbatoolsFormatter
550+
}
551+
542552
# Complete the overall progress
543553
Write-Progress -Activity "Repairing Pull Request Tests" -Status "Completed processing $($processedFiles.Keys.Count) unique test files" -PercentComplete 100 -Id 0
544554
Write-Progress -Activity "Repairing Pull Request Tests" -Completed -Id 0

0 commit comments

Comments
 (0)