feat(shipping-notice): 收敛复核状态隔离、STP 重试幂等与 XFA 合成预览标注

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
hugoandCursor committed 2026-08-07 02:58:28 +08:00
1 parent 84a881b554
commit 74270adc22
149 files changed
+20111 -3871

No files matched your search

@@ -0,0 +1,155 @@
/**
* features/shipping-progress/workbenchActionRegistry.spec.ts
* 用途:验收订单处理工作台动作注册表与 fail-closed 规则。
* 依赖:Vitest、workbenchActionRegistry、actionPresentation。
* 逻辑:合法码可渲染;未知码告警且不进入 presentation;review 隐藏自跳转与 refresh。
*/
import { afterEach, describe, expect, it, vi } from 'vitest';
import type { ShippingProcessingProjection } from '@/features/chat/types/shipping.api.types';
import { resolveProcessingActionPresentation } from './actionPresentation';
import {
WORKBENCH_ACTION_REGISTRY,
lookupWorkbenchAction,
resolveWorkbenchActionItem,
shouldRenderWorkbenchAction,
} from './workbenchActionRegistry';
function projection(
overrides: Partial<ShippingProcessingProjection> = {},
): ShippingProcessingProjection {
return {
workItemType: 'order_task',
workItemNo: 'OT-1',
sourceType: 'eml',
rootOrderTaskNo: 'OT-1',
shippingNoticeNo: 'SN-1',
conversationId: 'c1',
submissionNo: 'SOS-1',
intakeNo: 'SNI-1',
status: 'blocked',
stage: 'inventory_matching',
progressVersion: 1,
lastActivityAt: '2026-08-05T00:00:00Z',
currentGate: null,
availableActions: [],
sourceSummary: {
emailSubject: null,
filename: 'a.pdf',
documentCount: 1,
parsedDocumentCount: 1,
candidateCount: 1,
customerName: null,
poNumber: null,
},
childOrderTasks: [],
...overrides,
};
}
describe('workbenchActionRegistry', () => {
afterEach(() => {
vi.restoreAllMocks();
});
it('registers fulfillment and focus actions used by Footer', () => {
for (const code of [
'confirm_inventory_source',
'match_inventory',
'generate_excel',
'mark_manual_uploaded',
'retry_upload',
'view_result',
'view_record',
'confirm_customer',
'open_profile_review',
'open_inventory_source_review',
]) {
expect(lookupWorkbenchAction(code)).toBeTruthy();
}
expect(WORKBENCH_ACTION_REGISTRY.open_inventory_source_review.reviewBehavior).toBe('open_inventory_candidates');
expect(WORKBENCH_ACTION_REGISTRY.confirm_inventory_source.reviewBehavior).toBe('todo_panel');
expect(WORKBENCH_ACTION_REGISTRY.confirm_customer.reviewBehavior).toBe('open_customer_dialog');
});
it('hides open_order_review / edit_formal_task / refresh on review surface', () => {
expect(shouldRenderWorkbenchAction(WORKBENCH_ACTION_REGISTRY.open_order_review, {
actionsExecutable: true,
surface: 'review',
})).toBe(false);
expect(shouldRenderWorkbenchAction(WORKBENCH_ACTION_REGISTRY.edit_formal_task, {
actionsExecutable: true,
surface: 'review',
})).toBe(false);
expect(shouldRenderWorkbenchAction(WORKBENCH_ACTION_REGISTRY.refresh, {
actionsExecutable: true,
surface: 'review',
})).toBe(false);
});
it('hides write actions when actionsExecutable=false but keeps view_result', () => {
expect(shouldRenderWorkbenchAction(WORKBENCH_ACTION_REGISTRY.match_inventory, {
actionsExecutable: false,
surface: 'review',
})).toBe(false);
expect(shouldRenderWorkbenchAction(WORKBENCH_ACTION_REGISTRY.view_result, {
actionsExecutable: false,
surface: 'review',
})).toBe(true);
});
it('warns and omits unregistered action codes from review presentation', () => {
const warn = vi.spyOn(console, 'warn').mockImplementation(() => undefined);
const result = resolveProcessingActionPresentation(projection({
availableActions: ['totally_unknown_action', 'view_result'],
}), { surface: 'review', actionsExecutable: true });
expect(result.primary?.intent).toBe('view_result');
expect(warn).toHaveBeenCalled();
const payload = warn.mock.calls[0]?.[1] as { action_code?: string };
expect(payload?.action_code).toBe('totally_unknown_action');
});
it('exposes match_inventory as primary for review Footer', () => {
const result = resolveProcessingActionPresentation(projection({
currentGate: {
gateCode: 'inventory_match',
status: 'blocked',
nextActionCode: 'match_inventory',
blockingReasonCode: 'inventory_shortage',
attemptNo: 1,
},
availableActions: ['refresh'],
}), { surface: 'review', actionsExecutable: true });
expect(result.primary?.intent).toBe('open_inventory_match_review');
expect(result.primary?.actionCode).toBe('match_inventory');
expect(result.secondary).toBeNull();
});
it('hides confirm_customer when customer panel unavailable', () => {
const warn = vi.spyOn(console, 'warn').mockImplementation(() => undefined);
expect(shouldRenderWorkbenchAction(WORKBENCH_ACTION_REGISTRY.confirm_customer, {
actionsExecutable: true,
surface: 'review',
panels: { customerUnresolved: false },
actionCode: 'confirm_customer',
})).toBe(false);
expect(warn).toHaveBeenCalled();
});
it('routes aliased open_inventory_source_review to todo_panel after create', () => {
// 后端 normalize 后 Footer 只见 open_inventory_source_review;建单后须 Todo。
const pre = resolveWorkbenchActionItem({
intent: 'open_inventory_source_review',
actionCode: 'open_inventory_source_review',
labelKey: 'x',
}, { postCreate: false });
expect(pre?.reviewBehavior).toBe('open_inventory_candidates');
const post = resolveWorkbenchActionItem({
intent: 'open_inventory_source_review',
actionCode: 'open_inventory_source_review',
labelKey: 'x',
}, { postCreate: true });
expect(post?.reviewBehavior).toBe('todo_panel');
expect(post?.todoActionCode).toBe('confirm_inventory_source');
});
});