fix: make loading evidence replay idempotent
This commit is contained in:
@@ -99,6 +99,21 @@ async function waitForCompletion(context, taskDetailPath, operationsPath, attemp
|
||||
return { taskResponse, task, operationsResponse, operations, attempts }
|
||||
}
|
||||
|
||||
async function waitForEvidenceSnapshot(context, evidencePath, expectedTypes, attempts = 30) {
|
||||
let response = null
|
||||
for (let attempt = 1; attempt <= attempts; attempt += 1) {
|
||||
response = await context.request('GET', evidencePath)
|
||||
const evidences = response?.http === 200 && String(response?.body?.code) === '200'
|
||||
? response.body.data?.evidences : null
|
||||
if (Array.isArray(evidences) && expectedTypes.every((type) =>
|
||||
evidences.some((item) => item?.evidenceType === type && item?.status !== 'VOID'))) {
|
||||
return { response, attempts: attempt }
|
||||
}
|
||||
if (attempt < attempts) await new Promise((resolve) => setTimeout(resolve, 1_000))
|
||||
}
|
||||
return { response, attempts }
|
||||
}
|
||||
|
||||
export async function run(context) {
|
||||
const fixture = context.createdResources?.phase3Loading
|
||||
const tenantId = id(fixture?.tenantId); const inboundId = id(fixture?.inboundId)
|
||||
@@ -302,12 +317,14 @@ export async function run(context) {
|
||||
`orderId=${orderId}, found=${Boolean(unifiedRow)}, mainStatus=${unifiedRow?.mainStatus || 'missing'}`, OPTIONS)
|
||||
|
||||
const evidencePath = `${base}/loading/evidence?tenantId=${encodeURIComponent(tenantId)}`
|
||||
const immutableEvidenceResponse = await context.request('GET', evidencePath)
|
||||
const immutableEvidenceResult = await waitForEvidenceSnapshot(
|
||||
context, evidencePath, fixture.evidenceTypes || [])
|
||||
const immutableEvidenceResponse = immutableEvidenceResult.response
|
||||
const immutableEvidence = context.apiSuccess(MODULE, '读取 LOADED 后不可变证据快照', immutableEvidenceResponse, '', OPTIONS)
|
||||
context.assert(MODULE, '统一硬门禁通过后五类有效证据仍完整', immutableEvidenceResponse,
|
||||
fixture.evidenceTypes?.every?.((type) => immutableEvidence?.evidences?.some?.((item) =>
|
||||
item.evidenceType === type && item.status !== 'VOID')),
|
||||
`evidences=${immutableEvidence?.evidences?.length ?? 'missing'}`, OPTIONS)
|
||||
`evidences=${immutableEvidence?.evidences?.length ?? 'missing'}, attempts=${immutableEvidenceResult.attempts}`, OPTIONS)
|
||||
const immutablePlanResponse = await context.request('GET', planPath)
|
||||
const immutablePlan = context.apiSuccess(MODULE, '读取 LOADED 后装柜计划快照', immutablePlanResponse, '', OPTIONS)
|
||||
const finalVersion = Number(finalData?.summary?.version)
|
||||
|
||||
Reference in New Issue
Block a user