fix(pda): enforce sealed pallet contract and deduplicate activation refresh

This commit is contained in:
2026-09-09 12:35:03 +08:00
parent b19cecb54f
commit b03d5e1561
5 changed files with 56 additions and 6 deletions
+36
View File
@@ -4,6 +4,42 @@ import { readFile } from 'node:fs/promises'
const read = (path) => readFile(new URL(path, import.meta.url), 'utf8')
test('duplicate onShow shares one load chain while background return refreshes again', async () => {
const page = await read('../pages/picking/picking.vue')
const show = page.match(/async onShow\(\) \{[\s\S]*?\r?\n\t\t\},/)?.[0]
const hide = page.match(/onHide\(\) \{[\s\S]*?\r?\n\t\t\},/)?.[0]
assert.ok(show && hide)
const hooks = new Function('requireSession', 'session', `return ({${show}${hide}})`)(() => true, { currentUser: { id: '7' } })
const calls = []
let release
const pending = new Promise((resolve) => { release = resolve })
const context = { startHardwareScanner() {}, stopHardwareScanner() {}, async refreshAvailableBoxes() { calls.push('pending'); await pending }, async syncRemoteTask() { calls.push('detail+evidence') } }
const first = hooks.onShow.call(context)
const duplicate = hooks.onShow.call(context)
assert.deepEqual(calls, ['pending'])
release()
await Promise.all([first, duplicate])
assert.deepEqual(calls, ['pending', 'detail+evidence'])
await hooks.onShow.call(context)
assert.equal(calls.length, 2)
hooks.onHide.call(context)
await hooks.onShow.call(context)
assert.deepEqual(calls, ['pending', 'detail+evidence', 'pending', 'detail+evidence'])
const onLoad = page.match(/onLoad\(options = \{\}\) \{[\s\S]*?\r?\n\t\t\},/)?.[0]
assert.doesNotMatch(onLoad, /refreshAvailableBoxes|syncRemoteTask/)
})
test('camera and evidence preview resume still avoid unnecessary refreshes', async () => {
const page = await read('../pages/picking/picking.vue')
const show = page.match(/async onShow\(\) \{[\s\S]*?\r?\n\t\t\},/)?.[0]
const hooks = new Function('requireSession', 'session', `return ({${show}})`)(() => true, { currentUser: {} })
for (const flag of ['cameraPicking', 'evidencePreviewReturning']) {
const context = { [flag]: true, startHardwareScanner() {}, debugEvidence() {}, refreshAvailableBoxes() { throw new Error('unexpected refresh') } }
await hooks.onShow.call(context)
assert.equal(context._pageVisible, true)
}
})
test('direct H5 refresh restores the page user before rendering picking content', async () => {
const page = await read('../pages/picking/picking.vue')