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

205 lines
11 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')
. "\n" . $read('public/cloud/admin-instance-transport.js')
. "\n" . $read('public/cloud/admin-instance-detail.js')
. "\n" . $read('public/cloud/admin-instance-migration.js')
. "\n" . $read('public/cloud/admin-instance-backups.js');
$assets = $read('resources/views/venix/layout_assets.tpl');
$service = $read('app/Services/Cloud/CloudBackupService.php');
$placement = $read('app/Services/Cloud/CloudPlacementService.php');
$jobService = $read('app/Services/Cloud/CloudJobService.php');
$lifecycle = $read('app/Services/Cloud/CloudLifecycleService.php');
$upgrade = $read('app/Services/Cloud/CloudPlanUpgradeService.php');
$validationGuide = (string) file_get_contents(dirname($root) . '/docs/VALIDATION.md');
$pruningReport = (string) file_get_contents(dirname($root) . '/docs/PRUNING_REPORT.md');
$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/backups/{backup_id:[0-9]+}/cleanup-workspace'")
&& 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($routes,
"'/admin/instances/{id:[0-9]+}/maintenance-migrations'")
&& str_contains($routes,
"'/admin/instances/{id:[0-9]+}/maintenance-migrations/cleanup'")
&& str_contains($routes,
"'/admin/instances/{id:[0-9]+}/maintenance-migrations/recover'")
&& str_contains($controller, 'CloudBackupService::listing(')
&& str_contains($controller, 'CloudBackupService::create(')
&& str_contains($controller, 'CloudBackupService::restore(')
&& str_contains($controller, 'CloudBackupService::delete(')
&& str_contains($controller, 'CloudBackupService::cleanupWorkspace(')
&& 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.');
$migration = $read('app/Services/Cloud/CloudInstanceMigrationService.php');
$migrationWorkflow = $read(
'app/Services/Cloud/CloudInstanceMigrationWorkflow.php'
);
$migrationSettlement = $read(
'app/Services/Cloud/CloudInstanceMigrationSettlement.php'
);
$peerArtifacts = $read(
'app/Services/Cloud/CloudPeerMigrationArtifactService.php'
);
$assert(str_contains($runtime, 'export function createAdminInstanceMigration(')
&& str_contains($runtime,
"import(versionedModuleUrl('./admin-instance-migration.js'))")
&& str_contains($runtime, 'confirm_maintenance_migration: true')
&& str_contains($runtime, 'confirm_source_cleanup: true')
&& str_contains($runtime, '原账单、到期时间和流量周期')
&& str_contains(
$migrationSettlement,
"'maintenance_migration_transferred'"
)
&& str_contains($migration, "'traffic_counter_generation'")
&& str_contains($migration, "'reconcile_cleanup'")
&& str_contains($migration, "'managed_artifacts_absent'")
&& str_contains($migration, 'reserveBackupRestore(')
&& str_contains($migration, 'preparedBackupRestorePlacement(')
&& str_contains($migration, '$restore->target_instance_id = null;')
&& str_contains($jobService,
'CloudInstanceMigrationService::assertInstanceMutationAvailable(')
&& str_contains($lifecycle,
'CloudInstanceMigrationService::hasOpenMigration(')
&& str_contains($upgrade,
'CloudInstanceMigrationService::assertInstanceMutationAvailable(')
&& str_contains($migration, "['retain', 'delete']"),
'Maintenance migration must pre-reserve its target, preserve one service ledger and fence source cleanup.');
$assert(str_contains($peerArtifacts,
'final class CloudPeerMigrationArtifactService')
&& str_contains($migration, 'private const PROTOCOL_VERSION = 3;')
&& str_contains($migration, "\$peer['endpoints']")
&& str_contains($migration, "\$peer['identity_sha256']")
&& str_contains($migration, "\$peer['pinned_tls']")
&& str_contains($migration, "'source_endpoints' =>")
&& str_contains($migration, "'source_identity_sha256' =>")
&& str_contains($peerArtifacts, 'freezeSnapshotsLocked(')
&& str_contains($peerArtifacts, 'finishReceiveLocked(')
&& str_contains($migration, "'network_suspended' =>")
&& str_contains($migration, "'chunk_size_bytes'")
&& str_contains($migrationWorkflow, "'retry_transfer'")
&& str_contains($migrationWorkflow, "'abort_transfer'")
&& str_contains($migrationWorkflow, "'abort_prepare'")
&& str_contains($migration, 'queueMaintenanceMigrationReapplyLocked(')
&& str_contains($migration, 'queueActivationLocked(')
&& strpos($migration, 'queueMaintenanceMigrationReapplyLocked(')
< strpos($migration, 'queueActivationLocked(')
&& str_contains($migration, "\$spec['guest_hostname'] ?? \$instance->name")
&& str_contains($migrationWorkflow, "'label' => '恢复目标电源状态'")
&& str_contains($migrationWorkflow, "'label' => '重试目标状态恢复'")
&& str_contains($migrationWorkflow,
"'label' => '中止迁移并恢复源实例'")
&& str_contains($migrationWorkflow,
"'label' => '中止传输并恢复源实例'")
&& str_contains($runtime, 'migration.recovery_options')
&& str_contains($runtime, 'progress.steps'),
'PeerMigration V3 must transfer every snapshot offline, converge firewall before activation, and expose bounded recovery exits.');
$assert(str_contains($template, 'id="instances-backup-library"')
&& str_contains($template, 'id="backup-library"')
&& str_contains($runtime, 'export function createAdminInstanceBackups(')
&& str_contains($runtime,
"import(versionedModuleUrl('./admin-instance-backups.js'))")
&& str_contains($runtime, 'async function loadLibrary(')
&& str_contains($runtime, '/api/v1/admin/backups?page=')
&& str_contains($runtime,
'/api/v1/admin/backups/${encodeURIComponent(backup.id)}/cleanup-workspace')
&& str_contains($runtime, '源实例已删除')
&& str_contains($runtime, 'function mutationUrl('),
'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 = ['overview', 'service', 'configuration', 'backups', 'jobs']")
&& str_contains($runtime, "if (name === 'backups'")
&& str_contains($runtime, 'async function load(vmId, force = false)'),
'Administrator instance detail must expose a lazy portable-backup panel.');
$assert(str_contains($runtime,
"new Option('自动(优先文件系统一致)', 'filesystem', true, true)")
&& str_contains($runtime,
"new Option('强制崩溃一致(不冻结文件系统)', 'crash')")
&& str_contains($runtime, '自动模式在 QGA 不可用时降级为崩溃一致')
&& str_contains($runtime, '备份列表会显示最终实际使用的一致性模式')
&& str_contains($runtime,
"consistency_mode: consistency.value === 'crash' ? 'crash' : 'filesystem'")
&& str_contains($peerArtifacts, "\$root->consistency = 'crash'")
&& str_contains($runtime, "method = 'PATCH'")
&& str_contains($runtime, "mutate(path, body, controller, 'POST')")
&& str_contains($runtime, 'confirm_new_instance: true'),
'Ordinary backup creation must default to automatic filesystem consistency while maintenance migration remains crash-consistent.');
$assert(str_contains($runtime, "mutateJson")
&& str_contains($runtime, "controller, 'DELETE'")
&& str_contains($runtime, '核对删除状态')
&& str_contains($runtime, '两次间隔证据一致')
&& str_contains($runtime, 'requires_reconciliation'),
'Backup deletion UI must expose bounded stable-evidence 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($placement, "'is_source_host'")
&& !str_contains($placement, "->where('id', '<>', \$sourceHostId)")
&& !str_contains($service, '请选择与源宿主机不同的目标宿主机')
&& str_contains($runtime, '原宿主机'),
'Manual restore must offer an eligible original host while preserving an explicit UI label.');
$assert(!str_contains($validationGuide, '恢复必须选择不同宿主机')
&& str_contains($validationGuide, '原宿主机或其他合格宿主机')
&& !str_contains($pruningReport, '并在另一台 `bridge:br0` 宿主机')
&& str_contains($pruningReport, '原宿主机或其他合格的 `bridge:br0` 宿主机'),
'Portable-backup documentation must allow an independently reserved same-host restore.');
$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";