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.
84 lines
4.2 KiB
PHP
84 lines
4.2 KiB
PHP
<?php
|
|
|
|
$root = dirname(__DIR__);
|
|
$assert = static function ($condition, string $message): void {
|
|
if (!$condition) {
|
|
throw new RuntimeException($message);
|
|
}
|
|
};
|
|
|
|
$controller = file_get_contents(
|
|
$root . '/app/Controllers/CloudAdminController.php'
|
|
);
|
|
$catalog = file_get_contents(
|
|
$root . '/app/Services/Cloud/CloudTemplateCatalogService.php'
|
|
);
|
|
$routes = file_get_contents($root . '/config/routes_cloud.php');
|
|
$schema = file_get_contents($root . '/sql/cloud.sql');
|
|
$uploadStart = strpos($controller, 'public function cloudTemplateUpload(');
|
|
$uploadEnd = $uploadStart === false ? false
|
|
: strpos($controller, 'private static function catalogName(', $uploadStart);
|
|
$upload = $uploadStart === false || $uploadEnd === false ? ''
|
|
: substr($controller, $uploadStart, $uploadEnd - $uploadStart);
|
|
|
|
$assert(is_string($catalog)
|
|
&& str_contains($catalog, 'final class CloudTemplateCatalogService')
|
|
&& str_contains($catalog, 'CloudInput::only($input, [')
|
|
&& str_contains($catalog,
|
|
"self::newImport(\$name, \$family, \$version, 'remote'")
|
|
&& str_contains($catalog,
|
|
"self::newImport(\$name, \$family, \$version, 'upload'")
|
|
&& str_contains($catalog, 'CloudAgentSettingsService::enabledHostIds()')
|
|
&& str_contains($catalog, 'public static function deleteJob(')
|
|
&& str_contains($catalog, "->where('state', 'delete_dispatch')")
|
|
&& str_contains($catalog, "'state' => 'delete_sending'")
|
|
&& str_contains($catalog, "->where('state', 'delete_sending')")
|
|
&& str_contains($catalog, "'error_code' => 'delete_dispatch_unconfirmed'")
|
|
&& str_contains($catalog, "->where('state', 'delete_running')")
|
|
&& str_contains($catalog, 'CloudAgentCatalogDeletion::confirms(')
|
|
&& str_contains($catalog, "'delete_evidence_missing'")
|
|
&& str_contains($catalog,
|
|
"'status_url' => '/api/v1/admin/cloud-templates/delete-jobs/'")
|
|
&& str_contains($catalog,
|
|
"throw new CloudError('没有已启用且已配置 Agent 的宿主机', 409)")
|
|
&& str_contains($catalog,
|
|
"throw new CloudError('本地云镜像校验结果无效', 503)")
|
|
&& str_contains($catalog,
|
|
"throw new CloudError('云镜像导入源快照无效', 503)")
|
|
&& str_contains($catalog, "'agent_result_mismatch'")
|
|
&& str_contains($catalog, "throw new CloudError('云镜像模板不存在', 404)")
|
|
&& str_contains($catalog, "throw new CloudError('云镜像版本已变化,请刷新后重试', 409)"),
|
|
'PHP-owned template catalog lost strict validation or stable errors.');
|
|
|
|
$assert(is_string($controller)
|
|
&& str_contains($controller, 'CloudTemplateCatalogService::adminCatalog()')
|
|
&& str_contains($controller, 'CloudTemplateCatalogService::importRemote(')
|
|
&& str_contains($controller, 'CloudTemplateCatalogService::rename(')
|
|
&& str_contains($controller, 'CloudTemplateCatalogService::delete(')
|
|
&& $upload !== ''
|
|
&& str_contains($upload, 'CloudTemplateCatalogService::')
|
|
&& !str_contains($upload, ', 501')
|
|
&& !str_contains($upload, '尚未实现云镜像二进制上传'),
|
|
'Template remote import and QCOW2 upload must execute the PHP catalog/Agent workflow.');
|
|
|
|
$assert(is_string($routes)
|
|
&& str_contains($routes, "['cloud' => 'cloud-templates'")
|
|
&& str_contains($routes, "'/admin/' . \$name")
|
|
&& str_contains($routes, "['PATCH', 'DELETE']")
|
|
&& str_contains($routes, "'/delete-jobs/{id}'")
|
|
&& str_contains($routes, "'/admin/cloud-templates/import'")
|
|
&& str_contains($routes, "'/admin/cloud-templates/{id}/startup-script'")
|
|
&& str_contains($routes, "'/admin/cloud-templates/upload'"),
|
|
'Administrator template catalog routes are incomplete.');
|
|
$assert(is_string($schema)
|
|
&& str_contains($schema, 'CREATE TABLE IF NOT EXISTS cloud_templates')
|
|
&& str_contains($schema, 'generation_token CHAR(32)')
|
|
&& str_contains($schema, 'sealed_source_url LONGTEXT NOT NULL')
|
|
&& !preg_match('/\bsource_url\s+(?:TEXT|LONGTEXT)/', $schema)
|
|
&& str_contains($schema, 'startup_script MEDIUMTEXT NOT NULL')
|
|
&& !preg_match('/CREATE TABLE IF NOT EXISTS cloud_template_(?:retirements|catalog_locks)/',
|
|
$schema),
|
|
'Fresh template schema retained retired coordination tables or lost CAS fields.');
|
|
|
|
echo "Cloud template clean-break catalog and Agent error contract passed.\n";
|