From 3f9d3d2d63bed05c539f8212de3e91cff3eb0735 Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 4 Oct 2026 18:46:07 +0800 Subject: [PATCH] feat: add inline instance display-name editing --- web/app/Controllers/CloudApiController.php | 14 ++ web/app/Controllers/CloudPageController.php | 1 + web/app/Middleware/CloudApi.php | 1 + .../Cloud/CloudInstanceNameService.php | 45 ++++++ .../Cloud/CloudInstancePageService.php | 3 + web/app/Services/Cloud/CloudWorkerService.php | 10 +- web/config/routes_cloud.php | 1 + web/public/cloud/detail.js | 110 ++++++++++++++- web/public/cloud/instances.js | 10 +- web/public/cloud/runtime.js | 2 +- web/public/cloud/styles.css | 3 +- .../views/venix/cloud/pages/detail.tpl | 4 +- web/resources/views/venix/layout_assets.tpl | 2 +- web/tests/CloudInstanceNameServiceTest.php | 128 ++++++++++++++++++ web/tests/CloudInstancePageServiceTest.php | 8 +- .../CloudInstancePageSsrContractTest.php | 24 +++- web/tests/CloudSessionSecurityTest.php | 24 ++++ web/tests/VirtualizationAssetsTest.php | 12 ++ 18 files changed, 386 insertions(+), 16 deletions(-) create mode 100644 web/app/Services/Cloud/CloudInstanceNameService.php create mode 100644 web/tests/CloudInstanceNameServiceTest.php diff --git a/web/app/Controllers/CloudApiController.php b/web/app/Controllers/CloudApiController.php index bce5f44f..8ae9417e 100644 --- a/web/app/Controllers/CloudApiController.php +++ b/web/app/Controllers/CloudApiController.php @@ -17,6 +17,7 @@ use App\Services\Cloud\CloudEngineClient; use App\Services\Cloud\CloudError; use App\Services\Cloud\CloudInput; use App\Services\Cloud\CloudInstanceMetadata; +use App\Services\Cloud\CloudInstanceNameService; use App\Services\Cloud\CloudInstancePageService; use App\Services\Cloud\CloudInstanceRuntimeService; use App\Services\Cloud\CloudJobService; @@ -689,6 +690,7 @@ final class CloudApiController 'is_owner' => $owner, 'can_operate' => $canOperate, 'can_delete' => $canDelete, + 'can_rename' => $canDelete, 'can_view_credential' => $owner || $global, 'can_renew' => $lifecycleActive && $owner && $instance->expires_at !== null && (int) $instance->renewal_days > 0 @@ -955,6 +957,18 @@ final class CloudApiController return $this->json($response, $this->vmData(CloudAccess::instance($args['id'], $actor), $actor)); } + /** Rename only the PHP-owned display label; no engine operation is sent. */ + public function displayName($request, $response, $args) + { + $body = CloudInput::object($request); + CloudInput::only($body, ['name']); + return $this->json($response, CloudInstanceNameService::rename( + $args['id'] ?? null, + $this->actor($request), + $body['name'] ?? null + )); + } + public function operationLogs($request, $response, $args) { $actor = $this->actor($request); diff --git a/web/app/Controllers/CloudPageController.php b/web/app/Controllers/CloudPageController.php index ec829aca..f592c857 100644 --- a/web/app/Controllers/CloudPageController.php +++ b/web/app/Controllers/CloudPageController.php @@ -761,6 +761,7 @@ final class CloudPageController && (string) ($vm['os_source'] ?? '') === 'cloud_template', 'guest_hostname' => trim((string) ($vm['guest_hostname'] ?? '')) ?: '未记录', 'can_delete' => (bool) ($vm['can_delete'] ?? false), + 'can_rename' => (bool) ($vm['can_rename'] ?? false), 'service_status_label' => $serviceLabel, 'service_status_class' => $serviceClass, 'network_status_label' => $networkLabel, diff --git a/web/app/Middleware/CloudApi.php b/web/app/Middleware/CloudApi.php index 49aab4cf..ea322003 100644 --- a/web/app/Middleware/CloudApi.php +++ b/web/app/Middleware/CloudApi.php @@ -24,6 +24,7 @@ final class CloudApi || preg_match('#^/api/v1/admin/hosts/[0-9]+/(?:scheduling|capacity-sync)$#D', $path) === 1 || preg_match('#^/api/v1/ssh-keys(?:/|$)#D', $path) === 1 || preg_match('#^/api/v1/vms/[0-9]+/operations$#D', $path) === 1 + || preg_match('#^/api/v1/vms/[0-9]+/display-name$#D', $path) === 1 || $path === '/api/v1/announcements' || $path === '/api/v1/vms/page' // The normal list status poll reads only cloud_instance_runtime. diff --git a/web/app/Services/Cloud/CloudInstanceNameService.php b/web/app/Services/Cloud/CloudInstanceNameService.php new file mode 100644 index 00000000..13ebb26c --- /dev/null +++ b/web/app/Services/Cloud/CloudInstanceNameService.php @@ -0,0 +1,45 @@ +status !== 'active') { + throw new CloudError('当前实例状态不允许修改名称', 409); + } + + $initialName = (string) $instance->name; + return $instance->getConnection()->transaction(static function () use ( + $instance, $initialName, $name + ): array { + // Compare under a row lock in PHP. The production column uses a + // case-insensitive collation, so a SQL name predicate cannot be a + // safe compare-and-swap guard for case-preserving display names. + $current = CloudInstance::where('id', (int) $instance->id) + ->where('uuid', (string) $instance->uuid) + ->where('user_id', (int) $instance->user_id) + ->lockForUpdate() + ->first(['id', 'name', 'status']); + if ($current === null || (string) $current->status !== 'active') { + throw new CloudError('实例状态已变化,请刷新后重试', 409); + } + $currentName = (string) $current->name; + if (hash_equals($currentName, $name)) { + return ['id' => (string) $current->id, 'name' => $name]; + } + if (!hash_equals($currentName, $initialName)) { + throw new CloudError('实例名称已变化,请刷新后重试', 409); + } + $current->name = $name; + $current->updated_at = time(); + $current->save(); + return ['id' => (string) $current->id, 'name' => $name]; + }); + } +} diff --git a/web/app/Services/Cloud/CloudInstancePageService.php b/web/app/Services/Cloud/CloudInstancePageService.php index 477249ba..a380b9f1 100644 --- a/web/app/Services/Cloud/CloudInstancePageService.php +++ b/web/app/Services/Cloud/CloudInstancePageService.php @@ -142,6 +142,7 @@ final class CloudInstancePageService 'is_owner' => $owner, 'can_operate' => $canDelete && $instance->serviceAvailable(), 'can_delete' => $canDelete, + 'can_rename' => $canDelete, ]; } @@ -258,6 +259,7 @@ final class CloudInstancePageService 'is_owner' => (bool) $snapshot['is_owner'], 'can_operate' => (bool) $snapshot['can_operate'], 'can_delete' => (bool) $snapshot['can_delete'], + 'can_rename' => (bool) $snapshot['can_rename'], ]; } @@ -549,6 +551,7 @@ final class CloudInstancePageService 'is_owner' => $owner, 'can_operate' => $canOperate, 'can_delete' => $canDelete, + 'can_rename' => $canDelete, 'can_view_credential' => $owner || $global, 'can_renew' => $lifecycleActive && $owner && $instance->expires_at !== null diff --git a/web/app/Services/Cloud/CloudWorkerService.php b/web/app/Services/Cloud/CloudWorkerService.php index 3f1ede54..2163ba5e 100644 --- a/web/app/Services/Cloud/CloudWorkerService.php +++ b/web/app/Services/Cloud/CloudWorkerService.php @@ -516,7 +516,9 @@ final class CloudWorkerService '引擎成功结果与预留公网 IP 不一致,必须人工核查', 502 ); } - $instance = CloudInstance::where('order_id', $order->id)->first() ?? new CloudInstance(); + $instance = CloudInstance::where('order_id', $order->id)->first(); + $newInstance = $instance === null; + $instance ??= new CloudInstance(); $instance->uuid = $uuid; $instance->host_id = $order->host_id; $instance->user_id = $order->user_id; @@ -533,7 +535,11 @@ final class CloudWorkerService $traffic = $billingSnapshot ? max(0, (int) $spec['traffic_quota_bytes']) : 0; $instance->plan_id = $order->plan_id; - $instance->name = $payload['body']['name']; + // A late/replayed create result must not overwrite a display + // name the owner changed after the first success committed. + if ($newInstance) { + $instance->name = $payload['body']['name']; + } $instance->status = 'active'; // Orders submitted by a pre-billing release do not contain an // immutable term/quota snapshot. Never invent a 30-day expiry diff --git a/web/config/routes_cloud.php b/web/config/routes_cloud.php index 933d9b65..86f22855 100644 --- a/web/config/routes_cloud.php +++ b/web/config/routes_cloud.php @@ -34,6 +34,7 @@ $app->group('/api/v1', function () { $this->get('/vms/{id:[0-9]+}/metadata', 'App\Controllers\CloudApiController:vmMetadataOne'); $this->get('/vms/{id:[0-9]+}/status', 'App\Controllers\CloudApiController:vmStatus'); $this->get('/vms/{id:[0-9]+}/operations', 'App\Controllers\CloudApiController:operationLogs'); + $this->patch('/vms/{id:[0-9]+}/display-name', 'App\Controllers\CloudApiController:displayName'); $this->get('/vms', 'App\Controllers\CloudApiController:vms'); $this->get('/vms/{id}', 'App\Controllers\CloudApiController:vm'); $this->get('/vms/{id}/metrics', 'App\Controllers\CloudApiController:metrics'); diff --git a/web/public/cloud/detail.js b/web/public/cloud/detail.js index f7706f8c..806ccb55 100644 --- a/web/public/cloud/detail.js +++ b/web/public/cloud/detail.js @@ -11,7 +11,7 @@ const { } = await import(runtimeUrl.href); const VM_METADATA_FIELDS = Object.freeze([ - 'name', 'region', 'location', 'created_at', 'os_source', 'os_name', + 'region', 'location', 'created_at', 'os_source', 'os_name', 'install_iso', 'guest_hostname', 'public_ip_cidr', 'public_ip', 'login_name', 'vcpu', 'cpu_cores', 'memory_mib', 'ram_mib', 'disks', 'disk_gib', 'engine_metadata_version', @@ -22,6 +22,113 @@ let operationLogsRequest = null; let operationLogsLoadedVmId = null; let operationLogsPage = 1; let operationLogsPageCount = 1; +let displayNameSaving = false; +let displayNameStatusTimer = null; +const DISPLAY_NAME_PATTERN = /^[A-Za-z0-9][A-Za-z0-9_.-]{0,62}$/; + +function setDisplayNameStatus(message = '', kind = '') { + const status = byId('vm-detail-name-status'); + if (!status) return; + window.clearTimeout(displayNameStatusTimer); + displayNameStatusTimer = null; + status.textContent = message; + status.className = `vm-detail-name-status${kind ? ` ${kind}` : ''}`; + status.hidden = !message; +} + +function setDisplayNameEditing(editing) { + const display = byId('vm-detail-name-display'); + const form = byId('vm-detail-name-form'); + const trigger = byId('vm-detail-name-trigger'); + if (!display || !form || !trigger) return; + display.hidden = editing; + form.hidden = !editing; + trigger.setAttribute('aria-expanded', editing ? 'true' : 'false'); + if (editing) { + const input = byId('vm-detail-name-input'); + input.value = String(selectedVm()?.name || ''); + setDisplayNameStatus(); + window.requestAnimationFrame(() => { input.focus(); input.select(); }); + } +} + +function bindDisplayNameEditor(vmId) { + const trigger = byId('vm-detail-name-trigger'); + const form = byId('vm-detail-name-form'); + const input = byId('vm-detail-name-input'); + const save = byId('vm-detail-name-save'); + const cancel = byId('vm-detail-name-cancel'); + if (!trigger || !form || !input || !save || !cancel) return; + + trigger.addEventListener('click', () => setDisplayNameEditing(true)); + cancel.addEventListener('click', () => { + if (displayNameSaving) return; + setDisplayNameEditing(false); + setDisplayNameStatus(); + trigger.focus(); + }); + input.addEventListener('keydown', event => { + if (event.key !== 'Escape' || displayNameSaving) return; + event.preventDefault(); + setDisplayNameEditing(false); + setDisplayNameStatus(); + trigger.focus(); + }); + form.addEventListener('submit', async event => { + event.preventDefault(); + if (displayNameSaving) return; + const name = input.value.trim(); + if (!DISPLAY_NAME_PATTERN.test(name)) { + setDisplayNameStatus('名称需以英文或数字开头,可包含英文、数字、点、下划线和连字符,最多 63 个字符。', 'error'); + input.focus(); + return; + } + const vm = selectedVm(); + if (!vm) { + setDisplayNameStatus('实例信息已失效,请刷新页面后重试。', 'error'); + return; + } + if (name === String(vm.name || '')) { + setDisplayNameEditing(false); + trigger.focus(); + return; + } + + displayNameSaving = true; + save.disabled = true; + cancel.disabled = true; + input.disabled = true; + save.textContent = '保存中…'; + setDisplayNameStatus('正在保存名称…'); + try { + const result = await api(`/api/v1/vms/${encodeURIComponent(vmId)}/display-name`, { + method: 'PATCH', body: { name }, + }); + if (!result || typeof result.name !== 'string' + || !DISPLAY_NAME_PATTERN.test(result.name)) { + throw new Error('服务返回的实例名称无效,请刷新页面确认。'); + } + const current = selectedVm(); + if (current && String(current.api_id) === String(vmId)) current.name = result.name; + byId('vm-detail-name-value').textContent = result.name; + input.value = result.name; + setDisplayNameEditing(false); + setDisplayNameStatus('名称已保存。', 'success'); + trigger.focus(); + void loadVmStatus(vmId, { force: true }); + displayNameStatusTimer = window.setTimeout(() => setDisplayNameStatus(), 2600); + } catch (error) { + setDisplayNameStatus(error?.message || '名称保存失败,请稍后重试。', 'error'); + window.requestAnimationFrame(() => input.focus()); + } finally { + displayNameSaving = false; + save.disabled = false; + cancel.disabled = false; + input.disabled = false; + save.textContent = '保存'; + } + }); +} const OPERATION_STATUS_LABELS = Object.freeze({ queued: ['排队中', 'queued'], running: ['执行中', 'running'], @@ -470,6 +577,7 @@ export async function initialize() { if (operationLogsPage < operationLogsPageCount) void loadOperationLogs(vmId, true, operationLogsPage + 1); }); bindDetailTabs(vmId); + bindDisplayNameEditor(vmId); bindInstanceSettings(vmId); bindConsole(); window.addEventListener('resize', () => { diff --git a/web/public/cloud/instances.js b/web/public/cloud/instances.js index a0bb0aa8..bf703d4a 100644 --- a/web/public/cloud/instances.js +++ b/web/public/cloud/instances.js @@ -417,7 +417,7 @@ function vmMatchesUpdate(vm, update) { } const VM_METADATA_FIELDS = Object.freeze([ - 'name', 'region', 'location', 'os_source', 'os_name', 'install_iso', + 'region', 'location', 'os_source', 'os_name', 'install_iso', 'public_ip_cidr', 'public_ip', 'login_name', 'vcpu', 'cpu_cores', 'memory_mib', 'ram_mib', 'disks', 'disk_gib', 'engine_metadata_version', ]); @@ -477,6 +477,7 @@ async function refreshMetadata() { function applyStatuses(payload) { const updates = statusItems(payload); let statusFilterChanged = false; + let displayNameChanged = false; for (const update of updates) { const vm = state.vms.find(item => vmMatchesUpdate(item, update)); if (!vm) continue; @@ -485,6 +486,7 @@ function applyStatuses(payload) { const hasState = candidateState !== '' && normalizedState !== 'unknown' && normalizedState !== 'nostate'; const previousCategory = stateCategoryForVm(vm); + const previousName = String(vm.name || ''); const liveState = update?.live_state_available === true; const nextState = hasState ? candidateState : vm.state; const nextSync = firstText(update.state_sync_status, update.sync_status, @@ -500,6 +502,7 @@ function applyStatuses(payload) { state_label_hint: Object.prototype.hasOwnProperty.call(update, 'state_label_hint') ? firstText(update.state_label_hint) : vm.state_label_hint, }); + if (String(vm.name || '') !== previousName) displayNameChanged = true; const nextCategory = stateCategoryForVm(vm); if (previousCategory !== nextCategory) { if (previousCategory === 'running') state.stats.running = Math.max(0, state.stats.running - 1); @@ -534,7 +537,10 @@ function applyStatuses(payload) { } state.liveStatsReady = state.vms.length === 0 || state.vms.every(runtimeStateReady); renderStats(); - if (statusFilterChanged && (byId('state-filter')?.value || 'all') !== 'all') renderVms(); + if (displayNameChanged + || (statusFilterChanged && (byId('state-filter')?.value || 'all') !== 'all')) { + renderVms(); + } } async function refreshStatuses(scheduleNext = true) { diff --git a/web/public/cloud/runtime.js b/web/public/cloud/runtime.js index 5ac4aa68..802655bf 100644 --- a/web/public/cloud/runtime.js +++ b/web/public/cloud/runtime.js @@ -312,7 +312,7 @@ function powerTransition(vm) { } function renderVmDetail(vm) { const display = detailStateDisplay(vm); - text('vm-detail-name', vm.name); text('vm-detail-state', display.label); byId('vm-detail-state').className = `state-pill ${display.category}`; + text('vm-detail-name-value', vm.name); text('vm-detail-state', display.label); byId('vm-detail-state').className = `state-pill ${display.category}`; const syncElement = byId('vm-detail-state-sync'); if (syncElement) { syncElement.textContent = display.note; diff --git a/web/public/cloud/styles.css b/web/public/cloud/styles.css index 3defa66a..c9fc1d9c 100644 --- a/web/public/cloud/styles.css +++ b/web/public/cloud/styles.css @@ -130,6 +130,7 @@ tbody tr:hover{background:#fcfefe} .empty-state{text-align:center;padding:65px 20px 72px}.empty-icon{margin:0 auto 16px;width:54px;height:54px;display:flex;align-items:center;justify-content:center;border-radius:16px;background:#eaf7f7;color:#17a3aa;font-size:28px}.empty-state h3{font-size:16px;color:#34465a;margin:0 0 8px}.empty-state p{font-size:12px;color:#a0aebe;margin:0} .footer-note{text-align:right;color:#a9b4c0;font-size:10px;margin-top:18px} .vm-detail-back{padding-left:0;margin-bottom:22px;color:#267b86}.vm-detail-heading{align-items:center}.vm-detail-heading .heading-actions{align-items:center}.vm-detail-heading .state-pill{min-height:31px}.vm-detail-summary{display:flex;align-items:center;flex-wrap:wrap;gap:5px 18px}.vm-detail-summary span{white-space:nowrap}.vm-detail-summary strong{color:#455a70;font-weight:700;margin-left:4px}.vm-detail-tabs{display:flex;width:max-content;max-width:100%;gap:4px;margin:0 0 18px;padding:5px;overflow-x:auto;border:1px solid #dfeaec;border-radius:11px;background:#f3f8f9}.vm-detail-tab{min-height:39px;padding:9px 18px;border:0;border-radius:8px;background:transparent;color:#718497;font:inherit;font-size:12px;font-weight:800;white-space:nowrap;cursor:pointer}.vm-detail-tab:hover{color:#237f88;background:#e8f4f4}.vm-detail-tab.active{background:#fff;color:#157f88;box-shadow:0 2px 9px rgba(27,71,87,.1)}.vm-detail-tab:focus-visible{outline:2px solid #25adb4;outline-offset:2px}.vm-detail-grid{display:grid;grid-template-columns:minmax(0,1.15fr) minmax(320px,.85fr);gap:18px;align-items:start}.vm-detail-panel{min-height:0}.vm-detail-facts{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:0;margin:0;padding:6px 24px 17px}.vm-detail-facts>div{min-width:0;padding:17px 9px 17px 0;border-bottom:1px solid #edf1f5}.vm-detail-facts dt{font-size:11px;font-weight:700;color:#91a0af;margin-bottom:9px}.vm-detail-facts dd{margin:0;color:#273c52;font-size:13px;font-weight:700;line-height:1.5;overflow-wrap:anywhere}.vm-detail-operations{display:grid;gap:18px}.vm-detail-actions{display:flex;flex-wrap:wrap;gap:10px;padding:20px 24px 23px}.vm-detail-actions .row-button{min-height:39px;padding:9px 15px;border-color:#dce9ea;font-size:12px}.vm-detail-actions .row-button.primary{border-color:#cbecee}.vm-danger-panel .panel-heading h2{color:#a4434f}.vm-danger-panel .row-button.danger{border-color:#f2dfe2;background:#fff9f9}.vm-danger-panel .row-button.danger:not(:disabled):hover{background:#ffedef} +.vm-detail-name-control{position:relative;width:max-content;max-width:min(100%,680px)}.vm-detail-name-display{position:relative;display:flex;align-items:center;width:max-content;max-width:100%}.vm-detail-name-display h1{min-width:0;max-width:100%}.vm-detail-name-trigger{display:flex;align-items:center;gap:9px;min-width:0;max-width:100%;padding:0;border:0;background:transparent;color:inherit;font:inherit;font-weight:inherit;letter-spacing:inherit;text-align:left;cursor:pointer}.vm-detail-name-trigger:hover #vm-detail-name-value{color:#167f88}.vm-detail-name-trigger:focus-visible{outline:2px solid #25adb4;outline-offset:5px;border-radius:4px}.vm-detail-name-trigger #vm-detail-name-value{min-width:0;overflow-wrap:anywhere;transition:color .15s ease}.vm-detail-name-bubble{display:grid;place-items:center;flex:0 0 23px;width:23px;height:23px;border:1px solid #d5e6e8;border-radius:50%;background:#f3f9f9;color:#218b94;font-size:13px;transition:border-color .15s ease,background-color .15s ease}.vm-detail-name-trigger:hover .vm-detail-name-bubble,.vm-detail-name-trigger:focus-visible .vm-detail-name-bubble{border-color:#8ccdd1;background:#e7f6f6}.vm-detail-name-tooltip{position:absolute;z-index:20;top:calc(100% - 2px);left:100%;width:max-content;max-width:220px;padding:7px 10px;border:1px solid #d8e6e9;border-radius:8px;background:#29475b;color:#fff;font-size:10px;font-weight:700;line-height:1.4;box-shadow:0 8px 20px rgba(27,58,75,.16);opacity:0;pointer-events:none;transform:translate(-18px,7px);transition:opacity .15s ease,transform .15s ease}.vm-detail-name-display:hover .vm-detail-name-tooltip,.vm-detail-name-display:focus-within .vm-detail-name-tooltip{opacity:1;transform:translate(-18px,3px)}.vm-detail-name-form{display:flex;align-items:center;gap:8px;margin:9px 0 8px}.vm-detail-name-form input{width:min(360px,calc(100vw - 230px));min-width:180px;height:40px;margin:0;font-size:15px;font-weight:750}.vm-detail-name-form .button{flex:none}.vm-detail-name-status{margin:-2px 0 8px;color:#6b8190;font-size:10px;line-height:1.5}.vm-detail-name-status.success{color:#21785b}.vm-detail-name-status.error{color:#b13f4d} .vm-detail-inline,.vm-ip-copy-row{display:flex;align-items:center;flex-wrap:wrap;gap:7px}.vm-detail-inline{min-height:25px}.vm-detail-secret{font:600 12px/1.5 ui-monospace,SFMono-Regular,Menlo,monospace;overflow-wrap:anywhere}.vm-detail-mini-button,.vm-copy-icon{display:inline-flex;align-items:center;justify-content:center;flex:none;border:1px solid #d9e9ea;border-radius:6px;background:#f5fbfb;color:#1b8790;font-size:11px;font-weight:700;min-height:25px;padding:3px 7px}.vm-detail-mini-button:not(:disabled):hover,.vm-copy-icon:not(:disabled):hover{background:#e6f6f7;border-color:#b6dcdf}.vm-copy-icon{width:25px;padding:3px}.vm-copy-icon svg{display:block;width:15px;height:15px;fill:none;stroke:currentColor;stroke-width:1.8;stroke-linecap:round;stroke-linejoin:round} .vm-operation-log-view .panel-heading{align-items:center}.vm-operation-log-status{margin:0;padding:13px 24px;border-top:1px solid #edf1f5;background:#f7fbfc;color:#6f8496;font-size:12px;line-height:1.5}.vm-operation-log-status.warning{color:#a56c24;background:#fff8eb}.vm-operation-log-table{overflow-x:auto}.vm-operation-log-row{display:grid;grid-template-columns:minmax(120px,1fr) minmax(180px,1.35fr) minmax(75px,auto);align-items:center;gap:18px;padding:14px 24px;border-top:1px solid #edf1f5;color:#536b7e;font-size:12px}.vm-operation-log-header{border-top:0;background:#f7fbfc;color:#8a9baa;font-size:10px;font-weight:800;letter-spacing:.04em}.vm-operation-log-cell{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.vm-operation-log-cell.operation{color:#2c465a;font-weight:800}.vm-operation-log-cell.result{justify-self:end;overflow:visible;padding:5px 10px;border-radius:999px;background:#f1f4f6;color:#738495;font-size:11px;font-weight:800}.vm-operation-log-cell.result.queued,.vm-operation-log-cell.result.running{background:#eaf8f8;color:#21848c}.vm-operation-log-cell.result.succeeded{background:#eaf8f1;color:#23845d}.vm-operation-log-cell.result.failed{background:#fff0f1;color:#b34b57}.vm-operation-log-cell.result.uncertain{background:#fff7e9;color:#9a6a22}.vm-operation-log-footer{display:flex;align-items:center;justify-content:space-between;gap:12px;padding:14px 24px;border-top:1px solid #edf1f5;color:#7b8e9e;font-size:11px}.vm-operation-log-footer nav{display:flex;align-items:center;gap:8px}.vm-operation-log-footer .button{min-height:30px;padding:5px 10px;font-size:11px}.vm-operation-log-footer nav>span{min-width:42px;text-align:center;color:#536b7e;font-weight:700}.vm-operation-log-empty{margin:0;padding:24px;color:#8a9aa8;font-size:12px;text-align:center} .vm-credential-icon{width:30px;min-height:30px}.vm-credential-icon svg{width:17px;height:17px}.vm-credential-icon .vm-eye-slash{visibility:hidden}.vm-credential-icon[aria-pressed="true"] .vm-eye-slash{visibility:visible} @@ -180,7 +181,7 @@ tbody tr:hover{background:#fcfefe} @media(max-width:510px){.workspace-form-body{padding:22px 19px 25px}.workspace-form-actions{padding:15px 19px}.workspace-form-actions .button{flex:1 1 100%}.workspace-form-back{margin-bottom:10px}} @media(max-width:510px){.register-code-row{flex-wrap:wrap}.register-code-row input{flex-basis:100%}.register-code-row .button{width:100%}.pending-user-row{align-items:flex-start;flex-direction:column}.pending-user-row .button{width:100%}.smtp-card .form-grid{grid-template-columns:1fr}} @media(max-width:510px){.ssh-key-row{align-items:flex-start;flex-direction:column;justify-content:flex-start}.ssh-key-actions{width:100%}.ssh-key-actions .row-button{flex:1}} -@media(max-width:510px){.vm-detail-heading .heading-actions{justify-content:space-between}.vm-detail-heading .heading-actions .button{flex:0 0 auto}.vm-detail-facts{grid-template-columns:1fr}.vm-detail-facts>div{padding:12px 0}.vm-detail-actions .row-button{flex:1 1 135px}.vm-table td{padding:10px 11px}.vm-identity{min-width:0}.vm-name-link{max-width:calc(100vw - 130px)}.vm-settings-navigation{padding-inline:8px}.vm-settings-navigation-button{padding-inline:10px;font-size:11px}.vm-settings-content{padding:24px 17px 28px}.vm-settings-actions .button{width:100%}} +@media(max-width:510px){.vm-detail-heading .heading-actions{justify-content:space-between}.vm-detail-heading .heading-actions .button{flex:0 0 auto}.vm-detail-name-control{width:100%;max-width:100%}.vm-detail-name-display{max-width:100%}.vm-detail-name-tooltip{right:0;left:auto;transform:translateY(7px)}.vm-detail-name-display:hover .vm-detail-name-tooltip,.vm-detail-name-display:focus-within .vm-detail-name-tooltip{transform:translateY(3px)}.vm-detail-name-form{align-items:stretch;flex-wrap:wrap}.vm-detail-name-form input{width:100%;min-width:0;flex:1 1 100%}.vm-detail-name-form .button{flex:1}.vm-detail-facts{grid-template-columns:1fr}.vm-detail-facts>div{padding:12px 0}.vm-detail-actions .row-button{flex:1 1 135px}.vm-table td{padding:10px 11px}.vm-identity{min-width:0}.vm-name-link{max-width:calc(100vw - 130px)}.vm-settings-navigation{padding-inline:8px}.vm-settings-navigation-button{padding-inline:10px;font-size:11px}.vm-settings-content{padding:24px 17px 28px}.vm-settings-actions .button{width:100%}} @media(max-width:510px){.vm-operation-log-view .panel-heading{align-items:flex-start}.vm-operation-log-view .panel-heading .button{width:100%}.vm-operation-log-status{padding-inline:17px}.vm-operation-log-row{grid-template-columns:minmax(78px,1fr) minmax(130px,1.45fr) minmax(62px,auto);gap:8px;padding-inline:17px;font-size:11px}.vm-operation-log-header{font-size:9px}.vm-operation-log-cell.result{padding:4px 7px;font-size:10px}.vm-operation-log-footer{align-items:flex-start;flex-direction:column;padding-inline:17px}.vm-operation-log-footer nav{width:100%;justify-content:space-between}} .rescue-status{margin:8px 0 17px;padding:12px 14px;border:1px solid #c8e9e8;border-radius:9px;background:#f0fbfa;color:#236d71;font-size:12px;line-height:1.6} .rescue-directory-note{margin:0 0 17px;padding:10px 12px;border:1px solid #d6e8ee;border-radius:8px;background:#f6fafc;color:#557085;font-size:11px;line-height:1.6;overflow-wrap:anywhere} diff --git a/web/resources/views/venix/cloud/pages/detail.tpl b/web/resources/views/venix/cloud/pages/detail.tpl index ba6e0a3b..230583a9 100644 --- a/web/resources/views/venix/cloud/pages/detail.tpl +++ b/web/resources/views/venix/cloud/pages/detail.tpl @@ -1,7 +1,7 @@
-
+
← 返回实例列表 -
VIRTUAL MACHINE DETAILS

{$cloud_vm_view.name|default:'虚拟机'|escape:"html"}

服务器 IP:{$cloud_vm_view.ip|default:'未获取'|escape:"html"}区域:{$cloud_vm_view.region|default:'未设置'|escape:"html"}{$cloud_vm_view.created_display|default:'未记录'|escape:"html"}

{$cloud_vm_view.state_label|default:'正在读取'|escape:"html"}{$cloud_vm_view.state_sync_label|default:''|escape:"html"}
+
VIRTUAL MACHINE DETAILS

{if $cloud_vm_view.can_rename|default:false}{else}{$cloud_vm_view.name|default:'虚拟机'|escape:"html"}{/if}

{if $cloud_vm_view.can_rename|default:false}点击实例名称修改{/if}
{if $cloud_vm_view.can_rename|default:false}{/if}

服务器 IP:{$cloud_vm_view.ip|default:'未获取'|escape:"html"}区域:{$cloud_vm_view.region|default:'未设置'|escape:"html"}{$cloud_vm_view.created_display|default:'未记录'|escape:"html"}

{$cloud_vm_view.state_label|default:'正在读取'|escape:"html"}{$cloud_vm_view.state_sync_label|default:''|escape:"html"}
diff --git a/web/resources/views/venix/layout_assets.tpl b/web/resources/views/venix/layout_assets.tpl index 7c063f2b..c7e11a3a 100644 --- a/web/resources/views/venix/layout_assets.tpl +++ b/web/resources/views/venix/layout_assets.tpl @@ -1,2 +1,2 @@ {* Shared Venix CSS/JS cache key. Increment whenever a shared browser asset changes. *} -{assign var=venix_asset_version value='2026100403' scope='global'} +{assign var=venix_asset_version value='2026100404' scope='global'} diff --git a/web/tests/CloudInstanceNameServiceTest.php b/web/tests/CloudInstanceNameServiceTest.php new file mode 100644 index 00000000..a9095d66 --- /dev/null +++ b/web/tests/CloudInstanceNameServiceTest.php @@ -0,0 +1,128 @@ +lockForUpdate()') + && str_contains($serviceSource, 'hash_equals($currentName, $name)') + && str_contains($serviceSource, 'hash_equals($currentName, $initialName)'), + 'Display-name persistence lost its compare-and-swap concurrency guard.'); +$expectError = static function (callable $callback, int $status, string $message) use ($assert): void { + try { + $callback(); + } catch (CloudError $error) { + $assert($error->httpStatus === $status, + $message . ' Unexpected status: ' . $error->httpStatus); + return; + } + throw new RuntimeException($message); +}; + +$capsule = new Capsule(); +$capsule->addConnection(['driver' => 'sqlite', 'database' => ':memory:'], 'default'); +$capsule->setAsGlobal(); +$capsule->bootEloquent(); +$capsule->schema('default')->create('cloud_instances', static function (Blueprint $table): void { + $table->increments('id'); + $table->string('uuid'); + $table->integer('user_id'); + $table->string('name'); + $table->string('status'); + $table->text('spec_json'); + $table->integer('updated_at'); +}); + +$rows = [ + ['id' => 1, 'uuid' => '11111111-1111-4111-8111-111111111111', + 'user_id' => 1, 'name' => 'vm-owner1', 'status' => 'active', + 'spec_json' => '{"resource_name":"vc-immutable-owner"}', 'updated_at' => 10], + ['id' => 2, 'uuid' => '22222222-2222-4222-8222-222222222222', + 'user_id' => 2, 'name' => 'vm-owner2', 'status' => 'active', + 'spec_json' => '{"resource_name":"vc-immutable-foreign"}', 'updated_at' => 20], + ['id' => 3, 'uuid' => '33333333-3333-4333-8333-333333333333', + 'user_id' => 1, 'name' => 'vm-deleting', 'status' => 'deleting', + 'spec_json' => '{}', 'updated_at' => 30], + ['id' => 4, 'uuid' => '44444444-4444-4444-8444-444444444444', + 'user_id' => 1, 'name' => 'vm-deleted', 'status' => 'deleted', + 'spec_json' => '{}', 'updated_at' => 40], +]; +Capsule::table('cloud_instances')->insert($rows); + +$owner = ['user_id' => 1, 'is_admin' => false, 'is_super_admin' => false, + 'can_manage' => false]; +$readonlyAdmin = ['user_id' => 1, 'is_admin' => true, 'is_super_admin' => false, + 'can_manage' => false]; +$global = ['user_id' => 99, 'is_admin' => true, 'is_super_admin' => true, + 'can_manage' => true]; + +$result = CloudInstanceNameService::rename(1, $owner, 'Prod.Web_01'); +$renamed = Capsule::table('cloud_instances')->where('id', 1)->first(); +$assert($result === ['id' => '1', 'name' => 'Prod.Web_01'] + && $renamed->name === 'Prod.Web_01' + && $renamed->uuid === $rows[0]['uuid'] + && $renamed->spec_json === $rows[0]['spec_json'] + && $renamed->status === 'active' + && (int) $renamed->updated_at > 10, + 'Owner rename did not persist only the panel display identity.'); + +$sameTimestamp = (int) $renamed->updated_at; +$assert(CloudInstanceNameService::rename(1, $owner, 'Prod.Web_01')['name'] === 'Prod.Web_01' + && (int) Capsule::table('cloud_instances')->where('id', 1)->value('updated_at') + === $sameTimestamp, + 'Idempotent rename rewrote the instance row.'); + +foreach ([null, '', '-bad', 'space name', str_repeat('a', 64), 'bad/segment'] as $invalid) { + $expectError(static fn () => CloudInstanceNameService::rename(1, $owner, $invalid), + 422, 'Invalid display name was accepted.'); +} +$apiRequest = Request::createFromEnvironment(Environment::mock([ + 'REQUEST_METHOD' => 'PATCH', 'REQUEST_URI' => '/api/v1/vms/1/display-name', +]))->withParsedBody(['name' => 'Api-Label_02']) + ->withAttribute('cloud_actor', $owner); +$apiResponse = (new CloudApiController())->displayName( + $apiRequest, new Response(), ['id' => '1'] +); +$apiPayload = json_decode((string) $apiResponse->getBody(), true); +$assert($apiResponse->getStatusCode() === 200 + && $apiResponse->getHeaderLine('Cache-Control') === 'no-store' + && $apiPayload === ['id' => '1', 'name' => 'Api-Label_02'] + && Capsule::table('cloud_instances')->where('id', 1)->value('name') === 'Api-Label_02', + 'Display-name controller did not return a non-cacheable bounded response.'); +$extraFieldRequest = $apiRequest->withParsedBody([ + 'name' => 'Rejected', 'uuid' => $rows[0]['uuid'], +]); +$expectError(static fn () => (new CloudApiController())->displayName( + $extraFieldRequest, new Response(), ['id' => '1'] +), 422, 'Display-name endpoint accepted an extra mutable field.'); + +$expectError(static fn () => CloudInstanceNameService::rename(2, $owner, 'cross-tenant'), + 404, 'Ordinary owner renamed another tenant instance.'); +$expectError(static fn () => CloudInstanceNameService::rename(2, $readonlyAdmin, 'cross-tenant'), + 404, 'Read-only administrator inherited global rename permission.'); +$expectError(static fn () => CloudInstanceNameService::rename(3, $owner, 'too-late'), + 409, 'Deleting instance accepted a display-name mutation.'); +$expectError(static fn () => CloudInstanceNameService::rename(4, $owner, 'resurrected'), + 404, 'Deleted instance accepted a display-name mutation.'); + +$globalResult = CloudInstanceNameService::rename(2, $global, 'Prod.Web_01'); +$assert($globalResult['name'] === 'Prod.Web_01' + && Capsule::table('cloud_instances')->where('id', 2)->value('name') === 'Prod.Web_01', + 'Super administrator rename failed or an unsupported uniqueness rule was introduced.'); + +echo "Cloud instance display-name ownership and persistence passed.\n"; diff --git a/web/tests/CloudInstancePageServiceTest.php b/web/tests/CloudInstancePageServiceTest.php index 453fd10d..9c23b7e0 100644 --- a/web/tests/CloudInstancePageServiceTest.php +++ b/web/tests/CloudInstancePageServiceTest.php @@ -195,6 +195,7 @@ namespace { && $ownedDetail['country_code'] === 'JP', 'Instance detail did not use its safe region and country snapshot.'); $assert($ownedDetail['can_operate'] && $ownedDetail['can_delete'] + && $ownedDetail['can_rename'] && $ownedDetail['password_available'] && $ownedDetail['can_renew'], 'Owner lost expected instance capabilities.'); $assert($ownedDetail['state'] === 'running' @@ -224,7 +225,8 @@ namespace { $assertNoPlacement($foreign, 'The shared user-facing detail exposed placement to an administrator session.'); $assert(!$foreign['is_owner'] && !$foreign['can_operate'] - && !$foreign['can_delete'] && !$foreign['can_view_credential'] + && !$foreign['can_delete'] && !$foreign['can_rename'] + && !$foreign['can_view_credential'] && !$foreign['password_available'] && !$foreign['can_renew'], 'Read-only administrator inherited foreign instance mutation or credential access.'); @@ -232,7 +234,8 @@ namespace { $assertNoPlacement($managed, 'The shared user-facing detail exposed placement to a super-administrator session.'); $assert(!$managed['is_owner'] && $managed['can_operate'] - && $managed['can_delete'] && $managed['can_view_credential'] + && $managed['can_delete'] && $managed['can_rename'] + && $managed['can_view_credential'] && $managed['password_available'] && !$managed['can_renew'], 'Super administrator capabilities no longer match the legacy VM boundary.'); Capsule::connection('default')->flushQueryLog(); @@ -251,6 +254,7 @@ namespace { $assert($status['state'] === 'running' && $status['traffic_used_bytes'] === 500 && $status['traffic_remaining_bytes'] === 1500 && $status['name'] === 'foreign-vm' + && $status['can_rename'] === true && $status['live_state_available'] === true, 'Lightweight status did not merge live state while preserving the database display name.'); $assertNoPlacement($status, diff --git a/web/tests/CloudInstancePageSsrContractTest.php b/web/tests/CloudInstancePageSsrContractTest.php index 18948437..3e8c38b6 100644 --- a/web/tests/CloudInstancePageSsrContractTest.php +++ b/web/tests/CloudInstancePageSsrContractTest.php @@ -24,6 +24,7 @@ $api = file_get_contents($root . '/app/Controllers/CloudApiController.php'); $service = file_get_contents($root . '/app/Services/Cloud/CloudInstancePageService.php'); $middleware = file_get_contents($root . '/app/Middleware/CloudApi.php'); $routes = file_get_contents($root . '/config/routes_cloud.php'); +$worker = file_get_contents($root . '/app/Services/Cloud/CloudWorkerService.php'); $pageService = $section($service, 'public static function forActor(', 'public static function detailForActor('); @@ -77,6 +78,8 @@ $assert(str_contains($detail, 'CloudAccess::actor(false)') && str_contains($detail, "'cloud_vm_view'") && str_contains($detail, "'cloud_vm_bootstrap_json'"), 'Instance detail HTML must embed a useful owner-scoped database snapshot.'); +$assert(str_contains($page, "'can_rename' => (bool) (\$vm['can_rename'] ?? false)"), + 'Instance detail view dropped the explicit display-name mutation permission.'); $assert(str_contains($page, 'JSON_HEX_TAG') && str_contains($page, "'csrf_token' => AdminCsrf::token()") && str_contains($page, "withHeader('Cache-Control', 'private, no-store')"), @@ -87,18 +90,21 @@ $metadataRoute = strpos($routes, "'/vms/metadata'"); $statusesRoute = strpos($routes, "'/vms/statuses'"); $metadataOneRoute = strpos($routes, "'/vms/{id:[0-9]+}/metadata'"); $statusRoute = strpos($routes, "'/vms/{id:[0-9]+}/status'"); +$displayNameRoute = strpos($routes, "'/vms/{id:[0-9]+}/display-name'"); $legacyRoute = strpos($routes, "'/vms/{id}'"); $assert($pageRoute !== false && $metadataRoute !== false && $statusesRoute !== false - && $metadataOneRoute !== false && $statusRoute !== false + && $metadataOneRoute !== false && $statusRoute !== false && $displayNameRoute !== false && $legacyRoute !== false && $pageRoute < $legacyRoute && $metadataRoute < $legacyRoute && $statusesRoute < $legacyRoute - && $metadataOneRoute < $legacyRoute && $statusRoute < $legacyRoute, + && $metadataOneRoute < $legacyRoute && $statusRoute < $legacyRoute + && $displayNameRoute < $legacyRoute, 'Lightweight fixed VM routes must precede the legacy dynamic VM route.'); $pageApi = $section($api, 'public function vmPage(', 'public function vmMetadata('); $metadataApi = $section($api, 'public function vmMetadata(', 'public function vmStatuses('); $statusesApi = $section($api, 'public function vmStatuses(', 'public function vmStatus('); $statusApi = $section($api, 'public function vmStatus(', 'public function vm('); +$displayNameApi = $section($api, 'public function displayName(', 'public function operationLogs('); $assert(str_contains($pageApi, '$this->billingActor($request)') && str_contains($pageApi, 'CloudInstancePageService::forActor') && !str_contains($pageApi, 'CloudEngineClient'), @@ -108,7 +114,7 @@ $assert(str_contains($metadataApi, 'CloudInstancePageService::forActorIds') && str_contains($metadataApi, "'GET', 'vm-metadata?ids='") && str_contains($metadataApi, 'isset($allowed[$uuid])') && str_contains($metadataApi, 'CloudInstanceMetadata::persistBatch($group, $hostLive)') - && str_contains($metadataApi, ". ':' . $uuid") + && str_contains($metadataApi, ". ':' . \$uuid") && str_contains($metadataApi, 'CloudInstanceMetadata::publicView') && !str_contains($metadataApi, "'GET', 'vms'"), 'Static VM metadata refresh must be bounded, owner intersected and cached without full inventory.'); @@ -117,7 +123,7 @@ $assert(str_contains($statusesApi, 'CloudInstancePageService::forActorIds') && str_contains($statusesApi, 'CloudInstancePageService::powerStatus') && str_contains($statusesApi, "'GET', 'vm-states'") && str_contains($statusesApi, 'isset($allowed[$uuid])') - && str_contains($statusesApi, ". ':' . $uuid") + && str_contains($statusesApi, ". ':' . \$uuid") && !str_contains($statusesApi, "'GET', 'vms'"), 'Batch VM status must intersect owner UUIDs, preserve host identity and use only the lightweight engine resource.'); $assert(str_contains($statusApi, 'CloudInstancePageService::statusForActor') @@ -148,9 +154,19 @@ $assert(str_contains($vmData, "'name' => (string) \$instance->name") && !str_contains($vmData, 'host?->region') && !str_contains($vmData, 'CloudInput::safeResult($vm)'), 'Full VM responses must use the strict public metadata DTO and keep the database display name authoritative.'); +$assert(str_contains($displayNameApi, 'CloudInput::only($body, [\'name\'])') + && str_contains($displayNameApi, 'CloudInstanceNameService::rename(') + && !str_contains($displayNameApi, 'CloudEngineClient') + && !str_contains($displayNameApi, 'CloudJob'), + 'Display-name mutation must remain a strict PHP/database-only endpoint.'); $assert(str_contains($middleware, "\$path === '/api/v1/vms/page'") && str_contains($middleware, "^/api/v1/vms/[0-9]+/status\$#D") + && str_contains($middleware, "^/api/v1/vms/[0-9]+/display-name\$#D") && str_contains($middleware, 'CloudAccess::actor(!$databaseOnly)'), 'Database-only VM pagination and detail status must not allocate a private-engine cloud session.'); +$assert(str_contains($worker, '$newInstance = $instance === null;') + && str_contains($worker, 'if ($newInstance)') + && str_contains($worker, "\$instance->name = \$payload['body']['name'];"), + 'A late create reconciliation must not overwrite an owner-renamed display name.'); echo "Instance list/detail SSR and lightweight live-status contract passed.\n"; diff --git a/web/tests/CloudSessionSecurityTest.php b/web/tests/CloudSessionSecurityTest.php index 5d3a7d30..21177621 100644 --- a/web/tests/CloudSessionSecurityTest.php +++ b/web/tests/CloudSessionSecurityTest.php @@ -116,6 +116,30 @@ namespace { && ($sshKeysWriteActor['session_id'] ?? null) === '' && CloudSession::count() === $sessionCount, 'Valid SSH-key mutation CSRF failed or created an engine cloud session.'); + $displayNameWrite = Request::createFromEnvironment(Environment::mock([ + 'REQUEST_METHOD' => 'PATCH', 'REQUEST_URI' => '/api/v1/vms/1/display-name', + ])); + $displayNameCalled = false; + $displayNameActor = null; + $displayNameNext = function ($request, $response) use (&$displayNameCalled, + &$displayNameActor) { + $displayNameCalled = true; + $displayNameActor = $request->getAttribute('cloud_actor'); + return $response; + }; + $reply = $middleware($displayNameWrite, new Response(), $displayNameNext); + $assert($reply->getStatusCode() === 403 && !$displayNameCalled + && CloudSession::count() === $sessionCount, + 'Display-name mutation without CSRF was accepted or created a cloud session.'); + $displayNameWrite = $displayNameWrite->withHeader( + 'X-CSRF-Token', AdminCsrf::token() + ); + $reply = $middleware($displayNameWrite, new Response(), $displayNameNext); + $assert($reply->getStatusCode() === 200 && $displayNameCalled + && is_array($displayNameActor) + && ($displayNameActor['session_id'] ?? null) === '' + && CloudSession::count() === $sessionCount, + 'Valid display-name CSRF failed or allocated an engine cloud session.'); $billingRequest = Request::createFromEnvironment(Environment::mock([ 'REQUEST_METHOD' => 'GET', 'REQUEST_URI' => '/api/v1/invoices/1/status', ])); diff --git a/web/tests/VirtualizationAssetsTest.php b/web/tests/VirtualizationAssetsTest.php index 60c46831..11ec079f 100644 --- a/web/tests/VirtualizationAssetsTest.php +++ b/web/tests/VirtualizationAssetsTest.php @@ -708,6 +708,18 @@ $assert(str_contains($clientScript, 'function setInstanceSettingTab(') && !str_contains($baseStyles, '.vm-settings-grid{') && str_contains($clientScript, "if (settingsHostname) settingsHostname.textContent"), 'Instance settings must use a two-column navigation layout without the retired card grid.'); +$assert(str_contains($detailTemplate, 'id="vm-detail-name-trigger"') + && str_contains($detailTemplate, 'role="tooltip">点击实例名称修改') + && str_contains($detailTemplate, 'id="vm-detail-name-form"') + && str_contains($detailTemplate, 'maxlength="63"') + && str_contains($clientScript, 'function bindDisplayNameEditor(') + && str_contains($clientScript, '/display-name`') + && str_contains($clientScript, "event.key !== 'Escape'") + && str_contains($clientScript, "save.textContent = '保存中…'") + && str_contains($clientScript, 'let displayNameChanged = false;') + && str_contains($baseStyles, '.vm-detail-name-display:hover .vm-detail-name-tooltip') + && str_contains($baseStyles, '.vm-detail-name-display:focus-within .vm-detail-name-tooltip'), + 'Instance display-name editing must be inline, accessible and converge on list BFCache restores.'); $assert(str_contains($detailTemplate, 'id="vm-detail-password-result" class="reinstall-password-card"') && str_contains($detailTemplate, 'id="vm-detail-generated-password-close"') && str_contains($detailTemplate, 'id="vm-detail-generated-password-saved"')