<?php
$root=dirname(__DIR__); $tests=[]; function t(&$a,$n,$ok){$a[]=['name'=>$n,'status'=>$ok?'PASS':'FAIL'];}
t($tests,'version_target',strpos(file_get_contents($root.'/DDB_VERSION.json'),'11.0.11.58')!==false);
t($tests,'request_trace_class',is_file($root.'/app/Core/RequestTrace.php'));
t($tests,'browser_probe',is_file($root.'/public/assets/js/revenue-performance-trace.js'));
t($tests,'summary_tool',is_file($root.'/tools/revenue-end-to-end-summary.php'));
$idx=file_get_contents($root.'/public/index.php'); t($tests,'beacon_route',strpos($idx,'revenue-performance-beacon')!==false);
$c=file_get_contents($root.'/app/Controllers/RevenueController.php'); foreach(['auth_session','revenue_query','profit_loss_query','payload_preparation','performanceBeacon'] as $x)t($tests,'controller_'.$x,strpos($c,$x)!==false);
$d=file_get_contents($root.'/app/Core/Database.php'); t($tests,'oracle_connection_timing',strpos($d,"begin('oracle_connection')")!==false);
$vw=file_get_contents($root.'/app/Core/View.php'); foreach(['view_content_render','layout_render','emitHeaders'] as $x)t($tests,'view_'.$x,strpos($vw,$x)!==false);
t($tests,'no_oracle_writes',!preg_match('/\b(insert|update|delete|merge)\s+into\b/i',$c.$d));
$f=array_filter($tests,fn($x)=>$x['status']==='FAIL'); echo json_encode(['phase'=>'H11.0-P11.1-R45-P2.1','total'=>count($tests),'pass'=>count($tests)-count($f),'fail'=>count($f),'tests'=>$tests],JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES).PHP_EOL; exit($f?1:0);
