feat(shipping-notice): 实现对话级批量重试自动推进功能,优化库存与PDF匹配逻辑

- 新增对话级批量重试自动推进的完整链路:后端服务、API、数据投影逻辑
- 前端新增对话级重试按钮、多语言国际化支持与API类型定义
- 优化行级库存重试控制,新增retryable字段统一管控重试按钮展示,清理废弃的view_fulfillment_detail动作,标准化前端动作码排序逻辑
- 修复PDF坐标匹配的fail-close防护逻辑,避免生成伪精确匹配分数
- 调整订单确认后流程,提前进入库存获取阶段,移除冗余的确认建单按钮,优化用户流转体验
- 新增对应单元测试用例覆盖核心业务逻辑
This commit is contained in:
hugo committed 2026-08-07 16:30:45 +08:00
1 parent fd6a23f870
commit 1008911a7e
41 files changed
+3956 -1256

No files matched your search

@@ -15,6 +15,10 @@ import {
groupConversationProcessingTasks,
mapUserTaskObjectsToFileRows,
resolveConversationProcessingFromUnified,
normalizeActionCodes,
buildTaskSemanticKey,
buildProcessingSemanticKey,
stabilizeTaskObjects,
} from './conversationProcessingProjection';
import type {
ShippingProcessingProjection,
@@ -730,3 +734,166 @@ describe('conversationProcessingProjection', () => {
expect(merged?.recent_task_no).toBe('OT-RECENT');
});
});
/**
* 方案 1~4 的防御链单元测试:
* normalize → semanticKey → stabilize;任何一环击穿都会导致轮询按钮闪烁。
* 对应验收:动作顺序变化按钮不变 / updated_at 变化按钮不变 / 轮询相同数据按钮 DOM 不变。
*/
describe('conversationProcessingProjection — normalize & semantic & stabilize', () => {
it('normalizeActionCodes: 去空白、小写、去重、字典序排序', () => {
expect(normalizeActionCodes([' View_Details ', 'Confirm_Customer', 'view_details', ' confirm_customer ']))
.toEqual(['confirm_customer', 'view_details']);
expect(normalizeActionCodes([null, undefined, '', ' ', 'cancel', '0']))
.toEqual(['0', 'cancel']);
expect(normalizeActionCodes([])).toEqual([]);
expect(normalizeActionCodes([undefined, null])).toEqual([]);
});
it('buildTaskSemanticKey: available_actions 乱序 → 同一签名(不影响按钮顺序)', () => {
const base: Parameters<typeof projectConversationProcessingFromWorkItems>[0][number] = {
workItemType: 'order_task',
workItemNo: 'OT-1',
sourceType: 'direct_pdf',
rootOrderTaskNo: 'OT-1',
shippingNoticeNo: null,
conversationId: 'conv-1',
submissionNo: 'SOS-1',
intakeNo: 'SNI-1',
status: 'waiting_review',
stage: 'waiting_review',
progressVersion: 1,
lastActivityAt: '2026-08-10T00:00:00Z',
currentGate: {
gateCode: 'order_freeze_readiness',
status: 'blocked',
nextActionCode: 'open_order_review',
blockingReasonCode: 'review_case_draft',
attemptNo: 0,
},
availableActions: ['open_order_review', 'view_details'],
sourceSummary: {
emailSubject: null,
filename: 'a.pdf',
documentCount: 1,
parsedDocumentCount: 1,
candidateCount: 0,
customerName: null,
poNumber: 'PO-1',
},
childOrderTasks: [],
};
const p1 = projectConversationProcessingFromWorkItems([{ ...base }]);
const p2 = projectConversationProcessingFromWorkItems([
{ ...base, availableActions: ['view_details', 'open_order_review'], lastActivityAt: '2099-01-01T00:00:00Z' },
]);
const t1 = p1!.needs_action[0]!;
const t2 = p2!.needs_action[0]!;
// 相同语义字段 -> 同签名;即使 available_actions 顺序不同、lastActivityAt 不同。
expect(buildTaskSemanticKey(t1)).toBe(buildTaskSemanticKey(t2));
// available_actions 内永远是 normalized 排序后的数组,不是原始后端乱序。
expect(t1.available_actions).toEqual(['open_order_review', 'view_details']);
expect(t2.available_actions).toEqual(['open_order_review', 'view_details']);
});
it('stabilizeTaskObjects: 同一 user_task_no 且语义相同,优先复用旧对象引用(避免 DOM 重建)', () => {
const baseTask = (no: string, updatedAt: string) => ({
user_task_no: no,
group: 'processing' as const,
status_label: 'document_parsing',
run_no: 'RUN-1',
title: '订单识别任务',
primary_action: 'view_details',
display_kind: 'single_document_task',
file_count: 1,
can_append: false,
updated_at: updatedAt,
last_activity_at: updatedAt,
available_actions: ['view_details'],
current_gate: null,
user_task_authoritative: true,
documents: [],
});
const oldOne = baseTask('OT-1', '2026-08-10T00:00:00Z');
const nextOne = baseTask('OT-1', '2026-08-10T00:00:02Z');
const oldTasks = [oldOne];
const nextRawTasks = [nextOne];
const stabilized = stabilizeTaskObjects(oldTasks, nextRawTasks);
// updated_at/last_activity_at 不参与 semanticKey 比较 -> 复用旧引用。
expect(stabilized[0]).toBe(oldOne);
expect(stabilized[0].updated_at).toBe('2026-08-10T00:00:00Z');
});
it('buildProcessingSemanticKey: 只基于语义字段,忽略 updated_at/last_activity_at 扰动', () => {
function makeProjection() {
return projectConversationProcessingFromWorkItems([{
workItemType: 'order_task',
workItemNo: 'OT-A',
sourceType: 'direct_pdf',
rootOrderTaskNo: 'OT-A',
shippingNoticeNo: null,
conversationId: 'conv-1',
submissionNo: 'SOS-1',
intakeNo: 'SNI-1',
status: 'processing',
stage: 'document_parsing',
progressVersion: 1,
lastActivityAt: '2026-08-10T00:00:00Z',
currentGate: null,
availableActions: ['view_details'],
sourceSummary: {
emailSubject: null, filename: 'a.pdf',
documentCount: 1, parsedDocumentCount: 1, candidateCount: 0,
customerName: null, poNumber: null,
},
childOrderTasks: [],
}])!;
}
const pA = makeProjection();
const pB = makeProjection();
// 模拟轮询差异:updated_at / last_activity_at / created_at 等辅助字段都变。
pA.processing[0]!.updated_at = '2026-08-10T00:00:00Z';
pA.processing[0]!.last_activity_at = '2026-08-10T00:00:00Z';
pB.processing[0]!.updated_at = '2026-08-10T00:00:02Z';
pB.processing[0]!.last_activity_at = '2026-08-10T00:00:02Z';
expect(buildProcessingSemanticKey(pA)).toBe(buildProcessingSemanticKey(pB));
});
it('stabilizeTaskObjects: 语义变化时(status 改变)必须返回新对象,不能错误冻结旧状态', () => {
const oldTask = {
user_task_no: 'OT-1',
group: 'processing' as const,
status_label: 'document_parsing',
run_no: 'RUN-1',
title: '订单识别任务',
primary_action: 'view_details',
display_kind: 'single_document_task',
file_count: 1,
can_append: false,
updated_at: '2026-08-10T00:00:00Z',
last_activity_at: '2026-08-10T00:00:00Z',
available_actions: ['view_details'],
current_gate: null,
user_task_authoritative: true,
documents: [],
};
const nextTask = {
...oldTask,
group: 'needs_action' as const,
status_label: 'waiting_review',
primary_action: 'open_order_review',
available_actions: ['open_order_review', 'view_details'],
updated_at: '2026-08-10T00:00:10Z',
last_activity_at: '2026-08-10T00:00:10Z',
current_gate: {
blockingReasonCode: 'review_case_draft',
nextActionCode: 'open_order_review',
},
};
const stabilized = stabilizeTaskObjects([oldTask], [nextTask]);
// 状态从 processing→needs_action 语义已变,必须替换成新引用。
expect(stabilized[0]).not.toBe(oldTask);
expect(stabilized[0].status_label).toBe('waiting_review');
expect(stabilized[0].available_actions).toEqual(['open_order_review', 'view_details']);
});
});