diff --git a/.github/docs/maui-ci-facts.md b/.github/docs/maui-ci-facts.md index bdb090fded7f..63b767f8a3ed 100644 --- a/.github/docs/maui-ci-facts.md +++ b/.github/docs/maui-ci-facts.md @@ -406,6 +406,15 @@ on appearance alone: dismisses, because a broad known-issue regex could otherwise launder a PR-caused break in a *different* test that merely shares a red leg on base. An uncorroborated text match (no exact base match) stays `indeterminate` (`Needs human investigation`). + The local gatherer preserves `ErrorMessage` arrays as ordered AND conditions: + every literal must occur on a distinct subsequent line within one actual occurrence, + following the [public BA array contract](https://github.com/dotnet/arcade/blob/5a63d054ea793bdbdb6aa9f4558558e3a8f41529/Documentation/Build%20Analysis/KnownIssues.md#fill-out-known-issues-with-a-list-of-errors). + Each array's matched text includes that occurrence's name, message, and separately + captured stack trace. Arrays cannot combine evidence from separate occurrences of a + deduplicated test/platform. Scalar and regex rules retain their existing aggregated text. + Case-insensitive matching, the 20,000-character cap per matched text, first-matching-rule + selection, and attribution gates are unchanged. This local hint matcher does not + establish full Build Analysis/Build Insights service parity. 4. **Retry recovery** — the failing leg was retried by CI and **passed** on a later attempt (the recovered leg does not surface as a failure at all). A leg that was retried and **still failed** (`retriedStillFailing = true`) is the opposite — **persistent**, diff --git a/.github/skills/review-test-failures/scripts/Gather-TestFailureContext.Tests.ps1 b/.github/skills/review-test-failures/scripts/Gather-TestFailureContext.Tests.ps1 index 6c60d124200e..3ed584977ad0 100644 --- a/.github/skills/review-test-failures/scripts/Gather-TestFailureContext.Tests.ps1 +++ b/.github/skills/review-test-failures/scripts/Gather-TestFailureContext.Tests.ps1 @@ -7,14 +7,15 @@ .DESCRIPTION Gather-TestFailureContext.ps1 is a param'd, self-executing script (it does real GitHub/AzDO/ - Helix I/O on load), so these tests AST-extract only the pure, side-effect-free functions and - dot-source them — the same pattern Run-DeviceTests.Tests.ps1 uses. No network, no auth. + Helix I/O on load), so these tests AST-extract the functions under test and mock their I/O + rather than loading the entrypoint. No network, no auth. Functions covered: - Get-HelixWorkItemCounts (Phase 1: anonymous /workitems completeness + fail counting) - Get-XUnitFailures (Phase 2: parse xUnit v2 TestResults XML) - Get-ConsoleFailureReason (Phase 2: extract crash/timeout reason from console log) - New-DeviceWorkItemFailureRecords (Phase 2: classify ONE failed work item into records) + - Get-KnownBuildIssues / Test-KnownIssueMatch (mocked issue transport, real loader/matcher) CORE INVARIANT under test: NEVER A FALSE GREEN. A non-zero-ExitCode device-test work item must ALWAYS yield at least one capping record, and any incompleteness (running items, short counts, @@ -45,6 +46,8 @@ BeforeAll { 'Invoke-JsonUrl', 'Invoke-TextUrl', 'Get-PinnedPrDiff', + 'Get-KnownBuildIssues', + 'Test-KnownIssueMatch', 'Get-AzDoApiBase', 'Get-HttpStatusCode', 'Invoke-AzDoJsonWithProjectFallback', @@ -329,6 +332,339 @@ Describe 'No-results evaluation shortcut' { } } +Describe 'Known Build Error loader-to-matcher boundary' -Tag 'KnownBuildIssues' { + BeforeAll { + $expressions = @( + 'at System.IO.FileStream.ReadAsync', + 'at Microsoft.Maui.Essentials.DeviceTests.FileSystem_Tests.' + ) + + function New-KnownBuildIssueFixture { + param( + [object]$ErrorMessage = $expressions, + [object]$ErrorPattern = $null, + [int]$Number = 36435 + ) + $rule = [ordered]@{ ErrorMessage = $ErrorMessage; ErrorPattern = $ErrorPattern } + return [pscustomobject]@{ + number = $Number + title = 'FileSystem test failure signature' + url = "https://github.com/dotnet/maui/issues/$Number" + body = '```json' + "`n" + ($rule | ConvertTo-Json -Depth 6) + "`n" + '```' + } + } + + $matchTextAssignment = $gatherAst.Find({ + $args[0] -is [System.Management.Automation.Language.AssignmentStatementAst] -and + $args[0].Left.Extent.Text -eq '$matchText' + }, $true) + $matchAssignment = $gatherAst.Find({ + $args[0] -is [System.Management.Automation.Language.AssignmentStatementAst] -and + $args[0].Left.Extent.Text -eq '$failure[''matchesKnownIssue'']' + }, $true) + if (-not $matchTextAssignment -or -not $matchAssignment) { throw 'Known-issue cross-reference not found.' } + $source = Get-Content -LiteralPath $scriptPath -Raw + $script:kbeCrossReference = [scriptblock]::Create($source.Substring( + $matchTextAssignment.Extent.StartOffset, + $matchAssignment.Extent.EndOffset - $matchTextAssignment.Extent.StartOffset)) + + function Invoke-KnownIssueCrossReference { + param($Failure, $KnownIssues) + & $script:kbeCrossReference + return $Failure.matchesKnownIssue + } + } + + BeforeEach { + $script:kbeIssueFixture = New-KnownBuildIssueFixture + Mock Invoke-GhJson { return @($script:kbeIssueFixture) } + } + + It 'matches every array expression on separate stack frames: ' -ForEach @( + @{ Case = 'LF'; NewLine = "`n" } + @{ Case = 'CRLF'; NewLine = "`r`n" } + @{ Case = 'CR'; NewLine = "`r" } + ) { + $loaded = Get-KnownBuildIssues -Repository 'dotnet/maui' + $loaded.error | Should -BeNullOrEmpty + $text = @( + 'System.NullReferenceException : Arg_NullReferenceException', + " $($expressions[0])(Memory``1 buffer, CancellationToken cancellationToken)", + ' at System.IO.StreamReader.ReadToEndAsyncInternal(CancellationToken cancellationToken)', + " $($expressions[1])CheckFileResultOpenReadAsyncMultipleTimes()" + ) -join $NewLine + $match = Test-KnownIssueMatch -Patterns $loaded.patterns -Text $text + $match.number | Should -Be 36435 + $match.title | Should -Be $script:kbeIssueFixture.title + $match.url | Should -Be $script:kbeIssueFixture.url + $loaded.patterns[0].pattern.GetType().IsArray | Should -BeTrue + $loaded.patterns[0].pattern | Should -Be $expressions + Should -Invoke Invoke-GhJson -Times 1 -Exactly -ParameterFilter { + ($Arguments -join ' ') -eq 'issue list -R dotnet/maui --label Known Build Error --state open --json number,title,url,body --limit 100' + } + } + + It 'preserves scalar and single-expression array matching: ' -ForEach @( + @{ Case = 'scalar'; Message = 'at System.IO.FileStream.ReadAsync' } + @{ Case = 'single-expression array'; Message = @('at System.IO.FileStream.ReadAsync') } + ) { + $script:kbeIssueFixture = New-KnownBuildIssueFixture -ErrorMessage $Message + $loaded = Get-KnownBuildIssues -Repository 'dotnet/maui' + (Test-KnownIssueMatch -Patterns $loaded.patterns -Text 'before AT SYSTEM.IO.FILESTREAM.READASYNC after').number | Should -Be 36435 + if ($Message -is [System.Array]) { + $loaded.patterns[0].pattern.GetType().IsArray | Should -BeTrue + } + else { + $loaded.patterns[0].pattern | Should -BeOfType ([string]) + } + } + + It 'keeps array literals case-insensitive and does not interpret regex characters' { + $script:kbeIssueFixture = New-KnownBuildIssueFixture -ErrorMessage @('Assert.True() [ReadAsync]', 'Actual: False') + $loaded = Get-KnownBuildIssues -Repository 'dotnet/maui' + (Test-KnownIssueMatch -Patterns $loaded.patterns -Text "ASSERT.TRUE() [READASYNC]`nactual: false").number | Should -Be 36435 + Test-KnownIssueMatch -Patterns $loaded.patterns -Text "AssertXTrue ReadAsync`nActual: False" | Should -BeNullOrEmpty + } + + It 'requires every expression on a distinct later line: ' -ForEach @( + @{ Case = 'three expressions'; Message = @('first frame', 'middle frame', 'last frame'); MatchingText = "first frame`nmiddle frame`nlast frame"; PartialText = "first frame`nlast frame" } + @{ Case = 'repeated expression'; Message = @('same frame', 'same frame'); MatchingText = "same frame`nsame frame"; PartialText = 'same frame same frame' } + ) { + $script:kbeIssueFixture = New-KnownBuildIssueFixture -ErrorMessage $Message + $loaded = Get-KnownBuildIssues -Repository 'dotnet/maui' + (Test-KnownIssueMatch -Patterns $loaded.patterns -Text $MatchingText).number | Should -Be 36435 + Test-KnownIssueMatch -Patterns $loaded.patterns -Text $PartialText | Should -BeNullOrEmpty + } + + It 'rejects partial, unrelated, reversed, or same-line array evidence: ' -ForEach @( + @{ Case = 'first only'; Indices = @(0); Separator = "`n" } + @{ Case = 'second only'; Indices = @(1); Separator = "`n" } + @{ Case = 'unrelated'; Indices = @(); Separator = "`n" } + @{ Case = 'reversed'; Indices = @(1, 0); Separator = "`n" } + @{ Case = 'same line'; Indices = @(0, 1); Separator = ' ' } + ) { + $loaded = Get-KnownBuildIssues -Repository 'dotnet/maui' + $text = 'Unrelated failure' + "`n" + (($Indices | ForEach-Object { $expressions[$_] }) -join $Separator) + Test-KnownIssueMatch -Patterns $loaded.patterns -Text $text | Should -BeNullOrEmpty + } + + It 'does not combine expressions from different tests at the real cross-reference call site' { + $knownIssues = Get-KnownBuildIssues -Repository 'dotnet/maui' + $failures = @(Get-DeduplicatedFailures -Failures @( + @{ testName = 'FileReaderTest'; platform = 'Android'; message = $expressions[0] }, + @{ testName = 'FileSystemTest'; platform = 'Android'; message = $expressions[1] } + )) + $failures.Count | Should -Be 2 + foreach ($failure in $failures) { + Invoke-KnownIssueCrossReference -Failure $failure -KnownIssues $knownIssues | Should -BeNullOrEmpty + } + } + + It 'preserves regex precedence, invalid-regex fallback, and scalar multiline matching: ' -ForEach @( + @{ Case = 'regex'; Message = @('missing first', 'missing second'); Pattern = 'ReadAsync\(\d+\)'; Text = 'READASYNC(42)' } + @{ Case = 'invalid regex literal fallback'; Message = 'ignored'; Pattern = '['; Text = 'literal [ bracket' } + @{ Case = 'multiline scalar'; Message = "first`nsecond"; Pattern = $null; Text = "before first`nsecond after" } + ) { + $script:kbeIssueFixture = New-KnownBuildIssueFixture -ErrorMessage $Message -ErrorPattern $Pattern + $loaded = Get-KnownBuildIssues -Repository 'dotnet/maui' + (Test-KnownIssueMatch -Patterns $loaded.patterns -Text $Text).number | Should -Be 36435 + Test-KnownIssueMatch -Patterns $loaded.patterns -Text 'unrelated failure' | Should -BeNullOrEmpty + } + + It 'keeps first-matching-issue selection with multiple issue rules' { + $script:kbeIssueFixture = @( + (New-KnownBuildIssueFixture -ErrorMessage 'unrelated' -Number 1), + (New-KnownBuildIssueFixture), + (New-KnownBuildIssueFixture -ErrorMessage $expressions[0] -Number 2) + ) + $loaded = Get-KnownBuildIssues -Repository 'dotnet/maui' + (Test-KnownIssueMatch -Patterns $loaded.patterns -Text ($expressions -join "`n")).number | Should -Be 36435 + } + + It 'does not match an array expression beyond the existing 20000-character text limit' { + $script:kbeIssueFixture = New-KnownBuildIssueFixture -ErrorMessage @('first frame', 'last frame') + $loaded = Get-KnownBuildIssues -Repository 'dotnet/maui' + $prefix = "first frame`n" + $withinLimit = $prefix + ('x' * (20000 - $prefix.Length - "`nlast frame".Length)) + "`nlast frame" + $withinLimit.Length | Should -Be 20000 + (Test-KnownIssueMatch -Patterns $loaded.patterns -Text $withinLimit).number | Should -Be 36435 + $beyondLimit = $prefix + ('x' * (20000 - $prefix.Length)) + "`nlast frame" + Test-KnownIssueMatch -Patterns $loaded.patterns -Text $beyondLimit | Should -BeNullOrEmpty + } + + It 'rejects an invalid array without weakening it to a partial matcher: ' -ForEach @( + @{ Case = 'empty'; Message = @() } + @{ Case = 'null element'; Message = @('first frame', $null) } + @{ Case = 'blank element'; Message = @('first frame', ' ') } + @{ Case = 'numeric element'; Message = @('first frame', 42) } + @{ Case = 'object element'; Message = @('first frame', @{ nested = 'last frame' }) } + @{ Case = 'nested array'; Message = @('first frame', @('last frame')) } + ) { + $script:kbeIssueFixture = New-KnownBuildIssueFixture -ErrorMessage $Message + Mock Write-Warning {} + $loaded = Get-KnownBuildIssues -Repository 'dotnet/maui' + @($loaded.patterns).Count | Should -Be 0 + Test-KnownIssueMatch -Patterns $loaded.patterns -Text 'first frame' | Should -BeNullOrEmpty + Should -Invoke Write-Warning -Times 1 -Exactly -ParameterFilter { $Message -like '*ErrorMessage array*36435*' } + } + + Context 'Occurrence-local array evidence' -Tag 'KnownIssueOccurrences' { + It 'does not assemble an array signature from separate occurrences of the same test and platform' { + $script:kbeIssueFixture = New-KnownBuildIssueFixture -ErrorMessage @('first frame', 'last frame') + $knownIssues = Get-KnownBuildIssues -Repository 'dotnet/maui' + $failures = @(Get-DeduplicatedFailures -Failures @( + @{ testName = 'Same.Test'; platform = 'Android'; message = 'first frame'; buildId = 1 }, + @{ testName = 'Same.Test'; platform = 'Android'; message = 'last frame'; buildId = 2 } + )) + $failures.Count | Should -Be 1 + $failures[0].occurrenceCount | Should -Be 2 + $failures[0].messages | Should -Be @('first frame', 'last frame') + Invoke-KnownIssueCrossReference -Failure $failures[0] -KnownIssues $knownIssues | Should -BeNullOrEmpty + } + + It 'matches a complete signature in one actual occurrence: ' -ForEach @( + @{ Case = 'message'; Occurrence = @{ testName = 'Same.Test'; platform = 'Android'; message = "FIRST FRAME`nintermediate frame`nLAST FRAME" } } + @{ Case = 'errorMessage and name aliases'; Occurrence = @{ name = 'Same.Test'; platform = 'Android'; errorMessage = "FIRST FRAME`nintermediate frame`nLAST FRAME" } } + ) { + $script:kbeIssueFixture = New-KnownBuildIssueFixture -ErrorMessage @('first frame', 'last frame') + $knownIssues = Get-KnownBuildIssues -Repository 'dotnet/maui' + $failures = @(Get-DeduplicatedFailures -Failures @( + @{ testName = 'Same.Test'; platform = 'Android'; message = 'unrelated occurrence' }, + $Occurrence + )) + $failures.Count | Should -Be 1 + (Invoke-KnownIssueCrossReference -Failure $failures[0] -KnownIssues $knownIssues).number | Should -Be 36435 + } + + It 'does not reuse aggregate messages when occurrence evidence is absent: ' -ForEach @( + @{ Case = 'no occurrences'; Occurrences = @() } + @{ Case = 'no message'; Occurrences = @(@{ testName = 'Same.Test'; platform = 'Android' }) } + @{ Case = 'blank message'; Occurrences = @(@{ testName = 'Same.Test'; platform = 'Android'; message = ' ' }) } + ) { + $script:kbeIssueFixture = New-KnownBuildIssueFixture -ErrorMessage @('first frame', 'last frame') + $knownIssues = Get-KnownBuildIssues -Repository 'dotnet/maui' + $failure = @{ testName = 'Same.Test'; messages = @('first frame', 'last frame'); occurrences = $Occurrences } + Invoke-KnownIssueCrossReference -Failure $failure -KnownIssues $knownIssues | Should -BeNullOrEmpty + } + + It 'selects the first matching rule even when it matches a later occurrence' { + $script:kbeIssueFixture = @( + (New-KnownBuildIssueFixture -ErrorMessage @('first frame', 'last frame') -Number 1), + (New-KnownBuildIssueFixture -ErrorMessage @('alternate first', 'alternate last') -Number 2) + ) + $knownIssues = Get-KnownBuildIssues -Repository 'dotnet/maui' + $failures = @(Get-DeduplicatedFailures -Failures @( + @{ testName = 'Same.Test'; platform = 'Android'; message = "alternate first`nalternate last" }, + @{ testName = 'Same.Test'; platform = 'Android'; message = "first frame`nlast frame" } + )) + (Invoke-KnownIssueCrossReference -Failure $failures[0] -KnownIssues $knownIssues).number | Should -Be 1 + } + + It 'preserves scalar and regex matching across aggregated occurrence messages: ' -ForEach @( + @{ Case = 'scalar multiline literal'; Message = "first frame`nlast frame"; Pattern = $null } + @{ Case = 'regex'; Message = @('ignored first', 'ignored last'); Pattern = 'FIRST FRAME\s+LAST FRAME' } + ) { + $script:kbeIssueFixture = New-KnownBuildIssueFixture -ErrorMessage $Message -ErrorPattern $Pattern + $knownIssues = Get-KnownBuildIssues -Repository 'dotnet/maui' + $failures = @(Get-DeduplicatedFailures -Failures @( + @{ testName = 'Same.Test'; platform = 'Android'; message = 'first frame' }, + @{ testName = 'Same.Test'; platform = 'Android'; message = 'last frame' } + )) + (Invoke-KnownIssueCrossReference -Failure $failures[0] -KnownIssues $knownIssues).number | Should -Be 36435 + } + + It 'preserves mixed rule ordering for scalar and array rules: ' -ForEach @( + @{ Case = 'scalar first'; ArrayFirst = $false; Expected = 1 } + @{ Case = 'array first'; ArrayFirst = $true; Expected = 2 } + ) { + $scalar = New-KnownBuildIssueFixture -ErrorMessage 'first frame' -Number 1 + $array = New-KnownBuildIssueFixture -ErrorMessage @('first frame', 'last frame') -Number 2 + $script:kbeIssueFixture = if ($ArrayFirst) { @($array, $scalar) } else { @($scalar, $array) } + $knownIssues = Get-KnownBuildIssues -Repository 'dotnet/maui' + $failures = @(Get-DeduplicatedFailures -Failures @( + @{ testName = 'Same.Test'; platform = 'Android'; message = 'first frame' }, + @{ testName = 'Same.Test'; platform = 'Android'; message = "first frame`nlast frame" } + )) + (Invoke-KnownIssueCrossReference -Failure $failures[0] -KnownIssues $knownIssues).number | Should -Be $Expected + } + + It 'retains the 20000-character cap for each occurrence: ' -ForEach @( + @{ Case = 'at limit'; Padding = 0; Expected = 36435 } + @{ Case = 'past limit'; Padding = 1; Expected = $null } + ) { + $script:kbeIssueFixture = New-KnownBuildIssueFixture -ErrorMessage @('first frame', 'last frame') + $knownIssues = Get-KnownBuildIssues -Repository 'dotnet/maui' + $prefix = "Same.Test`nfirst frame`n" + $message = "first frame`n" + ('x' * (20000 - $prefix.Length - "`nlast frame".Length + $Padding)) + "`nlast frame" + $failures = @(Get-DeduplicatedFailures -Failures @( + @{ testName = 'Same.Test'; platform = 'Android'; message = $message } + )) + (Invoke-KnownIssueCrossReference -Failure $failures[0] -KnownIssues $knownIssues).number | Should -Be $Expected + } + + Context 'Separately captured stack trace evidence' -Tag 'KnownIssueStackTraces' { + It 'matches array expressions in the same occurrence stack trace: ' -ForEach @( + @{ Case = 'stack trace only'; Message = 'System.NullReferenceException'; MessageExpression = $false } + @{ Case = 'no message'; Message = $null; MessageExpression = $false } + @{ Case = 'message followed by stack trace'; Message = 'at System.IO.FileStream.ReadAsync'; MessageExpression = $true } + ) { + $knownIssues = Get-KnownBuildIssues -Repository 'dotnet/maui' + $stackTrace = if ($MessageExpression) { $expressions[1] } else { $expressions -join "`n" } + $failures = @(Get-DeduplicatedFailures -Failures @( + @{ + testName = 'Same.Test'; platform = 'Android'; source = 'azdo-test-results' + buildId = 1; runId = 10; resultId = 20 + message = $Message; stackTrace = $stackTrace + } + )) + $failures.Count | Should -Be 1 + $failures[0].occurrences[0].stackTrace | Should -Be $stackTrace + (Invoke-KnownIssueCrossReference -Failure $failures[0] -KnownIssues $knownIssues).number | Should -Be 36435 + } + + It 'does not combine stack trace evidence from separate occurrences: ' -ForEach @( + @{ Case = 'two stack traces'; FirstMessage = 'error'; FirstTrace = 'at System.IO.FileStream.ReadAsync' } + @{ Case = 'message and another stack trace'; FirstMessage = 'at System.IO.FileStream.ReadAsync'; FirstTrace = '' } + ) { + $knownIssues = Get-KnownBuildIssues -Repository 'dotnet/maui' + $failures = @(Get-DeduplicatedFailures -Failures @( + @{ testName = 'Same.Test'; platform = 'Android'; buildId = 1; message = $FirstMessage; stackTrace = $FirstTrace }, + @{ testName = 'Same.Test'; platform = 'Android'; buildId = 2; message = 'error'; stackTrace = $expressions[1] } + )) + $failures.Count | Should -Be 1 + $failures[0].occurrenceCount | Should -Be 2 + Invoke-KnownIssueCrossReference -Failure $failures[0] -KnownIssues $knownIssues | Should -BeNullOrEmpty + } + + It 'does not add stack traces to scalar or regex aggregated text: ' -ForEach @( + @{ Case = 'scalar'; Message = 'first frame'; Pattern = $null } + @{ Case = 'regex'; Message = ''; Pattern = 'first\s+frame' } + ) { + $script:kbeIssueFixture = New-KnownBuildIssueFixture -ErrorMessage $Message -ErrorPattern $Pattern + $knownIssues = Get-KnownBuildIssues -Repository 'dotnet/maui' + $failures = @(Get-DeduplicatedFailures -Failures @( + @{ testName = 'Same.Test'; platform = 'Android'; message = 'error'; stackTrace = "first frame`nlast frame" } + )) + Invoke-KnownIssueCrossReference -Failure $failures[0] -KnownIssues $knownIssues | Should -BeNullOrEmpty + } + + It 'applies the existing text cap after including the stack trace: ' -ForEach @( + @{ Case = 'at limit'; Padding = 0; Expected = 36435 } + @{ Case = 'past limit'; Padding = 1; Expected = $null } + ) { + $script:kbeIssueFixture = New-KnownBuildIssueFixture -ErrorMessage @('first frame', 'last frame') + $knownIssues = Get-KnownBuildIssues -Repository 'dotnet/maui' + $prefix = "Same.Test`nerror`nfirst frame`n" + $stackTrace = "first frame`n" + ('x' * (20000 - $prefix.Length - "`nlast frame".Length + $Padding)) + "`nlast frame" + $failures = @(Get-DeduplicatedFailures -Failures @( + @{ testName = 'Same.Test'; platform = 'Android'; message = 'error'; stackTrace = $stackTrace } + )) + (Invoke-KnownIssueCrossReference -Failure $failures[0] -KnownIssues $knownIssues).number | Should -Be $Expected + } + } + } +} + Describe 'Direct failure links' { It 'prefers a web test result, then Helix, then a specific log, then the build: ' -ForEach @( @{ Case = 'test'; Failure = @{ buildId = 123; runId = 10; resultId = 20; logId = 7 }; Expected = 'https://dev.azure.com/dnceng-public/public/_build/results?buildId=123&view=ms.vss-test-web.build-test-results-tab&runId=10&resultId=20' } diff --git a/.github/skills/review-test-failures/scripts/Gather-TestFailureContext.ps1 b/.github/skills/review-test-failures/scripts/Gather-TestFailureContext.ps1 index 0638876ac038..5fb2698813ed 100644 --- a/.github/skills/review-test-failures/scripts/Gather-TestFailureContext.ps1 +++ b/.github/skills/review-test-failures/scripts/Gather-TestFailureContext.ps1 @@ -2550,9 +2550,8 @@ function Get-AggregatedBaseLegMap { function Get-KnownBuildIssues { # Loads the repo's open "Known Build Error" issues (the dotnet Build Analysis # known-issues registry). Each such issue body carries one or more ```json blocks - # with an ErrorMessage (substring) and/or ErrorPattern (regex) field. We compile - # those into matchers so a PR failure whose message matches a documented known - # issue can be stamped as a known flake instead of being read as PR-caused. + # with an ErrorMessage (literal or ordered array of line literals) and/or + # ErrorPattern (regex) field. A match is a cross-reference hint, not a flake verdict. param([string]$Repository) $patterns = New-Object System.Collections.Generic.List[object] @@ -2576,11 +2575,26 @@ function Get-KnownBuildIssues { $pattern = [string]$obj.ErrorPattern $isRegex = $true } - elseif (($obj.PSObject.Properties.Name -contains "ErrorMessage") -and $obj.ErrorMessage) { - $pattern = [string]$obj.ErrorMessage - $isRegex = $false + elseif ($obj.PSObject.Properties.Name -contains "ErrorMessage") { + if ($obj.ErrorMessage -is [System.Array]) { + $validArray = $obj.ErrorMessage.Count -gt 0 + foreach ($expression in $obj.ErrorMessage) { + if ($expression -isnot [string] -or [string]::IsNullOrWhiteSpace($expression)) { + $validArray = $false + break + } + } + if (-not $validArray) { + Write-Warning "Skipping invalid ErrorMessage array in Known Build Error #$($issue.number): expected non-empty strings." + continue + } + $pattern = [string[]]$obj.ErrorMessage + } + elseif ($obj.ErrorMessage) { + $pattern = [string]$obj.ErrorMessage + } } - if ([string]::IsNullOrWhiteSpace($pattern)) { + if ($pattern -isnot [System.Array] -and [string]::IsNullOrWhiteSpace($pattern)) { continue } # Validate a declared regex; fall back to substring matching if it is invalid @@ -2606,9 +2620,12 @@ function Get-KnownBuildIssues { function Test-KnownIssueMatch { # Returns the first known-issue {number,title,url} whose pattern matches $Text, # or $null. Regex matches use a short timeout to defang a pathological pattern. + # Literal arrays require every expression on distinct subsequent lines in one + # occurrence. Omitted occurrence text preserves standalone single-text matching. param( [object[]]$Patterns, - [string]$Text + [string]$Text, + [string[]]$OccurrenceTexts ) if ([string]::IsNullOrWhiteSpace($Text) -or -not $Patterns) { @@ -2618,6 +2635,10 @@ function Test-KnownIssueMatch { $Text = $Text.Substring(0, 20000) } + $arrayTexts = @($Text) + if ($PSBoundParameters.ContainsKey('OccurrenceTexts')) { + $arrayTexts = @($OccurrenceTexts) + } foreach ($p in $Patterns) { $hit = $false if ($p.isRegex) { @@ -2629,6 +2650,27 @@ function Test-KnownIssueMatch { } catch { $hit = $false } } + elseif ($p.pattern -is [System.Array]) { + foreach ($arrayText in $arrayTexts) { + if ([string]::IsNullOrWhiteSpace($arrayText)) { continue } + if ($arrayText.Length -gt 20000) { $arrayText = $arrayText.Substring(0, 20000) } + $lines = $arrayText -split '\r\n|\n|\r' + $lineIndex = 0 + $hit = $p.pattern.Count -gt 0 + foreach ($expression in $p.pattern) { + $found = $false + while ($lineIndex -lt $lines.Count -and -not $found) { + $found = $lines[$lineIndex].IndexOf($expression, [System.StringComparison]::OrdinalIgnoreCase) -ge 0 + $lineIndex++ + } + if (-not $found) { + $hit = $false + break + } + } + if ($hit) { break } + } + } else { $hit = $Text.IndexOf([string]$p.pattern, [System.StringComparison]::OrdinalIgnoreCase) -ge 0 } @@ -4601,11 +4643,15 @@ foreach ($failure in $dedupedFailures) { } $failure['retriedStillFailing'] = [bool]$retried - # Known-issue cross-reference: match the test name + failure messages against the - # repo's open "Known Build Error" registry. A hit is strong "documented flake / - # unrelated" evidence the classifier can cite by issue number. + # Arrays must match within one occurrence; scalar/regex rules keep aggregated text. + # A signature match is a hint, not a presumed flake verdict. $matchText = (@([string]$failure.testName) + @($failure.messages)) -join "`n" - $failure['matchesKnownIssue'] = Test-KnownIssueMatch -Patterns $knownIssues.patterns -Text $matchText + $occurrenceMatchTexts = @($failure.occurrences | ForEach-Object { + (@([string](Get-ObjectValue -Object $_ -Names @("testName", "name") -Default $failure.testName)) + + @([string](Get-ObjectValue -Object $_ -Names @("message", "errorMessage"))) + + @([string](Get-ObjectValue -Object $_ -Names @("stackTrace")))) -join "`n" + }) + $failure['matchesKnownIssue'] = Test-KnownIssueMatch -Patterns $knownIssues.patterns -Text $matchText -OccurrenceTexts $occurrenceMatchTexts # ci-scan cross-reference: does this failure's exact test (or its failing leg) appear in the # multi-build base-branch failure registry for THIS PR's base branch family? A hit means the