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

4 lines
2.7 KiB
PHP

<?php
use Illuminate\Support\Facades\DB;
$s=json_decode(file_get_contents(getenv('RECEIPT_COMPOSITION_STATE')),true);$out=$s['root'].'/obligation-evidence-demo.json';if(!($s['obligationEvidence']??false)||is_file($out))throw new LogicException('New evidence 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.evidence_demo'=>$s['nativeConnection']]);$db=DB::connection('evidence_demo');$checks=[];$ok=function($v,$name)use(&$checks){if(!$v)throw new RuntimeException($name);$checks[]=$name;};$fingerprint=fn()=>hash('sha256',json_encode([$db->table('pa_proposals')->orderBy('id')->get(),$db->table('pa_obligations')->orderBy('id')->get(),$db->table('pa_events')->orderBy('id')->get(),$db->table('audit_logs')->orderBy('id')->get(),DB::table('permission_grants')->orderBy('id')->get()]));$before=$fingerprint();$ok($db->table('requisitions')->where('tenant_id',$n['tenant'])->count()===0&&$db->table('pa_proposals')->where('tenant_id',$n['tenant'])->count()===0&&$db->table('pa_obligations')->where('tenant_id',$n['tenant'])->count()===0,'fresh evidence demo contains no main operations proposals or obligations');$client=new GuzzleHttp\Client(['base_uri'=>'http://127.0.0.1:8082','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']]];$r=$client->get('/purchasing/obligations',$options);$ok($r->getStatusCode()===200&&str_contains((string)$r->getBody(),'data-evidence-enabled="true"'),'authorised obligation screen enables independent evidence navigation');$r=$client->get('/api/purchasing-obligations',$options);$d=json_decode((string)$r->getBody(),true);$ok($r->getStatusCode()===200&&$d['data']===[],'empty demonstration invents no invoice or selected proposal');foreach(['supplier-obligation-workspace.mjs','obligation-evidence.mjs']as$file){$r=$client->get('/'.$file);$ok($r->getStatusCode()===200&&hash('sha256',(string)$r->getBody())===hash_file('sha256',$s['app'].'/public/'.$file),'served evidence module matches '.$file);}$ok($fingerprint()===$before,'demo probes preserve proposals obligations events audit and grants');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)." obligation evidence demo checks passed.\n";