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/VirtualizationAssetsTest.php

827 lines
58 KiB
PHP

<?php
// Static source graph only: no application boot, database or browser network.
$root = dirname(__DIR__);
$public = $root . '/public/cloud';
$assert = static function ($condition, $message) {
if (!$condition) throw new RuntimeException($message);
};
$entry = $public . '/vendor/novnc/core/rfb.js';
$queue = [$entry];
$seen = [];
while ($queue !== []) {
$file = array_pop($queue);
$resolved = realpath($file);
$assert($resolved !== false && str_starts_with($resolved, realpath($public) . DIRECTORY_SEPARATOR), 'Missing or external noVNC module: ' . $file);
if (isset($seen[$resolved])) continue;
$seen[$resolved] = true;
$source = file_get_contents($resolved);
preg_match_all('/(?:import|export)\s+(?:[^;]*?\s+from\s+)?[\'"]([^\'"]+)[\'"]\s*;/', $source, $imports);
foreach ($imports[1] as $path) {
if (str_starts_with($path, './') || str_starts_with($path, '../')) $queue[] = dirname($resolved) . '/' . $path;
}
}
$assert(count($seen) > 20, 'noVNC dependency graph was not validated');
$assert(is_file($public . '/vendor/novnc/LICENSE.txt'), 'Vendored noVNC license missing');
foreach (['almalinux', 'ubuntu', 'debian', 'centos'] as $system) {
$assert(is_file($public . '/' . $system . '-icon.svg'), 'Local OS icon missing: ' . $system);
}
foreach (['user/layout_header.tpl', 'user/layout_plain_header.tpl', 'auth/layout_header.tpl'] as $template) {
$source = file_get_contents($root . '/resources/views/venix/' . $template);
$assert(str_contains($source, '/cloud/styles.css') && str_contains($source, '/cloud/account.css'), 'Unified user styles missing: ' . $template);
$assert(!str_contains($source, 'user-home.css') && !str_contains($source, '/css/auth.css'), 'Retired user stylesheet still active: ' . $template);
}
$views = $root . '/resources/views/venix';
$cloudShell = file_get_contents($views . '/cloud/page.tpl');
$cloudPages = '';
foreach (glob($views . '/cloud/pages/*.tpl') as $template) {
$cloudPages .= "\n" . file_get_contents($template);
}
$cloudTemplate = $cloudShell . $cloudPages;
$userLayout = file_get_contents($views . '/user/layout_header.tpl');
$sharedSidebar = file_get_contents($views . '/user/panel_sidebar.tpl');
$sharedTopbar = file_get_contents($views . '/user/panel_topbar.tpl');
$clientEntry = file_get_contents($public . '/app.js');
$clientScript = $clientEntry . "\n" . file_get_contents($public . '/runtime.js');
foreach (['instances', 'detail', 'deploy', 'iso-images', 'ssh-keys', 'invoices', 'invoice-detail', 'reinstall', 'rescue'] as $module) {
$path = $public . '/' . $module . '.js';
$assert(is_file($path), 'Cloud page module missing: ' . $module);
$clientScript .= "\n" . file_get_contents($path);
}
$invoiceDetailRuntimePath = $public . '/invoice-detail-runtime.js';
$assert(is_file($invoiceDetailRuntimePath),
'Dedicated invoice-detail runtime missing: invoice-detail-runtime.js');
$invoiceDetailModule = file_get_contents($public . '/invoice-detail.js');
$invoiceDetailRuntime = file_get_contents($invoiceDetailRuntimePath);
$clientStyles = file_get_contents($public . '/client.css');
$baseStyles = file_get_contents($public . '/styles.css');
$routes = file_get_contents($root . '/config/routes.php');
$userController = file_get_contents($root . '/app/Controllers/UserController.php');
$cloudPageController = file_get_contents($root . '/app/Controllers/CloudPageController.php');
$deploymentPageService = file_get_contents($root . '/app/Services/Cloud/CloudDeploymentPageService.php');
$deployTemplate = file_get_contents($views . '/cloud/pages/deploy.tpl');
$reinstallTemplate = file_get_contents($views . '/cloud/pages/reinstall.tpl');
$deployModule = file_get_contents($public . '/deploy.js');
$reinstallModule = file_get_contents($public . '/reinstall.js');
$shopFormScript = file_get_contents($views . '/admin/shop/form_js.tpl');
$templateAdmin = file_get_contents($views . '/admin/cloud/templates.tpl');
$rescueAdmin = file_get_contents($views . '/admin/cloud/rescue.tpl');
$adminScript = file_get_contents($public . '/admin.js');
$cloudAdminController = file_get_contents($root . '/app/Controllers/CloudAdminController.php');
$cloudRoutes = file_get_contents($root . '/config/routes_cloud.php');
$cloudSchema = file_get_contents($root . '/sql/cloud.sql');
$adminBillingTemplate = $views . '/admin/billing.tpl';
$adminBillingScript = $public . '/admin-billing.js';
$adminBillingRuntime = file_get_contents($adminBillingScript);
$adminBillingStyles = $public . '/admin-billing.css';
$adminSharedStyles = file_get_contents($root . '/public/theme/venix/css/admin-home.css');
$templateDeletionService = file_get_contents(
$root . '/app/Services/Cloud/CloudTemplateDeletionService.php');
$assert(str_contains($cloudShell, "file='user/panel_sidebar.tpl'")
&& str_contains($userLayout, "file='user/panel_sidebar.tpl'"), 'Cloud and account pages must share one sidebar partial');
$assert(str_contains($cloudShell, "file='user/panel_topbar.tpl'")
&& str_contains($userLayout, "file='user/panel_topbar.tpl'"), 'Cloud and account pages must share one topbar partial');
$assert(!str_contains($cloudShell, '<aside class="sidebar"')
&& !str_contains($userLayout, 'vu-sidebar'), 'A duplicate user sidebar shell remains active');
$assert(str_contains($userLayout, '/cloud/client.css'), 'Account pages must load the shared VM-panel navigation styles');
$assert(str_contains($sharedSidebar, 'mdi-server') && str_contains($sharedSidebar, 'mdi-lifebuoy'), 'Shared sidebar must retain Venix iconography');
$assert(str_contains($clientStyles, '.cloud-sidebar-nav .sidebar-link + .sidebar-link { margin-top: 6px; }'),
'Adjacent sidebar links must retain visual separation when active and hover states meet');
$assert(str_contains($sharedSidebar, '/user/logout') && !str_contains($clientScript, "location.assign('/auth/logout')"), 'Logged-in logout must use the authenticated user route');
$retiredUserPages = [
'/account' => 'index',
'/profile' => 'profile',
];
foreach ($retiredUserPages as $route => $method) {
$assert(!str_contains($routes, "get('" . $route . "', 'App\\Controllers\\UserController:" . $method . "')"),
'Retired user page route remains: ' . $route);
$assert(!str_contains($userController, 'public function ' . $method . '('),
'Retired user page controller remains: ' . $method);
}
$assert(!str_contains($routes, "'App\\Controllers\\UserController:bought'")
&& !str_contains($routes, "'App\\Controllers\\UserController:boughtInvoice'")
&& !str_contains($userController, 'public function bought(')
&& !str_contains($userController, 'public function boughtInvoice(')
&& !str_contains($userController, 'public function deleteBoughtGet('),
'Retired user order history handlers remain');
foreach (['index.tpl', 'profile.tpl', 'bought.tpl', 'bought_invoice.tpl'] as $retiredTemplate) {
$assert(!is_file($views . '/user/' . $retiredTemplate),
'Retired user page template remains: ' . $retiredTemplate);
}
$remainingUserTemplates = '';
foreach (glob($views . '/user/*.tpl') as $template) {
$remainingUserTemplates .= "\n" . file_get_contents($template);
}
$assert(!str_contains($sharedSidebar . $remainingUserTemplates, '/user/account')
&& !str_contains($sharedSidebar . $remainingUserTemplates, '/user/profile')
&& !str_contains($sharedSidebar . $remainingUserTemplates, '/user/bought'),
'A retained user template links to a retired user page');
$assert(str_contains($routes, "'/cloud/invoices'")
&& str_contains($routes, "get('/billing', 'App\\Controllers\\Admin\\CloudPageController:billing')")
&& !str_contains($routes, "'/bought'")
&& is_file($adminBillingTemplate)
&& is_file($adminBillingScript)
&& !is_file($adminBillingStyles),
'Cloud invoices and the unified administrator billing page must replace legacy bought history');
$assert(str_contains($cloudRoutes, "'/admin/billing/invoices'")
&& str_contains($cloudRoutes, "'/admin/billing/invoices/{id:[0-9]+}'")
&& str_contains($cloudRoutes, "'/admin/billing/orders'")
&& str_contains($cloudRoutes, "'/admin/billing/payments'"),
'Unified administrator billing API routes are incomplete');
$assert(str_contains($routes, "'/cloud/instances'")
&& str_contains($routes, "'/cloud/instances/{id:[0-9]+}'")
&& str_contains($routes, "'/cloud/deploy'")
&& str_contains($routes, "'/cloud/iso-images'")
&& str_contains($routes, "'/cloud/ssh-keys'")
&& str_contains($routes, "'/cloud/invoices'")
&& str_contains($routes, "'/cloud/invoices/{id:[0-9]+}'"),
'Cloud user pages must have stable first-class routes');
$assert(str_contains($cloudPageController, "'/user/cloud/instances'")
&& str_contains($cloudShell, 'data-cloud-page=')
&& str_contains($clientEntry, "instances: '/cloud/instances.js'")
&& str_contains($clientEntry, "import(moduleUrl.href)"),
'Cloud route controller and page-module bootstrap contract is incomplete');
$assert(!str_contains($clientScript, 'location.hash')
&& !str_contains($clientScript, 'hashchange')
&& !str_contains($clientScript, 'routeHash')
&& !str_contains($sharedSidebar, '/user/cloud#'),
'Retired hash routing must not remain in the user cloud UI');
$assert(str_contains($clientEntry, "new URL(import.meta.url).searchParams.get('v')")
&& str_contains($clientScript, "new URL('/cloud/runtime.js', location.origin)"),
'Page modules must propagate the asset version to avoid year-long stale module caching');
$assert(substr_count($clientScript, "window.addEventListener('pageshow'") >= 3
&& substr_count($clientScript, 'if (!event.persisted) return;') >= 3
&& substr_count($clientScript, 'startPolling();') >= 6,
'Instance, detail and invoice polling must resume after a browser back-forward cache restore');
$assert(str_contains($baseStyles, '#create-view.workspace-form-page,#reinstall-view.workspace-form-page{width:100%;margin-left:0;margin-right:0}'), 'Create and reinstall pages must align to the full VM-list content width');
$assert(str_contains($baseStyles, '.ssh-key-details small{display:block;margin:0;')
&& str_contains($baseStyles, '.ssh-key-actions .row-button{flex:1}')
&& str_contains($clientScript, "makeElement('small', '', key.fingerprint || '')"),
'Saved SSH keys must not inherit global muted spacing and mobile actions must target the rendered button class');
$assert(str_contains($baseStyles,
'.ssh-key-picker{display:grid;grid-template-columns:repeat(auto-fill,minmax(240px,320px));')
&& str_contains($baseStyles,
'.ssh-key-picker .ssh-key-option{display:grid;grid-template-columns:34px minmax(0,1fr) 20px;')
&& str_contains($baseStyles, '.ssh-key-choice-fingerprint{display:block;')
&& str_contains($clientScript,
"const fingerprintLabel = makeElement('small', 'ssh-key-choice-fingerprint'")
&& str_contains($clientScript, "button.dataset.keyId = keyId;")
&& str_contains($clientScript, "button.dataset.keyFingerprint = fingerprint;")
&& str_contains($clientScript, ",指纹 \${fingerprint || '未记录'}")
&& str_contains($clientScript,
"container.querySelectorAll('.ssh-key-option').forEach((option) =>"),
'Deploy and reinstall SSH key choices must stay compact, show fingerprints and update selection in place.');
$assert(str_contains($cloudTemplate, '>实例管理</h1>')
&& str_contains($cloudTemplate, '部署实例</a>'),
'Instance page terminology missing');
$assert(str_contains($sharedSidebar, '>我的实例</span>') && str_contains($sharedSidebar, '>部署实例</span>'), 'Shared sidebar instance terminology missing');
$assert(str_contains($sharedSidebar, 'href="/user/cloud/iso-images"')
&& str_contains($sharedSidebar, '{if !empty($user_iso_enabled)}')
&& str_contains($sharedSidebar, '>ISO 上传</span>')
&& str_contains($cloudShell, "cloud_page == 'isos'")
&& str_contains($clientEntry, "isos: '/cloud/iso-images.js'"),
'User-owned ISO page must be reachable from shared navigation and module bootstrap.');
$regionPosition = strpos($cloudTemplate, 'id="vm-region-picker"');
$planPosition = strpos($cloudTemplate, 'id="vm-plan-picker"');
$sourcePosition = strpos($cloudTemplate, 'id="vm-template-catalog"');
$assert($regionPosition !== false && $planPosition > $regionPosition && $sourcePosition > $planPosition
&& str_contains($clientScript, 'function renderRegionPicker()')
&& str_contains($clientScript, 'function renderPlanPicker()')
&& str_contains($clientScript, "source: 'cloud'")
&& !str_contains($clientScript, "body.iso_id")
&& !str_contains($cloudTemplate, 'class="create-source-picker"')
&& !str_contains($cloudTemplate, 'id="vm-iso"')
&& str_contains($clientScript, 'if (!strongPassword(password))')
&& str_contains($clientScript, '/^[\\x21-\\x7e]+$/.test(value)')
&& substr_count($cloudTemplate, 'maxlength="128"') >= 2
&& str_contains($clientScript, 'formBody.inert = true')
&& str_contains($clientScript, 'formBody.inert = false')
&& !str_contains($clientScript, 'body.iso_path ='),
'Deployment must select region, plan and a cloud image without exposing an installation-mode switch.');
$assert(str_contains($deployTemplate, '实例名称(可选)')
&& str_contains($deployTemplate, '留空自动生成,例如 vm-k7m4p2')
&& str_contains($deployTemplate, 'vm- 加 6 位随机编码')
&& !preg_match('/id="vm-name"[^>]*\srequired(?:\s|>)/', $deployTemplate),
'Deployment instance name must be optional and explain its short generated default.');
$planRendererStart = strpos($clientScript, 'function renderPlanPicker()');
$planRendererEnd = strpos($clientScript, 'async function selectRegion(', $planRendererStart);
$planRenderer = $planRendererStart === false || $planRendererEnd === false
? ''
: substr($clientScript, $planRendererStart, $planRendererEnd - $planRendererStart);
$assert(str_contains($planRenderer, "'plan-table-head'")
&& str_contains($planRenderer, 'formatMemoryGiB(plan.memory_mib)')
&& str_contains($planRenderer, 'formatTrafficTiBFromGiB(plan.traffic_gib)')
&& str_contains($planRenderer, 'formatUsd(plan.price)')
&& !str_contains($planRenderer, 'bandwidth_mbps')
&& str_contains($baseStyles, '.plan-option[aria-pressed="true"]::after{content:"✓"')
&& str_contains($baseStyles, '.plan-option>:nth-child(6)::before{content:"价格"}')
&& !str_contains($cloudTemplate, 'id="vm-plan-summary"')
&& !str_contains($cloudTemplate, 'class="vm-auto-public-pool"')
&& !str_contains($cloudTemplate, 'id="create-cloud-tip"')
&& !str_contains($cloudTemplate, 'id="create-iso-tip"'),
'Deployment plans must use selectable specification rows without obsolete helper panels.');
$assert(str_contains($baseStyles,
'.plan-option:last-of-type{border-bottom:0;border-bottom-right-radius:10px;border-bottom-left-radius:10px}')
&& str_contains($baseStyles,
'.plan-option:first-of-type{border-top-left-radius:10px;border-top-right-radius:10px}')
&& str_contains($baseStyles,
'.plan-option[aria-pressed="true"]{z-index:1;background:#eef9fa;box-shadow:inset 0 0 0 2px #2eabb4;'),
'Selected plan rows must preserve rounded first/last corners without clipping their inset border.');
$runtimeDeployScript = file_get_contents($public . '/runtime.js');
$selectRegionStart = strpos($runtimeDeployScript, 'async function selectRegion(');
$selectRegionEnd = $selectRegionStart === false ? false
: strpos($runtimeDeployScript, 'async function selectPlan(', $selectRegionStart);
$selectRegion = $selectRegionStart === false || $selectRegionEnd === false ? ''
: substr($runtimeDeployScript, $selectRegionStart, $selectRegionEnd - $selectRegionStart);
$selectPlanStart = strpos($runtimeDeployScript, 'async function selectPlan(');
$selectPlanEnd = $selectPlanStart === false ? false
: strpos($runtimeDeployScript, 'async function openCreate(', $selectPlanStart);
$selectPlan = $selectPlanStart === false || $selectPlanEnd === false ? ''
: substr($runtimeDeployScript, $selectPlanStart, $selectPlanEnd - $selectPlanStart);
$assert($selectPlan !== ''
&& !str_contains($selectPlan, 'renderPlanPicker();')
&& str_contains($selectPlan,
"byId('vm-plan-picker').querySelectorAll('.plan-option').forEach(button => {")
&& str_contains($selectPlan,
"button.setAttribute('aria-pressed', String(button.dataset.planId === String(plan.id)));"),
'Selecting a plan must preserve the focused row instead of replacing the plan list.');
$openCreateStart = strpos($runtimeDeployScript, 'async function openCreate(');
$openCreateEnd = $openCreateStart === false ? false
: strpos($runtimeDeployScript, 'async function loadGlobalTemplates()', $openCreateStart);
$openCreate = $openCreateStart === false || $openCreateEnd === false ? ''
: substr($runtimeDeployScript, $openCreateStart, $openCreateEnd - $openCreateStart);
$openReinstallStart = strpos($runtimeDeployScript, 'async function openReinstall(');
$openReinstallEnd = $openReinstallStart === false ? false
: strpos($runtimeDeployScript, 'async function pollJob(', $openReinstallStart);
$openReinstall = $openReinstallStart === false || $openReinstallEnd === false ? ''
: substr($runtimeDeployScript, $openReinstallStart, $openReinstallEnd - $openReinstallStart);
$deployHydrationReturn = strpos($openCreate, ' return;');
$deployFallbackRequest = strpos($openCreate, 'Promise.allSettled([');
$reinstallBootstrapStart = strpos($openReinstall,
'if (bootstrap && Array.isArray(bootstrap.templates))');
$reinstallHydrationReturn = $reinstallBootstrapStart === false ? false
: strpos($openReinstall, ' return;', $reinstallBootstrapStart);
$reinstallFallbackRequest = strpos($openReinstall, "api(`/api/v1/resources?vm_id=");
$assert(str_contains($deployTemplate, 'id="deploy-bootstrap" type="application/json"')
&& str_contains($deployTemplate, '{foreach $cloud_deploy_regions as $region}')
&& str_contains($deployTemplate, '$region.host_id == $cloud_deploy_default_host_id')
&& str_contains($deployTemplate, '{foreach $region.plans as $plan}')
&& str_contains($deployTemplate, '{foreach $cloud_deploy_template_groups as $group}')
&& str_contains($deployTemplate, '{foreach $cloud_deploy_ssh_keys as $key}')
&& !str_contains($deployTemplate, '正在加载系统镜像'),
'Deployment HTML must contain regions, first-region plans, images and SSH keys before hydration.');
$assert(str_contains($deploymentPageService, "->orderBy('sort')->orderBy('id')")
&& str_contains($deploymentPageService, "->where('enabled', 1)")
&& str_contains($deploymentPageService, "'plans' => []")
&& str_contains($cloudPageController, '$defaultHostId = $regions === [] ? 0 : (int) $regions[0][\'host_id\']')
&& str_contains($cloudPageController, "'cloud_deploy_bootstrap_json' => \$this->safeJson(\$payload)"),
'Deployment SSR must preserve sale order and select the first available host region by default.');
$assert(str_contains($deployModule, "readBootstrap('deploy-bootstrap')")
&& str_contains($deployModule, "initializeSession('create', bootstrap?.user)")
&& str_contains($deployModule, 'openCreate(bootstrap)')
&& !str_contains($deployModule, '/api/v1/session')
&& !str_contains($deployModule, '/api/v1/plans')
&& !str_contains($deployModule, '/api/v1/resources')
&& !str_contains($deployModule, '/api/v1/ssh-keys'),
'Deployment first paint must hydrate its embedded payload without initial data API requests.');
$assert(str_contains($openCreate, 'Array.isArray(bootstrap.plans)')
&& str_contains($openCreate, 'Array.isArray(bootstrap.templates)')
&& str_contains($openCreate, "bootstrapItems(bootstrap, 'regions')")
&& str_contains($openCreate, 'bootstrap.default_host_id')
&& str_contains($openCreate, "(regions[0]?.hostId || '')")
&& str_contains($openCreate, "renderTemplateCatalog('vm-template')")
&& $deployHydrationReturn !== false && $deployFallbackRequest !== false
&& $deployHydrationReturn < $deployFallbackRequest,
'Deployment hydration must use the embedded full catalog and first valid region before any compatibility fallback.');
$assert(str_contains($reinstallTemplate, 'id="reinstall-bootstrap" type="application/json"')
&& str_contains($reinstallTemplate, '$cloud_reinstall_vm.name')
&& str_contains($reinstallTemplate, '{foreach $cloud_reinstall_template_groups as $group}')
&& str_contains($reinstallTemplate, '{foreach $cloud_reinstall_ssh_keys as $key}')
&& str_contains($reinstallModule, "readBootstrap('reinstall-bootstrap')")
&& str_contains($reinstallModule, "initializeSession('reinstall', bootstrap?.user)")
&& str_contains($reinstallModule, 'selectVmByApiId(document.body.dataset.vmId || \'\', bootstrap?.vm)')
&& str_contains($reinstallModule, 'openReinstall(vm, bootstrap)')
&& !str_contains($reinstallModule, '/api/v1/session')
&& !str_contains($reinstallModule, '/api/v1/resources')
&& !str_contains($reinstallModule, '/api/v1/ssh-keys')
&& str_contains($openReinstall, 'Array.isArray(bootstrap.templates)')
&& $reinstallHydrationReturn !== false && $reinstallFallbackRequest !== false
&& $reinstallHydrationReturn < $reinstallFallbackRequest,
'Reinstall HTML must embed VM, image and key data and hydrate without initial data API requests.');
$assert($selectRegion !== '' && $selectPlan !== ''
&& !str_contains($selectRegion, 'resetInstallChoices()')
&& !str_contains($selectRegion, 'renderTemplateCatalog(')
&& !str_contains($selectRegion, 'loadGlobalTemplates(')
&& !str_contains($selectRegion, "byId('vm-template').value")
&& !str_contains($selectPlan, 'resetInstallChoices()')
&& !str_contains($selectPlan, 'renderTemplateCatalog(')
&& !str_contains($selectPlan, 'loadGlobalTemplates(')
&& !str_contains($selectPlan, "byId('vm-template').value"),
'Changing regions or plans must preserve the global image catalog and selected image.');
$catalogRendererStart = strpos($runtimeDeployScript, 'function renderTemplateCatalog(inputId)');
$catalogRendererEnd = $catalogRendererStart === false ? false
: strpos($runtimeDeployScript, 'async function initializeSession(', $catalogRendererStart);
$catalogRenderer = $catalogRendererStart === false || $catalogRendererEnd === false ? ''
: substr($runtimeDeployScript, $catalogRendererStart,
$catalogRendererEnd - $catalogRendererStart);
$mobileDeploymentStylesStart = strrpos($baseStyles, '@media(max-width:510px){');
$mobileDeploymentStyles = $mobileDeploymentStylesStart === false ? ''
: substr($baseStyles, $mobileDeploymentStylesStart);
$cardVersionRule = strpos($baseStyles,
'.template-version-option{width:100%;display:grid;gap:3px;');
$flatVersionRule = strpos($baseStyles,
'.template-version-option{min-height:44px;padding:11px 4px;border:0;');
$assert(str_contains($mobileDeploymentStyles,
'.plan-option{grid-template-columns:repeat(4,minmax(0,1fr));grid-template-rows:auto auto;gap:12px 8px;min-height:108px;')
&& str_contains($mobileDeploymentStyles,
'.plan-option-name{grid-column:1/3;grid-row:1;align-self:center;font-size:14px}')
&& str_contains($mobileDeploymentStyles,
'.plan-option-price{display:block;grid-column:3/5;grid-row:1;align-self:center;justify-self:end;padding-right:30px;')
&& str_contains($mobileDeploymentStyles,
'.plan-option-value{display:grid;grid-row:2;gap:4px;white-space:normal}')
&& str_contains($mobileDeploymentStyles,
'.plan-option>:nth-child(2){grid-column:1}.plan-option>:nth-child(3){grid-column:2}.plan-option>:nth-child(4){grid-column:3}.plan-option>:nth-child(5){grid-column:4}')
&& str_contains($mobileDeploymentStyles,
'.plan-option[aria-pressed="true"]{box-shadow:none}')
&& !str_contains($mobileDeploymentStyles, 'box-shadow:inset 4px 0 0')
&& str_contains($mobileDeploymentStyles,
'.plan-option-price::before{display:none;content:none}')
&& !str_contains($mobileDeploymentStyles,
'.plan-option{grid-template-columns:repeat(2,minmax(0,1fr))'),
'Mobile deployment plans must use a compact two-row comparison layout without replacing semantic plan buttons.');
$assert(str_contains($baseStyles,
'.template-catalog{display:grid;grid-template-columns:repeat(auto-fill,minmax(210px,1fr));align-items:start;')
&& str_contains($baseStyles,
'.template-family-card{position:relative;z-index:1;')
&& str_contains($baseStyles, 'background:#fff;overflow:visible;transition:')
&& str_contains($baseStyles, '.template-family-card[open]{z-index:20;')
&& str_contains($baseStyles,
'.template-versions{position:absolute;top:calc(100% + 8px);left:0;right:0;z-index:30;')
&& str_contains($baseStyles, 'max-height:min(260px,50vh);')
&& str_contains($baseStyles, 'overflow-y:auto;')
&& str_contains($mobileDeploymentStyles,
'.template-family-card{height:140px;min-height:140px;border:1px solid #dce7ec;border-radius:12px;background:#fff;overflow:hidden;box-shadow:none}')
&& str_contains($mobileDeploymentStyles,
'.template-family-summary{height:100%;min-height:100%;border:0;border-radius:inherit;background:transparent}')
&& str_contains($mobileDeploymentStyles,
'.template-family-card[open]{z-index:70;border-color:#a8dadd;box-shadow:')
&& str_contains($mobileDeploymentStyles,
'.template-family-card.has-selection{border-color:#2eabb4;background:#f5fbfb}')
&& str_contains($mobileDeploymentStyles,
'.template-versions{position:absolute;inset:0;z-index:80;width:auto;height:auto;max-height:none;margin:0;')
&& str_contains($mobileDeploymentStyles,
'padding:6px 8px 40px;overflow-y:auto;border:0;border-radius:inherit;background:#fbfdfd;box-shadow:none;')
&& str_contains($mobileDeploymentStyles,
'.template-family-card[open] .template-family-footer{position:absolute;right:7px;bottom:7px;z-index:90;width:32px;min-height:32px;')
&& str_contains($mobileDeploymentStyles,
'.template-family-card[open] .template-family-selection{display:none}')
&& str_contains($mobileDeploymentStyles, 'overscroll-behavior:contain;')
&& !str_contains($mobileDeploymentStyles,
'.template-versions{position:fixed;')
&& !str_contains($mobileDeploymentStyles,
'.template-versions{position:relative;')
&& !str_contains($mobileDeploymentStyles, 'width:calc(200%')
&& !str_contains($mobileDeploymentStyles, 'left:calc(-100%')
&& !str_contains($mobileDeploymentStyles,
'.template-family-card:nth-child(even) .template-versions')
&& !str_contains($baseStyles, 'width:min(280px,calc(100vw - 66px))')
&& str_contains($baseStyles, '.template-versions{gap:0;padding:5px 12px}')
&& str_contains($baseStyles,
'.template-version-option{min-height:44px;padding:11px 4px;border:0;border-bottom:1px solid #e4ecef;border-radius:0;background:transparent;box-shadow:none;')
&& str_contains($baseStyles,
'.template-version-option[aria-pressed="true"]{border-color:#e4ecef;background:#eaf8f8;box-shadow:none;')
&& $cardVersionRule !== false && $flatVersionRule !== false
&& $flatVersionRule > $cardVersionRule
&& str_contains($baseStyles,
'.template-family-card.has-selection{border-color:#2eabb4;background:#f5fbfb}')
&& str_contains($baseStyles,
'.template-family-selected-mark{position:absolute;top:10px;right:10px;')
&& str_contains($baseStyles,
'.template-family-card.has-selection .template-family-selected-mark{display:grid}')
&& str_contains($baseStyles,
'.template-family-summary{display:flex;align-items:center;flex-direction:column;gap:6px;min-height:152px;')
&& str_contains($baseStyles,
'list-style:none;-webkit-tap-highlight-color:transparent}')
&& str_contains($baseStyles,
'.template-family-icon{display:flex;align-items:center;justify-content:center;width:58px;height:58px;')
&& str_contains($baseStyles,
'.template-family-footer{display:flex;align-items:center;justify-content:center;gap:8px;width:100%;min-height:25px;')
&& str_contains($baseStyles,
'.template-family-arrow{display:block;flex:none;width:8px;height:8px;border-right:2px solid #718795;border-bottom:2px solid #718795;')
&& str_contains($baseStyles, '.template-family-selection{display:block;')
&& str_contains($baseStyles,
'.template-family-selection:empty{display:none}')
&& !str_contains($baseStyles,
'.template-family-selection:empty::before{content:"选择版本"}')
&& str_contains($baseStyles,
'.template-family-summary{min-height:140px;padding:13px 8px 10px}')
&& str_contains($deployTemplate, 'name="vm-template-family"')
&& str_contains($reinstallTemplate, 'name="reinstall-template-family"')
&& str_contains($deployTemplate, 'class="template-family-footer"')
&& str_contains($reinstallTemplate, 'class="template-family-footer"')
&& str_contains($deployTemplate, 'class="template-family-selected-mark" aria-hidden="true"')
&& str_contains($reinstallTemplate, 'class="template-family-selected-mark" aria-hidden="true"')
&& !str_contains($deployTemplate, '&#x2304;')
&& !str_contains($reinstallTemplate, '&#x2304;')
&& str_contains($deployTemplate, 'class="template-family-selection" aria-hidden="true"')
&& str_contains($reinstallTemplate, 'class="template-family-selection" aria-hidden="true"'),
'Image cards must stay fixed while mobile version menus scroll inside the selected card.');
$assert($catalogRenderer !== ''
&& str_contains($runtimeDeployScript, 'function bindTemplateVersionMenu(card, container)')
&& str_contains($runtimeDeployScript, 'const TEMPLATE_FAMILY_ORDER = new Map([')
&& str_contains($runtimeDeployScript,
'["AlmaLinux", 0], ["Debian", 1], ["CentOS Stream", 2], ["Ubuntu", 3]')
&& str_contains($runtimeDeployScript, 'function compareTemplateVersions(left, right)')
&& str_contains($runtimeDeployScript, '(?:\\.[0-9]+){0,2}$')
&& str_contains($runtimeDeployScript,
'function updateTemplateFamilySelection(card, selectedName = "", selectedVersion = "")')
&& str_contains($runtimeDeployScript,
'container.querySelectorAll(".template-family-card[open]")')
&& str_contains($runtimeDeployScript, 'if (other !== card) other.open = false;')
&& str_contains($runtimeDeployScript,
'summary?.setAttribute("aria-label", `${family},收起版本列表`);')
&& str_contains($runtimeDeployScript,
'card.querySelector(\'.template-version-option[aria-pressed="true"]\')')
&& str_contains($runtimeDeployScript, 'option?.focus({ preventScroll: true });')
&& str_contains($catalogRenderer,
'card.setAttribute("name", `${inputId}-family`);')
&& str_contains($catalogRenderer, 'card.open = opened.has(family);')
&& str_contains($catalogRenderer,
'const orderedGroups = Array.from(groups.entries()).sort')
&& str_contains($catalogRenderer,
'entries.sort((a, b) => compareTemplateVersions(b.version, a.version)')
&& !str_contains($catalogRenderer, 'card.open = opened.has(family) ||')
&& str_contains($catalogRenderer, 'card.open = false;')
&& str_contains($catalogRenderer, 'summary.focus({ preventScroll: true });')
&& str_contains($catalogRenderer, 'const footer = makeElement("span", "template-family-footer");')
&& str_contains($catalogRenderer, 'const selectedMark = makeElement("span", "template-family-selected-mark", "✓");')
&& str_contains($catalogRenderer, 'selectedMark.setAttribute("aria-hidden", "true");')
&& str_contains($catalogRenderer, 'footer.append(selection, arrow);')
&& str_contains($catalogRenderer,
'summary.append(selectedMark, icon, makeElement("strong", "", family), footer);')
&& !str_contains($catalogRenderer, '"⌄"')
&& str_contains($catalogRenderer, 'familyCard === card ? name : "", familyCard === card ? version : "");')
&& str_contains($catalogRenderer, 'selectedEntry?.version || "");')
&& str_contains($catalogRenderer, 'card.append(summary, versions);')
&& str_contains($runtimeDeployScript,
'label.textContent = selected ? versionLabel : "";')
&& str_contains($runtimeDeployScript,
'? `${family},已选择 ${selectedName},展开更改版本`')
&& str_contains($runtimeDeployScript,
'if (event.key !== "Escape") return;')
&& str_contains($runtimeDeployScript,
'!event.target.closest(".template-family-card")')
&& substr_count($runtimeDeployScript,
'document.addEventListener("click", (event) => {') === 1
&& substr_count($runtimeDeployScript,
'document.addEventListener("keydown", (event) => {') === 1
&& substr_count($runtimeDeployScript,
'document.addEventListener("focusin", (event) => {') === 1
&& str_contains($runtimeDeployScript,
'openCard.contains(event.target)'),
'Image version menus must be single-open, dismissible, and close after selection.');
$availabilityStart = strpos($runtimeDeployScript, 'function updateCreateAvailability()');
$availabilityEnd = $availabilityStart === false ? false
: strpos($runtimeDeployScript, 'function strongPassword(', $availabilityStart);
$availability = $availabilityStart === false || $availabilityEnd === false ? ''
: substr($runtimeDeployScript, $availabilityStart, $availabilityEnd - $availabilityStart);
$assert(str_contains($availability, 'const validHost = plan')
&& str_contains($availability, "const validMedia = Boolean(byId('vm-template')?.value)")
&& !str_contains($availability, 'state.resources'),
'Deployment submission must require a matching region/plan and selected global image.');
$assert(str_contains($baseStyles, '.deployment-step')
&& str_contains($baseStyles, '.region-option')
&& str_contains($baseStyles, '.plan-option')
&& str_contains($baseStyles, '.user-iso-row'),
'Region-first deployment and personal ISO pages must retain VM-panel styling.');
$assert(!str_contains($cloudTemplate, '购买并开通') && !str_contains($sharedSidebar, '我的虚拟机'), 'Retired VM sales labels remain');
$assert(str_contains($shopFormScript, 'Array.isArray(data.hosts)'), 'Plan editor must read the hosts collection returned by the admin API');
$assert(preg_match('/<input id="template-sha256"([^>]*)>/', $templateAdmin, $shaInput) === 1
&& !str_contains($shaInput[1], 'required'), 'Cloud image SHA-256 must be optional');
$assert(str_contains($templateAdmin, 'AlmaLinux 8/9/10')
&& str_contains($templateAdmin, 'Debian 11/12/13')
&& str_contains($templateAdmin, 'CentOS Stream 9/10')
&& str_contains($templateAdmin, 'Ubuntu 20.04 至 26.04')
&& str_contains($templateAdmin, '官方 HTTPS 文件地址')
&& str_contains($templateAdmin, '通过公网安全校验的跳转链')
&& str_contains($templateAdmin, 'accept=".qcow2,application/octet-stream"')
&& str_contains($templateAdmin, '不含 backing file 的独立 QCOW2'),
'Cloud image guidance must cover every supported official distribution and file format.');
$assert(str_contains($runtimeDeployScript, 'centosstream: "CentOS Stream"')
&& str_contains($runtimeDeployScript, '"CentOS Stream": "/cloud/centos-icon.svg"')
&& str_contains($runtimeDeployScript, 'debian: "Debian"')
&& str_contains($runtimeDeployScript, 'ubuntu: "Ubuntu"')
&& str_contains($runtimeDeployScript, '/^[0-9]+(?:\\.[0-9]+){0,2}$/'),
'Cloud image family icons or dotted Ubuntu versions are not mapped correctly.');
$importStart = strpos($adminScript, 'async function importTemplate(');
$importEnd = $importStart === false ? false : strpos($adminScript, 'async function uploadRescue(', $importStart);
$importScript = $importStart === false || $importEnd === false ? ''
: substr($adminScript, $importStart, $importEnd - $importStart);
$assert(!str_contains($templateAdmin, 'catalog-host')
&& str_contains($templateAdmin, '所有可售地区共用的 cloud-init 系统镜像目录')
&& str_contains($rescueAdmin, 'id="catalog-host"')
&& str_contains($adminScript, "root.dataset.cloudAdmin === 'templates'")
&& str_contains($adminScript, "root.dataset.cloudAdmin === 'rescue'"),
'Cloud images must be global while rescue templates remain host-scoped.');
$assert(str_contains($importScript, 'if (sha256) body.sha256 = sha256;')
&& !str_contains($importScript, 'host_id')
&& !str_contains($importScript, 'catalog-host'),
'Global cloud image imports must omit blank SHA-256 and all host selectors.');
$uploadStart = strpos($adminScript, 'async function uploadCloudTemplate(');
$uploadEnd = $uploadStart === false ? false
: strpos($adminScript, 'async function uploadRescue(', $uploadStart);
$uploadScript = $uploadStart === false || $uploadEnd === false ? ''
: substr($adminScript, $uploadStart, $uploadEnd - $uploadStart);
$assert(str_contains($templateAdmin, 'id="template-upload"')
&& str_contains($templateAdmin, 'id="template-upload-system"')
&& str_contains($templateAdmin, 'id="template-upload-file"')
&& str_contains($templateAdmin, 'accept=".qcow2,application/octet-stream"')
&& str_contains($templateAdmin, '不含 backing file')
&& str_contains($templateAdmin, '最大 4 GiB'),
'Cloud template admin must offer a constrained local QCOW2 upload form.');
$assert(str_contains($uploadScript, "file.name.toLowerCase().endsWith('.qcow2')")
&& str_contains($uploadScript, '4 * 1024 ** 3')
&& str_contains($uploadScript, "os_family: osFamily")
&& str_contains($uploadScript, "os_version: osVersion")
&& str_contains($uploadScript, '/api/v1/admin/cloud-templates/upload?')
&& str_contains($adminScript, "request.setRequestHeader('Content-Type', 'application/octet-stream')")
&& str_contains($adminScript, "request.upload.addEventListener('progress'"),
'Browser QCOW2 upload must stream raw bytes with explicit metadata and progress.');
$assert(str_contains($cloudRoutes,
"'/admin/cloud-templates/upload', 'App\\Controllers\\CloudAdminController:cloudTemplateUpload'")
&& str_contains($cloudAdminController, 'public function cloudTemplateUpload(')
&& str_contains($cloudAdminController, "'/internal/v1/vm-templates/upload?name='")
&& str_contains($cloudAdminController, 'CLOUD_IMAGE_UPLOAD_MAX_BYTES')
&& str_contains($cloudAdminController, 'CloudTemplateDeletionService::queueImport(')
&& str_contains($cloudAdminController, "'upload'"),
'PHP must stream administrator QCOW2 uploads through the signed private-engine path.');
$globalAdminStart = strpos($cloudAdminController, "if (\$kind === 'cloud')");
$globalAdminEnd = $globalAdminStart === false ? false
: strpos($cloudAdminController, '// Rescue ISOs remain', $globalAdminStart);
$globalAdmin = $globalAdminStart === false || $globalAdminEnd === false ? ''
: substr($cloudAdminController, $globalAdminStart, $globalAdminEnd - $globalAdminStart);
$assert(str_contains($globalAdmin, "'/internal/v1/vm-templates'")
&& str_contains($globalAdmin, "unset(\$body['host_id'])")
&& !str_contains($globalAdmin, "filter_var(\$body['host_id']")
&& !str_contains($globalAdmin, '->host('),
'The PHP admin proxy must use the global engine catalog without a host dependency.');
$assert(str_contains($cloudRoutes, "['PATCH', 'DELETE']")
&& str_contains($adminScript, '删除全局云镜像模版')
&& str_contains($adminScript, "method: 'DELETE'")
&& str_contains($templateAdmin, '已经创建的实例使用独立克隆磁盘')
&& str_contains($globalAdmin, 'CloudTemplateDeletionService::begin')
&& str_contains($globalAdmin, 'CloudTemplateDeletionService::complete')
&& str_contains($globalAdmin, 'CloudTemplateDeletionService::queueImport')
&& str_contains($globalAdmin, 'CloudTemplateDeletionService::fetchAuthoritativeCatalog')
&& str_contains($globalAdmin, 'CloudTemplateDeletionService::reactivateImportedTemplate')
&& !str_contains($globalAdmin, 'if ($currentTemplate)')
&& str_contains($globalAdmin, 'CloudDeploymentPageService::rememberTemplateCatalog')
&& str_contains($globalAdmin,
"\$error->getMessage() === '云镜像模板不存在'")
&& str_contains($adminScript, 'created_at: Number(entry.created_at)'),
'Global cloud templates must expose a confirmed, retryable admin deletion flow.');
$assert(str_contains($cloudSchema, 'CREATE TABLE IF NOT EXISTS cloud_template_retirements')
&& str_contains($cloudSchema, 'CREATE TABLE IF NOT EXISTS cloud_template_catalog_locks')
&& str_contains($cloudSchema, 'lease_token CHAR(32)')
&& str_contains($cloudSchema, 'lease_kind VARCHAR(16)')
&& str_contains($cloudSchema, 'lease_until BIGINT UNSIGNED')
&& str_contains($cloudSchema, 'template_created_at BIGINT UNSIGNED')
&& str_contains($templateDeletionService, "'awaiting_payment', 'queued', 'running', 'uncertain'")
&& str_contains($templateDeletionService, "whereIn('kind', ['create', 'reinstall'])")
&& str_contains($templateDeletionService, 'lockForUpdate()')
&& str_contains($templateDeletionService, "where('state', 'deleting')->exists()")
&& str_contains($templateDeletionService, 'IMPORT_LEASE_SECONDS')
&& str_contains($templateDeletionService, 'reserveImport(')
&& str_contains($templateDeletionService, 'clearImportLeaseSafely(')
&& str_contains($templateDeletionService, 'assertNoActiveImportLeaseLocked(')
&& str_contains($templateDeletionService, 'reconcileAuthoritativeCatalog')
&& !str_contains($templateDeletionService, 'array_slice($templates')
&& str_contains($deploymentPageService, 'availableTemplates(')
&& str_contains($deploymentPageService,
'CloudTemplateDeletionService::fetchAuthoritativeCatalog')
&& str_contains($deploymentPageService, 'forgetTemplate('),
'Template retirement must block active provisioning/reinstall references and stale SSR catalogs.');
$assert(str_contains($adminScript, 'function unixTime(value)')
&& str_contains($adminScript, 'orderStatus(record.status)'),
'Order diagnostics must format timestamps and localize task status');
$assert(str_contains($clientScript,
"makeElement('div', 'cloud-order-actions cloud-invoice-list-actions')")
&& str_contains($clientStyles, '.cloud-orders { min-height: 0;'),
'Billing records must use grouped actions without inheriting the inventory minimum height');
$assert(str_contains($cloudTemplate, 'data-detail-tab="operations"')
&& str_contains($cloudTemplate, 'data-detail-tab="performance"')
&& str_contains($cloudTemplate, 'data-detail-tab="traffic"'),
'VM details must expose operations, performance and traffic tabs');
$assert(str_contains($clientScript, '/traffic/daily?days=30')
&& str_contains($cloudTemplate, '最近 30 天每日流量'),
'VM traffic view must load and display daily traffic history');
$assert(preg_match('/\.inventory-panel\.vm-service-panel\s*\{[^}]*min-height:\s*0;/',
$clientStyles) === 1
&& str_contains($cloudTemplate,
'class="inventory-panel vm-service-panel"'),
'The service and traffic card must size to its content without the inventory minimum-height gap');
foreach (['expired_grace', 'blocked_expired', 'deleting', 'delete_failed',
'purge_pending', 'purge_stopping', 'purge_stop_failed', 'purge_deleting',
'purge_failed'] as $lifecycleStatus) {
$assert(str_contains($clientScript, $lifecycleStatus . ':'),
'Missing user-facing lifecycle status: ' . $lifecycleStatus);
}
$assert(str_contains($sharedSidebar, 'href="/user/cloud/invoices"')
&& str_contains($cloudTemplate, 'id="invoices-workspace"')
&& str_contains($cloudTemplate, 'id="invoice-detail-workspace"')
&& str_contains($sharedSidebar, '>账单信息</span>')
&& str_contains($invoiceDetailRuntime, '/pay-balance')
&& str_contains($invoiceDetailRuntime, '/payments'),
'Unified invoices must support balance and online payment paths');
$assert(str_contains($clientEntry, "'invoice-detail': '/cloud/invoice-detail.js'")
&& str_contains($cloudShell, 'data-invoice-id=')
&& str_contains($cloudShell, "panel_cloud_active='invoices'")
&& str_contains($invoiceDetailModule, '/cloud/invoice-detail-runtime.js')
&& str_contains($invoiceDetailModule, 'readInvoiceDetailBootstrap()')
&& str_contains($invoiceDetailModule, 'hydrateInvoiceDetail(bootstrap, invoiceId)')
&& !str_contains($invoiceDetailModule, '/cloud/runtime.js')
&& !str_contains($invoiceDetailModule, '/api/v1/invoices/'),
'Invoice details must hydrate SSR data through a dedicated lightweight module.');
$assert(str_contains($clientScript, "recharge: '余额充值', provision: '实例开通', renewal: '实例续费'")
&& str_contains($clientScript, '`账单 #${invoice.id} · ${formatDate(invoice.created_at)}`')
&& str_contains($clientScript, "makeElement('div', 'cloud-invoice-list-amount')")
&& str_contains($clientScript,
'link.href = `/user/cloud/invoices/${encodeURIComponent(String(invoice.id))}`')
&& !str_contains($clientScript, 'invoice.invoice_no'),
'Invoice rows must use short database IDs, type labels, a right-aligned amount and a detail link.');
$runtimeScript = file_get_contents($public . '/runtime.js');
$invoicesModule = file_get_contents($public . '/invoices.js');
$assert(!str_contains($runtimeScript, 'function loadInvoiceDetail(')
&& !str_contains($runtimeScript, 'function renderInvoiceDetail(')
&& !str_contains($runtimeScript, 'INVOICE_PAYMENT_STORAGE_PREFIX'),
'The all-feature VM runtime must not duplicate invoice-detail behavior.');
$invoiceLoaderStart = strpos($invoicesModule, 'async function loadInvoices(');
$invoiceLoaderEnd = $invoiceLoaderStart === false ? false
: strpos($invoicesModule, 'function hydrate(', $invoiceLoaderStart);
$invoiceLoader = $invoiceLoaderStart === false || $invoiceLoaderEnd === false
? '' : substr($invoicesModule, $invoiceLoaderStart, $invoiceLoaderEnd - $invoiceLoaderStart);
$assert(str_contains($cloudTemplate, 'id="invoices-pagination"')
&& str_contains($cloudTemplate, 'id="invoices-previous"')
&& str_contains($cloudTemplate, 'id="invoices-next"')
&& str_contains($cloudTemplate, 'id="invoices-page-label"')
&& str_contains($clientStyles, '.invoice-pagination'),
'The invoice list is missing its accessible previous/next pagination controls.');
$assert(str_contains($invoiceLoader, '/api/v1/invoices?page=${encodeURIComponent(requestedPage)}')
&& str_contains($invoiceLoader, 'if (state.loading) return;')
&& str_contains($invoiceLoader,
'state.pagination = normalizePagination(payload?.pagination, requestedPage);')
&& !str_contains($invoiceLoader, 'payment_methods'),
'Invoice pagination must fetch one server page at a time without detail-only payment data.');
$assert(str_contains($invoicesModule, "byId('invoices-previous')")
&& str_contains($invoicesModule, "byId('invoices-next')")
&& str_contains($invoicesModule, 'loadInvoices(state.page + 1)')
&& str_contains($invoicesModule, 'state.loading')
&& str_contains($invoicesModule, "byId('invoices-bootstrap')")
&& !str_contains($invoicesModule, "new URL('/cloud/runtime.js'")
&& !str_contains($invoicesModule, "api('/api/v1/session')"),
'Invoice pages must hydrate the server-rendered first page and fetch only guarded later pages.');
$assert(str_contains($cloudTemplate, 'id="invoice-payment-methods"')
&& str_contains($cloudTemplate, 'id="invoice-payment-submit"')
&& str_contains($invoiceDetailRuntime, "id: 'balance'")
&& str_contains($invoiceDetailRuntime, "name: '账户余额'")
&& str_contains($invoiceDetailRuntime, "card.setAttribute('aria-pressed'")
&& str_contains($clientStyles, '.invoice-payment-method-card[aria-pressed="true"]')
&& str_contains($invoiceDetailRuntime, 'renderInvoiceSpecification(invoice)')
&& str_contains($invoiceDetailRuntime, 'renderInvoiceFulfillment(invoice)'),
'Invoice detail must isolate plan data and expose one card-based payment selector.');
$assert(str_contains($invoiceDetailRuntime, "uncertain: ['正在核对结果', 'warning']")
&& !str_contains($invoiceDetailRuntime, "'needs_attention', 'uncertain'].includes(status)")
&& str_contains($invoiceDetailRuntime, 'invoiceJobProgress: new Map()')
&& str_contains($invoiceDetailRuntime, 'job?.phase'),
'Uncertain provisioning must remain non-terminal and continue reconciliation.');
$assert(!str_contains($sharedSidebar, 'data-view="orders"')
&& !str_contains($cloudTemplate, 'id="orders-workspace"')
&& !str_contains($clientScript, 'function loadOrders()')
&& !str_contains($clientScript, "target === 'orders' || target === 'invoices'"),
'The retired user provisioning-order page and hash redirect must be absent');
$assert(str_contains($cloudTemplate, '>生成开通账单</button>')
&& str_contains($clientScript, "api('/api/v1/invoices', { method: 'POST', body })")
&& str_contains($clientScript, '/api/v1/invoices/by-request/')
&& str_contains($invoiceDetailRuntime, "invoice?.purpose")
&& str_contains($invoiceDetailRuntime, 'appendProvisionInvoiceActions(invoice, detail, actions)')
&& str_contains($invoiceDetailRuntime, "makeElement('a', 'row-button', '查看实例')"),
'Instance deployment must create a recoverable invoice and expose fulfillment inside billing');
$assert(!str_contains($cloudShell, '/theme/venix/js/qrcode.min.js')
&& str_contains($invoiceDetailRuntime, "document.createElement('script')")
&& str_contains($invoiceDetailRuntime, '/theme/venix/js/qrcode.min.js')
&& str_contains($invoiceDetailRuntime, "'weixin:', 'alipays:', 'alipayqr:'")
&& str_contains($invoiceDetailRuntime,
'void appendPaymentQr(box, qrValue, generation)'),
'Invoice online payments must lazy-load local QR rendering after creating a payment order.');
$assert(str_contains($invoiceDetailRuntime, 'INVOICE_PAYMENT_STORAGE_PREFIX')
&& str_contains($invoiceDetailRuntime, 'pendingInvoicePaymentKey(invoice.id, method.id)'),
'Invoice provider orders must reuse a session-scoped idempotency key after lost responses');
$assert(str_contains($invoiceDetailRuntime, 'function invoiceNeedsPolling(')
&& str_contains($invoiceDetailRuntime,
'api(`/api/v1/invoices/${encodeURIComponent(state.pollInvoiceId)}/status`')
&& str_contains($invoiceDetailRuntime, 'stopInvoicePoll();')
&& !str_contains($invoiceDetailRuntime, 'setInterval(')
&& substr_count($invoiceDetailRuntime,
"container.querySelectorAll('button').forEach(button => { button.disabled = false; });") >= 2,
'Active invoice polling must use the lightweight status endpoint and remain recoverable.');
$assert(!str_contains($invoiceDetailRuntime, '/api/v1/jobs/')
&& str_contains($invoiceDetailRuntime, "actionButton('查看创建进度'")
&& str_contains($invoiceDetailRuntime,
'/api/v1/invoices/${encodeURIComponent(invoice.id)}/status'),
'Invoice creation progress must not load the general job payload or a cloud session.');
$assert(str_contains($invoiceDetailRuntime, 'function invoiceDeletionTimestamp(invoice)')
&& str_contains($invoiceDetailRuntime, 'invoice?.deletion_at')
&& str_contains($invoiceDetailRuntime, 'function invoiceCanPay(invoice)')
&& substr_count($invoiceDetailRuntime, 'if (!invoiceCanPay(invoice))') >= 2
&& str_contains($invoiceDetailRuntime, 'panel.hidden = true;')
&& str_contains($invoiceDetailRuntime, 'container.replaceChildren();')
&& str_contains($invoiceDetailRuntime, '已超过支付截止时间'),
'Invoice UI must show the deletion deadline and hide every payment path after the cutoff');
$assert(str_contains($invoiceDetailRuntime, 'status >= 400 && status < 500')
&& str_contains($invoiceDetailRuntime, 'const ambiguousHttpFailure = [408, 425, 429].includes(status)')
&& str_contains($invoiceDetailRuntime, 'pendingInvoicePaymentKey(invoice.id, method.id)'),
'Ambiguous 5xx or transport failures must retain the provider idempotency key');
$assert(!str_contains($clientScript, '/renewals')
&& !str_contains($cloudTemplate, '续费周期'),
'Retired direct-renewal controls must not remain in the user UI');
$assert(str_contains($cloudAdminController, "'known_owners' => (object) CloudInstanceDiscovery::knownOwners"),
'Empty VM ownership maps must be encoded as a JSON object for engine discovery');
foreach (['hosts/index.tpl', 'cloud/instances.tpl', 'cloud/rescue.tpl', 'cloud/templates.tpl'] as $template) {
$source = file_get_contents($views . '/admin/' . $template);
$assert(str_contains($source, '/cloud/admin.js?v={$venix_asset_version}'),
'Cloud admin script cache busting missing: ' . $template);
}
$adminBillingSource = file_get_contents($adminBillingTemplate);
$assert(str_contains($adminBillingSource,
'/cloud/admin-billing.js?v={$venix_asset_version}')
&& str_contains($adminBillingSource, "{include file='admin/static_footer.tpl'}")
&& !str_contains($adminBillingSource, '/cloud/admin-billing.css')
&& !is_file($adminBillingStyles)
&& str_contains($adminBillingSource, 'admin-billing-summary')
&& preg_match_all('/<article class="[^"]*\badmin-billing-stat\b/', $adminBillingSource) === 4
&& !str_contains($adminBillingSource, 'admin-ticket-stat h-100')
&& str_contains($adminBillingSource, 'admin-checkout-table')
&& str_contains($adminBillingSource, 'admin-modal-panel'),
'Unified administrator billing must reuse Venix admin styles and version its functional script');
$billingIds = [
'billing-notice', 'billing-refresh', 'billing-summary', 'billing-summary-total',
'billing-summary-amount-label', 'billing-summary-amount', 'billing-summary-focus-label',
'billing-summary-focus', 'billing-summary-result-label', 'billing-summary-result',
'billing-filter-title', 'billing-filter-form', 'billing-query', 'billing-user-id',
'billing-status-primary-field', 'billing-status-primary-label', 'billing-status-primary',
'billing-status-secondary-field', 'billing-status-secondary-label', 'billing-status-secondary',
'billing-category-field', 'billing-category-label', 'billing-category',
'billing-reference-field', 'billing-reference-label', 'billing-reference-select',
'billing-reference-input', 'billing-created-from', 'billing-created-to', 'billing-per-page',
'billing-apply', 'billing-reset', 'billing-panel', 'billing-view-heading',
'billing-view-description', 'billing-result-count', 'billing-table',
'billing-table-caption', 'billing-table-head', 'billing-table-body', 'billing-pagination',
'billing-previous', 'billing-page-label', 'billing-next', 'billing-detail-dialog',
'billing-detail-close', 'billing-detail-title', 'billing-detail-state', 'billing-detail-body',
];
foreach ($billingIds as $billingId) {
$assert(substr_count($adminBillingSource, 'id="' . $billingId . '"') === 1,
'Unified administrator billing hook missing or duplicated: ' . $billingId);
}
$assert(str_contains($adminBillingSource, '<main data-admin-billing>')
&& substr_count($adminBillingSource, 'data-billing-view=') === 3
&& str_contains($adminBillingSource, 'admin-billing-filter-actions')
&& str_contains($adminSharedStyles, '.admin-billing-summary .admin-billing-stat-value')
&& str_contains($adminSharedStyles, '.admin-billing-filter-actions')
&& str_contains($adminBillingRuntime, "document.querySelector('[data-admin-billing]')")
&& str_contains($adminBillingRuntime, "document.querySelectorAll('[data-billing-view]')")
&& str_contains($adminBillingRuntime, 'button.dataset.invoiceId')
&& str_contains($adminBillingRuntime, 'cell.dataset.label'),
'Unified administrator billing data hooks must remain aligned with its runtime');
$billingMobileStyles = strstr($adminSharedStyles, '@media (max-width: 575.98px)');
$assert($billingMobileStyles !== false
&& preg_match('/\[data-admin-billing\] \.form-control,\s*\[data-admin-billing\] \.form-select\s*\{(?=[^}]*min-height:\s*44px)(?=[^}]*font-size:\s*16px)[^}]*\}/s', $billingMobileStyles)
&& preg_match('/\[data-admin-billing\] \.btn,\s*\.admin-ticket-tabs a\s*\{[^}]*min-height:\s*44px/s', $billingMobileStyles),
'Administrator billing controls must remain zoom-safe and touch-friendly on phones');
$assert(preg_match('/\.admin-billing-dialog \.admin-modal-close\s*\{(?=[^}]*width:\s*44px)(?=[^}]*height:\s*44px)[^}]*\}/s', $adminSharedStyles)
&& preg_match('/\.admin-checkout-user\s*\{[^}]*min-width:\s*0/s', $adminSharedStyles)
&& preg_match('/\.admin-checkout-user strong,\s*\.admin-checkout-user span\s*\{[^}]*overflow-wrap:\s*anywhere/s', $adminSharedStyles),
'Administrator billing dialog controls and long table values must remain usable on narrow screens');
$assert(str_contains($adminBillingSource, '<header class="d-flex align-items-start justify-content-between')
&& str_contains($adminBillingSource, 'admin-modal-close position-static flex-shrink-0')
&& preg_match('/\.admin-billing-dialog-panel\s*\{(?=[^}]*display:\s*flex)(?=[^}]*flex-direction:\s*column)(?=[^}]*overflow:\s*hidden)[^}]*\}/s', $adminSharedStyles)
&& preg_match('/\.admin-billing-dialog-body\s*\{(?=[^}]*min-height:\s*0)(?=[^}]*overflow-y:\s*auto)(?=[^}]*overflow-wrap:\s*anywhere)[^}]*\}/s', $adminSharedStyles)
&& str_contains($adminBillingRuntime, "dialog.addEventListener('close'")
&& str_contains($adminBillingRuntime, "document.body.classList.remove('billing-detail-open')")
&& str_contains($adminBillingRuntime, 'opener.focus({ preventScroll: true })'),
'Administrator billing detail must keep its close action visible and restore page state after scrolling');
$assert(!preg_match('/text-bg-(?:success|info|warning|danger)/', $adminBillingRuntime)
&& str_contains($adminBillingRuntime, 'bg-success-subtle text-success-emphasis')
&& str_contains($adminBillingRuntime, 'bg-warning-subtle text-warning-emphasis')
&& str_contains($adminBillingRuntime, 'bg-danger-subtle text-danger-emphasis')
&& str_contains($adminBillingRuntime, 'bg-info-subtle text-info-emphasis'),
'Administrator billing status badges must retain readable semantic colors');
foreach (glob($views . '/user/*.tpl') as $template) {
$source = file_get_contents($template);
$assert(!str_contains($source, 'href="/user/shop"'), 'Obsolete package link remains: ' . basename($template));
$assert(!str_contains($source, 'href="/user"'), 'Ambiguous user-home link remains: ' . basename($template));
}
$assert(str_contains($sharedTopbar, 'panel-topbar') && str_contains($sharedTopbar, 'breadcrumb-current'), 'Shared topbar contract missing');
$assert(!str_contains(file_get_contents($root . '/.gitignore'), "\nvendor/"), 'Nested noVNC vendor directory would be omitted from Git');
echo 'Unified user styles, local icons and noVNC source modules passed: ' . count($seen) . " modules.\n";