'mysql', 'db_host' => '127.0.0.1:9998', 'db_database' => 'business', 'db_username' => 'web', 'db_password' => '', 'db_charset' => 'utf8mb4', 'db_collation' => 'utf8mb4_unicode_ci', 'db_prefix' => '', 'log_db_host' => '127.0.0.2', 'log_db_port' => '3307', 'log_db_database' => 'metrics', 'log_db_user' => 'logger', 'log_db_password' => '', ]; $assert = static function ($condition, $message) { if (!$condition) throw new RuntimeException($message); }; $main = Config::getDbConfig(); $log = Config::getLogDbConfig(); $assert($main['host'] === '127.0.0.1' && $main['port'] === 9998, 'Legacy host:port must be parsed separately'); $assert($log['host'] === '127.0.0.2' && $log['port'] === 3307 && $log['database'] === 'metrics', 'Separate log database lost'); $System_Config['db_port'] = 3308; $assert(Config::getDbConfig()['port'] === 3308, 'Explicit port must take precedence'); $System_Config['db_host'] = '::1'; $assert(Config::getDbConfig()['host'] === '::1', 'IPv6 address must not be split as host:port'); unset($System_Config['db_port']); $System_Config['db_host'] = '[::1]:9998'; $assert(Config::getDbConfig()['host'] === '::1' && Config::getDbConfig()['port'] === 9998, 'Bracketed IPv6 host:port lost'); $System_Config['log_db_host'] = ''; $assert(Config::getLogDbConfig()['host'] === 'localhost', 'Empty log host must preserve its local default, not use the business host'); $System_Config['db_port'] = 0; try { Config::getDbConfig(); throw new RuntimeException('Invalid port accepted'); } catch (InvalidArgumentException $expected) { } $root = dirname(__DIR__); $assert(str_contains(file_get_contents($root . '/bootstrap.php'), "'/config/config.php'"), 'Canonical config.php missing'); $example = file_get_contents($root . '/config/.config.php.example'); $assert(str_contains($example, "['cloud_data_key_file']") && str_contains($example, "['cloud_update_helper_secret']") && str_contains($example, "['cloud_agent_gateway_secret']") && str_contains($example, "['cloud_agent_gateway_url']") && !str_contains($example, "['cloud_engine_"), 'PHP data-seal, update-helper or Agent-gateway configuration is missing.'); $extractPlaceholder = static function (string $key) use ($example): string { if (preg_match("/\\['" . preg_quote($key, '/') . "'\\]\\s*=\\s*'([^']*)'/", $example, $match) !== 1) { throw new RuntimeException('Missing configuration placeholder: ' . $key); } return $match[1]; }; $assert(strlen($extractPlaceholder('cloud_update_helper_secret')) < 32 && strlen($extractPlaceholder('cloud_agent_gateway_secret')) < 32, 'Public example secrets must fail the runtime minimum-length validation.'); $agentExample = json_decode(file_get_contents(dirname($root) . '/deploy/virt-cloud-agent.json.example'), true, 32, JSON_THROW_ON_ERROR); $assert(is_string($agentExample['agent_secret'] ?? null) && strlen($agentExample['agent_secret']) < 32, 'Public Agent example secret must fail the runtime minimum-length validation.'); $assert(str_contains(file_get_contents($root . '/config/routes.php'), "'/config/routes_cloud.php'"), 'Cloud API routes not registered'); echo "Virtualization configuration and separate log database contracts passed.\n";