import assert from 'node:assert/strict'; import { operationFailureText, operationText, presentOperation, } from '../public/cloud/admin-operation-presentation.js'; assert.deepEqual(presentOperation(null), { terminal: true, status: 'failed', label: '协议错误', tone: 'text-danger', protocolError: true, }); assert.equal(presentOperation({ id: 7, completed: false, status: 'active' }).label, '执行中'); assert.equal(presentOperation({ id: 7, completed: true, status: 'succeeded' }).label, '已成功'); assert.equal(presentOperation({ id: 7, completed: true, status: 'failed', recovery: { pending: true, code: 'recovery_dispatch_ledger_conflict' }, }).label, '派发账本异常 · 待修复'); assert.equal(presentOperation({ id: 7, completed: true, status: 'failed', dispatch_state: 'not_dispatched', recovery: { pending: true }, }).label, 'PHP 本地账本收尾中'); assert.equal(operationText(' '), '未记录'); assert.match(operationFailureText({ id: 8, completed: true, status: 'failed', kind: 'host_storage_configure', }), /不会重放/); assert.match(operationFailureText({ id: 8, completed: true, status: 'failed', effect_may_have_applied: true, effect_resolution: 'unknown', }), /资源已安全锁定/); assert.match(operationFailureText({ id: 8, completed: true, status: 'failed', effect_may_have_applied: true, effect_resolution: 'applied', effect_scope: 'partial', }), /部分宿主机已应用、部分未应用/); assert.match(operationFailureText({ id: 8, completed: true, status: 'failed', dispatch_state: 'not_dispatched', recovery: { pending: true, message: '等待数据库。' }, }), /只重试.*本地|本地账本收尾|系统会持续重试本地收尾/); console.log('Admin operation presentation behavior tests passed.');