test: bind real containers before pda push

This commit is contained in:
2026-08-14 22:59:10 +08:00
parent 0c845874f4
commit b89f14217d
4 changed files with 29 additions and 16 deletions
@@ -16,8 +16,12 @@ test('retains all clickable container, loading-list and PDA workflow states thro
assert.match(source, /prepareInbound/)
assert.match(source, /\.\/orders\.mjs/)
assert.match(source, /\.\/inbound-measurement\.mjs/)
assert.doesNotMatch(source, /context\.request\('POST', CONTAINERS/)
assert.match(source, /context\.request\('POST', CONTAINERS/)
assert.match(source, /summary\?\.processStatus === 'WAIT_SPLIT'/)
const pushIndex = source.indexOf('`${SMART}/plans/${plan.id}/push-preload`')
const transportIndex = source.indexOf('`${CONTAINERS}/${containerId}/transport`')
assert.ok(transportIndex >= 0 && pushIndex > transportIndex)
assert.match(source, /transported\?\.cabinetNo !== container\?\.cabinetNo/)
const batch = source.slice(source.indexOf('async function pickAll'), source.indexOf('async function complete'))
assert.doesNotMatch(batch, /containerNo:/)
})
@@ -166,10 +166,6 @@ async function createPlanTask(context, label) {
expectedVersion: Number(plan.version), operationId: operationId(context, `${label}-assign`),
})
plan = context.apiSuccess(MODULE, `${label} 分配独立候选货物`, assignResponse, '', OPTIONS)
const pushResponse = await post(context, `${SMART}/plans/${plan.id}/push-preload`,
{ expectedVersion: Number(plan.version) }, `${label}-push`)
plan = context.apiSuccess(MODULE, `${label} 推送预装`, pushResponse, '', OPTIONS)
const detailResponse = await context.request('GET', `${CONTAINERS}/${containerId}`)
const container = context.apiSuccess(MODULE, `${label} 读取柜次`, detailResponse, '', OPTIONS)
const containerNo = `MAN-${suffix(context, label)}`.slice(0, 64)
@@ -177,7 +173,14 @@ async function createPlanTask(context, label) {
containerNo, voyageNo: `V-${suffix(context, label)}`.slice(0, 64), version: Number(container.version),
reason: `${context.marker} 人工状态样本`,
})
context.apiSuccess(MODULE, `${label} 写入真实集装箱号并开放 PDA`, transportResponse, '', OPTIONS)
const transported = context.apiSuccess(MODULE, `${label} 写入真实集装箱号并开放 PDA`, transportResponse, '', OPTIONS)
if (transported?.containerNo !== containerNo || id(transported?.id) !== containerId
|| transported?.cabinetNo !== container?.cabinetNo) {
throw new Error(`${label} 真实集装箱号未绑定到稳定柜次`)
}
const pushResponse = await post(context, `${SMART}/plans/${plan.id}/push-preload`,
{ expectedVersion: Number(plan.version) }, `${label}-push`)
plan = context.apiSuccess(MODULE, `${label} 补真实柜号后推送预装`, pushResponse, '', OPTIONS)
const taskResponse = await context.request('GET',
`${PDA}/tasks?loadingPlanId=${plan.id}&warehouseId=${source.warehouseId}`)
const task = context.apiSuccess(MODULE, `${label} 读取 PDA 任务`, taskResponse, '', OPTIONS)
@@ -19,8 +19,11 @@ test('PDA opens only after a real container number and uses stable plan identity
const pushIndex = source.indexOf("`${SMART}/plans/${planId}/push-preload`")
const transportIndex = source.indexOf("`${CONTAINERS}/${encodeURIComponent(containerId)}/transport`")
const taskIndex = source.indexOf("`${PDA}/tasks?loadingPlanId=${encodeURIComponent(planId)}&warehouseId=${encodeURIComponent(warehouseId)}`")
assert.ok(pushIndex >= 0 && transportIndex > pushIndex && taskIndex > transportIndex)
assert.ok(transportIndex >= 0 && pushIndex > transportIndex && taskIndex > pushIndex)
assert.match(source, /containerNo: realContainerNo/)
assert.match(source, /const transportStable = transported\?\.containerNo === realContainerNo/)
assert.match(source, /transported\?\.cabinetNo === simulation\.cabinetNo/)
assert.match(source, /if \(!transportStable\) return null/)
assert.match(source, /id\(task\?\.loadingPlanId\) === planId/)
assert.match(source, /id\(task\?\.containerBookingId\) === containerId/)
assert.doesNotMatch(source, /\$\{PDA\}\/tasks\?containerNo=/)
@@ -207,13 +207,6 @@ async function loadOneFragment(context, state) {
isConflict(staleAssign) && hasTrace(staleAssign),
`HTTP=${staleAssign.http}, code=${codeOf(staleAssign)}, requestId=${staleAssign.requestId || 'missing'}, traceId=${staleAssign.traceId || 'missing'}`, OPTIONS)
const push = await request(context, 'POST', `${SMART}/plans/${planId}/push-preload`,
{ expectedVersion: Number(assigned.version) }, { 'Idempotency-Key': `${operationBase}-push` })
const pushed = context.apiSuccess(MODULE, `推送 ${sourceOrderNo} 的预装计划`, push, '', OPTIONS)
context.assert(MODULE, `${sourceOrderNo} 未补真实柜号时计划保持 EDITING`, push,
pushed?.status === 'EDITING', `status=${pushed?.status || 'missing'}`, OPTIONS)
if (pushed?.status !== 'EDITING') return null
const containerDetailResponse = await context.request('GET', `${CONTAINERS}/${encodeURIComponent(containerId)}`)
const containerDetail = context.apiSuccess(MODULE, `回查 ${sourceOrderNo} 的自动柜次`, containerDetailResponse, '', OPTIONS)
const realContainerNo = `SPLIT-${operationBase.replace(/[^A-Za-z0-9]/g, '').slice(-18)}`.slice(0, 64)
@@ -222,9 +215,19 @@ async function loadOneFragment(context, state) {
version: Number(containerDetail?.version), reason: context.marker,
})
const transported = context.apiSuccess(MODULE, `为 ${sourceOrderNo} 补充真实柜号并开放 PDA`, transportResponse, '', OPTIONS)
const transportStable = transported?.containerNo === realContainerNo && id(transported?.id) === containerId
&& transported?.cabinetNo === simulation.cabinetNo
context.assert(MODULE, `${sourceOrderNo} 真实柜号已绑定到稳定柜次`, transportResponse,
transported?.containerNo === realContainerNo,
`containerBookingId=${containerId}, containerNo=${transported?.containerNo || 'missing'}`, OPTIONS)
transportStable,
`containerBookingId=${containerId}, containerNo=${transported?.containerNo || 'missing'}, cabinetNo=${transported?.cabinetNo || 'missing'}`, OPTIONS)
if (!transportStable) return null
const push = await request(context, 'POST', `${SMART}/plans/${planId}/push-preload`,
{ expectedVersion: Number(assigned.version) }, { 'Idempotency-Key': `${operationBase}-push` })
const pushed = context.apiSuccess(MODULE, `推送 ${sourceOrderNo} 的预装计划`, push, '', OPTIONS)
context.assert(MODULE, `${sourceOrderNo} 补真实柜号后计划保持 EDITING`, push,
pushed?.status === 'EDITING', `status=${pushed?.status || 'missing'}`, OPTIONS)
if (pushed?.status !== 'EDITING') return null
const taskResponse = await context.request('GET',
`${PDA}/tasks?loadingPlanId=${encodeURIComponent(planId)}&warehouseId=${encodeURIComponent(warehouseId)}`)