Files
Investidor-V2/outputs/investmoz-audit-current-20261012/business-country-persistence.php
T
nala 287e991486
tests / ci (push) Waiting to run
oportunidades 7
2026-10-13 11:40:29 +02:00

13 lines
3.5 KiB
PHP

<?php
ini_set('zend.exception_ignore_args','1');set_exception_handler(function(Throwable$e){fwrite(STDERR,json_encode(['error_type'=>$e::class,'line'=>$e->getLine(),'values_recorded'=>false]));exit(1);});
$root=dirname(__DIR__,2);$f=json_decode(file_get_contents(__DIR__.'/business-country-fixture.json'),true,512,JSON_THROW_ON_ERROR);$qa=$f['QA_source'];putenv('STABILITY_QA_MODE=consumers');$app=require $qa.'/tools/portal-stability-runtime.php';$c=config('database.connections.'.config('database.default'));if($c['database']!==$f['target']['database']||(int)$c['port']!==55441)throw new RuntimeException('QA guard');
$db=Illuminate\Support\Facades\DB::connection();$db->beginTransaction();$db->statement('SET TRANSACTION READ ONLY');$actual=(array)$db->selectOne('SELECT current_database() AS database,inet_server_port() AS port');if($actual!==$f['target'])throw new RuntimeException('Actual target differs');
$variants=json_decode(file_get_contents(__DIR__.'/business-country-variants.json'),true,512,JSON_THROW_ON_ERROR);$legacy=json_decode(file_get_contents(__DIR__.'/business-country-after.json'),true,512,JSON_THROW_ON_ERROR);$refs=[$legacy['reference'],$variants['synthetic_references']['ISO'],$variants['synthetic_references']['unknown']];$rows=App\Models\InterestRequest::whereIn('reference',$refs)->get();if(count($rows)!==3)throw new RuntimeException('Records missing');$checks=[];
foreach($rows as$r){if($r->existing_business_id!==$f['business_id'])throw new RuntimeException('Business relation mixed');$receipts=$db->table('interest_submission_receipts')->where('interest_request_id',$r->id)->count();$events=$db->table('outbox_events')->where('aggregate_id',$r->integration_id)->where('event_type','ExpressionOfInterestSubmitted')->get();$consents=$db->table('consents')->where('interest_request_id',$r->id)->get();if($receipts!==1||count($events)!==1||count($consents)!==1||$events[0]->status!=='pending'||$consents[0]->purpose!=='respond_to_interest')throw new RuntimeException('Duplicate or unexpected processing');
$checks[]=['reference'=>$r->reference,'country'=>$r->country,'origin_code'=>$r->metadata['declared_origin_country_code']??null,'receipt_count'=>$receipts,'event_count'=>count($events),'event_still_pending'=>true,'response_consent_count'=>1,'proponent_sharing_not_granted'=>true];
}
if(!in_array('Moçambique',array_column($checks,'country'),true)||!in_array('MZ',array_column($checks,'country'),true))throw new RuntimeException('Legacy values changed');
$country=app(App\Services\CountryCatalogue::class);if(!in_array('moçambique',$country->filterValues('MZ'),true)||!in_array('mozambique',$country->filterValues('MZ'),true)||$country->filterValues('ZZ')!==[])throw new RuntimeException('Catalogue alias invariants');
$payload=$db->table('existing_businesses')->where('id',$f['business_id'])->value('payload');$encrypted=!str_contains($payload,'Anúncio sintético');if(!$encrypted)throw new RuntimeException('Business payload lost encryption');
$db->rollBack();$proof=['at'=>gmdate('c'),'result'=>'passed','target'=>$actual,'read_only'=>true,'active_writes'=>0,'synthetic_records_only'=>$checks,'legacy_country_and_explicit_origin_distinct'=>true,'no_duplicates_per_receipt_event_consent'=>true,'outbox_not_consumed'=>true,'external_notifications_enabled'=>(bool)config('portal.notifications_enabled'),'private_business_payload_remains_encrypted'=>$encrypted,'visual_acceptance_pending'=>true];file_put_contents(__DIR__.'/business-country-persistence.json',json_encode($proof,JSON_PRETTY_PRINT|JSON_THROW_ON_ERROR));echo json_encode($proof);