Files
SGF/scripts/budget-workspace-proof.ps1
2026-10-29 18:43:29 +02:00

26 lines
2.2 KiB
PowerShell

$ErrorActionPreference='Stop'
$budgetRoot=[IO.Path]::GetFullPath((Join-Path $PSScriptRoot '..'))
if($budgetRoot -ne 'C:\laragon\www\sgf-tempo'){throw 'Unexpected project path.'}
if(Get-NetTCPConnection -LocalPort 8004 -State Listen -ErrorAction SilentlyContinue){throw 'Proof port occupied; no process stopped.'}
$budgetProvisionPhp='C:\Users\macbook\.config\investmoz\php-8.5.11\php.exe'
$budgetWebPhp='C:\laragon\tools\sgf-tempo\php-8.4.27\php.exe'
$budgetProofProcess=$null
try {
& $budgetProvisionPhp (Join-Path $PSScriptRoot 'budget-demo-provision.php') --proof
if($LASTEXITCODE){throw 'Isolated proof preparation failed.'}
$budgetAccount=[Security.Principal.WindowsIdentity]::GetCurrent().Name
foreach($budgetFile in @('budget-proof.json','budget-proof-access.json')){& icacls.exe "C:\laragon\data\sgf-tempo\secrets\$budgetFile" /inheritance:r /grant:r "${budgetAccount}:F" 'SYSTEM:F' | Out-Null}
$env:BUDGET_DEMO_SETTINGS_FILE='C:/laragon/data/sgf-tempo/secrets/budget-proof.json'
$budgetProofProcess=Start-Process -FilePath $budgetWebPhp -ArgumentList @('-S','127.0.0.1:8004','-t','public','scripts/budget-demo-router.php') -WorkingDirectory $budgetRoot -WindowStyle Hidden -PassThru -RedirectStandardOutput 'C:\laragon\data\sgf-tempo\run\budget-proof.stdout.log' -RedirectStandardError 'C:\laragon\data\sgf-tempo\run\budget-proof.stderr.log'
Remove-Item Env:BUDGET_DEMO_SETTINGS_FILE
$budgetReady=$false
for($budgetAttempt=0;$budgetAttempt -lt 30;$budgetAttempt++) { if(Get-NetTCPConnection -LocalPort 8004 -State Listen -ErrorAction SilentlyContinue){$budgetReady=$true;break}; Start-Sleep -Milliseconds 100 }
if(!$budgetReady){throw 'Proof server did not start.'}
Push-Location $budgetRoot
try { & 'C:\laragon\tools\sgf-tempo\node-v24.22.1-win-arm64\node.exe' scripts/budget-workspace-http-proof.mjs; if($LASTEXITCODE){throw 'HTTP budget workspace checks failed.'} } finally {Pop-Location}
} finally {
Remove-Item Env:BUDGET_DEMO_SETTINGS_FILE -ErrorAction SilentlyContinue
if($budgetProofProcess -and !$budgetProofProcess.HasExited){Stop-Process -Id $budgetProofProcess.Id}
& $budgetProvisionPhp (Join-Path $PSScriptRoot 'budget-demo-provision.php') --cleanup-proof
}