feat(phase3): 收口父子单与全链路验收

This commit is contained in:
2026-08-10 12:23:43 +08:00
parent b294695169
commit 75d5fd4e26
55 changed files with 1110 additions and 115 deletions
@@ -179,8 +179,10 @@ export async function run(context) {
const scanPath = `/api/platform/v1/first-leg/inbounds/${inboundId}/measurement/carton-scans?${query(tenantId)}`
// Keep the isolated sample inside the customer's largest configured inner box (60x50x50cm).
const firstDimensions = { length: 59.1, width: 40.2, height: 30.3, weight: 12.5 }
const firstShipmentId = `FBA-${context.marker.slice(-12)}-01`
const firstScanResponse = await multipartRequest(context, scanPath, {
boxCode, ...firstDimensions, machineNo: 'MJ-ADMIN-E2E-01', measuredAt: new Date().toISOString().slice(0, 19),
boxCode, ...firstDimensions, scannedShipmentId: firstShipmentId,
machineNo: 'MJ-ADMIN-E2E-01', measuredAt: new Date().toISOString().slice(0, 19),
})
const firstScan = context.apiSuccess(MODULE, '模拟墨家首次扫描单箱', firstScanResponse,
`boxCode=${boxCode}, machineNo=MJ-ADMIN-E2E-01`, OPTIONS)
@@ -204,6 +206,7 @@ export async function run(context) {
context.assert(MODULE, '箱级查询回显箱码、尺寸、图片与设备信息', firstQueryResponse,
firstItem?.boxCode === boxCode && asId(firstItem?.intelligentImageFileId)
&& firstItem?.machineNo === 'MJ-ADMIN-E2E-01'
&& firstItem?.scannedShipmentId === firstShipmentId
&& closeTo(firstItem?.lengthCm, firstDimensions.length)
&& closeTo(firstItem?.widthCm, firstDimensions.width)
&& closeTo(firstItem?.heightCm, firstDimensions.height),
@@ -220,8 +223,10 @@ export async function run(context) {
`version=${countResult?.measurementVersion ?? 'missing'}`, OPTIONS)
const replacement = { length: 59.5, width: 41.2, height: 31.3, weight: 13.6 }
const replacementShipmentId = `FBA-${context.marker.slice(-12)}-02`
const rescanResponse = await multipartRequest(context, scanPath, {
boxCode, ...replacement, machineNo: 'MJ-ADMIN-E2E-02', measuredAt: new Date().toISOString().slice(0, 19),
boxCode, ...replacement, scannedShipmentId: replacementShipmentId,
machineNo: 'MJ-ADMIN-E2E-02', measuredAt: new Date().toISOString().slice(0, 19),
})
const rescan = context.apiSuccess(MODULE, '同箱号重新扫描覆盖当前记录', rescanResponse,
`boxCode=${boxCode}, machineNo=MJ-ADMIN-E2E-02`, OPTIONS)
@@ -244,6 +249,7 @@ export async function run(context) {
context.assert(MODULE, '覆盖尺寸、箱数和服务端体积公式正确', measuredResponse,
measuredItem && closeTo(measuredItem.lengthCm, replacement.length)
&& closeTo(measuredItem.widthCm, replacement.width) && closeTo(measuredItem.heightCm, replacement.height)
&& measuredItem.scannedShipmentId === replacementShipmentId
&& Number(measuredItem.confirmedPackageCount) === originalPackageCount
&& closeTo(measuredItem.outerLengthCm, weightedOuter.length)
&& closeTo(measuredItem.outerWidthCm, weightedOuter.width)
@@ -1,10 +1,23 @@
import { registerPendingContract } from './_phase3-pending-contract.mjs'
const MODULE = 'phase3-dispatch-gate'
const OPTIONS = { scenario: 'domestic-dispatch-gate', deploymentBlocker: true }
const BASE = '/api/platform/v1/first-leg/outbound-dispatches'
export async function run(context) {
registerPendingContract(context, {
module: 'phase3-dispatch-gate', scenario: 'domestic-dispatch-gate', name: '国内出仓统一门禁',
reason: '统一门禁、confirm-dispatch/reverse-dispatch 已实现并推送,待目标提交部署且真实 HTTP 通过后删除此项', category: 'deployment-validation-pending',
fixtures: ['phase3Loading', 'phase3ContainerLoading', 'oceanBooking', 'truckAppointment'], contractSource: 'PlatformOutboundDispatchController / phase3-outbound-dispatch-v1.yaml',
assertions: ['门禁逐项返回真实阻断原因', '旧 version 和重复确认安全冲突', '确认与撤销均保留审计时间线'],
})
const fixture = context.createdResources?.phase3OutboundDispatch
if (!fixture?.inboundId || !fixture?.containerBookingId || fixture.marker !== context.marker) {
context.addCoverageGap(MODULE, OPTIONS.scenario, '订舱/拖车/报关/PDA/五类证据统一硬门禁',
'本轮未取得 phase3-outbound-dispatch 的 marker 隔离聚合,未使用历史资源', 'fixture')
return
}
const selector = `inboundId=${encodeURIComponent(fixture.inboundId)}&containerBookingId=${encodeURIComponent(fixture.containerBookingId)}`
const response = await context.request('GET', `${BASE}/check-gate?${selector}`)
const gate = context.apiSuccess(MODULE, '复核国内出仓统一硬门禁', response, selector, OPTIONS)
const items = Array.isArray(gate?.items) ? gate.items : []
const required = ['INBOUND_LOADED', 'LOADING_PLAN_COMPLETED', 'PDA_PICK_COMPLETED',
'OCEAN_BOOKING_RELEASED', 'TRUCK_DEPARTED', 'LOADING_EVIDENCE_COMPLETE',
'CUSTOMS_CLEARANCE', 'SAILING_SCHEDULE']
context.assert(MODULE, '八项业务门禁全部由服务端真实判定并通过', response,
gate?.passed === true && required.every((code) => items.some((item) => item.code === code
&& item.passed === true && item.actual !== 'MODULE_UNAVAILABLE' && item.actual !== 'ASSESSMENT_ERROR')),
`passed=${gate?.passed ?? 'missing'}, gates=${items.map((item) => `${item.code}:${item.passed}`).join(',')}`, OPTIONS)
}
@@ -1,10 +1,32 @@
import { registerPendingContract } from './_phase3-pending-contract.mjs'
const MODULE = 'phase3-evidence-gate'
const OPTIONS = { scenario: 'loading-evidence-gate', deploymentBlocker: true }
function id(value) { return value == null ? '' : String(value) }
export async function run(context) {
registerPendingContract(context, {
module: 'phase3-evidence-gate', scenario: 'loading-evidence-gate', name: '四步照片与铅封证据完整性门禁',
reason: '五类证据、真实文件归属和柜次 PDA 复核门禁已实现并推送,待目标提交部署且 phase3-loading 真实 HTTP 通过后删除此项', category: 'deployment-validation-pending',
fixtures: ['phase3Loading', 'phase3ContainerLoading'], contractSource: 'PlatformLoadingDeliveryController / phase3-loading-delivery-v1.yaml',
assertions: ['四步照片和铅封均绑定本轮柜次', '缺任一证据时完成装柜被拒绝', '全部证据与 PDA 复核齐备后幂等完成'],
})
const fixture = context.createdResources?.phase3Loading
if (!fixture?.tenantId || !fixture?.inboundId || fixture.marker !== context.marker) {
context.addCoverageGap(MODULE, OPTIONS.scenario, '五类证据多图追加、作废审计和有效证据门禁',
'本轮未取得 phase3-loading 的 marker 隔离证据 fixture,未使用历史资源', 'fixture')
return
}
const path = `/api/platform/v1/inbounds/${fixture.inboundId}/loading/evidence?tenantId=${encodeURIComponent(fixture.tenantId)}`
const response = await context.request('GET', path)
const data = context.apiSuccess(MODULE, '复核本轮装柜证据聚合', response, `inboundId=${fixture.inboundId}`, OPTIONS)
const evidences = Array.isArray(data?.evidences) ? data.evidences : []
const required = ['PHOTO_STEP_1', 'PHOTO_STEP_2', 'PHOTO_STEP_3', 'PHOTO_STEP_4', 'SEAL']
const active = evidences.filter((item) => item.status !== 'VOID')
const voided = evidences.find((item) => id(item.id) === id(fixture.voidedEvidenceId))
context.assert(MODULE, '五类有效证据齐全且同类型多图追加不覆盖历史', response,
required.every((type) => active.some((item) => item.evidenceType === type))
&& active.filter((item) => item.evidenceType === 'PHOTO_STEP_1').length >= 1
&& active.some((item) => item.evidenceType === 'SEAL' && Boolean(String(item.sealNo || '').trim()))
&& active.every((item) => String(item.fileName || '').includes(context.marker)
&& String(item.remark || '').includes(context.marker)),
`active=${active.length}, types=${[...new Set(active.map((item) => item.evidenceType))].join(',')}`, OPTIONS)
context.assert(MODULE, '作废证据保留原因、操作者和时间且不计入有效门禁', response,
Boolean(voided) && voided.status === 'VOID' && voided.voidReason === `${context.marker}-wrong-photo`
&& Boolean(voided.voidedBy) && Boolean(voided.voidedAt)
&& !active.some((item) => id(item.id) === id(fixture.voidedEvidenceId)),
`voidedEvidenceId=${id(fixture.voidedEvidenceId) || 'missing'}, status=${voided?.status || 'missing'}`, OPTIONS)
}
@@ -0,0 +1,75 @@
const MODULE = 'phase3-loading-finalize'
const OPTIONS = { scenario: 'phase3-loading-hard-gate-finalize', deploymentBlocker: true }
function id(value) { return value == null ? '' : String(value) }
async function request(context, method, path, body, headers = {}) {
try {
const response = await fetch(`${context.options.gateway}${path}`, {
method,
headers: { Accept: 'application/json', Authorization: `Bearer ${context.token}`,
...(body === undefined ? {} : { 'Content-Type': 'application/json; charset=utf-8' }), ...headers },
body: body === undefined ? undefined : JSON.stringify(body), signal: AbortSignal.timeout(60_000),
})
const raw = await response.text(); let payload = null
try { payload = raw ? JSON.parse(raw) : null } catch { /* bounded raw evidence */ }
return { method, path, http: response.status, body: payload,
raw: payload === null ? raw.slice(0, 500) : null,
requestId: payload?.requestId || response.headers.get('x-request-id'),
traceId: payload?.traceId || response.headers.get('x-trace-id') }
} catch (error) {
return { method, path, http: 0, body: null, raw: String(error), requestId: null, traceId: null }
}
}
export async function run(context) {
const fixture = context.createdResources?.phase3Loading
const tenantId = id(fixture?.tenantId); const inboundId = id(fixture?.inboundId)
if (!tenantId || !inboundId || fixture?.marker !== context.marker
|| fixture?.loadingPlanStatus !== 'COMPLETED') {
context.addStep(MODULE, '取得下游门禁待完成装柜 fixture', null, false,
`tenantId=${tenantId || 'missing'}, inboundId=${inboundId || 'missing'}, marker=${fixture?.marker || 'missing'}, plan=${fixture?.loadingPlanStatus || 'missing'}`, OPTIONS)
return
}
const detailPath = `/api/platform/inbounds/${inboundId}?tenantId=${encodeURIComponent(tenantId)}`
const beforeResponse = await context.request('GET', detailPath)
const before = context.apiSuccess(MODULE, '读取下游门禁齐备后的装柜状态', beforeResponse, '', OPTIONS)
const version = Number(before?.summary?.version)
context.assert(MODULE, '最终装柜前保持 LOADING 且版本有效', beforeResponse,
before?.summary?.processStatus === 'LOADING' && Number.isInteger(version),
`status=${before?.summary?.processStatus || 'missing'}, version=${before?.summary?.version ?? 'missing'}`, OPTIONS)
if (!Number.isInteger(version)) return
const base = `/api/platform/v1/inbounds/${inboundId}`
const completeResponse = await request(context, 'POST',
`${base}/loading/complete?tenantId=${encodeURIComponent(tenantId)}`,
{ expectedVersion: version, remark: context.marker },
{ 'Idempotency-Key': `${context.marker}-p3-complete-after-downstream`.slice(0, 128) })
const completed = context.apiSuccess(MODULE, '订舱拖车报关齐备后完成装柜', completeResponse, '', OPTIONS)
const evidences = completed?.evidences?.evidences || []
context.assert(MODULE, '统一硬门禁通过后推进 LOADED 且五类有效证据仍完整', completeResponse,
completed?.mainStatus === 'LOADED' && fixture.evidenceTypes?.every?.((type) =>
evidences.some((item) => item.evidenceType === type && item.status !== 'VOID')),
`mainStatus=${completed?.mainStatus || 'missing'}, evidences=${evidences.length}`, OPTIONS)
const replayResponse = await request(context, 'POST',
`${base}/loading/complete?tenantId=${encodeURIComponent(tenantId)}`,
{ expectedVersion: version, remark: context.marker },
{ 'Idempotency-Key': `${context.marker}-p3-complete-after-downstream`.slice(0, 128) })
context.assert(MODULE, 'LOADED 完成请求 Idempotency-Key 重放保持终态', replayResponse,
replayResponse.http === 200 && String(replayResponse.body?.code) === '200'
&& replayResponse.body?.data?.mainStatus === 'LOADED',
`HTTP=${replayResponse.http}, code=${replayResponse.body?.code ?? 'missing'}, status=${replayResponse.body?.data?.mainStatus || 'missing'}`, OPTIONS)
const finalResponse = await context.request('GET', detailPath)
const finalData = context.apiSuccess(MODULE, '回查三期装柜完成终态', finalResponse, '', OPTIONS)
context.assert(MODULE, '入库单终态 LOADED、版本递增且审计历史存在', finalResponse,
finalData?.summary?.processStatus === 'LOADED' && Number(finalData?.summary?.version) === version + 1
&& finalData?.statusHistory?.some?.((item) => item.action === 'COMPLETE_LOADING'
&& item.operatorName && item.fromStatus === 'LOADING' && item.toStatus === 'LOADED'),
`status=${finalData?.summary?.processStatus || 'missing'}, version=${finalData?.summary?.version ?? 'missing'}, histories=${finalData?.statusHistory?.length ?? 'n/a'}`, OPTIONS)
context.createdResources.phase3Loading = {
...fixture, inboundVersion: Number(finalData?.summary?.version), inboundStatus: 'LOADED', finalStatus: 'LOADED',
}
}
@@ -25,9 +25,6 @@ export async function run(context) {
{ activation: { state: 'pending-fixture', assertions: ['双向关联可查', '双版本冲突原子回滚', '终态门禁一致'] } })
return
}
context.addCoverageGap(MODULE, OPTIONS.scenario, '入库单级预装与柜次级智能装柜串联',
'桥接契约、SQL和真实断言已完成,待目标提交部署并取得本模块真实 HTTP PASS 后删除此项',
'deployment-validation-pending', { activation: { state: 'pending-deployment-validation' } })
const inboundPath = `/api/platform/v1/inbounds/${inboundId}/preload/loading-plans?tenantId=${encodeURIComponent(tenantId)}`
const inboundResponse = await request(context, 'GET', inboundPath)
const inboundLinks = context.apiSuccess(MODULE, '从入库侧查询预装与柜次关联', inboundResponse, '', OPTIONS)
@@ -227,6 +227,32 @@ export async function run(context) {
claimed?.workflowStatus === 'IN_PROGRESS' && Boolean(claimed?.assignment?.assigneeId),
`workflow=${claimed?.workflowStatus || 'missing'}`, OPTIONS)
const itemClaimBody = {
expectedAssignmentVersion: 0,
operationId: `${context.marker}-bridge-item-claim`.slice(0, 128),
}
const itemClaim = await request(context, 'POST',
`${pdaBase}/tasks/${canonicalTaskId}/items/${id(canonicalItem.id)}/claim`, itemClaimBody)
const itemClaimed = context.apiSuccess(MODULE, '领取柜次 PDA 明细单人作业权', itemClaim, '', OPTIONS)
const claimedItem = itemClaimed?.items?.find?.((item) => id(item.id) === id(canonicalItem.id))
context.assert(MODULE, 'PDA 明细作业员与任务领取人一致', itemClaim,
id(claimedItem?.assignment?.assigneeId) === id(itemClaimed?.assignment?.assigneeId)
&& Number(claimedItem?.assignment?.version) === 0,
`taskAssignee=${id(itemClaimed?.assignment?.assigneeId) || 'missing'}, itemAssignee=${id(claimedItem?.assignment?.assigneeId) || 'missing'}`, OPTIONS)
const itemClaimReplay = await request(context, 'POST',
`${pdaBase}/tasks/${canonicalTaskId}/items/${id(canonicalItem.id)}/claim`, itemClaimBody)
context.assert(MODULE, 'PDA 明细领取 operationId 幂等重放', itemClaimReplay,
codeOf(itemClaimReplay) === '200'
&& id(itemClaimReplay.body?.data?.items?.find?.((item) => id(item.id) === id(canonicalItem.id))?.assignment?.assigneeId)
=== id(claimedItem?.assignment?.assigneeId),
`HTTP=${itemClaimReplay.http}, code=${codeOf(itemClaimReplay)}`, OPTIONS)
const claimHashConflict = await request(context, 'POST',
`${pdaBase}/tasks/${canonicalTaskId}/items/${id(canonicalItem.id)}/claim`, {
...itemClaimBody, expectedAssignmentVersion: 1,
})
context.addStep(MODULE, 'PDA 明细同 operationId 不同版本请求被拒绝', claimHashConflict,
failure(claimHashConflict), `HTTP=${claimHashConflict.http}, code=${codeOf(claimHashConflict)}`, OPTIONS)
const canonicalPick = await request(context, 'POST',
`${pdaBase}/tasks/${canonicalTaskId}/items/${id(canonicalItem.id)}/pick`, {
warehouseId, pickedPackageCount: 1, locationIds: [], version: Number(canonicalItem.version),
@@ -370,26 +396,18 @@ export async function run(context) {
&& evidenceListData.evidences.some((item) => item.evidenceType === 'SEAL' && item.sealNo === `SEAL-${suffix}`),
`evidences=${evidenceListData?.evidences?.length ?? 'n/a'}`, OPTIONS)
const complete = await request(context, 'POST', `${base}/loading/complete?tenantId=${encodeURIComponent(tenantId)}`,
{ expectedVersion: loadingVersion, remark: context.marker }, { 'Idempotency-Key': `${context.marker}-p3-complete`.slice(0, 128) })
const completed = context.apiSuccess(MODULE, '确认本轮入库单装柜完成', complete, '', OPTIONS)
context.assert(MODULE, '装柜完成推进主状态 LOADED 且保留五类证据', complete,
completed?.mainStatus === 'LOADED' && completed?.evidences?.evidences?.length >= evidenceTypes.length,
`mainStatus=${completed?.mainStatus || 'missing'}, evidences=${completed?.evidences?.evidences?.length ?? 'n/a'}`, OPTIONS)
const blockedBeforeDownstream = await request(context, 'POST', `${base}/loading/complete?tenantId=${encodeURIComponent(tenantId)}`,
{ expectedVersion: loadingVersion, remark: `${context.marker}-before-downstream` },
{ 'Idempotency-Key': `${context.marker}-p3-complete-before-downstream`.slice(0, 128) })
context.addStep(MODULE, '订舱拖车报关未齐备时 LOADED 硬门禁拒绝', blockedBeforeDownstream,
failure(blockedBeforeDownstream),
`HTTP=${blockedBeforeDownstream.http}, code=${codeOf(blockedBeforeDownstream)}`, OPTIONS)
const finalResponse = await context.request('GET', detailPath)
const finalData = context.apiSuccess(MODULE, '回查三期装柜完成终态', finalResponse, '', OPTIONS)
context.assert(MODULE, '入库单终态 LOADED、版本递增且审计历史存在', finalResponse,
finalData?.summary?.processStatus === 'LOADED' && Number(finalData?.summary?.version) === loadingVersion + 1
&& finalData?.statusHistory?.some?.((item) => item.action === 'COMPLETE_LOADING' && item.operatorName),
`status=${finalData?.summary?.processStatus || 'missing'}, version=${finalData?.summary?.version ?? 'missing'}, histories=${finalData?.statusHistory?.length ?? 'n/a'}`, OPTIONS)
context.createdResources.phase3Loading = {
tenantId, inboundId, preloadPlanId: planId, evidenceIds: evidenceItems.map((item) => id(item.id)),
voidedEvidenceId: id(voidTarget?.id), evidenceTypes,
loadingPlanId, containerBookingId, containerNo, warehouseId, canonicalPdaTaskId: canonicalTaskId,
pickingTaskId: id(pickingCompleted?.id), marker: context.marker, finalStatus: 'LOADED',
pickingTaskId: id(pickingCompleted?.id), inboundVersion: loadingVersion,
marker: context.marker, inboundStatus: 'LOADING', loadingPlanStatus: 'COMPLETED', finalStatus: 'COMPLETED',
}
context.addCoverageGap(MODULE, OPTIONS.scenario, 'PDA 真机在线限制与设备持久化草稿批量提交',
'当前验收运行器只能发起平台 HTTP 请求,未具备 PDA 真机断网、设备草稿隔离及批量提交端点的可执行环境',
'device-and-batch-fixture')
}
@@ -0,0 +1,30 @@
const MODULE = 'phase3-order-splitting'
const SCENARIO = 'parent-child-multi-container-consolidation'
export async function run(context) {
const fixture = context.createdResources?.phase3Loading
|| context.createdResources?.phase3ContainerLoading
const metadata = {
fixture: {
available: Boolean(fixture?.inboundId && fixture?.containerBookingId),
marker: fixture?.marker || null,
inboundId: fixture?.inboundId || null,
containerBookingId: fixture?.containerBookingId || null,
},
activation: {
state: 'pending-public-contract',
assertions: [
'父单与自动剩余子单关系可由 HTTP 查询',
'已装数量 + 自动子单剩余数量 = 拆分前数量',
'同一订单可分配多个柜次且同柜可包含多个订单',
'子单仅允许一层且继续拆分被拒绝',
],
},
}
context.addCoverageGap(MODULE, SCENARIO, '父/子订单拆分、装载数量守恒与剩余自动子订单',
'PDA partial/skip 内部结算已实现,但公开 InboundOrderSummary/Detail 未返回 inboundRole、parentInboundId、rootInboundId、splitStatus 或拆分批次,HTTP 总控无法证明父子关系和守恒,不能用同 orderId 的记录数量伪造成功',
'contract-gap', metadata)
context.addCoverageGap(MODULE, SCENARIO, '一单多柜与多单拼柜',
'SmartLoadingController 支持按明细分配,但当前公开契约没有订单-多柜/柜次-多订单关系聚合,也没有本轮安全 fixture 一次生成两个可装柜入库单;待真实查询 DTO 与专用 fixture 接口公开后转为断言',
'contract-gap', metadata)
}
@@ -1,11 +1,52 @@
import { registerPendingContract } from './_phase3-pending-contract.mjs'
const MODULE = 'phase3-outbound-aggregate'
const OPTIONS = { scenario: 'outbound-aggregate', deploymentBlocker: true }
const BASE = '/api/platform/v1/first-leg/outbound-dispatches'
function id(value) { return value == null ? '' : String(value) }
function codeOf(response) { return response?.body?.code == null ? 'missing' : String(response.body.code) }
function rejected(response) {
return [400, 401, 403, 404, 409, 503].includes(response?.http)
|| (response?.http === 200 && codeOf(response) !== '200')
}
function ordered(items) {
return items.every((item, index) => index === 0
|| String(items[index - 1]?.occurredAt || '') <= String(item?.occurredAt || ''))
}
export async function run(context) {
registerPendingContract(context, {
module: 'phase3-outbound-aggregate', scenario: 'outbound-aggregate', name: '出仓单/柜次主聚合与整体时间线',
reason: '出仓主聚合与整体时间线契约已实现并推送,待目标提交部署且 phase3-outbound-dispatch 真实 HTTP 通过后删除此项', category: 'deployment-validation-pending',
fixtures: ['orders', 'phase3Loading', 'phase3ContainerLoading', 'oceanBooking', 'truckAppointment'],
contractSource: 'PlatformOutboundDispatchController / phase3-outbound-dispatch-v1.yaml',
assertions: ['marker 所属主单与柜次关联唯一', '时间线按真实动作有序且含审计字段', '跨客户 ID 不可见'],
})
const fixture = context.createdResources?.phase3OutboundDispatch
if (!fixture?.inboundId || !fixture?.containerBookingId || fixture.marker !== context.marker) {
context.addCoverageGap(MODULE, OPTIONS.scenario, '出仓单/柜次主聚合与整体时间线',
'本轮未取得 phase3-outbound-dispatch 的 marker 隔离聚合,未使用历史资源', 'fixture')
return
}
const selector = `inboundId=${encodeURIComponent(fixture.inboundId)}&containerBookingId=${encodeURIComponent(fixture.containerBookingId)}`
const response = await context.request('GET', `${BASE}/detail?${selector}`)
const detail = context.apiSuccess(MODULE, '复核出仓主聚合与统一时间线', response, selector, OPTIONS)
const aggregate = detail?.aggregate
const timeline = Array.isArray(detail?.timeline) ? detail.timeline : []
const expectedModules = ['INBOUND', 'LOADING_PLAN', 'PDA_PICK', 'LOADING_EVIDENCE',
'OCEAN_BOOKING', 'TRUCK_APPOINTMENT', 'OUTBOUND_DISPATCH']
context.assert(MODULE, '聚合唯一关联本轮订单、入库单、柜次和客户', response,
id(aggregate?.orderId) === id(fixture.orderId) && id(aggregate?.tenantId) === id(fixture.tenantId)
&& id(aggregate?.inboundId) === id(fixture.inboundId)
&& id(aggregate?.containerBookingId) === id(fixture.containerBookingId),
`orderId=${id(aggregate?.orderId) || 'missing'}, inboundId=${id(aggregate?.inboundId) || 'missing'}, containerBookingId=${id(aggregate?.containerBookingId) || 'missing'}`, OPTIONS)
context.assert(MODULE, '统一时间线有序且各子流程包含审计字段', response,
timeline.length > 0 && ordered(timeline)
&& expectedModules.every((module) => timeline.some((item) => item.module === module))
&& timeline.every((item) => Boolean(item.action) && Boolean(item.occurredAt)),
`timeline=${timeline.length}, modules=${[...new Set(timeline.map((item) => item.module))].join(',')}`, OPTIONS)
const other = context.createdResources?.phase3ContainerLoading
if (other?.inboundId && other?.containerBookingId
&& (id(other.inboundId) !== id(fixture.inboundId) || id(other.containerBookingId) !== id(fixture.containerBookingId))) {
const forged = await context.request('GET', `${BASE}/detail?inboundId=${encodeURIComponent(fixture.inboundId)}&containerBookingId=${encodeURIComponent(other.containerBookingId)}`)
context.addStep(MODULE, '伪造跨资源入库单与柜次组合不可匹配', forged, rejected(forged),
`HTTP=${forged.http}, code=${codeOf(forged)}`, OPTIONS)
}
context.addCoverageGap(MODULE, OPTIONS.scenario, '报关与船期历史并入统一时间线',
'当前 OutboundDispatchReadMapper 时间线仅聚合入库、装柜计划、PDA、证据、订舱、拖车和出仓历史,未公开报关与船期历史投影',
'contract-gap')
}
@@ -93,7 +93,7 @@ export async function run(context) {
const confirmed = context.apiSuccess(MODULE, '确认国内出仓进入等待装船', confirmResponse, '', OPTIONS)
context.assert(MODULE, 'confirm-dispatch 推进 WAITING_FOR_LOADING 并递增版本', confirmResponse,
confirmed?.aggregate?.dispatchStatus === 'WAITING_FOR_LOADING'
&& confirmed?.aggregate?.inboundStatus === 'WAITING_FOR_LOADING'
&& confirmed?.aggregate?.inboundStatus === 'LOADED'
&& Number(confirmed?.aggregate?.version) === expectedVersion + 1,
`dispatch=${confirmed?.aggregate?.dispatchStatus || 'missing'}, inbound=${confirmed?.aggregate?.inboundStatus || 'missing'}, version=${confirmed?.aggregate?.version ?? 'missing'}`, OPTIONS)
@@ -119,4 +119,16 @@ export async function run(context) {
reversed?.aggregate?.dispatchStatus === 'READY_FOR_DISPATCH' && reversed?.aggregate?.inboundStatus === 'LOADED'
&& reversed?.timeline?.some?.((item) => item.module === 'OUTBOUND_DISPATCH' && item.action === 'REVERSE_DISPATCH'),
`dispatch=${reversed?.aggregate?.dispatchStatus || 'missing'}, inbound=${reversed?.aggregate?.inboundStatus || 'missing'}`, OPTIONS)
if (reversed?.aggregate) {
context.createdResources.phase3OutboundDispatch = {
marker: context.marker, inboundId, containerBookingId,
orderId: id(reversed.aggregate.orderId), tenantId: id(reversed.aggregate.tenantId),
confirmedStatus: confirmed?.aggregate?.dispatchStatus || null,
confirmedInboundStatus: confirmed?.aggregate?.inboundStatus || null,
confirmedVersion: Number(confirmed?.aggregate?.version),
finalStatus: reversed.aggregate.dispatchStatus,
finalInboundStatus: reversed.aggregate.inboundStatus,
finalVersion: Number(reversed.aggregate.version),
}
}
}
@@ -25,9 +25,6 @@ export async function run(context) {
'本轮未取得 marker 隔离的柜次 PDA 与入库汇总 fixture,未使用历史资源', 'fixture')
return
}
context.addCoverageGap(MODULE, OPTIONS.scenario, 'PDA 柜次拣货与入库单汇总拣货收敛',
'PDA唯一事实源、作业员隔离、复核和入库聚合真实断言已完成,待目标提交部署并取得真实 HTTP PASS 后删除此项',
'deployment-validation-pending', { activation: { state: 'pending-deployment-validation' } })
const taskResponse = await request(context, 'GET',
`/api/platform/v1/first-leg/pda-loading/tasks?containerNo=${encodeURIComponent(containerNo)}&warehouseId=${encodeURIComponent(warehouseId)}`)
const task = context.apiSuccess(MODULE, '回查柜次 PDA 唯一事实任务', taskResponse, '', OPTIONS)
@@ -47,7 +44,7 @@ export async function run(context) {
`/api/platform/v1/first-leg/pda-loading/tasks/${taskId}/operations`)
const operations = context.apiSuccess(MODULE, '查询柜次 PDA 不可变操作历史', operationsResponse, '', OPTIONS)
context.assert(MODULE, '领取和复核操作历史含操作者与时间', operationsResponse,
Array.isArray(operations) && ['CLAIM', 'REVIEW'].every((action) => operations.some((item) => item.actionType === action
Array.isArray(operations) && ['CLAIM', 'ITEM_CLAIM', 'REVIEW'].every((action) => operations.some((item) => item.actionType === action
&& Boolean(item.operatorId) && Boolean(item.createdAt))),
`actions=${Array.isArray(operations) ? operations.map((item) => item.actionType).join(',') : 'missing'}`, OPTIONS)
const forged = await request(context, 'POST',
@@ -56,4 +53,14 @@ export async function run(context) {
{ 'Idempotency-Key': `${context.marker}-pda-forged-projection`.slice(0, 128) })
context.addStep(MODULE, '入库兼容入口拒绝客户端伪造汇总数量', forged, failure(forged),
`HTTP=${forged.http}, code=${codeOf(forged)}`, OPTIONS)
context.addCoverageGap(MODULE, OPTIONS.scenario, 'PDA 批量提交、设备草稿版本与批次幂等',
'当前 PlatformLoadingPdaController 仅公开单明细 pick/partial/skip 与任务 review,没有批量提交或设备草稿 DTO/OpenAPI',
'contract-gap')
context.addCoverageGap(MODULE, OPTIONS.scenario, 'PDA 实时库存查询与提交前库存快照校验',
'当前 PDA Controller/OpenAPI 未公开实时库存查询或库存版本快照端点,不能用智能装柜候选列表伪装库存契约',
'contract-gap')
context.addCoverageGap(MODULE, OPTIONS.scenario, '不同仓库作业员竞争同一 PDA 明细',
'单明细领取和版本 CAS 已自动化;当前总控没有第二个具备 warehouse PDA work 权限的隔离账号 fixture,不能伪造跨操作者冲突',
'fixture')
}
@@ -71,6 +71,15 @@ function scheduleData(context, suffix, oceanBookingId, containerBookingId, expir
}
export async function run(context) {
context.addCoverageGap(MODULE, OPTIONS.scenario, '官网船期查询任务、3天窗口最多3次及失败/过期状态',
'当前 PlatformPortScheduleController/OpenAPI 仅公开来源观测 CRUD,没有官网查询 task、3天计数、FAILED/EXPIRED 或任务级人工兜底端点',
'contract-gap')
context.addCoverageGap(MODULE, OPTIONS.scenario, 'ZIM 官网 hCaptcha 自动查询',
'ZIM hCaptcha 需要第三方交互能力,仓库未公开 provider/task 契约;保留为外部依赖缺口',
'external-third-party')
context.addCoverageGap(MODULE, OPTIONS.scenario, 'COSCO 动态页面自动查询',
'COSCO 动态页面没有已公开 provider/task 契约或稳定机器接口;保留为外部依赖缺口',
'external-third-party')
const suffix = context.marker.replace(/\D/g, '').slice(-10)
const probe = await request(context, 'GET', `${BASE}?page=1&size=5&keyword=${encodeURIComponent(context.marker)}`)
if (probe.http === 404 || probe.http === 405 || probe.http === 503 || probe.http === 0) {
@@ -180,14 +189,18 @@ export async function run(context) {
const currentData = scheduleData(context, suffix, ocean.id, knownAllocation, false)
currentData.sourceRef = payload.data.sourceRef
currentData.sourceType = 'MANUAL'
currentData.sourceName = `平台人工兜底-${suffix}`
const refreshResponse = await request(context, 'PUT', `${BASE}/${scheduleId}`,
{ expectedVersion: initialVersion + 1, data: currentData, reason: '刷新为当前有效船期' },
{ 'Idempotency-Key': `${context.marker}-port-refresh`.slice(0, 128) })
const refreshed = context.apiSuccess(MODULE, '刷新船期为国内出仓可用终态', refreshResponse, '', OPTIONS)
context.assert(MODULE, '刷新后船期有效且版本再次递增', refreshResponse,
refreshed?.portSchedule?.expired === false
&& refreshed?.portSchedule?.schedule?.sourceType === 'MANUAL'
&& refreshed?.portSchedule?.schedule?.sourceName === currentData.sourceName
&& Number(refreshed?.portSchedule?.schedule?.version) === initialVersion + 2,
`expired=${refreshed?.portSchedule?.expired ?? 'missing'}, version=${refreshed?.portSchedule?.schedule?.version ?? 'missing'}`, OPTIONS)
`expired=${refreshed?.portSchedule?.expired ?? 'missing'}, sourceType=${refreshed?.portSchedule?.schedule?.sourceType || 'missing'}, version=${refreshed?.portSchedule?.schedule?.version ?? 'missing'}`, OPTIONS)
if (knownAllocation && inboundId) {
const selector = `inboundId=${encodeURIComponent(inboundId)}&containerBookingId=${encodeURIComponent(knownAllocation)}`
@@ -1,10 +1,30 @@
import { registerPendingContract } from './_phase3-pending-contract.mjs'
const MODULE = 'phase3-waiting-for-loading'
const OPTIONS = { scenario: 'waiting-for-loading-status', deploymentBlocker: true }
const BASE = '/api/platform/v1/first-leg/outbound-dispatches'
export async function run(context) {
registerPendingContract(context, {
module: 'phase3-waiting-for-loading', scenario: 'waiting-for-loading-status', name: 'WAITING_FOR_LOADING 统一终态',
reason: 'WAITING_FOR_LOADING、查询和状态时间线已实现并推送,待目标提交部署且 confirm/reverse 真实 HTTP 通过后删除此项', category: 'deployment-validation-pending',
fixtures: ['phase3Loading', 'phase3ContainerLoading'], contractSource: 'OutboundDispatchStatus / phase3-outbound-dispatch-v1.yaml',
assertions: ['本轮出仓完成后进入 WAITING_FOR_LOADING', '列表与详情状态一致', '历史记录来源状态、操作者和时间完整'],
})
const fixture = context.createdResources?.phase3OutboundDispatch
if (!fixture?.inboundId || !fixture?.containerBookingId || fixture.marker !== context.marker) {
context.addCoverageGap(MODULE, OPTIONS.scenario, 'WAITING_FOR_LOADING 状态与历史',
'本轮未取得 phase3-outbound-dispatch 的 marker 隔离聚合,未使用历史资源', 'fixture')
return
}
const selector = `inboundId=${encodeURIComponent(fixture.inboundId)}&containerBookingId=${encodeURIComponent(fixture.containerBookingId)}`
const response = await context.request('GET', `${BASE}/detail?${selector}`)
const detail = context.apiSuccess(MODULE, '回查 WAITING_FOR_LOADING 状态历史', response, selector, OPTIONS)
const history = Array.isArray(detail?.timeline)
? detail.timeline.filter((item) => item.module === 'OUTBOUND_DISPATCH') : []
const confirmed = history.find((item) => item.action === 'CONFIRM_DISPATCH')
const reversed = history.find((item) => item.action === 'REVERSE_DISPATCH')
context.assert(MODULE, '确认出仓真实进入 WAITING_FOR_LOADING', response,
fixture.confirmedStatus === 'WAITING_FOR_LOADING'
&& fixture.confirmedInboundStatus === 'LOADED'
&& confirmed?.fromStatus === 'READY_FOR_DISPATCH' && confirmed?.toStatus === 'WAITING_FOR_LOADING'
&& Boolean(confirmed?.operatorId) && Boolean(confirmed?.operatorName) && Boolean(confirmed?.occurredAt),
`confirmed=${confirmed?.fromStatus || 'missing'}->${confirmed?.toStatus || 'missing'}, version=${fixture.confirmedVersion ?? 'missing'}`, OPTIONS)
context.assert(MODULE, '撤销后状态恢复且 WAITING 历史不可变', response,
detail?.aggregate?.dispatchStatus === 'READY_FOR_DISPATCH' && detail?.aggregate?.inboundStatus === 'LOADED'
&& reversed?.fromStatus === 'WAITING_FOR_LOADING' && reversed?.toStatus === 'READY_FOR_DISPATCH'
&& Boolean(reversed?.operatorId) && Boolean(reversed?.occurredAt),
`current=${detail?.aggregate?.dispatchStatus || 'missing'}, reversed=${reversed?.fromStatus || 'missing'}->${reversed?.toStatus || 'missing'}`, OPTIONS)
}
@@ -6,6 +6,30 @@ const TRUCK = '/api/platform/v1/truck-appointments'
function id(value) { return value == null ? '' : String(value) }
function codeOf(response) { return response?.body?.code == null ? 'missing' : String(response.body.code) }
async function actionRequest(context, path, endpoint, version) {
try {
const response = await fetch(`${context.options.gateway}${path}/${endpoint}`, {
method: 'POST',
headers: {
Accept: 'application/json', Authorization: `Bearer ${context.token}`,
'Content-Type': 'application/json; charset=utf-8',
'Idempotency-Key': `${context.marker}-flow-${endpoint}`.slice(0, 128),
},
body: JSON.stringify({ expectedVersion: version, reason: context.marker }),
signal: AbortSignal.timeout(60_000),
})
const raw = await response.text(); let payload = null
try { payload = raw ? JSON.parse(raw) : null } catch { /* bounded raw evidence */ }
return { method: 'POST', path: `${path}/${endpoint}`, http: response.status, body: payload,
raw: payload === null ? raw.slice(0, 500) : null,
requestId: payload?.requestId || response.headers.get('x-request-id'),
traceId: payload?.traceId || response.headers.get('x-trace-id') }
} catch (error) {
return { method: 'POST', path: `${path}/${endpoint}`, http: 0, body: null,
raw: String(error), requestId: null, traceId: null }
}
}
export async function run(context) {
const ocean = context.createdResources?.oceanBooking
const containerFlow = context.createdResources?.phase3Loading
@@ -76,27 +100,42 @@ export async function run(context) {
appointmentId, oceanBookingId: ocean.id,
containerBookingId: linkContainer ? id(containerFlow.containerBookingId) : null,
loadingPlanId: linkContainer ? id(containerFlow.loadingPlanId) : null,
marker: context.marker, finalStatus: 'CANCELLED',
marker: context.marker, finalStatus: 'COMPLETED',
}
const path = `${TRUCK}/${appointmentId}`
let version = Number(appointment.version)
for (const [name, endpoint, status] of [
['提交跨链路预约', 'submit', 'PENDING_DISPATCH'],
['派发跨链路拖车', 'dispatch', 'DISPATCHED'],
['跨链路开始提货', 'pickup', 'PICKUP_IN_PROGRESS'],
['跨链路拖车到仓', 'arrive', 'ARRIVED_WAREHOUSE'],
['跨链路开始装货', 'load', 'LOADING'],
['跨链路拖车离仓', 'depart', 'DEPARTED'],
['完成跨链路拖车', 'complete', 'COMPLETED'],
]) {
const action = await actionRequest(context, path, endpoint, version)
const changed = context.apiSuccess(MODULE, name, action, '', OPTIONS)
context.assert(MODULE, `${name}状态正确`, action, changed?.status === status,
`status=${changed?.status || 'missing'}, version=${changed?.version ?? 'missing'}`, OPTIONS)
if (!changed) return
version = Number(changed.version)
}
const action = await context.request('POST', `${TRUCK}/${appointmentId}/cancel`, { expectedVersion: Number(appointment.version), reason: context.marker })
const cancelled = context.apiSuccess(MODULE, '取消跨服务链路拖车预约', action, '', OPTIONS)
context.assert(MODULE, '跨服务链路安全终态为 CANCELLED', action, cancelled?.status === 'CANCELLED', `status=${cancelled?.status || 'missing'}`, OPTIONS)
const detail = await context.request('GET', `${TRUCK}/${appointmentId}`)
const final = context.apiSuccess(MODULE, '回查跨服务链路安全终态', detail, '', OPTIONS)
context.assert(MODULE, '跨服务链路终态持久化且关联订舱未漂移', detail,
final?.status === 'CANCELLED' && id(final?.oceanBookingId) === id(ocean.id)
final?.status === 'COMPLETED' && id(final?.oceanBookingId) === id(ocean.id)
&& (!linkContainer || id(final?.containerBookingId) === id(containerFlow.containerBookingId)
&& id(final?.loadingPlanId) === id(containerFlow.loadingPlanId)),
`status=${final?.status || 'missing'}, oceanBookingId=${final?.oceanBookingId || 'missing'}, containerBookingId=${final?.containerBookingId || 'n/a'}, loadingPlanId=${final?.loadingPlanId || 'n/a'}`, OPTIONS)
const historyResponse = await context.request('GET', `${TRUCK}/${appointmentId}/history`)
const history = context.apiSuccess(MODULE, '查询跨服务链路拖车预约状态历史', historyResponse, '', OPTIONS)
const cancel = Array.isArray(history) ? history.find((item) => item?.action === 'CANCEL') : null
context.assert(MODULE, '跨服务链路历史包含归属、状态、操作者、时间和备注', historyResponse,
Boolean(cancel) && id(cancel?.appointmentId) === appointmentId
&& cancel?.fromStatus === 'DRAFT' && cancel?.toStatus === 'CANCELLED'
&& Boolean(cancel?.operatorId) && Boolean(cancel?.operatorName) && Boolean(cancel?.createdAt)
&& cancel?.reason === context.marker,
`history=${history?.length ?? 'n/a'}, cancelFrom=${cancel?.fromStatus || 'missing'}, cancelTo=${cancel?.toStatus || 'missing'}`,
const actions = Array.isArray(history) ? history.filter((item) => item?.action !== 'CREATE') : []
const expectedActions = ['SUBMIT', 'DISPATCH', 'PICKUP', 'ARRIVE', 'LOAD', 'DEPART', 'COMPLETE']
context.assert(MODULE, '跨服务链路历史包含完整状态链、操作者、时间和备注', historyResponse,
expectedActions.every((action) => actions.some((item) => item.action === action
&& id(item.appointmentId) === appointmentId && Boolean(item.operatorId)
&& Boolean(item.operatorName) && Boolean(item.createdAt) && item.reason === context.marker)),
`history=${history?.length ?? 'n/a'}, actions=${actions.map((item) => item.action).join(',')}`,
OPTIONS)
}