Skip to content

Commit 41b5db8

Browse files
author
Agent Runner
committed
feat: prefer live harness lease metadata in loop status (#1905)
1 parent 755c047 commit 41b5db8

2 files changed

Lines changed: 75 additions & 3 deletions

File tree

scripts/Run-AutonomousIntegrationLoop.ps1

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,43 @@ function Get-HarnessInstanceLeaseMetadata {
243243
return [pscustomobject]$metadata
244244
}
245245

246+
function Get-TestStandHarnessSessionMetadata {
247+
param([string]$IterationRoot)
248+
249+
$metadata = [ordered]@{
250+
harnessInstanceId = $null
251+
harnessInstanceLeaseId = $null
252+
harnessInstanceLeasePath = $null
253+
}
254+
255+
if ([string]::IsNullOrWhiteSpace($IterationRoot)) {
256+
return [pscustomobject]$metadata
257+
}
258+
259+
try {
260+
$sessionIndexPath = Join-Path $IterationRoot 'session-index.json'
261+
if (-not (Test-Path -LiteralPath $sessionIndexPath -PathType Leaf)) {
262+
return [pscustomobject]$metadata
263+
}
264+
265+
$payload = Get-Content -LiteralPath $sessionIndexPath -Raw | ConvertFrom-Json -ErrorAction Stop
266+
$harnessInstance = if ($payload -and $payload.PSObject.Properties.Name -contains 'harnessInstance') { $payload.harnessInstance } else { $null }
267+
if ($harnessInstance) {
268+
if ($harnessInstance.PSObject.Properties.Name -contains 'instanceId' -and -not [string]::IsNullOrWhiteSpace($harnessInstance.instanceId)) {
269+
$metadata.harnessInstanceId = [string]$harnessInstance.instanceId
270+
}
271+
if ($harnessInstance.PSObject.Properties.Name -contains 'leaseId' -and -not [string]::IsNullOrWhiteSpace($harnessInstance.leaseId)) {
272+
$metadata.harnessInstanceLeaseId = [string]$harnessInstance.leaseId
273+
}
274+
if ($harnessInstance.PSObject.Properties.Name -contains 'leasePath' -and -not [string]::IsNullOrWhiteSpace($harnessInstance.leasePath)) {
275+
$metadata.harnessInstanceLeasePath = [string]$harnessInstance.leasePath
276+
}
277+
}
278+
} catch {}
279+
280+
return [pscustomobject]$metadata
281+
}
282+
246283
# Defaults / fallbacks
247284
if (-not $MaxIterations) { $MaxIterations = 1 }
248285
if ($null -eq $IntervalSeconds) { $IntervalSeconds = 0 }
@@ -380,6 +417,11 @@ if ($UseTestStandHarness) {
380417
$harnessInstanceLeaseMetadata = Get-HarnessInstanceLeaseMetadata -LeasePath $harnessInstanceLeasePath
381418
$harnessInstanceId = $TestStandHarnessInstanceId
382419
$harnessIteration = [ref]0
420+
$latestHarnessSessionMetadata = [ref]([pscustomobject]@{
421+
harnessInstanceId = $null
422+
harnessInstanceLeaseId = $null
423+
harnessInstanceLeasePath = $null
424+
})
383425

384426
$executor = {
385427
param($CliPath,$BasePath,$HeadPath,$ArgsList)
@@ -434,6 +476,10 @@ if ($UseTestStandHarness) {
434476
try {
435477
& $resolvedHarness @harnessParams | Out-Null
436478
$exitCode = $LASTEXITCODE
479+
$sessionMetadata = Get-TestStandHarnessSessionMetadata -IterationRoot $iterationRoot
480+
if (-not [string]::IsNullOrWhiteSpace($sessionMetadata.harnessInstanceId) -or -not [string]::IsNullOrWhiteSpace($sessionMetadata.harnessInstanceLeaseId) -or -not [string]::IsNullOrWhiteSpace($sessionMetadata.harnessInstanceLeasePath)) {
481+
$latestHarnessSessionMetadata.Value = $sessionMetadata
482+
}
437483
} catch {
438484
Write-JsonEvent 'harnessResult' @{ iteration=$currentIteration; status='exception'; message=$_.Exception.Message }
439485
throw
@@ -682,6 +728,19 @@ try {
682728
}
683729
throw
684730
}
731+
732+
if ($UseTestStandHarness -and $harnessPlan -and $latestHarnessSessionMetadata.Value) {
733+
if (-not [string]::IsNullOrWhiteSpace($latestHarnessSessionMetadata.Value.harnessInstanceId)) {
734+
$harnessPlan.harnessInstanceId = $latestHarnessSessionMetadata.Value.harnessInstanceId
735+
}
736+
if (-not [string]::IsNullOrWhiteSpace($latestHarnessSessionMetadata.Value.harnessInstanceLeaseId)) {
737+
$harnessPlan.harnessInstanceLeaseId = $latestHarnessSessionMetadata.Value.harnessInstanceLeaseId
738+
}
739+
if (-not [string]::IsNullOrWhiteSpace($latestHarnessSessionMetadata.Value.harnessInstanceLeasePath)) {
740+
$harnessPlan.harnessInstanceLeasePath = $latestHarnessSessionMetadata.Value.harnessInstanceLeasePath
741+
}
742+
}
743+
685744
Write-JsonEvent 'result' (@{ iterations=$result.Iterations; diffs=$result.DiffCount; errors=$result.ErrorCount; succeeded=$result.Succeeded })
686745

687746
# Final status JSON emission (independent of run summary JSON produced by loop if that param was set)

tests/Run-AutonomousIntegrationLoop.Tests.ps1

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,19 @@ if (`$logDir -and -not (Test-Path `$logDir)) { New-Item -ItemType Directory -Pat
164164
replaceFlags = `$ReplaceFlags.IsPresent
165165
}
166166
(`$payload | ConvertTo-Json -Compress) | Add-Content -Path `$log
167+
`$sessionIndex = [ordered]@{
168+
schema = 'teststand-compare-session-v1'
169+
harnessInstance = [ordered]@{
170+
instanceId = "session-`$HarnessInstanceId"
171+
leaseId = 'harness-lease-session-hooke-loop-01'
172+
leasePath = (Join-Path `$OutputRoot 'session-harness-lease.json')
173+
}
174+
processModel = [ordered]@{
175+
runtimeSurface = 'windows-native-teststand'
176+
processModelClass = if (`$SuiteClass -eq 'dual-plane-parity') { 'parallel-process-model' } else { 'sequential-process-model' }
177+
}
178+
}
179+
(`$sessionIndex | ConvertTo-Json -Depth 8) | Set-Content -LiteralPath (Join-Path `$OutputRoot 'session-index.json') -Encoding UTF8
167180
if (`$env:HARNESS_EXIT_CODE) { exit [int]`$env:HARNESS_EXIT_CODE }
168181
exit 0
169182
"@
@@ -218,9 +231,9 @@ exit `$LASTEXITCODE
218231
$finalStatus.harness.executionCellLeasePath | Should -Be $leasePath
219232
$finalStatus.harness.executionCellId | Should -Be 'exec-cell-hooke-loop-01'
220233
$finalStatus.harness.executionCellLeaseId | Should -Be 'lease-hooke-loop-01'
221-
$finalStatus.harness.harnessInstanceLeasePath | Should -Be $harnessLeasePath
222-
$finalStatus.harness.harnessInstanceLeaseId | Should -Be 'harness-lease-hooke-loop-01'
223-
$finalStatus.harness.harnessInstanceId | Should -Be 'ts-loop-hooke-01'
234+
$finalStatus.harness.harnessInstanceLeasePath | Should -Be (Join-Path (Join-Path $outputRoot 'iteration-0002') 'session-harness-lease.json')
235+
$finalStatus.harness.harnessInstanceLeaseId | Should -Be 'harness-lease-session-hooke-loop-01'
236+
$finalStatus.harness.harnessInstanceId | Should -Be 'session-ts-loop-hooke-01'
224237
}
225238
finally {
226239
Remove-Item Env:HARNESS_LOG -ErrorAction SilentlyContinue

0 commit comments

Comments
 (0)