fix(shipping-recovery): 恢复库存RPA入口与门禁恢复流程
This commit is contained in:
1 parent
eb55f407ae
commit
938f3dd0e8
8 files changed
+1329
-194
No files matched your search
@@ -59,6 +59,7 @@ const api = vi.hoisted(() => ({
|
||||
confirmCase: vi.fn(),
|
||||
|
||||
validateDraft: vi.fn(),
|
||||
patchHeader: vi.fn(),
|
||||
|
||||
}));
|
||||
|
||||
@@ -89,7 +90,7 @@ vi.mock('../api/shipping.api', () => ({
|
||||
|
||||
confirmWorkspaceShippingOrderReviewCase: api.confirmCase,
|
||||
|
||||
patchWorkspaceShippingOrderReviewHeaderField: vi.fn(),
|
||||
patchWorkspaceShippingOrderReviewHeaderField: api.patchHeader,
|
||||
|
||||
patchWorkspaceShippingOrderReviewLineField: vi.fn(),
|
||||
|
||||
@@ -135,7 +136,7 @@ const buildCase = (patch: Partial<ShippingOrderReviewCase> = {}): ShippingOrderR
|
||||
|
||||
header_values: {},
|
||||
|
||||
lines: [{ line_key: 'line-1' }],
|
||||
lines: [{ draft_line_id: 'line-1' }],
|
||||
|
||||
issues: [],
|
||||
|
||||
@@ -149,7 +150,7 @@ const buildCase = (patch: Partial<ShippingOrderReviewCase> = {}): ShippingOrderR
|
||||
|
||||
line_projections: [{
|
||||
|
||||
line_key: 'line-1',
|
||||
draft_line_id: 'line-1',
|
||||
|
||||
line_index: 0,
|
||||
|
||||
@@ -403,7 +404,7 @@ describe('useShippingOrderReview build eligibility writes', () => {
|
||||
expect(review.canConfirmBuild.value).toBe(false);
|
||||
|
||||
expect(review.routingRecoveryLines.value).toHaveLength(1);
|
||||
expect(review.routingRecoveryLines.value[0]?.line_key).toBe('line-1');
|
||||
expect(review.routingRecoveryLines.value[0]?.draft_line_id).toBe('line-1');
|
||||
|
||||
});
|
||||
|
||||
@@ -441,6 +442,68 @@ describe('useShippingOrderReview build eligibility writes', () => {
|
||||
expect(resume).toEqual({ outcome: 'auto_create_enqueued' });
|
||||
});
|
||||
|
||||
it('tracks an enqueued validation until the worker creates the formal order task', async () => {
|
||||
vi.useFakeTimers();
|
||||
const queuedCase = buildCase({
|
||||
status: 'ready',
|
||||
automation: { status: 'queued' },
|
||||
});
|
||||
const confirmedCase = buildCase({
|
||||
status: 'confirmed',
|
||||
order_task_no: 'OT-1',
|
||||
confirmed_task_no: 'OT-1',
|
||||
automation: { status: 'running' },
|
||||
});
|
||||
api.validateDraft.mockResolvedValue({
|
||||
case: queuedCase,
|
||||
resume_outcome: { outcome: 'auto_create_enqueued' },
|
||||
});
|
||||
api.getCase.mockResolvedValueOnce(buildCase()).mockResolvedValue(confirmedCase);
|
||||
api.getQueue.mockResolvedValue({
|
||||
summary: { total: 1, needs_action: 0, processing: 1, completed: 0 },
|
||||
items: [{
|
||||
case_no: 'CASE-1', document_id: 1, status: 'confirmed',
|
||||
lifecycle_stage: 'fulfillment_prep', lifecycle_entries: [],
|
||||
}],
|
||||
});
|
||||
api.getExtractionRun.mockResolvedValue({ run_no: 'RUN-1', status: 'completed' });
|
||||
api.getProcessingWorkItem.mockResolvedValue({
|
||||
work_item_no: 'OT-1', status: 'processing', stage: 'inventory_preparation',
|
||||
});
|
||||
|
||||
const review = useShippingOrderReview();
|
||||
await review.load('RUN-1', 'CASE-1');
|
||||
await review.validate();
|
||||
|
||||
await vi.advanceTimersByTimeAsync(0);
|
||||
expect(review.workflowProgressPolling.value).toBe(true);
|
||||
await vi.advanceTimersByTimeAsync(PROGRESS_POLL_MS + 100);
|
||||
expect(review.reviewProgressContext.value?.user_task_no).toBe('OT-1');
|
||||
expect(api.getProcessingWorkItem).toHaveBeenCalledWith('order_task', 'OT-1');
|
||||
|
||||
review.stopWorkflowProgressPolling();
|
||||
vi.useRealTimers();
|
||||
});
|
||||
|
||||
it('does not treat a field edit revalidation as a formal-order creation request', async () => {
|
||||
vi.useFakeTimers();
|
||||
const revalidatingCase = buildCase({
|
||||
status: 'draft',
|
||||
automation: { status: 'queued' },
|
||||
});
|
||||
api.patchHeader.mockResolvedValue(revalidatingCase);
|
||||
|
||||
const review = useShippingOrderReview();
|
||||
await review.load('RUN-1', 'CASE-1');
|
||||
await review.patchHeader('ship_to_name', '新收货方');
|
||||
await vi.advanceTimersByTimeAsync(PROGRESS_POLL_MS + 100);
|
||||
|
||||
// 字段编辑后的 queued 是异步重校验,不是用户已确认的建单请求。
|
||||
expect(api.getCase).toHaveBeenCalledTimes(1);
|
||||
expect(review.workflowProgressPolling.value).toBe(false);
|
||||
vi.useRealTimers();
|
||||
});
|
||||
|
||||
it('refreshes the current Case silently without entering the PDF-switch loading state', async () => {
|
||||
const review = useShippingOrderReview();
|
||||
await review.load('RUN-1', 'CASE-1');
|
||||
@@ -934,6 +997,44 @@ describe('useShippingOrderReview build eligibility writes', () => {
|
||||
vi.useRealTimers();
|
||||
});
|
||||
|
||||
it('stops workflow progress polling once the unified work item is interrupted (waiting_human)', async () => {
|
||||
vi.useFakeTimers();
|
||||
const readyCase = buildCase({
|
||||
status: 'ready',
|
||||
draft: {
|
||||
...buildCase().draft!,
|
||||
build_eligibility: { can_build: true, status: 'ready', line_projections: [] },
|
||||
},
|
||||
});
|
||||
api.getCase.mockResolvedValue(readyCase);
|
||||
api.getRun.mockResolvedValue({
|
||||
run_no: 'RUN-1', summary: {},
|
||||
items: [{ case_no: 'CASE-1', document_id: 1, status: 'ready', available_actions: ['confirm'] }],
|
||||
});
|
||||
api.getEvidence.mockResolvedValue({ items: [] });
|
||||
api.getPreview.mockResolvedValue({ preview_url: '' });
|
||||
api.getProcessingWorkItem.mockResolvedValue({
|
||||
work_item_no: 'OT-1', status: 'blocked', user_status: 'waiting_human',
|
||||
currentGate: { gateCode: 'inventory_matching', status: 'blocked_manual' },
|
||||
});
|
||||
api.confirmCase.mockResolvedValue({
|
||||
task_no: 'SN-1', order_task_no: 'OT-1', shipping_notice_no: 'SN-1', idempotent_replay: false,
|
||||
case: { ...readyCase, status: 'confirmed', order_task_no: 'OT-1' }, auto_progress_started: true,
|
||||
});
|
||||
|
||||
const review = useShippingOrderReview();
|
||||
await review.load('RUN-1', 'CASE-1', { conversationId: 'conv-1', itemNo: 'WFI-1' });
|
||||
await review.confirm();
|
||||
|
||||
await vi.advanceTimersByTimeAsync(0);
|
||||
await Promise.resolve();
|
||||
// 中断(waiting_human,即“等待人工处理”)视为线性终态:结果不会自行变化,必须停止轮询。
|
||||
expect(review.workflowProgressPolling.value).toBe(false);
|
||||
|
||||
review.stopWorkflowProgressPolling();
|
||||
vi.useRealTimers();
|
||||
});
|
||||
|
||||
it('refreshes the active Case and queue while post-confirm automation is still active', async () => {
|
||||
vi.useFakeTimers();
|
||||
const readyCase = buildCase({
|
||||
@@ -1116,7 +1217,8 @@ describe('useShippingOrderReview build eligibility writes', () => {
|
||||
run_no: caseNo === 'CASE-2' ? 'RUN-2' : 'RUN-1',
|
||||
}));
|
||||
|
||||
const review = useShippingOrderReview();
|
||||
const onReparseCaseReady = vi.fn();
|
||||
const review = useShippingOrderReview({ onReparseCaseReady });
|
||||
await review.load('RUN-1', 'CASE-1', { conversationId: 'conv-1', itemNo: 'SWI-1' });
|
||||
await review.reparseDocument('document_quality');
|
||||
|
||||
@@ -1125,6 +1227,8 @@ describe('useShippingOrderReview build eligibility writes', () => {
|
||||
|
||||
expect(review.reviewRun.value?.run_no).toBe('RUN-2');
|
||||
expect(review.activeCase.value?.case_no).toBe('CASE-2');
|
||||
// 关键断言:只有新版 Case 真正落到 activeCase 后,页面才接收可同步深链的目标。
|
||||
expect(onReparseCaseReady).toHaveBeenCalledWith({ runNo: 'RUN-2', caseNo: 'CASE-2', documentId: 1 });
|
||||
review.stopReparseCaseRefreshPolling();
|
||||
vi.useRealTimers();
|
||||
});
|
||||
@@ -1250,6 +1354,44 @@ describe('useShippingOrderReview build eligibility writes', () => {
|
||||
vi.useRealTimers();
|
||||
});
|
||||
|
||||
it('[选法 2] defers review Case + Evidence load on a formal downstream work item', async () => {
|
||||
api.getRun.mockResolvedValue({ run_no: 'RUN-1', summary: {}, items: [] });
|
||||
api.getQueue.mockResolvedValue({
|
||||
summary: { total: 1, needs_action: 0, processing: 0, completed: 1 },
|
||||
items: [{
|
||||
case_no: 'CASE-1', document_id: 1, status: 'confirmed',
|
||||
lifecycle_stage: 'fulfillment_prep', lifecycle_entries: [],
|
||||
has_formal_ot: true, confirmed_task_no: 'SN-1',
|
||||
}],
|
||||
});
|
||||
api.getCase.mockClear();
|
||||
api.getEvidence.mockClear();
|
||||
|
||||
const review = useShippingOrderReview();
|
||||
await review.load('RUN-1', 'CASE-1', { conversationId: 'conv-1' });
|
||||
|
||||
// 正式任务下游阶段:首屏不拉复核 Case 快照 + Evidence。
|
||||
expect(api.getCase).not.toHaveBeenCalled();
|
||||
expect(api.getEvidence).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('[选法 2] loadReviewCase lazily fetches review Case + Evidence on demand', async () => {
|
||||
api.getCase.mockClear();
|
||||
api.getEvidence.mockClear();
|
||||
api.getCase.mockResolvedValue({
|
||||
case: buildCase({ case_no: 'CASE-1' }),
|
||||
projection_version: 1,
|
||||
loading_context: null,
|
||||
});
|
||||
api.getEvidence.mockResolvedValue({ case_no: 'CASE-1', items: [] });
|
||||
|
||||
const review = useShippingOrderReview();
|
||||
await review.loadReviewCase('CASE-1');
|
||||
|
||||
expect(api.getCase).toHaveBeenCalledWith('CASE-1');
|
||||
expect(api.getEvidence).toHaveBeenCalledWith('CASE-1');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
@@ -1295,7 +1437,7 @@ describe('inventory routing recovery', () => {
|
||||
can_build: true,
|
||||
status: 'ready',
|
||||
line_projections: [{
|
||||
line_key: 'line-pending',
|
||||
draft_line_id: 'line-pending',
|
||||
line_index: 0,
|
||||
can_build: false,
|
||||
block_reason: 'inventory_source_unavailable',
|
||||
@@ -1309,7 +1451,7 @@ describe('inventory routing recovery', () => {
|
||||
const review = useShippingOrderReview();
|
||||
await review.load('RUN-1', 'CASE-1');
|
||||
expect(review.routingRecoveryLines.value).toHaveLength(1);
|
||||
expect(review.routingRecoveryLines.value[0]?.line_key).toBe('line-pending');
|
||||
expect(review.routingRecoveryLines.value[0]?.draft_line_id).toBe('line-pending');
|
||||
});
|
||||
|
||||
it('reroutes inventory routing with idempotency_key and expected_draft_version', async () => {
|
||||
@@ -1324,7 +1466,7 @@ describe('inventory routing recovery', () => {
|
||||
expect(api.rerouteInventoryRouting).toHaveBeenCalledWith('CASE-1', {
|
||||
expected_draft_version: 2,
|
||||
idempotency_key: 'idem-reroute-1',
|
||||
line_key: 'line-1',
|
||||
draft_line_id: 'line-1',
|
||||
});
|
||||
expect(review.activeCase.value?.draft?.draft_version).toBe(3);
|
||||
uuidSpy.mockRestore();
|
||||
|
||||
Reference in new issue
Block a user