<?php
declare(strict_types=1);
require __DIR__.'/bootstrap.php';require __DIR__.'/oracle.php';require __DIR__.'/StrictWire.php';$phase=getenv('INFOS_PHASE')?:'original';$check(in_array($phase,['original','candidate','candidate_v2'],true),'Frozen infos phase');$reportFile=$runtime.'/private-meal-infos-'.$phase.'.json';$check(!is_file($reportFile),'No overwriting infos checkpoints');$before=analysisOriginalSnapshot($read,$tenant,$staff,$operator);$extra=json_decode(file_get_contents($base.'/__infos_boundary'),true);$check($extra['controller_private_path'],'Actual infos Controller source');$last=$before['last'];$dishes=[];foreach($before['dishes'] as $d)$dishes[$d['id']]=$d;$list=[];$fields=array_column(\app\common\enum\dishes\Nutrient::data(),'field');foreach($before['last_infos'] as $i){if(!isset($dishes[$i['dishes_id']]))continue;$d=$dishes[$i['dishes_id']];$one=['id'=>$i['id'],'dishes_id'=>$d['id'],'dishes_weight'=>$i['dishes_weight'],'dishes_name'=>$d['name']];foreach($fields as $field)$one[$field]=$i[$field];$list[]=$one;}
require __DIR__.'/meal_infos_v2_gate.php';
$data=['list'=>$list,'meal_date'=>substr((string)$last['meal_date'],0,10),'meal_times'=>$last['meal_times'],'meal_time'=>substr((string)$last['meal_time'],0,19),'meal_times_name'=>\app\common\enum\dishes\MealTimes::getName($last['meal_times']),'is_loading'=>$last['is_loading']];$want=json_decode(json_encode($data,JSON_UNESCAPED_UNICODE));$token=bin2hex(random_bytes(24));$cache->set($token,['user'=>['store_user_id'=>$operator,'store_id'=>$tenant,'real_name'=>$marker,'user_name'=>$marker,'is_super'=>1],'store_id'=>$tenant,'is_login'=>true],1800);$scenario='PILOT_TA_MI_'.strtoupper($phase);$item=['id'=>$scenario,'name'=>'terminal last meal infos '.$phase,'type'=>'http','metaInfo'=>['type'=>'HTTP'],'request'=>['method'=>'GET','url'=>$base.'/terminal/meal.meal/infos?staff_id='.$staff,'header'=>[['key'=>'Host','value'=>'analysis-natural.invalid'],['key'=>'Access-Token','value'=>$token],['key'=>'Platform','value'=>'POC'],['key'=>'X-Pilot-Scenario','value'=>$scenario]]],'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 business200',function(){pm.expect(b.status).to.eql(200);});","pm.test('Complete three-table original projection values types containers array order',function(){pm.expect(b.data).to.deep.eql(".json_encode($data,JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES).");});","pm.test('Trace contract',function(){pm.expect(b.trace_id).to.match(/^[0-9a-f]{13}$/);});"]]]]];$collection=['apifoxCli'=>'2.2.8','info'=>['name'=>'最后餐详情单GET只读原表验收'],'item'=>[['name'=>'Meal infos','item'=>[$item]]]];$file=$runtime.'/private-mi-collection.json';file_put_contents($file,json_encode($collection,JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE));chmod($file,0600);$dir=$runtime.'/private-mi-cli-'.$phase;mkdir($dir,0700);$p=proc_open(['node',getenv('ANALYSIS_CLI'),'run',$file,'-r','json','--out-dir',$dir,'--out-file','result','--on-error','continue','--silent'],[0=>['file','/dev/null','r'],1=>['file',$runtime.'/private-mi-cli.log','a'],2=>['file',$runtime.'/private-mi-cli.log','a']],$pipes);$exit=proc_close($p);$wire=null;foreach(file($runtime.'/private-wire.jsonl',FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES) as $line){$w=json_decode($line,true);if($w['scenario']===$scenario)$wire=$w;}$check($wire!==null,'Actual native infos wire checkpoint');$body=json_decode($wire['raw']);$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']),'raw_report_sha256'=>hash_file('sha256',$f)];}$after=analysisOriginalSnapshot($read,$tenant,$staff,$operator);$cache->delete($token);$cache->clear();$out=['lane'=>$lane,'phase'=>$phase,'body'=>$body,'expected_data'=>$want,'native_exit'=>$exit,'http_status'=>$wire['http_status'],'raw_sha256'=>hash('sha256',$wire['raw']),'stats'=>$stats,'complete_original_equal'=>strictWireEqual($body->data,$want),'original_unchanged'=>hash('sha256',serialize($before))===hash('sha256',serialize($after)),'before_snapshot'=>$before,'after_sha256'=>hash('sha256',serialize($after)),'controller_identity'=>$extra,'boundary'=>$boundary,'collection'=>$collection,'tokens_reclaimed'=>true];file_put_contents($reportFile,json_encode($out,JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE|JSON_PRESERVE_ZERO_FRACTION));chmod($reportFile,0600);$diff=static function($a,$b,$path='')use(&$diff){if(gettype($a)!==gettype($b))return [['path'=>$path,'actual_type'=>gettype($a),'expected_type'=>gettype($b)]];if(is_object($a)||is_array($a)){$out=[];foreach((array)$b as $k=>$v)$out=array_merge($out,$diff(((array)$a)[$k]??null,$v,$path.'/'.$k));return $out;}return $a===$b?[]:[['path'=>$path,'value_diff'=>true,'actual_type'=>gettype($a),'expected_type'=>gettype($b)]];};echo json_encode(['lane'=>$lane,'phase'=>$phase,'native_exit'=>$exit,'rows'=>count($list),'complete_original_equal'=>$out['complete_original_equal'],'original_unchanged'=>$out['original_unchanged'],'differences'=>$diff($body->data,$want)]),"\n";
