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.
81 lines
4.5 KiB
JavaScript
81 lines
4.5 KiB
JavaScript
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, 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, /unresolved_effect/);
|
|
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(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, /taskSucceededWithoutRecovery\(task\)/);
|
|
assert.doesNotMatch(source, /task\.status === 'succeeded'/);
|
|
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, /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, /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.');
|