<?php
declare(strict_types=1);
require __DIR__.'/bootstrap.php';require __DIR__.'/oracle.php';require __DIR__.'/StrictWire.php';$check(!is_file($runtime.'/private-v2-report.json'),'V2 evidence must not be overwritten');$old=json_decode(file_get_contents($runtime.'/private-green-report.json'),true);$check(count($old['cases'])===7&&$old['errors']===[],'Seven v1 regression checkpoints present');$before=analysisOriginalSnapshot($read,$tenant,$staff,$operator);$check(hash('sha256',serialize($before))===$old['before_sha256'],'Same original natural sample before V2');$check($boundary['reflection']['app/terminal/service/analysis/Analysis.php']['sha256']==='6eae0679fbb36a8dc76f5287e28257bc991e4db1993c4c638c1f55f8b4b9f0b1','Actual V2 service SHA');$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);$items=[];$expected=[];foreach($old['collections'] as $collection){$i=$collection['item'][0]['item'][0];if(strpos($i['id'],'VITAMIN_')===false)continue;$i['id']=str_replace('PILOT_TA_','PILOT_TA_V2_',$i['id']);foreach($i['request']['header'] as &$h){if($h['key']==='Access-Token')$h['value']=$token;if($h['key']==='X-Pilot-Scenario')$h['value']=$i['id'];}unset($h);$items[]=$i;foreach($old['cases'] as $case)if(str_replace('PILOT_TA_','PILOT_TA_V2_',$case['scenario'])===$i['id'])$expected[$i['id']]=$case['expected_data'];}
$check(count($items)===2&&count($expected)===2,'Only two vitamin branches V2');$collection=['apifoxCli'=>'2.2.8','info'=>['name'=>'vitamin缺餐次保护修正只读回归'],'item'=>[['name'=>'V2必要两分支','item'=>$items]]];$file=$runtime.'/private-v2-collection.json';file_put_contents($file,json_encode($collection,JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE));chmod($file,0600);$dir=$runtime.'/private-v2-cli-report';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-cli.log','a'],2=>['file',$runtime.'/private-cli.log','a']],$pipes);$exit=proc_close($p);$cases=[];foreach(file($runtime.'/private-wire.jsonl',FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES) as $line){$w=json_decode($line,true);if(!isset($expected[$w['scenario']]))continue;$body=json_decode($w['raw']);$want=json_decode(json_encode($expected[$w['scenario']],JSON_UNESCAPED_UNICODE));$cases[]=['scenario'=>$w['scenario'],'actual_body'=>$body,'expected_data'=>$want,'complete_original_equal'=>strictWireEqual($body->data,$want),'http_status'=>$w['http_status'],'raw_sha256'=>hash('sha256',$w['raw'])];}$reports=[];foreach(glob($dir.'/*.json') as $f){$r=json_decode(file_get_contents($f),true);if(isset($r['run']))$reports[]=['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,'cases'=>$cases,'native_exit'=>$exit,'stats'=>$reports,'original_unchanged'=>hash('sha256',serialize($before))===hash('sha256',serialize($after)),'boundary'=>$boundary,'tokens_reclaimed'=>true,'collection'=>$collection];file_put_contents($runtime.'/private-v2-report.json',json_encode($out,JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE|JSON_PRESERVE_ZERO_FRACTION));chmod($runtime.'/private-v2-report.json',0600);echo json_encode(['lane'=>$lane,'native_exit'=>$exit,'requests'=>count($cases),'original_equal'=>array_column($cases,'complete_original_equal'),'original_unchanged'=>$out['original_unchanged']]),"\n";
