Test #1

Merged
admin merged 1726 commits from test into main 2026-09-17 11:52:45 +08:00
2 changed files with 25 additions and 1 deletions
Showing only changes of commit b8a649e705 - Show all commits
@@ -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 },
@@ -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)