<?php
declare(strict_types=1);require __DIR__.'/bootstrap.php';require __DIR__.'/natural.php';$lock=fopen($runtime.'/phase.lock','c');$check(flock($lock,LOCK_EX|LOCK_NB),'Serial same-lane phase');$phase=getenv('COMMENT_PHASE');$check(in_array($phase,['NA','CONTROL','FINAL'],true),'Only original and root-approved necessary readonly phases');$check(!is_file($runtime.'/run-'.$phase.'.json'),'Never replay phase');$f=json_decode(file_get_contents($runtime.'/fixture-journal.json'),true);$check($f['committed']&&$own()===$f['after']&&$natural()===$f['natural_after'],'All committed original baselines exact');$app=commentApp($root,$runtime);$cache=new \think\cache\driver\File($app,['path'=>$runtime.'/cache/','prefix'=>'','expire'=>0]);$model=\app\terminal\model\store\User::withoutGlobalScope()->where('store_user_id','=',$lane==='B'?10075:10011)->where('store_id','=',2147001112)->find();$check($model!==null,'Existing own marked operator principal');$profile=$model->toArray();$check(!array_key_exists('password',$profile)&&$profile['user_name']==='cdxop11f64c_terminal','Normal principal hides credential');$tokens=['terminal'=>bin2hex(random_bytes(24)),'admin'=>bin2hex(random_bytes(24))];$cache->set($tokens['terminal'],['user'=>$profile,'store_id'=>2147001112,'is_login'=>true],3600);$cache->set($tokens['admin'],['user'=>['admin_user_id'=>2147001142,'user_name'=>$marker.'_admin'],'is_login'=>true],3600);$items=[];$cases=[];
$add=static function($module,$name,$path,$params=[],$status=200)use(&$items,&$cases,$tokens,$base,$phase){$s='PILOT_AD_'.$phase.'_'.strtoupper($module.'_'.$name);$cases[]=['scenario'=>$s,'module'=>$module,'name'=>$name,'method'=>'GET','path'=>'/'.$module.'/'.$path,'params'=>$params,'expected_status'=>$status];$headers=[['key'=>'Host','value'=>$module.'.admin-dishes-read.invalid'],['key'=>'Platform','value'=>'POC'],['key'=>'X-Pilot-Scenario','value'=>$s],['key'=>'Access-Token','value'=>$tokens[$module]]];$items[]=['id'=>$s,'name'=>$name,'type'=>'http','metaInfo'=>['type'=>'HTTP'],'request'=>['method'=>'GET','url'=>$base.'/'.$module.'/'.$path.'?'.http_build_query($params),'header'=>$headers],'event'=>[['listen'=>'test','script'=>['type'=>'text/javascript','exec'=>["pm.test('HTTP200',function(){pm.response.to.have.status(200);});var b=pm.response.json();","pm.test('Expected business status',function(){pm.expect(b.status).to.eql(".$status.");});","pm.test('Trace contract',function(){pm.expect(b.trace_id).to.match(/^[0-9a-f]{13}$/);});","pm.test('Top DTO types',function(){pm.expect(typeof b.data).to.eql('object');pm.expect(typeof b.message).to.eql('string');});"]]]]];};
$add('admin','DETAIL','store.Equipment/detail',['id'=>$f['owned']['equipment']]);$add('admin','LIST','store.Equipment/lists',['type'=>60]);if($phase==='NA'){$add('admin','STORES','store.Equipment/getStoreList');$add('terminal','IMAGES','dishes.Img/all',['dishes_id'=>$f['owned']['dishes']]);$add('terminal','CATEGORY','recommend.Recommend/dishesCategory');$add('admin','MISSING_DETAIL','store.Equipment/detail',['id'=>0]);$add('admin','EMPTY_TYPE','store.Equipment/lists',['type'=>50]);$add('terminal','MISSING_DISH','dishes.Img/all',['dishes_id'=>0],500);}$persist('cases-'.$phase.'.json',$cases);$persist('private-collection-'.$phase.'.json',['apifoxCli'=>'2.2.8','info'=>['name'=>'Synthetic device and dishes metadata read5'],'item'=>[['name'=>'NA','item'=>$items]]]);$dir=$runtime.'/native-'.$phase;mkdir($dir,0700);$p=proc_open(['node',getenv('COMMENT_CLI'),'run',$runtime.'/private-collection-'.$phase.'.json','-r','json','--out-dir',$dir,'--out-file','result','--on-error','continue','--timeout-request','30000','--silent'],[0=>['file','/dev/null','r'],1=>['file',$runtime.'/private-cli.log','a'],2=>['file',$runtime.'/private-cli.log','a']],$pipes);$exit=proc_close($p);$stats=[];foreach(glob($dir.'/*.json') as $file){$r=json_decode(file_get_contents($file),true);if(isset($r['run']))$stats[]=['stats'=>$r['run']['stats'],'failures'=>count($r['run']['failures']),'sha256'=>hash_file('sha256',$file)];}foreach($tokens as $token)$cache->delete($token);$out=['lane'=>$lane,'native_exit'=>$exit,'stats'=>$stats,'after'=>$own(),'natural_after'=>$natural(),'own_tokens'=>2,'all_own_tokens_absent'=>count(array_filter($tokens,static function($t)use($cache){return $cache->has($t);}))===0];$persist('run-'.$phase.'.json',$out);echo json_encode(['lane'=>$lane,'native_exit'=>$exit,'stats'=>$stats]),"\n";exit($exit);
