Files
ARCADIA-Studio/harness/experiments/scenario-comparators-gui-b10b28c-20260913/details/validate-scripts.ps1
T

54 lines
5.2 KiB
PowerShell

#Requires -Version 7.0
$ErrorActionPreference='Stop'
$records=@(foreach($name in @('build.ps1','check.ps1','validate-scripts.ps1')){
$path=Join-Path $PSScriptRoot $name;$tokens=$null;$errors=$null
[void][Management.Automation.Language.Parser]::ParseFile($path,[ref]$tokens,[ref]$errors)
if(@($errors).Count){throw ($errors|Out-String)}
[ordered]@{path=$name;bytes=(Get-Item -LiteralPath $path).Length;sha256=(Get-FileHash -LiteralPath $path -Algorithm SHA256).Hash.ToLowerInvariant()}
})
# Load only the three pure guard definitions from the actual builder AST.
$tokens=$null;$errors=$null
$ast=[Management.Automation.Language.Parser]::ParseFile((Join-Path $PSScriptRoot 'build.ps1'),[ref]$tokens,[ref]$errors)
foreach($name in @('Assert-ReviewedHash','Assert-ListPreparation','Select-SourceRecords')){
$nodes=@($ast.FindAll({param($n)$n -is [Management.Automation.Language.FunctionDefinitionAst] -and $n.Name -ceq $name},$true))
if($nodes.Count -ne 1){throw 'Pure guard definition missing/ambiguous'}
. ([scriptblock]::Create($nodes[0].Extent.Text))
}
$pin='b10b28cefd1d0794073ba241a0c8de9a83e85f68'
$expectedPath=(Resolve-Path -LiteralPath (Join-Path $PSScriptRoot '../scenario-validation-gates-b10b28c-20260913/expected-inputs.json')).Path
$actualExpected=Get-Content -Raw -LiteralPath $expectedPath|ConvertFrom-Json
$expectedHash=(Get-FileHash -LiteralPath $expectedPath -Algorithm SHA256).Hash.ToLowerInvariant()
$actualList=Get-Content -Raw -LiteralPath (Join-Path (Split-Path -Parent $expectedPath) 'list-receipt.json')|ConvertFrom-Json
if($actualList.boundScriptAndInputHashes.'expected-inputs.json' -cne $expectedHash){throw 'Actual expected-inputs schema example is not LIST-bound'}
$good=[ordered]@{reference=@{base=$pin;stage='list';cargoExitCode=0;selectionValid=$true;inputsUnchanged=$true;testBinaryBindingValid=$true;postflightFailure=$null;listSummaries=@(@{tests=1095;benchmarks=0})};selection=@{source_commit=$pin;expected_desktop_count=1095;expected_count=301};expected=$actualExpected}
$json=$good|ConvertTo-Json -Depth 8
Assert-ListPreparation $good.reference $good.selection $good.expected
Assert-ReviewedHash ('a'*64) ('a'*64)
$sourcePaths=@('C:\probe\main.rs','C:\probe\fixtures\incident.arcadia')
$sourceRecords=@($sourcePaths|ForEach-Object {[pscustomobject]@{path=$_;bytes=1;sha256=('0'*64)}})
if(@(Select-SourceRecords $sourceRecords $sourcePaths).Count -ne 2){throw 'Canonical source selection failed'}
$cases=@(
@{name='old_source';mutate={param($v)$v.reference.base='8bf7607a3f3b53db0c36364f54f57674c64ea2f1'}},
@{name='not_list';mutate={param($v)$v.reference.stage='clippy'}},
@{name='failed_list';mutate={param($v)$v.reference.cargoExitCode=1}},
@{name='changed_inputs';mutate={param($v)$v.reference.inputsUnchanged=$false}},
@{name='missing_binary_binding';mutate={param($v)$v.reference.testBinaryBindingValid=$false}},
@{name='postflight_failure';mutate={param($v)$v.reference.postflightFailure='changed'}},
@{name='old_desktop_count';mutate={param($v)$v.selection.expected_desktop_count=1089}},
@{name='old_focused_count';mutate={param($v)$v.selection.expected_count=295}},
@{name='old_source_count';mutate={param($v)$v.expected.count=611}},
@{name='missing_source_record';mutate={param($v)$v.expected.files=@($v.expected.files|Select-Object -First 611)}},
@{name='extra_source_record';mutate={param($v)$v.expected.files=@($v.expected.files)+@($v.expected.files[0])}},
@{name='wrong_expected_source';mutate={param($v)$v.expected.base=('0'*40)}},
@{name='wrong_actual_listing';mutate={param($v)$v.reference.listSummaries[0].tests=1094}}
)
$rejections=@();foreach($case in $cases){$v=$json|ConvertFrom-Json;& $case.mutate $v;$rejected=$false;try{Assert-ListPreparation $v.reference $v.selection $v.expected}catch{$rejected=$true};if(-not $rejected){throw ('Admitted '+$case.name)};$rejections+=@($case.name)}
foreach($hashes in @(@{actual=('b'*64);expected=('a'*64)},@{actual=('a'*64);expected=''})){
$rejected=$false;try{Assert-ReviewedHash $hashes.actual $hashes.expected}catch{$rejected=$true};if(-not $rejected){throw 'Unreviewed artifact hash admitted'};$rejections+=@('wrong_or_missing_reviewed_hash')
}
$badRecords=@([pscustomobject]@{path='C:\probe\main.rs';bytes=1;sha256=('0'*64)},[pscustomobject]@{path='C:\probe\oracle\..\fixtures\incident.arcadia';bytes=1;sha256=('0'*64)})
foreach($case in @(@{name='missing_fixture';rows=@($sourceRecords[0])},@{name='uncanonical_fixture';rows=$badRecords},@{name='duplicate_fixture';rows=(@($sourceRecords)+@($sourceRecords[1]))})){
$rejected=$false;try{Select-SourceRecords $case.rows $sourcePaths|Out-Null}catch{$rejected=$true};if(-not $rejected){throw ('Admitted '+$case.name)};$rejections+=@($case.name)
}
[ordered]@{status='passed';scripts=$records;positive_cases=3;negative_cases=$rejections;actual_expected_inputs=@{path=$expectedPath;sha256=$expectedHash;base=$actualExpected.base;count=$actualExpected.count;file_count=@($actualExpected.files).Count};compiler_executed=$false;oracle_executed=$false;gate_admitted=$false;scope='AST and actual pure builder guards only, with synthetic metadata. Actual LIST-bound expected-inputs schema read; no full gate/fingerprint selection or source admission executed.'}|ConvertTo-Json -Depth 8