selectOne('SELECT current_database() AS database,inet_server_port() AS port'); if($t!==['database'=>'stability_consumers_20261011_084534_test','port'=>55441])throw new RuntimeException('QA target guard'); $db->beginTransaction();$db->statement('SET TRANSACTION READ ONLY'); try{ $before=json_decode(file_get_contents(__DIR__.'/option-B3-preflight.json'),true,512,JSON_THROW_ON_ERROR); $s=json_decode(file_get_contents(__DIR__.'/option-B3-project-progress.json'),true,512,JSON_THROW_ON_ERROR); $f=json_decode(file_get_contents(__DIR__.'/option-B3-PDF-fixture.json'),true,512,JSON_THROW_ON_ERROR); $newTasks=$db->table('tasks')->where('created_at','>=',$before['at'])->get(['id','external_id','source_system','due_at']); foreach($newTasks as$task)if($task->source_system!=='opportunity-workflow'||!str_starts_with($task->external_id,'portal-opportunity:30:')||$task->due_at!==null)throw new RuntimeException('Unexpected task scope or deadline'); $preserved=[]; foreach($before['protected_tables']as$name=>$expected){ $q=$db->table($name);if($name==='documents')$q->where('id','!=',$s['document_id']); if($name==='opportunity_documents')$q->where('id','!=',$s['resource_id']); if($name==='tasks')$q->whereNotIn('id',$newTasks->pluck('id')); $rows=$q->get();$bytes=$rows->map(fn($r)=>json_encode($r,JSON_THROW_ON_ERROR))->all();sort($bytes,SORT_STRING); $preserved[$name]=$rows->count()===$expected['count']&&hash('sha256',implode("\n",$bytes))===$expected['sha256']; } if(in_array(false,$preserved,true))throw new RuntimeException('Existing protected data changed'); $doc=$db->table('documents')->where('id',$s['document_id'])->first(); $same=$db->table('opportunity_documents as r')->join('documents as d','d.id','=','r.document_id')->where('r.opportunity_id',30)->where('d.sha256',$f['sha256'])->count(); if($same!==1||$doc->storage_encryption!=='laravel'||$doc->malware_scan_status!=='clean'||trim($doc->sha256)!==$doc->malware_scanned_sha256)throw new RuntimeException('Original/scan/duplication mismatch'); $o=App\Models\Opportunity::findOrFail(30);$c=app(App\Services\OpportunityManagement::class)->values($o)['canonical']; if($o->workflow_context['working_state']!=='published'||$o->workflow_context['publication']['visibility']!=='internal'||$c['licenses'][0]['number']!=='SIM-QA-B3-LIC-30')throw new RuntimeException('Workflow recovery mismatch'); $baseline=$s['baseline_reviews']['technical_review'];$technical=$o->workflow_context['reviews']['technical_review']; foreach(['hash','actor_id','at']as$key)if($baseline[$key]!==$technical[$key])throw new RuntimeException('Unaffected review changed'); $p=['at'=>gmdate('c'),'target'=>$t,'SQL_read_only'=>true,'active_writes'=>0,'protected_tables_preserved'=>$preserved, 'prior_tasks_preserved'=>$before['protected_tables']['tasks']['count'],'new_tasks'=>$newTasks->count(), 'new_tasks_only_project30_without_due_dates'=>true,'one_original_resource_for_bytes'=>$same,'original_sha256'=>$f['sha256'], 'original_cifred'=>true,'scan_hash_matches'=>true,'scan_attempts'=>$doc->malware_scan_attempts, 'legal_review_uses_specific_resource'=>$o->workflow_context['reviews']['legal_territorial_review']['evidence_document_ids']===[$s['resource_id']], 'technical_review_signature_actor_time_preserved'=>true,'state'=>'published','visibility'=>'internal', 'synthetic_external_license_not_real'=>true,'external_notifications_off'=>!config('portal.notifications_enabled'), 'browser_observed'=>false,'A_B_C37_not_repeated'=>true]; $dest=__DIR__.'/option-B3-final-QA.json';if(is_file($dest))throw new RuntimeException('Preserve final proof'); file_put_contents($dest,json_encode($p,JSON_PRETTY_PRINT|JSON_THROW_ON_ERROR));echo json_encode($p).PHP_EOL; }finally{$db->rollBack();}