Files
Investidor-V2/outputs/investmoz-audit-current-20261012/option-B6-final-QA.php
T
nala ba1c0340ea
tests / ci (push) Canceled after 0s
oportunidades 8
2026-10-14 08:25:30 +02:00

44 lines
5.8 KiB
PHP

<?php
ini_set('zend.exception_ignore_args','1');putenv('STABILITY_QA_MODE=consumers');
$b6Root=dirname(__DIR__,2);$b6QA=$b6Root.'/storage/app/private/investmoz-v2/portal-audit/portal-stability-source-20261011_083742';
$app=require $b6QA.'/tools/portal-stability-runtime.php';$db=Illuminate\Support\Facades\DB::connection();
$target=(array)$db->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 only');
$db->beginTransaction();$db->statement('SET TRANSACTION READ ONLY');
try{
$pre=json_decode(file_get_contents(__DIR__.'/option-B6-preflight.json'),true,512,JSON_THROW_ON_ERROR);
$proof=['at'=>gmdate('c'),'target'=>$target,'SQL_read_only'=>true,'active_writes'=>0,'browser_observed'=>false,'preserved_tables'=>[]];
foreach($pre['protected_tables']as$t=>$expected){
if(in_array($t,['opportunities','tasks','organizations','investment_submissions','outbox_events'],true))continue;
$rows=$db->table($t)->get();$bytes=$rows->map(fn($r)=>json_encode($r,JSON_THROW_ON_ERROR))->all();sort($bytes,SORT_STRING);
if($rows->count()!==$expected['count']||!hash_equals($expected['sha256'],hash('sha256',implode("\n",$bytes))))throw new RuntimeException('Protected table changed: '.$t);
$proof['preserved_tables'][]=$t;
}
$state=json_decode(file_get_contents(__DIR__.'/option-B6-company-submission-progress.json'),true,512,JSON_THROW_ON_ERROR);
$submission=App\Models\InvestmentSubmission::findOrFail($state['submission_id']);$payload=$submission->payload;
if($submission->status!=='submitted'||$payload['residence_country_code']!=='PT'||$payload['incorporation_country_code']!=='FR'||$payload['declared_origin_country_code']!=='BR'||$payload['organization_country_snapshot']['organization_version']!==2)throw new RuntimeException('Submitted countries changed');
$interest=App\Models\InterestRequest::where('reference',$state['reference'])->sole();
$counts=['receipt'=>$db->table('interest_submission_receipts')->where('interest_request_id',$interest->id)->count(),'consent'=>$db->table('consents')->where('interest_request_id',$interest->id)->count(),'outbox'=>$db->table('outbox_events')->where('aggregate_id',$interest->integration_id)->count()];
if(array_filter($counts,fn($n)=>$n!==1))throw new RuntimeException('Duplicate submission effects');
$org=$db->table('organizations')->where('id','99964753-2632-4658-a687-8ebc6a178296')->sole();
if($org->incorporation_country_code!=='ZA'||(int)$org->version_no!==5)throw new RuntimeException('Synthetic master not returned');
$company=$db->table('investment_company_declarations')->where('id',$state['company_id'])->sole();$cv=json_decode(Illuminate\Support\Facades\Crypt::decryptString($company->payload),true);
if($cv['incorporation_country_code']!=='FR'||$cv['organization_country_snapshot']['organization_version']!==2)throw new RuntimeException('Company snapshot rewritten');
$proof['countries']=['submission_id'=>$submission->id,'version'=>$submission->version,'residence'=>'PT','constitution'=>'FR','origin'=>'BR','snapshot_organization_version'=>2,'master_country'=>'ZA','master_version'=>5,'single_records'=>$counts,'private_payload_encrypted'=>!str_contains($submission->getRawOriginal('payload'),'Entidade sintética')];
$o=App\Models\Opportunity::findOrFail(34);$p=app(App\Services\OpportunityManagement::class)->values($o)['canonical'];$expected=json_decode(file_get_contents(__DIR__.'/option-B6-partnership-obligations-progress.json'),true);
if(Illuminate\Support\Arr::sortRecursive($p)!==Illuminate\Support\Arr::sortRecursive($expected['canonical']))throw new RuntimeException('Partnership contract changed');
$old=collect($pre['operational_records'])->firstWhere('id',34);$reviews=$o->workflow_context['reviews'];
foreach(['hash','actor_id','at']as$key)if($reviews['corporate_screening'][$key]!==$old['reviews']['corporate_screening'][$key])throw new RuntimeException('Unaffected signature rewritten');
$condition=$o->workflow_context['conditions']['8165f88d-e8d4-4ebe-84be-1f1457c63945']??null;
if(!$condition||($condition['status']??null)!=='resolved')throw new RuntimeException('Prior legal condition not resolved');
if(app(App\Services\PortalProfileAccess::class)->state($o)!=='published'||($o->workflow_context['publication']['visibility']??null)!=='internal')throw new RuntimeException('Publication scope changed');
$proof['partnership']=['id'=>34,'state'=>'published','visibility'=>'internal','changed_text_obligations_recovered'=>true,'unaffected_corporate_signature_preserved'=>true,'prior_legal_condition_resolved'=>true,'documents_and_financial_periods_preserved'=>true];
$manager=null;foreach(json_decode(file_get_contents(__DIR__.'/QA-credential-correspondence.json'),true)['candidates']as$c)if($c['source_file']==='i0-qa-actor-private.json')$manager=App\Models\User::findOrFail($c['user_id']);
$actual=array_map(fn($rows)=>array_sum(array_column($rows,'count')),app(App\Services\DeclaredOriginStatistics::class)->forManager($manager));
$expectedCounts=['interests'=>$db->table('interest_requests')->whereNull('deleted_at')->count(),'desk'=>$db->table('desk_requests')->whereNotIn('status',['draft','cancelled'])->count(),'businesses'=>app(App\Services\Mne\BusinessRepository::class)->query()->whereNotIn('status',['draft','cancelled'])->count()];
if($actual!==$expectedCounts||$actual!==['interests'=>17,'desk'=>1,'businesses'=>2])throw new RuntimeException('Denominator mismatch');
$proof['statistic_denominators']=['actual'=>$actual,'SQL_expected'=>$expectedCounts,'not_unique_people'=>true];
$proof['result']='passed';$dest=__DIR__.'/option-B6-final-QA.json';if(is_file($dest))throw new RuntimeException('Preserve evidence');
file_put_contents($dest,json_encode($proof,JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE|JSON_THROW_ON_ERROR));echo json_encode($proof,JSON_UNESCAPED_UNICODE).PHP_EOL;
}finally{$db->rollBack();}