Files
baiyue-firstleg/scripts/admin-test-env-modules/phase3-pda-convergence.mjs
T

150 lines
12 KiB
JavaScript
Raw Normal View History

const MODULE = 'phase3-pda-convergence'
const OPTIONS = { scenario: 'pda-picking-convergence', deploymentBlocker: true }
function id(value) { return value == null ? '' : String(value) }
function codeOf(response) { return response?.body?.code == null ? 'missing' : String(response.body.code) }
function failure(response) { return [400, 401, 403, 404, 409, 503].includes(response?.http) || (response?.http === 200 && codeOf(response) !== '200') }
2026-08-17 16:17:20 +08:00
export function buildPendingActions(task) {
if (task?.workflowStatus === 'AWAITING_REVIEW' || task?.workflowStatus === 'COMPLETED') return []
return (task?.items || []).filter((item) => ['PENDING', 'PICKING'].includes(item?.itemStatus))
.map((item) => ({ itemId: id(item?.id), action: 'PICK' }))
}
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)
const taskId = id(fixture?.canonicalPdaTaskId); const containerNo = fixture?.containerNo
const warehouseId = id(fixture?.warehouseId); const loadingPlanId = id(fixture?.loadingPlanId)
if (!tenantId || !inboundId || !taskId || !containerNo || !warehouseId || !loadingPlanId
|| fixture?.marker !== context.marker) {
2026-08-24 19:58:35 +08:00
context.addStep(MODULE, '取得同 marker 的 PDA 收敛前置', null, false,
`tenantId=${tenantId || 'missing'}, inboundId=${inboundId || 'missing'}, taskId=${taskId || 'missing'}, loadingPlanId=${loadingPlanId || 'missing'}, fixtureMarker=${fixture?.marker || 'missing'}, runMarker=${context.marker}`,
OPTIONS)
context.addCoverageGap(MODULE, OPTIONS.scenario, 'PDA 柜次拣货与入库单汇总拣货收敛',
'本轮未取得 marker 隔离的柜次 PDA 与入库汇总 fixture,未使用历史资源', 'fixture')
return
}
const loadingPlanResponse = await request(context, 'GET',
`/api/platform/v1/first-leg/smart-loading/plans/${loadingPlanId}`)
const loadingPlan = context.apiSuccess(MODULE, '回查柜次 PDA 待最终完成的运行中计划', loadingPlanResponse, '', OPTIONS)
context.assert(MODULE, '运行中计划保持 LOADING 且尚未最终完成', loadingPlanResponse,
id(loadingPlan?.id) === loadingPlanId && loadingPlan?.status === 'LOADING'
&& loadingPlan?.finalCompletionStatus === 'IN_PROGRESS',
`planId=${id(loadingPlan?.id) || 'missing'}, status=${loadingPlan?.status || 'missing'}, final=${loadingPlan?.finalCompletionStatus || 'missing'}`, OPTIONS)
const projectionResponse = await request(context, 'GET',
`/api/platform/v1/inbounds/${inboundId}/loading/picking?tenantId=${encodeURIComponent(tenantId)}`)
const projection = context.apiSuccess(MODULE, '查询入库级 PDA 服务端聚合投影', projectionResponse, '', OPTIONS)
2026-08-17 15:41:42 +08:00
context.assert(MODULE, '入库投影数量已拣齐但仍等待最终门禁', projectionResponse,
['IN_PROGRESS', 'AWAITING_REVIEW', 'COMPLETED'].includes(projection?.status) && Number(projection?.expectedCount) > 0
&& Number(projection?.expectedCount) === Number(projection?.pickedCount),
`status=${projection?.status || 'missing'}, expected=${projection?.expectedCount ?? 'missing'}, picked=${projection?.pickedCount ?? 'missing'}`, OPTIONS)
2026-08-17 16:17:20 +08:00
const taskPath = `/api/platform/v1/first-leg/pda-loading/tasks/${taskId}`
const taskDetailResponse = await request(context, 'GET',
`${taskPath}?warehouseId=${encodeURIComponent(warehouseId)}`)
const taskDetail = context.apiSuccess(MODULE, '按稳定 taskId 读取 PDA 任务详情', taskDetailResponse, '', OPTIONS)
const pendingResponse = await request(context, 'GET',
`/api/platform/v1/first-leg/pda-loading/tasks/pending?keyword=${encodeURIComponent(containerNo)}`)
const pendingTasks = context.apiSuccess(MODULE, '读取当前操作员 PDA pending 列表', pendingResponse, '', OPTIONS)
const pendingTask = Array.isArray(pendingTasks)
? pendingTasks.find((item) => id(item?.taskId) === taskId)
: null
const unresolvedItems = (taskDetail?.items || []).filter((item) =>
['PENDING', 'PICKING'].includes(item?.itemStatus))
context.assert(MODULE, 'pending 与 detail 使用同一 workflowStatus 和未完成数量事实', pendingResponse,
Boolean(pendingTask) && pendingTask?.workflowStatus === taskDetail?.workflowStatus
&& Number(pendingTask?.pendingItemCount) === unresolvedItems.length
&& Number(pendingTask?.itemCount) === Number(taskDetail?.items?.length),
`taskId=${taskId}, pendingWorkflow=${pendingTask?.workflowStatus || 'missing'}, detailWorkflow=${taskDetail?.workflowStatus || 'missing'}, pendingItemCount=${pendingTask?.pendingItemCount ?? 'missing'}, detailUnresolved=${unresolvedItems.length}`, OPTIONS)
const pendingActions = buildPendingActions(taskDetail)
context.assert(MODULE, 'AWAITING_REVIEW 已全拣任务 actions 为空且不再提交 batch', taskDetailResponse,
taskDetail?.workflowStatus === 'AWAITING_REVIEW' && unresolvedItems.length === 0
&& pendingActions.length === 0,
`workflow=${taskDetail?.workflowStatus || 'missing'}, unresolved=${unresolvedItems.length}, actions=${pendingActions.length}`, OPTIONS)
const evidenceResponse = await request(context, 'GET',
`${taskPath}/evidence?warehouseId=${encodeURIComponent(warehouseId)}`)
2026-08-17 16:17:20 +08:00
const evidence = context.apiSuccess(MODULE, 'AWAITING_REVIEW 可进入装柜取证只读入口', evidenceResponse, '', OPTIONS)
context.assert(MODULE, 'AWAITING_REVIEW 取证 GET 开放且不依赖重复 batch', evidenceResponse,
taskDetail?.workflowStatus === 'AWAITING_REVIEW' && id(evidence?.taskId) === taskId
&& id(evidence?.containerBookingId) === id(fixture?.containerBookingId)
&& Array.isArray(evidence?.evidences),
2026-08-17 16:17:20 +08:00
`workflow=${taskDetail?.workflowStatus || 'missing'}, evidences=${evidence?.evidences?.length ?? 'missing'}, actions=${pendingActions.length}`, OPTIONS)
const operationsResponse = await request(context, 'GET',
2026-08-17 16:17:20 +08:00
`${taskPath}/operations`)
const operations = context.apiSuccess(MODULE, '查询柜次 PDA 不可变操作历史', operationsResponse, '', OPTIONS)
2026-08-24 19:58:35 +08:00
const batchOperations = Array.isArray(operations)
? operations.filter((item) => item.actionType === 'BATCH'
&& Boolean(item.operatorId) && Boolean(item.createdAt)) : []
2026-08-25 13:59:58 +08:00
const expectedBatchOperationIds = Array.isArray(fixture?.expectedBatchOperationIds)
? fixture.expectedBatchOperationIds.map(id).filter(Boolean) : []
const actualBatchOperationIds = batchOperations.map((item) => id(item.operationId)).filter(Boolean)
2026-08-17 15:41:42 +08:00
context.assert(MODULE, '最终完成前保留领取操作且不伪造复核或完成历史', operationsResponse,
Array.isArray(operations) && operations.some((item) => item.actionType === 'CLAIM'
&& Boolean(item.operatorId) && Boolean(item.createdAt))
2026-08-17 15:41:42 +08:00
&& !operations.some((item) => item.actionType === 'REVIEW')
&& !operations.some((item) => item.actionType === 'COMPLETE_LOADING'),
`actions=${Array.isArray(operations) ? operations.map((item) => item.actionType).join(',') : 'missing'}`, OPTIONS)
2026-08-12 10:59:39 +08:00
context.assert(MODULE, 'PDA 原子批次完成审计包含 BATCH 操作', operationsResponse,
2026-08-25 13:59:58 +08:00
expectedBatchOperationIds.length === 4
&& new Set(expectedBatchOperationIds).size === 4
&& actualBatchOperationIds.length === 4
&& new Set(actualBatchOperationIds).size === 4
&& expectedBatchOperationIds.every((operationId) => actualBatchOperationIds.includes(operationId))
&& actualBatchOperationIds.every((operationId) => expectedBatchOperationIds.includes(operationId)),
`expectedBatchCount=${expectedBatchOperationIds.length}, actualBatchCount=${actualBatchOperationIds.length}, expectedIds=${expectedBatchOperationIds.join(',') || 'missing'}, actualIds=${actualBatchOperationIds.join(',') || 'missing'}`, OPTIONS)
const forged = await request(context, 'POST',
`/api/platform/v1/inbounds/${inboundId}/loading/picking/start?tenantId=${encodeURIComponent(tenantId)}`,
{ expectedVersion: Number(projection?.version), expectedCount: 999, pickedCount: 999, remark: 'forged' },
{ 'Idempotency-Key': `${context.marker}-pda-forged-projection`.slice(0, 128) })
context.addStep(MODULE, '入库兼容入口拒绝客户端伪造汇总数量', forged, failure(forged),
`HTTP=${forged.http}, code=${codeOf(forged)}`, OPTIONS)
if (fixture?.atomicBatchVerified !== true) {
2026-08-24 19:58:35 +08:00
context.addStep(MODULE, 'PDA 原子批次成功且同键重放零新增', null, false,
'phase3-loading 未发布 atomicBatchVerified=true;不能以 coverageGap 代替真实批次与幂等断言', OPTIONS)
context.addCoverageGap(MODULE, OPTIONS.scenario, 'PDA 原子批量成功与批次幂等闭环',
'原子 batch 端点已部署,但本轮合法整批提交或同键重放未通过真实 HTTP 断言;保留真实失败证据',
'deployment-blocker')
}
2026-08-11 20:10:24 +08:00
if (fixture?.inventorySnapshotVerified !== true) {
2026-08-24 19:58:35 +08:00
context.addStep(MODULE, 'PDA 实时库存快照身份与合法 token 提交', null, false,
'phase3-loading 未发布 inventorySnapshotVerified=true;不能以 coverageGap 代替真实库存快照断言', OPTIONS)
2026-08-11 20:10:24 +08:00
context.addCoverageGap(MODULE, OPTIONS.scenario, 'PDA 实时库存快照身份、稳定性与合法 token 提交',
'inventory-snapshot 端点已公开,但本轮未完成归属、稳定 token/version、数量及合法 batch 的联合真实 HTTP 验证',
'deployment-blocker')
}
if (fixture?.inventoryMutationRequired !== false && fixture?.inventoryMutationVerified !== true
2026-08-11 20:10:24 +08:00
&& !context.coverageGaps.some((gap) => gap.name === 'PDA 真实库存变化后的旧快照冲突与刷新重试')) {
2026-08-24 19:58:35 +08:00
context.addStep(MODULE, 'PDA 真实库存变化后旧 token A0409 与刷新重试', null, false,
'本轮未取得 inventoryMutationVerified=true;无法安全制造库存变化时必须作为部署阻断失败', OPTIONS)
2026-08-11 20:10:24 +08:00
context.addCoverageGap(MODULE, OPTIONS.scenario, 'PDA 真实库存变化后的旧快照冲突与刷新重试',
'inventory-snapshot 已公开;本轮没有可通过平台代理安全变更的 A0 临时占用,不能用普通库位改写或内部 Warehouse 接口伪造库存变化',
'fixture')
} else if (fixture?.inventoryMutationRequired === false) {
context.addStep(MODULE, '依赖链不重复执行 A0 旧快照破坏性专项', null, true,
'正常库存快照、原子批次和幂等已验证;A0 换绑与旧 token A0409 仅在显式 phase3-loading 专项运行',
{ scenario: OPTIONS.scenario })
2026-08-11 20:10:24 +08:00
}
2026-08-24 19:58:35 +08:00
if (fixture?.dynamicIncrementVerified !== true) {
context.addStep(MODULE, 'LOADING 增量重开、刷新续拣与已拣不可删减', null, false,
'phase3-loading 未发布 dynamicIncrementVerified=true;不能跳过增量重开、旧 token A0409、刷新续拣和已拣项保护', OPTIONS)
}
2026-08-25 13:59:58 +08:00
if (fixture?.skipBatchVerified !== true || fixture?.partialBatchVerified !== true) {
context.addStep(MODULE, 'SKIP 与 PARTIAL 独立原子批次均完成', null, false,
`skipBatchVerified=${fixture?.skipBatchVerified === true}, partialBatchVerified=${fixture?.partialBatchVerified === true};不能按普通 PICK 批次代替异常处理审计`, OPTIONS)
}
2026-08-11 11:41:41 +08:00
context.addCoverageGap(MODULE, OPTIONS.scenario, 'PDA Android/HBuilderX 真机完整闭环',
'原子 batch 真实 HTTP 契约已自动化;扫码、弱网恢复、在线草稿和设备交互仍需 Android/HBuilderX 真机验收',
'device')
}