feat(shipping-notice): 增强发货通知与审计功能,支持敏感数据控制与哈希链校验
- 更新发货通知工具 API,剥离不可信的操作人身份字段,确保审计安全 - 引入审计事件的哈希链校验机制,支持数据完整性验证 - 增强订单抽取与审计功能,支持敏感快照的访问控制 - 更新相关模型与服务,确保新功能的完整性与可追溯性 - 完善文档与代码注释,反映新的业务逻辑与审计要求
This commit is contained in:
1 parent
95cdfe66b0
commit
d0fe084999
225 files changed
+25923
-6653
No files matched your search
@@ -0,0 +1,201 @@
|
||||
/**
|
||||
* features/chat/shipping/useShippingNoticeWorkflow.spec.ts
|
||||
* 用途:覆盖 Workflow 轮询退避、多批次选择、停轮询条件与取消/重识别后刷新。
|
||||
* 依赖:Vitest、vue、shipping.api mock。
|
||||
* 逻辑:断言 backoff 封顶、终态停轮询、选中保留、cancelItem/reparseItem 调 API 后 refresh。
|
||||
*/
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
import { nextTick, ref } from 'vue';
|
||||
import {
|
||||
resolveSelectedWorkflowNo,
|
||||
resolveWorkflowPollBackoffMs,
|
||||
shouldContinueWorkflowPolling,
|
||||
useShippingNoticeWorkflow,
|
||||
} from './useShippingNoticeWorkflow';
|
||||
import type { ShippingWorkflow, ShippingWorkflowItem } from '../types/shipping.api.types';
|
||||
|
||||
const api = vi.hoisted(() => ({
|
||||
listWorkflows: vi.fn(),
|
||||
cancelItem: vi.fn(),
|
||||
reparseItem: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock('../api/shipping.api', () => ({
|
||||
listWorkspaceShippingWorkflows: api.listWorkflows,
|
||||
cancelWorkspaceShippingWorkflowItem: api.cancelItem,
|
||||
reparseWorkspaceShippingWorkflowItem: api.reparseItem,
|
||||
}));
|
||||
|
||||
function buildItem(patch: Partial<ShippingWorkflowItem> = {}): ShippingWorkflowItem {
|
||||
return {
|
||||
item_no: 'SWI-1',
|
||||
workflow_no: 'SNWF-1',
|
||||
conversation_id: 'conv-1',
|
||||
root_document_id: 1,
|
||||
current_document_id: 1,
|
||||
current_document_filename: 'notice-a.pdf',
|
||||
current_version_no: 1,
|
||||
lifecycle_status: 'layout_parsing',
|
||||
current_stage: 'layout_parsing',
|
||||
lock_version: 1,
|
||||
...patch,
|
||||
};
|
||||
}
|
||||
|
||||
function buildWorkflow(patch: Partial<ShippingWorkflow> = {}): ShippingWorkflow {
|
||||
const items = patch.items ?? [buildItem()];
|
||||
return {
|
||||
workflow_no: 'SNWF-1',
|
||||
conversation_id: 'conv-1',
|
||||
status: 'open',
|
||||
current_stage: 'layout_parsing',
|
||||
lock_version: 1,
|
||||
counts: {
|
||||
total: items.length,
|
||||
processing: items.length,
|
||||
pending_review: 0,
|
||||
failed: 0,
|
||||
completed: 0,
|
||||
},
|
||||
items,
|
||||
...patch,
|
||||
};
|
||||
}
|
||||
|
||||
describe('useShippingNoticeWorkflow helpers', () => {
|
||||
it('caps failure backoff at 8s', () => {
|
||||
expect(resolveWorkflowPollBackoffMs(1)).toBe(2000);
|
||||
expect(resolveWorkflowPollBackoffMs(2)).toBe(4000);
|
||||
expect(resolveWorkflowPollBackoffMs(3)).toBe(8000);
|
||||
expect(resolveWorkflowPollBackoffMs(10)).toBe(8000);
|
||||
});
|
||||
|
||||
it('stops polling on terminal workflow status', () => {
|
||||
const workflow = buildWorkflow({ status: 'completed' });
|
||||
expect(shouldContinueWorkflowPolling([workflow])).toBe(false);
|
||||
});
|
||||
|
||||
it('continues while layout_parsing items remain', () => {
|
||||
const items = [buildItem({ lifecycle_status: 'layout_parsing' })];
|
||||
const workflow = buildWorkflow({ status: 'open', items });
|
||||
expect(shouldContinueWorkflowPolling([workflow])).toBe(true);
|
||||
});
|
||||
|
||||
it('stops when open workflow has only closed items', () => {
|
||||
const items = [buildItem({ lifecycle_status: 'closed' })];
|
||||
const workflow = buildWorkflow({ status: 'open', items });
|
||||
expect(shouldContinueWorkflowPolling([workflow])).toBe(false);
|
||||
});
|
||||
|
||||
it('keeps previous selection when still present, else first', () => {
|
||||
const a = buildWorkflow({ workflow_no: 'SNWF-A' });
|
||||
const b = buildWorkflow({ workflow_no: 'SNWF-B' });
|
||||
expect(resolveSelectedWorkflowNo([a, b], 'SNWF-B')).toBe('SNWF-B');
|
||||
expect(resolveSelectedWorkflowNo([a, b], 'SNWF-GONE')).toBe('SNWF-A');
|
||||
expect(resolveSelectedWorkflowNo([a, b], 'SNWF-A', 'SNWF-B')).toBe('SNWF-B');
|
||||
});
|
||||
});
|
||||
|
||||
describe('useShippingNoticeWorkflow', () => {
|
||||
beforeEach(() => {
|
||||
api.listWorkflows.mockReset();
|
||||
api.cancelItem.mockReset();
|
||||
api.reparseItem.mockReset();
|
||||
vi.useFakeTimers();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
vi.useRealTimers();
|
||||
});
|
||||
|
||||
it('loads open workflow items and exposes cancelItem refresh', async () => {
|
||||
const workflow = buildWorkflow({
|
||||
items: [
|
||||
buildItem({ item_no: 'SWI-A', lifecycle_status: 'extracting' }),
|
||||
buildItem({ item_no: 'SWI-B', lifecycle_status: 'pending_review' }),
|
||||
],
|
||||
});
|
||||
api.listWorkflows.mockResolvedValue({
|
||||
conversation_id: 'conv-1',
|
||||
workflows: [workflow],
|
||||
});
|
||||
api.cancelItem.mockResolvedValue({
|
||||
item: buildItem({ item_no: 'SWI-A', lifecycle_status: 'cancelled' }),
|
||||
});
|
||||
|
||||
const conversationId = ref('conv-1');
|
||||
const ctl = useShippingNoticeWorkflow({ conversationId });
|
||||
await vi.advanceTimersByTimeAsync(0);
|
||||
await nextTick();
|
||||
await Promise.resolve();
|
||||
|
||||
expect(api.listWorkflows).toHaveBeenCalled();
|
||||
expect(ctl.items.value.map((row) => row.item_no)).toEqual(['SWI-A', 'SWI-B']);
|
||||
expect(ctl.selectedWorkflowNo.value).toBe('SNWF-1');
|
||||
|
||||
await ctl.cancelItem('SWI-A', { reason: 'user cancel', expected_lock_version: 1 });
|
||||
expect(api.cancelItem).toHaveBeenCalledWith('SWI-A', {
|
||||
reason: 'user cancel',
|
||||
expected_lock_version: 1,
|
||||
});
|
||||
expect(api.listWorkflows.mock.calls.length).toBeGreaterThanOrEqual(2);
|
||||
|
||||
ctl.stop();
|
||||
});
|
||||
|
||||
it('selects among multiple workflows and reparses', async () => {
|
||||
const first = buildWorkflow({
|
||||
workflow_no: 'SNWF-1',
|
||||
items: [buildItem({ item_no: 'SWI-1', workflow_no: 'SNWF-1' })],
|
||||
});
|
||||
const second = buildWorkflow({
|
||||
workflow_no: 'SNWF-2',
|
||||
items: [
|
||||
buildItem({
|
||||
item_no: 'SWI-2',
|
||||
workflow_no: 'SNWF-2',
|
||||
lifecycle_status: 'failed',
|
||||
current_document_filename: 'fail.pdf',
|
||||
}),
|
||||
],
|
||||
});
|
||||
api.listWorkflows.mockResolvedValue({
|
||||
conversation_id: 'conv-1',
|
||||
workflows: [first, second],
|
||||
});
|
||||
api.reparseItem.mockResolvedValue({
|
||||
item: buildItem({ item_no: 'SWI-2', lifecycle_status: 'extracting' }),
|
||||
});
|
||||
|
||||
const conversationId = ref('conv-1');
|
||||
const ctl = useShippingNoticeWorkflow({ conversationId });
|
||||
await vi.advanceTimersByTimeAsync(0);
|
||||
await nextTick();
|
||||
await Promise.resolve();
|
||||
|
||||
expect(ctl.workflows.value).toHaveLength(2);
|
||||
expect(ctl.selectedWorkflowNo.value).toBe('SNWF-1');
|
||||
ctl.selectWorkflow('SNWF-2');
|
||||
expect(ctl.selectedWorkflowNo.value).toBe('SNWF-2');
|
||||
expect(ctl.items.value[0]?.item_no).toBe('SWI-2');
|
||||
|
||||
await ctl.reparseItem('SWI-2', { reason: 'retry', comment: 'note' });
|
||||
expect(api.reparseItem).toHaveBeenCalledWith('SWI-2', {
|
||||
reason: 'retry',
|
||||
comment: 'note',
|
||||
});
|
||||
|
||||
ctl.stop();
|
||||
});
|
||||
|
||||
it('records recoverable error without throwing', async () => {
|
||||
api.listWorkflows.mockRejectedValue(new Error('network down'));
|
||||
const conversationId = ref('conv-1');
|
||||
const ctl = useShippingNoticeWorkflow({ conversationId });
|
||||
await vi.advanceTimersByTimeAsync(0);
|
||||
await nextTick();
|
||||
await Promise.resolve();
|
||||
expect(ctl.error.value).toBe('network_recoverable');
|
||||
ctl.stop();
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user