Files
ARCADIA-Studio/harness/experiments/scenario-label-fields-11c605f-20260913/original/run.ps1
T

61 lines
5.2 KiB
PowerShell

#Requires -Version 7.0
param([ValidateSet('list','normal','font','timing')][string]$Stage)
$ErrorActionPreference='Stop'
$PSNativeCommandUseErrorActionPreference=$false
$out=Join-Path $PSScriptRoot 'attempt1'
function Get-BoundHash($p){(Get-FileHash -LiteralPath $p -Algorithm SHA256).Hash.ToLowerInvariant()}
function J($p){Get-Content -LiteralPath $p -Raw|ConvertFrom-Json}
function Save($p,$v){$b=[Text.UTF8Encoding]::new($false).GetBytes(($v|ConvertTo-Json -Depth 12)+[Environment]::NewLine);$f=[IO.File]::Open($p,'CreateNew','Write','Read');try{$f.Write($b,0,$b.Length)}finally{$f.Dispose()}}
$receiptPath=Join-Path $out 'build-receipt.json'
$r=J $receiptPath
if($r.exit_code -ne 0 -or -not $r.inputs_unchanged -or $null -ne $r.postflight_failure){throw 'Build did not pass'}
$expectedPath=Join-Path $PSScriptRoot 'expected-tests.json'
$e=J $expectedPath
if($r.source_commit -cne $e.source_commit){throw 'Wrong source'}
$exe=$r.binary.path;$dll=Join-Path $out 'libunwind.dll'
if((Get-BoundHash $exe) -cne $r.binary.sha256 -or (Get-Item $exe).Length -ne $r.binary.bytes -or (Get-BoundHash $dll) -cne $r.runtime_sha256){throw 'Binary or runtime differs from build'}
$manifestPath=Join-Path $out 'inputs-after.json'
if((Get-BoundHash $manifestPath) -cne $r.after_manifest_sha256){throw 'Build capture changed'}
$sourceInputs=@((J $manifestPath)|Where-Object {$_.path -match 'scenario-label-fields-(harness|ytr83r)'})
foreach($s in $sourceInputs){if((Get-BoundHash $s.path) -cne $s.sha256 -or (Get-Item -LiteralPath $s.path).Length -ne $s.bytes){throw ('Source changed: '+$s.path)}}
$prior= switch($Stage){normal{'list'} font{'normal'} timing{'font'} default{$null}}
$paths=@($PSCommandPath,$receiptPath,$manifestPath,$expectedPath,$exe,$dll)+@($sourceInputs.path)
if($prior){$p=Join-Path $out ($prior+'-run-receipt.json');$previous=J $p;if(-not $previous.passed -or $previous.binary_sha256 -cne $r.binary.sha256){throw 'Required previous stage failed'};$paths+=@($p,(Join-Path $out ($prior+'.log')));if((Get-BoundHash $paths[-1]) -cne $previous.log_sha256){throw 'Previous log changed'}}
function Capture {@($paths|Sort-Object -Unique|ForEach-Object {@{path=$_;sha256=(Get-BoundHash $_);bytes=(Get-Item -LiteralPath $_).Length}})}
$before=@(Capture)
$log=Join-Path $out ($Stage+'.log')
$receipt=Join-Path $out ($Stage+'-run-receipt.json')
if((Test-Path $log) -or (Test-Path $receipt)){throw 'Preserve existing run'}
$font='scenario_label::tests::actual_font_load_rejects_retained_label_and_old_session'
$timing='scenario_label::field_tests::field_lookup_4096_scalars_and_combining_heavy_full_coverage'
$argsForExe=switch($Stage){list{@('--list')} normal{@('--test-threads=1','--show-output')} font{@('--exact',$font,'--ignored','--show-output','--test-threads=1')} timing{@('--exact',$timing,'--ignored','--show-output','--test-threads=1')}}
$oldPin=$env:SCENARIO_LABEL_FIELDS_SOURCE_PIN
$start=[DateTime]::UtcNow.ToString('o')
try{if($Stage -eq 'timing'){$env:SCENARIO_LABEL_FIELDS_SOURCE_PIN=$r.source_commit};& $exe @argsForExe *> $log;$code=$LASTEXITCODE}finally{$env:SCENARIO_LABEL_FIELDS_SOURCE_PIN=$oldPin}
$end=[DateTime]::UtcNow.ToString('o')
$failure=$null;$passed=$false;$after=@();$inventory=@();$summary=$null
try{
$after=@(Capture)
if(($before|ConvertTo-Json -Depth 6 -Compress) -cne ($after|ConvertTo-Json -Depth 6 -Compress)){throw 'Run inputs changed'}
$raw=Get-Content -LiteralPath $log -Raw
if($Stage -eq 'list'){
$inventory=@([regex]::Matches($raw,'(?m)^(.+): test\r?$')|ForEach-Object {$_.Groups[1].Value})
if($inventory.Count -ne 25 -or @($inventory|Sort-Object -Unique).Count -ne 25 -or (Compare-Object ($e.tests|Sort-Object) ($inventory|Sort-Object)) -or $raw -notmatch '25 tests, 0 benchmarks'){throw 'Actual test list differs'}
}else{
$rows=@([regex]::Matches($raw,'(?m)^test (.+?) \.\.\. (ok|FAILED|ignored)(?:, [^\r\n]*)?\r?$'))
$inventory=@($rows|ForEach-Object {$_.Groups[1].Value})
$want=switch($Stage){normal{@($e.tests)} font{@($font)} timing{@($timing)}}
if($inventory.Count -ne $want.Count -or (Compare-Object ($want|Sort-Object) ($inventory|Sort-Object))){throw 'Executed membership differs'}
foreach($row in $rows){$status=if($Stage -eq 'normal' -and $row.Groups[1].Value -in $e.isolated){'ignored'}else{'ok'};if($row.Groups[2].Value -cne $status){throw ('Unexpected outcome: '+$row.Value)}}
$summary=[regex]::Match($raw,'test result: ok\. (\d+) passed; (\d+) failed; (\d+) ignored; (\d+) measured; (\d+) filtered out; finished in ([\d.]+)s')
$wantSummary=if($Stage -eq 'normal'){@('23','0','2','0','0')}else{@('1','0','0','0','24')}
if(-not $summary.Success -or (Compare-Object ($summary.Groups[1..5].Value) $wantSummary -SyncWindow 0)){throw 'Unexpected test summary'}
$summary=$summary.Value
}
if($code -ne 0){throw ('Executable exit '+$code)}
$passed=$true
}catch{$failure=$_.Exception.Message}
Save $receipt @{stage=$Stage;source_commit=$r.source_commit;command=@($exe)+$argsForExe;start_utc=$start;end_utc=$end;exit_code=$code;passed=$passed;failure=$failure;binary_sha256=$r.binary.sha256;log_sha256=(Get-BoundHash $log);inventory=$inventory;summary=$summary;before=$before;after=$after;scope='Isolated CPU Iced/Cosmic label checks; no native renderer or navigation acceptance'}
Write-Output ($Stage+': passed='+$passed+'; exit='+$code+'; '+$summary)
if(-not $passed){throw $failure}