Files
SGF/scripts/request-history-finalize.php
2026-11-04 09:37:20 +02:00

7 lines
2.9 KiB
PHP

<?php
use Illuminate\Support\Facades\DB;
$s=json_decode(file_get_contents(getenv('RECEIPT_COMPOSITION_STATE')),true);$out=$s['root'].'/request-history-result.json';if(file_exists($out))throw new LogicException('Completed proof preserved');require $s['app'].'/vendor/autoload.php';$app=require $s['app'].'/bootstrap/app.php';$app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap();App\Modules\Purchasing\BudgetAdapter::guard();$n=json_decode(file_get_contents($s['root'].'/native-fixture.json'),true);config(['database.connections.history_verify'=>$s['nativeConnection']]);$db=DB::connection('history_verify');$checks=json_decode(file_get_contents($s['root'].'/request-history-progress.json'),true);if(count($checks)!==17)throw new LogicException('Exact successful prefix required');$id=(int)$db->table('audit_logs')->where('action','requisition.qa_history')->value('requisition_id');$ok=function($value,$name)use(&$checks){if(!$value)throw new RuntimeException($name);$checks[]=$name;};$empty=true;foreach(['goods_receipts','invoices','pa_obligations','external_payments']as$table)$empty=$empty&&$db->table($table)->where('tenant_id',$n['tenant'])->count()===0;
$createdAt=$db->table('requisitions')->where('id',$id)->value('created_at');$orders=$db->table('purchase_orders')->where('tenant_id',$n['tenant']);$ok($empty&&(int)$db->table('requisitions')->where('id',$id)->value('process_version')===1&&$db->table('requisitions')->where('id',$id)->value('status')==='draft'&&(clone $orders)->count()===1&&(clone $orders)->where('issued_at','<=',$createdAt)->count()===1,'history preserves draft version/status and pre-existing harness order without stock invoice debt or payment');
$queries=0;DB::listen(function()use(&$queries){$queries++;});$controller=new App\Modules\Purchasing\RequestController;$runtime=new App\Modules\Purchasing\ReceiptRuntime;$request=Illuminate\Http\Request::create('/','GET');$denied=function($fn)use($ok){try{$fn();throw new RuntimeException('Guard accepted');}catch(Symfony\Component\HttpKernel\Exception\HttpException $e){if($e->getStatusCode()!==404)throw $e;}};$denied(fn()=>$controller->history(0,$request,$runtime));$ok($queries===0,'zero request id refuses before database access');config(['receipt_qa.request_history_enabled'=>false]);$denied(fn()=>$controller->history($id,$request,$runtime));$ok($queries===0,'disabled request-history feature refuses before database access');
file_put_contents($out,json_encode(['passed'=>true,'checks'=>$checks,'request_id'=>$id,'initial_events'=>127,'events_after_append'=>128,'native_audit_fixture_notes'=>126,'main_drafts'=>2,'inherited_harness_order_before_history_request'=>1,'inherited_order_source_setup_removed_for_future_runs'=>true,'request_version_unchanged'=>true,'successful_prefix_reused'=>17,'guard_database_queries'=>0,'new_right_names'=>[],'visual_review'=>false,'deployment_capacity_validated'=>false],JSON_PRETTY_PRINT|JSON_THROW_ON_ERROR));echo count($checks)." request history checks passed,17 reused.\n";