feat(shipping-notice): 增强发货通知与审计功能,支持敏感数据控制与哈希链校验
- 更新发货通知工具 API,剥离不可信的操作人身份字段,确保审计安全 - 引入审计事件的哈希链校验机制,支持数据完整性验证 - 增强订单抽取与审计功能,支持敏感快照的访问控制 - 更新相关模型与服务,确保新功能的完整性与可追溯性 - 完善文档与代码注释,反映新的业务逻辑与审计要求
This commit is contained in:
1 parent
95cdfe66b0
commit
d0fe084999
225 files changed
+25923
-6653
No files matched your search
@@ -1,31 +1,580 @@
|
||||
/**
|
||||
|
||||
* features/chat/shipping-review/useShippingOrderReview.spec.ts
|
||||
* 用途:阶段 3 复核页历史版本只读契约冒烟。
|
||||
* 依赖:isReviewCaseHistorical 纯函数。
|
||||
* 逻辑:断言 superseded / 非当前 case_no 时强制只读。
|
||||
|
||||
* 用途:阶段 3 复核页历史版本只读、草稿版本冲突、建单资格门禁与库存候选写入冒烟。
|
||||
|
||||
* 依赖:isReviewCaseHistorical / isDraftVersionMismatchError / summarizeDraftConflictDiff /
|
||||
|
||||
* isBuildConfirmBlocked / lineNeedsManualInventorySelection、useShippingOrderReview。
|
||||
|
||||
* 逻辑:断言 superseded 只读、版本冲突码识别、差异摘要、confirm 门禁与 inventory PUT happy path。
|
||||
|
||||
*/
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { isReviewCaseHistorical } from './useShippingOrderReview';
|
||||
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
|
||||
import { BusinessError } from '@/shared/api/client';
|
||||
|
||||
import {
|
||||
|
||||
isBuildConfirmBlocked,
|
||||
|
||||
isDraftVersionMismatchError,
|
||||
|
||||
isReviewCaseHistorical,
|
||||
|
||||
isReviewReadOnly,
|
||||
|
||||
isReviewWorkItemClosed,
|
||||
|
||||
lineNeedsManualInventorySelection,
|
||||
|
||||
REVIEW_BUILD_ELIGIBILITY_BLOCKED,
|
||||
|
||||
REVIEW_DRAFT_VERSION_MISMATCH,
|
||||
|
||||
summarizeDraftConflictDiff,
|
||||
|
||||
useShippingOrderReview,
|
||||
|
||||
} from './useShippingOrderReview';
|
||||
|
||||
import type { ShippingOrderReviewCase } from '../types/shipping.api.types';
|
||||
|
||||
|
||||
|
||||
const api = vi.hoisted(() => ({
|
||||
|
||||
getCase: vi.fn(),
|
||||
|
||||
getRun: vi.fn(),
|
||||
|
||||
getEvidence: vi.fn(),
|
||||
|
||||
getPreview: vi.fn(),
|
||||
|
||||
listWorkflows: vi.fn(),
|
||||
getWorkflowItem: vi.fn(),
|
||||
|
||||
putInventoryCandidates: vi.fn(),
|
||||
|
||||
confirmCase: vi.fn(),
|
||||
|
||||
}));
|
||||
|
||||
|
||||
|
||||
vi.mock('../api/shipping.api', () => ({
|
||||
|
||||
getWorkspaceShippingOrderReviewCase: api.getCase,
|
||||
|
||||
getWorkspaceShippingOrderReviewRun: api.getRun,
|
||||
|
||||
getWorkspaceShippingOrderReviewEvidence: api.getEvidence,
|
||||
|
||||
getWorkspaceShippingOrderReviewPreview: api.getPreview,
|
||||
|
||||
listWorkspaceShippingWorkflows: api.listWorkflows,
|
||||
|
||||
getWorkspaceShippingWorkflowItem: api.getWorkflowItem,
|
||||
|
||||
putWorkspaceShippingOrderReviewInventoryCandidates: api.putInventoryCandidates,
|
||||
|
||||
confirmWorkspaceShippingOrderReviewCase: api.confirmCase,
|
||||
|
||||
patchWorkspaceShippingOrderReviewHeaderField: vi.fn(),
|
||||
|
||||
patchWorkspaceShippingOrderReviewLineField: vi.fn(),
|
||||
|
||||
addWorkspaceShippingOrderReviewLine: vi.fn(),
|
||||
|
||||
copyWorkspaceShippingOrderReviewLine: vi.fn(),
|
||||
|
||||
deleteWorkspaceShippingOrderReviewLine: vi.fn(),
|
||||
|
||||
validateWorkspaceShippingOrderReviewDraft: vi.fn(),
|
||||
|
||||
createWorkspaceShippingOrderReviewManualDraft: vi.fn(),
|
||||
|
||||
markWorkspaceShippingOrderReviewNonOrder: vi.fn(),
|
||||
|
||||
markWorkspaceShippingOrderReviewQualityIssue: vi.fn(),
|
||||
|
||||
reparseWorkspaceShippingOrderReviewDocument: vi.fn(),
|
||||
|
||||
createWorkspaceShippingOrderReviewReplacementIntake: vi.fn(),
|
||||
|
||||
createWorkspaceShippingOrderReviewReplacementRun: vi.fn(),
|
||||
|
||||
}));
|
||||
|
||||
|
||||
|
||||
const buildCase = (patch: Partial<ShippingOrderReviewCase> = {}): ShippingOrderReviewCase => ({
|
||||
|
||||
case_no: 'CASE-1',
|
||||
|
||||
run_no: 'RUN-1',
|
||||
|
||||
document: { id: 1, file_name: 'order.pdf' },
|
||||
|
||||
status: 'draft',
|
||||
|
||||
schema: { schema_version_id: 1, fields: [] },
|
||||
|
||||
draft: {
|
||||
|
||||
draft_version: 2,
|
||||
|
||||
header_values: {},
|
||||
|
||||
lines: [{ line_key: 'line-1' }],
|
||||
|
||||
issues: [],
|
||||
|
||||
validation: {},
|
||||
|
||||
build_eligibility: {
|
||||
|
||||
can_build: false,
|
||||
|
||||
status: 'needs_review',
|
||||
|
||||
line_projections: [{
|
||||
|
||||
line_key: 'line-1',
|
||||
|
||||
line_index: 0,
|
||||
|
||||
effective_reservation_id: '3000000001',
|
||||
|
||||
candidate_inventory_source_codes: ['DSV360_AWSDU', 'DSV360_AWSHK'],
|
||||
|
||||
routing_status: 'conflicted',
|
||||
|
||||
can_build: false,
|
||||
|
||||
block_reason: 'require_manual_review',
|
||||
|
||||
}],
|
||||
|
||||
},
|
||||
|
||||
},
|
||||
|
||||
available_actions: ['edit_draft', 'validate', 'confirm'],
|
||||
|
||||
...patch,
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
describe('useShippingOrderReview historical readonly', () => {
|
||||
|
||||
it('forces readonly when case status is superseded', () => {
|
||||
|
||||
expect(isReviewCaseHistorical(
|
||||
|
||||
{ case_no: 'CASE-OLD', status: 'superseded' },
|
||||
|
||||
{ current_case_no: 'CASE-NEW' },
|
||||
|
||||
)).toBe(true);
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
it('forces readonly when viewing non-current work item case', () => {
|
||||
|
||||
expect(isReviewCaseHistorical(
|
||||
|
||||
{ case_no: 'CASE-OLD', status: 'draft' },
|
||||
|
||||
{ current_case_no: 'CASE-NEW', version_replaced: true },
|
||||
|
||||
)).toBe(true);
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
it('allows edit when viewing current case', () => {
|
||||
|
||||
expect(isReviewCaseHistorical(
|
||||
|
||||
{ case_no: 'CASE-1', status: 'draft' },
|
||||
|
||||
{ current_case_no: 'CASE-1', version_replaced: false },
|
||||
|
||||
)).toBe(false);
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
it('forces readonly when session work item is closed', () => {
|
||||
|
||||
expect(isReviewWorkItemClosed({ lifecycle_status: 'closed', current_case_no: 'CASE-1' })).toBe(true);
|
||||
|
||||
expect(isReviewReadOnly(
|
||||
|
||||
{ case_no: 'CASE-1', status: 'draft' },
|
||||
|
||||
{ current_case_no: 'CASE-1', lifecycle_status: 'closed' },
|
||||
|
||||
)).toBe(true);
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
describe('draft version conflict helpers', () => {
|
||||
|
||||
it('recognizes REVIEW_DRAFT_VERSION_MISMATCH BusinessError', () => {
|
||||
|
||||
expect(isDraftVersionMismatchError(
|
||||
|
||||
new BusinessError({ message: 'stale', code: REVIEW_DRAFT_VERSION_MISMATCH }),
|
||||
|
||||
)).toBe(true);
|
||||
|
||||
expect(isDraftVersionMismatchError(
|
||||
|
||||
new BusinessError({ message: 'other', code: 'SHIPPING.REVIEW_FIELD_INVALID' }),
|
||||
|
||||
)).toBe(false);
|
||||
|
||||
expect(isDraftVersionMismatchError(new Error('nope'))).toBe(false);
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
it('summarizes local vs server draft version and header values', () => {
|
||||
|
||||
const local = {
|
||||
|
||||
status: 'draft',
|
||||
|
||||
draft: {
|
||||
|
||||
draft_version: 3,
|
||||
|
||||
issues: [],
|
||||
|
||||
header_values: { values: { 'po-id': { value: 'PO-LOCAL' } } },
|
||||
|
||||
},
|
||||
|
||||
} as unknown as ShippingOrderReviewCase;
|
||||
|
||||
const server = {
|
||||
|
||||
status: 'ready',
|
||||
|
||||
draft: {
|
||||
|
||||
draft_version: 5,
|
||||
|
||||
issues: [{ code: 'x' }],
|
||||
|
||||
header_values: { values: { 'po-id': { value: 'PO-SERVER' } } },
|
||||
|
||||
},
|
||||
|
||||
} as unknown as ShippingOrderReviewCase;
|
||||
|
||||
const lines = summarizeDraftConflictDiff(local, server);
|
||||
|
||||
expect(lines.some((line) => line.includes('draft_version'))).toBe(true);
|
||||
|
||||
expect(lines.some((line) => line.includes('header.po-id'))).toBe(true);
|
||||
|
||||
expect(lines.some((line) => line.includes('status'))).toBe(true);
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
describe('build eligibility helpers', () => {
|
||||
|
||||
it('blocks confirm only when can_build is explicitly false', () => {
|
||||
|
||||
expect(isBuildConfirmBlocked(null)).toBe(false);
|
||||
|
||||
expect(isBuildConfirmBlocked(undefined)).toBe(false);
|
||||
|
||||
expect(isBuildConfirmBlocked({ can_build: true, status: 'ready', line_projections: [] })).toBe(false);
|
||||
|
||||
expect(isBuildConfirmBlocked({ can_build: false, status: 'needs_review', line_projections: [] })).toBe(true);
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
it('detects lines needing manual inventory selection', () => {
|
||||
|
||||
expect(lineNeedsManualInventorySelection({ can_build: true })).toBe(false);
|
||||
|
||||
expect(lineNeedsManualInventorySelection({
|
||||
|
||||
can_build: false,
|
||||
|
||||
candidate_inventory_source_codes: ['DSV360_AWSDU'],
|
||||
|
||||
})).toBe(true);
|
||||
|
||||
expect(lineNeedsManualInventorySelection({
|
||||
|
||||
can_build: false,
|
||||
|
||||
block_reason: 'require_manual_review',
|
||||
|
||||
})).toBe(true);
|
||||
|
||||
expect(lineNeedsManualInventorySelection({
|
||||
|
||||
can_build: false,
|
||||
|
||||
block_reason: 'customer_unresolved',
|
||||
|
||||
})).toBe(false);
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
describe('useShippingOrderReview build eligibility writes', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
|
||||
api.getRun.mockResolvedValue({
|
||||
|
||||
run_no: 'RUN-1',
|
||||
|
||||
items: [{ case_no: 'CASE-1', status: 'draft', issue_count: 0 }],
|
||||
|
||||
});
|
||||
|
||||
api.getEvidence.mockResolvedValue({ items: [] });
|
||||
|
||||
api.getPreview.mockRejectedValue(new Error('preview unavailable'));
|
||||
|
||||
api.listWorkflows.mockResolvedValue({ conversation_id: 'conv-1', workflows: [] });
|
||||
|
||||
api.getWorkflowItem.mockResolvedValue({
|
||||
item_no: 'SWI-1',
|
||||
workflow_no: 'SNWF-1',
|
||||
conversation_id: 'conv-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('exposes buildEligibility and manualInventoryLines from active case draft', async () => {
|
||||
|
||||
const review = useShippingOrderReview();
|
||||
|
||||
await review.load('RUN-1', 'CASE-1');
|
||||
|
||||
expect(review.buildEligibility.value?.can_build).toBe(false);
|
||||
|
||||
expect(review.canConfirmBuild.value).toBe(false);
|
||||
|
||||
expect(review.manualInventoryLines.value).toHaveLength(1);
|
||||
|
||||
expect(review.manualInventoryLines.value[0]?.line_key).toBe('line-1');
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
it('submits inventory candidates via PUT and refreshes case', async () => {
|
||||
|
||||
const updated = buildCase({
|
||||
|
||||
draft: {
|
||||
|
||||
...buildCase().draft!,
|
||||
|
||||
draft_version: 3,
|
||||
|
||||
build_eligibility: {
|
||||
|
||||
can_build: true,
|
||||
|
||||
status: 'ready',
|
||||
|
||||
line_projections: [{
|
||||
|
||||
line_key: 'line-1',
|
||||
|
||||
line_index: 0,
|
||||
|
||||
can_build: true,
|
||||
|
||||
selection_mode: 'manual',
|
||||
|
||||
manual_reason: 'Confirmed with planner',
|
||||
|
||||
candidate_inventory_source_codes: ['DSV360_AWSDU'],
|
||||
|
||||
}],
|
||||
|
||||
},
|
||||
|
||||
},
|
||||
|
||||
});
|
||||
|
||||
api.putInventoryCandidates.mockResolvedValue(updated);
|
||||
|
||||
|
||||
|
||||
const review = useShippingOrderReview();
|
||||
|
||||
await review.load('RUN-1', 'CASE-1');
|
||||
|
||||
await review.setLineInventoryCandidates('line-1', ['DSV360_AWSDU'], 'Confirmed with planner');
|
||||
|
||||
|
||||
|
||||
expect(api.putInventoryCandidates).toHaveBeenCalledWith('CASE-1', 'line-1', {
|
||||
|
||||
expected_draft_version: 2,
|
||||
|
||||
source_codes: ['DSV360_AWSDU'],
|
||||
|
||||
reason: 'Confirmed with planner',
|
||||
|
||||
});
|
||||
|
||||
expect(review.activeCase.value?.draft?.draft_version).toBe(3);
|
||||
|
||||
expect(review.buildEligibility.value?.can_build).toBe(true);
|
||||
|
||||
expect(review.canConfirmBuild.value).toBe(true);
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
it('blocks confirm when build eligibility cannot build', async () => {
|
||||
|
||||
const review = useShippingOrderReview();
|
||||
|
||||
await review.load('RUN-1', 'CASE-1');
|
||||
|
||||
|
||||
|
||||
await expect(review.confirm()).rejects.toMatchObject({
|
||||
|
||||
code: REVIEW_BUILD_ELIGIBILITY_BLOCKED,
|
||||
|
||||
});
|
||||
|
||||
expect(api.confirmCase).not.toHaveBeenCalled();
|
||||
|
||||
});
|
||||
|
||||
it('starts workflow progress polling after successful confirm', async () => {
|
||||
vi.useFakeTimers();
|
||||
const readyCase: ShippingOrderReviewCase = {
|
||||
case_no: 'CASE-1',
|
||||
run_no: 'RUN-1',
|
||||
document: { id: 1, file_name: 'a.pdf' },
|
||||
status: 'ready',
|
||||
schema: { schema_version_id: 1, fields: [] },
|
||||
draft: {
|
||||
draft_version: 2,
|
||||
header_values: { values: {} },
|
||||
lines: [],
|
||||
issues: [],
|
||||
validation: {},
|
||||
build_eligibility: {
|
||||
can_build: true,
|
||||
status: 'ready',
|
||||
line_projections: [],
|
||||
},
|
||||
},
|
||||
available_actions: ['edit_draft', 'confirm'],
|
||||
};
|
||||
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.listWorkflows.mockResolvedValue({ conversation_id: 'conv-1', workflows: [] });
|
||||
api.getWorkflowItem.mockResolvedValue({
|
||||
item_no: 'WFI-1',
|
||||
workflow_no: 'WF-1',
|
||||
lifecycle_status: 'building_order',
|
||||
current_stage: 'building_order',
|
||||
current_task_no: 'SN-1',
|
||||
current_version_no: 1,
|
||||
});
|
||||
api.confirmCase.mockResolvedValue({
|
||||
task_no: 'SN-1',
|
||||
idempotent_replay: false,
|
||||
workflow_id: 'WF-1',
|
||||
workflow_item_id: 'WFI-1',
|
||||
case: { ...readyCase, status: 'confirmed' },
|
||||
auto_progress_started: true,
|
||||
});
|
||||
|
||||
const review = useShippingOrderReview();
|
||||
await review.load('RUN-1', 'CASE-1', { conversationId: 'conv-1', itemNo: 'WFI-1' });
|
||||
const response = await review.confirm();
|
||||
|
||||
expect(response?.workflow_item_id).toBe('WFI-1');
|
||||
expect(review.showWorkflowProgress.value).toBe(true);
|
||||
expect(review.workflowProgressPolling.value).toBe(true);
|
||||
expect(api.getWorkflowItem).toHaveBeenCalled();
|
||||
|
||||
api.getWorkflowItem.mockResolvedValue({
|
||||
item_no: 'WFI-1',
|
||||
workflow_no: 'WF-1',
|
||||
lifecycle_status: 'manual_upload_pending',
|
||||
current_stage: 'manual_upload_pending',
|
||||
current_task_no: 'SN-1',
|
||||
current_version_no: 1,
|
||||
});
|
||||
await vi.advanceTimersByTimeAsync(2600);
|
||||
expect(review.workItem.value?.lifecycle_status).toBe('manual_upload_pending');
|
||||
expect(review.workflowProgressPolling.value).toBe(false);
|
||||
|
||||
review.stopWorkflowProgressPolling();
|
||||
vi.useRealTimers();
|
||||
});
|
||||
|
||||
});
|
||||
Reference in new issue
Block a user