Files
Investidor-V2/tools/portal-stability-consumer-persistence.php
nala 287e991486
tests / ci (push) Waiting to run
oportunidades 7
2026-10-13 11:40:29 +02:00

16 lines
3.8 KiB
PHP

<?php
// Evidence recovery for existing browser operations; READ ONLY, no new test writes.
$root=dirname(__DIR__);$dir=$root.'/storage/app/private/investmoz-v2/portal-audit';
$read=static fn($p)=>json_decode(file_get_contents($p),true,512,JSON_THROW_ON_ERROR);
$plan=$read($dir.'/portal-stability-latest.json');$qa=$read($plan['source'].'/stability-consumers-qa.json');$cold=$read($dir.'/portal-stability-cold-profile.json');
$connect=static function(array $t):PDO{if((int)$t['port']!==55441||!preg_match('/^(country_candidate|stability_consumers)_\d{8}_\d{6}_test$/D',$t['database']))throw new RuntimeException('QA identity required.');$p=new PDO('pgsql:host=127.0.0.1;port=55441;dbname='.$t['database'],'postgres','',[PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION]);$p->exec('BEGIN READ ONLY');if((int)$p->query('SELECT inet_server_port()')->fetchColumn()!==55441)throw new RuntimeException('QA server required.');return $p;};
$p=$connect($qa['target']);$stmt=$p->prepare("SELECT action,after_data FROM audit_events WHERE source_system='geometry-import' AND entity_id=:id ORDER BY created_at,id");$stmt->execute(['id'=>'db1ac49b-0d6a-4e1c-9e38-39ee117b1790']);$events=[];foreach($stmt->fetchAll(PDO::FETCH_ASSOC) as $event){$data=json_decode($event['after_data'],true,512,JSON_THROW_ON_ERROR);$events[]=['action'=>$event['action'],'created'=>$data['inserted']??null,'reused'=>$data['reused']??null,'reversed'=>$data['reversed']??null,'reused_preserved'=>$data['reused_preserved']??null,'published'=>$data['published']];}
if(count($events)!==2||$events[0]['created']!==0||$events[0]['reused']!==11||$events[1]['reversed']!==0||$events[1]['reused_preserved']!==11)throw new RuntimeException('Geometry apply/reversal evidence differs.');
$baselineLink=$read($dir.'/portal-stability-consumers-latest.json');$baseline=$read($baselineLink['path']);$geometryRows=$p->query('SELECT row_to_json(t)::text FROM geo_geometries t ORDER BY row_to_json(t)::text')->fetchAll(PDO::FETCH_COLUMN);$geometryState=['count'=>count($geometryRows),'sha256'=>hash('sha256',implode("\n",$geometryRows))];if($geometryState!==$baseline['tables']['"public"."geo_geometries"'])throw new RuntimeException('Geometry bytes/associations changed from exact consumer QA baseline.');$count=count($geometryRows);
$resource=$p->query("SELECT payload->>'title' AS title,version FROM opportunity_location_drafts WHERE id='f23efcc2-dbbb-44cc-bdb2-9e5be18b877c'")->fetch(PDO::FETCH_ASSOC);if(!$resource||(int)$resource['version']!==2||!str_contains($resource['title'],'edited'))throw new RuntimeException('Resource edit was not recovered.');$p->exec('ROLLBACK');
$p=$connect($cold['target']);$tables=(int)$p->query("SELECT count(*) FROM pg_tables WHERE schemaname NOT IN ('pg_catalog','information_schema')")->fetchColumn();
$events040=$p->query("SELECT action,count(*) AS count FROM audit_events WHERE source_system='portal-profile-installation' GROUP BY action ORDER BY action")->fetchAll(PDO::FETCH_ASSOC);
$pair=$p->query('SELECT first_user_id,second_user_id FROM portal_superuser_pair')->fetchAll(PDO::FETCH_ASSOC);if(count($pair)!==1||(int)$pair[0]['first_user_id']!==15||(int)$pair[0]['second_user_id']!==16||$tables!==295)throw new RuntimeException('Explicit QA bootstrap differs.');$p->exec('ROLLBACK');
$receipt=['result'=>'passed','at'=>gmdate('c'),'consumer_target'=>$qa['target'],'geometry_import_events'=>$events,'original_ine_geometries_preserved'=>$count,'geometry_rows_sha256_preserved'=>$geometryState['sha256'],'recoverable_resource_version'=>(int)$resource['version'],'cold040_target'=>$cold['target'],'cold040_tables'=>$tables,'cold040_unique_events'=>$events040,'synthetic_pair_recovered'=>$pair,'scope'=>'Technical QA only; no publication or active profile assignment','active_writes'=>0];
file_put_contents($dir.'/portal-stability-consumer-persistence.json',json_encode($receipt,JSON_PRETTY_PRINT|JSON_THROW_ON_ERROR));echo json_encode($receipt).PHP_EOL;