151 lines
8.0 KiB
PHP
151 lines
8.0 KiB
PHP
<?php
|
|
// WEVIA QUALITY AGENT — cron */10
|
|
// Monitors ALL test suites: L99 UX, L99 Auth, NonReg, Full NonReg, Chat Monitor, 6sigma
|
|
header("Content-Type: application/json");
|
|
$LOG="/var/log/wevia-quality-agent.log";
|
|
$SF="/var/www/html/api/wevia-quality-status.json";
|
|
$ts=date("H:i");
|
|
$suites=[];$total_pass=0;$total_fail=0;$issues=[];
|
|
|
|
function lg($m){global $LOG,$ts;file_put_contents($LOG,"$ts $m
|
|
",FILE_APPEND);}
|
|
|
|
// 1. L99 UX Agent
|
|
$l99=@json_decode(@file_get_contents('/var/www/html/api/l99-ux-results.json'),true);
|
|
if($l99){$p=$l99['pass']??0;$f=$l99['fail']??0;$w=$l99['warn']??0;$total_pass+=$p;$total_fail+=$f;
|
|
$suites['l99_ux']=['pass'=>$p,'fail'=>$f,'warn'=>$w,'total'=>$p+$f+$w,'ts'=>$l99['timestamp']??''];
|
|
if($f>0)$issues[]="L99 UX: {$f} failures";}
|
|
|
|
// 2. L99 Auth
|
|
$auth=@json_decode(@file_get_contents('/var/www/html/api/l99-auth-results.json'),true);
|
|
if($auth){$p=$auth['pass']??0;$f=$auth['fail']??0;$total_pass+=$p;$total_fail+=$f;
|
|
$suites['l99_auth']=['pass'=>$p,'fail'=>$f,'total'=>$p+$f];
|
|
if($f>0)$issues[]="L99 Auth: {$f} failures";}
|
|
|
|
// 3. NonReg (153 tests)
|
|
$nr=@json_decode(@file_get_contents('/var/www/html/api/nonreg-latest.json'),true);
|
|
if($nr){$p=$nr['pass']??0;$f=$nr['fail']??0;$total_pass+=$p;$total_fail+=$f;
|
|
$suites['nonreg']=['pass'=>$p,'fail'=>$f,'total'=>$nr['total']??0];
|
|
if($f>0){$fails=[];foreach($nr['tests']??[] as $t){if(($t['status']??'')==='FAIL')$fails[]=$t['name'];}
|
|
$issues[]="NonReg: {$f} failures (".implode(', ',array_slice($fails,0,3)).")";}}
|
|
|
|
// 4. Full NonReg Dashboard (35 tests)
|
|
$fnr=@json_decode(@file_get_contents('/var/www/html/test-report/full-nonreg-results.json'),true);
|
|
if($fnr){$p=$fnr['pass']??0;$f=$fnr['fail']??0;$total_pass+=$p;$total_fail+=$f;
|
|
$suites['full_nonreg']=['pass'=>$p,'fail'=>$f,'total'=>$fnr['total']??0,'rate'=>$fnr['total']>0?round($p/$fnr['total']*100):0];
|
|
if($f>0)$issues[]="Full NonReg: {$f}/{$fnr['total']} failures ({$suites['full_nonreg']['rate']}%)";}
|
|
|
|
// 5. L99 Command Center (old format)
|
|
$l99old=@json_decode(@file_get_contents('/var/www/html/api/l99-results.json'),true);
|
|
if($l99old&&($l99old['total']??0)>0){$p=$l99old['pass']??0;$f=$l99old['fail']??0;
|
|
$suites['l99_command']=['pass'=>$p,'fail'=>$f,'total'=>$l99old['total']??0];
|
|
if($f>0)$issues[]="L99 Command: {$f} failures";}
|
|
|
|
// 6. Chat Monitor capabilities
|
|
$chatResults=[];$chatPass=0;$chatFail=0;
|
|
$caps=['Lean Six Sigma'=>'/api/weval-ia-fast.php?msg=lean+six+sigma&format=json',
|
|
'Qdrant'=>'/api/weval-ia-fast.php?msg=qdrant+status&format=json',
|
|
'SearXNG'=>'/api/weval-ia-fast.php?msg=searxng+test&format=json'];
|
|
foreach($caps as $name=>$path){
|
|
$ch=curl_init("https://weval-consulting.com$path");curl_setopt_array($ch,[CURLOPT_RETURNTRANSFER=>1,CURLOPT_TIMEOUT=>10]);
|
|
$r=curl_exec($ch);$code=curl_getinfo($ch,CURLINFO_HTTP_CODE);curl_close($ch);
|
|
$isJson=json_decode($r)!==null;$ok=$code==200&&$isJson;
|
|
if($ok)$chatPass++;else $chatFail++;
|
|
$chatResults[$name]=['ok'=>$ok,'code'=>$code,'json'=>$isJson];}
|
|
$suites['chat_monitor']=['pass'=>$chatPass,'fail'=>$chatFail,'total'=>$chatPass+$chatFail,'caps'=>$chatResults];
|
|
if($chatFail>0)$issues[]="Chat Monitor: {$chatFail} capabilities returning non-JSON";
|
|
|
|
// 7. Auth Agent status
|
|
$aa=@json_decode(@file_get_contents('/var/www/html/api/wevia-auth-status.json'),true);
|
|
if($aa){$suites['auth_agent']=['flow_ok'=>$aa['flow_ok']??0,'alerts'=>$aa['alerts_count']??0,'healthy'=>$aa['healthy']??false];
|
|
if(!($aa['healthy']??false))$issues[]="Auth Agent: unhealthy";}
|
|
|
|
// 8. Architecture score
|
|
$arch=@json_decode(@file_get_contents('/var/www/html/api/architecture-index.json'),true);
|
|
$score=$arch['recommendations']['score']??0;
|
|
$suites['architecture']=['score'=>$score];
|
|
if($score<90)$issues[]="Architecture score: {$score}/100";
|
|
|
|
// 9. CHATBOT POST HEALTH (detect "Service en maintenance" crash)
|
|
$ch=curl_init('https://127.0.0.1/api/weval-ia-fast.php');
|
|
curl_setopt_array($ch,[CURLOPT_POST=>1,CURLOPT_RETURNTRANSFER=>1,CURLOPT_TIMEOUT=>15,
|
|
CURLOPT_HTTPHEADER=>['Content-Type: application/json','Host: weval-consulting.com'],CURLOPT_SSL_VERIFYPEER=>false,CURLOPT_SSL_VERIFYHOST=>false,
|
|
CURLOPT_POSTFIELDS=>json_encode(['message'=>'test health check']),CURLOPT_SSL_VERIFYPEER=>false]);
|
|
$chatResp=curl_exec($ch);$chatCode=curl_getinfo($ch,CURLINFO_HTTP_CODE);curl_close($ch);
|
|
$chatData=json_decode($chatResp,true);
|
|
$chatOk=$chatCode==200&&!empty($chatData['response'])&&strpos($chatData['response'],'maintenance')===false;
|
|
$suites['chatbot_post']=['healthy'=>$chatOk,'provider'=>$chatData['provider']??'none','code'=>$chatCode];
|
|
if(!$chatOk){
|
|
$issues[]="Chatbot POST: returning maintenance/crash (provider cascade broken)";
|
|
// AUTO-FIX: check for duplicate function
|
|
$fast=@file_get_contents('/var/www/html/api/weval-ia-fast.php');
|
|
$wire=@file_get_contents('/var/www/weval/wevia-ia/cognitive-wire.php');
|
|
if($fast&&$wire&&substr_count($fast,'function wevia_mirofish_insights')>0&&substr_count($wire,'function wevia_mirofish_insights')>0){
|
|
// Duplicate detected — remove from fast.php
|
|
shell_exec("chattr -i /var/www/html/api/weval-ia-fast.php 2>/dev/null");
|
|
$lines=explode("
|
|
",$fast);$new=[];$skip=false;$depth=0;
|
|
foreach($lines as $L){
|
|
if(!$skip&&strpos($L,"function wevia_mirofish_insights")!==false&&strpos($L,"\$msg")!==false){
|
|
$skip=true;$depth=0;$new[]="// wevia_mirofish_insights: auto-fixed, using cognitive-wire.php";continue;}
|
|
if($skip){$depth+=substr_count($L,"{")-substr_count($L,"}");
|
|
if($depth<=0&&strpos($L,"}")!==false){$skip=false;continue;}continue;}
|
|
$new[]=$L;}
|
|
file_put_contents('/var/www/html/api/weval-ia-fast.php',implode("
|
|
",$new));
|
|
shell_exec("chattr +i /var/www/html/api/weval-ia-fast.php 2>/dev/null");
|
|
lg("[AUTO-FIX] Removed duplicate wevia_mirofish_insights from fast.php");
|
|
}
|
|
}
|
|
|
|
// 10. REGRESSION SCANNER STATUS
|
|
$reg=@json_decode(@file_get_contents('/var/www/html/api/wevia-regression-status.json'),true);
|
|
if($reg){$suites['regression_scan']=['ok'=>$reg['ok']??0,'total'=>$reg['total']??0,'issues'=>$reg['issues_count']??0,'regressions'=>$reg['regressions_count']??0];
|
|
if(($reg['regressions_count']??0)>0)$issues[]="Regression detected: {$reg['regressions_count']} pages changed status";}
|
|
|
|
// 10. L99 MISSION CONTROL (697 tests master)
|
|
$l99m = @json_decode(@file_get_contents('/var/www/html/api/l99-results.json'), true);
|
|
if ($l99m && !empty($l99m['tests'])) {
|
|
$mp = $mf = $mw = 0;
|
|
foreach ($l99m['tests'] as $t) {
|
|
$s = $t['status'] ?? '';
|
|
if (in_array($s, ['PASS','P','pass'])) $mp++;
|
|
elseif (in_array($s, ['FAIL','F','fail','ERROR'])) $mf++;
|
|
elseif (in_array($s, ['WARN','W','warn'])) $mw++;
|
|
}
|
|
$suites['l99_mission'] = ['pass'=>$mp, 'fail'=>$mf, 'warn'=>$mw, 'total'=>$mp+$mf+$mw];
|
|
$total_pass += $mp; $total_fail += $mf;
|
|
if ($mf > 0) {
|
|
$fail_names = [];
|
|
foreach ($l99m['tests'] as $t) {
|
|
if (in_array($t['status'] ?? '', ['FAIL','F','fail','ERROR'])) {
|
|
$fail_names[] = $t['name'] ?? $t['test'] ?? '?';
|
|
}
|
|
}
|
|
$issues[] = "L99 Mission: {$mf} failures (" . implode(', ', array_slice($fail_names, 0, 3)) . ")";
|
|
}
|
|
}
|
|
|
|
// GLOBAL
|
|
$global_rate=$total_pass+$total_fail>0?round($total_pass/($total_pass+$total_fail)*100,1):0;
|
|
$healthy=empty($issues)&&$global_rate>=95;
|
|
|
|
$status=['timestamp'=>date('Y-m-d H:i:s'),'healthy'=>$healthy,
|
|
'global_pass'=>$total_pass,'global_fail'=>$total_fail,'global_rate'=>$global_rate,
|
|
'suites'=>$suites,'issues'=>$issues,'issues_count'=>count($issues)];
|
|
file_put_contents($SF,json_encode($status,JSON_PRETTY_PRINT));
|
|
|
|
// EMAIL on issues
|
|
if(!empty($issues)){
|
|
$body="WEVIA Quality Agent - ".date('Y-m-d H:i')."
|
|
Global: {$total_pass}/".($total_pass+$total_fail)." ({$global_rate}%)
|
|
|
|
";
|
|
foreach($issues as $i)$body.="- $i
|
|
";
|
|
@mail('ymahboub@weval-consulting.com','[WEVIA QUALITY] '.count($issues).' issues',$body,"From: wevia@weval-consulting.com");}
|
|
|
|
lg("Quality: {$total_pass}/".($total_pass+$total_fail)." ({$global_rate}%) Issues:".count($issues));
|
|
echo "$ts Quality: {$total_pass}/".($total_pass+$total_fail)." ({$global_rate}%) Issues:".count($issues)."
|
|
";
|