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.
71 lines
3.8 KiB
PHP
71 lines
3.8 KiB
PHP
<?php
|
|
|
|
$root = dirname(__DIR__);
|
|
$read = static function (string $path) use ($root): string {
|
|
$contents = file_get_contents($root . '/' . $path);
|
|
if (!is_string($contents)) {
|
|
throw new RuntimeException('Unable to read ' . $path);
|
|
}
|
|
return $contents;
|
|
};
|
|
$assert = static function (bool $condition, string $message): void {
|
|
if (!$condition) {
|
|
throw new RuntimeException($message);
|
|
}
|
|
};
|
|
|
|
$service = $read('app/Services/Cloud/CloudAdminHostSchedulingService.php');
|
|
$controller = $read('app/Controllers/CloudAdminController.php');
|
|
$routes = $read('config/routes_cloud.php');
|
|
$middleware = $read('app/Middleware/CloudApi.php');
|
|
$template = $read('resources/views/venix/admin/hosts/index.tpl');
|
|
$script = $read('public/cloud/admin.js');
|
|
$assets = $read('resources/views/venix/layout_assets.tpl');
|
|
|
|
$assert(str_contains($routes, "'/admin/hosts/{id:[0-9]+}/scheduling'")
|
|
&& str_contains($routes, "'/admin/hosts/{id:[0-9]+}/capacity-sync'"),
|
|
'Host scheduling and capacity sync routes must be registered.');
|
|
$assert(str_contains($middleware, '(?:scheduling|capacity-sync)')
|
|
&& str_contains($controller, '$this->actor($request, $write)')
|
|
&& str_contains($controller, '$this->actor($request, true)'),
|
|
'Scheduling reads must allow administrators while writes stay super-admin only.');
|
|
$assert(str_contains($controller, "'resource_pool_id', 'scheduler_state'")
|
|
&& !str_contains(substr($controller,
|
|
strpos($controller, 'public function hostScheduling'),
|
|
strpos($controller, 'public function syncHostCapacity')
|
|
- strpos($controller, 'public function hostScheduling')), 'public_ip'),
|
|
'The scheduling allowlist must not accept manual public IP fields.');
|
|
|
|
$hostLock = strpos($service, "CloudHost::where('id', \$hostId)->lockForUpdate()");
|
|
$policyLock = strpos($service, "CloudHostCapacityPolicy::where('host_id', \$hostId)");
|
|
$assert($hostLock !== false && $policyLock !== false && $hostLock < $policyLock
|
|
&& str_contains($service, '->lockForUpdate()->first();'),
|
|
'Scheduling writes must lock host before capacity policy.');
|
|
$assert(str_contains($service, "\$schedulerState === 'active'")
|
|
&& str_contains($service, 'CloudNetworkLineFeature::enabled()')
|
|
&& str_contains($service, "(string) \$pool->status !== 'active'")
|
|
&& str_contains($service, "(string) \$region->status !== 'active'")
|
|
&& str_contains($service, '$safety >= $configured'),
|
|
'Active scheduling must validate the host, pool hierarchy and safety reserves.');
|
|
$assert(str_contains($service, 'CloudHostInventorySyncService())->syncOne($hostId)')
|
|
&& str_contains($service, '可以保存配置,但调度器会拒绝放置实例'),
|
|
'Manual sync and non-blocking health/staleness warnings must remain explicit.');
|
|
|
|
$assert(str_contains($template, 'data-admin-host-scheduling-drawer')
|
|
&& str_contains($template, 'id="host-capacity-sync"')
|
|
&& str_contains($template, '{if $admin_can_manage|default:false}')
|
|
&& str_contains($template, '公网 IP 仅由宿主机盘点维护'),
|
|
'The host drawer must expose server-rendered write controls without IP editing.');
|
|
$assert(str_contains($script, 'window.VenixDrawerMotion.openDrawerWithMotion')
|
|
&& str_contains($script, 'window.VenixDrawerMotion.closeDrawerWithMotion')
|
|
&& str_contains($script, '/capacity-sync')
|
|
&& str_contains($script, '/scheduling'),
|
|
'The host drawer must reuse shared motion and scheduling endpoints.');
|
|
$assert(preg_match("/venix_asset_version value='([0-9]+)'/", $assets, $match) === 1
|
|
&& (int) $match[1] >= 2026100308,
|
|
'Shared asset version must be bumped for admin.js changes.');
|
|
$assert(!file_exists($root . '/public/cloud/admin-host-scheduling.css'),
|
|
'Host scheduling must not introduce a standalone CSS file.');
|
|
|
|
echo "Administrator host scheduling contract checks passed.\n";
|