8 lines
3.9 KiB
PHP
8 lines
3.9 KiB
PHP
<?php
|
|
require dirname(__DIR__).'/app/Shared/Geography/Cartography.php';
|
|
use App\Shared\Geography\Cartography;
|
|
$run=json_decode(file_get_contents('C:/laragon/data/sgf-tempo/run/modular-regression-current.json'),true,32,JSON_THROW_ON_ERROR);$private=$run['root'].'/private';$source=$private.'/cartography-source-20261103.json';$prepared=$private.'/cartography-prepared-20261103.json';$out=dirname(__DIR__).'/docs/proofs/cartography-preparation-20261103.json';if(is_file($prepared)||is_file($out))throw new LogicException('Completed proof preserved');$s=json_decode(file_get_contents($source),true,64,JSON_THROW_ON_ERROR);$checks=[];$ok=function($v,$name)use(&$checks){if(!$v)throw new RuntimeException($name);$checks[]=$name;};$c=Cartography::prepare($s);
|
|
$ok($c['total']===20407,'all20407 source records are preserved');$ok(array_values($c['levels'])===[11,148,437,1334,1870,16607],'source levels reconcile to the full record count');$ok($c['nodes'][0]['codes']['province']==='01','leading zero preserved as text');$ok(count(array_unique(array_column($c['nodes'],'key')))===20407,'source-version plus source-ID uniquely identifies each record');$ok($c['diagnostics']['duplicate_path_groups']===48&&$c['diagnostics']['duplicate_extra_rows']===48,'duplicate code paths are retained and signalled');$ok($c['diagnostics']['conflicting_designation_groups']===39,'conflicting duplicate designations are exposed');$ok($c['diagnostics']['missing_designations']===9,'nine absent designations remain absent');$ok($c['diagnostics']['missing_parent_records']===8610,'missing immediate parent rows are reported without invented labels');$alpha=array_values(array_filter($c['nodes'],fn($n)=>in_array($n['codes']['village_quarter'],['7A','7B'],true)));$ok(count($alpha)===2,'alphanumeric source codes survive unchanged');$province=Cartography::selection($c,$s['sha256'],$c['nodes'][0]['key']);$ok($province['designation']==='Niassa'&&$province['codes']['district']==='','explicit selection permits a province without imposing deeper precision');$refuse=function($fn,$message)use($ok){try{$fn();throw new RuntimeException('Selection accepted unexpectedly');}catch(DomainException $e){$ok($e->getMessage()===$message,$message);}};
|
|
$refuse(fn()=>Cartography::selection($c,str_repeat('0',64),$c['nodes'][0]['key']),'CARTOGRAPHY_VERSION_CHANGED');$refuse(fn()=>Cartography::selection($c,$s['sha256'],'Niassa'),'CARTOGRAPHY_TERRITORY_UNKNOWN');$ambiguous=array_values(array_filter($c['nodes'],fn($n)=>in_array('duplicate_path',$n['issues'],true)))[0];$refuse(fn()=>Cartography::selection($c,$s['sha256'],$ambiguous['key']),'CARTOGRAPHY_REVIEW_REQUIRED');$ok(Cartography::prepare($s)===$c,'preparation is deterministic without source mutation');$bad=$s;$bad['rows'][0]['cells']['B']='Other';try{Cartography::prepare($bad);throw new RuntimeException('Wrong schema accepted');}catch(InvalidArgumentException $e){$ok($e->getMessage()==='CARTOGRAPHY_SOURCE_REFUSED','unexpected workbook schema is refused');}$bad=$s;$bad['rows'][2]['cells']['A']=$bad['rows'][1]['cells']['A'];try{Cartography::prepare($bad);throw new RuntimeException('Duplicate ID accepted');}catch(InvalidArgumentException $e){$ok($e->getMessage()==='CARTOGRAPHY_SOURCE_ID_REFUSED','duplicate source IDs are refused');}
|
|
file_put_contents($prepared,json_encode($c,JSON_UNESCAPED_UNICODE|JSON_THROW_ON_ERROR));file_put_contents($out,json_encode(['passed'=>true,'checks'=>count($checks),'names'=>$checks,'source'=>$c['source'],'total'=>$c['total'],'levels'=>$c['levels'],'diagnostics'=>$c['diagnostics'],'prepared_sha256'=>hash_file('sha256',$prepared),'implementation_sha256'=>hash_file('sha256',dirname(__DIR__).'/app/Shared/Geography/Cartography.php'),'original_workbook_modified'=>false,'database_connections'=>0,'business_records_assigned'=>0,'catalogue_activated'=>false,'authority_independently_verified'=>false,'public_data_payload_committed'=>false],JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE|JSON_THROW_ON_ERROR));echo count($checks)." cartography preparation checks passed.\n";
|