<?php
require __DIR__.'/db.php';$report=['lane'=>$lane,'passed'=>false,'business_dml'=>0,'ddl'=>0,'HTTP'=>0];try{
$identity=$lane==='B'?$q('SELECT VERSION() AS VERSION,@@SESSION.sql_mode AS SESSION_SQL_MODE,@@GLOBAL.sql_mode AS GLOBAL_SQL_MODE'):$q("SELECT SYS_CONTEXT('USERENV','CURRENT_SCHEMA') AS SCHEMA_NAME FROM DUAL");$check($lane==='B'?strpos($identity[0]['version'],'5.6.')===0:$identity[0]['schema_name']==='ZHCT_APP','Database identity');$report['identity']=$identity;
$actors=$q('SELECT * FROM '.$p.'user WHERE ID=(SELECT MIN(ID) FROM '.$p.'user WHERE TYPE=0 AND IS_DELETE=0)');$check(count($actors)===1&&strlen($actors[0]['uuid'])===36,'Actual actor UUID36');$actor=$actors[0];
$nameSha=$lane==='B'?'f483ba1c130ac167b850ae5099196f085b2f5b7db2faf5787a201eb5f7dbf321':'8b7f1416ace012169e9ac5c94fceb49115287a7006c1f0712ebac2d30af000b4';$staffs=array_values(array_filter($q('SELECT * FROM '.$p.'staff WHERE NAME LIKE ?',['CDXPAY%']),static function($r)use($nameSha){return preg_match('/^CDXPAY[A-F0-9]{8}$/D',$r['name'])===1&&hash('sha256',$r['name'])===$nameSha;}));$check(count($staffs)===1,'Exact dedicated marked Staff');$staff=$staffs[0];$users=$q('SELECT * FROM '.$p.'user WHERE STAFF_UUID=? AND IS_DELETE=0',[$staff['uuid']]);$check(count($users)===1&&$users[0]['account']===$staff['name']&&(int)$users[0]['type']===1&&(int)$staff['is_show']===1,'Unique marked user mapping');
$baseline=['staff'=>[$staff],'user'=>$users,'actor'=>[$actor]];$sentinelIds=['syllabus_evaluate'=>['1','2'],'syllabus_evaluate_ext'=>['1']];$natural=[];$oldMarker=$lane==='B'?'CDXSYLB20261010_0E1A13':'CDXSYLC20261010_CB7CDD';
foreach(['syllabus_evaluate','syllabus_evaluate_ext']as $t){$table=$p.$t;$cols=$lane==='B'?$q('SELECT COLUMN_NAME,COLUMN_TYPE,IS_NULLABLE,COLUMN_DEFAULT,EXTRA,DATETIME_PRECISION FROM information_schema.COLUMNS WHERE TABLE_SCHEMA=DATABASE() AND TABLE_NAME=? ORDER BY ORDINAL_POSITION',[$table]):$q('SELECT COLUMN_NAME,DATA_TYPE,DATA_LENGTH,DATA_SCALE,NULLABLE,DATA_DEFAULT FROM USER_TAB_COLUMNS WHERE TABLE_NAME=? ORDER BY COLUMN_ID',[strtoupper($table)]);$expected=$t==='syllabus_evaluate'?['id','uuid','staff_uuid','test_content','test_time','achievement','demo','create_time','create_by']:['id','uuid','staff_uuid','content'];$check(array_map(static function($c){return strtolower($c['column_name']);},$cols)===$expected,'All fields known');
$triggers=$lane==='B'?$q('SELECT TRIGGER_NAME,EVENT_MANIPULATION FROM information_schema.TRIGGERS WHERE TRIGGER_SCHEMA=DATABASE() AND EVENT_OBJECT_TABLE=?',[$table]):$q('SELECT TRIGGER_NAME,STATUS,TRIGGERING_EVENT FROM USER_TRIGGERS WHERE TABLE_NAME=?',[strtoupper($table)]);$fk=$lane==='B'?$q('SELECT TABLE_NAME,CONSTRAINT_NAME,REFERENCED_TABLE_NAME FROM information_schema.KEY_COLUMN_USAGE WHERE TABLE_SCHEMA=DATABASE() AND REFERENCED_TABLE_NAME IS NOT NULL AND (TABLE_NAME=? OR REFERENCED_TABLE_NAME=?)',[$table,$table]):$q("SELECT C.TABLE_NAME,C.CONSTRAINT_NAME,P.TABLE_NAME AS REFERENCED_TABLE_NAME FROM USER_CONSTRAINTS C LEFT JOIN USER_CONSTRAINTS P ON C.R_CONSTRAINT_NAME=P.CONSTRAINT_NAME WHERE C.CONSTRAINT_TYPE='R' AND (C.TABLE_NAME=? OR P.TABLE_NAME=?)",[strtoupper($table),strtoupper($table)]);$check($triggers===[]&&$fk===[],'No triggers or incoming/outgoing FK');$indexes=$lane==='B'?$q('SELECT INDEX_NAME,NON_UNIQUE,SEQ_IN_INDEX,COLUMN_NAME FROM information_schema.STATISTICS WHERE TABLE_SCHEMA=DATABASE() AND TABLE_NAME=? ORDER BY INDEX_NAME,SEQ_IN_INDEX',[$table]):$q('SELECT I.INDEX_NAME,I.UNIQUENESS,C.COLUMN_POSITION,C.COLUMN_NAME FROM USER_INDEXES I JOIN USER_IND_COLUMNS C ON I.INDEX_NAME=C.INDEX_NAME WHERE I.TABLE_NAME=? ORDER BY I.INDEX_NAME,C.COLUMN_POSITION',[strtoupper($table)]);
$rows=$q('SELECT * FROM '.$table.' ORDER BY ID');$ownRows=array_values(array_filter($rows,static function($r)use($staff){return $r['staff_uuid']===$staff['uuid'];}));$check(array_map('strval',array_column($ownRows,'id'))===$sentinelIds[$t],'Exact old sentinel PKs');foreach($ownRows as $r)$check(strpos($r[$t==='syllabus_evaluate'?'test_content':'content'],$oldMarker)!==false,'Explicit old marker sentinel');$baseline[$t]=$rows;$natural[$t]=array_values(array_filter($rows,static function($r)use($t,$sentinelIds){return !in_array((string)$r['id'],$sentinelIds[$t],true);}));$check(count($natural[$t])===0,'Original natural tables still zero');$report['tables'][$t]=['columns'=>$cols,'indexes'=>$indexes,'triggers'=>$triggers,'foreign_keys'=>$fk,'natural_count'=>count($natural[$t]),'natural_sha256'=>$hash($natural[$t]),'sentinel_count'=>count($ownRows),'sentinel_sha256'=>$hash($ownRows)];}
$marker='CDXSYC'.$lane.'20261011_'.strtoupper(bin2hex(random_bytes(3)));$check((int)$q('SELECT COUNT(*) AS CNT FROM '.$p.'syllabus_evaluate WHERE TEST_CONTENT LIKE ?',['%'.$marker.'%'])[0]['cnt']===0,'New marker absent');$absent='CD000000-0000-4000-8000-'.strtoupper(bin2hex(random_bytes(6)));$check((int)$q('SELECT COUNT(*) AS CNT FROM '.$p.'syllabus_evaluate WHERE UUID=?',[$absent])[0]['cnt']===0,'Absent UUID proven');
$lease=['lane'=>$lane,'staff_uuid'=>$staff['uuid'],'actor_id'=>$actor['id'],'actor_uuid'=>$actor['uuid'],'marker'=>$marker,'absent_uuid'=>$absent,'baseline'=>$baseline,'sentinel_ids'=>$sentinelIds,'natural'=>$natural];$save('private-lease.json',$lease);
$lock=[];foreach(['p/controller/SyllabusEvaluate.php','p/logic/SyllabusEvaluate.php','model/SyllabusEvaluate.php','model/SyllabusEvaluateExt.php','model/Staff.php','model/UserData.php','model/RoleData.php','model/SyncFeimao.php','model/BaseModel.php','validate/SyllabusEvaluate.php','base/AdminController.php','common.php','route.php']as $file)$lock[$file]=hash_file('sha256',__DIR__.'/source/application/'.$file);$save('private-source-lock.json',$lock);$report['source_lock']=$lock;
require __DIR__.'/init.php';$check((int)\think\Config::get('pagesize')===10,'Inherited pagesize10');$probe=\think\Db::table($p.'syllabus_evaluate')->where('id',1)->find();$check((string)$probe['id']==='1','Pure CLI init and actual PDO field access');if($lane==='B')$report['actual_TP_sql_mode']=\think\Db::query('SELECT @@SESSION.sql_mode AS session_sql_mode,@@GLOBAL.sql_mode AS global_sql_mode');$report['reference']=['staff_sha256'=>$hash($baseline['staff']),'user_sha256'=>$hash($baseline['user']),'actor_sha256'=>$hash($baseline['actor']),'actor_uuid_length'=>36];$report['marker']=$marker;$report['passed']=true;
}catch(Throwable $e){$save('private-error.json',['class'=>get_class($e),'message'=>$e->getMessage()]);$report['failure']=['class'=>get_class($e),'reason_sha256'=>hash('sha256',$e->getMessage())];}$save('private-preflight.json',$report);echo json_encode($report,JSON_UNESCAPED_UNICODE),"\n";exit($report['passed']?0:2);
