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.
virt/web/tests/CloudTemplateErrorContractT...

117 lines
5.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'
);
$remoteAcquisition = file_get_contents(
$root . '/app/Services/Cloud/CloudTemplateRemoteAcquisition.php'
);
$publication = file_get_contents(
$root . '/app/Services/Cloud/CloudTemplateImportPublication.php'
);
$deletion = file_get_contents(
$root . '/app/Services/Cloud/CloudTemplateDeletionService.php'
);
$artifactManager = file_get_contents(
$root . '/app/Services/Cloud/CloudTemplateArtifactManager.php'
);
$routes = file_get_contents($root . '/config/routes_cloud.php');
$schema = file_get_contents($root . '/sql/cloud.sql');
$assert(is_string($catalog)
&& str_contains($catalog, 'final class CloudTemplateCatalogService')
&& 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(')
&& is_string($deletion)
&& str_contains($deletion, 'CloudAgentCatalogDeletion::confirms(')
&& str_contains($deletion, 'Agent 云镜像删除回执缺少清理证据')
&& str_contains($deletion, 'CloudStorageArtifactDeletionService')
&& str_contains($deletion, "['template_import_intent_id' =>")
&& is_string($artifactManager)
&& str_contains($artifactManager,
'CloudStorageArtifactService::presignedRead(')
&& !str_contains($artifactManager, 'CloudSecrets::decrypt(')
&& !str_contains($catalog, 'CloudAgentClient')
&& !str_contains($catalog, '->request(')
&& str_contains($catalog,
"throw new CloudError('没有已启用且已配置 Agent 的宿主机', 409)")
&& 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)
&& is_string($remoteAcquisition)
&& is_string($publication)
&& str_contains($controller, 'CloudTemplateCatalogService::adminCatalog()')
&& str_contains($controller, 'CloudTemplateRemoteAcquisition())->importRemote(')
&& str_contains($controller, 'CloudTemplateCatalogService::rename(')
&& str_contains($controller, 'CloudTemplateCatalogService::delete(')
&& str_contains($remoteAcquisition, 'CloudTemplateRemoteFetcher')
&& str_contains($remoteAcquisition,
'CloudTemplateStoragePublicationService::reserve(')
&& str_contains($remoteAcquisition,
'CloudTemplateStoragePublicationService::publishFile(')
&& str_contains($remoteAcquisition,
"finally {\n if (is_array(\$file)")
&& str_contains($remoteAcquisition,
"@unlink((string) \$file['path'])")
&& str_contains($remoteAcquisition,
"'path' => ''")
&& str_contains($remoteAcquisition, 'publication()->finalizeReadyIntent(')
&& str_contains($publication, 'finalizeReadyIntent(')
&& !str_contains($controller, 'CloudLocalUploadService')
&& !str_contains($catalog, 'publishAndReserveImport('),
'Template sources must converge through the durable import 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-template-imports/remote'")
&& str_contains($routes,
"'/admin/cloud-template-imports/{id}/resume'")
&& str_contains($routes, "'/admin/cloud-templates/{id}/startup-script'")
&& !str_contains($routes, "'/admin/cloud-templates/import'")
&& !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, 'delete_generation INT UNSIGNED NOT NULL')
&& str_contains($schema, 'cloud_template_artifact_delete_due')
&& preg_match('/CREATE TABLE cloud_templates \((.*?)\n\) ENGINE=/s',
$schema, $templateTable) === 1
&& !str_contains($templateTable[1], 'source_type')
&& !str_contains($templateTable[1], 'sealed_source_url')
&& 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";