<?php
declare(strict_types=1);require __DIR__.'/db.php';
$boundary=json_decode(file_get_contents($base.'/__boundary'),true);$check(!isset($boundary['harness_error'])&&$boundary['private_cache']&&$boundary['only_network_and_png_leaves_synthetic'],'Boundary response');foreach($boundary['namespace_resolution'] as $v)$check($v,'Namespace curl resolution');foreach($boundary['hashes'] as $f=>$sha)$check(hash_file('sha256',$root.'/'.$f)===$sha,'Private source hash');
define('TP_ENV','poc');define('BUSINESS','aizhct');define('ENTERPRISE_NO','10001');require $root.'/vendor/autoload.php';spl_autoload_register(static function($class)use($root){foreach(['app\\'=>'app/','cores\\'=>'cores/'] as $prefix=>$dir)if(strpos($class,$prefix)===0){$f=$root.'/'.$dir.str_replace('\\','/',substr($class,strlen($prefix))).'.php';if(is_file($f))require $f;}},true,true);require __DIR__.'/external_boundary.php';$app=new \think\App($root);$app->setEnvName('poc');$app->setRuntimePath($runtime.'/preflight-runtime/');$app->initialize();$log=$app->config->get('log');$log['close']=true;foreach($log['channels'] as &$lc)$lc['close']=true;unset($lc);$app->config->set($log,'log');$app->config->set(['default'=>'file','stores'=>['file'=>['type'=>'File','path'=>$runtime.'/preflight-cache/','prefix'=>'','expire'=>0]]],'cache');$app->instance('cache',new \think\Cache($app));
$offset=is_file($runtime.'/external-leaves.jsonl')?count(file($runtime.'/external-leaves.jsonl')):0;$app->cache->clear();$wx=new \app\common\library\wechat\Qrcode('SYNTHETIC_APP_ID','SYNTHETIC_SECRET');$png=$wx->getQrcode('PREFLIGHT:PRIVATE','pages/home/home','develop');$check(hash('sha256',$png)===hash('sha256',base64_decode('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII=')),'Original WxBase network leaves resolved');$file=$root.'/public/uploads/temp/own-preflight.png';\PHPQRCode\QRcode::png('PREFLIGHT:PRIVATE',$file,'L',5,2);$check(file_get_contents($file)===$png,'Pure third party PNG leaf');unlink($file);$app->cache->clear();
$leaves=array_map(static function($l){return json_decode($l,true);},file($runtime.'/external-leaves.jsonl',FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES));$leaves=array_slice($leaves,$offset);$check(array_column($leaves,'kind')===['token','wx_png','qr_png'],'Exact leaf counts');foreach($leaves as $l)$check($l['network_sent']===false&&$l['scenario']==='PROBE','No external network');$out=['lane'=>$lane,'business_dml'=>0,'boundary'=>$boundary,'leaf_probe'=>['counts'=>array_count_values(array_column($leaves,'kind')),'original_WxBase_and_Qrcode_preserved'=>true,'network_sent'=>false,'private_PNG_verified_and_removed'=>true],'metadata_sha256'=>hash_file('sha256',__DIR__.'/structure-'.$lane.'.json')];file_put_contents(__DIR__.'/preflight-'.$lane.'.json',json_encode($out,JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES));echo json_encode(['lane'=>$lane,'private_paths'=>true,'source_hashes'=>count($boundary['hashes']),'leaf_counts'=>$out['leaf_probe']['counts'],'business_dml'=>0]),"\n";
