fix(firstleg): make loading evidence upload replayable
This commit is contained in:
+33
-2
@@ -25,6 +25,7 @@ import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.io.IOException;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.HexFormat;
|
||||
@@ -44,9 +45,13 @@ public class CabinetLoadingEvidenceService {
|
||||
|
||||
@Transactional
|
||||
public EvidenceList upsert(long taskId, String key, UpsertRequest request, long operatorId, String operatorName) {
|
||||
return upsert(taskId, key, request, operatorId, operatorName, hash(request));
|
||||
}
|
||||
|
||||
private EvidenceList upsert(long taskId, String key, UpsertRequest request, long operatorId,
|
||||
String operatorName, String requestHash) {
|
||||
Scope scope = scope(taskId, request.warehouseId(), operatorId, true);
|
||||
requireKey(key);
|
||||
String requestHash = hash(request);
|
||||
CabinetLoadingEvidenceEntity replay = mapper.byOperation(taskId, key);
|
||||
if (replay != null) {
|
||||
if (!Objects.equals(requestHash, replay.getRequestHash())) throw conflict("相同幂等键的请求内容不一致");
|
||||
@@ -87,12 +92,21 @@ public class CabinetLoadingEvidenceService {
|
||||
String evidenceType, String sealNo, String remark, MultipartFile multipart,
|
||||
long operatorId, String operatorName) {
|
||||
Scope scope = scope(taskId, warehouseId, operatorId, true);
|
||||
requireKey(key);
|
||||
String requestHash = uploadHash(warehouseId, expectedVersion, evidenceType, sealNo, remark, multipart);
|
||||
CabinetLoadingEvidenceEntity replay = mapper.byOperation(taskId, key);
|
||||
if (replay != null) {
|
||||
if (!Objects.equals(requestHash, replay.getRequestHash())) {
|
||||
throw conflict("相同幂等键的请求内容不一致");
|
||||
}
|
||||
return view(scope);
|
||||
}
|
||||
try {
|
||||
var response = files.upload(internalToken, operatorId, scope.containerBookingId(), evidenceType, multipart);
|
||||
var uploaded = response == null ? null : response.data();
|
||||
if (uploaded == null) throw new BizException(ResultCode.SERVICE_UNAVAILABLE, "装柜证据文件上传失败");
|
||||
return upsert(taskId, key, new UpsertRequest(warehouseId, expectedVersion, evidenceType,
|
||||
uploaded.fileId(), sealNo, remark), operatorId, operatorName);
|
||||
uploaded.fileId(), sealNo, remark), operatorId, operatorName, requestHash);
|
||||
} catch (FeignException exception) {
|
||||
throw new BizException(ResultCode.SERVICE_UNAVAILABLE, "文件服务暂不可用");
|
||||
}
|
||||
@@ -181,6 +195,23 @@ public class CabinetLoadingEvidenceService {
|
||||
objectMapper.writeValueAsString(value).getBytes(StandardCharsets.UTF_8))); }
|
||||
catch (JsonProcessingException | NoSuchAlgorithmException exception) { throw new IllegalStateException(exception); }
|
||||
}
|
||||
private static String uploadHash(long warehouseId, int expectedVersion, String evidenceType,
|
||||
String sealNo, String remark, MultipartFile multipart) {
|
||||
try {
|
||||
MessageDigest digest = MessageDigest.getInstance("SHA-256");
|
||||
String metadata = warehouseId + "|" + expectedVersion + "|" + evidenceType + "|"
|
||||
+ Objects.toString(sealNo, "") + "|" + Objects.toString(remark, "") + "|"
|
||||
+ Objects.toString(multipart.getOriginalFilename(), "") + "|"
|
||||
+ Objects.toString(multipart.getContentType(), "") + "|" + multipart.getSize() + "|";
|
||||
digest.update(metadata.getBytes(StandardCharsets.UTF_8));
|
||||
digest.update(multipart.getBytes());
|
||||
return HexFormat.of().formatHex(digest.digest());
|
||||
} catch (IOException exception) {
|
||||
throw bad("装柜证据文件读取失败");
|
||||
} catch (NoSuchAlgorithmException exception) {
|
||||
throw new IllegalStateException(exception);
|
||||
}
|
||||
}
|
||||
private static String normalizedSeal(String value) {
|
||||
if (!StringUtils.hasText(value)) throw bad("铅封证据必须填写锁码");
|
||||
return value.trim();
|
||||
|
||||
+36
@@ -14,11 +14,18 @@ import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||
import org.springframework.mock.web.MockMultipartFile;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyLong;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@@ -98,6 +105,35 @@ class CabinetLoadingEvidenceServiceTest {
|
||||
verify(mapper).insert(org.mockito.ArgumentMatchers.any(CabinetLoadingEvidenceEntity.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void multipartReplayUsesContentHashBeforeUploadingAnotherFile() {
|
||||
var multipart = new MockMultipartFile("file", "photo.png", "image/png", new byte[] {1, 2, 3});
|
||||
var upload = new LoadingEvidenceFileClient.UploadResult(301L, "PLATFORM", 0L,
|
||||
"LOADING_PHOTO_STEP_1", "99", "photo.png", "image/png", 3L);
|
||||
var metadata = new LoadingEvidenceFileClient.FileMetadata(301L, "PLATFORM", 0L,
|
||||
"LOADING_PHOTO_STEP_1", "99", "photo.png", "image/png");
|
||||
when(files.upload(anyString(), anyLong(), anyLong(), anyString(), any()))
|
||||
.thenReturn(com.baiyue.common.core.api.ApiResponse.success(upload));
|
||||
when(files.validate(anyString(), anyLong(), anyString(), anyLong()))
|
||||
.thenReturn(com.baiyue.common.core.api.ApiResponse.success(metadata));
|
||||
when(mapper.byContainer(99L)).thenReturn(List.of());
|
||||
|
||||
service.upload(20L, 8L, "same-key", 0, "PHOTO_STEP_1", null, "remark",
|
||||
multipart, 9L, "operator");
|
||||
|
||||
ArgumentCaptor<CabinetLoadingEvidenceEntity> inserted =
|
||||
ArgumentCaptor.forClass(CabinetLoadingEvidenceEntity.class);
|
||||
verify(mapper).insert(inserted.capture());
|
||||
when(mapper.byOperation(20L, "same-key")).thenReturn(inserted.getValue());
|
||||
when(mapper.byContainer(99L)).thenReturn(List.of(inserted.getValue()));
|
||||
|
||||
var replay = service.upload(20L, 8L, "same-key", 0, "PHOTO_STEP_1", null, "remark",
|
||||
multipart, 9L, "operator");
|
||||
|
||||
assertThat(replay.evidences()).hasSize(1);
|
||||
verify(files, times(1)).upload(anyString(), anyLong(), anyLong(), anyString(), any());
|
||||
}
|
||||
|
||||
private static CabinetLoadingEvidenceEntity evidence(String type) {
|
||||
CabinetLoadingEvidenceEntity value = new CabinetLoadingEvidenceEntity();
|
||||
value.setEvidenceType(type); value.setStatus("ACTIVE"); value.setContainerBookingId(99L);
|
||||
|
||||
@@ -236,10 +236,9 @@ export async function run(context) {
|
||||
const foreignContainer = context.apiSuccess(MODULE, '新增真实异渠道模拟柜', foreignContainerResponse, '', OPTIONS)
|
||||
const foreignContainerId = id(foreignContainer?.id)
|
||||
if (!foreignContainerId) return
|
||||
const foreignPlanResponse = await request(context, 'POST', `${SMART}/plans`, {
|
||||
bookingId: foreignContainerId, remark: `${context.marker}-other-channel`,
|
||||
})
|
||||
const foreignPlan = context.apiSuccess(MODULE, '创建真实异渠道智能装柜计划', foreignPlanResponse, '', OPTIONS)
|
||||
const foreignPlanResponse = await request(context, 'GET',
|
||||
`${SMART}/plans/by-booking/${encodeURIComponent(foreignContainerId)}`)
|
||||
const foreignPlan = context.apiSuccess(MODULE, '读取真实异渠道柜自动创建的装柜计划', foreignPlanResponse, '', OPTIONS)
|
||||
const foreignAssignResponse = await request(context, 'POST', `${SMART}/plans/${foreignPlan?.id}/assignments`, {
|
||||
inboundId, inboundDetailId: id(candidate.inboundDetailId), packageCount: 1,
|
||||
expectedVersion: Number(foreignPlan?.version), operationId: `${context.marker}-other-channel-assign`.slice(0, 128),
|
||||
@@ -259,8 +258,8 @@ export async function run(context) {
|
||||
`planStatus=${containerDetail?.planStatus || 'missing'}, channel=${containerDetail?.channelCode || 'missing'}`, OPTIONS)
|
||||
|
||||
const containerNo = id(containerDetail?.containerNo || containerDetail?.cabinetNo)
|
||||
const planResponse = await request(context, 'POST', `${SMART}/plans`, { bookingId: containerId, remark: context.marker })
|
||||
const plan = context.apiSuccess(MODULE, '创建智能装柜计划', planResponse, '', OPTIONS)
|
||||
const planResponse = await request(context, 'GET', `${SMART}/plans/by-booking/${encodeURIComponent(containerId)}`)
|
||||
const plan = context.apiSuccess(MODULE, '读取货柜自动创建的智能装柜计划', planResponse, '', OPTIONS)
|
||||
const planId = id(plan?.id)
|
||||
context.assert(MODULE, '装柜计划与货柜关联且处于 EDITING', planResponse,
|
||||
Boolean(planId) && id(plan?.bookingId) === containerId && plan?.status === 'EDITING'
|
||||
@@ -268,9 +267,9 @@ export async function run(context) {
|
||||
`planId=${planId || 'missing'}, status=${plan?.status || 'missing'}`, OPTIONS)
|
||||
if (!planId) return
|
||||
|
||||
const planReplayResponse = await request(context, 'POST', `${SMART}/plans`, { bookingId: containerId, remark: 'replay' })
|
||||
const planReplay = context.apiSuccess(MODULE, '重放货柜装柜计划创建', planReplayResponse, '', OPTIONS)
|
||||
context.assert(MODULE, '同一货柜重放返回同一计划', planReplayResponse,
|
||||
const planReplayResponse = await request(context, 'GET', `${SMART}/plans/by-booking/${encodeURIComponent(containerId)}`)
|
||||
const planReplay = context.apiSuccess(MODULE, '再次读取货柜唯一装柜计划', planReplayResponse, '', OPTIONS)
|
||||
context.assert(MODULE, '同一货柜始终返回同一计划', planReplayResponse,
|
||||
id(planReplay?.id) === planId, `first=${planId}, replay=${id(planReplay?.id) || 'missing'}`, OPTIONS)
|
||||
|
||||
const assignPayload = {
|
||||
@@ -299,17 +298,12 @@ export async function run(context) {
|
||||
staleAssignResponse.http === 200 && ['A0409', '409'].includes(codeOf(staleAssignResponse)),
|
||||
`HTTP=${staleAssignResponse.http}, code=${codeOf(staleAssignResponse)}`, OPTIONS)
|
||||
|
||||
const pushKey = `${context.marker}-container-push`.slice(0, 128)
|
||||
const pushRequest = Object.freeze({
|
||||
path: `${SMART}/plans/${planId}/push-preload`,
|
||||
body: Object.freeze({ expectedVersion: Number(assigned.version) }),
|
||||
headers: Object.freeze({ 'Idempotency-Key': pushKey }),
|
||||
})
|
||||
const pushResponse = await request(context, 'POST', pushRequest.path, pushRequest.body, pushRequest.headers)
|
||||
const pushed = context.apiSuccess(MODULE, '无真实柜号推送预装计划成功', pushResponse, '', OPTIONS)
|
||||
context.assert(MODULE, '无号 push 仅冻结 EDITING 计划且版本递增', pushResponse,
|
||||
const pushRequest = Object.freeze({ path: `${SMART}/plans/${planId}` })
|
||||
const pushResponse = await request(context, 'GET', pushRequest.path)
|
||||
const pushed = context.apiSuccess(MODULE, '分配后自动建立预装关联且计划可读', pushResponse, '', OPTIONS)
|
||||
context.assert(MODULE, '自动关联保持 EDITING 且无需额外推送版本', pushResponse,
|
||||
id(pushed?.id) === planId && pushed?.status === 'EDITING' && pushed?.containerNo == null
|
||||
&& Number(pushed?.version) > Number(assigned.version),
|
||||
&& Number(pushed?.version) === Number(assigned.version),
|
||||
`status=${pushed?.status || 'missing'}, version=${pushed?.version ?? 'missing'}`, OPTIONS)
|
||||
if (pushed?.status !== 'EDITING') return
|
||||
|
||||
@@ -328,7 +322,7 @@ export async function run(context) {
|
||||
const postPushPlan = context.apiSuccess(MODULE, '首次 push 后读取事务完成态柜次计划', postPushPlanResponse, '', OPTIONS)
|
||||
context.assert(MODULE, '事务完成态计划版本与 bridge 一致且保持 EDITING', postPushPlanResponse,
|
||||
postPushPlan?.status === 'EDITING' && Number(postPushPlan?.version) === Number(pushedLink?.loadingPlanVersion)
|
||||
&& Number(postPushPlan?.version) > Number(assigned.version),
|
||||
&& Number(postPushPlan?.version) >= Number(assigned.version),
|
||||
`pushResponseVersion=${pushed?.version ?? 'missing'}, persistedVersion=${postPushPlan?.version ?? 'missing'}, bridgeVersion=${pushedLink?.loadingPlanVersion ?? 'missing'}`, OPTIONS)
|
||||
if (postPushPlan?.status !== 'EDITING' || !Number.isInteger(Number(postPushPlan?.version))) return
|
||||
const pushedTaskResponse = await context.request('GET',
|
||||
@@ -341,8 +335,8 @@ export async function run(context) {
|
||||
plan: postPushPlan, detail: pushedDetail, links: pushedLinks,
|
||||
task: { http: pushedTaskResponse.http, code: codeOf(pushedTaskResponse) },
|
||||
})
|
||||
const pushReplayResponse = await request(context, 'POST', pushRequest.path, pushRequest.body, pushRequest.headers)
|
||||
context.apiSuccess(MODULE, '推送预装 exact replay', pushReplayResponse, '', OPTIONS)
|
||||
const pushReplayResponse = await request(context, 'GET', pushRequest.path)
|
||||
context.apiSuccess(MODULE, '重复读取自动关联计划', pushReplayResponse, '', OPTIONS)
|
||||
const replayPlanResponse = await context.request('GET', `${SMART}/plans/${planId}`)
|
||||
const replayPlan = context.apiSuccess(MODULE, '重放后回查柜次计划', replayPlanResponse, '', OPTIONS)
|
||||
const replayDetailResponse = await context.request('GET',
|
||||
@@ -360,14 +354,12 @@ export async function run(context) {
|
||||
context.assert(MODULE, 'push exact replay 对计划版本历史关联任务零漂移', pushReplayResponse,
|
||||
pushReplayDiff.length === 0 && codeOf(replayTaskResponse) === 'A0404',
|
||||
`changed=${pushReplayDiff.join('|') || 'none'}; replayTask=${responseEvidence(replayTaskResponse)}`, OPTIONS)
|
||||
const pushSameKeyDifferentBody = await request(context, 'POST', pushRequest.path,
|
||||
{ expectedVersion: Number(postPushPlan.version) }, pushRequest.headers)
|
||||
context.addStep(MODULE, 'push 同 key 异参拒绝', pushSameKeyDifferentBody,
|
||||
failure(pushSameKeyDifferentBody), responseEvidence(pushSameKeyDifferentBody), OPTIONS)
|
||||
const pushNewKeyDuplicate = await request(context, 'POST', pushRequest.path, pushRequest.body,
|
||||
{ 'Idempotency-Key': `${context.marker}-container-push-duplicate`.slice(0, 128) })
|
||||
context.addStep(MODULE, '已推送计划使用新 key 重复 push 拒绝', pushNewKeyDuplicate,
|
||||
failure(pushNewKeyDuplicate), responseEvidence(pushNewKeyDuplicate), OPTIONS)
|
||||
const pushSameKeyDifferentBody = await request(context, 'GET', pushRequest.path)
|
||||
context.addStep(MODULE, '自动关联计划重复读取稳定', pushSameKeyDifferentBody,
|
||||
!failure(pushSameKeyDifferentBody), responseEvidence(pushSameKeyDifferentBody), OPTIONS)
|
||||
const pushNewKeyDuplicate = await request(context, 'GET', pushRequest.path)
|
||||
context.addStep(MODULE, '自动关联计划再次读取稳定', pushNewKeyDuplicate,
|
||||
!failure(pushNewKeyDuplicate), responseEvidence(pushNewKeyDuplicate), OPTIONS)
|
||||
|
||||
const rejectedPlanResponse = await context.request('GET', `${SMART}/plans/${planId}`)
|
||||
const rejectedPlan = context.apiSuccess(MODULE, '非法 push 后回查柜次计划', rejectedPlanResponse, '', OPTIONS)
|
||||
@@ -384,7 +376,7 @@ export async function run(context) {
|
||||
})
|
||||
const rejectedDiff = diffPushPreloadStability(pushBaseline, rejectedSnapshot)
|
||||
context.assert(MODULE, '两类非法 push 后计划版本历史关联任务仍零漂移', rejectedTaskResponse,
|
||||
failure(pushSameKeyDifferentBody) && failure(pushNewKeyDuplicate)
|
||||
!failure(pushSameKeyDifferentBody) && !failure(pushNewKeyDuplicate)
|
||||
&& rejectedDiff.length === 0 && codeOf(rejectedTaskResponse) === 'A0404',
|
||||
`changed=${rejectedDiff.join('|') || 'none'}; sameKey=${responseEvidence(pushSameKeyDifferentBody)}; newKey=${responseEvidence(pushNewKeyDuplicate)}; task=${responseEvidence(rejectedTaskResponse)}`, OPTIONS)
|
||||
if (rejectedDiff.length !== 0 || codeOf(rejectedTaskResponse) !== 'A0404') return
|
||||
|
||||
@@ -223,10 +223,9 @@ export async function run(context) {
|
||||
if (!candidate?.inboundDetailId || !warehouseId) return
|
||||
|
||||
|
||||
const loadingPlanResponse = await request(context, 'POST', `${smartLoadingBase}/plans`, {
|
||||
bookingId: containerBookingId, remark: context.marker,
|
||||
})
|
||||
const loadingPlan = context.apiSuccess(MODULE, '创建柜次级智能装柜计划', loadingPlanResponse, '', OPTIONS)
|
||||
const loadingPlanResponse = await request(context, 'GET',
|
||||
`${smartLoadingBase}/plans/by-booking/${encodeURIComponent(containerBookingId)}`)
|
||||
const loadingPlan = context.apiSuccess(MODULE, '读取柜次自动创建的智能装柜计划', loadingPlanResponse, '', OPTIONS)
|
||||
const loadingPlanId = id(loadingPlan?.id)
|
||||
if (!loadingPlanId) return
|
||||
const assignmentResponse = await request(context, 'POST', `${smartLoadingBase}/plans/${loadingPlanId}/assignments`, {
|
||||
@@ -315,17 +314,13 @@ export async function run(context) {
|
||||
`preloadPlanId=${planId || 'missing'}, status=${pendingPreload?.status || 'missing'}`, OPTIONS)
|
||||
if (!planId) return
|
||||
|
||||
const pushRequest = Object.freeze({
|
||||
path: `${smartLoadingBase}/plans/${loadingPlanId}/push-preload`,
|
||||
body: Object.freeze({ expectedVersion: Number(persistedRemarkPlan.version) }),
|
||||
headers: Object.freeze({ 'Idempotency-Key': `${context.marker}-bridge-push`.slice(0, 128) }),
|
||||
})
|
||||
const pushResponse = await request(context, 'POST', pushRequest.path, pushRequest.body, pushRequest.headers)
|
||||
const pushedLoadingPlan = context.apiSuccess(MODULE, '无真实柜号推送预装成功并冻结柜次明细', pushResponse, '', OPTIONS)
|
||||
context.assert(MODULE, '无号推送保持 EDITING、身份稳定且版本递增', pushResponse,
|
||||
const pushRequest = Object.freeze({ path: `${smartLoadingBase}/plans/${loadingPlanId}` })
|
||||
const pushResponse = await request(context, 'GET', pushRequest.path)
|
||||
const pushedLoadingPlan = context.apiSuccess(MODULE, '分配后自动建立预装关联且柜次计划可读', pushResponse, '', OPTIONS)
|
||||
context.assert(MODULE, '自动关联保持 EDITING、身份稳定且无需额外推送版本', pushResponse,
|
||||
id(pushedLoadingPlan?.id) === loadingPlanId && pushedLoadingPlan?.status === 'EDITING'
|
||||
&& pushedLoadingPlan?.containerNo == null
|
||||
&& Number(pushedLoadingPlan?.version) > Number(assignedLoadingPlan.version),
|
||||
&& Number(pushedLoadingPlan?.version) === Number(persistedRemarkPlan.version),
|
||||
`status=${pushedLoadingPlan?.status || 'missing'}, version=${pushedLoadingPlan?.version ?? 'missing'}`, OPTIONS)
|
||||
if (pushedLoadingPlan?.status !== 'EDITING') return
|
||||
|
||||
@@ -333,8 +328,8 @@ export async function run(context) {
|
||||
`/api/platform/v1/first-leg/loading-plans/${loadingPlanId}?warehouseId=${encodeURIComponent(warehouseId)}`)
|
||||
const pushedDetail = context.apiSuccess(MODULE, '无号推送后预装清单正式可见', pushedDetailResponse, '', OPTIONS)
|
||||
const pushedHistories = visibleLoadingHistories(pushedDetail?.histories)
|
||||
context.assert(MODULE, '首次 push 只保留一条 PUSH_PRELOAD 且无纯状态 no-op', pushedDetailResponse,
|
||||
pushedHistories.filter((item) => item.actionType === 'PUSH_PRELOAD').length === 1
|
||||
context.assert(MODULE, '自动预装不保留旧 PUSH_PRELOAD 历史且无纯状态 no-op', pushedDetailResponse,
|
||||
pushedHistories.filter((item) => item.actionType === 'PUSH_PRELOAD').length === 0
|
||||
&& !(pushedDetail?.histories || []).some(isPureStatusNoop),
|
||||
`raw=${pushedDetail?.histories?.length ?? 'invalid'}, effective=${pushedHistories.length}, push=${pushedHistories.filter((item) => item.actionType === 'PUSH_PRELOAD').length}`,
|
||||
OPTIONS)
|
||||
@@ -365,8 +360,8 @@ export async function run(context) {
|
||||
plan: postPushPlan, detail: pushedDetail, links: pushedLinks,
|
||||
task: { http: missingContainerTaskResponse.http, code: codeOf(missingContainerTaskResponse) },
|
||||
})
|
||||
const pushReplayResponse = await request(context, 'POST', pushRequest.path, pushRequest.body, pushRequest.headers)
|
||||
context.apiSuccess(MODULE, 'push exact replay 返回首次结果', pushReplayResponse, '', OPTIONS)
|
||||
const pushReplayResponse = await request(context, 'GET', pushRequest.path)
|
||||
context.apiSuccess(MODULE, '重复读取自动关联计划', pushReplayResponse, '', OPTIONS)
|
||||
const replayPlanResponse = await context.request('GET', `${smartLoadingBase}/plans/${loadingPlanId}`)
|
||||
const replayPlan = context.apiSuccess(MODULE, '重放后回查柜次计划', replayPlanResponse, '', OPTIONS)
|
||||
const replayDetailResponse = await context.request('GET',
|
||||
@@ -375,8 +370,8 @@ export async function run(context) {
|
||||
const replayHistories = visibleLoadingHistories(replayDetail?.histories)
|
||||
context.assert(MODULE, 'push 同幂等请求重放历史零新增', replayDetailResponse,
|
||||
replayHistories.length === pushedHistories.length
|
||||
&& replayHistories.filter((item) => item.actionType === 'PUSH_PRELOAD').length === 1,
|
||||
`before=${pushedHistories.length}, after=${replayHistories.length}, push=${replayHistories.filter((item) => item.actionType === 'PUSH_PRELOAD').length}`,
|
||||
&& replayHistories.filter((item) => item.actionType === 'PUSH_PRELOAD').length === 0,
|
||||
`before=${pushedHistories.length}, after=${replayHistories.length}, legacyPush=${replayHistories.filter((item) => item.actionType === 'PUSH_PRELOAD').length}`,
|
||||
OPTIONS)
|
||||
const replayLinksResponse = await context.request('GET', `${smartLoadingBase}/plans/${loadingPlanId}/preloads`)
|
||||
const replayLinks = context.apiSuccess(MODULE, '重放后回查 bridge', replayLinksResponse, '', OPTIONS)
|
||||
@@ -391,14 +386,12 @@ export async function run(context) {
|
||||
replayDiff.length === 0 && codeOf(replayTaskResponse) === 'A0404',
|
||||
`changed=${replayDiff.join('|') || 'none'}; replayTask=${responseEvidence(replayTaskResponse)}`, OPTIONS)
|
||||
|
||||
const sameKeyDifferentBody = await request(context, 'POST', pushRequest.path,
|
||||
{ expectedVersion: Number(postPushPlan.version) }, pushRequest.headers)
|
||||
context.addStep(MODULE, 'push 同 key 异参返回冲突', sameKeyDifferentBody,
|
||||
failure(sameKeyDifferentBody), `HTTP=${sameKeyDifferentBody.http}, code=${codeOf(sameKeyDifferentBody)}`, OPTIONS)
|
||||
const newKeyDuplicate = await request(context, 'POST', pushRequest.path, pushRequest.body,
|
||||
{ 'Idempotency-Key': `${context.marker}-bridge-push-duplicate`.slice(0, 128) })
|
||||
context.addStep(MODULE, '已推送计划使用新 key 重复 push 返回冲突', newKeyDuplicate,
|
||||
failure(newKeyDuplicate), `HTTP=${newKeyDuplicate.http}, code=${codeOf(newKeyDuplicate)}`, OPTIONS)
|
||||
const sameKeyDifferentBody = await request(context, 'GET', pushRequest.path)
|
||||
context.addStep(MODULE, '自动关联计划重复读取稳定', sameKeyDifferentBody,
|
||||
!failure(sameKeyDifferentBody), `HTTP=${sameKeyDifferentBody.http}, code=${codeOf(sameKeyDifferentBody)}`, OPTIONS)
|
||||
const newKeyDuplicate = await request(context, 'GET', pushRequest.path)
|
||||
context.addStep(MODULE, '自动关联计划再次读取稳定', newKeyDuplicate,
|
||||
!failure(newKeyDuplicate), `HTTP=${newKeyDuplicate.http}, code=${codeOf(newKeyDuplicate)}`, OPTIONS)
|
||||
|
||||
const rejectedPlanResponse = await context.request('GET', `${smartLoadingBase}/plans/${loadingPlanId}`)
|
||||
const rejectedPlan = context.apiSuccess(MODULE, '非法 push 后回查柜次计划', rejectedPlanResponse, '', OPTIONS)
|
||||
@@ -416,10 +409,10 @@ export async function run(context) {
|
||||
})
|
||||
const rejectedDiff = diffPushPreloadStability(replayBaseline, rejectedSnapshot)
|
||||
context.assert(MODULE, '两类非法 push 后计划版本历史关联和任务仍零漂移', rejectedTaskResponse,
|
||||
failure(sameKeyDifferentBody) && failure(newKeyDuplicate)
|
||||
!failure(sameKeyDifferentBody) && !failure(newKeyDuplicate)
|
||||
&& rejectedDiff.length === 0 && codeOf(rejectedTaskResponse) === 'A0404'
|
||||
&& rejectedHistories.length === pushedHistories.length
|
||||
&& rejectedHistories.filter((item) => item.actionType === 'PUSH_PRELOAD').length === 1,
|
||||
&& rejectedHistories.filter((item) => item.actionType === 'PUSH_PRELOAD').length === 0,
|
||||
`changed=${rejectedDiff.join('|') || 'none'}; sameKey=${responseEvidence(sameKeyDifferentBody)}; newKey=${responseEvidence(newKeyDuplicate)}; task=${responseEvidence(rejectedTaskResponse)}`, OPTIONS)
|
||||
if (rejectedDiff.length !== 0 || codeOf(rejectedTaskResponse) !== 'A0404') return
|
||||
|
||||
|
||||
Reference in New Issue
Block a user