From 41b5db8298cc992da1250cfc38a16d6c61dfedfb Mon Sep 17 00:00:00 2001 From: Agent Runner Date: Tue, 24 Mar 2026 05:19:42 -0700 Subject: [PATCH] feat: prefer live harness lease metadata in loop status (#1905) --- scripts/Run-AutonomousIntegrationLoop.ps1 | 59 +++++++++++++++++++ tests/Run-AutonomousIntegrationLoop.Tests.ps1 | 19 +++++- 2 files changed, 75 insertions(+), 3 deletions(-) diff --git a/scripts/Run-AutonomousIntegrationLoop.ps1 b/scripts/Run-AutonomousIntegrationLoop.ps1 index a18c1813a..083a9ce9c 100644 --- a/scripts/Run-AutonomousIntegrationLoop.ps1 +++ b/scripts/Run-AutonomousIntegrationLoop.ps1 @@ -243,6 +243,43 @@ function Get-HarnessInstanceLeaseMetadata { return [pscustomobject]$metadata } +function Get-TestStandHarnessSessionMetadata { + param([string]$IterationRoot) + + $metadata = [ordered]@{ + harnessInstanceId = $null + harnessInstanceLeaseId = $null + harnessInstanceLeasePath = $null + } + + if ([string]::IsNullOrWhiteSpace($IterationRoot)) { + return [pscustomobject]$metadata + } + + try { + $sessionIndexPath = Join-Path $IterationRoot 'session-index.json' + if (-not (Test-Path -LiteralPath $sessionIndexPath -PathType Leaf)) { + return [pscustomobject]$metadata + } + + $payload = Get-Content -LiteralPath $sessionIndexPath -Raw | ConvertFrom-Json -ErrorAction Stop + $harnessInstance = if ($payload -and $payload.PSObject.Properties.Name -contains 'harnessInstance') { $payload.harnessInstance } else { $null } + if ($harnessInstance) { + if ($harnessInstance.PSObject.Properties.Name -contains 'instanceId' -and -not [string]::IsNullOrWhiteSpace($harnessInstance.instanceId)) { + $metadata.harnessInstanceId = [string]$harnessInstance.instanceId + } + if ($harnessInstance.PSObject.Properties.Name -contains 'leaseId' -and -not [string]::IsNullOrWhiteSpace($harnessInstance.leaseId)) { + $metadata.harnessInstanceLeaseId = [string]$harnessInstance.leaseId + } + if ($harnessInstance.PSObject.Properties.Name -contains 'leasePath' -and -not [string]::IsNullOrWhiteSpace($harnessInstance.leasePath)) { + $metadata.harnessInstanceLeasePath = [string]$harnessInstance.leasePath + } + } + } catch {} + + return [pscustomobject]$metadata +} + # Defaults / fallbacks if (-not $MaxIterations) { $MaxIterations = 1 } if ($null -eq $IntervalSeconds) { $IntervalSeconds = 0 } @@ -380,6 +417,11 @@ if ($UseTestStandHarness) { $harnessInstanceLeaseMetadata = Get-HarnessInstanceLeaseMetadata -LeasePath $harnessInstanceLeasePath $harnessInstanceId = $TestStandHarnessInstanceId $harnessIteration = [ref]0 + $latestHarnessSessionMetadata = [ref]([pscustomobject]@{ + harnessInstanceId = $null + harnessInstanceLeaseId = $null + harnessInstanceLeasePath = $null + }) $executor = { param($CliPath,$BasePath,$HeadPath,$ArgsList) @@ -434,6 +476,10 @@ if ($UseTestStandHarness) { try { & $resolvedHarness @harnessParams | Out-Null $exitCode = $LASTEXITCODE + $sessionMetadata = Get-TestStandHarnessSessionMetadata -IterationRoot $iterationRoot + if (-not [string]::IsNullOrWhiteSpace($sessionMetadata.harnessInstanceId) -or -not [string]::IsNullOrWhiteSpace($sessionMetadata.harnessInstanceLeaseId) -or -not [string]::IsNullOrWhiteSpace($sessionMetadata.harnessInstanceLeasePath)) { + $latestHarnessSessionMetadata.Value = $sessionMetadata + } } catch { Write-JsonEvent 'harnessResult' @{ iteration=$currentIteration; status='exception'; message=$_.Exception.Message } throw @@ -682,6 +728,19 @@ try { } throw } + +if ($UseTestStandHarness -and $harnessPlan -and $latestHarnessSessionMetadata.Value) { + if (-not [string]::IsNullOrWhiteSpace($latestHarnessSessionMetadata.Value.harnessInstanceId)) { + $harnessPlan.harnessInstanceId = $latestHarnessSessionMetadata.Value.harnessInstanceId + } + if (-not [string]::IsNullOrWhiteSpace($latestHarnessSessionMetadata.Value.harnessInstanceLeaseId)) { + $harnessPlan.harnessInstanceLeaseId = $latestHarnessSessionMetadata.Value.harnessInstanceLeaseId + } + if (-not [string]::IsNullOrWhiteSpace($latestHarnessSessionMetadata.Value.harnessInstanceLeasePath)) { + $harnessPlan.harnessInstanceLeasePath = $latestHarnessSessionMetadata.Value.harnessInstanceLeasePath + } +} + Write-JsonEvent 'result' (@{ iterations=$result.Iterations; diffs=$result.DiffCount; errors=$result.ErrorCount; succeeded=$result.Succeeded }) # Final status JSON emission (independent of run summary JSON produced by loop if that param was set) diff --git a/tests/Run-AutonomousIntegrationLoop.Tests.ps1 b/tests/Run-AutonomousIntegrationLoop.Tests.ps1 index 5444caca5..7e14f99de 100644 --- a/tests/Run-AutonomousIntegrationLoop.Tests.ps1 +++ b/tests/Run-AutonomousIntegrationLoop.Tests.ps1 @@ -164,6 +164,19 @@ if (`$logDir -and -not (Test-Path `$logDir)) { New-Item -ItemType Directory -Pat replaceFlags = `$ReplaceFlags.IsPresent } (`$payload | ConvertTo-Json -Compress) | Add-Content -Path `$log +`$sessionIndex = [ordered]@{ + schema = 'teststand-compare-session-v1' + harnessInstance = [ordered]@{ + instanceId = "session-`$HarnessInstanceId" + leaseId = 'harness-lease-session-hooke-loop-01' + leasePath = (Join-Path `$OutputRoot 'session-harness-lease.json') + } + processModel = [ordered]@{ + runtimeSurface = 'windows-native-teststand' + processModelClass = if (`$SuiteClass -eq 'dual-plane-parity') { 'parallel-process-model' } else { 'sequential-process-model' } + } +} +(`$sessionIndex | ConvertTo-Json -Depth 8) | Set-Content -LiteralPath (Join-Path `$OutputRoot 'session-index.json') -Encoding UTF8 if (`$env:HARNESS_EXIT_CODE) { exit [int]`$env:HARNESS_EXIT_CODE } exit 0 "@ @@ -218,9 +231,9 @@ exit `$LASTEXITCODE $finalStatus.harness.executionCellLeasePath | Should -Be $leasePath $finalStatus.harness.executionCellId | Should -Be 'exec-cell-hooke-loop-01' $finalStatus.harness.executionCellLeaseId | Should -Be 'lease-hooke-loop-01' - $finalStatus.harness.harnessInstanceLeasePath | Should -Be $harnessLeasePath - $finalStatus.harness.harnessInstanceLeaseId | Should -Be 'harness-lease-hooke-loop-01' - $finalStatus.harness.harnessInstanceId | Should -Be 'ts-loop-hooke-01' + $finalStatus.harness.harnessInstanceLeasePath | Should -Be (Join-Path (Join-Path $outputRoot 'iteration-0002') 'session-harness-lease.json') + $finalStatus.harness.harnessInstanceLeaseId | Should -Be 'harness-lease-session-hooke-loop-01' + $finalStatus.harness.harnessInstanceId | Should -Be 'session-ts-loop-hooke-01' } finally { Remove-Item Env:HARNESS_LOG -ErrorAction SilentlyContinue