<?php
declare(strict_types=1);
require __DIR__.'/bootstrap.php';require __DIR__.'/StrictWire.php';
$p=json_decode(file_get_contents($runtime.'/private-retention.json'),true);$r=json_decode(file_get_contents($runtime.'/report.json'),true);$check($p['lane']===$lane&&$p['marker']===$marker&&$p['tenants']===$tenants,'Retained chain identity');$owned=$p['owned_unique_tuples'];$fresh=$connect();$counts=[];$complete=0;
foreach($tables as $t){$s=$fresh->prepare('SELECT * FROM yoshop_'.$t.' WHERE store_id IN (?,?)');$s->execute(array_values($tenants));$rows=$s->fetchAll(PDO::FETCH_ASSOC);$counts[$t]=count($rows);foreach($rows as $row){foreach($row as &$v)if(is_resource($v))$v=stream_get_contents($v);unset($v);$store=(int)$row['store_id'];$module=array_search($store,$tenants,true);$family=$t==='h5_setting'?'h5':'wxapp';$key=$row['key'];$check(is_string($module)&&isset($owned[$t][(string)$store][$key]),'Exact retained unique tuple own');$check($row['describe']===($key==='basic'?'基础设置':'审核开关'),'All original describe');$expect=$p['expected_values'][$module][$family][$key];$check(strictWireEqual(json_decode($row['values']),json_decode(json_encode($expect,JSON_UNESCAPED_UNICODE))),'Complete actual retained JSON values/types/containers');$window=$p['update_windows'][$module][$t][$key];$check((int)$row['update_time']>=$window[0]-2&&(int)$row['update_time']<=$window[1]+2,'Original retained Unix time window');if($key==='basic')$check($expect['enabled']===false,'Retained basic enabled=false');else $check($expect['switch']===0,'Retained examine switch0');$complete++;}}
$check($counts===['h5_setting'=>2,'wxapp_setting'=>4]&&$complete===6,'Fresh retained six exact tuples');$check($snapshot()===$p['before'],'Natural two-table all-field SHA exact tuple exclusions');$files=0;if(is_dir($runtime.'/cache'))foreach(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($runtime.'/cache',FilesystemIterator::SKIP_DOTS)) as $f)if($f->isFile())$files++;$check($files===0,'Private token/cache files0');$port=$lane==='B'?18321:18322;$socket=@fsockopen('127.0.0.1',$port,$no,$error,1);$check($socket===false,'Only own worker stopped');
$r['independent_final_original']=['fresh_counts'=>$counts,'six_exact_composite_keys_owned'=>true,'all_five_original_columns_verified'=>true,'full_JSON_scalar_container_and_array_order_verified'=>true,'all_basic_disabled_and_examine_switch_zero'=>true,'native_unix_HTTP_windows_verified'=>true,'natural_two_table_all_fields_sha_unchanged'=>true,'independent_connection_after_worker_stop'=>true,'private_cache_files'=>0,'own_port_listening'=>false];file_put_contents($runtime.'/report.json',json_encode($r,JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES));echo json_encode(['lane'=>$lane,'fresh_counts'=>$counts,'independent_final_original'=>true,'natural_sha_unchanged'=>true,'cache_files'=>$files,'port_listening'=>false]),"\n";
