<?php
require __DIR__.'/NativeGate.php';$plan=json_decode(file_get_contents(__DIR__.'/log-http-plan.json'),true);$good=0;$negative=0;
$make=static function($case)use($plan){$rows=[];foreach($case['log_values']as $i=>$values){foreach($values as $k=>&$v){if($k==='uuid')$v=sprintf('C8EAA110-0099-4000-8000-%012X',$i+1);elseif($k==='create_time')$v=date('Y-m-d H:i:s');elseif(is_array($v))$v=$v['lane_'.getenv('NR_LANE')];}unset($v);$rows[]='( '.implode(',',array_map(static function($v){return is_int($v)?(string)$v:"'".$v."'";},$values)).' )';}return 'INSERT INTO `ydy_initial_menu_log` ('.implode(' , ',array_map(static function($f){return '`'.$f.'`';},$plan['log_SQL_contract']['insert_fields_order'])).') VALUES '.implode(' , ',$rows);};
foreach($plan['cases']as $case){NRGate::$case=$case;NRGate::$started=microtime(true);$sql=$make($case);if(count(NRGate::logRows($sql))!==$case['log_rows'])throw new RuntimeException('Positive count');$good++;}
NRGate::$case=$plan['cases'][0];$sql=$make(NRGate::$case);
$bad=[str_replace('ydy_initial_menu_log','ydy_staff',$sql),str_replace('`content`','`account`',$sql),str_replace('202610110001','202610119999',$sql),str_replace('查看个人单日维生素摄入','其它内容',$sql),str_replace('127.0.0.1','127.0.0.2',$sql),str_replace('2026-10-08','2026-10-09',$sql),str_replace("'".(getenv('NR_LANE')==='B'?'CDXPAY72BEB125':'CDXDMENU10C3EED1F43')."'","'other'",$sql),$sql.'; DELETE FROM ydy_staff',$sql.',',$sql.' -- x',preg_replace('/,1,1,1,1,/',',1,2,1,1,',$sql),str_replace('2026-10-08','2020-10-08',$sql)];
foreach($bad as $v){try{NRGate::logRows($v);throw new LogicException('Accepted mutation');}catch(RuntimeException $e){$negative++;}}
NRGate::$priorGuids=['C8EAA110-0099-4000-8000-000000000001'=>true];try{NRGate::logRows($sql);throw new LogicException('GUID replay accepted');}catch(RuntimeException $e){$negative++;}NRGate::$priorGuids=[];
try{NRGate::beforeExecute($sql,['1'=>['value'=>1]],null);throw new LogicException('Bind accepted');}catch(RuntimeException $e){$negative++;}
NRGate::beforeExecute($sql,[],null);try{NRGate::beforeExecute($sql,[],null);throw new LogicException('Write replay accepted');}catch(RuntimeException $e){$negative++;}
echo json_encode(['positive_log_plans'=>$good,'negative_gate_cases'=>$negative,'HTTP'=>0,'DML'=>0,'DB_connections'=>0]),"\n";
