Files
ARCADIA-Studio/harness/experiments/scenario-details-focused-8bf7607-20260913/original/diagnostic.ps1
T

70 lines
6.7 KiB
PowerShell

#Requires -Version 7.0
# Optional after full acceptance; invokes the bound test executable, never Cargo.
Set-StrictMode -Version Latest
$ErrorActionPreference='Stop'
$PSNativeCommandUseErrorActionPreference=$false
$taskPin='8bf7607a3f3b53db0c36364f54f57674c64ea2f1'
if($taskPin -notmatch '^[0-9a-f]{40}$'){throw 'Finalize the reviewed source first.'}
$taskWorkspace='C:/Users/User/Documents/Git/ARCADIA-Studio/.local/scenario-spacing-ytr83r-20260913'
$taskTarget='C:/Users/User/Documents/Git/ARCADIA-Studio/target'
function Hash-Input([string]$Path){(Get-FileHash -LiteralPath $Path -Algorithm SHA256).Hash.ToLowerInvariant()}
. (Join-Path $PSScriptRoot 'binary-inputs.ps1')
$log=Join-Path $PSScriptRoot 'diagnostic.log'
$receiptPath=Join-Path $PSScriptRoot 'diagnostic-receipt.json'
if((Test-Path -LiteralPath $log)-or(Test-Path -LiteralPath $receiptPath)){throw 'Preserve existing diagnostic evidence.'}
$priorPath=Join-Path $PSScriptRoot 'all-receipt.json'
$prior=Get-Content -Raw -LiteralPath $priorPath|ConvertFrom-Json
if($prior.stage -cne 'all' -or $prior.base -cne $taskPin -or $prior.workspace.Replace('\','/') -cne $taskWorkspace -or $prior.target.Replace('\','/') -cne $taskTarget -or $prior.cargoExitCode -ne 0 -or -not $prior.selectionValid -or -not $prior.inputsUnchanged -or -not $prior.testBinaryBindingValid){throw 'The exact full stage has not passed.'}
$bound=@{}
foreach($property in $prior.boundScriptAndInputHashes.PSObject.Properties){
$hash=Hash-Input (Join-Path $PSScriptRoot $property.Name)
if($hash -cne $property.Value){throw ('Prior binding changed: '+$property.Name)}
$bound[$property.Name]=$hash
}
foreach($name in @('all-receipt.json','all.log','toolchain-versions.json')){$bound[$name]=Hash-Input (Join-Path $PSScriptRoot $name)}
if($bound['all.log'] -cne $prior.rawLogSha256 -or $bound['toolchain-versions.json'] -cne $prior.toolchainVersionsSha256){throw 'Full log/toolchain receipt changed.'}
if(-not $bound.ContainsKey('diagnostic.ps1')){throw 'Diagnostic recipe was not bound by the full gate.'}
$selection=Get-Content -Raw -LiteralPath (Join-Path $PSScriptRoot 'expected-tests.json')|ConvertFrom-Json
$name=$selection.diagnostic_test
if($selection.source_commit -cne $taskPin -or $name -cnotin $selection.ignored_tests -or $name -cnotin $selection.desktop_tests -or $name -cin $selection.tests){throw 'Wrong ignored diagnostic membership.'}
$binaries=@($prior.testExecutables|ForEach-Object {Get-GateBinary $_.path $taskTarget})
if($binaries.Count -ne 1 -or -not (Same-GateBinaries @($prior.testExecutables) $binaries)){throw 'Previously listed test executable changed.'}
& (Join-Path $PSScriptRoot 'capture.ps1') -Stage diagnostic-before
$arguments=@('--exact',$name,'--ignored','--nocapture','--test-threads=1')
$started=[DateTime]::UtcNow.ToString('o')
$exitCode=$null;$finished=$null;$failure=$null;$valid=$false;$unchanged=$false;$after=@();$summaries=@();$payload=$null
$hadSourcePin=Test-Path Env:SCENARIO_SPACING_SOURCE_PIN
$previousSourcePin=$env:SCENARIO_SPACING_SOURCE_PIN
Push-Location -LiteralPath $taskWorkspace
try {
. 'C:/Users/User/Documents/Git/ARCADIA-Studio/.local/toolchain/env.ps1'
$env:SCENARIO_SPACING_SOURCE_PIN=$taskPin
$executable=$binaries[0].path
& $executable @arguments 2>&1|Tee-Object -FilePath $log
$exitCode=$LASTEXITCODE
$finished=[DateTime]::UtcNow.ToString('o')
$raw=Get-Content -Raw -LiteralPath $log
$startedNames=@([regex]::Matches($raw,'(?m)^test ([^\r\n]+?) \.\.\. ')|ForEach-Object {$_.Groups[1].Value})
$summaries=@([regex]::Matches($raw,'test result: (ok|FAILED)\. (\d+) passed; (\d+) failed; (\d+) ignored; (\d+) measured; (\d+) filtered out;')|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}})
$json=@([regex]::Matches($raw,'SPACING_TIMING_JSON=(\{[^\r\n]+\})'))
if($json.Count -eq 1){$payload=$json[0].Groups[1].Value|ConvertFrom-Json}
$valid=$exitCode -eq 0 -and $startedNames.Count -eq 1 -and $startedNames[0] -ceq $name -and $summaries.Count -eq 1 -and $summaries[0].status -ceq 'ok' -and $summaries[0].passed -eq 1 -and $summaries[0].failed -eq 0 -and $summaries[0].ignored -eq 0 -and $summaries[0].measured -eq 0 -and $summaries[0].filtered -eq (@($selection.desktop_tests).Count-1) -and $null -ne $payload -and $payload.invariant_status -ceq 'passed'
if($valid){
$valid=$payload.schema -ceq 'scenario_spacing_timing_v1' -and $payload.profile_context.source_pin_from_runner -ceq $taskPin -and $payload.fixture.lanes -eq 20 -and $payload.fixture.messages -eq 1000 -and $payload.fixture.saved_views -eq 3 -and $payload.fixture.target_index -eq 500 -and $payload.fixture.distinct_message_ids -eq 1000 -and @($payload.samples).Count -eq 28
foreach($phase in @(@('capture_message',4),@('prepare_message',20),@('capture_lane',1),@('prepare_lane',3))){$valid=$valid -and @($payload.samples|Where-Object phase -CEQ $phase[0]).Count -eq $phase[1]}
}
} catch {$failure=$_.Exception.Message}
finally {
if($hadSourcePin){$env:SCENARIO_SPACING_SOURCE_PIN=$previousSourcePin}else{Remove-Item Env:SCENARIO_SPACING_SOURCE_PIN -ErrorAction SilentlyContinue}
Pop-Location
try {
& (Join-Path $PSScriptRoot 'capture.ps1') -Stage diagnostic-after
$after=@($binaries|ForEach-Object {Get-GateBinary $_.path $taskTarget})
if(-not (Same-GateBinaries $binaries $after)){throw 'Diagnostic executable changed during execution.'}
foreach($file in $bound.Keys){if((Hash-Input (Join-Path $PSScriptRoot $file)) -cne $bound[$file]){throw ('Bound input changed: '+$file)}}
$unchanged=$true
} catch {$failure=$_.Exception.Message}
[ordered]@{stage='diagnostic';base=$taskPin;workspace=$taskWorkspace;test=$name;arguments=$arguments;startUtc=$started;endUtc=$finished;exitCode=$exitCode;selectionValid=$valid;inputsUnchanged=$unchanged;failure=$failure;priorFullReceiptSha256=$bound['all-receipt.json'];boundHashes=$bound;binaryBefore=$binaries;binaryAfter=$after;summary=$summaries;timing=$payload;rawLogSha256=if(Test-Path -LiteralPath $log){Hash-Input $log}else{$null};beforeCaptureSha256=(Hash-Input (Join-Path $PSScriptRoot 'inputs-complete-diagnostic-before.json'));afterCaptureSha256=if(Test-Path -LiteralPath (Join-Path $PSScriptRoot 'inputs-complete-diagnostic-after.json')){Hash-Input (Join-Path $PSScriptRoot 'inputs-complete-diagnostic-after.json')}else{$null};scope='Optional debug-profile diagnostic; not a responsiveness budget or release performance claim. No Cargo, compile, native UI or persistent model edits.'}|ConvertTo-Json -Depth 16|Set-Content -LiteralPath $receiptPath -Encoding utf8
}
if(-not $valid -or -not $unchanged -or $failure){throw 'Diagnostic failed; inspect retained receipt and raw log.'}