<?php
require __DIR__.'/common.php';
$lock=json_decode(file_get_contents(__DIR__.'/source-lock.json'),true);if(count($lock)!==958||hash_file('sha256',__DIR__.'/source-lock.json')!=='57d57588410be71682c8597d092b125cb26cf2b3d489b6ce7f1a136c56bad96b')throw new RuntimeException('Full source lock identity');foreach($lock as $f=>$h)if(hash_file('sha256',__DIR__.'/source/application/'.$f)!==$h)throw new RuntimeException('Locked source drift '.$f);
$lease=json_decode(file_get_contents(__DIR__.'/private/lease-expected-'.$lane.'.json'),true)['source_after'];$current=$source();if($lease!==$current)throw new RuntimeException('Fresh full lease');$ports=[];foreach([18921,18922]as $port){$s=@fsockopen('127.0.0.1',$port,$n,$e,0.5);$ports[$port]=$s!==false;if($s)fclose($s);}if(array_filter($ports))throw new RuntimeException('Port collision');
$tools=[];foreach(['common.php','observe.php','NativeGate.php','app-init.php','index.php','auth.php','fetch.php','launcher.php','test-gate.php','cleanup.php','plan.json','readiness.php']as $f)$tools[$f]=hash_file('sha256',__DIR__.'/'.$f);$save('readiness.json',['lane'=>$lane,'source_count'=>count($lock),'source_lock_sha256'=>hash_file('sha256',__DIR__.'/source-lock.json'),'all_source_equal'=>true,'tools'=>$tools,'full_lease_equal'=>true,'source'=>$current,'ports'=>$ports,'HTTP'=>0,'DML'=>0,'DDL'=>0,'oracle'=>$GLOBALS['NF_ORACLE']]);echo json_encode(['lane'=>$lane,'source958'=>true,'full_lease_equal'=>true,'ports'=>$ports,'HTTP'=>0,'DML'=>0,'DDL'=>0]),PHP_EOL;
