<?php
require __DIR__.'/oracle.php';
$auditSourceRows=$source;
try {
 require $root.'/env.php';
 if(!function_exists('json')){function json($data=[],$code=200,array $header=[],$options=[]){return \think\Response::create($data,'json',$code,$header,$options);}}
 require $root.'/external_stubs.php';define('APP_PATH',__DIR__.'/source/application/');define('RUNTIME_PATH',__DIR__.'/runtime/');require $root.'/thinkphp/base.php';\think\App::initCommon();
 \think\Config::set(['type'=>'File','path'=>__DIR__.'/cache/','prefix'=>'SECURITY10_'],'cache');\think\Config::set('redis',[]);\think\Config::set(require $root.'/application/database.php','database');\think\Db::clear();
 $service=new \app\common\service\SecurityAuditService();$spec=json_decode(file_get_contents(__DIR__.'/private-spec.json'),true);$checks=[];$original=$auditSourceRows();
 foreach($spec as $s){$response=$service->lists($s['params']);$wanted=$s['label']==='no_match'?[]:array_slice($original,((int)$s['params']['page']-1)*2,2);foreach($wanted as &$r){$r['id']=(int)$r['id'];$r['store_id']=(int)$r['store_id'];$raw=$r['context_json'];$decoded=json_decode((string)$raw,true);unset($r['context_json']);$r['context']=is_array($decoded)?$decoded:[];if($lane==='C'&&is_string($r['created_at'])&&preg_match('/^(.{19})\.0{1,6}$/D',$r['created_at'],$m))$r['created_at']=$m[1];}unset($r);$checks[$s['label'].'_all18_values_types']=$response['data']===$wanted;$checks[$s['label'].'_paging_count']=$response['total']===($s['label']==='no_match'?0:count($original))&&$response['current_page']===(int)$s['params']['page']&&$response['per_page']===2;}
 $checks['source_unchanged']=$original===$auditSourceRows();$checks['actor_unchanged']=$actor===$actorNow();$save('private-runtime-gate.json',['lane'=>$lane,'checks'=>$checks,'passed'=>!in_array(false,$checks,true)]);echo json_encode(['lane'=>$lane,'checks'=>$checks,'passed'=>!in_array(false,$checks,true)]),"\n";exit(in_array(false,$checks,true)?2:0);
}catch(Throwable $e){$save('private-init-error.json',['class'=>get_class($e),'message'=>$e->getMessage(),'file'=>$e->getFile(),'line'=>$e->getLine()]);echo json_encode(['class'=>get_class($e),'reason_sha256'=>hash('sha256',$e->getMessage())]),"\n";exit(2);}
