selectOne('SELECT current_database() AS database, inet_server_port() AS port'); if ($target !== ['database'=>'stability_consumers_20261011_084534_test','port'=>55441]) { throw new RuntimeException('QA isolada obrigatória.'); } $db->beginTransaction(); $db->statement('SET TRANSACTION READ ONLY'); try { $record = App\Models\Opportunity::findOrFail(32); $payload = app(App\Services\OpportunityManagement::class)->values($record)['canonical']; $reference = data_get($payload, 'land_rights.required_authorizations.0.document_id'); $table = app(App\Services\OpportunityResources::class)->table('documents'); $resource = $reference ? $db->table($table)->where('id',$reference)->where('opportunity_id',32)->first() : null; $file = $resource ? $db->table('documents')->where('id',$resource->document_id)->first() : null; $apiProof = json_decode(file_get_contents(__DIR__.'/case32-editor-recovery-saved-503-HTTP-QA-20261014.json'),true,512,JSON_THROW_ON_ERROR); if ($apiProof['result'] !== 'passed' || $apiProof['response']['version'] !== (int)$record->management_version || $apiProof['response']['validation_error_paths'] !== ['canonical.land_rights.required_authorizations.0.document_id']) { throw new RuntimeException('Conferência deve corresponder à leitura HTTP autenticada.'); } $currentDocs = $payload['documents'] ?? []; $submittedDocs = data_get($record->workflow_context, 'submission.payload.documents', []); $allIds = $db->table($table)->where('opportunity_id',32)->whereNull('deleted_at')->pluck('id')->all(); $receipt = ['at'=>gmdate('c'),'base_review'=>'396c691930bc','target'=>$target,'SQL_read_only'=>true, 'case'=>32,'version'=>(int)$record->management_version, 'validation_field'=>'canonical.land_rights.required_authorizations.0.document_id', 'validation_source'=>'Leitura HTTP autenticada já registada; nenhuma repetição da verificação binária no CLI.', 'rule_source'=>'OpportunityCategoryFields::validate, referência a recurso incluído no contrato.', 'reference_present'=>is_string($reference)&&$reference!=='', 'resource_in_this_opportunity'=>$resource!==null,'resource_logically_deleted'=>$resource?->deleted_at!==null, 'reference_selected_in_current_documents'=>in_array($reference,$currentDocs,true), 'reference_selected_in_last_submission'=>in_array($reference,$submittedDocs,true), 'current_selected_documents_count'=>count($currentDocs),'last_submission_selected_documents_count'=>count($submittedDocs), 'available_resources_count'=>count($allIds), 'original_available'=>$file!==null&&$file->deleted_at===null, 'original_status'=>$file?->status,'recorded_scan_status'=>$file?->malware_scan_status, 'recorded_scan_hash_matches'=>$file!==null&&hash_equals(trim($file->sha256),trim((string)$file->malware_scanned_sha256)), 'synthetic_filename'=>$file && str_contains($file->file_name,'synthetic') ? $file->file_name : null, 'field_contents_or_authentication_exported'=>false,'QA_database_changes'=>0,'active_changes'=>0]; file_put_contents($proofPath,json_encode($receipt,JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE|JSON_THROW_ON_ERROR).PHP_EOL); echo json_encode($receipt,JSON_THROW_ON_ERROR).PHP_EOL; } finally { $db->rollBack(); }