Skip to content
Closed
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
c98bc94
Auto-apply s/agent-ready-for-rerun from the PR Review Queue workflow
Copilot Jul 3, 2026
152406b
Grant pull-requests: write so the auto-label step can apply the label
Copilot Jul 3, 2026
a2fc3e9
Allow scanner to trigger reruns from autonomous queue labels
Copilot Jul 4, 2026
fb233b4
Harden auto-rerun labeler: per-PR error isolation, arg-passing, fetch…
Copilot Jul 7, 2026
9b0a5aa
Auto-rerun labeler: single-source label metadata, fail-loud label fet…
Copilot Jul 7, 2026
f2cd01e
auto-rerun labeler: fail loud on gh api errors in activity/commit fet…
Copilot Jul 7, 2026
b60eadf
Merge remote-tracking branch 'origin/main' into feature/auto-rerun-la…
Copilot Jul 8, 2026
5c53948
auto-rerun labeler: fix -Limit help default, fail-loud label re-read,…
Copilot Jul 10, 2026
5b4acfe
Address review: verify-read regression, label-desc drift, redundant l…
Copilot Jul 16, 2026
8d72e52
Fix autonomous-rerun daily flap on scanner skip (last-declined checkp…
Copilot Jul 16, 2026
fe99a54
Doc: note head-SHA-differs as qualifying rerun activity
Copilot Jul 16, 2026
6b46aac
Surface gh api stderr in Get-IssueLabels on failure
Copilot Jul 16, 2026
0fa7212
Make -ApplyLabel post-apply verification failure-tolerant
Copilot Jul 16, 2026
2637ec3
Merge origin/main into feature/auto-rerun-labeler
kubaflo Jul 26, 2026
620a7d9
Merge main into feature/auto-rerun-labeler
Copilot Aug 6, 2026
5886164
Harden autonomous rerun candidate scanning
Aug 10, 2026
d4ed6b3
Make rerun tests hermetic in full suite
Aug 10, 2026
3a3c1ab
Make rerun decline lifecycle race-safe
Aug 10, 2026
1967d88
Address auto-rerun review feedback
Aug 12, 2026
9657be3
Handle concurrent rerun label creation
Aug 12, 2026
e60d765
Harden autonomous rerun queue handling
Aug 15, 2026
fc4d474
Fix auto-rerun review activity checkpoints
Aug 18, 2026
89a9bae
Make rerun decline markers retry-safe
Aug 18, 2026
08ce06b
Harden PR queue validation
Aug 18, 2026
16a93c7
Fix rerun decline activity checkpoints
Aug 18, 2026
d29cfbd
Paginate rerun decline markers
Aug 18, 2026
d4a0773
Correct rerun queue guidance
Aug 18, 2026
e35aebd
Harden rerun scanner decisions
Aug 18, 2026
75a906c
Harden rerun scanner validation
Aug 19, 2026
d14abf2
Harden rerun queue activity handling
Aug 19, 2026
2a399db
Keep queue contract test outside skill validation
Aug 19, 2026
17dc7d3
Clarify scanner decline marker contract
Aug 19, 2026
5b9ec42
Paginate rerun label verification
Aug 19, 2026
b37011d
Harden rerun pagination and anti-flap
Aug 19, 2026
55879a1
Secure rerun logging and scanner coverage
Aug 19, 2026
0f44489
Disable queue checkout credential persistence
Aug 19, 2026
8f2a314
Harden rerun validation and live dispatch
Aug 19, 2026
94a3766
Discover queue validation test suites
Aug 19, 2026
98dc01d
Fix rerun eligibility and batch validation
Aug 19, 2026
d09eaa9
Fix mixed rerun decision batch validation
Aug 19, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions .github/scripts/Invoke-RerunReviewTrigger.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -333,14 +333,17 @@ Describe 'Get-RerunActions' {
$result.Actions.Count | Should -Be 0
}

It 'refuses to trigger when the candidate has no rerun comment id' {
It 'triggers when the candidate has no rerun comment id (autonomous queue label)' {
$items = @(New-TestDecision -PRNumber '5' -Decision 'trigger' -ExpectedHeadSha 'x')
$candidates = @(New-TestCandidate -PRNumber 5 -HeadSha 'x' -RerunCommentId 0)

$result = Get-RerunActions -Items $items -Candidates $candidates

$result.HadFailure | Should -BeTrue
$result.Actions.Count | Should -Be 0
$result.HadFailure | Should -BeFalse
$result.Actions.Count | Should -Be 1
$result.Actions[0].prNumber | Should -Be 5
$result.Actions[0].decision | Should -Be 'trigger'
$result.Actions[0].rerunCommentId | Should -Be 0
}

It 'continues processing valid decisions after a failed one' {
Expand Down
6 changes: 5 additions & 1 deletion .github/scripts/Invoke-RerunReviewTrigger.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,12 @@ function Get-RerunActions {
$platform = Get-PlatformFromLabels -Labels @() -Fallback ([string]$candidate.platform)
$pipelineRef = Normalize-PipelineRef -Value ([string]$candidate.pipelineRef) -Fallback $DefaultPipelineRef

# A comment-less trigger is valid: the PR Review Queue workflow applies
# s/agent-ready-for-rerun autonomously (no `/review rerun` comment), so
# rerunCommentId is 0. review-trigger.yml does not need a comment to
# dispatch, and the downstream react step no-ops when the id is <= 0.
if ($decision -eq 'trigger' -and $rerunCommentId -le 0) {
throw "Candidate for PR #$prNumber has no rerun comment id; cannot trigger."
Write-Host "PR #$prNumber trigger has no rerun comment id (autonomous queue label); dispatching without a reaction target."
}

$actions.Add([pscustomobject]@{
Expand Down
244 changes: 244 additions & 0 deletions .github/scripts/Query-AutoRerunCandidates.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,244 @@
#!/usr/bin/env pwsh
#Requires -Modules Pester

BeforeAll {
$scriptPath = Join-Path $PSScriptRoot 'Query-AutoRerunCandidates.ps1'
$workflowPath = Join-Path $PSScriptRoot '../workflows/pr-review-queue.yml'
$scannerPath = Join-Path $PSScriptRoot '../workflows/rerun-review-scanner.md'
$labelHelperPath = Join-Path $PSScriptRoot 'shared/Update-AgentLabels.ps1'
$outputDir = Join-Path $PSScriptRoot '../../CustomAgentLogsTmp/QueryAutoRerunTests'
New-Item -ItemType Directory -Force -Path $outputDir | Out-Null

. $scriptPath -Owner 'test-owner' -Repo 'test-repo'

function New-TestPR {
param(
[int]$Number,
[bool]$IsDraft = $false,
[string[]]$Labels = @(),
[string]$HeadSha = '2222222abcdef'
)

[pscustomobject]@{
number = $Number
title = "PR $Number"
url = "https://example.test/$Number"
headRefOid = $HeadSha
isDraft = $IsDraft
labels = @($Labels | ForEach-Object { [pscustomobject]@{ name = $_ } })
author = [pscustomobject]@{ login = 'dev-user' }
}
}

function ConvertTo-GhLines {
param([object[]]$Items)
return @($Items | ForEach-Object { $_ | ConvertTo-Json -Depth 10 -Compress })
}

function Invoke-TestScan {
Invoke-AutoRerunCandidateScan `
-ScanOwner 'test-owner' `
-ScanRepo 'test-repo' `
-ScanLimit $script:Limit `
-ScanDryRun:$script:DryRun `
-ScanOutputPath $script:OutputPath
}
}

AfterAll {
Remove-Item -LiteralPath $outputDir -Recurse -Force -ErrorAction SilentlyContinue
}

Describe 'Query-AutoRerunCandidates' {
BeforeEach {
$script:Owner = 'test-owner'
$script:Repo = 'test-repo'
$script:Limit = 5
$script:DryRun = $true
$script:OutputPath = Join-Path $outputDir "$([Guid]::NewGuid().ToString('N')).json"
$script:prList = @()
$script:issueComments = @()
$script:reviews = @()
$script:reviewComments = @()
$script:commits = @()
$script:declinedTimestamps = @()
$script:failedPRs = @()
$script:ghCalls = @()

Mock gh {
param(
[Parameter(ValueFromRemainingArguments = $true)]
[string[]]$GhArgs
)

$command = $GhArgs -join ' '
$script:ghCalls += $command
$global:LASTEXITCODE = 0

if ($command -match '^pr list ') {
return ($script:prList | ConvertTo-Json -Depth 10 -Compress)
}

$numberMatch = [regex]::Match($command, '/(?:issues|pulls)/(\d+)/')
$number = if ($numberMatch.Success) { [int]$numberMatch.Groups[1].Value } else { 0 }
if ($script:failedPRs -contains $number) {
$global:LASTEXITCODE = 1
return @()
}

if ($command -match '/issues/\d+/comments') { return ConvertTo-GhLines $script:issueComments }
if ($command -match '/pulls/\d+/reviews') { return ConvertTo-GhLines $script:reviews }
if ($command -match '/pulls/\d+/comments') { return ConvertTo-GhLines $script:reviewComments }
if ($command -match '/pulls/\d+/commits') { return ConvertTo-GhLines $script:commits }
if ($command -match '/issues/\d+/events') { return @($script:declinedTimestamps) }

throw "Unexpected gh call: $command"
}
}

Context 'bounded scan metadata' {
It 'processes only Limit items and reports exact truncation using one sentinel item' {
$script:prList = @(1..6 | ForEach-Object { New-TestPR -Number $_ -IsDraft $true })

$messages = Invoke-TestScan 6>&1 | Out-String

$summary = Get-Content -Raw -LiteralPath $script:OutputPath | ConvertFrom-Json
$messages | Should -Match '::warning::Open PR scan truncated'
$summary.scan.limit | Should -Be 5
$summary.scan.fetchedCount | Should -Be 5
$summary.scan.observedCount | Should -Be 6
$summary.scan.truncated | Should -BeTrue
$summary.decisions.Count | Should -Be 5
@($script:ghCalls | Where-Object { $_ -match '^pr list .*--limit 6' }).Count | Should -Be 1
}

It 'pins pull-request dry-run validation to Limit 5' {
$workflow = Get-Content -Raw -LiteralPath $workflowPath
$workflow | Should -Match '(?s)Validate auto-rerun labeler \(dry-run\).*?-DryRun\s+\\\s*\r?\n\s*-Limit 5\s+\\'
}
}

Context 'error aggregation' {
It 'fails a dry-run after writing structured error details' {
$script:prList = @(1..2 | ForEach-Object { New-TestPR -Number $_ })
$script:failedPRs = @(1, 2)

{ Invoke-TestScan } | Should -Throw '*2 of 2 evaluated PR(s) had errors*'

$summary = Get-Content -Raw -LiteralPath $script:OutputPath | ConvertFrom-Json
$summary.errors | Should -Be 2
$summary.evaluated | Should -Be 2
$summary.systemicFailure | Should -BeTrue
@($summary.decisions | Where-Object reason -like 'error:*').Count | Should -Be 2
}

It 'keeps an isolated scheduled error non-fatal but visible' {
$script:DryRun = $false
$script:prList = @(1..4 | ForEach-Object { New-TestPR -Number $_ })
$script:failedPRs = @(1)

{ Invoke-TestScan } | Should -Not -Throw

$summary = Get-Content -Raw -LiteralPath $script:OutputPath | ConvertFrom-Json
$summary.errors | Should -Be 1
$summary.systemicFailure | Should -BeFalse
}

It 'fails a scheduled scan when evaluation failures are systemic' {
$script:DryRun = $false
$script:prList = @(1..3 | ForEach-Object { New-TestPR -Number $_ })
$script:failedPRs = @(1, 2, 3)

{ Invoke-TestScan } | Should -Throw '*3 of 3 evaluated PR(s) had errors*'

$summary = Get-Content -Raw -LiteralPath $script:OutputPath | ConvertFrom-Json
$summary.systemicFailure | Should -BeTrue
}
}

Context 'scanner decline checkpoint' {
It 'does not treat generic ready-label removals as scanner declines' {
$script:prList = @(New-TestPR -Number 6)
$script:issueComments = @(
[pscustomobject]@{
id = 1
body = "<!-- AI Summary -->`n<!-- SESSION:1111111 START -->"
created_at = '2026-05-31T09:00:00Z'
updated_at = '2026-05-31T09:00:00Z'
user = [pscustomobject]@{ login = 'MauiBot'; type = 'User' }
author_association = 'MEMBER'
}
)
$script:declinedTimestamps = @('2026-05-31T10:00:00Z')

Invoke-TestScan

$summary = Get-Content -Raw -LiteralPath $script:OutputPath | ConvertFrom-Json
$summary.decisions[0].eligible | Should -BeTrue
$summary.decisions[0].reason | Should -Be 'new-head-commit'
@($script:ghCalls | Where-Object { $_ -match '/issues/\d+/events' }).Count | Should -Be 0
}

It 'sorts explicit scanner markers newest-first and re-evaluates eligibility against that checkpoint' {
$script:prList = @(
New-TestPR -Number 7 -Labels @('s/agent-rerun-declined')
)
$script:issueComments = @(
[pscustomobject]@{
id = 1
body = "<!-- AI Summary -->`n<!-- SESSION:1111111 START -->"
created_at = '2026-05-31T09:00:00Z'
updated_at = '2026-05-31T09:00:00Z'
user = [pscustomobject]@{ login = 'MauiBot'; type = 'User' }
author_association = 'MEMBER'
},
[pscustomobject]@{
id = 2
body = 'I pushed the update.'
created_at = '2026-05-31T09:45:00Z'
updated_at = '2026-05-31T09:45:00Z'
user = [pscustomobject]@{ login = 'dev-user'; type = 'User' }
author_association = 'CONTRIBUTOR'
}
)
$script:declinedTimestamps = @(
'2026-05-31T08:00:00Z',
'2026-05-31T10:00:00Z',
'2026-05-31T09:30:00Z'
)

Invoke-TestScan

$summary = Get-Content -Raw -LiteralPath $script:OutputPath | ConvertFrom-Json
$summary.decisions[0].eligible | Should -BeFalse
$summary.decisions[0].reason | Should -Be 'declined-state-unchanged'
@($script:ghCalls | Where-Object {
$_ -match 'event == .labeled.' -and $_ -match 's/agent-rerun-declined'
}).Count | Should -Be 1
}

It 'persists skip markers before consuming ready labels and clears them before trigger dispatch' {
Comment thread
kubaflo marked this conversation as resolved.
Resolved
$scanner = Get-Content -Raw -LiteralPath $scannerPath
$scanner.IndexOf('await markDeclined(prNumber);') |
Should -BeLessThan $scanner.IndexOf("await react(a.rerunCommentId, '-1');")
$scanner.IndexOf("await react(a.rerunCommentId, '-1');") |
Should -BeLessThan $scanner.IndexOf('await removeReadyLabel(prNumber);')
$scanner.IndexOf('await clearDeclined(prNumber);') |
Should -BeLessThan $scanner.IndexOf('await github.rest.actions.createWorkflowDispatch({')
}

It 'keeps scanner decline-label metadata aligned with the shared definition' {
$scanner = Get-Content -Raw -LiteralPath $scannerPath
$labelHelper = Get-Content -Raw -LiteralPath $labelHelperPath

foreach ($value in @(
's/agent-rerun-declined',
'AI rerun scanner declined the current PR state; new author activity is required',
'D4C5F9'
)) {
$scanner | Should -Match ([regex]::Escape($value))
$labelHelper | Should -Match ([regex]::Escape($value))
}
}
}
}
Loading
Loading