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";