105 lines
11 KiB
PowerShell
105 lines
11 KiB
PowerShell
#Requires -Version 7.0
|
|
param([Parameter(Mandatory=$true)][ValidatePattern('^[0-9a-f]{40}$')][string]$SourceCommit,[Parameter(Mandatory=$true)][switch]$Reviewed)
|
|
Set-StrictMode -Version Latest
|
|
$ErrorActionPreference='Stop'
|
|
$workspace='C:/Users/User/Documents/Git/ARCADIA-Studio/.local/scenario-spacing-ytr83r-20260913'
|
|
$root='C:/Users/User/Documents/Git/ARCADIA-Studio'
|
|
if(-not $Reviewed){throw 'Parent must review the exact Details source before finalization.'}
|
|
if(Test-Path -LiteralPath (Join-Path $PSScriptRoot 'finalization.json')){throw 'Already finalized; preserve this gate.'}
|
|
foreach($name in @('enumeration.json','expected-inputs.json','external-inputs.json','inputs-complete-before.json','toolchain-versions.json','list.log','list-receipt.json')){
|
|
if(Test-Path -LiteralPath (Join-Path $PSScriptRoot $name)){throw ('Prior capture or run exists: '+$name)}
|
|
}
|
|
function Hash-Input([string]$Path){(Get-FileHash -LiteralPath $Path -Algorithm SHA256).Hash.ToLowerInvariant()}
|
|
function Save-Record([string]$Name,$Record){$Record|ConvertTo-Json -Depth 16|Set-Content -LiteralPath (Join-Path $PSScriptRoot $Name) -Encoding utf8}
|
|
Push-Location -LiteralPath $workspace
|
|
try {
|
|
$head=git rev-parse HEAD
|
|
if($LASTEXITCODE -ne 0 -or $head -cne $SourceCommit){throw 'Source is not at the reviewed pin.'}
|
|
$status=@(git status --porcelain)
|
|
if($LASTEXITCODE -ne 0 -or $status.Count){throw 'Source must be committed and clean.'}
|
|
$correction=Get-Content -Raw -LiteralPath (Join-Path $PSScriptRoot 'source-change-template.json')|ConvertFrom-Json
|
|
$changes=@(git diff --name-only $correction.previous_source $SourceCommit)
|
|
if($LASTEXITCODE -ne 0 -or $changes.Count -ne 4 -or @(Compare-Object @($correction.expected_changed_paths|Sort-Object) @($changes|Sort-Object)).Count){throw 'Expected exactly the four reviewed Details paths from 0409.'}
|
|
if($SourceCommit -cne $correction.reviewed_source){throw 'SourceCommit must equal the exact reviewed Details commit.'}
|
|
$reviewDiff=@(git diff --name-only $correction.reviewed_source $SourceCommit)
|
|
if($LASTEXITCODE -ne 0 -or $reviewDiff.Count){throw 'Tree differs from reviewed Details source; revise/review the template first.'}
|
|
$instructionBlob=git rev-parse 'HEAD:AGENTS.md'
|
|
if($LASTEXITCODE -ne 0 -or $instructionBlob -cne $correction.instruction_git_blob -or (Get-Item -LiteralPath 'AGENTS.md').Length -ne $correction.instruction_bytes -or (Hash-Input 'AGENTS.md') -cne $correction.instruction_sha256){throw 'User instructions differ from reviewed bytes.'}
|
|
$serverChanges=@(git diff --name-only 37be41092beb1c940f345072df1e017ce45fe2fc $SourceCommit -- crates/oa-core crates/oa-server Cargo.toml Cargo.lock rust-toolchain.toml)
|
|
if($LASTEXITCODE -ne 0 -or $serverChanges.Count){throw 'Core/server provenance changed; parent must revise gate scope.'}
|
|
} finally {Pop-Location}
|
|
# All evidence admission precedes mutation of the pending template or source captures.
|
|
foreach($binding in @($correction.prior_gate_bindings)+@($correction.prior_recipe_bindings)){
|
|
if((Get-Item -LiteralPath $binding.path).Length -ne $binding.bytes -or (Hash-Input $binding.path) -cne $binding.sha256){throw ('Prior evidence changed: '+$binding.path)}
|
|
}
|
|
$priorGate=Split-Path -Parent $correction.previous_capture.path
|
|
$list=Get-Content -Raw -LiteralPath (Join-Path $priorGate 'list-receipt.json')|ConvertFrom-Json
|
|
$focused=Get-Content -Raw -LiteralPath (Join-Path $priorGate 'focused-receipt.json')|ConvertFrom-Json
|
|
if($list.base -cne $correction.previous_source -or $list.cargoExitCode -ne 0 -or -not $list.selectionValid -or -not $list.inputsUnchanged -or -not $list.testBinaryBindingValid -or $list.postflightFailure -or @($list.listedTests).Count -ne 1083){throw 'Prior 0409 listing is not the bound successful 1083 inventory.'}
|
|
$focusedResult=@($focused.testResultSummaries)
|
|
if($focused.base -cne $correction.previous_source -or $focused.cargoExitCode -ne 0 -or -not $focused.selectionValid -or -not $focused.inputsUnchanged -or -not $focused.testBinaryBindingValid -or $focused.postflightFailure -or $focusedResult.Count -ne 1 -or $focusedResult[0].passed -ne 289 -or $focusedResult[0].failed -ne 0 -or $focusedResult[0].ignored -ne 0 -or $focusedResult[0].filtered -ne 794){throw 'Prior focused result differs from reviewed 289 passed / 0 failed evidence.'}
|
|
foreach($name in @('run.ps1','capture.ps1','enumerate-inputs.ps1','diagnostic.ps1')){
|
|
$path=Join-Path $PSScriptRoot $name
|
|
$text=[IO.File]::ReadAllText($path)
|
|
if(-not $text.Contains('PENDING_REVIEWED_SOURCE_PIN')){throw 'Template was already modified; inspect before retry.'}
|
|
[IO.File]::WriteAllText($path,$text.Replace('PENDING_REVIEWED_SOURCE_PIN',$SourceCommit),[Text.UTF8Encoding]::new($false))
|
|
}
|
|
$selection=Get-Content -Raw -LiteralPath (Join-Path $PSScriptRoot 'expected-tests.json')|ConvertFrom-Json
|
|
if(@($selection.tests).Count -ne 295 -or @($selection.tests|Sort-Object -Unique).Count -ne 295 -or @($selection.desktop_tests).Count -ne 1089 -or @($selection.desktop_tests|Sort-Object -Unique).Count -ne 1089){throw 'Expected membership changed; parent must review selection.'}
|
|
if(@($selection.tests|Where-Object {$_ -cnotin $selection.desktop_tests}).Count){throw 'Focused test absent from expected desktop listing.'}
|
|
$selectionEvidence=Get-Content -Raw -LiteralPath (Join-Path $PSScriptRoot 'selection-provenance.json')|ConvertFrom-Json
|
|
$oldSelection=Get-Content -Raw -LiteralPath (Join-Path $priorGate 'expected-tests.json')|ConvertFrom-Json
|
|
$detailsPath=Join-Path $workspace $correction.expected_added_path
|
|
$detailsText=[IO.File]::ReadAllText($detailsPath)
|
|
$newTests=@([regex]::Matches($detailsText,'#\[(?:tokio::)?test\]\s*(?:async\s+)?fn\s+(\w+)\s*\(')|ForEach-Object {'behavior::scenario::workspace::details_tests::'+$_.Groups[1].Value})
|
|
if($newTests.Count -ne 6 -or @($newTests|Sort-Object -Unique).Count -ne 6 -or $detailsText -match '#\[ignore'){throw 'Expected six nonignored Details tests in the actual source.'}
|
|
if(@(Compare-Object @(@($oldSelection.tests)+$newTests|Sort-Object) @($selection.tests|Sort-Object)).Count -or @(Compare-Object @(@($oldSelection.desktop_tests)+$newTests|Sort-Object) @($selection.desktop_tests|Sort-Object)).Count){throw 'New membership must be exactly prior inventory plus the six source-derived tests.'}
|
|
if(@($selection.ignored_tests).Count -ne 4 -or @(Compare-Object @($oldSelection.ignored_tests|Sort-Object) @($selection.ignored_tests|Sort-Object)).Count){throw 'Ignored membership must remain unchanged.'}
|
|
|
|
$selection.source_commit=$SourceCommit
|
|
Save-Record 'expected-tests.json' $selection
|
|
& (Join-Path $PSScriptRoot 'enumerate-inputs.ps1')
|
|
$enumeration=Get-Content -Raw -LiteralPath (Join-Path $PSScriptRoot 'enumeration.json')|ConvertFrom-Json
|
|
$inputs=@(foreach($relative in $enumeration.gitPaths){$path=Join-Path $workspace $relative;$item=Get-Item -LiteralPath $path;[ordered]@{path=$relative;bytes=$item.Length;sha256=(Hash-Input $path)}})
|
|
$previousCapture=$correction.previous_capture
|
|
$previous=Get-Content -Raw -LiteralPath $previousCapture.path|ConvertFrom-Json
|
|
if($previous.base -cne $correction.previous_source -or $previous.count -ne 610 -or $inputs.Count -ne 611){throw 'Details must retain the 610 prior inputs and add exactly one reviewed test module.'}
|
|
$remaining=@{}
|
|
foreach($file in $previous.files){if($remaining.ContainsKey($file.path)){throw 'Duplicate previous input'};$remaining[$file.path]=$file}
|
|
$changedInputs=@(foreach($file in $inputs){
|
|
if(-not $remaining.ContainsKey($file.path)){
|
|
if($file.path -cne $correction.expected_added_path){throw ('Unreviewed new compiled input: '+$file.path)}
|
|
continue
|
|
}
|
|
$old=$remaining[$file.path]
|
|
if($file.bytes -ne $old.bytes -or $file.sha256 -cne $old.sha256){
|
|
if($file.path -cnotin $correction.expected_changed_paths){throw ('Unreviewed compiled input changed: '+$file.path)}
|
|
$file.path
|
|
}
|
|
$remaining.Remove($file.path)
|
|
})
|
|
if($remaining.Count -or $changedInputs.Count -ne 3 -or @($inputs|Where-Object path -CEQ $correction.expected_added_path).Count -ne 1){throw 'Expected three changed existing inputs, 607 byte-identical inputs, and one reviewed added test module.'}
|
|
Save-Record 'source-change-provenance.json' ([ordered]@{source_commit=$SourceCommit;reviewed_source=$correction.reviewed_source;previous_source=$correction.previous_source;tree_equal_to_reviewed=$true;input_count=611;changed_inputs=$changedInputs;added_input=$correction.expected_added_path;unchanged_input_count=607;instruction_git_blob=$instructionBlob;status='Parent-reviewed Details tree in original spacing checkout verified; source-only capture, no Cargo executed'})
|
|
Save-Record 'expected-inputs.json' ([ordered]@{base=$SourceCommit;workspace=$workspace;count=$inputs.Count;files=$inputs})
|
|
$external=Get-Content -Raw -LiteralPath (Join-Path $PSScriptRoot 'external-input-template.json')|ConvertFrom-Json
|
|
$externalFiles=@(foreach($file in $external.files){$present=Test-Path -LiteralPath $file.path;if($present){$item=Get-Item -LiteralPath $file.path;[ordered]@{path=$file.path;present=$true;bytes=$item.Length;sha256=(Hash-Input $file.path)}}else{[ordered]@{path=$file.path;present=$false}}})
|
|
Save-Record 'external-inputs.json' ([ordered]@{base=$SourceCommit;status='Fresh external environment/config snapshot; not version-controlled inputs';files=$externalFiles})
|
|
$server=Get-Content -Raw -LiteralPath (Join-Path $PSScriptRoot 'server-provenance-template.json')|ConvertFrom-Json
|
|
$server.source=$SourceCommit
|
|
Save-Record 'server-provenance.json' $server
|
|
Save-Record 'cache-policy.json' ([ordered]@{base=$SourceCommit;retainExistingTarget=$true;cleanRequested=$false;target=(Join-Path $root 'target');scope='Original spacing checkout rebuild after reviewed Details fast-forward. Retain shared target/cache and jobs1/incremental0; no clearance is performed by this recipe. Parent owns any separately authorized package clearance. Exact source and executable binding are required.'})
|
|
Save-Record 'prior-gate-provenance.json' ([ordered]@{
|
|
source=$SourceCommit
|
|
previousSource=$correction.previous_source
|
|
scope='Closed 0409 listing passed (1083); focused passed (289 / 0 / 0, 794 filtered). These are previous-version evidence only. No prior full/strict/build success is inferred. Older c4 failure/diagnostic provenance is preserved through the bound prior gate record. Every Details acceptance stage must pass anew.'
|
|
bindings=$correction.prior_gate_bindings
|
|
recipeBindings=$correction.prior_recipe_bindings
|
|
list=[ordered]@{cargoExitCode=$list.cargoExitCode;selectionValid=$list.selectionValid;inputsUnchanged=$list.inputsUnchanged;count=@($list.listedTests).Count}
|
|
focused=[ordered]@{cargoExitCode=$focused.cargoExitCode;selectionValid=$focused.selectionValid;inputsUnchanged=$focused.inputsUnchanged;result=$focused.testResultSummaries}
|
|
})
|
|
& (Join-Path $PSScriptRoot 'capture.ps1') -Stage before
|
|
& (Join-Path $PSScriptRoot 'validate-scripts.ps1')
|
|
& (Join-Path $PSScriptRoot 'verify-parser.ps1')
|
|
Save-Record 'finalization.json' ([ordered]@{base=$SourceCommit;capturedUtc=[DateTime]::UtcNow.ToString('o');sourceCount=$inputs.Count;focusedCount=295;desktopExpectedCount=1089;cleanPerformed=$false;cargoExecuted=$false;sourceBeforeSha256=(Hash-Input (Join-Path $PSScriptRoot 'inputs-complete-before.json'));selectionSha256=(Hash-Input (Join-Path $PSScriptRoot 'expected-tests.json'));parserSha256=(Hash-Input (Join-Path $PSScriptRoot 'parser-verification.json'));status='Prepared only; parent dispatches list, focused, all, clippy, build sequentially'})
|
|
Write-Output ('Finalized source-only gate for '+$SourceCommit+' with '+$inputs.Count+' inputs; no Cargo or clean executed.')
|