From b8a649e7052ceb06cfc05204efbe8951eceec93b Mon Sep 17 00:00:00 2001 From: ouyangxq <775153912@qq.com> Date: Fri, 4 Sep 2026 16:04:12 +0800 Subject: [PATCH] test: retry transient unauthenticated upload probe --- .../inbound-weight-ocr-contract.test.mjs | 10 ++++++++++ .../inbound-weight-ocr.mjs | 16 +++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/scripts/admin-test-env-modules/inbound-weight-ocr-contract.test.mjs b/scripts/admin-test-env-modules/inbound-weight-ocr-contract.test.mjs index 40684161b..eed42368e 100644 --- a/scripts/admin-test-env-modules/inbound-weight-ocr-contract.test.mjs +++ b/scripts/admin-test-env-modules/inbound-weight-ocr-contract.test.mjs @@ -4,6 +4,7 @@ import test from 'node:test' import { confirmedNetSummary, + isTransientGatewayFailure, normalizeWeightPalletOptionPage, normalizedGrossKg, palletOptionsPath, @@ -13,6 +14,15 @@ import { workspaceWeightMatchesBaseline, } from './inbound-weight-ocr.mjs' +test('retries only transient gateway failures for the unauthenticated upload probe', () => { + assert.equal(isTransientGatewayFailure({ http: 0 }), true) + assert.equal(isTransientGatewayFailure({ http: 502 }), true) + assert.equal(isTransientGatewayFailure({ http: 503 }), true) + assert.equal(isTransientGatewayFailure({ http: 401 }), false) + assert.equal(isTransientGatewayFailure({ http: 403 }), false) + assert.equal(isTransientGatewayFailure({ http: 500 }), false) +}) + test('selects a stable complete pallet snapshot without status or availability', () => { const selected = selectWeightPallet([ { palletId: '20', palletCode: 'P-20', palletType: 'STANDARD', capacityCbm: 2, tareWeightKg: 18.5 }, diff --git a/scripts/admin-test-env-modules/inbound-weight-ocr.mjs b/scripts/admin-test-env-modules/inbound-weight-ocr.mjs index 0ced75364..e6920b8b8 100644 --- a/scripts/admin-test-env-modules/inbound-weight-ocr.mjs +++ b/scripts/admin-test-env-modules/inbound-weight-ocr.mjs @@ -72,6 +72,20 @@ function expectedRejection(response) { return response?.http === 200 && response?.body && String(response.body.code) !== '200' } +export function isTransientGatewayFailure(response) { + return response?.http === 0 || response?.http === 502 || response?.http === 503 +} + +async function unauthenticatedMultipart(context, path, file) { + let response = null + for (let attempt = 1; attempt <= 3; attempt += 1) { + response = await multipart(context, path, file, '') + if (!isTransientGatewayFailure(response) || attempt === 3) return response + await new Promise((resolve) => setTimeout(resolve, attempt * 750)) + } + return response +} + function markerVisible(detail, marker) { const values = [ detail?.publicRemark, @@ -435,7 +449,7 @@ export async function run(context) { } const uploadPath = `/api/platform/v1/files/measurements/${encodeURIComponent(target.tenantId)}/${encodeURIComponent(target.inboundId)}` - const noAuth = await multipart(context, uploadPath, image, '') + const noAuth = await unauthenticatedMultipart(context, uploadPath, image) context.assert(MODULE, '未认证请求不能上传称重图片', noAuth, noAuth.http === 401 || noAuth.http === 403, `HTTP=${noAuth.http}, code=${noAuth.body?.code ?? 'none'}`, SCENARIO_OPTIONS)