|
| 1 | +Set-StrictMode -Version Latest |
| 2 | +$ErrorActionPreference = 'Stop' |
| 3 | + |
| 4 | +Describe 'Agent Handoff queue-empty mode' -Tag 'Unit' { |
| 5 | + It 'tolerates a queue-empty cache even when a stale numeric snapshot is still present' { |
| 6 | + $repoRoot = (Resolve-Path (Join-Path $PSScriptRoot '..')).Path |
| 7 | + $workspaceRoot = Join-Path $TestDrive 'repo' |
| 8 | + $toolsDir = Join-Path $workspaceRoot 'tools' |
| 9 | + $scriptPath = Join-Path $toolsDir 'Print-AgentHandoff.ps1' |
| 10 | + $issueDir = Join-Path $workspaceRoot 'tests' 'results' '_agent' 'issue' |
| 11 | + $cachePath = Join-Path $workspaceRoot '.agent_priority_cache.json' |
| 12 | + $resultsRoot = Join-Path $TestDrive 'results' |
| 13 | + New-Item -ItemType Directory -Force -Path $toolsDir | Out-Null |
| 14 | + Copy-Item -LiteralPath (Join-Path $repoRoot 'tools' 'Print-AgentHandoff.ps1') -Destination $scriptPath -Force |
| 15 | + |
| 16 | + try { |
| 17 | + New-Item -ItemType Directory -Force -Path $issueDir | Out-Null |
| 18 | + New-Item -ItemType Directory -Force -Path $resultsRoot | Out-Null |
| 19 | + Set-Content -LiteralPath (Join-Path $workspaceRoot 'AGENT_HANDOFF.txt') -Value @( |
| 20 | + '# Agent Handoff' |
| 21 | + '' |
| 22 | + 'Synthetic queue-empty handoff workspace for test coverage.' |
| 23 | + ) -Encoding utf8 |
| 24 | + |
| 25 | + Push-Location $workspaceRoot |
| 26 | + |
| 27 | + [pscustomobject][ordered]@{ |
| 28 | + schema = 'standing-priority/issue@v1' |
| 29 | + number = 911 |
| 30 | + title = 'Standing Priority Intake: handle an empty backlog without breaking bootstrap' |
| 31 | + state = 'OPEN' |
| 32 | + updatedAt = '2026-03-08T23:35:13Z' |
| 33 | + url = 'https://github.com/LabVIEW-Community-CI-CD/compare-vi-cli-action/issues/911' |
| 34 | + labels = @('bug', 'standing-priority') |
| 35 | + assignees = @() |
| 36 | + milestone = 'LabVIEW CI Platform v1 (2026Q2)' |
| 37 | + commentCount = 0 |
| 38 | + bodyDigest = 'body-digest-911' |
| 39 | + digest = 'digest-911' |
| 40 | + } | ConvertTo-Json -Depth 6 | Set-Content -LiteralPath (Join-Path $issueDir '911.json') -Encoding utf8 |
| 41 | + |
| 42 | + [pscustomobject][ordered]@{ |
| 43 | + schema = 'standing-priority/no-standing@v1' |
| 44 | + generatedAt = '2026-03-08T23:51:50.543Z' |
| 45 | + repository = 'LabVIEW-Community-CI-CD/compare-vi-cli-action' |
| 46 | + labels = @('standing-priority') |
| 47 | + message = 'No open issues remain in LabVIEW-Community-CI-CD/compare-vi-cli-action; the standing-priority queue is empty.' |
| 48 | + reason = 'queue-empty' |
| 49 | + openIssueCount = 0 |
| 50 | + failOnMissing = $true |
| 51 | + } | ConvertTo-Json -Depth 6 | Set-Content -LiteralPath (Join-Path $issueDir 'no-standing-priority.json') -Encoding utf8 |
| 52 | + |
| 53 | + [pscustomobject][ordered]@{ |
| 54 | + schema = 'agent/priority-router@v1' |
| 55 | + issue = $null |
| 56 | + updatedAt = '2026-03-08T23:51:50.541Z' |
| 57 | + actions = @() |
| 58 | + } | ConvertTo-Json -Depth 6 | Set-Content -LiteralPath (Join-Path $issueDir 'router.json') -Encoding utf8 |
| 59 | + |
| 60 | + [pscustomobject][ordered]@{ |
| 61 | + number = $null |
| 62 | + title = $null |
| 63 | + url = $null |
| 64 | + cachedAtUtc = '2026-03-08T23:51:50.541Z' |
| 65 | + repository = 'LabVIEW-Community-CI-CD/compare-vi-cli-action' |
| 66 | + state = 'NONE' |
| 67 | + labels = @() |
| 68 | + assignees = @() |
| 69 | + milestone = $null |
| 70 | + commentCount = $null |
| 71 | + lastSeenUpdatedAt = $null |
| 72 | + issueDigest = $null |
| 73 | + bodyDigest = $null |
| 74 | + lastFetchSource = 'none' |
| 75 | + lastFetchError = 'No open issues remain in LabVIEW-Community-CI-CD/compare-vi-cli-action; the standing-priority queue is empty.' |
| 76 | + noStandingReason = 'queue-empty' |
| 77 | + noStandingOpenIssueCount = 0 |
| 78 | + } | ConvertTo-Json -Depth 6 | Set-Content -LiteralPath $cachePath -Encoding utf8 |
| 79 | + |
| 80 | + { & $scriptPath -ApplyToggles -ResultsRoot $resultsRoot } | Should -Not -Throw |
| 81 | + |
| 82 | + $handoffDir = Join-Path $resultsRoot '_agent' 'handoff' |
| 83 | + $issueSummaryPath = Join-Path $handoffDir 'issue-summary.json' |
| 84 | + $routerPath = Join-Path $handoffDir 'issue-router.json' |
| 85 | + $sessionPath = Get-ChildItem -LiteralPath (Join-Path $resultsRoot '_agent' 'sessions') -Filter '*.json' | Select-Object -First 1 |
| 86 | + |
| 87 | + Test-Path -LiteralPath $issueSummaryPath | Should -BeTrue |
| 88 | + Test-Path -LiteralPath $routerPath | Should -BeTrue |
| 89 | + $sessionPath | Should -Not -BeNullOrEmpty |
| 90 | + |
| 91 | + $issueSummary = Get-Content -LiteralPath $issueSummaryPath -Raw | ConvertFrom-Json -ErrorAction Stop |
| 92 | + $issueSummary.schema | Should -Be 'standing-priority/no-standing@v1' |
| 93 | + $issueSummary.reason | Should -Be 'queue-empty' |
| 94 | + $issueSummary.openIssueCount | Should -Be 0 |
| 95 | + |
| 96 | + $router = Get-Content -LiteralPath $routerPath -Raw | ConvertFrom-Json -ErrorAction Stop |
| 97 | + $router.issue | Should -Be $null |
| 98 | + @($router.actions).Count | Should -Be 0 |
| 99 | + |
| 100 | + $session = Get-Content -LiteralPath $sessionPath.FullName -Raw | ConvertFrom-Json -ErrorAction Stop |
| 101 | + $session.standingPriority.mode | Should -Be 'queue-empty' |
| 102 | + $session.standingPriority.reason | Should -Be 'queue-empty' |
| 103 | + $session.standingPriority.openIssueCount | Should -Be 0 |
| 104 | + } finally { |
| 105 | + if ((Get-Location).Path -eq $workspaceRoot) { |
| 106 | + Pop-Location |
| 107 | + } |
| 108 | + } |
| 109 | + } |
| 110 | +} |
0 commit comments