<?php
declare(strict_types=1);define('CDX_GRADE_CONTEXT',true);require __DIR__.'/preflight.php';$baseline=json_decode(file_get_contents(__DIR__.'/private-baseline.json'),true);$lease=json_decode(file_get_contents(__DIR__.'/private-lease.json'),true);$finish=json_decode(file_get_contents(__DIR__.'/private-finish.json'),true);$checks=[];
foreach($baseline['tables']as $table=>$source){$checks[$table.'_all_original_rows_unchanged']=$report['tables'][$table]['sha256']===$source['sha256'];foreach(['columns','indexes','triggers','foreign_keys']as $kind)$checks[$table.'_'.$kind.'_unchanged']=json_encode($report['tables'][$table][$kind])===json_encode($source[$kind]);$checks[$table.'_zero_remaining']=$report['tables'][$table]['rows']===0;}
$checks['staff_reference_unchanged']=$report['synthetic_reference']['staff_projection_sha256']===$baseline['synthetic_reference']['staff_projection_sha256'];$checks['user_reference_unchanged']=$report['synthetic_reference']['user_projection_sha256']===$baseline['synthetic_reference']['user_projection_sha256'];$checks['all_formal_deletes_success']=$finish['failure']===null&&$finish['business_dml']===2&&$finish['fixture_dml']===0;
$out=['lane'=>$lane,'independent_new_connection'=>true,'business_dml'=>0,'ddl'=>0,'checks'=>$checks,'all_passed'=>!in_array(false,$checks,true),'retained_rows'=>0,'source_rows'=>array_map(static function($x){return $x['rows'];},$report['tables']),'business_sha256'=>[]];foreach(['GradeEstimation','JudgmentRank']as $class)$out['business_sha256'][$class]=hash_file('sha256',__DIR__.'/source/application/p/logic/'.$class.'.php');file_put_contents(__DIR__.'/private-final-audit.json',json_encode($out,JSON_PRETTY_PRINT));chmod(__DIR__.'/private-final-audit.json',0600);echo json_encode($out),"\n";exit($out['all_passed']?0:2);
