Skip to content

Commit 516d4ab

Browse files
author
Agent Runner
committed
feat: emit loop execution topology events (#1905)
1 parent a7ece27 commit 516d4ab

2 files changed

Lines changed: 68 additions & 4 deletions

File tree

scripts/Run-AutonomousIntegrationLoop.ps1

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -471,17 +471,40 @@ if ($UseTestStandHarness) {
471471
if ($logDir -and -not (Test-Path -LiteralPath $logDir)) { New-Item -ItemType Directory -Path $logDir -Force | Out-Null }
472472
}
473473

474+
$iterationExecutionTopology = [ordered]@{
475+
runtimeSurface = 'windows-native-teststand'
476+
processModelClass = if ($TestStandSuiteClass -eq 'dual-plane-parity') { 'parallel-process-model' } else { 'sequential-process-model' }
477+
windowsOnly = $true
478+
requestedSimultaneous = ($TestStandSuiteClass -eq 'dual-plane-parity')
479+
cellClass = $executionCellLeaseMetadata.cellClass
480+
executionCellLeasePath = $executionCellLeasePath
481+
executionCellId = $executionCellId
482+
executionCellLeaseId = $executionCellLeaseId
483+
harnessInstanceLeasePath = $harnessInstanceLeasePath
484+
harnessInstanceLeaseId = $harnessInstanceLeaseMetadata.leaseId
485+
harnessInstanceId = $harnessInstanceId
486+
}
487+
474488
$exitCode = 0
475-
Write-JsonEvent 'harnessInvoke' @{ iteration=$currentIteration; output=$iterationRoot; status='start' }
489+
Write-JsonEvent 'harnessInvoke' @{ iteration=$currentIteration; output=$iterationRoot; status='start'; executionTopology=$iterationExecutionTopology }
476490
try {
477491
& $resolvedHarness @harnessParams | Out-Null
478492
$exitCode = $LASTEXITCODE
479493
$sessionMetadata = Get-TestStandHarnessSessionMetadata -IterationRoot $iterationRoot
480494
if (-not [string]::IsNullOrWhiteSpace($sessionMetadata.harnessInstanceId) -or -not [string]::IsNullOrWhiteSpace($sessionMetadata.harnessInstanceLeaseId) -or -not [string]::IsNullOrWhiteSpace($sessionMetadata.harnessInstanceLeasePath)) {
481495
$latestHarnessSessionMetadata.Value = $sessionMetadata
496+
if (-not [string]::IsNullOrWhiteSpace($sessionMetadata.harnessInstanceId)) {
497+
$iterationExecutionTopology.harnessInstanceId = $sessionMetadata.harnessInstanceId
498+
}
499+
if (-not [string]::IsNullOrWhiteSpace($sessionMetadata.harnessInstanceLeaseId)) {
500+
$iterationExecutionTopology.harnessInstanceLeaseId = $sessionMetadata.harnessInstanceLeaseId
501+
}
502+
if (-not [string]::IsNullOrWhiteSpace($sessionMetadata.harnessInstanceLeasePath)) {
503+
$iterationExecutionTopology.harnessInstanceLeasePath = $sessionMetadata.harnessInstanceLeasePath
504+
}
482505
}
483506
} catch {
484-
Write-JsonEvent 'harnessResult' @{ iteration=$currentIteration; status='exception'; message=$_.Exception.Message }
507+
Write-JsonEvent 'harnessResult' @{ iteration=$currentIteration; status='exception'; message=$_.Exception.Message; executionTopology=$iterationExecutionTopology }
485508
throw
486509
} finally {
487510
if ($restoreHarnessLog) {
@@ -490,7 +513,7 @@ if ($UseTestStandHarness) {
490513
$env:HARNESS_LOG = $originalHarnessLog
491514
}
492515
}
493-
Write-JsonEvent 'harnessResult' @{ iteration=$currentIteration; exitCode=$exitCode }
516+
Write-JsonEvent 'harnessResult' @{ iteration=$currentIteration; exitCode=$exitCode; executionTopology=$iterationExecutionTopology }
494517
return $exitCode
495518
}
496519
$skipValidation = $false
@@ -697,6 +720,19 @@ if ($UseTestStandHarness -and $harnessPlan) {
697720
$planPayload.harnessRuntimeSurface = $harnessPlan.runtimeSurface
698721
$planPayload.harnessProcessModelClass = $harnessPlan.processModelClass
699722
$planPayload.harnessRequestedSimultaneous = $harnessPlan.requestedSimultaneous
723+
$planPayload.executionTopology = [ordered]@{
724+
runtimeSurface = $harnessPlan.runtimeSurface
725+
processModelClass = $harnessPlan.processModelClass
726+
windowsOnly = $harnessPlan.windowsOnly
727+
requestedSimultaneous = $harnessPlan.requestedSimultaneous
728+
cellClass = $harnessPlan.cellClass
729+
executionCellLeasePath = $harnessPlan.executionCellLeasePath
730+
executionCellId = $harnessPlan.executionCellId
731+
executionCellLeaseId = $harnessPlan.executionCellLeaseId
732+
harnessInstanceLeasePath = $harnessPlan.harnessInstanceLeasePath
733+
harnessInstanceLeaseId = $harnessPlan.harnessInstanceLeaseId
734+
harnessInstanceId = $harnessPlan.harnessInstanceId
735+
}
700736
}
701737
Write-JsonEvent 'plan' $planPayload
702738

@@ -715,6 +751,19 @@ if ($DryRun) {
715751
$dryRunPayload.harnessOutput = $harnessPlan.output
716752
$dryRunPayload.harnessRuntimeSurface = $harnessPlan.runtimeSurface
717753
$dryRunPayload.harnessProcessModelClass = $harnessPlan.processModelClass
754+
$dryRunPayload.executionTopology = [ordered]@{
755+
runtimeSurface = $harnessPlan.runtimeSurface
756+
processModelClass = $harnessPlan.processModelClass
757+
windowsOnly = $harnessPlan.windowsOnly
758+
requestedSimultaneous = $harnessPlan.requestedSimultaneous
759+
cellClass = $harnessPlan.cellClass
760+
executionCellLeasePath = $harnessPlan.executionCellLeasePath
761+
executionCellId = $harnessPlan.executionCellId
762+
executionCellLeaseId = $harnessPlan.executionCellLeaseId
763+
harnessInstanceLeasePath = $harnessPlan.harnessInstanceLeasePath
764+
harnessInstanceLeaseId = $harnessPlan.harnessInstanceLeaseId
765+
harnessInstanceId = $harnessPlan.harnessInstanceId
766+
}
718767
}
719768
Write-JsonEvent 'dryRun' $dryRunPayload
720769
Set-LoopExit 0

tests/Run-AutonomousIntegrationLoop.Tests.ps1

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ Describe 'Run-AutonomousIntegrationLoop TestStand harness mode' -Tag 'Unit' {
108108

109109
$harnessStub = Join-Path $outDir 'TestStand-CompareHarness.ps1'
110110
$logPath = Join-Path $outDir 'harness-log.ndjson'
111+
$jsonLogPath = Join-Path $outDir 'loop.events.json'
111112
$outputRoot = Join-Path $outDir 'outputs'
112113
$stubContent = @"
113114
param(
@@ -186,7 +187,7 @@ exit 0
186187
try {
187188
$runner = Join-Path $outDir 'runner-harness.ps1'
188189
$runnerContent = @"
189-
& '$scriptPath' -Base '$base' -Head '$head' -MaxIterations 2 -IntervalSeconds 0 -LogVerbosity Quiet -LvCompareArgs '-foo 1 -bar' -UseTestStandHarness -TestStandHarnessPath '$harnessStub' -TestStandOutputRoot '$outputRoot' -TestStandWarmup detect -TestStandSuiteClass dual-plane-parity -TestStandLabVIEW64Path 'C:\Program Files\National Instruments\LabVIEW 2026\LabVIEW.exe' -TestStandLabVIEW32Path 'C:\Program Files (x86)\National Instruments\LabVIEW 2026\LabVIEW.exe' -TestStandAgentId 'hooke' -TestStandAgentClass 'subagent' -TestStandExecutionCellLeasePath '$leasePath' -TestStandExecutionCellId 'exec-cell-hooke-loop-01' -TestStandExecutionCellLeaseId 'lease-hooke-loop-01' -TestStandHarnessInstanceLeasePath '$harnessLeasePath' -TestStandHarnessInstanceId 'ts-loop-hooke-01' -TestStandRenderReport -TestStandCloseLabVIEW -TestStandCloseLVCompare -TestStandTimeoutSeconds 45 -TestStandReplaceFlags -FinalStatusJsonPath '$outDir/final.json'
190+
& '$scriptPath' -Base '$base' -Head '$head' -MaxIterations 2 -IntervalSeconds 0 -LogVerbosity Quiet -JsonLogPath '$jsonLogPath' -LvCompareArgs '-foo 1 -bar' -UseTestStandHarness -TestStandHarnessPath '$harnessStub' -TestStandOutputRoot '$outputRoot' -TestStandWarmup detect -TestStandSuiteClass dual-plane-parity -TestStandLabVIEW64Path 'C:\Program Files\National Instruments\LabVIEW 2026\LabVIEW.exe' -TestStandLabVIEW32Path 'C:\Program Files (x86)\National Instruments\LabVIEW 2026\LabVIEW.exe' -TestStandAgentId 'hooke' -TestStandAgentClass 'subagent' -TestStandExecutionCellLeasePath '$leasePath' -TestStandExecutionCellId 'exec-cell-hooke-loop-01' -TestStandExecutionCellLeaseId 'lease-hooke-loop-01' -TestStandHarnessInstanceLeasePath '$harnessLeasePath' -TestStandHarnessInstanceId 'ts-loop-hooke-01' -TestStandRenderReport -TestStandCloseLabVIEW -TestStandCloseLVCompare -TestStandTimeoutSeconds 45 -TestStandReplaceFlags -FinalStatusJsonPath '$outDir/final.json'
190191
exit `$LASTEXITCODE
191192
"@
192193
Set-Content -LiteralPath $runner -Encoding UTF8 -Value $runnerContent
@@ -217,6 +218,20 @@ exit `$LASTEXITCODE
217218
$entries | ForEach-Object { $_.replaceFlags } | Sort-Object -Unique | Should -Be @($true)
218219
$entries | ForEach-Object { $_.flags } | ForEach-Object { $_ } | Sort-Object -Unique | Should -Be @('-bar','-foo','1')
219220

221+
$eventEntries = Get-Content -LiteralPath $jsonLogPath | ForEach-Object { $_ | ConvertFrom-Json }
222+
$planEvent = $eventEntries | Where-Object { $_.type -eq 'plan' } | Select-Object -First 1
223+
$planEvent.executionTopology.runtimeSurface | Should -Be 'windows-native-teststand'
224+
$planEvent.executionTopology.processModelClass | Should -Be 'parallel-process-model'
225+
$planEvent.executionTopology.executionCellLeaseId | Should -Be 'lease-hooke-loop-01'
226+
$planEvent.executionTopology.harnessInstanceLeaseId | Should -Be 'harness-lease-hooke-loop-01'
227+
$planEvent.executionTopology.harnessInstanceId | Should -Be 'ts-loop-hooke-01'
228+
229+
$lastHarnessResult = $eventEntries | Where-Object { $_.type -eq 'harnessResult' -and $_.PSObject.Properties.Name -contains 'exitCode' } | Select-Object -Last 1
230+
$lastHarnessResult.executionTopology.executionCellLeaseId | Should -Be 'lease-hooke-loop-01'
231+
$lastHarnessResult.executionTopology.harnessInstanceLeaseId | Should -Be 'harness-lease-session-hooke-loop-01'
232+
$lastHarnessResult.executionTopology.harnessInstanceLeasePath | Should -Be (Join-Path (Join-Path $outputRoot 'iteration-0002') 'session-harness-lease.json')
233+
$lastHarnessResult.executionTopology.harnessInstanceId | Should -Be 'session-ts-loop-hooke-01'
234+
220235
$finalStatus = Get-Content -LiteralPath (Join-Path $outDir 'final.json') -Raw | ConvertFrom-Json
221236
$finalStatus.harness.path | Should -Be $harnessStub
222237
$finalStatus.harness.output | Should -Be $outputRoot

0 commit comments

Comments
 (0)