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.
89 lines
4.8 KiB
PHTML
89 lines
4.8 KiB
PHTML
|
2 months ago
|
<?php
|
||
|
|
|
||
|
|
$root = dirname(__DIR__);
|
||
|
|
$read = static function (string $path): string {
|
||
|
|
$source = file_get_contents($path);
|
||
|
|
if (!is_string($source)) {
|
||
|
|
throw new RuntimeException('Unable to read ' . $path);
|
||
|
|
}
|
||
|
|
return $source;
|
||
|
|
};
|
||
|
|
$assert = static function (bool $condition, string $message): void {
|
||
|
|
if (!$condition) {
|
||
|
|
throw new RuntimeException($message);
|
||
|
|
}
|
||
|
|
};
|
||
|
|
|
||
|
|
$routes = $read($root . '/config/routes.php');
|
||
|
|
$apiRoutes = $read($root . '/config/routes_cloud.php');
|
||
|
|
$middleware = $read($root . '/app/Middleware/CloudApi.php');
|
||
|
|
$pageController = $read($root . '/app/Controllers/Admin/CloudPageController.php');
|
||
|
|
$apiController = $read($root . '/app/Controllers/CloudAdminResourceController.php');
|
||
|
|
$service = $read($root . '/app/Services/Cloud/CloudAdminResourceService.php');
|
||
|
|
$feature = $read($root . '/app/Services/Cloud/CloudNetworkLineFeature.php');
|
||
|
|
$template = $read($root . '/resources/views/venix/admin/cloud/resources.tpl');
|
||
|
|
$header = $read($root . '/resources/views/venix/admin/static_header.tpl');
|
||
|
|
$script = $read($root . '/public/cloud/admin-resources.js');
|
||
|
|
$styles = $read($root . '/public/theme/venix/css/admin-home.css');
|
||
|
|
|
||
|
|
$assert(str_contains($routes, "'/resources', 'App\\Controllers\\Admin\\CloudPageController:resources'")
|
||
|
|
&& str_contains($pageController, 'CloudAdminResourceService::page(')
|
||
|
|
&& str_contains($pageController, "fetch('admin/cloud/resources.tpl')")
|
||
|
|
&& str_contains($pageController, 'JSON_HEX_TAG')
|
||
|
|
&& str_contains($pageController, "Cache-Control', 'private, no-store"),
|
||
|
|
'Resource scheduling must use a safe database-owned SSR first paint.');
|
||
|
|
|
||
|
|
foreach (['/admin/resources', '/admin/resources/settings', '/admin/regions',
|
||
|
|
'/admin/network-lines', '/admin/resource-pools', '/admin/resource-reservations'] as $path) {
|
||
|
|
$assert(str_contains($apiRoutes, "'" . $path), 'Missing resource API route: ' . $path);
|
||
|
|
}
|
||
|
|
$assert(!str_contains($apiRoutes, "delete('/admin/regions")
|
||
|
|
&& !str_contains($apiRoutes, "delete('/admin/network-lines")
|
||
|
|
&& !str_contains($apiRoutes, "delete('/admin/resource-pools"),
|
||
|
|
'Region, line and pool lifecycle must use statuses rather than hard deletion.');
|
||
|
|
|
||
|
|
$assert(str_contains($middleware, 'resource-reservations')
|
||
|
|
&& str_contains($apiController, 'CloudAccess::manage($actor)')
|
||
|
|
&& str_contains($apiController, "if (!($actor['is_admin'] ?? false))")
|
||
|
|
&& str_contains($apiController, "CloudInput::only($body, ['network_lines_enabled'])"),
|
||
|
|
'All administrators may read resources, while mutations require server-side superadmin authorization.');
|
||
|
|
|
||
|
|
$assert(str_contains($feature, "CONFIG_KEY = 'cloud_network_lines_enabled'")
|
||
|
|
&& str_contains($feature, 'return self::$cached = false')
|
||
|
|
&& str_contains($service, "private const POOL_STATUSES = ['active', 'draining', 'disabled']")
|
||
|
|
&& str_contains($service, "whereIn('state', ['held', 'committed', 'uncertain'])")
|
||
|
|
&& str_contains($service, 'active_default_line_count')
|
||
|
|
&& str_contains($service, 'CloudHostCapacityPolicy')
|
||
|
|
&& str_contains($service, 'CloudHostCapacitySnapshot')
|
||
|
|
&& !str_contains($service, 'CloudEngineClient'),
|
||
|
|
'Resource projections must be DB-only, reserve capacity explicitly and retain a disabled-by-default line feature.');
|
||
|
|
|
||
|
|
foreach (['资源总览', '地区', '线路', '资源池', '资源预留'] as $label) {
|
||
|
|
$assert(str_contains($template, '>' . $label . '<') || str_contains($template, '>' . $label . '</a>'),
|
||
|
|
'Resource page is missing a persistent tab: ' . $label);
|
||
|
|
}
|
||
|
|
$assert(str_contains($template, "{if $admin_can_manage|default:false}<button")
|
||
|
|
&& str_contains($template, 'data-resource-create="region"')
|
||
|
|
&& str_contains($template, 'data-resource-create="line"')
|
||
|
|
&& str_contains($template, 'data-resource-create="pool"')
|
||
|
|
&& str_contains($template, 'id="network-line-feature-form"')
|
||
|
|
&& str_contains($template, 'data-admin-instance-drawer')
|
||
|
|
&& str_contains($template, '/cloud/admin-resources.js?v={$venix_asset_version}')
|
||
|
|
&& str_contains($header, 'href="/admin/resources"'),
|
||
|
|
'Resource management controls, line switch, shared drawer and sidebar link are incomplete.');
|
||
|
|
|
||
|
|
$assert(str_contains($script, 'window.VenixDrawerMotion')
|
||
|
|
&& str_contains($script, "'X-CSRF-Token': window.ADMIN_CSRF_TOKEN")
|
||
|
|
&& str_contains($script, "method: id ? 'PATCH' : 'POST'")
|
||
|
|
&& str_contains($script, "method: 'PUT'")
|
||
|
|
&& !str_contains($script, 'is_super_admin')
|
||
|
|
&& !str_contains($script, 'data-can-manage'),
|
||
|
|
'Resource JavaScript must use shared motion and CSRF without duplicating authorization rules.');
|
||
|
|
|
||
|
|
$assert(str_contains($styles, '[data-admin-resources] .admin-resource-tabs')
|
||
|
|
&& str_contains($styles, '[data-admin-resource-drawer] .admin-resource-form-fields')
|
||
|
|
&& !is_file($root . '/public/cloud/admin-resources.css'),
|
||
|
|
'Resource UI must extend the shared Venix stylesheet without adding a parallel theme file.');
|
||
|
|
|
||
|
|
echo "Administrator resource scheduling contracts passed.\n";
|