|
|
<?php
|
|
|
|
|
|
// Static host-location contract: no application boot, database or Agent connection.
|
|
|
$root = dirname(__DIR__);
|
|
|
$schema = file_get_contents($root . '/sql/cloud.sql');
|
|
|
$controller = file_get_contents($root . '/app/Controllers/CloudAdminController.php');
|
|
|
$pageController = file_get_contents($root . '/app/Controllers/Admin/CloudPageController.php');
|
|
|
$legacyPageController = file_get_contents($root . '/app/Controllers/Admin/HostController.php');
|
|
|
$catalog = file_get_contents($root . '/app/Services/Cloud/CloudCountryCatalog.php');
|
|
|
$template = file_get_contents($root . '/resources/views/venix/admin/hosts/index.tpl');
|
|
|
$client = file_get_contents($root . '/public/cloud/admin.js');
|
|
|
$hostWriteStart = strpos($controller, 'public function hosts(');
|
|
|
$hostWriteEnd = strpos($controller, 'public function hostScheduling(', $hostWriteStart);
|
|
|
$hostWrite = $hostWriteStart === false || $hostWriteEnd === false ? ''
|
|
|
: substr($controller, $hostWriteStart, $hostWriteEnd - $hostWriteStart);
|
|
|
|
|
|
$assert = static function ($condition, string $message): void {
|
|
|
if (!$condition) {
|
|
|
throw new RuntimeException($message);
|
|
|
}
|
|
|
};
|
|
|
|
|
|
$assert(str_contains($schema, "country_code CHAR(2) NOT NULL DEFAULT ''")
|
|
|
&& str_contains($schema,
|
|
|
"default_network VARCHAR(128) NOT NULL DEFAULT 'public'")
|
|
|
&& !preg_match('/\b(?:ALTER|DROP)\s+TABLE\b/i', $schema),
|
|
|
'Fresh cloud_hosts schema must contain structured location and the public selector default without upgrade DDL.');
|
|
|
$assert(str_contains($controller, "'region', 'country_code'")
|
|
|
&& str_contains($controller,
|
|
|
"CloudCountryCatalog::normalize(\$body['country_code'] ?? null)")
|
|
|
&& !str_contains($controller, 'HOST_COUNTRY_CODES')
|
|
|
&& str_contains($controller, '$host->country_code = $countryCode;')
|
|
|
&& $hostWrite !== ''
|
|
|
&& str_contains($hostWrite,
|
|
|
'CloudAgentSettingsService::invalidateForNetworkSelectorChange(')
|
|
|
&& !str_contains($hostWrite, '->request('),
|
|
|
'Host writes must persist country_code and invalidate stale selector readiness without contacting the Agent.');
|
|
|
$assert(str_contains($catalog, "'CN' => ['name' => '中国'")
|
|
|
&& str_contains($catalog, "'HK' => ['name' => '中国香港'")
|
|
|
&& str_contains($catalog, "'JP' => ['name' => '日本'")
|
|
|
&& str_contains($catalog, "'US' => ['name' => '美国'")
|
|
|
&& str_contains($catalog, "'SG' => ['name' => '新加坡'")
|
|
|
&& str_contains($catalog, '$code = strtoupper(trim($value));')
|
|
|
&& !str_contains($catalog, 'safeText'),
|
|
|
'The shared country catalog must normalize complete values without truncation.');
|
|
|
$assert(str_contains($pageController,
|
|
|
"assign('cloud_country_options', CloudCountryCatalog::options())")
|
|
|
&& str_contains($legacyPageController,
|
|
|
"assign('cloud_country_options', CloudCountryCatalog::options())")
|
|
|
&& str_contains($template, '{foreach $cloud_country_options as $country}')
|
|
|
&& str_contains($template, '{$country.name|escape}')
|
|
|
&& str_contains($template, '({$country.code|escape})'),
|
|
|
'Host country selector must render the shared readable country catalog.');
|
|
|
$assert(str_contains($template, 'id="host-country-code"')
|
|
|
&& preg_match('/id="host-region"[^>]*required[^>]*maxlength="64"/', $template) === 1
|
|
|
&& str_contains($controller, '具体地区需为 1 至 64 字符'),
|
|
|
'Host editor must require a country and an exact region within the panel limit.');
|
|
|
$assert(str_contains($client, "'host-country-code': h.country_code || ''")
|
|
|
&& str_contains($client,
|
|
|
"country_code: byId('host-country-code').value"),
|
|
|
'Host editor must round-trip country_code through the admin API.');
|
|
|
$assert(str_contains($controller,
|
|
|
"preg_match('/^[A-Za-z0-9][A-Za-z0-9_.-]{0,63}$/D', \$network)")
|
|
|
&& str_contains($controller, 'Agent network_selectors')
|
|
|
&& str_contains($client, "'host-network': h.default_network || 'public'")
|
|
|
&& str_contains($template, 'value="public"')
|
|
|
&& str_contains($template, 'Agent 网络选择器 key')
|
|
|
&& str_contains($template, '不能填写 <code>bridge:br0</code>'),
|
|
|
'Host network input must use the stable public Agent selector instead of a raw bridge name.');
|
|
|
$legacyPublicInputs = [
|
|
|
'host-public-pool', 'host-gateway', 'host-dns', 'host-reserved',
|
|
|
'host-vm-prefix',
|
|
|
];
|
|
|
foreach ($legacyPublicInputs as $inputId) {
|
|
|
$assert(!str_contains($template, 'id="' . $inputId . '"'),
|
|
|
'The main host form still exposes the retired single-pool input: '
|
|
|
. $inputId);
|
|
|
}
|
|
|
$assert(!str_contains($client, 'function hostPublicNetworkPayload()')
|
|
|
&& !str_contains($controller, 'normalizeHostPublicNetwork')
|
|
|
&& str_contains($template, 'id="host-network-pools-drawer"')
|
|
|
&& !str_contains($hostWrite, 'public_pool_cidr')
|
|
|
&& !str_contains($hostWrite, 'public_dns_servers'),
|
|
|
'Public pools must use the dedicated panel-owned drawer, separate from host metadata writes.');
|
|
|
$assert(str_contains($template, 'href="/admin/agents"')
|
|
|
&& str_contains($template, '配置宿主机 Agent API')
|
|
|
&& !str_contains($template, 'host-private-key')
|
|
|
&& !str_contains($client, 'private_key')
|
|
|
&& !str_contains($controller, 'engineHost')
|
|
|
&& str_contains($client,
|
|
|
"const body = { name: byId('host-name').value.trim(), enabled: byId('host-enabled').checked, country_code: byId('host-country-code').value, region: byId('host-region').value.trim(), default_network: byId('host-network').value.trim() }"),
|
|
|
'Host metadata must not retain old SSH/engine credentials; Agent API settings are managed on their dedicated page.');
|
|
|
|
|
|
echo "Structured cloud host country and region contracts passed.\n";
|