Files
SGF/scripts/order-demo-smoke.php
2026-11-04 09:37:20 +02:00

6 lines
3.0 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-demo-smoke.json';if(file_exists($out))throw new LogicException('Completed order smoke preserved');require $s['app'].'/vendor/autoload.php';$app=require $s['app'].'/bootstrap/app.php';$app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap();$n=json_decode(file_get_contents($s['root'].'/native-fixture.json'),true);config(['database.connections.order_smoke'=>$s['nativeConnection']]);$db=DB::connection('order_smoke');$checks=[];$ok=function($v,$name)use(&$checks){if(!$v)throw new RuntimeException($name);$checks[]=$name;};$fingerprint=function()use($db){$h=hash_init('sha256');foreach(['purchase_orders','purchase_order_items','goods_receipts','stock_movements','budget_entries','audit_logs']as$table){hash_update($h,$table);foreach($db->table($table)->orderBy('id')->get()as$row)hash_update($h,json_encode((array)$row,JSON_THROW_ON_ERROR));}return hash_final($h);};$before=$fingerprint();$ok($db->table('purchase_orders')->count()===0&&$db->table('goods_receipts')->count()===0&&$db->table('stock_movements')->count()===0,'new demonstration preserves unconsumed order and receipt decisions');$client=new GuzzleHttp\Client(['base_uri'=>'http://127.0.0.1:8065','http_errors'=>false,'timeout'=>25]);
foreach(['actor'=>true,'issuer'=>false,'validator'=>null]as$role=>$can){$jar=new GuzzleHttp\Cookie\CookieJar;$r=$client->get('/qa/enter/'.$role,['cookies'=>$jar]);$v=json_decode((string)$r->getBody(),true);$options=['cookies'=>$jar,'headers'=>['Accept'=>'application/json','X-SGF-Context'=>$v['context']]];$r=$client->get('/api/purchasing-orders/awards/'.$n['award'],$options);$d=json_decode((string)$r->getBody(),true);$ok($can===null?$r->getStatusCode()===403:($r->getStatusCode()===200&&$d['can_issue']===$can),'demo has exact order authority for '.$role);if($role==='actor'){$r=$client->get('/purchasing/orders',$options);$ok($r->getStatusCode()===200&&str_contains((string)$r->getBody(),'order-workspace.mjs'),'order workspace is live');}if($role==='validator'){$r=$client->get('/api/purchasing-receipts',$options);$d=json_decode((string)$r->getBody(),true);$ok($r->getStatusCode()===200&&count($d['data'])===0,'warehouse waits for issued orders in the same composition');}}
$r=$client->get('/order-workspace.mjs');$ok($r->getStatusCode()===200&&hash('sha256',(string)$r->getBody())===hash_file('sha256',$s['app'].'/public/order-workspace.mjs'),'served order interface matches source');$ok($db->table('budget_entries')->where('kind','commit')->count()===0,'read-only demonstration smoke creates no commitment');$ok($fingerprint()===$before,'all initial canonical evidence remains unchanged');file_put_contents($out,json_encode(['passed'=>true,'checks'=>$checks,'before'=>$before,'after'=>$fingerprint(),'orders'=>0,'receipts'=>0,'movements'=>0,'commitments'=>0,'visual_review'=>false],JSON_PRETTY_PRINT|JSON_THROW_ON_ERROR));echo count($checks)." order demonstration checks passed.\n";