<?php
declare(strict_types=1);$sent=false;$label=$_SERVER['HTTP_X_CORE_CASE']??'UNKNOWN';try{require __DIR__.'/app.php';require __DIR__.'/observer.php';require __DIR__.'/data.php';require __DIR__.'/cases.php';require __DIR__.'/dto.php';$map=[];foreach(cases() as $c)$map[$c['label']]=$c;ck(isset($map[$label]),'Exact authorized reader');$c=$map[$label];$token=json_decode(file_get_contents($runtime.'/tokens.json'),true)['U1'];ck($_SERVER['REQUEST_METHOD']===$c['method']&&parse_url($_SERVER['REQUEST_URI'],PHP_URL_PATH)===$c['path']&&($_SERVER['QUERY_STRING']??'')===$c['query']&&($_SERVER['HTTP_HOST']??'')==='customer-fast5.invalid'&&($_SERVER['HTTP_PLATFORM']??'')==='POC'&&($_SERVER['HTTP_ACCESS_TOKEN']??'')===$token&&file_get_contents('php://input')===$c['body_raw'],'Exact literal method/path/query/body/Auth');ck(!file_exists($runtime.'/request-'.$label.'.json'),'Never replay');saveOnce('request-'.$label.'.json',['case'=>$c,'at'=>microtime(true),'token_sha256'=>hash('sha256',$token)]);$_SERVER['SCRIPT_FILENAME']=$root.'/public/index.php';$_SERVER['SCRIPT_NAME']='/index.php';$_SERVER['PHP_SELF']='/index.php';$app=coreApp($label);ck(count(file($runtime.'/sql-budget.jsonl'))+($lane==='B'?80:140)+60<=600,'Reserve native plus final protection');$start=microtime(true);$http=$app->http;$response=$http->run();$end=microtime(true);preserveSendObserve($response,static function($r)use($label){saveOnce('response-'.$label.'.json',$r);},static function()use($response,&$sent){$response->send();$sent=true;},static function($r)use($label){global $runtime;ck(CoreGate::$counts===[],'Readonly no DML');foreach(file($runtime.'/business-native.jsonl') as $line){$e=json_decode($line,true);ck($e['scenario']!==$label||!isset($e['error']),'No swallowed source DB/gate error');}saveOnce('included-'.$label.'.json',['files'=>includedProof(),'native_count'=>CoreGate::$total,'counts'=>CoreGate::$counts]);checkDTO($label,$r);},static function($e)use($label){saveOnce('observer-error-'.$label.'.json',$e);},$start,$end);try{$http->end($response);}catch(Throwable $e){saveOnce('http-end-error-'.$label.'.json',['message'=>$e->getMessage()]);}}catch(Throwable $e){if(function_exists('saveOnce')&&!file_exists($runtime.'/harness-error-'.$label.'.json'))saveOnce('harness-error-'.$label.'.json',['class'=>get_class($e),'message'=>$e->getMessage(),'sent'=>$sent]);if(!$sent){http_response_code(500);echo json_encode(['harness_error'=>get_class($e),'message'=>$e->getMessage()]);}}
