<?php
declare(strict_types=1);require __DIR__.'/bootstrap.php';$lock=fopen($runtime.'/phase.lock','c');$check(flock($lock,LOCK_EX|LOCK_NB),'Same lane serial dependency gate');$phase=getenv('COMMENT_PHASE');$check(in_array($phase,['NA','CONTROL','GREEN','FINAL'],true),'Frozen read phase');$check(!is_file($runtime.'/run-'.$phase.'.json'),'No phase replay');$fixture=json_decode(file_get_contents($runtime.'/fixture-journal.json'),true);$check($fixture['committed']&&$fixture['after']===$own(),'Committed exact original fixture');$app=commentApp($root,$runtime);$cache=new \think\cache\driver\File($app,['path'=>$runtime.'/cache/','prefix'=>'','expire'=>0]);$tokens=[];foreach($tenants as $module=>$tenant){$tokens[$module]=bin2hex(random_bytes(24));$cache->set($tokens[$module],['user'=>['store_user_id'=>$tenant,'store_id'=>$tenant,'real_name'=>$marker,'user_name'=>$marker,'is_super'=>1],'store_id'=>$tenant,'is_login'=>true],3600);}$items=[];$cases=[];
$add=static function($module,$name,$path,$params=[])use(&$cases,&$items,$tokens,$phase,$base){$scenario='PILOT_DS_'.$phase.'_'.strtoupper($module.'_'.$name);$cases[]=['scenario'=>$scenario,'module'=>$module,'name'=>$name,'method'=>'GET','path'=>'/'.$module.'/'.$path,'params'=>$params,'expected_status'=>200];$headers=[['key'=>'Host','value'=>$module.'.dashboard.invalid'],['key'=>'Platform','value'=>'POC'],['key'=>'X-Pilot-Scenario','value'=>$scenario],['key'=>'Access-Token','value'=>$tokens[$module]]];$items[]=['id'=>$scenario,'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 success',function(){pm.expect(b.status).to.eql(200);});","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');});"]]]]];};
foreach($tenants as $module=>$tenant){if($phase==='NA')$add($module,'HOME','Home/data');$add($module,'STATISTICS','statistics.Data/data');if($phase==='NA'){$add($module,'SURVEY','statistics.Data/survey',['startDate'=>'2026-10-11','endDate'=>'2026-10-11']);$add($module,'EXPORT_LIST','order.Export/list');}}
$persist('cases-'.$phase.'.json',$cases);$persist('private-collection-'.$phase.'.json',['apifoxCli'=>'2.2.8','info'=>['name'=>'真实合成统计与导出记录八读'],'item'=>[['name'=>$phase,'item'=>$items]]]);$before=$own();$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 $f){$r=json_decode(file_get_contents($f),true);if(isset($r['run']))$stats[]=['stats'=>$r['run']['stats'],'failures'=>count($r['run']['failures']),'sha256'=>hash_file('sha256',$f)];}foreach($tokens as $token)$cache->delete($token);$after=$own();$check($before===$after&&$after===$fixture['after'],'All23 rows remain unchanged');$out=['lane'=>$lane,'phase'=>$phase,'native_exit'=>$exit,'stats'=>$stats,'before'=>$before,'after'=>$after,'protect'=>$protect(),'own_token_count'=>count($tokens),'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,'phase'=>$phase,'native_exit'=>$exit,'stats'=>$stats]),"\n";exit($exit);
