feat(shipping-notice): 新增发货通知自动上传功能与候选资格评估
- 在环境配置中新增 SHIPPING_NOTICE_AUTO_UPLOAD_ENABLED 选项,默认关闭,需显式开启以支持自动上传。 - 引入新的 pytest.ini 文件,增加测试标记以支持自动化测试。 - 删除不再使用的 seed_shipping_notice_agents.py 文件,简化代码库。 - 更新相关 API,增强发货通知与候选资格评估功能,支持多种筛选条件。 - 增强文档与代码注释,反映新的业务逻辑与功能要求。
This commit is contained in:
1 parent
cef3d5b26a
commit
3a9fbac2fc
226 files changed
+25010
-2098
No files matched your search
@@ -1,15 +1,11 @@
|
||||
/**
|
||||
|
||||
* features/chat/shipping-review/useShippingOrderReview.spec.ts
|
||||
|
||||
* 用途:阶段 3 复核页历史版本只读、草稿版本冲突、建单资格门禁与库存候选写入冒烟。
|
||||
|
||||
* 用途:阶段 3 复核页历史版本只读、草稿版本冲突、建单资格门禁、库存候选与路由恢复写入冒烟。
|
||||
* 依赖:isReviewCaseHistorical / isDraftVersionMismatchError / summarizeDraftConflictDiff /
|
||||
|
||||
* isBuildConfirmBlocked / lineNeedsManualInventorySelection、useShippingOrderReview。
|
||||
|
||||
* 逻辑:断言 superseded 只读、版本冲突码识别、差异摘要、confirm 门禁与 inventory PUT happy path。
|
||||
|
||||
* isBuildConfirmBlocked / lineNeedsManualInventorySelection /
|
||||
* lineHasPendingRoutingSuggestion / lineNeedsInventoryRoutingRecovery、useShippingOrderReview。
|
||||
* 逻辑:断言 superseded 只读、版本冲突码识别、差异摘要、confirm 门禁、inventory PUT、
|
||||
* reroute/adopt/keep 与 suggestion_pending 行筛选。
|
||||
*/
|
||||
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
@@ -30,6 +26,10 @@ import {
|
||||
|
||||
lineNeedsManualInventorySelection,
|
||||
|
||||
lineHasPendingRoutingSuggestion,
|
||||
|
||||
lineNeedsInventoryRoutingRecovery,
|
||||
|
||||
REVIEW_BUILD_ELIGIBILITY_BLOCKED,
|
||||
|
||||
REVIEW_DRAFT_VERSION_MISMATCH,
|
||||
@@ -57,7 +57,12 @@ const api = vi.hoisted(() => ({
|
||||
listWorkflows: vi.fn(),
|
||||
getWorkflowItem: vi.fn(),
|
||||
|
||||
reparseDocument: vi.fn(),
|
||||
|
||||
putInventoryCandidates: vi.fn(),
|
||||
rerouteInventoryRouting: vi.fn(),
|
||||
adoptInventoryRoutingSuggestion: vi.fn(),
|
||||
keepManualInventoryRouting: vi.fn(),
|
||||
|
||||
confirmCase: vi.fn(),
|
||||
|
||||
@@ -80,6 +85,9 @@ vi.mock('../api/shipping.api', () => ({
|
||||
getWorkspaceShippingWorkflowItem: api.getWorkflowItem,
|
||||
|
||||
putWorkspaceShippingOrderReviewInventoryCandidates: api.putInventoryCandidates,
|
||||
postWorkspaceShippingOrderReviewInventoryRoutingReroute: api.rerouteInventoryRouting,
|
||||
postWorkspaceShippingOrderReviewInventoryRoutingAdoptSuggestion: api.adoptInventoryRoutingSuggestion,
|
||||
postWorkspaceShippingOrderReviewInventoryRoutingKeepManual: api.keepManualInventoryRouting,
|
||||
|
||||
confirmWorkspaceShippingOrderReviewCase: api.confirmCase,
|
||||
|
||||
@@ -101,7 +109,7 @@ vi.mock('../api/shipping.api', () => ({
|
||||
|
||||
markWorkspaceShippingOrderReviewQualityIssue: vi.fn(),
|
||||
|
||||
reparseWorkspaceShippingOrderReviewDocument: vi.fn(),
|
||||
reparseWorkspaceShippingOrderReviewDocument: api.reparseDocument,
|
||||
|
||||
createWorkspaceShippingOrderReviewReplacementIntake: vi.fn(),
|
||||
|
||||
@@ -414,6 +422,23 @@ describe('useShippingOrderReview build eligibility writes', () => {
|
||||
|
||||
});
|
||||
|
||||
it('does not prefetch PDF preview on load or selectCase; ensurePreviewLoaded fetches on demand', async () => {
|
||||
// 关键断言:进入工作台/切换文档不触发 preview 审计与下载。
|
||||
const review = useShippingOrderReview();
|
||||
await review.load('RUN-1', 'CASE-1');
|
||||
expect(api.getPreview).not.toHaveBeenCalled();
|
||||
|
||||
await review.selectCase('CASE-1');
|
||||
expect(api.getPreview).not.toHaveBeenCalled();
|
||||
|
||||
const blob = new Blob(['%PDF'], { type: 'application/pdf' });
|
||||
api.getPreview.mockResolvedValue(blob);
|
||||
const ok = await review.ensurePreviewLoaded('CASE-1');
|
||||
expect(ok).toBe(true);
|
||||
expect(api.getPreview).toHaveBeenCalledTimes(1);
|
||||
expect(review.previewUrl.value).toMatch(/^blob:/);
|
||||
});
|
||||
|
||||
|
||||
|
||||
it('submits inventory candidates via PUT and refreshes case', async () => {
|
||||
@@ -577,4 +602,237 @@ describe('useShippingOrderReview build eligibility writes', () => {
|
||||
vi.useRealTimers();
|
||||
});
|
||||
|
||||
it('polls reparse progress and loads the new review version when ready', async () => {
|
||||
vi.useFakeTimers();
|
||||
let reparseStarted = false;
|
||||
let reparsePollCount = 0;
|
||||
api.reparseDocument.mockImplementation(async () => {
|
||||
reparseStarted = true;
|
||||
return { run: { run_no: 'RUN-2', items: [], summary: {} }, reused: false };
|
||||
});
|
||||
api.getRun.mockImplementation(async (runNo: string) => ({
|
||||
run_no: runNo,
|
||||
summary: {},
|
||||
items: [{ case_no: runNo === 'RUN-2' ? 'CASE-2' : 'CASE-1', status: 'draft', issue_count: 0 }],
|
||||
}));
|
||||
api.getCase.mockImplementation(async (caseNo: string) => buildCase({
|
||||
case_no: caseNo,
|
||||
run_no: caseNo === 'CASE-2' ? 'RUN-2' : 'RUN-1',
|
||||
}));
|
||||
api.getWorkflowItem.mockImplementation(async () => {
|
||||
if (reparseStarted) reparsePollCount += 1;
|
||||
const ready = reparseStarted && reparsePollCount > 2;
|
||||
return {
|
||||
item_no: 'SWI-1',
|
||||
current_run_no: ready ? 'RUN-2' : 'RUN-1',
|
||||
current_case_no: ready ? 'CASE-2' : 'CASE-1',
|
||||
lifecycle_status: ready ? 'pending_review' : (reparseStarted ? 'extracting' : 'pending_review'),
|
||||
current_stage: ready ? 'pending_review' : (reparseStarted ? 'extracting' : 'pending_review'),
|
||||
current_version_no: ready ? 2 : 1,
|
||||
};
|
||||
});
|
||||
|
||||
const review = useShippingOrderReview();
|
||||
await review.load('RUN-1', 'CASE-1', { conversationId: 'conv-1', itemNo: 'SWI-1' });
|
||||
await review.reparseDocument('document_quality');
|
||||
|
||||
expect(review.reparseProgressActive.value).toBe(true);
|
||||
await vi.advanceTimersByTimeAsync(2600);
|
||||
|
||||
// 关键断言:新版指针就绪后自动停止轮询并加载新的 Run/Case。
|
||||
expect(review.reparseProgressStage.value).toBe('draft_ready');
|
||||
expect(review.reparseProgressPolling.value).toBe(false);
|
||||
expect(review.reviewRun.value?.run_no).toBe('RUN-2');
|
||||
expect(review.activeCase.value?.case_no).toBe('CASE-2');
|
||||
review.stopReparseProgressPolling();
|
||||
vi.useRealTimers();
|
||||
});
|
||||
|
||||
it('refreshes the work item before resolving the current version target', async () => {
|
||||
const review = useShippingOrderReview();
|
||||
await review.load('RUN-1', 'CASE-1', { conversationId: 'conv-1', itemNo: 'SWI-1' });
|
||||
api.getWorkflowItem.mockResolvedValue({
|
||||
item_no: 'SWI-1', current_run_no: 'RUN-2', current_case_no: 'CASE-2',
|
||||
lifecycle_status: 'pending_review', current_stage: 'pending_review', current_version_no: 2,
|
||||
});
|
||||
api.getRun.mockResolvedValue({
|
||||
run_no: 'RUN-2', summary: {}, items: [{ case_no: 'CASE-2', status: 'draft', issue_count: 0 }],
|
||||
});
|
||||
api.getCase.mockResolvedValue(buildCase({ case_no: 'CASE-2', run_no: 'RUN-2' }));
|
||||
|
||||
const target = await review.openCurrentVersion();
|
||||
|
||||
expect(target).toEqual({ runNo: 'RUN-2', caseNo: 'CASE-2' });
|
||||
expect(review.activeCase.value?.case_no).toBe('CASE-2');
|
||||
});
|
||||
|
||||
it('shows a terminal failed stage when reparse fails', async () => {
|
||||
vi.useFakeTimers();
|
||||
api.reparseDocument.mockResolvedValue({
|
||||
run: { run_no: 'RUN-FAILED', items: [], summary: {} }, reused: false,
|
||||
});
|
||||
api.getWorkflowItem.mockResolvedValue({
|
||||
item_no: 'SWI-1', current_run_no: 'RUN-1', current_case_no: 'CASE-1',
|
||||
lifecycle_status: 'reparse_failed', current_stage: 'reparse_failed', current_version_no: 1,
|
||||
});
|
||||
|
||||
const review = useShippingOrderReview();
|
||||
await review.load('RUN-1', 'CASE-1', { conversationId: 'conv-1', itemNo: 'SWI-1' });
|
||||
await review.reparseDocument('document_quality');
|
||||
await vi.runAllTicks();
|
||||
|
||||
// 关键断言:失败必须成为明确终态,不能继续伪装为字段提取进行中。
|
||||
expect(review.reparseProgressStage.value).toBe('failed');
|
||||
expect(review.reparseProgressPolling.value).toBe(false);
|
||||
review.stopReparseProgressPolling();
|
||||
vi.useRealTimers();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
describe('inventory routing recovery', () => {
|
||||
beforeEach(() => {
|
||||
api.getRun.mockResolvedValue({
|
||||
run_no: 'RUN-1',
|
||||
summary: {},
|
||||
items: [{
|
||||
case_no: 'CASE-1',
|
||||
document_id: 1,
|
||||
file_name: 'order.pdf',
|
||||
status: 'draft',
|
||||
draft_version: 2,
|
||||
issue_count: 0,
|
||||
available_actions: ['edit_draft', 'validate', 'confirm'],
|
||||
}],
|
||||
});
|
||||
api.getEvidence.mockResolvedValue({ items: [] });
|
||||
api.getPreview.mockResolvedValue(new Blob());
|
||||
api.listWorkflows.mockResolvedValue({ conversation_id: 'conv-1', workflows: [] });
|
||||
api.getWorkflowItem.mockResolvedValue({
|
||||
item_no: 'WFI-1',
|
||||
workflow_no: 'WF-1',
|
||||
root_document_id: 1,
|
||||
current_document_id: 1,
|
||||
current_version_no: 1,
|
||||
current_case_no: 'CASE-1',
|
||||
lifecycle_status: 'pending_review',
|
||||
current_stage: 'pending_review',
|
||||
lock_version: 1,
|
||||
});
|
||||
api.getCase.mockResolvedValue(buildCase());
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
it('detects pending suggestion and recovery lines beyond manual selection', () => {
|
||||
// 关键断言:suggestion_pending 即使 can_build true 也应进入恢复集合。
|
||||
expect(lineHasPendingRoutingSuggestion({ suggestion_pending: true })).toBe(true);
|
||||
expect(lineNeedsInventoryRoutingRecovery({
|
||||
can_build: true,
|
||||
suggestion_pending: true,
|
||||
})).toBe(true);
|
||||
expect(lineNeedsInventoryRoutingRecovery({
|
||||
can_build: true,
|
||||
unavailable_source_codes: ['OFFLINE_SRC'],
|
||||
})).toBe(true);
|
||||
expect(lineNeedsManualInventorySelection({
|
||||
can_build: true,
|
||||
suggestion_pending: true,
|
||||
})).toBe(false);
|
||||
});
|
||||
|
||||
it('exposes routingRecoveryLines for suggestion_pending rows', async () => {
|
||||
api.getCase.mockResolvedValue(buildCase({
|
||||
draft: {
|
||||
...buildCase().draft!,
|
||||
build_eligibility: {
|
||||
can_build: true,
|
||||
status: 'ready',
|
||||
line_projections: [{
|
||||
line_key: 'line-pending',
|
||||
line_index: 0,
|
||||
can_build: true,
|
||||
suggestion_pending: true,
|
||||
rule_suggestion_source_codes: ['DSV360_AWSDU'],
|
||||
candidate_inventory_source_codes: ['DSV360_AWSHK'],
|
||||
selection_mode: 'manual',
|
||||
}],
|
||||
},
|
||||
},
|
||||
}));
|
||||
const review = useShippingOrderReview();
|
||||
await review.load('RUN-1', 'CASE-1');
|
||||
expect(review.manualInventoryLines.value).toHaveLength(0);
|
||||
expect(review.routingRecoveryLines.value).toHaveLength(1);
|
||||
expect(review.routingRecoveryLines.value[0]?.line_key).toBe('line-pending');
|
||||
});
|
||||
|
||||
it('reroutes inventory routing with idempotency_key and expected_draft_version', async () => {
|
||||
const updated = buildCase({ draft: { ...buildCase().draft!, draft_version: 3 } });
|
||||
api.rerouteInventoryRouting.mockResolvedValue(updated);
|
||||
const uuidSpy = vi.spyOn(crypto, 'randomUUID').mockReturnValue('idem-reroute-1');
|
||||
|
||||
const review = useShippingOrderReview();
|
||||
await review.load('RUN-1', 'CASE-1');
|
||||
await review.rerouteInventoryRouting('line-1');
|
||||
|
||||
expect(api.rerouteInventoryRouting).toHaveBeenCalledWith('CASE-1', {
|
||||
expected_draft_version: 2,
|
||||
idempotency_key: 'idem-reroute-1',
|
||||
line_key: 'line-1',
|
||||
});
|
||||
expect(review.activeCase.value?.draft?.draft_version).toBe(3);
|
||||
uuidSpy.mockRestore();
|
||||
});
|
||||
|
||||
it('adopts and keeps inventory routing suggestions via POST APIs', async () => {
|
||||
const updated = buildCase({ draft: { ...buildCase().draft!, draft_version: 4 } });
|
||||
api.adoptInventoryRoutingSuggestion.mockResolvedValue(updated);
|
||||
api.keepManualInventoryRouting.mockResolvedValue(updated);
|
||||
const uuidSpy = vi.spyOn(crypto, 'randomUUID')
|
||||
.mockReturnValueOnce('idem-adopt-1')
|
||||
.mockReturnValueOnce('idem-keep-1');
|
||||
|
||||
const review = useShippingOrderReview();
|
||||
await review.load('RUN-1', 'CASE-1');
|
||||
await review.adoptInventoryRoutingSuggestion('line-1', 'use rule');
|
||||
await review.keepManualInventoryRouting('line-1', 'keep manual');
|
||||
|
||||
expect(api.adoptInventoryRoutingSuggestion).toHaveBeenCalledWith('CASE-1', 'line-1', {
|
||||
expected_draft_version: 2,
|
||||
idempotency_key: 'idem-adopt-1',
|
||||
reason: 'use rule',
|
||||
});
|
||||
expect(api.keepManualInventoryRouting).toHaveBeenCalledWith('CASE-1', 'line-1', {
|
||||
expected_draft_version: 4,
|
||||
idempotency_key: 'idem-keep-1',
|
||||
reason: 'keep manual',
|
||||
});
|
||||
uuidSpy.mockRestore();
|
||||
});
|
||||
|
||||
it('sets draftConflict on 409 VERSION_MISMATCH during reroute', async () => {
|
||||
api.rerouteInventoryRouting.mockRejectedValue(
|
||||
new BusinessError({ message: 'stale', code: REVIEW_DRAFT_VERSION_MISMATCH }),
|
||||
);
|
||||
api.getCase
|
||||
.mockResolvedValueOnce(buildCase())
|
||||
.mockResolvedValueOnce(buildCase({
|
||||
draft: { ...buildCase().draft!, draft_version: 9 },
|
||||
}));
|
||||
|
||||
const review = useShippingOrderReview();
|
||||
await review.load('RUN-1', 'CASE-1');
|
||||
await expect(review.rerouteInventoryRouting('line-1')).rejects.toMatchObject({
|
||||
code: REVIEW_DRAFT_VERSION_MISMATCH,
|
||||
});
|
||||
expect(review.draftConflict.value).toMatchObject({
|
||||
localVersion: 2,
|
||||
serverVersion: 9,
|
||||
});
|
||||
expect(review.saveFailed.value).toBe(true);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user