true, CURLOPT_POST => true, CURLOPT_HTTPHEADER => ['Content-Type: application/json'], CURLOPT_POSTFIELDS => json_encode(['message' => '2+2', 'provider' => $provider, 'session_id' => 'test_' . time()]), CURLOPT_TIMEOUT => 30 ]); $response = curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); $duration = round((microtime(true) - $start) * 1000); $data = json_decode($response, true); $success = $httpCode == 200 && isset($data['response']) && !empty($data['response']); if ($success) $passedTests++; $results['providers'][$provider] = [ 'success' => $success, 'duration' => $duration, 'http_code' => $httpCode, 'has_response' => isset($data['response']) ]; } // 2. Test Status API $totalTests++; $ch = curl_init('http://localhost:5821/hamid-status.php'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_TIMEOUT, 10); $response = curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); $data = json_decode($response, true); $success = $httpCode == 200 && isset($data['providers']) && isset($data['best_available']); if ($success) $passedTests++; $results['status_api'] = [ 'success' => $success, 'http_code' => $httpCode, 'providers_count' => isset($data['providers']) ? count($data['providers']) : 0, 'best_available' => $data['best_available'] ?? 'N/A', 'ready_count' => isset($data['providers']) ? count(array_filter($data['providers'], fn($p) => $p['status'] === 'ready')) : 0 ]; // 3. Test PHP Syntax $phpFiles = [ 'hamid-api.php', 'hamid-fullscreen.php', 'hamid-cli.php', 'hamid-ssh.php', 'hamid-widget.php', 'hamid-status.php', 'hamid-index.php', 'hamid-failover-monitor.php', 'hamid-providers-config.php', 'hamid-providers.php' ]; foreach ($phpFiles as $file) { $totalTests++; $path = "/opt/wevads/public/$file"; if (file_exists($path)) { $output = shell_exec("php -l $path 2>&1"); $success = strpos($output, 'No syntax errors') !== false; } else { $success = false; $output = 'File not found'; } if ($success) $passedTests++; $results['php_syntax'][$file] = [ 'success' => $success, 'exists' => file_exists($path) ]; } // 4. Test HTTP Access $pages = [ 'hamid-index.php', 'hamid-fullscreen.php', 'hamid-cli.php', 'hamid-ssh.php', 'hamid-widget.php', 'hamid-failover-monitor.php', 'hamid-status.php', 'hamid-providers.php', 'hamid-code/' ]; foreach ($pages as $page) { $totalTests++; $ch = curl_init("http://localhost:5821/$page"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_TIMEOUT, 10); curl_setopt($ch, CURLOPT_NOBODY, false); curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); $success = $httpCode == 200; if ($success) $passedTests++; $results['http_access'][$page] = [ 'success' => $success, 'http_code' => $httpCode ]; } // 5. Test Failover Health $totalTests++; $ch = curl_init('http://localhost:5821/hamid-failover-monitor.php?api=health_check'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_TIMEOUT, 10); $response = curl_exec($ch); curl_close($ch); $data = json_decode($response, true); $success = isset($data['healthy']); if ($success) $passedTests++; $results['failover_health'] = [ 'success' => $success, 'healthy' => $data['healthy'] ?? false, 'ready_count' => $data['ready_count'] ?? 0, 'down_count' => $data['down_count'] ?? 0 ]; // 6. Test CLI Python $totalTests++; $output = shell_exec('python3 -m py_compile /usr/local/bin/hamid 2>&1'); $success = empty($output) || strpos($output, 'Error') === false; if ($success) $passedTests++; $results['cli_python'] = [ 'success' => $success, 'has_cloudflare' => strpos(file_get_contents('/usr/local/bin/hamid'), 'cloudflare') !== false, 'has_sambanova' => strpos(file_get_contents('/usr/local/bin/hamid'), 'sambanova') !== false ]; // 7. Test Config centralisée $totalTests++; try { require_once '/opt/wevads/public/hamid-providers-config.php'; global $WEVAL_MIND_PROVIDERS, $WEVAL_MIND_ROTATION_ORDER; $success = isset($WEVAL_MIND_PROVIDERS) && count($WEVAL_MIND_PROVIDERS) > 20; $cfPriority = $WEVAL_MIND_PROVIDERS['cloudflare']['priority'] ?? 'N/A'; $rotationCount = count($WEVAL_MIND_ROTATION_ORDER ?? []); } catch (Exception $e) { $success = false; $cfPriority = 'ERROR'; $rotationCount = 0; } if ($success) $passedTests++; $results['config'] = [ 'success' => $success, 'providers_count' => isset($WEVAL_MIND_PROVIDERS) ? count($WEVAL_MIND_PROVIDERS) : 0, 'cloudflare_priority' => $cfPriority, 'rotation_count' => $rotationCount ]; // 8. Test Database $totalTests++; try { $pdo = new PDO("pgsql:host=localhost;dbname=adx_system", "admin", "admin123"); $stmt = $pdo->query("SELECT COUNT(*) FROM admin.hamid_config"); $configCount = $stmt->fetchColumn(); $success = $configCount > 0; } catch (Exception $e) { $success = false; $configCount = 0; } if ($success) $passedTests++; $results['database'] = [ 'success' => $success, 'config_count' => $configCount ]; // Summary $results['summary'] = [ 'total_tests' => $totalTests, 'passed' => $passedTests, 'failed' => $totalTests - $passedTests, 'success_rate' => round(($passedTests / $totalTests) * 100, 1), 'timestamp' => date('Y-m-d H:i:s') ]; echo json_encode($results, JSON_PRETTY_PRINT);