Files
ARCADIA-Studio/harness/experiments/scenario-validation-focused-b10b28c-20260913/original/batch-helpers.ps1
T

27 lines
3.1 KiB
PowerShell

# Pure batch inventory/result checks; this file never starts an executable.
function Read-BatchResults([string]$Text) {
$rows=@([regex]::Matches($Text,'(?m)^test ([^\r\n]+?) \.\.\. (ok|FAILED|ignored)[^\r\n]*\r?$')|ForEach-Object {[ordered]@{name=$_.Groups[1].Value;result=$_.Groups[2].Value}})
$summaries=@([regex]::Matches($Text,'(?m)^test result: (ok|FAILED)\. (\d+) passed; (\d+) failed; (\d+) ignored; (\d+) measured; (\d+) filtered out; finished in ([\d.]+)s\r?$')|ForEach-Object {[ordered]@{status=$_.Groups[1].Value;passed=[int]$_.Groups[2].Value;failed=[int]$_.Groups[3].Value;ignored=[int]$_.Groups[4].Value;measured=[int]$_.Groups[5].Value;filtered=[int]$_.Groups[6].Value;seconds=$_.Groups[7].Value}})
[ordered]@{executedTests=$rows;testResultSummaries=$summaries}
}
function Assert-ExactBatch($Batch,$Result,[int]$DesktopCount) {
$wanted=@($Batch.tests);$actual=@($Result.executedTests|ForEach-Object {$_.name})
if($wanted.Count -eq 0 -or @($wanted|Sort-Object -Unique).Count -ne $wanted.Count -or $actual.Count -ne $wanted.Count -or @($actual|Sort-Object -Unique).Count -ne $actual.Count -or (Compare-Object $wanted $actual -CaseSensitive)){throw 'Batch membership is not exact and unique'}
if(@($Result.executedTests|Where-Object {$_.result -cne 'ok'}).Count -or @($Result.testResultSummaries).Count -ne 1){throw 'Batch contains failed/ignored tests or wrong summary count'}
$s=$Result.testResultSummaries[0]
if($s.status -cne 'ok' -or $s.passed -ne $wanted.Count -or $s.failed -ne 0 -or $s.ignored -ne 0 -or $s.measured -ne 0 -or $s.filtered -ne ($DesktopCount-$wanted.Count)){throw 'Batch summary differs from exact selection'}
}
function Assert-BatchPlan($Plan,$Expected,[string]$CargoPath) {
if($Plan.schema -cne 'scenario_details_exact_batches_v1' -or $Plan.source_commit -cne 'b10b28cefd1d0794073ba241a0c8de9a83e85f68' -or $Plan.focused_count -ne 301 -or $Plan.desktop_count -ne 1095 -or $Plan.max_command_characters -ne 12000 -or $Plan.cargo_path -ine $CargoPath){throw 'Wrong batch plan identity or bound'}
if((Compare-Object @('test','-p','oa-desktop','--bin','arcadia-studio','--locked','--offline','--','--exact') @($Plan.base_arguments) -SyncWindow 0) -or (Compare-Object @('--test-threads=1') @($Plan.tail_arguments) -SyncWindow 0)){throw 'Unexpected batch arguments'}
$union=@();$index=0
foreach($batch in $Plan.batches){
$index++;if($batch.id -cne ('focused-batch{0:d2}' -f $index)){throw 'Unexpected batch identity/order'}
$args=@($Plan.base_arguments)+@($batch.tests)+@($Plan.tail_arguments)
$length=0;foreach($arg in @($CargoPath)+$args){$length+=$arg.Length+3}
if($length -gt 12000 -or $length -ne $batch.command_characters -or $batch.expected_passed -ne @($batch.tests).Count -or $batch.expected_filtered -ne (1095-@($batch.tests).Count) -or @($batch.tests|Where-Object {$_ -cnotmatch '^[A-Za-z0-9_:]+$'}).Count){throw 'Unsafe or inconsistent batch arguments'}
$union+=@($batch.tests)
}
if($union.Count -ne 301 -or @($union|Sort-Object -Unique).Count -ne 301 -or (Compare-Object @($Expected) $union -CaseSensitive)){throw 'Batch union is not exactly301 unique selected tests'}
}