import test from 'node:test' import assert from 'node:assert/strict' import { readFile } from 'node:fs/promises' const source = await readFile(new URL('../stores/picking.js', import.meta.url), 'utf8') const taskIdentitySource = await readFile(new URL('../utils/task-identity.js', import.meta.url), 'utf8') test('picking drafts are persisted under stable operator, task and loading plan identity', () => { assert.match(source, /pda-picking-draft/) assert.match(source, /operatorId/) assert.match(source, /taskId/) assert.match(source, /loadingPlanId/) assert.match(source, /containerBookingId/) assert.match(source, /uni\.setStorageSync\(key/) assert.match(source, /uni\.getStorageSync\(key/) assert.match(source, /uni\.removeStorageSync\(key/) }) test('draft restore rejects a different operator or task', () => { assert.match(source, /saved\.operatorId !== expected\.operatorId/) assert.match(source, /saved\.taskId !== expected\.taskId/) assert.match(source, /saved\.loadingPlanId !== expected\.loadingPlanId/) assert.match(source, /saved\.containerBookingId !== expected\.containerBookingId/) assert.doesNotMatch(taskIdentitySource, /containerNo|currentContainerNo|boxNo/) }) test('mutable real container number is not part of draft identity or restore validation', () => { const restoreGuard = source.match(/const expected = stableTaskIdentity[\s\S]*?return null/)?.[0] || '' assert.doesNotMatch(taskIdentitySource, /containerNo|currentContainerNo|boxNo/) assert.doesNotMatch(restoreGuard, /containerNo|currentContainerNo|boxNo/) }) test('completion retry persists the exact accepted operation id and request version', () => { assert.match(source, /pda-loading-completion/) assert.match(source, /saveLoadingCompletionAttempt/) assert.match(source, /restoreLoadingCompletionAttempt/) assert.match(source, /operationId: String\(attempt\.operationId\)/) assert.match(source, /expectedTaskVersion: Number\(attempt\.expectedTaskVersion\)/) })