@@ -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
247284if (-not $MaxIterations ) { $MaxIterations = 1 }
248285if ($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+
685744Write-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)
0 commit comments