import assert from 'node:assert/strict'; import { readFile } from 'node:fs/promises'; const source = await readFile(new URL('../public/cloud/admin-operations.js', import.meta.url), 'utf8'); 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, inspects, aborts, cleans, or stops an old task workflow. for (const forbidden of [ 'stop-auto', 'abort-job', '/cleanup', 'can_stop_auto_reconcile', 'job_id', 'uncertain', 'needs_attention', '自动核对', '待核对', '正在核对', ]) assert.doesNotMatch(shipped, new RegExp(forbidden)); // 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, /unresolved_effect/); assert.match(source, /资源已安全锁定,需管理员人工处理/); assert.match(source, /job\.kind === 'host_storage_configure'/); 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(source, /expectedStatus: 202/); assert.match(source, /taskUrl\(payload\)/); assert.match(source, /announceTaskAccepted\(payload/); assert.match(source, /observeTask\(payload/); assert.match(source, /taskFailureMessage\(task/); assert.match(source, /await loadPage\(listUrl\(\), 'none'\)/); assert.match(source, /await openDetail\(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(source, /method: 'POST', body: '\{\}'/); assert.match(source, /\/resolve-effect`/); assert.match(source, /JSON\.stringify\(\{ resolution, reason \}\)/); assert.match(source, /reason\.length < 20 \|\| reason\.length > 500/); assert.match(shipped, /原任务仍保持失败/); assert.match(shipped, /不会重放 Agent 或支付请求/); // 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.');