You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
virt/web/tests/PrunedProjectContractTest.php

53 lines
4.0 KiB
PHP

<?php
// Source contracts, without application boot or a database connection.
$root = dirname(__DIR__);
$assert = static function ($condition, $message) {
if (!$condition) {
throw new RuntimeException($message);
}
};
$routes = file_get_contents($root . '/config/routes.php');
$assert(!str_contains($routes, "get('/node'") && !str_contains($routes, 'NodeController:'), 'Old user/admin node routes remain');
$assert(str_contains($routes, "get('/hosts', 'App\\Controllers\\Admin\\CloudPageController:hosts')"), 'Admin host page missing');
foreach (['/community', '/paid-registration', '/trafficlog', '/tcplog', '/tcpmonitor', '/redis-online', '/inactive-', '/abnormal-users', '/apple-', '/detect', '/edge-config', '/node-access-api', '/sublink', '/sub_server', '/checkin', '/cleanup', '/doc'] as $retired) {
$assert(!str_contains($routes, "'" . $retired), 'Retired route remains: ' . $retired);
}
$assert(!is_dir($root . '/resources/views/material') && !is_dir($root . '/resources/views/codex'), 'Retired templates remain');
$assert(is_file($root . '/resources/views/venix/admin/hosts/index.tpl'), 'Host administration template missing');
$config = file_get_contents($root . '/config/.config.php.example');
foreach (['user_try', 'reg_method', 'user_class_default', 'enable_class_expire_reset', 'auto_clean_', 'auto_backup_webroot', 'mu_suffix', 'mu_regex', 'checkinMin', 'enable_documents', 'subUrl', 'tgUrl', 'chatgpt_api'] as $key) {
$assert(!str_contains($config, $key), 'Retired configuration remains: ' . $key);
}
foreach (['db_password', 'smtp_passsword', 'super_admin', 'auto_backup_passwd', 'enable_login_bind_ip', 'notify_limit_mode'] as $key) {
$assert(str_contains($config, "['" . $key . "']"), 'Preserved configuration missing: ' . $key);
}
$shop = file_get_contents($root . '/app/Controllers/UserController.php');
$assert(str_contains($shop, "withJson(['ret' => 0") || str_contains($shop, "'ret' => 0"), 'Shop error contract missing');
$assert(str_contains($shop, '409'), 'Not-yet-integrated purchase must reject without charging');
$assert(str_contains($routes, '/password/reset') === false && str_contains($routes, "group('/password'"), 'Password recovery routes missing');
$schema = file_get_contents($root . '/sql/ss.sql');
preg_match('/CREATE TABLE `user` \(([\s\S]+?)\) ENGINE/', $schema, $userTable);
$assert(isset($userTable[1]), 'Clean account table missing');
foreach (['class', 'class_expire', 'expire_in', 'transfer_enable', 'passwd', 'method', 'obfs', 'port', 'protocol', 'node_group'] as $column) {
$assert(!str_contains($userTable[1], '`' . $column . '`'), 'Retired account column remains: ' . $column);
}
$logSchema = file_get_contents($root . '/sql/user_log.sql');
preg_match_all('/CREATE\s+TABLE\s+`([^`]+)`/i', $logSchema, $logTableMatches);
$logTables = $logTableMatches[1];
sort($logTables);
$assert($logTables === ['setting', 'site_security_events', 'site_visit_daily_stats', 'site_visit_events', 'user_email_log'], 'Retained log table set changed');
foreach (['access_log', 'dns_rule', 'node_access_api_log', 'node_network_issues', 'node_network_samples', 'node_network_status', 'online_user', 'ss_node_backend', 'ss_node_info', 'ss_node_online_log', 'user_apple_copy_log', 'user_subscribe_log', 'user_tcp_daily_stats', 'user_tcp_log', 'user_traffic_daily_stats', 'user_traffic_log'] as $table) {
$assert(!str_contains($logSchema, '`' . $table . '`'), 'Retired log table is still referenced: ' . $table);
}
preg_match_all('/ALTER\s+TABLE\s+`([^`]+)`/i', $logSchema, $logAlterMatches);
foreach ($logAlterMatches[1] as $table) {
$assert(in_array($table, $logTables, true), 'Log schema alters an undefined table: ' . $table);
}
preg_match_all('/CREATE\s+TRIGGER\s+`[^`]+`\s+(?:BEFORE|AFTER)\s+(?:INSERT|UPDATE|DELETE)\s+ON\s+`([^`]+)`/i', $logSchema, $logTriggerMatches);
foreach ($logTriggerMatches[1] as $table) {
$assert(in_array($table, $logTables, true), 'Log schema trigger targets an undefined table: ' . $table);
}
echo "Pruned project routes/configuration/schema contracts passed.\n";