<?php
declare(strict_types=1);
require __DIR__.'/bootstrap.php';require __DIR__.'/StrictWire.php';$p=json_decode(file_get_contents($runtime.'/private-report.json'),true);$fresh=$connect();$s=$fresh->query('SELECT * FROM yoshop_page WHERE store_id IN (2147001521,2147001522) ORDER BY page_id');$rows=$s->fetchAll(PDO::FETCH_ASSOC);foreach($rows as &$r)foreach($r as &$v)if(is_resource($v))$v=stream_get_contents($v);unset($r,$v);$check(count($rows)===4,'Independent final four owned rows');foreach($rows as $r)$check((int)$r['page_type']===20&&(int)$r['is_delete']===1&&strpos($r['page_data'],$marker)!==false,'Independent retained nonhome soft-delete marker');$check($snapshot()===$p['before'],'Final independent full natural SHA');
$audit=[];foreach(file($runtime.'/private-write-sql.jsonl',FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES)?:[] as $l){$w=json_decode($l,true);$sql=$w['sql'];$op=strtoupper(strtok(trim($sql),' '));$table=preg_match('/(?:INTO|UPDATE)\s+["`]?yoshop_page["`]?\b/i',$sql)===1;$tenant=$op==='UPDATE'?preg_match('/store_id["`]?\s*=\s*[\x27]?'.$w['tenant'].'\b/i',$sql)===1:strpos($sql,(string)$w['tenant'])!==false;$audit[]=['scenario'=>$w['scenario'],'operation'=>$op,'only_page_table'=>$table,'own_tenant_predicate'=>$tenant,'sql_sha256'=>hash('sha256',$sql)];$check($table&&$tenant&&in_array($op,['UPDATE','INSERT'],true),'Actual all DML table/tenant audit');}
$counts=['requests'=>0,'assertions'=>0,'failures'=>0];foreach($p['cli_stats'] as $v){$counts['requests']+=$v['stats']['requests']['total'];$counts['assertions']+=$v['stats']['assertions']['total'];$counts['failures']+=$v['failures'];}$check($counts['requests']===30&&$counts['assertions']===150&&$counts['failures']===0,'Actual Native CLI totals');$check(count($p['cases'])===30&&count($p['proofs'])===16&&$p['errors']===[],'Complete original chain');
$epochs=[];foreach(file($runtime.'/private-write-sql.jsonl',FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES)?:[] as $line){$w=json_decode($line,true);if(preg_match('/["`]?update_time["`]?\s*=\s*[\x27]?(\d{10})\b/i',$w['sql'],$m))$epochs[$w['scenario']]=(int)$m[1];}
$p['independent_final_original_rows']=$rows;$p['actual_SQL_update_epochs']=$epochs;$p['write_audit']=$audit;$p['native_cli_totals']=$counts;$p['final_natural_unchanged']=true;$p['metadata']=$gate;$p['request_container_rule']='Original ThinkPHP postForm associative parse converts incoming empty object to empty array; asserted on both lanes, not ignored in response comparison';
file_put_contents(__DIR__.'/evidence-'.$lane.'.json',json_encode($p,JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES|JSON_PRESERVE_ZERO_FRACTION));$j=json_decode(file_get_contents($runtime.'/private-journal.json'),true);$items=[];foreach($j['collections'] as $collection){$item=$collection['item'][0]['item'][0];foreach($item['request']['header'] as &$h)if($h['key']==='Access-Token')$h['value']='{{'.$item['id'].'_PRIVATE_TOKEN}}';unset($h);$item['request']['url']=str_replace($base,'{{base_url}}',$item['request']['url']);$items[]=$item;}$collection=['apifoxCli'=>'2.2.8','info'=>['name'=>'Page已执行场景档案，写步骤仅可在新的自有租户运行'],'item'=>[['name'=>'Page原生CLI真实请求档案','item'=>$items]]];file_put_contents(__DIR__.'/page-executed-'.$lane.'.apifox-cli.json',json_encode($collection,JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES));
$out=['lane'=>$lane,'actual_requests'=>$counts['requests'],'actual_assertions'=>$counts['assertions'],'DML_audit'=>count($audit),'every_write_own_tenant'=>true,'four_owned_rows_retained_nonhome_softdeleted'=>true,'natural_sha_unchanged'=>true];file_put_contents(__DIR__.'/resource-cleanup-'.$lane.'.json',json_encode($out,JSON_PRETTY_PRINT));echo json_encode($out),"\n";
