<?php
require __DIR__.'/oracle.php';$wires=array_map(static function($s){return json_decode($s,true);},file(__DIR__.'/private-wire.jsonl',FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES));$ids=[];foreach($wires as $w){$b=json_decode($w['response'],true);foreach($b['data']['data']??[]as $r)$ids[(string)$r['id']]=$r['id'];}$check(count($ids)<=20,'Returned ID cap20');$returned=[];foreach($ids as $id){$r=$q('SELECT ID,STORE_ID,EVENT_CODE,EVENT_NAME,MODULE,ACTION,RESULT,OPERATOR,USER_UUID,TARGET_TYPE,TARGET_ID,MESSAGE,TERMINAL_IP,REQUEST_METHOD,REQUEST_PATH,TRACE_ID,CONTEXT_JSON,CREATE_TIME AS CREATED_AT,IS_DELETE FROM '.$p.'security_audit_log WHERE ID=?',[$id]);$check(count($r)===1,'Returned ID actual row unique');$check(strlen((string)$r[0]['context_json'])<=262144,'Returned context cap');$returned[]=$r[0];}
$save('private-returned-source.json',$returned);$baseline=json_decode(file_get_contents(__DIR__.'/private-baseline.json'),true);$end=$source();$report=['lane'=>$lane,'scope_count'=>count($end),'scope_sha256'=>$hash($end),'scope_unchanged'=>$baseline['source']===$end,'actor_unchanged'=>$baseline['actor']===$actorNow(),'actual_http'=>count($wires),'returned_original_row_count'=>count($returned),'business_dml'=>0,'ddl'=>0];$save('private-final-audit.json',$report);echo json_encode($report),"\n";
