<?php
declare(strict_types=1);require __DIR__.'/bootstrap.php';$phase=getenv('COMMENT_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'],'Own preparation committed');$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=[],$status=200,$auth=true)use(&$items,&$cases,$tokens,$base,$phase){$scenario='PILOT_OR_'.$phase.'_'.strtoupper($module.'_'.$name);$headers=[['key'=>'Host','value'=>$module.'.order-read.invalid'],['key'=>'Platform','value'=>'POC'],['key'=>'X-Pilot-Scenario','value'=>$scenario]];if($auth)$headers[]=['key'=>'Access-Token','value'=>$tokens[$module]];$cases[]=['scenario'=>$scenario,'module'=>$module,'name'=>$name,'path'=>'/'.$module.'/'.$path,'params'=>$params,'expected_status'=>$status,'auth'=>$auth];$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('Numeric intended business status',function(){pm.expect(b.status).to.eql(".$status.");});","pm.test('Trace string',function(){pm.expect(b.trace_id).to.match(/^[0-9a-f]{13}$/);});","pm.test('Data object or array contract',function(){pm.expect(typeof b.data).to.eql('object');pm.expect(typeof b.message).to.eql('string');});"]]]]];};
if($phase==='FINAL'){foreach($tenants as $module=>$tenant){$id=$fixture['owned'][$module];$add($module,'ORDER_ALL','order/list',['dataType'=>'all']);$add($module,'ORDER_DETAIL','order/detail',['orderId'=>$id['order']]);$add($module,'RECHARGE_ALL','user.recharge/order');}}else foreach($tenants as $module=>$tenant){$id=$fixture['owned'][$module];$other=$fixture['owned'][$module==='store'?'terminal':'store'];$add($module,'ORDER_ALL','order/list',['dataType'=>'all']);$add($module,'ORDER_CANCEL','order/list',['dataType'=>'cancel']);$add($module,'ORDER_PENDING_EMPTY','order/list',['dataType'=>'pay']);$add($module,'ORDER_SEARCH_USER','order/list',['dataType'=>'all','searchType'=>10,'searchValue'=>'CDXCM11F782','userId'=>$id['user']]);$add($module,'ORDER_DATE','order/list',['dataType'=>'all','betweenTime'=>['2027-01-15','2027-01-15']]);$add($module,'ORDER_PAGE2','order/list',['dataType'=>'all','page'=>2]);$add($module,'ORDER_DETAIL','order/detail',['orderId'=>$id['order']]);$add($module,'ORDER_CROSS_DETAIL','order/detail',['orderId'=>$other['order']],500);$add($module,'RECHARGE_ALL','user.recharge/order');$add($module,'RECHARGE_SEARCH_USER','user.recharge/order',['search'=>$marker,'user_id'=>$id['user'],'recharge_type'=>10,'pay_status'=>10]);$add($module,'RECHARGE_DATE_EMPTY','user.recharge/order',['betweenTime'=>['2026-10-11','2026-10-11']]);$add($module,'AUTH','order/list',['dataType'=>'all'],401,false);}
$persist('cases-'.$phase.'.json',$cases);$persist('private-collection-'.$phase.'.json',['apifoxCli'=>'2.2.8','info'=>['name'=>'Order和RechargeOrder六GET双库真实读取'],'item'=>[['name'=>'独立取消订单与未付零金额样本','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);$cache->clear();$out=['lane'=>$lane,'phase'=>$phase,'native_exit'=>$exit,'stats'=>$stats,'before'=>$before,'after'=>$own(),'own_unchanged'=>$before===$own(),'natural_count_unchanged'=>$protect()===$fixture['before_protect'],'cache_cleared'=>true];$persist('run-'.$phase.'.json',$out);echo json_encode(['lane'=>$lane,'phase'=>$phase,'native_exit'=>$exit,'stats'=>$stats,'own_unchanged'=>$out['own_unchanged']]),"\n";
