<?php
declare(strict_types=1);require __DIR__.'/common.php';$cases=json_decode(file_get_contents(__DIR__.($lane==='B'&&is_file(__DIR__.'/cases-retry.json')?'/cases-retry.json':'/cases.json')),true);$tokens=json_decode(file_get_contents($runtime.'/tokens.json'),true);$port=$lane==='B'?18901:18902;$out=[];
foreach($cases as $name=>$case){$check(!file_exists($runtime.'/client-'.$name.'.json'),'Never repeat completed HTTP');$headers=['Host: '.$case['host'],'Platform: '.$case['platform'],'Version: '.$case['version'],'X-Pilot-Scenario: '.$name];if($case['actor']!=='none')$headers[]='Access-Token: '.$tokens[$case['actor']];if($case['method']==='POST')$headers[]='Content-Type: application/x-www-form-urlencoded';$url='http://127.0.0.1:'.$port.$case['path'].($case['query']===''?'':'?'.$case['query']);$context=stream_context_create(['http'=>['method'=>$case['method'],'header'=>implode("\r\n",$headers),'content'=>$case['body_raw'],'ignore_errors'=>true,'timeout'=>120]]);$raw=file_get_contents($url,false,$context);$persist('client-'.$name.'.json',['case'=>$case,'response_headers'=>$http_response_header,'raw'=>$raw]);$decoded=json_decode($raw,true);$out[$name]=['http_headers'=>$http_response_header,'status'=>$decoded['status']??null,'message'=>$decoded['message']??null];echo json_encode(['lane'=>$lane,'case'=>$name,'status'=>$out[$name]['status'],'harness_error'=>$decoded['harness_error']??null]),"\n";if(isset($decoded['harness_error']))break;if(strpos($name,'ADD_')===0&&($decoded['status']??null)!==200)break;}
$persist($lane==='B'&&is_file(__DIR__.'/cases-retry.json')?'run-result-retry.json':'run-result.json',$out);$persist($lane==='B'&&is_file(__DIR__.'/cases-retry.json')?'batch-after-retry.json':'batch-after.json',$large());
