9 lines
3.9 KiB
PHP
9 lines
3.9 KiB
PHP
<?php
|
|
ini_set('zend.exception_ignore_args','1');putenv('STABILITY_QA_MODE=consumers');$b7Root=dirname(__DIR__,2);$b7QA=$b7Root.'/storage/app/private/investmoz-v2/portal-audit/portal-stability-source-20261011_083742';$app=require$b7QA.'/tools/portal-stability-runtime.php';$db=Illuminate\Support\Facades\DB::connection();$t=(array)$db->selectOne('SELECT current_database() AS database,inet_server_port() AS port');if($t!==['database'=>'stability_consumers_20261011_084534_test','port'=>55441])throw new RuntimeException('QA only');$db->beginTransaction();$db->statement('SET TRANSACTION READ ONLY');
|
|
try{$s=json_decode(file_get_contents(__DIR__.'/option-B7-three-actor-progress.json'),true);$old=json_decode(file_get_contents(__DIR__.'/option-B7-business-progress.json'),true);$pre=json_decode(file_get_contents(__DIR__.'/option-B7-business-preflight.json'),true);$ids=[$s['id'],$old['id']];$protected=[];
|
|
foreach($pre['protected_tables']as$table=>$expected){$q=$db->table($table);$q=match($table){'existing_businesses'=>$q->whereNotIn('id',$ids),'business_workflow_transitions'=>$q->whereNotIn('existing_business_id',$ids),'existing_business_revisions'=>$q->whereNotIn('business_id',$ids),'tasks'=>$q->where(fn($v)=>$v->whereNull('existing_business_id')->orWhereNotIn('existing_business_id',$ids)),'outbox_events'=>$q->whereNotIn('aggregate_id',$ids),default=>$q};$rows=$q->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('Unrelated rows changed');$protected[]=$table;}
|
|
$b=App\Models\ExistingBusiness::findOrFail($s['id']);if($b->version_no!==8||$b->status!=='published'||$b->owner_user_id!==21)throw new RuntimeException('Final state');$events=$db->table('business_workflow_transitions')->where('existing_business_id',$b->id)->orderBy('created_at')->get();if($events->count()!==7||$events->where('to_status','published')->count()!==1)throw new RuntimeException('Duplicate transition');foreach($events as$e)if((json_decode($e->metadata,true)['authorization_mode']??null)!=='profiles-v1-company-sale')throw new RuntimeException('Policy mode missing');foreach(['approval_l2','approved']as$state)if((int)$events->where('to_status',$state)->sole()->actor_id!==24)throw new RuntimeException('Same validator not demonstrated');if((int)$events->where('to_status','published')->sole()->actor_id!==25)throw new RuntimeException('Publisher independence');
|
|
$revisions=$db->table('existing_business_revisions')->where('business_id',$b->id)->get();if($revisions->count()!==8)throw new RuntimeException('Revisions');foreach($revisions as$r)if(!hash_equals($r->sha256,hash('sha256',Illuminate\Support\Facades\Crypt::decryptString($r->snapshot))))throw new RuntimeException('Cipher/hash changed');$older=App\Models\ExistingBusiness::findOrFail($old['id']);if($older->version_no!==16||$older->status!=='published')throw new RuntimeException('Old case changed');
|
|
$proof=['at'=>gmdate('c'),'target'=>$t,'SQL_read_only'=>true,'active_writes'=>0,'browser_observed'=>false,'result'=>'passed','id'=>$b->id,'version'=>8,'encrypted_revisions'=>8,'transitions'=>7,'single_publication'=>true,'approval_actor'=>24,'publication_actor'=>25,'mode_in_all_transitions'=>'profiles-v1-company-sale','old_case16_preserved'=>true,'unrelated_tables_preserved'=>$protected,'current_denominators'=>['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()]];$p=__DIR__.'/option-B7-three-actor-SQL.json';if(is_file($p))throw new RuntimeException('Preserve evidence');file_put_contents($p,json_encode($proof,JSON_PRETTY_PRINT|JSON_THROW_ON_ERROR));echo json_encode($proof).PHP_EOL;
|
|
}finally{$db->rollBack();}
|