<?php
declare(strict_types=1);
try{require __DIR__.'/bootstrap.php';$started=microtime(true);$path=parse_url($_SERVER['REQUEST_URI']??'',PHP_URL_PATH);$scenario=$_SERVER['HTTP_X_PILOT_SCENARIO']??'';if(($_SERVER['REQUEST_METHOD']??'')!=='GET'||!preg_match('#^/(store|terminal)/(order/(list|detail)|user\.recharge/order)$#iD',(string)$path)||!preg_match('/^PILOT_OR_[A-Z0-9_]{1,60}$/D',$scenario)){http_response_code(403);echo '{"denied":true}';return;}
ini_set('log_errors','1');ini_set('error_log',$runtime.'/private-errors.log');$_SERVER['SCRIPT_FILENAME']=$root.'/public/index.php';$_SERVER['SCRIPT_NAME']='/index.php';$_SERVER['PHP_SELF']='/index.php';$app=commentApp($root,$runtime);$hosts=['store.order-read.invalid'=>2147001111,'terminal.order-read.invalid'=>2147001112];$app->env->set('store.host',$hosts);$check(isset($hosts[$app->request->host()])&&getStoreId()===$hosts[$app->request->host()],'Tenant host gate');$cfg=$app->config->get('database');foreach($cfg['connections'] as &$c){$c['trigger_sql']=true;$c['debug']=false;}unset($c);$app->config->set($cfg,'database');$app->db->setConfig($app->config);
require __DIR__.'/SqlCoverageRecorder.php';$rec=new SqlCoverageRecorder($runtime.'/queries.jsonl',$root,$scenario);$app->db->listen(static function($sql,$elapsed=null)use($rec,$runtime,$scenario){if(strpos((string)$sql,'CONNECT:')===0)return;$rec->observe($sql,$elapsed);file_put_contents($runtime.'/private-sql.jsonl',json_encode(['scenario'=>$scenario,'sql'=>$sql],JSON_UNESCAPED_UNICODE)."\n",FILE_APPEND|LOCK_EX);chmod($runtime.'/private-sql.jsonl',0600);});register_shutdown_function([$rec,'finish']);
$http=$app->http;$response=$http->run();$hashes=[];$hashFiles=['app/store/model/Order.php','app/terminal/model/Order.php','app/store/model/recharge/Order.php','app/terminal/model/recharge/Order.php','app/common/model/Order.php','app/common/database/DmBuilder.php'];if(strpos($scenario,'PILOT_OR_FINAL_')===0)$hashFiles=array_merge($hashFiles,['app/store/controller/Order.php','app/terminal/controller/Order.php','app/store/controller/user/Recharge.php','app/terminal/controller/user/Recharge.php','app/common/service/OrderReadResponse.php']);foreach($hashFiles as $f){$cl=str_replace('/','\\',substr($f,0,-4));$actual=(new ReflectionClass($cl))->getFileName();$check(realpath($actual)===realpath($root.'/'.$f),'Actual green source root');$hashes[$f]=hash_file('sha256',$actual);}$wire=['scenario'=>$scenario,'method'=>$_SERVER['REQUEST_METHOD'],'path'=>$path,'http_status'=>$response->getCode(),'elapsed_ms'=>(microtime(true)-$started)*1000,'raw'=>$response->getContent(),'original'=>$own(),'source_sha256'=>$hashes];file_put_contents($runtime.'/private-wire.jsonl',json_encode($wire,JSON_UNESCAPED_UNICODE|JSON_PRESERVE_ZERO_FRACTION)."\n",FILE_APPEND|LOCK_EX);chmod($runtime.'/private-wire.jsonl',0600);$response->send();$http->end($response);
}catch(Throwable $e){if(isset($persist))$persist('harness-failure.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()]);}
