<?php
declare(strict_types=1);require __DIR__.'/native.php';require $root.'/vendor/autoload.php';spl_autoload_register(static function($c)use($root){if(strpos($c,'app\\')===0){$f=$root.'/app/'.str_replace('\\','/',substr($c,4)).'.php';if(is_file($f))require $f;}},true,true);require __DIR__.'/NativePdo.php';$n=0;$neg=0;foreach(['yoshop_staff','yoshop_user_weight_status'] as $t){CoreGate::plan('AI','SHOW FULL COLUMNS FROM `'.$t.'`',[]);CoreGate::plan('AI',CoreGate::COLUMNS,[strtoupper($t)]);CoreGate::plan('AI',CoreGate::PRIMARY,[strtoupper($t)]);CoreGate::$meta=true;CoreGate::plan('AI','CALL SP_TABLEDEF(?, ?)',[strtoupper((string)getenv('POC_AI_SCHEMA')),strtoupper($t)]);CoreGate::$meta=false;$n+=4;}
$bad=[['AI','SELECT * FROM yoshop_user_weight_status WHERE user_id=?',[(getenv('CORE_LANE')==='B'?44676:1836)]],['AI','UPDATE yoshop_user_weight SET weight=1',[]],['AI',CoreGate::COLUMNS,['']],['AI',CoreGate::COLUMNS,['OTHER.YOSHOP_STAFF']],['AI',CoreGate::COLUMNS,['unknown_table']],['ZHCT',CoreGate::COLUMNS,['YOSHOP_STAFF']],['AI','CALL OTHER_PROC(?, ?)',[]],['AI','SELECT * FROM USER_TAB_COLUMNS',[]]];foreach($bad as [$db,$sql,$b]){try{CoreGate::plan($db,$sql,$b);throw new LogicException('Unsafe shape accepted');}catch(RuntimeException $e){$n++;$neg++;}}
CoreGate::$meta=true;foreach(['','OTHER_SCHEMA'] as $schema){try{CoreGate::plan('AI','CALL SP_TABLEDEF(?, ?)',[$schema,'YOSHOP_STAFF']);throw new LogicException('Wrong schema accepted');}catch(RuntimeException $e){$n++;$neg++;}}CoreGate::$meta=false;$copy=CoreGate::$metadataMap;CoreGate::$metadataMap['AI']['schema']='OTHER_SCHEMA';try{CoreGate::plan('AI',CoreGate::COLUMNS,['YOSHOP_STAFF']);throw new LogicException('Foreign schema map accepted');}catch(RuntimeException $e){$n++;$neg++;}CoreGate::$metadataMap=$copy;saveOnce('metadata-gate-tests.json',['checks'=>$n,'counterexamples'=>$neg,'SQL'=>0,'HTTP'=>0]);echo json_encode(['checks'=>$n,'counterexamples'=>$neg,'SQL'=>0,'HTTP'=>0]),"\n";
