<?php
declare(strict_types=1);require __DIR__.'/bootstrap.php';$journal=json_decode(file_get_contents($runtime.'/run-journal.json'),true);$pre=json_decode(file_get_contents($runtime.'/preflight.json'),true);$check($journal['complete']&&$journal['own_token_absent'],'All approved stages complete and token absent');$final=$own();$check($final===$journal['after'],'Independent final original exact');foreach($pre['baseline'] as $t=>$rows){$pk=trim($pks[$t],'`"');$ids=array_column($rows,$pk);$kept=array_values(array_filter($final[$t],static function($r)use($ids,$pk){return in_array($r[$pk],$ids,true);}));$check($kept===$rows,'Old sealed full rows exact '.$t);if(!in_array($t,['goods','goods_sku','goods_image'],true))$check($final[$t]===$rows,'No unapproved new rows '.$t);}$g=$read('SELECT * FROM yoshop_goods WHERE goods_id=? AND store_id=2147001112 AND goods_no=?',[$journal['new_goods_id'],$marker]);$check(count($g)===1&&(int)$g[0]['is_delete']===1&&(int)$g[0]['status']===20&&(int)$g[0]['stock_total']===0,'Final new product hidden zero stock');$check($protect()===$pre['protect'],'Natural/default unchanged');$persist('final-original.json',['original'=>$final,'protect'=>$protect(),'new_goods_id'=>$journal['new_goods_id']]);$dir=$runtime.'/evidence';if(!is_dir($dir))mkdir($dir,0700);foreach(['preflight.json','run-journal.json','final-original.json','private-wire.jsonl','private-sql.jsonl','queries.jsonl'] as $name){copy($runtime.'/'.$name,$dir.'/'.$name);chmod($dir.'/'.$name,0600);}
foreach(glob($runtime.'/native-*/*.json') as $file){$r=json_decode(file_get_contents($file),true);if(isset($r['run'])){$phase=substr(basename(dirname($file)),7);$native=['stats'=>$r['run']['stats'],'failures'=>count($r['run']['failures']),'raw_result_sha256'=>hash_file('sha256',$file)];file_put_contents(__DIR__.'/native-'.$phase.'-'.$lane.'.json',json_encode($native,JSON_PRETTY_PRINT));}}$out=['lane'=>$lane,'all_old_twenty_table_rows_exact'=>true,'natural_default_unchanged'=>true,'own_token_absent'=>true,'new_goods_id'=>$journal['new_goods_id'],'retained_goods_softdeleted'=>true,'retained_sku'=>count($read('SELECT id FROM yoshop_goods_sku WHERE goods_id=? AND store_id=2147001112',[$journal['new_goods_id']])),'retained_image'=>count($read('SELECT id FROM yoshop_goods_image WHERE goods_id=? AND store_id=2147001112',[$journal['new_goods_id']])),'evidence'=>$dir];file_put_contents(__DIR__.'/audit-'.$lane.'.json',json_encode($out,JSON_PRETTY_PRINT));echo json_encode($out),"\n";
