#Requires -Version 7.0 param([Parameter(Mandatory=$true)][ValidatePattern('^[0-9a-f]{40}$')][string]$SourceCommit) Set-StrictMode -Version Latest $ErrorActionPreference='Stop' $workspace='C:/Users/User/Documents/Git/ARCADIA-Studio/.local/scenario-workspace-ytr83r-20260913' $root='C:/Users/User/Documents/Git/ARCADIA-Studio' 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.'} $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} foreach($name in @('run.ps1','capture.ps1','enumerate-inputs.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 224 -or @($selection.tests|Sort-Object -Unique).Count -ne 224 -or @($selection.desktop_tests).Count -ne 1045 -or @($selection.desktop_tests|Sort-Object -Unique).Count -ne 1045){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.'} $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)}}) 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='Same-worktree development rebuild; parent requested no package clearance. Existing task env remains jobs1/incremental0. Source and executable binding are required.'}) $recovery=Join-Path $root '.local/scenario-workspace-focused-recovery83-20260913' $receipt=Get-Content -Raw -LiteralPath (Join-Path $recovery 'focused-receipt.json')|ConvertFrom-Json $oldList=Join-Path $root '.local/scenario-workspace-gates-attempt2-20260913/list-receipt.json' Save-Record 'prior-failure-provenance.json' ([ordered]@{source=$SourceCommit;previousSource=$receipt.base;scope='Original list1045 then corrected direct-executable focused222pass2fail; not acceptance';listReceiptPath=$oldList;listReceiptSha256=(Hash-Input $oldList);focusedReceiptPath=(Join-Path $recovery 'focused-receipt.json');focusedReceiptSha256=(Hash-Input (Join-Path $recovery 'focused-receipt.json'));focusedLogSha256=(Hash-Input (Join-Path $recovery 'focused.log'));correctedSelectionSha256=(Hash-Input (Join-Path $recovery 'expected-tests.json'));exitCode=$receipt.exitCode;inputsUnchanged=$receipt.inputsUnchanged;result=$receipt.testResultSummaries;failed=@($receipt.executedTests|Where-Object result -eq 'FAILED')}) & (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=224;desktopExpectedCount=1045;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.')