<?php
declare(strict_types=1);require __DIR__.'/app.php';require __DIR__.'/data.php';require __DIR__.'/observer.php';$app=coreApp('PURE_TOOL_TEST');$n=0;foreach(['INSERT INTO ydy_measurement_session VALUES(1)','UPDATE yoshop_user SET balance=0','DELETE FROM ydy_staff','DROP TABLE yoshop_user','SELECT * FROM ydy_config','CALL arbitrary(?)','SELECT * FROM other_schema.ydy_health_record FOR UPDATE'] as $sql){$bad=false;try{CoreGate::kind(strpos($sql,'yoshop_')!==false?'AI':'ZHCT',$sql);}catch(Throwable $e){$bad=true;}ck($bad,'Reject unapproved write/table/lock SQL');$n++;}foreach(['','other.ydy_staff','ydy_never_existing'] as $t){$bad=false;try{CoreGate::known('ZHCT',$t);}catch(Throwable $e){$bad=true;}ck($bad,'Exact existing metadata names only');$n++;}$events=[];$response=new class{function getCode(){return 200;}function getHeader(){return ['Content-Type'=>'application/json'];}function getContent(){return '{"ok":true}';}};preserveSendObserve($response,static function($r)use(&$events){$events[]='save';},static function()use(&$events){$events[]='send';},static function($r){throw new RuntimeException('observer-fault');},static function($e)use(&$events){$events[]='error';},1,2);ck($events===['save','send','error'],'Wire persistence before send, observer isolated');$n++;saveOnce('pure-gate-tests.json',['checks'=>$n,'passed'=>true,'SQL'=>0,'HTTP'=>0,'DMLDDL'=>0,'source_read_app_initialization_only'=>true]);echo json_encode(['lane'=>$lane,'checks'=>$n,'SQL'=>0,'HTTP'=>0]),"\n";
