<?php
declare(strict_types=1);try{require __DIR__.'/common.php';$scenario=$_SERVER['HTTP_X_PILOT_SCENARIO']??'';$cases=json_decode(file_get_contents($runtime.'/cases-original.json'),true);if($lane==='B'&&$scenario==='PROBLEM_CREATE_RETRY'){$cases[$scenario]=$cases['PROBLEM_CREATE'];}$check(isset($cases[$scenario]),'Exact case');$case=$cases[$scenario];$tokens=json_decode(file_get_contents($runtime.'/tokens.json'),true);$check($_SERVER['REQUEST_METHOD']==='POST'&&parse_url($_SERVER['REQUEST_URI'],PHP_URL_PATH)===$case['path']&&($_SERVER['QUERY_STRING']??'')===''&&$_SERVER['HTTP_HOST']===$case['host']&&($_SERVER['CONTENT_TYPE']??'')==='application/json'&&file_get_contents('php://input')===$case['body_raw']&&($_SERVER['HTTP_ACCESS_TOKEN']??'')===$tokens['one'],'Exact original POST/JSON/host/Auth/body');$check(!file_exists($runtime.'/wire-original-'.$scenario.'.json'),'Do not replay original HTTP');$_SERVER['SCRIPT_FILENAME']=$root.'/public/index.php';$_SERVER['SCRIPT_NAME']='/index.php';$_SERVER['PHP_SELF']='/index.php';$app=invApp($root,$runtime,$scenario==='PROBLEM_CREATE_RETRY'?'PROBLEM_CREATE':$scenario);InvGate::$scenario=$scenario==='PROBLEM_CREATE_RETRY'?'PROBLEM_CREATE':$scenario;InvGate::$case=$case;$before=$small();if($scenario==='PROBLEM_CREATE_RETRY'){foreach($before as $rows)foreach($rows as $row)$check((int)$row['type']!==6&&(int)$row['type']!==7&&(int)$row['type']!==8&&(int)$row['type']!==9,'Fresh failed Problem scope0 before retry');InvGate::$recordScenario=$scenario;}$originalBefore=$protected();$http=$app->http;$response=$http->run();$after=$small();$originalAfter=$protected();$check($originalBefore===$originalAfter,'Original 13 and own principals unchanged');$source=json_decode(file_get_contents(__DIR__.'/source-frozen-sha.json'),true)['files'];$included=[];foreach(get_included_files() as $file)if(strpos($file,$root.'/')===0){$name=substr($file,strlen($root)+1);$included[$name]=hash_file('sha256',$file);$check($source[$name]===$included[$name],'Actual included original source '.$name);}$persist('wire-original-'.$scenario.'.json',['scenario'=>$scenario,'case'=>$case,'http_status'=>$response->getCode(),'raw'=>$response->getContent(),'before'=>$before,'after'=>$after,'protected_before'=>$originalBefore,'protected_after'=>$originalAfter,'included_source_sha256'=>$included,'successful_master_INSERT'=>InvGate::$masterInserts,'successful_answer_INSERT'=>InvGate::$answerInserts,'master_generated_native_ID'=>InvGate::$masterId,'successful_UPDATE'=>InvGate::$updates]);$response->send();$http->end($response);}catch(Throwable $e){if(isset($persist))$persist('harness-failure-original-'.preg_replace('/[^A-Z0-9_]/','',strtoupper($scenario??'INIT')).'.json',['class'=>get_class($e),'message'=>$e->getMessage(),'file'=>$e->getFile(),'line'=>$e->getLine()]);http_response_code(500);header('Content-Type: application/json');echo json_encode(['harness_error'=>get_class($e),'message'=>$e->getMessage()]);}
