<?php
declare(strict_types=1);require __DIR__.'/native.php';require __DIR__.'/cases.php';$token=json_decode(file_get_contents($runtime.'/tokens.json'),true)['U1'];ck(file_exists($runtime.'/guard.json')&&!file_exists($runtime.'/run-attempt.json'),'Exact once batch');saveOnce('run-attempt.json',['HTTP_cap'=>2,'at'=>date('c')]);$port=$lane==='B'?19011:19012;$results=[];foreach(cases() as $label=>[$method,$path,$body]){$url='http://127.0.0.1:'.$port.$path;$headers="Host: owned-disease.invalid\r\nplatform: POC\r\nAccess-Token: ".$token."\r\nX-Core-Case: ".$label."\r\nContent-Type: application/json\r\n";saveOnce('client-attempt-'.$label.'.json',['method'=>$method,'url'=>$url,'body_raw'=>$body,'at'=>microtime(true),'token_sha256'=>hash('sha256',$token)]);$start=microtime(true);$raw=file_get_contents($url,false,stream_context_create(['http'=>['method'=>$method,'header'=>$headers,'content'=>$body,'ignore_errors'=>true,'timeout'=>40]]));$end=microtime(true);$status=isset($http_response_header[0])&&preg_match('/HTTP\/\S+\s+(\d+)/',$http_response_header[0],$m)?(int)$m[1]:0;saveOnce('client-'.$label.'.json',['label'=>$label,'http_status'=>$status,'body_raw'=>$raw,'headers_raw'=>$http_response_header,'start'=>$start,'end'=>$end]);$results[$label]=['http_status'=>$status,'business_status'=>is_string($raw)?(json_decode($raw,true)['status']??null):null];usleep(200000);if($status!==200||$results[$label]['business_status']!==200||!file_exists($runtime.'/oracle-'.$label.'.json')||file_exists($runtime.'/observer-error-'.$label.'.json')||file_exists($runtime.'/harness-error-'.$label.'.json')){saveOnce('run-stopped.json',['results'=>$results,'actual_HTTP'=>count($results),'no_retry'=>true,'label'=>$label]);echo json_encode(['lane'=>$lane,'actual_HTTP'=>count($results),'stopped'=>$label,'results'=>$results]),"\n";exit(2);}}saveOnce('run-complete.json',['results'=>$results,'actual_HTTP'=>count($results)]);echo json_encode(['lane'=>$lane,'actual_HTTP'=>2,'results'=>$results]),"\n";
