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 required');$db->beginTransaction();$db->statement('SET TRANSACTION READ ONLY'); try{ $baseline=json_decode(file_get_contents(__DIR__.'/option-B8-preflight.json'),true,512,JSON_THROW_ON_ERROR);$p=['at'=>gmdate('c'),'target'=>$t,'SQL_read_only'=>true,'active_writes'=>0,'browser_observed'=>false,'result'=>'passed','unchanged_tables'=>[]]; foreach(['users','organizations','memberships','portal_role_assignments','portal_superuser_pair','jobs','outbox_events','investor_journeys','journey_steps','investment_submissions','investment_company_declarations','investment_accounts','opportunity_locations']as$table){$rows=$db->table($table)->get();$bytes=$rows->map(fn($r)=>json_encode($r,JSON_THROW_ON_ERROR))->all();sort($bytes,SORT_STRING);$actual=['count'=>$rows->count(),'sha256'=>hash('sha256',implode("\n",$bytes))];if($actual!==$baseline['protected_tables'][$table])throw new RuntimeException('Protected table changed: '.$table);$p['unchanged_tables'][]=$table;} foreach($baseline['records']as$old){$o=App\Models\Opportunity::findOrFail($old['id']);$values=app(App\Services\OpportunityManagement::class)->values($o)['canonical'];$ctx=$o->workflow_context;if(app(App\Services\PortalProfileAccess::class)->state($o)!=='published'||$ctx['approval']['actor_id']!==24||$ctx['publication']['actor_id']!==25||$ctx['publication']['visibility']!=='internal')throw new RuntimeException('Publication identity/state mismatch'); foreach($old['resources']['documents']as$r){$current=$db->table('opportunity_documents')->where('id',$r['id'])->first();if(!$current||$current->document_id!==$r['document_id']||$current->version!==$r['version']||json_decode($current->payload,true)!==$r['payload'])throw new RuntimeException('Original resource changed');$d=$db->table('documents')->where('id',$r['document_id'])->first();$bytes=Illuminate\Support\Facades\Storage::disk('local')->get($d->storage_key);if($d->storage_encryption==='laravel')$bytes=Illuminate\Support\Facades\Crypt::decryptString($bytes);if(hash('sha256',$bytes)!==trim($d->sha256)||trim($d->sha256)!==$r['file']['sha256'])throw new RuntimeException('Original hash mismatch');} $s=json_decode(file_get_contents(__DIR__.'/option-B8-documents-'.$o->id.'-progress.json'),true,512,JSON_THROW_ON_ERROR);if(Illuminate\Support\Arr::sortRecursive($values)!==Illuminate\Support\Arr::sortRecursive($s['canonical']))throw new RuntimeException('Recovered canonical mismatch'); $p['opportunities'][]=['id'=>$o->id,'version'=>$o->management_version,'content_revision'=>$ctx['approval']['content_revision'],'state'=>'published','approval_actor'=>24,'publication_actor'=>25,'visibility'=>'internal','original_documents_preserved'=>count($old['resources']['documents']),'new_documents'=>count($s['resources']),'current_contract_recovered'=>true]; } $parcel=$values=null;$o=App\Models\Opportunity::findOrFail(32);$values=app(App\Services\OpportunityManagement::class)->values($o)['canonical'];$parcel=$values['land_rights']['parcels'][0];$measure=$db->selectOne('SELECT ST_Area(ST_SetSRID(ST_GeomFromGeoJSON(?),4326)::geography) area_sqm',[json_encode($parcel['geometry'])]);$p['parcel32']=['declared_area'=>$parcel['area'],'unit'=>$parcel['area_unit'],'measured_area_sqm'=>(float)$measure->area_sqm,'difference_sqm'=>abs($parcel['area']-$measure->area_sqm),'previous_value_1100_preserved_in_baseline'=>true];if(abs($parcel['area']-$measure->area_sqm)>0.01)throw new RuntimeException('Corrected fixture measurement mismatch'); $secondary=json_decode(file_get_contents(__DIR__.'/option-B8-secondary-progress.json'),true,512,JSON_THROW_ON_ERROR);$request=$db->table('desk_requests')->where('id',$secondary['desk_request_id'])->first();if((int)$request->analyst_id!==25||$request->status!=='submitted'||$request->protocol!==$secondary['protocol'])throw new RuntimeException('Desk recovery mismatch'); $p['desk_request']=['id'=>$request->id,'version'=>$request->version,'status'=>$request->status,'analyst_id'=>(int)$request->analyst_id,'protocol_preserved'=>true,'old_analyst24_other_assigned_requests_in_case'=>$db->table('desk_requests')->where('case_id',$request->case_id)->where('analyst_id',24)->count()]; $context=json_decode(file_get_contents(__DIR__.'/option-B8-context-progress.json'),true,512,JSON_THROW_ON_ERROR);$land=App\Models\LandAssistanceCase::findOrFail($context['case_id']);if($land->payload['investor_path_case_id']!==$context['dossier_id']||$land->user_id!==21||$land->status!=='draft')throw new RuntimeException('Explicit context mismatch');$p['linked_land_case']=['id'=>$land->id,'owner'=>21,'dossier_id'=>$context['dossier_id'],'payload_encryption'=>'laravel','status'=>'draft','existing_schema_reused'=>true]; $p['denominators']=['interests'=>$db->table('interest_requests')->whereNull('deleted_at')->count(),'desk_requests'=>$db->table('desk_requests')->whereNotNull('submitted_snapshot')->count(),'businesses'=>app(App\Services\Mne\BusinessRepository::class)->query()->whereNotIn('status',['draft','cancelled'])->count()]; $p['QA_scanner_health']=app(App\Services\Malware\MalwareScanner::class)->health();file_put_contents(__DIR__.'/option-B8-final-current-QA.json',json_encode($p,JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE|JSON_THROW_ON_ERROR));echo json_encode($p,JSON_UNESCAPED_UNICODE).PHP_EOL; }finally{$db->rollBack();}