import assert from 'node:assert/strict'; import { readFile } from 'node:fs/promises'; const entry = await readFile(new URL('../public/cloud/admin-operations.js', import.meta.url), 'utf8'); const presentation = await readFile(new URL('../public/cloud/admin-operation-presentation.js', import.meta.url), 'utf8'); const directory = await readFile(new URL('../public/cloud/admin-operations-directory.js', import.meta.url), 'utf8'); const health = await readFile(new URL('../public/cloud/admin-operations-health.js', import.meta.url), 'utf8'); const recovery = await readFile(new URL('../public/cloud/admin-operations-recovery.js', import.meta.url), 'utf8'); const source = [entry, presentation, directory, health, recovery].join('\n'); const template = await readFile(new URL('../resources/views/venix/admin/cloud/operations.tpl', import.meta.url), 'utf8'); const rows = await readFile(new URL('../resources/views/venix/admin/cloud/operations_rows.tpl', import.meta.url), 'utf8'); const shipped = `${source}\n${template}\n${rows}`; // The fresh task architecture deliberately has no browser control that // replays, aborts, cleans, or stops an old task workflow. Read-only recovery // status is visible, but it never becomes a browser-triggered mutation retry. for (const forbidden of [ 'stop-auto', 'abort-job', '/cleanup', 'can_stop_auto_reconcile', 'job_id', 'uncertain', 'needs_attention', '待核对', ]) assert.doesNotMatch(shipped, new RegExp(forbidden)); assert.match(source, /job\.recovery\?\.pending === true/); assert.match(source, /系统不会重复执行原操作/); assert.match(source, /账本异常 · 待修复/); assert.match(source, /派发账本修复/); assert.match(source, /PHP 本地账本收尾/); // Admin task rendering accepts one active representation and the exact two // public terminal states. Unknown payloads are rendered as protocol failures. assert.match(source, /task\.completed === false && task\.status === 'active'/); assert.match(source, /task\.completed === true/); assert.match(source, /new Set\(\['succeeded', 'failed'\]\)/); assert.match(source, /label: '协议错误'/); assert.match(source, /effect_may_have_applied === true/); assert.match(source, /\['total', 'active', 'attention', 'failed', 'locked'\]/); assert.match(source, /data-operation-summary-status/); assert.match(source, /summaryHref\(page, status\)/); assert.match(template, /'attention'=>'需要处理'/); assert.match(template, /系统运行与异常任务/); assert.match(source, /资源已安全锁定,需管理员人工处理/); assert.match(source, /job\.kind === 'host_storage_configure'/); assert.match(source, /job\.effect_scope === 'partial'/); assert.match(shipped, /部分宿主机已应用、部分未应用/); assert.match(source, /可到宿主机存储目录页修正后提交新的独立任务/); assert.match(source, /storageFailure/); assert.match(source, /收尾事件仅保留审计且不会重放/); assert.match(source, /不会影响存储目录页提交新的独立任务/); assert.match(source, /\['Agent 原因', job\.agent_cause_label \|\| job\.agent_cause_code\]/); // The one retained high-risk action creates a distinct task once. The UI // validates the fresh receipt, immediately acknowledges it, and observes the // task with bounded GET requests without resubmitting the mutation. assert.match(source, /\/force-delete`/); assert.match(entry, /response: 'task'/); assert.match(entry, /taskObserver\.taskUrl\(payload\)/); assert.match(source, /announceTaskAccepted\(payload/); assert.match(source, /observeTask\(payload/); assert.match(source, /taskFailureMessage\(task/); assert.match(source, /taskSucceededWithoutRecovery\(task\)/); assert.doesNotMatch(source, /task\.status === 'succeeded'/); assert.match(recovery, /await refreshDirectory\(\)/); assert.match(recovery, /await open\(task\.id, null\)/); assert.match(source, /forceDeleteAccepted = true/); assert.match(source, /force\.disabled = busy \|\| state\.forceDeleteAccepted \|\| state\.forceDeleteBlocked/); assert.match(source, /state\.forceDeleteBlocked = true/); assert.match(source, /forceDeleteBlockedIds\.add\(String\(id\)\)/); assert.doesNotMatch(source, /setInterval\(/); // Manual inspection is read-only. Resolving an effect is a separate audited // action with an explicit result and a 20-500 character reason; neither route // retries or changes the original task to success in the browser. assert.match(source, /\/inspect`/); assert.match(recovery, /body: \{\}/); assert.match(source, /state\.inspection\.completion_delivery_error/); assert.match(source, /infoList\(\[\['回执异常', completionDeliveryError\]\]\)/); assert.match(source, /if \(content !== undefined\) node\.textContent = String\(content\)/); assert.doesNotMatch(source, /completion_delivery_error[^\n]*innerHTML/); assert.match(source, /\/resolve-effect`/); assert.match(source, /body: \{ resolution, reason \}/); assert.match(source, /reason\.length < 20 \|\| reason\.length > 500/); assert.match(shipped, /原任务仍保持失败/); assert.match(shipped, /不会重放 Agent 或支付请求/); assert.doesNotMatch(source, /window\.prompt\(/); assert.match(template, /id="operation-vpc-retirement-evidence" hidden/); assert.match(template, /id="operation-vpc-retirement-reason" minlength="20" maxlength="500"/); assert.match(source, /function retirementReason\(\)/); assert.match(source, /Array\.from\(value\)\.length/); assert.match(source, /reason: reason\.value/); assert.match(source, /requiredText: String\(id\)/); // The entry is only a composition root. Directory, health and recovery each // expose one deep browser interface, while task display rules remain pure. assert.match(entry, /mountOperationsDirectory\(/); assert.match(entry, /mountOperationsHealth\(/); assert.match(entry, /mountOperationsRecovery\(/); assert.doesNotMatch(entry, /\/force-delete|\/repair-vpc|\/resolve-effect|\/retire-vpc-host/); assert.match(directory, /export function mountOperationsDirectory/); assert.match(health, /export function mountOperationsHealth/); assert.match(recovery, /export function mountOperationsRecovery/); assert.match(presentation, /export function presentOperation/); // Navigation lifecycle aborts every in-flight GET or mutation request. assert.match(source, /visibilitychange/); assert.match(source, /abort\('hidden'\)/); assert.match(source, /pagehide/); assert.match(source, /abort\('pagehide'\)/); console.log('Admin operations fresh task behavior tests passed.');