<?php
declare(strict_types=1);require __DIR__.'/bootstrap.php';$fixture=json_decode(file_get_contents($runtime.'/fixture-journal.json'),true);$final=$own();foreach($fixture['after'] as $t=>$rows)if($t!=='printer')$check($final[$t]===$rows,'Final prior/preparation rows exact '.$t);$check(count($final['printer'])===2,'Exactly two API-created records');foreach($final['printer'] as $p)$check((int)$p['is_delete']===1&&(int)$p['print_times']===0&&strpos($p['printer_name'],$marker.'_')===0,'Softdeleted own inert Printer');$check($protect()===$fixture['before_protect'],'Natural/default final exact');$persist('final-original.json',['original'=>$final,'protect'=>$protect()]);$e=$runtime.'/evidence';if(!is_dir($e))mkdir($e,0700);foreach(glob($runtime.'/*') as $file){$name=basename($file);if(preg_match('/^(?:fixture-journal|recovery-journal|inspect-raw|final-original|run-[A-Z]+|cases-[A-Z]+)\.json$|^(?:private-wire|private-sql|queries)\.jsonl$/D',$name)){copy($file,$e.'/'.$name);chmod($e.'/'.$name,0600);}}
$native=[];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[$phase]=['stats'=>$r['run']['stats'],'failures'=>array_map(static function($f){return ['error_name'=>$f['error']['name']??null,'message'=>$f['error']['message']??null,'item'=>$f['source']['name']??null];},$r['run']['failures']),'raw_result_sha256'=>hash_file('sha256',$file)];file_put_contents(__DIR__.'/native-'.$phase.'-'.$lane.'.json',json_encode($native[$phase],JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE));}}
$report=['lane'=>$lane,'final_nonprinter_20table_scope_exact'=>true,'retained_api_printers'=>array_map(static function($p){return ['printer_id'=>(int)$p['printer_id'],'store_id'=>(int)$p['store_id'],'is_delete'=>(int)$p['is_delete']];},$final['printer']),'natural_default_unchanged'=>true,'evidence'=>$e,'files'=>array_map('basename',glob($e.'/*'))];file_put_contents(__DIR__.'/audit-'.$lane.'.json',json_encode($report,JSON_PRETTY_PRINT));echo json_encode($report),"\n";
