<?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__.'/scope.php';require __DIR__.'/cases.php';require __DIR__.'/dto.php';$cases=cases();ck(isset($cases[$label]),'Approved route label');[$method,$path,$body]=$cases[$label];$token=json_decode(file_get_contents($runtime.'/tokens.json'),true)['U1'];ck($_SERVER['REQUEST_METHOD']===$method&&$_SERVER['REQUEST_URI']===$path&&($_SERVER['QUERY_STRING']??'')===''&&($_SERVER['HTTP_HOST']??'')==='owned-disease.invalid'&&($_SERVER['HTTP_PLATFORM']??'')==='POC'&&($_SERVER['HTTP_ACCESS_TOKEN']??'')===$token&&file_get_contents('php://input')===$body,'Exact authorized request bytes/actor');ck(!file_exists($runtime.'/request-'.$label.'.json'),'Never replay');saveOnce('request-'.$label.'.json',['method'=>$method,'path'=>$path,'body_raw'=>$body,'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);$writer=$label==='W1_DISEASE_EDIT';$cap=$writer?($lane==='B'?80:160):($lane==='B'?60:120);ck(count(file($runtime.'/sql-budget.jsonl'))+$cap+75<=600,'Reserve native+final protection under unified600');if($writer){$before=newRows();foreach($before as $t=>$r)ck($r===[],'Mandatory own related0 before writer');saveOnce('before-'.$label.'.json',$before);}$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,$writer){global $runtime;$rows=newRows();saveOnce('after-'.$label.'.json',['rows'=>$rows,'counts'=>CoreGate::$counts,'generated'=>CoreGate::$generated]);ck(count($rows['user_disease'])===1&&count($rows['habit'])===1&&$rows['user_other_info']===[],'Exactly two own relations and OtherInfo0');if($writer)ck(CoreGate::$counts===['INSERT.yoshop_user_disease'=>1,'INSERT.yoshop_habit'=>1],'Exactly original2I/no hidden DML');foreach(file($runtime.'/business-native.jsonl') as $line){$e=json_decode($line,true);ck($e['scenario']!==$label||!isset($e['error']),'No swallowed native/gate errors');}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()]);}}
