20 lines
10 KiB
PHP
20 lines
10 KiB
PHP
<?php
|
|
$host=DB::connection();$url=fn($kind,$id)=>$base.'/entities/'.$kind.'/'.$id;$enter('issuer',1);
|
|
$nativeFingerprint=fn()=>hash('sha256',json_encode([$db->table('suppliers')->orderBy('id')->get(),$db->table('audit_logs')->orderBy('id')->get(),$db->table('budget_entries')->orderBy('id')->get()]));$nativeBefore=$nativeFingerprint();$associations=$host->table('identity_audit')->where('action','module.record.associated')->count();$pending=(array)$host->table('a_clients')->where('id',$f['pending_client'])->first();
|
|
$preview=function($role,$kind,$id,$key,$operation=null,$i=0)use($call,$url){$r=$call($role,$url($kind,$id),null,$i);if($r['status']!==200)throw new RuntimeException('Entity state unavailable');return $call($role,$url($kind,$id).'/preview',['operation_key'=>$operation??(string)Illuminate\Support\Str::uuid(),'revision'=>$r['data']['revision'],'catalogue_version'=>$r['data']['catalogue_version'],'territory_key'=>$key,'reason'=>'Indicação territorial explícita, exclusivamente QA.'],$i);};$commit=fn($role,$kind,$id,$cut,$i=0)=>$call($role,$url($kind,$id).'/confirm',['preview'=>$cut],$i);
|
|
$ok($host->table('geo_territories')->count()===20407&&$host->table('geo_locations')->count()===0,'all source rows imported without business locations');$r=$call('actor',$base.'/catalogue');$ok($r['status']===200&&count($r['data']['records']['data'])===11,'province reference page is accessible');$provinces=$r['data']['records']['data'];$province=$provinces[0]['key'];$otherProvince=$provinces[1]['key'];$version=$r['data']['version'];$r=$call('actor',$base.'/catalogue?parent='.urlencode($province));$ok($r['status']===200&&$r['data']['records']['data'][0]['level']===2,'cascade follows explicit parent');$ok($call('actor',$base.'/catalogue?page=0')['status']===422,'invalid page is rejected');$ok($call('actor',$base.'/catalogue',null,0,['X-SGF-Context'=>'old'])['status']===409,'stale general reference context is refused');
|
|
$parent=$host->table('geo_territories as t')->join('geo_territories as p','p.territory_key','=','t.parent_key')->where('p.selectable',true)->groupBy('t.parent_key')->havingRaw('count(*)>25')->value('t.parent_key');$a=$call('actor',$base.'/catalogue?parent='.urlencode($parent).'&page=1');$b=$call('actor',$base.'/catalogue?parent='.urlencode($parent).'&page=2');$ok(count($a['data']['records']['data'])===25&&count($b['data']['records']['data'])>0&&array_intersect(array_column($a['data']['records']['data'],'key'),array_column($b['data']['records']['data'],'key'))===[],'server catalogue pages25 are disjoint');$r=$call('actor',$base.'/catalogue?search=QUARTEL%207A');$ok($r['status']===200&&in_array('7A',array_column(array_column($r['data']['records']['data'],'codes'),'village_quarter'),true),'alphanumeric territorial code survives import and search');
|
|
$ok($call('actor','/geography/company/'.$f['company'])['status']===200,'common location screen served');$ok($call('actor',$url('company',$f['company']+999))['status']===403,'foreign company ID refused');$ok($call('actor',$url('unit',$f['foreign_unit']))['status']===403,'another active unit cannot be inferred');$ok($preview('validator','company',$f['company'],$province)['status']===403,'read permission does not grant editing');$bad=$host->table('geo_territories')->where('selectable',false)->value('territory_key');$ok($preview('actor','company',$f['company'],$bad)['status']===422,'source ambiguities cannot be assigned');
|
|
$key=(string)Illuminate\Support\Str::uuid();$p=$preview('actor','company',$f['company'],$province,$key);$cut=$p['data']['preview'];$alternate=$preview('actor','company',$f['company'],$otherProvince,$key)['data']['preview'];$ok($p['status']===200&&$p['data']['impact']['before']===null&&$p['data']['impact']['after']['version']===$version&&$host->table('geo_locations')->count()===0,'preview is read only and presents the exact source version');$ok($commit('actor','company',$f['company'],$cut.'bad')['status']===409,'tampered preview refused');
|
|
$host->unprepared("CREATE FUNCTION public.geo_qa_fail() RETURNS trigger LANGUAGE plpgsql AS \$\$ BEGIN RAISE EXCEPTION 'synthetic geographic history failure'; END \$\$; CREATE TRIGGER geo_qa_fail BEFORE INSERT ON geo_location_history FOR EACH ROW EXECUTE FUNCTION public.geo_qa_fail()");try{$ok($commit('actor','company',$f['company'],$cut)['status']===500,'history failure aborts confirmation');$ok($host->table('geo_locations')->count()===0&&$host->table('geo_commands')->count()===0,'history failure rolls back location and receipt');}finally{$host->unprepared('DROP TRIGGER geo_qa_fail ON geo_location_history; DROP FUNCTION public.geo_qa_fail()');}
|
|
$r=$commit('actor','company',$f['company'],$cut);$ok($r['status']===201&&$r['data']['revision']===1,'same preview recovers after failure removal');$ok($commit('actor','company',$f['company'],$cut)['status']===200&&$host->table('geo_location_history')->count()===1,'replay preserves one location and history entry');$ok($commit('actor','company',$f['company'],$alternate)['status']===409,'same key cannot change territory');
|
|
$p1=$preview('actor','company',$f['company'],$otherProvince);$p2=$preview('issuer','company',$f['company'],$province,null,1);$responses=GuzzleHttp\Promise\Utils::unwrap([$clients[0]->postAsync($url('company',$f['company']).'/confirm',$options('actor',0,['preview'=>$p1['data']['preview']])),$clients[1]->postAsync($url('company',$f['company']).'/confirm',$options('issuer',1,['preview'=>$p2['data']['preview']]))]);$statuses=array_map(fn($r)=>$r->getStatusCode(),$responses);sort($statuses);$ok($statuses===[201,409]&&$host->table('geo_location_history')->count()===2,'independent editors commit once and refuse stale concurrent version');
|
|
$p=$preview('actor','unit',$f['unit'],$province);$grant=$host->table('permission_grants')->where($f['scope'])->where('user_id',$f['actor'])->where('permission','unit.edit')->first();$host->table('permission_grants')->where('id',$grant->id)->delete();try{$ok($commit('actor','unit',$f['unit'],$p['data']['preview'])['status']===403,'editing right revalidated at confirmation');}finally{$host->table('permission_grants')->insert((array)$grant);}$ok($commit('actor','unit',$f['unit'],$p['data']['preview'])['status']===201,'unit uses the shared location mechanism');
|
|
$p=$preview('actor','company',$f['company'],$province);$host->table('companies')->where('id',$f['company'])->update(['name'=>'Empresa QA revista']);$ok($commit('actor','company',$f['company'],$p['data']['preview'])['status']===409,'changed entity invalidates geographic preview');$p=$preview('actor','company',$f['company'],$province);$host->table('geo_versions')->insert(['source_version'=>str_repeat('a',64),'metadata'=>'{}']);$host->table('geo_catalogue_state')->where('id',1)->update(['source_version'=>str_repeat('a',64)]);try{$ok($commit('actor','company',$f['company'],$p['data']['preview'])['status']===409,'changed active reference requires renewed conference');}finally{$host->table('geo_catalogue_state')->where('id',1)->update(['source_version'=>$version]);}
|
|
$p=$preview('actor','company',$f['company'],$province);$enter('actor',0,['module'=>'commercial']);$ok($commit('actor','company',$f['company'],$p['data']['preview'])['status']===409,'new context generation invalidates general company preview');$ok($call('actor',$url('client',$f['pending_client']))['status']===403,'pending unassociated client cannot be reached');$p=$preview('actor','client',$f['client'],$province);$ok($p['status']===200&&$commit('actor','client',$f['client'],$p['data']['preview'])['status']===201,'associated client receives explicitly selected location');$enter('issuer',0,['module'=>'commercial']);$ok($call('issuer',$url('client',$f['client']))['status']===200&&$preview('issuer','client',$f['client'],$province)['status']===403,'client consultation does not imply editing');$r=$call('actor',$base.'/segments/client?province='.$provinces[0]['codes']['province']);$ok($r['status']===200&&$r['data']['data'][0]['entity_id']===$f['client'],'client segmentation applies explicit territorial filter');$ok(count($call('actor',$base.'/segments/client?province=ZZ')['data']['data'])===0,'absent filter code does not fabricate matches');
|
|
$enter('actor',0,['module'=>'purchasing']);$p=$preview('actor','supplier',$n['supplier_ids'][0],$province);$ok($p['status']===200&&$commit('actor','supplier',$n['supplier_ids'][0],$p['data']['preview'])['status']===201,'supplier location reuses original administrative authority');$ok($call('validator',$url('supplier',$n['supplier_ids'][0]))['status']===403,'warehouse cannot inspect supplier location');$ok($call('actor',$url('supplier',$n['foreign_supplier']))['status']===404,'foreign native supplier is inaccessible');$r=$call('actor',$base.'/segments/supplier?province='.$provinces[0]['codes']['province']);$ok($r['status']===200&&count($r['data']['data'])===1,'supplier segmentation rechecks native visibility');$enter('actor',1,['foreign'=>1]);$ok($call('actor',$url('supplier',$n['supplier_ids'][0]),null,1)['status']===403,'unmapped unit cannot reuse supplier location');
|
|
$p=$preview('actor','supplier',$n['supplier_ids'][0],null);$r=$commit('actor','supplier',$n['supplier_ids'][0],$p['data']['preview']);$ok($r['status']===201&&$r['data']['selection']===null,'explicit removal assigns no replacement territory');$h=$call('actor',$url('supplier',$n['supplier_ids'][0]).'/history?page=1');$ok($h['status']===200&&$h['data']['per_page']===15&&$h['data']['total']===2&&$h['data']['data'][0]['before']['selection']!==null&&$h['data']['data'][0]['after']['selection']===null,'paged history preserves before after author reason and date');
|
|
foreach(['geo_location_history','geo_territories']as$table){try{$host->table($table)->delete();throw new RuntimeException('Immutable data deleted');}catch(Illuminate\Database\QueryException $e){$ok(str_contains($e->getMessage(),'APPEND_ONLY'),$table.' refuses deletion');}}
|
|
$ok((array)$host->table('a_clients')->where('id',$f['pending_client'])->first()===$pending&&$host->table('identity_audit')->where('action','module.record.associated')->count()===$associations,'pending client and module associations are unchanged');$ok($nativeFingerprint()===$nativeBefore,'native supplier addresses review and financial evidence are unchanged');
|
|
file_put_contents($out,json_encode(['passed'=>true,'checks'=>$checks,'concurrent_edit_statuses'=>$statuses,'catalogue_rows'=>20407,'native_before'=>$nativeBefore,'native_after'=>$nativeFingerprint(),'purpose'=>'segmentation_only','pending_client_unchanged'=>true,'module_associations_unchanged'=>true,'visual_review'=>false,'deployment_capacity_validated'=>false],JSON_PRETTY_PRINT|JSON_THROW_ON_ERROR));echo count($checks)." geographic integration checks passed.\n";
|