fix(pda): drop stale sealed pallets from task workspace

This commit is contained in:
2026-10-23 18:45:48 +08:00
parent b663aac4c7
commit f39303ea24
2 changed files with 25 additions and 7 deletions
+15 -1
View File
@@ -2,6 +2,7 @@ import test from 'node:test'
import assert from 'node:assert/strict'
import { readFile } from 'node:fs/promises'
import vm from 'node:vm'
import { sanitizeUserMessage } from '../utils/user-facing.js'
const source = await readFile(new URL('../pages/dropship-palletization/dropship-palletization.vue', import.meta.url), 'utf8')
const script = source.match(/<script>([\s\S]*?)<\/script>/)[1].replace(/^\s*import .*$/gm, '').replace('export default', 'globalThis.page =')
@@ -18,7 +19,7 @@ function harness(overrides = {}) {
countDropshipCarton: async (id, payload) => { calls.push(['count', id, payload]); return { carton: {} } },
moveDropshipCarton: async (id, cartonId, payload) => { calls.push(['move', id, cartonId, payload]); return { ...target, taskId: id } },
saveDropshipPalletizingDraft: () => {}, clearDropshipPalletizingDraft: () => {}, stableOperationId: () => 'stable-key',
isOnline: () => true, formatApiError: (error) => error.message, uni: { redirectTo: (value) => calls.push(['redirect', value]) },
isOnline: () => true, sanitizeUserMessage, console: { error: (...args) => calls.push(['diagnostic', ...args]) }, uni: { redirectTo: (value) => calls.push(['redirect', value]) },
...overrides
}
vm.runInNewContext(script, context)
@@ -28,6 +29,19 @@ function harness(overrides = {}) {
return { state, calls, pallet, target }
}
test('scan failures show the business message and retain correlation evidence in diagnostics', async () => {
const failure = { message: '箱码不属于当前一件代发入仓单', code: 'A0404', requestId: 'request-test', traceId: 'trace-test' }
const { state, calls } = harness({ resolveDropshipWorkspaceCarton: async () => { throw failure } })
await state.resolveCarton('WRONG-BOX')
assert.equal(state.error, failure.message)
assert.equal(state.loading, false)
const evidence = calls.find(call => call[0] === 'diagnostic')[2]
assert.equal(evidence.code, failure.code)
assert.equal(evidence.requestId, failure.requestId)
assert.equal(evidence.traceId, failure.traceId)
assert.equal(state.formatOperationError({}, '箱码解析失败'), '箱码解析失败')
})
test('cross customer scan remains read only until confirmation and then claims original task', async () => {
const { state, calls, pallet, target } = harness()
state.workspace = { pallet, members: [] }; state.selectedPalletNo = pallet.palletNo