<?php
require __DIR__.'/oracle.php';$baseline=json_decode(file_get_contents(__DIR__.'/private-baseline.json'),true);$state=$source();$report=['lane'=>$lane,'actual_http'=>count(file(__DIR__.'/private-wire.jsonl',FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES)),'source_unchanged'=>$baseline['source']===$state,'actor_unchanged'=>$baseline['actor']===$actorNow(),'rows'=>count($state['rows']),'ext_rows'=>count($state['ext']),'source_sha256'=>$hash($state),'business_dml'=>0,'ddl'=>0];$check($report['source_unchanged']&&$report['actor_unchanged'],'Consumed source unchanged');
if(file_exists(__DIR__.'/private-fixture-own.json')){$own=json_decode(file_get_contents(__DIR__.'/private-fixture-own.json'),true);$natural=json_decode(file_get_contents(__DIR__.'/private-fixture-natural.json'),true);$lease=json_decode(file_get_contents(__DIR__.'/private-fixture-lease.json'),true);foreach($own as $name=>$rows){$ids=array_column($rows,'id');$args=implode(',',array_fill(0,count($ids),'?'));$ownNow=$q('SELECT * FROM '.$p.$name.' WHERE ID IN ('.$args.') ORDER BY ID',$ids);$naturalNow=$q('SELECT * FROM '.$p.$name.' WHERE ID NOT IN ('.$args.') ORDER BY ID',$ids);$report['fixture'][$name]=['own_ids'=>$ids,'own_full_value_unchanged'=>$rows===$ownNow,'natural_rows'=>count($naturalNow),'natural_before_sha256'=>$hash($natural[$name]),'natural_after_sha256'=>$hash($naturalNow),'natural_full_value_unchanged'=>$natural[$name]===$naturalNow,'own_full_sha256'=>$hash($ownNow),'retained'=>true];$check($rows===$ownNow&&$natural[$name]===$naturalNow,'Exact own/natural PK values unchanged');}$report['marked_staff_unchanged']=[$lease['staff']]===$q('SELECT ID,UUID,NAME,AI_USER_ID,IS_SHOW,JOB_STATUS FROM '.$p.'staff WHERE UUID=?',[$lease['staff']['uuid']]);$report['marked_user_unchanged']=[$lease['user']]===$q('SELECT ID,UUID,STAFF_UUID,ACCOUNT,TYPE,IS_DELETE FROM '.$p.'user WHERE STAFF_UUID=? AND IS_DELETE=0',[$lease['staff']['uuid']]);$check($report['marked_staff_unchanged']&&$report['marked_user_unchanged'],'Marked reference unchanged');$report['fixture_PDO_INSERTs']=3;}
$save('private-final-audit.json',$report);echo json_encode($report),"\n";
