test: complete phase4 PDA shipping prerequisites

This commit is contained in:
2026-08-25 15:27:26 +08:00
parent fa92936406
commit 1f6f1a0677
6 changed files with 177 additions and 22 deletions
@@ -81,7 +81,7 @@ test('measurement and loading pass destination identity into the LOADED producer
assert.match(finalize, /resourceKey: `\$\{context\.marker\}:\$\{fixture\.destinationType \|\| 'UNKNOWN'\}:\$\{fixture\.containerNo \|\| containerBookingId\}`/)
assert.match(finalize, /phase4InboundProducerFixtures = collectPhase4InboundProducerFixture/)
const entry = read('../admin-test-env-acceptance.mjs')
assert.match(entry, /runPhase4ProducerVariant\('DROPSHIP-PRIMARY', 'FBA', 'ONE_CLICK_DROPSHIP'\)/)
assert.match(entry, /runPhase4ProducerVariant\('DROPSHIP-PRIMARY', 'FBA', 'ONE_CLICK_DROPSHIP', true\)/)
assert.match(entry, /orderFulfillmentType/)
assert.match(entry, /fulfillmentType: fixtureOrder\.fulfillmentType \|\| 'STANDARD'/)
assert.match(entry, /skuCodes: Array\.isArray\(fixtureOrder\.skuCodes\) \? fixtureOrder\.skuCodes : \[\]/)
@@ -90,3 +90,35 @@ test('measurement and loading pass destination identity into the LOADED producer
assert.match(pda, /find\(\(item\) => item\?\.fulfillmentType === 'ONE_CLICK_DROPSHIP'\)/)
assert.match(pda, /skuFixtures\(context, producer\)/)
})
test('only PDA-operated variants traverse real outbound and carrier nodes before overseas receiving', () => {
const entry = read('../admin-test-env-acceptance.mjs')
assert.match(entry, /runPhase4ProducerVariant\('OVERSEAS-PRIMARY', 'OVERSEAS', 'STANDARD', true\)/)
assert.match(entry, /runPhase4ProducerVariant\('FBA-STANDARD', 'FBA', 'STANDARD', false\)/)
assert.match(entry, /runPhase4ProducerVariant\('SECONDARY', 'FBA', 'STANDARD', false\)/)
const start = entry.indexOf('if (pickupRequired && producerKey)')
const end = entry.indexOf('} finally {', start)
const pickupChain = entry.slice(start, end)
const ordered = [
'phase3-customs.mjs', 'service-center-flow.mjs', 'phase3-port-schedules.mjs',
'phase3-outbound-dispatch.mjs', 'phase3-carrier-schedule-queries.mjs',
'phase4-carrier-nodes.mjs', 'runUntilPickupReady(this)',
]
let cursor = -1
for (const token of ordered) {
const next = pickupChain.indexOf(token)
assert.ok(next > cursor, `${token} must follow the real prerequisite chain`)
cursor = next
}
for (const key of ['phase3Customs', 'serviceCenterFlow', 'portSchedule', 'phase3OutboundDispatch',
'phase3CarrierScheduleQuery', 'phase4CarrierPickupReady']) assert.match(entry, new RegExp(`'${key}'`))
assert.match(pickupChain, /shippingReady/)
assert.match(entry, /carrierScheduleQueryId/)
assert.match(pickupChain, /pickup\?\.marker === variantMarker/)
assert.doesNotMatch(pickupChain, /internal\/event-bridge|ll_container_shipping_gate|requestOverseas/)
assert.match(entry, /dropshipReady\?\.shippingReady === true/)
assert.match(entry, /overseasReady\?\.shippingReady === true/)
assert.match(entry, /awaitingVariants\.length >= 1/)
assert.doesNotMatch(entry, /awaitingVariants\.length === 2/)
assert.match(entry, /awaitingVariants\.every\(\(item\) => item\.shippingReady === false/)
})
@@ -80,7 +80,14 @@ test('cross-region normalization keeps existing producers ahead of every phase-t
test('phase-four producer variants restore the primary orchestration fixture after each matrix branch', async () => {
const source = await import('node:fs/promises').then((fs) => fs.readFile(
new URL('../admin-test-env-acceptance.mjs', import.meta.url), 'utf8'))
assert.match(source, /const createdKeys = \['phase3Loading', 'phase3LoadingCompletedProducer', 'orchestrationFixtures', 'oceanBooking'\]/)
const start = source.indexOf('const createdKeys = [', source.indexOf('async runPhase4ProducerVariant'))
const end = source.indexOf(']', start)
const createdKeys = source.slice(start, end)
for (const key of [
'phase3Loading', 'phase3LoadingCompletedProducer', 'orchestrationFixtures', 'oceanBooking',
'phase3CustomsSupplier', 'phase3Customs', 'serviceCenterFlow', 'portSchedule',
'phase3OutboundDispatch', 'phase3CarrierScheduleQuery', 'phase4CarrierPickupReady',
]) assert.match(createdKeys, new RegExp(`'${key}'`))
})
test('contract covers dual audience, canonical 403, both event directions and diagnostics', () => {
@@ -55,6 +55,18 @@ test('PDA module covers the container-number receiving contract and excludes out
assert.match(source, /phase4OverseasPda\.customerId = id\(order\.customerId\)/)
assert.match(source, /现场库存查询只返回Token绑定仓且包含库存位置/)
assert.match(source, /作业历史包含本轮柜号收货动作且分页稳定/)
assert.match(source, /awaitProducerConsumption\(context, allProducers\)/)
assert.match(source, /last-leg\/orders\?page=1&size=200&containerNo=/)
assert.match(source, /跨区消费生成尾程订单/)
assert.match(source, /awaitPickupReadyCandidates\(context, primary\.token, producers, allProducers\)/)
assert.match(source, /missingPickupReady=/)
assert.match(source, /item\?\.shippingReady === false/)
assert.match(source, /!expectedSet\.has\(id\(item\?\.containerNo\)\)/)
assert.match(source, /unexpectedAwaiting=/)
assert.match(source, /missingPickupReady\.length === 0 && unexpectedAwaiting\.length === 0/)
assert.doesNotMatch(source, /shippingReady == null|shippingReady !== true/)
assert.match(source, /unexpectedHistorical=/)
assert.doesNotMatch(source, /awaitProducerCandidates/)
})
test('missing WAREHOUSE_PICKER overseas authority is a deployment blocker', async () => {
@@ -205,22 +205,63 @@ async function uploadPhotos(context, token) {
return photos
}
async function awaitProducerCandidates(context, token, producers) {
async function awaitProducerConsumption(context, producers) {
const expected = [...new Set(producers.map((item) => id(item?.containerNo)).filter(nonBlank))]
if (!expected.length) return true
const consumed = new Set()
const lastResponses = new Map()
for (let attempt = 1; attempt <= 30; attempt += 1) {
const missing = expected.filter((containerNo) => !consumed.has(containerNo))
const results = await Promise.all(missing.map(async (containerNo) => {
const response = await context.requestOverseas('GET',
`/api/platform/v1/last-leg/orders?page=1&size=200&containerNo=${encodeURIComponent(containerNo)}`)
return { containerNo, response }
}))
for (const { containerNo, response } of results) {
lastResponses.set(containerNo, response)
const rows = records(response?.body?.data)
if (success(response) && rows.some((item) => id(item?.containerNo) === containerNo)) {
consumed.add(containerNo)
}
}
if (expected.every((containerNo) => consumed.has(containerNo))) break
await new Promise((resolve) => setTimeout(resolve, 1000))
}
for (const containerNo of expected) {
const response = lastResponses.get(containerNo) || null
context.addStep(MODULE, `跨区消费生成尾程订单 ${containerNo}`, response,
consumed.has(containerNo),
`containerNo=${containerNo}, consumed=${consumed.has(containerNo)}; ${trace(response)}`, OPTIONS)
}
return expected.every((containerNo) => consumed.has(containerNo))
}
async function awaitPickupReadyCandidates(context, token, producers, allProducers) {
const expected = [...new Set(producers.map((item) => id(item?.containerNo)).filter(nonBlank))]
const expectedSet = new Set(expected)
const awaiting = [...new Set(allProducers
.filter((item) => item?.shippingReady === false && !expectedSet.has(id(item?.containerNo)))
.map((item) => id(item?.containerNo)).filter(nonBlank))]
const known = new Set(allProducers.map((item) => id(item?.containerNo)).filter(nonBlank))
if (!expected.length) return false
let response = null
let seen = new Set()
for (let attempt = 1; attempt <= 30; attempt += 1) {
response = await context.requestOverseas('GET',
'/api/pda/v1/last-leg/receiving-containers/candidates', undefined, {}, token)
const records = success(response) && Array.isArray(response.body?.data) ? response.body.data : []
seen = new Set(records.map((item) => id(item?.containerNo)).filter(nonBlank))
if (expected.every((containerNo) => seen.has(containerNo))) break
const candidateRows = success(response) && Array.isArray(response.body?.data) ? response.body.data : []
seen = new Set(candidateRows.map((item) => id(item?.containerNo)).filter(nonBlank))
if (expected.every((containerNo) => seen.has(containerNo))
&& awaiting.every((containerNo) => !seen.has(containerNo))) break
await new Promise((resolve) => setTimeout(resolve, 1000))
}
const ready = expected.every((containerNo) => seen.has(containerNo))
context.addStep(MODULE, '三期生产矩阵全部进入海外待收候选后再开始PDA', response, ready,
`expected=${expected.join('|')}, seen=${[...seen].join('|')}; ${trace(response)}`, OPTIONS)
const seenExpected = expected.filter((containerNo) => seen.has(containerNo))
const missingPickupReady = expected.filter((containerNo) => !seen.has(containerNo))
const unexpectedAwaiting = awaiting.filter((containerNo) => seen.has(containerNo))
const unexpectedHistorical = [...seen].filter((containerNo) => !known.has(containerNo))
const ready = missingPickupReady.length === 0 && unexpectedAwaiting.length === 0
context.addStep(MODULE, '实际处理柜全部达到PICKUP_READY并进入PDA候选', response, ready,
`expected=${expected.join('|')}, awaiting=${awaiting.join('|') || 'none'}, seenExpected=${seenExpected.join('|') || 'none'}, missingPickupReady=${missingPickupReady.join('|') || 'none'}, unexpectedAwaiting=${unexpectedAwaiting.join('|') || 'none'}, unexpectedHistorical=${unexpectedHistorical.join('|') || 'none'}; ${trace(response)}`, OPTIONS)
return ready
}
@@ -501,9 +542,14 @@ export async function run(context) {
const producers = [dropship || matrix?.byDestinationType?.FBA?.[0], matrix?.byDestinationType?.OVERSEAS?.[0]]
.filter((item) => nonBlank(item?.containerNo))
const allProducers = Array.isArray(matrix?.containers) ? matrix.containers : producers
if (allProducers.length && !(await awaitProducerCandidates(context, primary.token, allProducers))) {
blockerGap(context, '海外待收柜生产矩阵',
'三期已发布的FBA、OVERSEAS和第二柜尚未全部被海外事件消费者提交,禁止与消费事务并发入库')
if (allProducers.length && !(await awaitProducerConsumption(context, allProducers))) {
blockerGap(context, '跨区消费生产矩阵',
'三期已发布的四柜尚未全部由海外消费者生成尾程订单,禁止把PICKUP_READY缺口与事件消费混为一谈')
return
}
if (producers.length && !(await awaitPickupReadyCandidates(context, primary.token, producers, allProducers))) {
blockerGap(context, '实际处理柜PICKUP_READY门禁',
'Dropship/FBA与OVERSEAS实际处理柜尚未全部达到PICKUP_READY;跨区消费已独立验证,不回退处理历史柜')
return
}
for (const [index, producer] of (producers.length ? producers : [null]).entries()) {