From e2892b088c61cfd7e43b69c8e715abb6cae99907 Mon Sep 17 00:00:00 2001 From: PureWeen <223556219+Copilot@users.noreply.github.com> Date: Wed, 7 Oct 2026 11:43:34 -0500 Subject: [PATCH 1/3] CI: Match Known Build Error message arrays on ordered lines Preserve literal ErrorMessage arrays instead of joining their expressions into a contiguous scalar substring. Require ordered matches on distinct subsequent lines in the same failure text and warn when skipping invalid arrays. Preserve scalar, regex, text-limit, selection, and attribution behavior. Add 25 loader-to-matcher regression cases and document the bounded public Build Analysis contract. All 215 collector cases pass; current-main red/green checks reproduce 16 expected failures and nine controls before the fix. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 876ad450-5f81-4c61-8ec7-e54600c51004 --- .github/docs/maui-ci-facts.md | 6 + .../Gather-TestFailureContext.Tests.ps1 | 168 +++++++++++++++++- .../scripts/Gather-TestFailureContext.ps1 | 51 ++++-- 3 files changed, 213 insertions(+), 12 deletions(-) diff --git a/.github/docs/maui-ci-facts.md b/.github/docs/maui-ci-facts.md index bdb090fded7f..ba5f0c834e20 100644 --- a/.github/docs/maui-ci-facts.md +++ b/.github/docs/maui-ci-facts.md @@ -406,6 +406,12 @@ 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 in the same failure text, + 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). + Existing case-insensitive scalar substring and regex handling, the 20,000-character + text limit, 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..625cf3954ab2 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,167 @@ 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" + '```' + } + } + } + + 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' + $assignments = $gatherAst.FindAll({ + $args[0] -is [System.Management.Automation.Language.AssignmentStatementAst] -and + $args[0].Left.Extent.Text -in @('$matchText', '$failure[''matchesKnownIssue'']') + }, $true) + $assignments.Count | Should -Be 2 + foreach ($failure in @( + @{ testName = 'FileReaderTest'; messages = @($expressions[0]) }, + @{ testName = 'FileSystemTest'; messages = @($expressions[1]) } + )) { + foreach ($assignment in $assignments) { Invoke-Expression $assignment.Extent.Text } + $failure.matchesKnownIssue | 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*' } + } +} + 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..280511676c49 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,6 +2620,7 @@ 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, in order, on distinct subsequent lines. param( [object[]]$Patterns, [string]$Text @@ -2618,6 +2633,7 @@ function Test-KnownIssueMatch { $Text = $Text.Substring(0, 20000) } + $lines = $null foreach ($p in $Patterns) { $hit = $false if ($p.isRegex) { @@ -2629,6 +2645,22 @@ function Test-KnownIssueMatch { } catch { $hit = $false } } + elseif ($p.pattern -is [System.Array]) { + if ($null -eq $lines) { $lines = $Text -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 + } + } + } else { $hit = $Text.IndexOf([string]$p.pattern, [System.StringComparison]::OrdinalIgnoreCase) -ge 0 } @@ -4601,9 +4633,8 @@ 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. + # Known-issue cross-reference for this failure only. A signature match is a hint; + # attribution still needs independent evidence, not a presumed flake verdict. $matchText = (@([string]$failure.testName) + @($failure.messages)) -join "`n" $failure['matchesKnownIssue'] = Test-KnownIssueMatch -Patterns $knownIssues.patterns -Text $matchText From 7c1ee12b305e83abe996ef042b8ccfdf35466ff7 Mon Sep 17 00:00:00 2001 From: PureWeen <223556219+Copilot@users.noreply.github.com> Date: Wed, 7 Oct 2026 12:24:44 -0500 Subject: [PATCH 2/3] CI: Keep KBE array matches within one occurrence Evaluate literal ErrorMessage arrays against each actual failure occurrence instead of messages aggregated across occurrences of the same test and platform. Keep scalar and regex aggregation, the 20000-character cap per text, pattern-first selection, and attribution gates unchanged. Add same-test split-occurrence regression coverage through production deduplication and the actual cross-reference path, plus complete-occurrence, alias, empty-evidence, ordering, scalar/regex, and text-limit controls. All 38 KBE cases and 228 collector cases pass; four new cases reproduce unsupported hints on the prior PR head. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 876ad450-5f81-4c61-8ec7-e54600c51004 --- .github/docs/maui-ci-facts.md | 8 +- .../Gather-TestFailureContext.Tests.ps1 | 133 ++++++++++++++++-- .../scripts/Gather-TestFailureContext.ps1 | 50 ++++--- 3 files changed, 159 insertions(+), 32 deletions(-) diff --git a/.github/docs/maui-ci-facts.md b/.github/docs/maui-ci-facts.md index ba5f0c834e20..7b76359d76c0 100644 --- a/.github/docs/maui-ci-facts.md +++ b/.github/docs/maui-ci-facts.md @@ -407,10 +407,12 @@ on appearance alone: 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 in the same failure text, + 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). - Existing case-insensitive scalar substring and regex handling, the 20,000-character - text limit, and attribution gates are unchanged. This local hint matcher does not + Arrays cannot combine partial messages 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 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 625cf3954ab2..aea8af80b171 100644 --- a/.github/skills/review-test-failures/scripts/Gather-TestFailureContext.Tests.ps1 +++ b/.github/skills/review-test-failures/scripts/Gather-TestFailureContext.Tests.ps1 @@ -353,6 +353,26 @@ Describe 'Known Build Error loader-to-matcher boundary' -Tag 'KnownBuildIssues' 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 { @@ -430,17 +450,13 @@ Describe 'Known Build Error loader-to-matcher boundary' -Tag 'KnownBuildIssues' It 'does not combine expressions from different tests at the real cross-reference call site' { $knownIssues = Get-KnownBuildIssues -Repository 'dotnet/maui' - $assignments = $gatherAst.FindAll({ - $args[0] -is [System.Management.Automation.Language.AssignmentStatementAst] -and - $args[0].Left.Extent.Text -in @('$matchText', '$failure[''matchesKnownIssue'']') - }, $true) - $assignments.Count | Should -Be 2 - foreach ($failure in @( - @{ testName = 'FileReaderTest'; messages = @($expressions[0]) }, - @{ testName = 'FileSystemTest'; messages = @($expressions[1]) } - )) { - foreach ($assignment in $assignments) { Invoke-Expression $assignment.Extent.Text } - $failure.matchesKnownIssue | Should -BeNullOrEmpty + $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 } } @@ -491,6 +507,101 @@ Describe 'Known Build Error loader-to-matcher boundary' -Tag 'KnownBuildIssues' 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 + } + } } Describe 'Direct failure links' { diff --git a/.github/skills/review-test-failures/scripts/Gather-TestFailureContext.ps1 b/.github/skills/review-test-failures/scripts/Gather-TestFailureContext.ps1 index 280511676c49..13ea11040d3b 100644 --- a/.github/skills/review-test-failures/scripts/Gather-TestFailureContext.ps1 +++ b/.github/skills/review-test-failures/scripts/Gather-TestFailureContext.ps1 @@ -2620,10 +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, in order, on distinct subsequent lines. + # 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) { @@ -2633,7 +2635,10 @@ function Test-KnownIssueMatch { $Text = $Text.Substring(0, 20000) } - $lines = $null + $arrayTexts = @($Text) + if ($PSBoundParameters.ContainsKey('OccurrenceTexts')) { + $arrayTexts = @($OccurrenceTexts) + } foreach ($p in $Patterns) { $hit = $false if ($p.isRegex) { @@ -2646,19 +2651,24 @@ function Test-KnownIssueMatch { catch { $hit = $false } } elseif ($p.pattern -is [System.Array]) { - if ($null -eq $lines) { $lines = $Text -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 + 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 { @@ -4633,10 +4643,14 @@ foreach ($failure in $dedupedFailures) { } $failure['retriedStillFailing'] = [bool]$retried - # Known-issue cross-reference for this failure only. A signature match is a hint; - # attribution still needs independent evidence, not a presumed flake verdict. + # 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")))) -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 From 6379c58d9da3d5ba086d7f1a3379913677b82c93 Mon Sep 17 00:00:00 2001 From: PureWeen <223556219+Copilot@users.noreply.github.com> Date: Fri, 9 Oct 2026 15:46:25 -0500 Subject: [PATCH 3/3] CI: Include occurrence stack traces in KBE array matching MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Append each occurrence’s separately captured stackTrace only to its literal-array matching text. Keep aggregate scalar/regex behavior unchanged and cover real deduplication and cross-reference paths, isolation, and text limits. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 876ad450-5f81-4c61-8ec7-e54600c51004 --- .github/docs/maui-ci-facts.md | 5 +- .../Gather-TestFailureContext.Tests.ps1 | 61 +++++++++++++++++++ .../scripts/Gather-TestFailureContext.ps1 | 3 +- 3 files changed, 66 insertions(+), 3 deletions(-) diff --git a/.github/docs/maui-ci-facts.md b/.github/docs/maui-ci-facts.md index 7b76359d76c0..63b767f8a3ed 100644 --- a/.github/docs/maui-ci-facts.md +++ b/.github/docs/maui-ci-facts.md @@ -409,8 +409,9 @@ on appearance alone: 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). - Arrays cannot combine partial messages from separate occurrences of a deduplicated - test/platform. Scalar and regex rules retain their existing aggregated text. + 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. 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 aea8af80b171..3ed584977ad0 100644 --- a/.github/skills/review-test-failures/scripts/Gather-TestFailureContext.Tests.ps1 +++ b/.github/skills/review-test-failures/scripts/Gather-TestFailureContext.Tests.ps1 @@ -601,6 +601,67 @@ Describe 'Known Build Error loader-to-matcher boundary' -Tag 'KnownBuildIssues' )) (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 + } + } } } diff --git a/.github/skills/review-test-failures/scripts/Gather-TestFailureContext.ps1 b/.github/skills/review-test-failures/scripts/Gather-TestFailureContext.ps1 index 13ea11040d3b..5fb2698813ed 100644 --- a/.github/skills/review-test-failures/scripts/Gather-TestFailureContext.ps1 +++ b/.github/skills/review-test-failures/scripts/Gather-TestFailureContext.ps1 @@ -4648,7 +4648,8 @@ foreach ($failure in $dedupedFailures) { $matchText = (@([string]$failure.testName) + @($failure.messages)) -join "`n" $occurrenceMatchTexts = @($failure.occurrences | ForEach-Object { (@([string](Get-ObjectValue -Object $_ -Names @("testName", "name") -Default $failure.testName)) + - @([string](Get-ObjectValue -Object $_ -Names @("message", "errorMessage")))) -join "`n" + @([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