Files
SGF/scripts/purchasing-focus-demo.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);$out=$s['root'].'/purchasing-focus-demo.json';if(!($s['focus']??false)||is_file($out))throw new LogicException('New focus demonstration required');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.focus_demo'=>$s['nativeConnection']]);$db=DB::connection('focus_demo');$checks=[];$ok=function($v,$name)use(&$checks){if(!$v)throw new RuntimeException($name);$checks[]=$name;};$fingerprint=fn()=>hash('sha256',json_encode([array_map(fn($t)=>$db->table($t)->orderBy('id')->get(),['suppliers','requisitions','purchase_orders','goods_receipts','receipt_documents','invoices','pa_obligations','audit_logs']),DB::table('permission_grants')->orderBy('id')->get(),DB::table('geo_locations')->orderBy('tenant_id')->orderBy('company_id')->orderBy('unit_key')->orderBy('module_key')->orderBy('kind')->orderBy('entity_id')->orderBy('provider')->get()]));$before=$fingerprint();$ok($db->table('requisitions')->where('tenant_id',$n['tenant'])->count()===0&&$db->table('purchase_orders')->count()===0&&$db->table('goods_receipts')->count()===0&&$db->table('invoices')->count()===0&&$db->table('pa_obligations')->count()===0,'fresh integrated focus demo starts without main business operations');$client=new GuzzleHttp\Client(['base_uri'=>'http://127.0.0.1:8078','http_errors'=>false,'timeout'=>25]);$jar=new GuzzleHttp\Cookie\CookieJar;$r=$client->get('/qa/enter/issuer',['cookies'=>$jar]);$v=json_decode((string)$r->getBody(),true);$options=['cookies'=>$jar,'headers'=>['Accept'=>'application/json','X-SGF-Context'=>$v['context']]];
foreach(['requests?request=1','sourcing?request=1','orders?award=1','receipts?order=1&receipt=1','invoices?order=1&invoice=1','obligations?invoice=1','dossiers?request=1']as$path){$r=$client->get('/purchasing/'.$path,$options);$ok($r->getStatusCode()===200&&str_contains((string)$r->getBody(),'data-focus-enabled="true"'),'fresh workspace mounts focused reading: '.$path);}
foreach(['/api/purchasing-dossiers/999999','/api/purchasing-obligations/999999']as$path){$r=$client->get($path,$options);$ok($r->getStatusCode()===403,'unknown focus source never grants or creates authority: '.$path);}$r=$client->get('/purchasing-focus.mjs');$ok($r->getStatusCode()===200&&hash('sha256',(string)$r->getBody())===hash_file('sha256',$s['app'].'/public/purchasing-focus.mjs'),'shared focus module is served with exact private source bytes');$ok($fingerprint()===$before,'demonstration probes preserve selected business tables grants geography and native audit');file_put_contents($out,json_encode(['passed'=>true,'checks'=>$checks,'before'=>$before,'after'=>$fingerprint(),'visual_review'=>false],JSON_PRETTY_PRINT|JSON_THROW_ON_ERROR));echo count($checks)." purchasing focus demonstration checks passed.\n";