Files
Investidor-V2/outputs/investmoz-negocios-classificacao-QA-20261016/verify-preservation.php
T
nala 6a76aac80f
tests / ci (push) Canceled after 0s
versao compilada 1
2026-10-16 09:17:28 +02:00

31 lines
5.6 KiB
PHP

<?php
ini_set('zend.exception_ignore_args','1');require __DIR__.'/boot-QA.php';
set_exception_handler(function(Throwable $e){fwrite(STDERR,'Preservation check stopped: '.$e::class.' line '.$e->getLine().PHP_EOL);exit(1);});
$reference=new PDO('pgsql:host=127.0.0.1;port=55441;dbname=stability_consumers_20261011_084534_test','postgres','',[PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION]);
$clone=Illuminate\Support\Facades\DB::connection()->getPdo();
foreach([$reference,$clone]as$db){$db->exec('BEGIN ISOLATION LEVEL REPEATABLE READ READ ONLY');$db->exec("SET LOCAL TIME ZONE 'UTC'");}
try{
if((int)$reference->query('SELECT inet_server_port()')->fetchColumn()!==55441||$reference->query('SELECT current_database()')->fetchColumn()!=='stability_consumers_20261011_084534_test'||$clone->query('SELECT current_database()')->fetchColumn()!=='business_classification_20261016_test')throw new RuntimeException('QA pair identity');
$id='172aa874-98fc-4bf6-b78f-d2e9a386d345';
$record=function(PDO$db)use($id){$q=$db->prepare('SELECT row_to_json(t)::text FROM existing_businesses t WHERE id=?');$q->execute([$id]);return json_decode($q->fetchColumn(),true);};
$before=$record($reference);$after=$record($clone);
if($before['status']!=='published'||$before['version_no']!==12||$after['status']!=='published'||$after['version_no']!==26)throw new RuntimeException('Primary case versions/state');
$exclude=['version_no'=>true,'updated_at'=>true];if(array_diff_key($before,$exclude)!==array_diff_key($after,$exclude))throw new RuntimeException('Primary content or identity changed');
$tables=[];foreach(['portal_role_assignments','portal_superuser_pair','existing_business_reviews','business_workflow_transitions','existing_business_objects','existing_business_mandates','existing_business_locations','documents']as$table){
$sql='SELECT row_to_json(t)::text FROM "'.$table.'" t ORDER BY row_to_json(t)::text';$a=$reference->query($sql)->fetchAll(PDO::FETCH_COLUMN);$b=$clone->query($sql)->fetchAll(PDO::FETCH_COLUMN);
if($a!==$b)throw new RuntimeException('Unrelated table changed: '.$table);$tables[$table]=['rows'=>count($a),'sha256'=>hash('sha256',implode("\n",$a))];
}
$sql='SELECT row_to_json(t)::text FROM existing_business_revisions t ORDER BY row_to_json(t)::text';$a=$reference->query($sql)->fetchAll(PDO::FETCH_COLUMN);$b=$clone->query($sql)->fetchAll(PDO::FETCH_COLUMN);
if(array_diff($a,$b))throw new RuntimeException('Prior immutable revisions changed');
$q=$reference->prepare('SELECT row_to_json(t)::text FROM existing_business_revisions t WHERE business_id=? ORDER BY version_no');$q->execute([$id]);$refRevisions=$q->fetchAll(PDO::FETCH_COLUMN);
$q=$clone->prepare('SELECT row_to_json(t)::text FROM existing_business_revisions t WHERE business_id=? AND version_no<=12 ORDER BY version_no');$q->execute([$id]);if($refRevisions!==$q->fetchAll(PDO::FETCH_COLUMN))throw new RuntimeException('Primary v1-v12 history changed');
$refIds=$reference->query('SELECT id FROM existing_businesses ORDER BY id')->fetchAll(PDO::FETCH_COLUMN);if($refIds!==$clone->query('SELECT id FROM existing_businesses ORDER BY id')->fetchAll(PDO::FETCH_COLUMN))throw new RuntimeException('Parallel business record created');
$columns="SELECT table_schema,table_name,column_name,data_type FROM information_schema.columns WHERE table_schema NOT LIKE 'pg_%' AND table_schema<>'information_schema' ORDER BY table_schema,table_name,ordinal_position";
if($reference->query($columns)->fetchAll(PDO::FETCH_ASSOC)!==$clone->query($columns)->fetchAll(PDO::FETCH_ASSOC))throw new RuntimeException('Schema changed');
$q=$reference->prepare('SELECT count(*) FROM existing_business_document_links WHERE existing_business_id=?');$q->execute([$id]);if((int)$q->fetchColumn()!==0)throw new RuntimeException('Reference QA links changed');
$q=$clone->prepare('SELECT count(*) FROM existing_business_document_links WHERE existing_business_id=?');$q->execute([$id]);if((int)$q->fetchColumn()!==1)throw new RuntimeException('Synthetic support link count');
$migrationSql='SELECT row_to_json(t)::text FROM migrations t ORDER BY id';if($reference->query($migrationSql)->fetchAll(PDO::FETCH_COLUMN)!==$clone->query($migrationSql)->fetchAll(PDO::FETCH_COLUMN))throw new RuntimeException('Migrations changed');
$proof=['target'=>$target,'reference_target'=>'stability_consumers_20261011_084534_test:55441','reference_case_published_v12_intact'=>true,'reference_primary_revisions'=>count($refRevisions),'reference_primary_revision_sha256'=>hash('sha256',implode("\n",$refRevisions)),'primary_clone_status'=>'published','primary_clone_version'=>26,'primary_content_UUID_slug_confidentiality_payload_unchanged'=>true,'only_primary_fields_changed'=>['version_no','updated_at'],'all_prior_immutable_revisions_preserved'=>true,'additional_revision_count'=>count($b)-count($a),'business_UUID_set_unchanged'=>true,'business_record_count'=>count($refIds),'schema_and_migrations_unchanged'=>true,'role_workflow_documents_unchanged'=>$tables,'synthetic_document_link_added_only_in_clone'=>1,'new_uploads'=>0,'new_businesses'=>0,'active_changes'=>0,'accepted_tests_repeated'=>false,'secondary_draft_fixture'=>'Existing draft payload initialized synthetically in clone because its pre-QA ciphertext key is unavailable; original ciphertext retained privately; compatibility proof uses actual prior code. No active key imported.'];
if(is_file(__DIR__.'/PRESERVACAO-FINAL.json'))throw new RuntimeException('Preserve proof');file_put_contents(__DIR__.'/PRESERVACAO-FINAL.json',json_encode($proof,JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE).PHP_EOL);echo json_encode(array_diff_key($proof,['role_workflow_documents_unchanged'=>true])).PHP_EOL;
}finally{foreach([$reference,$clone]as$db)$db->exec('ROLLBACK');}