<?php
declare(strict_types=1);require __DIR__.'/bootstrap.php';$check(!is_file($runtime.'/run-journal.json'),'No automatic write replay');$fixture=json_decode(file_get_contents($runtime.'/fixture-journal.json'),true);$check($fixture['committed'],'Committed fixtures');$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);}$persist('private-tokens.json',$tokens);$cases=[];
$add=static function($module,$name,$action,$params=[],$status=200,$auth=true)use(&$cases,$base,$tokens){$scenario='PILOT_CM_'.strtoupper($module.'_'.$name);$method=in_array($action,['list','detail'],true)?'GET':'POST';$headers=[['key'=>'Host','value'=>$module.'.comment.invalid'],['key'=>'Platform','value'=>'POC'],['key'=>'X-Pilot-Scenario','value'=>$scenario]];if($auth)$headers[]=['key'=>'Access-Token','value'=>$tokens[$module]];$request=['method'=>$method,'url'=>$base.'/'.$module.'/goods.comment/'.$action,'header'=>$headers];if($method==='GET')$request['url'].='?'.http_build_query($params);else{$request['header'][]=['key'=>'Content-Type','value'=>'application/json'];$request['body']=['mode'=>'raw','raw'=>json_encode($params,JSON_UNESCAPED_UNICODE),'options'=>['raw'=>['language'=>'json']]];}$exec=["pm.test('HTTP 200',function(){pm.response.to.have.status(200);});var b=pm.response.json();","pm.test('Numeric expected 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('Message and data types',function(){pm.expect(typeof b.message).to.eql('string');pm.expect(typeof b.data).to.eql('object');});"];$cases[]=['scenario'=>$scenario,'module'=>$module,'name'=>$name,'action'=>$action,'method'=>$method,'params'=>$params,'expected_status'=>$status,'auth'=>$auth,'item'=>['id'=>$scenario,'name'=>$name,'type'=>'http','metaInfo'=>['type'=>'HTTP'],'request'=>$request,'event'=>[['listen'=>'test','script'=>['type'=>'text/javascript','exec'=>$exec]]]]];};
foreach($tenants as $module=>$tenant){$id=$fixture['owned'][$module];$other=$fixture['owned'][$module==='store'?'terminal':'store'];$add($module,'AUTH','list',[],401,false);$add($module,'LIST','list');$add($module,'GOODS','list',['goodsName'=>$marker]);$add($module,'ORDER','list',['orderNo'=>$marker]);$add($module,'USER','list',['userId'=>$id['user']]);$add($module,'SCORE','list',['score'=>20,'status'=>0]);$add($module,'EMPTY_FILTER','list',['goodsName'=>'MISSING_'.$marker]);$add($module,'PAGE2','list',['page'=>2]);$add($module,'DETAIL','detail',['commentId'=>$id['comment'][0]]);$add($module,'CROSS_DETAIL','detail',['commentId'=>$other['comment'][0]],500);$add($module,'MISSING_ID','detail',[],500);$add($module,'INVALID_ID','detail',['commentId'=>'not-an-int'],500);
$form=['score'=>30,'content'=>'修改评价 中文\' \\ '.$marker.'_'.$module,'imageIds'=>[],'status'=>0,'sort'=>1];$add($module,'EDIT_EMPTY','edit',['commentId'=>$id['comment'][0],'form'=>$form]);$add($module,'DETAIL_EMPTY','detail',['commentId'=>$id['comment'][0]]);$form['score']=10;$form['imageIds']=[$id['upload_file']];$form['sort']=5;$add($module,'EDIT_IMAGE','edit',['commentId'=>$id['comment'][0],'form'=>$form]);$add($module,'DETAIL_IMAGE','detail',['commentId'=>$id['comment'][0]]);$add($module,'DELETE','delete',['commentId'=>$id['comment'][0]]);$add($module,'LIST_DELETED','list');$add($module,'DETAIL_DELETED','detail',['commentId'=>$id['comment'][0]]);}
$persist('run-journal.json',['lane'=>$lane,'before'=>$own(),'before_protect'=>$protect(),'cases'=>array_map(static function($c){unset($c['item']);return $c;},$cases)]);$collection=['apifoxCli'=>'2.2.8','info'=>['name'=>'goods.Comment双端真实双库验收'],'item'=>[['name'=>'有界自有评价链','item'=>array_column($cases,'item')]]];$persist('private-collection.json',$collection);mkdir($runtime.'/native',0700);$p=proc_open(['node',getenv('COMMENT_CLI'),'run',$runtime.'/private-collection.json','-r','json','--out-dir',$runtime.'/native','--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($runtime.'/native/*.json') as $f){$r=json_decode(file_get_contents($f),true);if(isset($r['run']))$stats[]=['stats'=>$r['run']['stats'],'failure_count'=>count($r['run']['failures']),'sha256'=>hash_file('sha256',$f)];}foreach($tokens as $token)$cache->delete($token);$cache->clear();$out=['lane'=>$lane,'native_exit'=>$exit,'stats'=>$stats,'after'=>$own(),'protected_unchanged'=>$protect()===$fixture['before_protect'],'token_cache_cleared'=>true];$persist('run-result.json',$out);echo json_encode(['lane'=>$lane,'native_exit'=>$exit,'stats'=>$stats,'protected_unchanged'=>$out['protected_unchanged']]),"\n";
