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/CloudPortableBackupAdminUiC...

96 lines
4.8 KiB
PHP

<?php
$root = dirname(__DIR__);
$read = static fn (string $path): string => (string) file_get_contents(
$root . '/' . $path
);
$assert = static function (bool $condition, string $message): void {
if (!$condition) {
throw new RuntimeException($message);
}
};
$controller = $read('app/Controllers/CloudAdminInstanceController.php');
$routes = $read('config/routes_cloud.php');
$template = $read('resources/views/venix/admin/cloud/instances.tpl');
$runtime = $read('public/cloud/admin-instances.js');
$assets = $read('resources/views/venix/layout_assets.tpl');
$service = $read('app/Services/Cloud/CloudBackupService.php');
$assert(str_contains($routes,
"['GET', 'POST'], '/admin/instances/{id:[0-9]+}/backups'")
&& str_contains($routes, "'/admin/backups'")
&& str_contains($routes, "'/admin/backups/{backup_id:[0-9]+}/restore'")
&& str_contains($routes, "'/admin/backups/{backup_id:[0-9]+}'")
&& str_contains($routes,
"'/admin/instances/{id:[0-9]+}/backups/{backup_id:[0-9]+}/restore'")
&& str_contains($routes,
"'/admin/instances/{id:[0-9]+}/backups/{backup_id:[0-9]+}'")
&& str_contains($controller, 'CloudBackupService::listing(')
&& str_contains($controller, 'CloudBackupService::create(')
&& str_contains($controller, 'CloudBackupService::restore(')
&& str_contains($controller, 'CloudBackupService::delete(')
&& str_contains($controller, 'CloudBackupService::library(')
&& substr_count($controller, 'CloudAccess::manage($actor);') >= 2
&& str_contains($controller, 'CloudJobService::acknowledgement($job)'),
'Administrator portable backup routes must use the durable backup service and strict task receipt.');
$assert(str_contains($template, 'id="instances-backup-library"')
&& str_contains($template, 'id="backup-library"')
&& str_contains($runtime, 'async function loadBackupLibrary(')
&& str_contains($runtime, '/api/v1/admin/backups?page=')
&& str_contains($runtime, '源实例已删除')
&& str_contains($runtime, 'backupMutationUrl('),
'The bounded global backup library must remain usable after source VM deletion.');
$assert(str_contains($template, 'data-instance-tab="backups"')
&& str_contains($template, 'id="instance-panel-backups"')
&& str_contains($runtime, "const tabs = ['basic', 'service', 'backups', 'jobs', 'invoices']")
&& str_contains($runtime, "if (name === 'backups'")
&& str_contains($runtime, 'async function loadBackups('),
'Administrator instance detail must expose a lazy portable-backup panel.');
$assert(str_contains($runtime, "new Option('崩溃一致(默认)', 'crash')")
&& str_contains($runtime, "consistency_mode: consistency.value === 'filesystem' ? 'filesystem' : 'crash'")
&& str_contains($runtime, "method = 'PATCH'")
&& str_contains($runtime, "'POST',")
&& str_contains($runtime, 'confirm_new_instance: true'),
'Backup creation and restore must use explicit POST mutations and confirmation.');
$assert(str_contains($runtime, "method: 'DELETE'")
&& str_contains($runtime, '核对删除状态')
&& str_contains($runtime, '不会重发删除请求')
&& str_contains($runtime, 'requires_reconciliation'),
'Backup deletion UI must expose non-replaying read-only reconciliation after unknown effect.');
$assert(str_contains($runtime, '统一接入 br0 并分配全新公网 IP')
&& str_contains($runtime, '不会继承原 IP、账单、到期时间或流量周期')
&& str_contains($runtime, '临时快照清理仍需管理员核对')
&& str_contains($runtime, '系统不会重复上传')
&& str_contains($runtime, 'target_host_id')
&& str_contains($runtime, 'available_ip_count'),
'The restore UI must describe and collect the independent br0/new-IP target intent.');
$assert(str_contains($service,
"is_bool(\$spec['debian_12_network_fix'] ?? null)")
&& str_contains($service, '实例缺少创建时冻结的网络兼容快照'),
'Backup listing must reject missing network compatibility metadata before submission.');
$assert(str_contains($service,
'private const CREATE_TRANSACTION_ATTEMPTS = 1;')
&& str_contains($service,
'}, self::CREATE_TRANSACTION_ATTEMPTS);'),
'CreateMultipartUpload must not be replayed by automatic database transaction retries.');
$assert(!str_contains($runtime, 'object_key')
&& !str_contains($runtime, 'part_url')
&& !str_contains($runtime, 'source_url')
&& !str_contains($runtime, 'access_key_id')
&& !str_contains($runtime, 'secret_access_key'),
'Browser backup code must not consume object keys, presigned URLs or credentials.');
$assert(preg_match("/venix_asset_version value='([0-9]+)'/", $assets) === 1,
'Portable backup browser changes must use the shared asset cache key.');
echo "Cloud portable backup administrator UI contract passed.\n";