Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions scripts/Run-AutonomousIntegrationLoop.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
19 changes: 16 additions & 3 deletions tests/Run-AutonomousIntegrationLoop.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
"@
Expand Down Expand Up @@ -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
Expand Down
Loading