|
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
// Static host-location contract: no application boot, database or engine 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');
|
|
|
|
|
|
|
|
|
|
|
|
$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,
|
|
|
|
|
|
"ALTER TABLE cloud_hosts ADD COLUMN IF NOT EXISTS\n country_code CHAR(2) NOT NULL DEFAULT '' AFTER region"),
|
|
|
|
|
|
'Fresh and upgraded cloud_hosts schemas must contain the structured country code.');
|
|
|
|
|
|
$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,
|
|
|
|
|
|
"unset(\$body['name'], \$body['enabled'], \$body['country_code']);")
|
|
|
|
|
|
&& str_contains($controller, '$host->country_code = $countryCode;'),
|
|
|
|
|
|
'Host writes must validate and persist country_code without forwarding it to the engine.');
|
|
|
|
|
|
$unsetAt = strpos($controller,
|
|
|
|
|
|
"unset(\$body['name'], \$body['enabled'], \$body['country_code']);");
|
|
|
|
|
|
$enginePutAt = strpos($controller, "'PUT', 'host', \$actor, \$body");
|
|
|
|
|
|
$assert($unsetAt !== false && $enginePutAt !== false && $unsetAt < $enginePutAt,
|
|
|
|
|
|
'country_code must be removed before the strict engine HostBody receives the request.');
|
|
|
|
|
|
$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 engine 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.');
|
|
|
|
|
|
$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($controller,
|
|
|
|
|
|
"\$engineHost['public_pool_cidr'] ?? ''")
|
|
|
|
|
|
&& str_contains($controller,
|
|
|
|
|
|
"\$engineHost['public_dns_servers'] ?? null"),
|
|
|
|
|
|
'Public pools must use the dedicated drawer while host edits preserve legacy engine fields server-side.');
|
|
|
|
|
|
$newHostAt = strpos($controller, '$host = isset($args[\'id\'])');
|
|
|
|
|
|
$privateKeyCheckAt = strpos(
|
|
|
|
|
|
$controller, 'if (!$host->exists && !$hasPrivateKey)', $newHostAt
|
|
|
|
|
|
);
|
|
|
|
|
|
$newHostSaveAt = strpos($controller, '$host->save();', $newHostAt);
|
|
|
|
|
|
$assert(str_contains($template, 'id="host-private-key-help"')
|
|
|
|
|
|
&& str_contains($client, 'state.hostConfigured = h.configured === true;')
|
|
|
|
|
|
&& str_contains($client, 'if (!state.hostConfigured && !privateKey)')
|
|
|
|
|
|
&& str_contains($client, '该宿主机尚未完成引擎配置,请重新粘贴现有 SSH 私钥')
|
|
|
|
|
|
&& str_contains($controller, "(\$engineHost['configured'] ?? false) !== true")
|
|
|
|
|
|
&& str_contains($controller, "new CloudError('首次添加宿主机必须提供现有 SSH 私钥', 422)")
|
|
|
|
|
|
&& str_contains($controller, "new CloudError('该宿主机尚未完成引擎配置,请重新粘贴现有 SSH 私钥', 422)")
|
|
|
|
|
|
&& $privateKeyCheckAt !== false && $newHostSaveAt !== false
|
|
|
|
|
|
&& $privateKeyCheckAt < $newHostSaveAt && $privateKeyCheckAt < $enginePutAt,
|
|
|
|
|
|
'Only an engine-configured host may retain its saved private key without resubmitting it.');
|
|
|
|
|
|
|
|
|
|
|
|
echo "Structured cloud host country and region contracts passed.\n";
|