<?php
declare(strict_types=1);$_SERVER['HTTP_HOST']='customer-fast5.invalid';require __DIR__.'/app.php';require __DIR__.'/data.php';require __DIR__.'/scope.php';require __DIR__.'/fast-scope.php';$app=coreApp('PREFLIGHT');ck(!file_exists($runtime.'/preflight-state.json')&&date('Y')==='2026','Fresh exact year');$meta=[];foreach(['AI','ZHCT'] as $db){$id=readNative($db,$dm?"SELECT SYS_CONTEXT('USERENV','CURRENT_SCHEMA') schema_name FROM DUAL":'SELECT DATABASE() schema_name,VERSION() version');ck($id[0]['schema_name']===getenv('POC_'.$db.'_SCHEMA'),'Independent approved schema');if(!$dm)ck(strpos($id[0]['version'],'5.6.')===0,'MySQL56');$tables=readNative($db,$dm?'SELECT TABLE_NAME FROM USER_TABLES ORDER BY TABLE_NAME':"SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA=DATABASE() AND TABLE_TYPE='BASE TABLE' ORDER BY TABLE_NAME");$meta[$db]=['schema'=>getenv('POC_'.$db.'_SCHEMA'),'tables'=>array_map('strtolower',array_column($tables,'table_name'))];}saveOnce('metadata-tables.json',$meta);CoreGate::$metadataMap=$meta;$preferred=$lane==='B'?44676:1836;$u=readNative('AI','SELECT * FROM yoshop_user WHERE user_id=? AND store_id=?',[$preferred,10001]);$proof=json_decode(file_get_contents($runtime.'/old-marked-user.json'),true);$fallback=false;if($u!==$proof['user_fullrows']){$base=json_decode(file_get_contents($runtime.'/AI-baseline.json'),true);$u=readNative('AI','SELECT * FROM yoshop_user WHERE user_id=? AND store_id=?',[$base['user'][0]['user_id'],10001]);ck($u===$base['user'],'Only original or exactknown fallback actor');$fallback=true;}ck(count($u)===1&&$u[0]['is_delete']===0,'Real marked identity');$uid=$u[0]['user_id'];$staff=readNative('AI','SELECT * FROM yoshop_staff WHERE user_id=? AND store_id=? AND is_delete=0',[$uid,10001]);ck(count($staff)===1,'Actual own AIStaff relation, not StoreID');saveOnce('owned-actor.json',['user_id'=>$uid,'staff_id'=>$staff[0]['id'],'store_id'=>10001,'marker'=>$u[0]['nick_name'],'preferred_exact_sealed_actor'=>!$fallback]);$z=readNative('ZHCT','SELECT * FROM ydy_user WHERE ai_user_id=? AND is_delete=0',[$uid],true);ck(count($z)<=1,'Exact source linked StoreUser cardinality');saveOnce('auth-version.json',['password_version'=>(int)($z[0]['password_version']??0),'linked_StoreUserID'=>$z[0]['id']??null,'no_credentials_saved'=>true]);$sessions=readNative('ZHCT','SELECT * FROM ydy_measurement_session WHERE ai_user_id=? AND vendor=? AND is_valid=1 ORDER BY start_time DESC',[$uid,'yingjiduo']);$type=1;foreach([1,2,3] as $t){$have=array_values(array_filter($sessions,static function($s)use($t){return in_array($s['device_type'],typeDevices($t),true);}));if($have){$type=$t;break;}}$devices=typeDevices($type);$owned=array_values(array_filter($sessions,static function($s)use($devices){return in_array($s['device_type'],$devices,true);}));$day=$owned?substr($owned[0]['start_time'],0,10):'2026-10-11';ck(preg_match('/^\d{4}-\d\d-\d\d$/D',$day)&&strtotime($day)!==false,'Actual original selected day');$action=readNative('AI','SELECT * FROM yoshop_sign_action WHERE store_id=? AND is_delete=0 AND status=1 ORDER BY id'.($dm?' FETCH FIRST 1 ROWS ONLY':' LIMIT 1'),[10001]);$signId=$action[0]['id']??0;$scope=['type'=>$type,'devices'=>$devices,'day'=>$day,'own_session_ids'=>array_column($owned,'session_id'),'sign_id'=>$signId,'own_sports_empty_only'=>$owned===[],'no_fixture'=>true];saveOnce('fast-scope.json',$scope);$schema=[];foreach(['sign_action','sign_address'] as $t){$arg=$dm?strtoupper('yoshop_'.$t):'yoshop_'.$t;$schema[$t]=readNative('AI',$dm?'SELECT COLUMN_NAME,DATA_TYPE,NULLABLE,DATA_DEFAULT FROM USER_TAB_COLUMNS WHERE TABLE_NAME=? ORDER BY COLUMN_ID':'SELECT COLUMN_NAME,DATA_TYPE,COLUMN_TYPE,IS_NULLABLE,COLUMN_DEFAULT FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA=DATABASE() AND TABLE_NAME=? ORDER BY ORDINAL_POSITION',[$arg]);ck(count($schema[$t])>0,'Original source field columns');}saveOnce('sign-schema.json',$schema);$snap=fastSnapshot();saveOnce('source-snapshot.json',$snap);saveOnce('preflight-state.json',['actor'=>$u,'actor_staff'=>$staff,'preferred_exact_sealed_actor'=>!$fallback,'source'=>sourceProof(),'protection'=>fastProtection(),'snapshot_sha256'=>hash('sha256',json_encode($snap,JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES|JSON_PRESERVE_ZERO_FRACTION)),'HTTP'=>0,'DMLDDL'=>0]);echo json_encode(['lane'=>$lane,'actor'=>$uid,'type'=>$type,'day'=>$day,'own_sports_sessions'=>count($owned),'rank_global_sessions'=>count($snap['global_sessions']),'published_sign_id'=>$signId,'SQL'=>count(file($runtime.'/sql-budget.jsonl')),'HTTP'=>0,'DMLDDL'=>0]),"\n";
