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.
92 lines
4.8 KiB
PHP
92 lines
4.8 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::publishAndReserveImport(')
|
|
&& str_contains($catalog,
|
|
'CloudTemplateArtifactManager::publishReserved($template, $file)')
|
|
&& str_contains($catalog,
|
|
'CloudTemplateArtifactManager::downloadSource($template)')
|
|
&& str_contains($catalog, 'CloudAgentSettingsService::enabledHostIds()')
|
|
&& str_contains($catalog, 'CloudJobService::reserveAggregate(')
|
|
&& str_contains($catalog, 'CloudJobService::reserveAgentMutation(')
|
|
&& str_contains($catalog, "'template_import_replica', 'POST'")
|
|
&& str_contains($catalog,
|
|
"'source_size_bytes' =>\n (int) \$source['source_size_bytes']")
|
|
&& str_contains($catalog, "'template_delete_replica', 'DELETE'")
|
|
&& str_contains($catalog, 'CloudJobService::acknowledgement($parent)')
|
|
&& str_contains($catalog, 'public static function finishJobLocked(')
|
|
&& str_contains($catalog, 'public static function expireAggregateLocked(')
|
|
&& str_contains($catalog, 'CloudJobService::completeAggregateLocked(')
|
|
&& str_contains($catalog, 'CloudAgentCatalogDeletion::confirms(')
|
|
&& str_contains($catalog, 'Agent 云镜像删除回执缺少清理证据')
|
|
&& !str_contains($catalog, 'CloudAgentClient')
|
|
&& !str_contains($catalog, '->request(')
|
|
&& str_contains($catalog,
|
|
"throw new CloudError('没有已启用且已配置 Agent 的宿主机', 409)")
|
|
&& str_contains($catalog,
|
|
"throw new CloudError('本地云镜像校验结果无效', 503)")
|
|
&& str_contains($catalog,
|
|
"throw new CloudError('云镜像主副本状态不允许开始分发', 409)")
|
|
&& 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, "'/tasks/{id:[0-9]+}'")
|
|
&& 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 cloud_templates')
|
|
&& str_contains($schema, 'generation_token CHAR(32)')
|
|
&& str_contains($schema, 'catalog_key VARCHAR(80)')
|
|
&& str_contains($schema, 'version_label VARCHAR(64)')
|
|
&& str_contains($schema, 'CREATE TABLE cloud_template_artifacts')
|
|
&& str_contains($schema, 'sealed_storage_runtime LONGTEXT NOT NULL')
|
|
&& 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 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";
|