8 lines
3.8 KiB
PHP
8 lines
3.8 KiB
PHP
<?php
|
|
$book='8085';require __DIR__.'/sgf-single-bootstrap.php';$pointer=json_decode(file_get_contents($s['root'].'/fiscal-obligations-backup-pointer.json'),true);$before=json_decode(file_get_contents($pointer['root'].'/preservation-private.json'),true);$checks=[];$ok=function($v,$name)use(&$checks){if(!$v)throw new LogicException($name);$checks[]=$name;};$identical=[];$allowed=[];
|
|
foreach(['host','native']as$name){$db=$name==='host'?$host:$native;foreach($before[$name]as$table=>$json){$order=in_array($table,['sr_outbox','sr_deliveries'],true)?'event_id':(in_array($table,['sc_catalogue_meta','pd_due_meta'],true)?'policy':'id');$rows=$db->table($table)->orderBy($order)->get();$old=json_decode($json,true);if($name==='host'&&$table==='permission_grants'){$byId=collect($old)->keyBy('id');$original=$rows->filter(fn($v)=>$byId->has($v->id))->values();$ok($original->toJson()===$json,'old grants identical');$new=$rows->reject(fn($v)=>$byId->has($v->id))->values();$decision=json_decode(file_get_contents($repo.'/docs/integration/sgf-fiscal-obligations-access-proposal.json'),true);$expected=array_map(fn($g)=>['user_id'=>$g['user_id'],'permission'=>$g['permission'],'tenant_id'=>1,'company_id'=>2,'unit_id'=>2],$decision['grants_per_book']);$ok($new->map(fn($v)=>['user_id'=>$v->user_id,'permission'=>$v->permission,'tenant_id'=>$v->tenant_id,'company_id'=>$v->company_id,'unit_id'=>$v->unit_id])->all()===$expected,'exact approved seven grants only');$allowed[]=$name.'.'.$table;}else{$ok($rows->toJson()===$json,'identical '.$name.'.'.$table);$identical[]=$name.'.'.$table;}}}
|
|
foreach(['binding'=>'binding.json','single_binding'=>'single-bindings.json','stock_binding'=>'stock-binding.json']as$key=>$file)$ok(hash_file('sha256',$s['root'].'/'.$file)===$before[$key],$file.' unchanged');
|
|
$versions=$host->table('fo_versions')->orderBy('version')->get();$ok($versions->count()===4&&$versions->pluck('actor_id')->all()===[13,14,13,14],'four administrative versions correct distinct actors');$ok($host->table('fo_commands')->count()===4,'four receipts only');$data=json_decode($versions[3]->data,true);$ok($data['administrative_status']==='delivery_simulated'&&$data['due_on']==='2026-12-15','approved artificial deadline and simulated delivery retained');$ok($host->table('fx_versions')->count()===4,'original four IVA versions retained');$ok($native->table('gl_journals')->count()===27,'original journals27');$ok($host->table('fr_calculations')->count()===5,'original five calculations');$ok($host->table('identity_audit')->whereIn('action',['fiscal_obligations.prepare','fiscal_obligations.review'])->count()===4,'four matching administrative audit events');
|
|
$public=$host->select("SELECT c.relname FROM pg_class c CROSS JOIN LATERAL aclexplode(coalesce(c.relacl,CASE WHEN c.relkind='S' THEN acldefault('S',c.relowner) ELSE acldefault('r',c.relowner) END)) a WHERE c.relnamespace='public'::regnamespace AND c.relname IN('fo_meta','fo_versions','fo_commands','fo_versions_id_seq','fo_commands_id_seq') AND a.grantee=0");$ok($public===[],'no PUBLIC table or sequence rights');$publicFunction=$host->select("SELECT a.* FROM pg_proc p CROSS JOIN LATERAL aclexplode(coalesce(p.proacl,acldefault('f',p.proowner))) a WHERE p.pronamespace='public'::regnamespace AND p.proname='fo_append_only' AND a.grantee=0");$ok($publicFunction===[],'no PUBLIC execution');
|
|
file_put_contents($work.'/fiscal-obligations-preservation.json',json_encode(['passed'=>true,'checks'=>$checks,'identical_original_tables'=>$identical,'original_rows_preserved_with_authorized_append'=>$allowed,'new_grants'=>7,'new_command_receipts'=>4,'new_demo'=>false,'financial_effects'=>0,'cache_cleared'=>false,'protected_six_targeted'=>false],JSON_PRETTY_PRINT));echo json_encode(['passed'=>true,'checks'=>count($checks),'identical_tables'=>count($identical),'preserved_plus_append'=>count($allowed),'proof'=>$work.'/fiscal-obligations-preservation.json']).PHP_EOL;
|