Files
SGF/scripts/order-guard-proof.php
T
2026-11-04 09:37:20 +02:00

5 lines
1.5 KiB
PHP

<?php
use Illuminate\Support\Facades\DB;
$s=json_decode(file_get_contents(getenv('RECEIPT_COMPOSITION_STATE')),true,64,JSON_THROW_ON_ERROR);$out=$s['root'].'/order-guards.json';if(file_exists($out))throw new LogicException('Completed guard proof preserved');require $s['app'].'/vendor/autoload.php';$app=require $s['app'].'/bootstrap/app.php';$app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap();$checks=[];$queries=0;DB::listen(function()use(&$queries){$queries++;});$runtime=new App\Modules\Purchasing\ReceiptRuntime;$probe=function($fn,$status,$name)use(&$checks,&$queries){$before=$queries;try{$fn();throw new RuntimeException('Expected refusal');}catch(Symfony\Component\HttpKernel\Exception\HttpException $e){if($e->getStatusCode()!==$status||$before!==$queries)throw new RuntimeException($name);$checks[]=$name;}};
config(['receipt_qa.orders_enabled'=>false]);$probe(fn()=>$runtime->run('purchasing_orders.issue',fn()=>true),404,'disabled order runtime refuses before SQL');$probe(fn()=>(new App\Modules\Purchasing\OrderController)->index(new Illuminate\Http\Request,$runtime),404,'disabled order endpoint refuses before SQL');config(['receipt_qa.orders_enabled'=>true]);$app->instance('env','production');$probe(fn()=>$runtime->run('purchasing_orders.issue',fn()=>true),403,'production cannot activate QA issuance');file_put_contents($out,json_encode(['passed'=>true,'checks'=>$checks,'database_queries'=>0,'business_writes'=>0],JSON_PRETTY_PRINT|JSON_THROW_ON_ERROR));echo count($checks)." order guard checks passed.\n";