48 lines
5.8 KiB
PHP
48 lines
5.8 KiB
PHP
<?php
|
|
ini_set('zend.exception_ignore_args','1');putenv('STABILITY_QA_MODE=consumers');
|
|
$b5Root=dirname(__DIR__,2);$b5QA=$b5Root.'/storage/app/private/investmoz-v2/portal-audit/portal-stability-source-20261011_083742';
|
|
$app=require $b5QA.'/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-B5-finite-inventory.json'),true,512,JSON_THROW_ON_ERROR);
|
|
$rev=json_decode(file_get_contents(__DIR__.'/option-B5-coeditor-revoke-progress.json'),true,512,JSON_THROW_ON_ERROR);
|
|
$land=json_decode(file_get_contents(__DIR__.'/option-B5-land-entity-progress.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,['users','portal_role_assignments'],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;
|
|
}
|
|
// The only user-row change expected from revocation is the access revision of QA22.
|
|
$rows=$db->table('users')->get();$adjusted=$rows->map(function($r){if((int)$r->id===22)$r->portal_access_revision--;return json_encode($r,JSON_THROW_ON_ERROR);})->all();sort($adjusted,SORT_STRING);
|
|
if(!hash_equals($pre['protected_tables']['users']['sha256'],hash('sha256',implode("\n",$adjusted))))throw new RuntimeException('Unexpected user data change');
|
|
$old=$db->table('portal_role_assignments')->where('id',$rev['revoked_grant_id'])->sole();if(!$old->revoked_at)throw new RuntimeException('Revocation history lost');
|
|
$new=$db->table('portal_role_assignments')->where('request_id',$rev['new_request_id'])->sole();
|
|
if((int)$new->user_id!==22||$new->role!=='promoter'||$new->organization_id!==$old->organization_id||json_decode($new->opportunity_types,true)!==['investment_project']||$new->revoked_at!==null||(int)$new->approved_by!==27)throw new RuntimeException('Scope changed or duplicate assignment');
|
|
if($db->table('portal_role_assignments')->count()!==$pre['protected_tables']['portal_role_assignments']['count']+1)throw new RuntimeException('Unexpected grant count');
|
|
$revAudit=$db->table('audit_events')->where('source_system','portal-profiles-v1')->where('action','role_revoked')->where('after_data->assignment_id',$old->id)->count();
|
|
if($revAudit!==1)throw new RuntimeException('Repeated revocation duplicated audit');
|
|
$proof['revocation']=['one_revoked_assignment'=>$old->id,'new_scoped_assignment'=>$new->id,'independent_approver'=>27,'user_revision_delta'=>1,'role_revoked_audit_count'=>1,'repeat_did_not_revoke_again'=>true,'opportunities_and_other_roles_not_reassigned'=>true];
|
|
$case=App\Models\LandAssistanceCase::findOrFail($land['id']);$interest=App\Models\InterestRequest::findOrFail($case->interest_request_id);
|
|
if($interest->investor_type!=='empresa'||$interest->country!=='ZA'||($interest->metadata['declared_origin_country_code']??null)!=='PT'||($interest->metadata['applicant_category']??null)!=='entity')throw new RuntimeException('Entity fields lost');
|
|
$counts=['case_interest'=>$db->table('interest_requests')->where('metadata->land_case_id',$case->id)->count(),'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(),
|
|
'support_event'=>$db->table('land_assistance_events')->where('case_id',$case->id)->where('action','support_requested')->count()];
|
|
if(array_filter($counts,fn($count)=>$count!==1))throw new RuntimeException('Duplicate support operations');
|
|
$proof['entity']=['case_id'=>$case->id,'interest_id'=>$interest->id,'category'=>'entity','intake_type'=>'empresa','country'=>'ZA','origin'=>'PT','single_records'=>$counts,'private_payload_encrypted'=>!str_contains($case->getRawOriginal('payload'),'Entidade fictícia')];
|
|
$manager=null;
|
|
// Explicit manager lookup from the same sanitized correspondence used by the HTTP harness.
|
|
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']);
|
|
if(!$manager)throw new RuntimeException('Named QA manager required');
|
|
$stats=app(App\Services\DeclaredOriginStatistics::class)->forManager($manager);$actual=array_map(fn($rows)=>array_sum(array_column($rows,'count')),$stats);
|
|
$expected=['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!==$expected)throw new RuntimeException('Statistics denominator mismatch');
|
|
$proof['statistic_denominators']=['actual'=>$actual,'SQL_expected'=>$expected,'collections_not_summed_as_unique_people'=>true];
|
|
$proof['result']='passed';$dest=__DIR__.'/option-B5-final-QA.json';if(is_file($dest))throw new RuntimeException('Preserve final 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();}
|