import test from 'node:test' import assert from 'node:assert/strict' import { readFile } from 'node:fs/promises' import { businessReference, displayBusinessValue, formatApiError, sanitizeUserMessage } from '../utils/user-facing.js' const read = (path) => readFile(new URL(path, import.meta.url), 'utf8') test('business identifiers never fall back to an internal id', () => { assert.equal(displayBusinessValue(null), '—') assert.equal(displayBusinessValue('', '未关联'), '未关联') assert.equal(businessReference({ orderNo: 'SO-2026-001', inboundCode: 'RK-2026-002', taskId: '2092889048731414530' }), '订单号 SO-2026-001 · 入仓码 RK-2026-002') assert.equal(businessReference({ taskId: '2092889048731414530', inboundId: '2092889048731414531' }), '业务编号未关联') }) test('operator errors hide internal ids but retain request and trace evidence', () => { const error = { message: 'taskId: 2092889048731414530 对应 loadingPlanId=2092889048731414531 处理失败', code: 'S0500', requestId: 'dbde0d81-7798-4d22-a12e-1731d7ec9bb1', traceId: '5b0ba4f3ed5236b34997dd82162a5138' } const message = formatApiError(error, '任务处理失败') assert.doesNotMatch(message, /209288904873141453[01]|taskId|loadingPlanId/) assert.match(message, /错误码:S0500/) assert.match(message, /requestId:dbde0d81/) assert.match(message, /traceId:5b0ba4f3/) assert.equal(sanitizeUserMessage('operation 2092889048731414530 failed'), 'operation 内部标识已隐藏 failed') }) test('priority PDA templates do not interpolate internal ids', async () => { const pages = await Promise.all([ read('../pages/login/login.vue'), read('../pages/tasks/tasks.vue'), read('../pages/picking/picking.vue'), read('../pages/history/history.vue') ]) for (const page of pages) { const template = page.match(/