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.
282 lines
15 KiB
PHP
282 lines
15 KiB
PHP
<?php
|
|
|
|
// Static contract for the revisioned administrator host public-pool boundary.
|
|
$root = dirname(__DIR__);
|
|
$routes = file_get_contents($root . '/config/routes_cloud.php');
|
|
$controller = file_get_contents(
|
|
$root . '/app/Controllers/CloudAdminHostNetworkController.php'
|
|
);
|
|
$service = file_get_contents(
|
|
$root . '/app/Services/Cloud/CloudAdminHostNetworkService.php'
|
|
);
|
|
$projectionService = file_get_contents(
|
|
$root . '/app/Services/Cloud/CloudAdminHostProjectionService.php'
|
|
);
|
|
$schedulingService = file_get_contents(
|
|
$root . '/app/Services/Cloud/CloudAdminHostSchedulingService.php'
|
|
);
|
|
$resourceService = file_get_contents(
|
|
$root . '/app/Services/Cloud/CloudAdminResourceService.php'
|
|
);
|
|
$capacityProjection = file_get_contents(
|
|
$root
|
|
. '/app/Services/Cloud/CloudAdminPublicNetworkCapacityProjection.php'
|
|
);
|
|
$usage = file_get_contents(
|
|
$root . '/app/Services/Cloud/CloudPanelUsageService.php'
|
|
);
|
|
$hostController = file_get_contents(
|
|
$root . '/app/Controllers/CloudAdminController.php'
|
|
);
|
|
$template = file_get_contents(
|
|
$root . '/resources/views/venix/admin/hosts/index.tpl'
|
|
);
|
|
$client = file_get_contents($root . '/public/cloud/admin-hosts.js');
|
|
$styles = file_get_contents($root . '/public/cloud/admin.css');
|
|
$assets = file_get_contents(
|
|
$root . '/resources/views/venix/layout_assets.tpl'
|
|
);
|
|
|
|
$assert = static function ($condition, string $message): void {
|
|
if (!$condition) {
|
|
throw new RuntimeException($message);
|
|
}
|
|
};
|
|
|
|
$assert(str_contains($routes,
|
|
"map(['GET', 'POST'], '/admin/hosts/{id:[0-9]+}/network-pools'")
|
|
&& str_contains($routes,
|
|
"'/admin/hosts/{id:[0-9]+}/network-pools/{pool_key:[0-9a-f]{32}}'")
|
|
&& str_contains($routes,
|
|
"'App\\Controllers\\CloudAdminHostNetworkController:update'")
|
|
&& !str_contains($routes,
|
|
"delete('/admin/hosts/{id:[0-9]+}/network-pools"),
|
|
'Host public pools require bounded GET/POST/PUT routes and no hard-delete route.');
|
|
|
|
$assert(str_contains($controller, 'CloudAccess::manage($actor);')
|
|
&& str_contains($controller, '$write = $method !== \'GET\';')
|
|
&& substr_count($controller, "'network_attachment_id'") === 2
|
|
&& substr_count($controller,
|
|
"'network_attachment_id', 'address_family', 'name', 'cidr'") === 2
|
|
&& substr_count($controller,
|
|
"'gateway', 'gateway_on_link', 'dns_servers', 'reserved_ips'") === 2
|
|
&& substr_count($controller,
|
|
"'allocation_start', 'allocation_end', 'max_allocations'") === 2
|
|
&& str_contains($controller,
|
|
"'state', 'request_key'")
|
|
&& str_contains($controller,
|
|
"'state', 'expected_revision'")
|
|
&& str_contains($controller,
|
|
"->withHeader('Cache-Control', 'private, no-store')"),
|
|
'Pool writes must be super-admin-only and use a strict request/response boundary.');
|
|
|
|
$assert(str_contains($service, 'private const MAX_POOLS = 32;')
|
|
&& str_contains($service,
|
|
"private const STATES = ['active', 'draining', 'disabled'];")
|
|
&& str_contains($service, "hash_hmac(\n 'sha256'")
|
|
&& str_contains($service, "CloudSecrets::key('public-pool-key')")
|
|
&& !str_contains($service, 'bin2hex(random_bytes(16))')
|
|
&& !str_contains($service, 'CloudAgentClient')
|
|
&& str_contains($service, 'CloudHostPoolMembershipService::lockedRows')
|
|
&& !str_contains($service, 'CloudHostPoolMembershipService::selected')
|
|
&& !str_contains($service, 'CloudHostPoolMembershipService::primary')
|
|
&& !str_contains($service, 'default_network')
|
|
&& !str_contains($service, 'CloudNetworkSelector::isValid')
|
|
&& !str_contains($service, 'new CloudHostNetworkAttachment')
|
|
&& str_contains($service, "'network_attachment_id' => \$attachmentId")
|
|
&& str_contains($service, 'CloudHostNetworkAttachment')
|
|
&& str_contains($service, 'CloudHostAgent')
|
|
&& str_contains($service,
|
|
"(string) \$attachment->verification_state !== 'verified'")
|
|
&& str_contains($service,
|
|
'(int) $attachment->verified_agent_revision')
|
|
&& str_contains($service,
|
|
'CloudAgentSettingsService::publicNetworkReady(')
|
|
&& str_contains($service, 'assertMembershipLine(')
|
|
&& str_contains($service, 'CloudPublicIpPool')
|
|
&& str_contains($service, 'desired_revision')
|
|
&& str_contains($service, 'observed_revision')
|
|
&& str_contains($service, 'sync_state')
|
|
&& !str_contains($service, 'refreshAttachmentAggregate')
|
|
&& !str_contains($service, '$attachment->save();'),
|
|
'Pools must bind verified attachments without rewriting attachment state.');
|
|
$assert(str_contains($capacityProjection,
|
|
'CloudAgentSettingsService::publicNetworkReady(')
|
|
&& str_contains($service,
|
|
'CloudAdminPublicNetworkCapacityProjection::forHosts(')
|
|
&& str_contains($projectionService,
|
|
'CloudAdminPublicNetworkCapacityProjection::forHosts(')
|
|
&& str_contains($schedulingService,
|
|
'CloudAdminPublicNetworkCapacityProjection::forHosts(')
|
|
&& str_contains($resourceService,
|
|
'CloudAdminPublicNetworkCapacityProjection::forHosts('),
|
|
'Every administrator readiness projection must require the tested public-network contract.');
|
|
|
|
$assert(str_contains($service,
|
|
"preg_match('/^[0-9a-f]{32}$/D', \$requestKey)")
|
|
&& str_contains($service, 'sameCreateRequest(')
|
|
&& str_contains($service,
|
|
'(int) $pool->network_attachment_id')
|
|
&& str_contains($service, "'replay' => true")
|
|
&& str_contains($service,
|
|
'存在尚未核对的地址池创建记录,请刷新后编辑该记录,不能继续创建新地址池')
|
|
&& str_contains($service, '$expectedRevision !== $revisionBase')
|
|
&& str_contains($service, '公网地址池版本已变化,请刷新后重试')
|
|
&& str_contains($service, '->transaction(function () use (')
|
|
&& str_contains($service, "\$pool->observed_revision = \$revision;")
|
|
&& str_contains($service, "\$pool->sync_state = 'applied';")
|
|
&& !str_contains($service, 'dispatch_attempts')
|
|
&& str_contains($service, 'materializeIpLedger')
|
|
&& str_contains($service, "(string) \$pool->sync_state === 'applied'"),
|
|
'Creates must be idempotent, updates CAS-fenced and local commits must atomically materialize the panel IP ledger.');
|
|
|
|
$assert(str_contains($service, 'assertNoOverlap(')
|
|
&& str_contains($service, 'assertNoGlobalOverlap(')
|
|
&& str_contains($service, 'catalogCount(')
|
|
&& str_contains($service, '一台宿主机最多配置 32 个公网地址池')
|
|
&& str_contains($service, 'OCCUPIED_IP_STATES')
|
|
&& str_contains($service, 'MAX_IPV6_ALLOCATIONS')
|
|
&& str_contains($service, "'address_family'")
|
|
&& str_contains($service, "'gateway_on_link'")
|
|
&& str_contains($service, "'allocation_start'")
|
|
&& str_contains($service, "'allocation_end'")
|
|
&& str_contains($service, "'max_allocations'")
|
|
&& str_contains($service, 'refreshSparseIpv6Ledger')
|
|
&& str_contains($service, "'dual_stack_ready'")
|
|
&& str_contains($service, "'available_count'")
|
|
&& str_contains($service,
|
|
'该地址池仍有实例或任务占用,只能修改名称、运行状态和未占用的保留 / 禁用 IP')
|
|
&& str_contains($service,
|
|
'已分配或任务占用的公网 IP 不能加入保留 / 禁用列表')
|
|
&& str_contains($service, '$occupiedAddressesByPool')
|
|
&& str_contains($service, 'occupiedUnsafeRuntimeChanged')
|
|
&& str_contains($service, '$originalAttachment')
|
|
&& str_contains($service, '$attachmentChanged')
|
|
&& str_contains($service, "'attachments' => \$attachments")
|
|
&& str_contains($service, "'attachment' => \$attachment")
|
|
&& str_contains($service, "'line' => \$attachment['line']")
|
|
&& !str_contains($service, '->delete()'),
|
|
'Pool limits, overlap checks, occupied runtime locks and soft lifecycle states are required.');
|
|
$catalogLockAt = strpos($service,
|
|
'CloudPublicIpPoolCatalogMutex::where(');
|
|
$hostLockAt = strpos($service,
|
|
"CloudHost::where('id', (int) \$host->id)");
|
|
$assert($catalogLockAt !== false && $hostLockAt !== false
|
|
&& $catalogLockAt < $hostLockAt
|
|
&& str_contains(substr($service, $catalogLockAt,
|
|
$hostLockAt - $catalogLockAt), '->lockForUpdate()'),
|
|
'Public-pool mutations must lock the global catalog before any host-scoped row.');
|
|
$assert(str_contains($service, 'materializeIpLedger(')
|
|
&& str_contains((string) $usage,
|
|
"CloudInstance::where('cloud_instances.host_id', \$hostId)")
|
|
&& str_contains((string) $usage, 'capacity_snapshots')
|
|
&& str_contains((string) $usage, "'unknown'")
|
|
&& str_contains((string) $usage, 'spec_json')
|
|
&& str_contains((string) $usage, 'managementAddressFromValue'),
|
|
'Panel instances must be counted from PHP metadata and block on unknown usage without host discovery.');
|
|
|
|
$assert(str_contains($service,
|
|
'PHP is the sole authority for public-pool configuration and IP allocation')
|
|
&& str_contains($service, "'applied'")
|
|
&& !str_contains($service, 'CloudAgentClient')
|
|
&& !str_contains($service, 'request('),
|
|
'PHP-owned pool writes must not depend on a second host-side pool catalog.');
|
|
|
|
foreach (['host-public-pool', 'host-gateway', 'host-dns', 'host-reserved',
|
|
'host-vm-prefix'] as $retiredId) {
|
|
$assert(!str_contains($template, 'id="' . $retiredId . '"'),
|
|
'The old single-pool host input remains in the main form: ' . $retiredId);
|
|
}
|
|
$assert(!str_contains($hostController, "'public_pool_cidr', 'public_gateway'")
|
|
&& !str_contains($client, 'function hostPublicNetworkPayload()')
|
|
&& str_contains($hostController, "'default_network'")
|
|
&& !str_contains($hostController, 'public_gateway'),
|
|
'The main host writer must not accept pool input or double-write the pool catalog.');
|
|
|
|
$assert(str_contains($template, 'id="host-network-pools-drawer"')
|
|
&& str_contains($template, 'data-admin-host-network-drawer')
|
|
&& str_contains($template, 'id="host-network-pool-new-attachment"')
|
|
&& str_contains($template, '选择后显示派生线路与 selector')
|
|
&& !str_contains($template, '使用宿主机当前默认网络')
|
|
&& str_contains($template,
|
|
'{if !$admin_can_manage|default:false}disabled{/if}')
|
|
&& str_contains($client, 'window.VenixDrawerMotion.openDrawerWithMotion')
|
|
&& str_contains($client, 'window.VenixDrawerMotion.closeDrawerWithMotion')
|
|
&& str_contains($client, "{ method: 'POST', body }")
|
|
&& str_contains($client, "{ method: 'PUT', body }")
|
|
&& str_contains($client, 'networkPoolEpoch')
|
|
&& str_contains($client,
|
|
'`/admin/maintenance-notices?scope_type=public_ip_pool&host_id=${encodeURIComponent(state.networkPoolHostId)}&pool_key=${encodeURIComponent(pool.pool_key)}`')
|
|
&& str_contains($client, 'networkPoolHostId')
|
|
&& str_contains($client, 'networkPoolContextCurrent(hostId, epoch)')
|
|
&& str_contains($client, 'globalThis.crypto?.getRandomValues')
|
|
&& str_contains($client, 'request_key: requestKey')
|
|
&& str_contains($client, 'expected_revision: expectedRevision')
|
|
&& str_contains($client,
|
|
'network_attachment_id: networkAttachmentId')
|
|
&& str_contains($client, 'address_family: family')
|
|
&& str_contains($client, 'gateway_on_link:')
|
|
&& str_contains($client, 'allocation_start:')
|
|
&& str_contains($client, 'max_allocations:')
|
|
&& str_contains($client, 'networkPoolAttachmentDetail(')
|
|
&& str_contains($client, 'const readyAttachments = networkPoolAttachments()')
|
|
&& str_contains($client,
|
|
'const payload = await api(`/api/v1/admin/hosts/${encodeURIComponent(hostId)}/network-pools`);')
|
|
&& str_contains($client, 'save.disabled = !canManage')
|
|
&& str_contains($client, 'for (const control of [attachment, family, cidr, gateway, gatewayOnLink, prefix, dns, allocationStart, allocationEnd, maxAllocations]) control.disabled = true;')
|
|
&& !str_contains($client, '[cidr, gateway, prefix, dns, reserved]')
|
|
&& str_contains($client, '已分配或任务占用的 IP 会被拒绝')
|
|
&& !file_exists($root . '/public/cloud/admin-host-network.css'),
|
|
'The responsive pool editor must lock network identity while allowing unoccupied disabled-IP edits.');
|
|
|
|
$assert(str_contains($template, '受控迁移占用地址')
|
|
&& str_contains($template, 'Public IPv4 / IPv6 Pools')
|
|
&& str_contains($template, 'id="host-network-pool-new-family"')
|
|
&& str_contains($template, 'id="host-network-pool-new-gateway-on-link"')
|
|
&& str_contains($template, 'id="host-network-pool-new-allocation-start"')
|
|
&& str_contains($template, 'id="host-network-pool-new-allocation-end"')
|
|
&& str_contains($template, 'id="host-network-pool-new-max-allocations"')
|
|
&& str_contains($client, 'function networkPoolReplacementPath(')
|
|
&& str_contains($client,
|
|
'/replacement-batches`')
|
|
&& str_contains($client,
|
|
'function renderNetworkPoolReplacementPanel(')
|
|
&& str_contains($client,
|
|
'receipt = await acceptedTask(networkPoolReplacementPath(')
|
|
&& str_contains($client,
|
|
'await loadNetworkPoolReplacement(hostId, pool, panel);')
|
|
&& !str_contains($client, 'receipt?.batch')
|
|
&& !str_contains($client, 'receipt?.batch_key')
|
|
&& str_contains($client, "response: 'task'")
|
|
&& str_contains($client, 'observeNetworkPoolReplacement(')
|
|
&& str_contains($client, 'expected_source_revision: sourceRevision')
|
|
&& str_contains($client, 'expected_target_revision: targetRevision')
|
|
&& str_contains($client, 'confirm_replacement: true')
|
|
&& str_contains($client, 'replacement_history_count')
|
|
&& str_contains($client, 'has_replacement_history')
|
|
&& str_contains($service, "'replacement_history_count'")
|
|
&& str_contains($service, "'has_replacement_history'")
|
|
&& str_contains($client, "'查看换池记录'")
|
|
&& str_contains($client, 'const running = Number(progress.running || 0)')
|
|
&& str_contains($client, '· 执行 ${running} ·')
|
|
&& str_contains($client,
|
|
'function networkPoolReplacementAttentionChildIds(')
|
|
&& str_contains($client, "`核对子任务 #\${jobId}`")
|
|
&& str_contains($client,
|
|
'`/admin/operations?q=${encodeURIComponent(jobId)}`')
|
|
&& str_contains($client, '按上方子任务编号逐项核对效果')
|
|
&& str_contains($client, '当前为只读管理权限')
|
|
&& str_contains($client,
|
|
'页面不会自动重试,也不会重新分配目标地址')
|
|
&& !str_contains($client, '重试换池')
|
|
&& str_contains((string) $styles, '.cloud-admin-pool-replacement')
|
|
&& str_contains((string) $styles,
|
|
'.cloud-admin-pool-replacement-facts'),
|
|
'The host pool drawer lost its strict-receipt controlled replacement UI or exposed unsafe replay.');
|
|
|
|
$assert(preg_match("/venix_asset_version value='([0-9]+)'/", $assets, $match) === 1
|
|
&& (int) $match[1] >= 2026110207,
|
|
'The shared browser asset version must cover the host pool drawer release.');
|
|
|
|
echo "Administrator host public-pool contracts passed.\n";
|