48 lines
5.5 KiB
PowerShell
48 lines
5.5 KiB
PowerShell
#Requires -Version 7.0
|
|
Set-StrictMode -Version Latest
|
|
$ErrorActionPreference='Stop'
|
|
$PSNativeCommandUseErrorActionPreference=$false
|
|
$pin='83e840e37f3c3d230382722e99e87bf865abb12e'
|
|
function Hash([string]$Path){(Get-FileHash -LiteralPath $Path -Algorithm SHA256).Hash.ToLowerInvariant()}
|
|
function Assert-Files($Files){foreach($f in $Files){$item=Get-Item -LiteralPath $f.path;if($item.Length -ne $f.bytes -or (Hash $f.path) -cne $f.sha256){throw ('Bound file changed: '+$f.path)}}}
|
|
function Same-Names($A,$B){$a1=@($A|Sort-Object);$b1=@($B|Sort-Object);return $a1.Count -eq $b1.Count -and @(Compare-Object $a1 $b1).Count -eq 0}
|
|
function Parse-Focused([string]$Text,$Expected,[int]$Filtered){
|
|
$executed=@([regex]::Matches($Text,'(?m)^test ([^\r\n]+?) \.\.\. (ok|FAILED|ignored)\r?$')|ForEach-Object {[ordered]@{name=$_.Groups[1].Value;result=$_.Groups[2].Value}})
|
|
$summaries=@([regex]::Matches($Text,'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}})
|
|
$valid=$executed.Count -eq 224 -and $summaries.Count -eq 1 -and (Same-Names @($executed|ForEach-Object{$_.name}) $Expected) -and @($executed|Where-Object{$_.result -cne 'ok'}).Count -eq 0
|
|
if($summaries.Count -eq 1){$s=$summaries[0];$valid=$valid -and $s.status -ceq 'ok' -and $s.passed -eq 224 -and $s.failed -eq 0 -and $s.ignored -eq 0 -and $s.measured -eq 0 -and $s.filtered -eq $Filtered}
|
|
return [pscustomobject]@{valid=$valid;executed=$executed;summaries=$summaries}
|
|
}
|
|
$log=Join-Path $PSScriptRoot 'focused.log';$receiptPath=Join-Path $PSScriptRoot 'focused-receipt.json'
|
|
foreach($name in @('focused.log','focused-receipt.json','inputs-complete-focused-before.json','inputs-complete-focused-after.json')){if(Test-Path -LiteralPath (Join-Path $PSScriptRoot $name)){throw 'Preserve prior recovery evidence; use a new directory for retry.'}}
|
|
$bindingPath=Join-Path $PSScriptRoot 'original-list-binding.json';$bindingHash=Hash $bindingPath
|
|
$binding=Get-Content -Raw -LiteralPath $bindingPath|ConvertFrom-Json
|
|
$prep=Get-Content -Raw -LiteralPath (Join-Path $PSScriptRoot 'preparation.json')|ConvertFrom-Json
|
|
$prepHash=Hash (Join-Path $PSScriptRoot 'preparation.json')
|
|
Assert-Files $prep.files;Assert-Files $binding.files;Assert-Files @($binding.test_binary)
|
|
$selection=Get-Content -Raw -LiteralPath (Join-Path $PSScriptRoot 'expected-tests.json')|ConvertFrom-Json
|
|
$prior=Get-Content -Raw -LiteralPath (Join-Path $binding.original_gate 'list-receipt.json')|ConvertFrom-Json
|
|
if($binding.base -cne $pin -or $prior.base -cne $pin -or $prior.cargoExitCode -ne 0 -or $prior.selectionValid -or -not $prior.inputsUnchanged -or $null -ne $prior.postflightFailure -or @($prior.listedTests).Count -ne 1045 -or $selection.source_commit -cne $pin -or @($selection.tests).Count -ne 224 -or @($selection.tests|Sort-Object -Unique).Count -ne 224 -or -not(Same-Names $selection.desktop_tests $prior.listedTests) -or @($selection.tests|Where-Object {$_ -cnotin $prior.listedTests}).Count -ne 0){throw 'Exact successful compilation and corrected membership required; original selection failure must remain recorded.'}
|
|
& (Join-Path $PSScriptRoot 'capture.ps1') -Stage focused-before
|
|
. $prior.externalEnvironmentPath
|
|
$env:CARGO_TERM_COLOR='never'
|
|
$PSNativeCommandUseErrorActionPreference=$false
|
|
$arguments=@('--exact')+@($selection.tests)+@('--test-threads=1')
|
|
$start=[DateTime]::UtcNow.ToString('o')
|
|
Push-Location -LiteralPath $prior.workspace
|
|
try { & $binding.test_binary.path @arguments 2>&1 | Tee-Object -FilePath $log; $code=$LASTEXITCODE } finally { Pop-Location }
|
|
$end=[DateTime]::UtcNow.ToString('o')
|
|
$parsed=Parse-Focused (Get-Content -Raw -LiteralPath $log) $selection.tests 821
|
|
$unchanged=$false;$failure=$null
|
|
try{
|
|
& (Join-Path $PSScriptRoot 'capture.ps1') -Stage focused-after
|
|
Assert-Files $prep.files;Assert-Files $binding.files;Assert-Files @($binding.test_binary)
|
|
if((Hash $bindingPath) -cne $bindingHash -or (Hash (Join-Path $PSScriptRoot 'preparation.json')) -cne $prepHash){throw 'Recovery binding changed during execution.'}
|
|
$unchanged=$true
|
|
}catch{$failure=$_.Exception.Message}
|
|
$receipt=[ordered]@{base=$pin;stage='focused-direct-executable';startUtc=$start;endUtc=$end;executable=$binding.test_binary;arguments=$arguments;exitCode=$code;selectionValid=$parsed.valid;inputsUnchanged=$unchanged;postflightFailure=$failure;executedTests=$parsed.executed;testResultSummaries=$parsed.summaries;originalListCargoExitCode=0;originalListSelectionValid=$false;originalListBindingSha256=$bindingHash;preparationSha256=$prepHash;rawLogSha256=(Hash $log);beforeCaptureSha256=(Hash (Join-Path $PSScriptRoot 'inputs-complete-focused-before.json'));afterCaptureSha256=if(Test-Path -LiteralPath (Join-Path $PSScriptRoot 'inputs-complete-focused-after.json')){Hash (Join-Path $PSScriptRoot 'inputs-complete-focused-after.json')}else{$null};scope='Existing successfully compiled test executable only. No Cargo, compiler, clean, full suite, strict or GUI build invoked.'}
|
|
$stream=[IO.File]::Open($receiptPath,[IO.FileMode]::CreateNew,[IO.FileAccess]::Write,[IO.FileShare]::Read)
|
|
try{$bytes=[Text.UTF8Encoding]::new($false).GetBytes(($receipt|ConvertTo-Json -Depth 15)+"`n");$stream.Write($bytes,0,$bytes.Length);$stream.Flush($true)}finally{$stream.Dispose()}
|
|
if($code -ne 0){exit $code}
|
|
if(-not $parsed.valid -or -not $unchanged){throw 'Focused recovery failed membership or input binding.'}
|