Files
SGF/scripts/purchasing-integrated-smoke.php
T
2026-11-04 09:37:20 +02:00

12 lines
3.3 KiB
PHP

<?php
use Illuminate\Support\Facades\DB;
$s=json_decode(file_get_contents(getenv('RECEIPT_COMPOSITION_STATE')),true);$out=$s['root'].'/integrated-smoke.json';if(!($s['integrated']??false)||is_file($out))throw new LogicException('Fresh integrated demonstration required');require $s['app'].'/vendor/autoload.php';$app=require $s['app'].'/bootstrap/app.php';$app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap();$f=json_decode(file_get_contents($s['root'].'/fixture.json'),true);$n=json_decode(file_get_contents($s['root'].'/native-fixture.json'),true);config(['database.connections.demo_verify'=>$s['nativeConnection']]);$db=DB::connection('demo_verify');$checks=[];$ok=function($v,$name)use(&$checks){if(!$v)throw new RuntimeException($name);$checks[]=$name;};
$fingerprint=function()use($db){$rows=[];foreach(['requisitions','quotations','proposal_evaluations','purchase_awards','purchase_orders','goods_receipts','stock_movements','invoices','budget_entries','budget_consumptions','pa_proposals','pa_obligations','pa_commands','pa_events','audit_logs','external_payments']as$t)$rows['native:'.$t]=$db->table($t)->orderBy('id')->get();foreach(['geo_locations','geo_location_history','geo_commands','cb_budget_entries']as$t)$rows['host:'.$t]=DB::table($t)->get();return hash('sha256',json_encode($rows));};$before=$fingerprint();
foreach(['requisitions','quotations','purchase_awards','purchase_orders','goods_receipts','invoices','pa_proposals','pa_obligations']as$t)$ok($db->table($t)->where('tenant_id',$n['tenant'])->count()===0,'live main book starts without '.$t);
$client=new GuzzleHttp\Client(['base_uri'=>'http://127.0.0.1:8072','http_errors'=>false,'timeout'=>25]);
foreach(['requester','approver','actor','validator','issuer','reviewer','auditor']as$role){$jar=new GuzzleHttp\Cookie\CookieJar;$r=$client->get('/qa/enter/'.$role,['cookies'=>$jar]);$v=json_decode((string)$r->getBody(),true);$o=['cookies'=>$jar,'headers'=>['Accept'=>'application/json','X-SGF-Context'=>$v['context']]];$r=$client->get('/purchasing/workspace',$o);$body=(string)$r->getBody();$ok($r->getStatusCode()===200&&str_contains($body,'aria-label="Etapas de Compras"'),'workspace live for '.$role);if($role==='validator')$ok(str_contains($body,'href="/purchasing/receipts"')&&!str_contains($body,'href="/purchasing/invoices"'),'warehouse sees physical stage without invoice economics');
$path=match($role){'requester','approver'=>'/purchasing/requests','actor'=>'/purchasing/sourcing','validator'=>'/purchasing/receipts','issuer'=>'/purchasing/invoices',default=>'/purchasing/obligations'};$r=$client->get($path,$o);$ok($r->getStatusCode()===200&&str_contains((string)$r->getBody(),'aria-label="Etapas de Compras"'),'stage shares permission-aware navigation for '.$role);
}
$ok(DB::table('geo_territories')->count()===20407&&DB::table('geo_locations')->count()===0,'same host contains pinned reference without automatic localisation');$ok($fingerprint()===$before,'live navigation and screens preserve all business geography and budget evidence');
file_put_contents($out,json_encode(['passed'=>true,'checks'=>$checks,'before'=>$before,'after'=>$fingerprint(),'initial_main_operations'=>0,'automatic_locations'=>0,'visual_review'=>false],JSON_PRETTY_PRINT|JSON_THROW_ON_ERROR));echo count($checks)." integrated demonstration checks passed.\n";