feat(shipping-notice): 新增货代客户管理功能,支持客户导入、识别证据管理与客户确认
This commit is contained in:
1 parent
b595e157e9
commit
4fbaed2b4c
176 files changed
+14011
-994
No files matched your search
@@ -22,7 +22,14 @@ const createContext = (
|
||||
conversationId: ref('conv-send'),
|
||||
history: ref([]),
|
||||
input: ref(''),
|
||||
attachments: ref([{ kind: 'local', file: new File(['notice'], 'notice.txt', { type: 'text/plain' }) }]),
|
||||
attachments: ref([{
|
||||
id: 'local-notice',
|
||||
kind: 'local',
|
||||
file: new File(['notice'], 'notice.txt', { type: 'text/plain' }),
|
||||
type: 'document',
|
||||
uploadStatus: 'waiting',
|
||||
uploadProgress: 0,
|
||||
}]),
|
||||
shippingAutoFlowRequested: ref(true),
|
||||
resolvedShippingTaskId: ref(''),
|
||||
getActiveShippingBatchNo: () => '',
|
||||
@@ -32,7 +39,7 @@ const createContext = (
|
||||
getActiveShippingTaskId: () => '',
|
||||
lastAssistantMessageContent: () => '',
|
||||
lastAssistantShippingActions: () => [],
|
||||
sendMessage: vi.fn(async () => undefined),
|
||||
sendMessage: vi.fn(async () => true),
|
||||
buildFileSpecsForSend: vi.fn(async () => []),
|
||||
loadHistory: vi.fn(async () => undefined),
|
||||
sendShippingMenuMessage: vi.fn(async () => undefined),
|
||||
@@ -44,6 +51,9 @@ const createContext = (
|
||||
handleShippingAutoUploadFile: vi.fn(async () => undefined),
|
||||
handleShippingAutoUploadNoticeBatch: vi.fn(async () => undefined),
|
||||
isShippingNoticeBatchSubmitting: () => isShippingNoticeBatchSubmitting(),
|
||||
markOrderExtractionStarted: vi.fn(),
|
||||
rollbackOrderExtractionStarted: vi.fn(),
|
||||
syncShippingConversationWorkspace: vi.fn(async () => true),
|
||||
refreshShippingActions: vi.fn(async () => undefined),
|
||||
shippingSuggestedPrompt: computed(() => ''),
|
||||
isShippingShortageQueryIntent: () => false,
|
||||
@@ -73,6 +83,7 @@ describe('useChatShippingSendHandler', () => {
|
||||
});
|
||||
|
||||
it('sends parsed intakes to the existing Chatflow without requiring upload-time candidates', async () => {
|
||||
const completionOrder: string[] = [];
|
||||
const attachment = {
|
||||
id: 'notice-1',
|
||||
kind: 'shipping_notice' as const,
|
||||
@@ -89,8 +100,11 @@ describe('useChatShippingSendHandler', () => {
|
||||
hasCandidateReviewIssues: () => true,
|
||||
hasSelectedNoticeCandidates: () => true,
|
||||
getParsedIntakeNos: () => ['SNI-1'],
|
||||
refreshNoticeIntakeStatuses: vi.fn(async () => undefined),
|
||||
clearConsumedNoticeAttachments: vi.fn(),
|
||||
applyShippingMessageRecovery: vi.fn(async () => { completionOrder.push('recovery'); return true; }),
|
||||
refreshNoticeIntakeStatuses: vi.fn(async () => { completionOrder.push('intakes'); }),
|
||||
syncShippingConversationWorkspace: vi.fn(async () => { completionOrder.push('workspace'); return true; }),
|
||||
clearConsumedNoticeAttachments: vi.fn(() => { completionOrder.push('clear'); }),
|
||||
refreshShippingActions: vi.fn(async () => { completionOrder.push('actions'); }),
|
||||
});
|
||||
const { tryHandleShippingAttachmentAutoFlow } = createShippingSendHandlers(ctx);
|
||||
|
||||
@@ -107,8 +121,26 @@ describe('useChatShippingSendHandler', () => {
|
||||
shipping_intake_nos: ['SNI-1'],
|
||||
display_query: 'chat.shippingOrderExtractionDefaultPrompt',
|
||||
},
|
||||
expect.objectContaining({ onAssistantMessageFinished: expect.any(Function) }),
|
||||
expect.objectContaining({
|
||||
userAttachments: [{
|
||||
id: 'notice-1',
|
||||
name: 'orders.eml',
|
||||
size: 100,
|
||||
extension: 'eml',
|
||||
type: 'document',
|
||||
source: 'shipping_notice',
|
||||
}],
|
||||
onAssistantMessageFinished: expect.any(Function),
|
||||
}),
|
||||
);
|
||||
expect(ctx.markOrderExtractionStarted).toHaveBeenCalledWith(['SNI-1']);
|
||||
|
||||
const hooks = vi.mocked(ctx.sendMessage).mock.calls[0]?.[5];
|
||||
const assistantMessage = { role: 'assistant', content: '已打开已有任务' } as const;
|
||||
await hooks?.onAssistantMessageFinished?.(assistantMessage, []);
|
||||
expect(ctx.applyShippingMessageRecovery).toHaveBeenCalledWith(assistantMessage);
|
||||
expect(completionOrder).toEqual(['recovery', 'intakes', 'workspace', 'clear', 'actions']);
|
||||
expect(ctx.syncShippingConversationWorkspace).toHaveBeenCalledWith({ preferLatest: true });
|
||||
});
|
||||
|
||||
it('uses the user query for full extraction even when no candidate exists before send', async () => {
|
||||
@@ -144,7 +176,102 @@ describe('useChatShippingSendHandler', () => {
|
||||
shipping_intake_nos: ['SNI-1'],
|
||||
display_query: '请解析这些附件',
|
||||
},
|
||||
expect.objectContaining({ onAssistantMessageFinished: expect.any(Function) }),
|
||||
expect.objectContaining({
|
||||
userAttachments: [{
|
||||
id: 'notice-1',
|
||||
name: 'orders.eml',
|
||||
size: 100,
|
||||
extension: 'eml',
|
||||
type: 'document',
|
||||
source: 'shipping_notice',
|
||||
}],
|
||||
onAssistantMessageFinished: expect.any(Function),
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it('retries the conversation workspace once when the first refresh fails', async () => {
|
||||
const syncWorkspace = vi.fn()
|
||||
.mockResolvedValueOnce(false)
|
||||
.mockResolvedValueOnce(true);
|
||||
const ctx = createContext({
|
||||
attachments: ref([{
|
||||
id: 'notice-retry',
|
||||
kind: 'shipping_notice' as const,
|
||||
type: 'document' as const,
|
||||
uploadStatus: 'uploaded' as const,
|
||||
parseStatus: 'parsed' as const,
|
||||
uploadProgress: 100,
|
||||
originalFilename: 'orders.eml',
|
||||
fileSize: 100,
|
||||
intakeNo: 'SNI-RETRY',
|
||||
}]),
|
||||
getParsedIntakeNos: () => ['SNI-RETRY'],
|
||||
syncShippingConversationWorkspace: syncWorkspace,
|
||||
});
|
||||
const { tryHandleShippingAttachmentAutoFlow } = createShippingSendHandlers(ctx);
|
||||
|
||||
await tryHandleShippingAttachmentAutoFlow(undefined, '', '');
|
||||
const hooks = vi.mocked(ctx.sendMessage).mock.calls[0]?.[5];
|
||||
await hooks?.onAssistantMessageFinished?.({} as never, []);
|
||||
|
||||
expect(syncWorkspace).toHaveBeenCalledTimes(2);
|
||||
expect(syncWorkspace).toHaveBeenNthCalledWith(1, { preferLatest: true });
|
||||
expect(syncWorkspace).toHaveBeenNthCalledWith(2, { preferLatest: true });
|
||||
expect(ctx.refreshShippingActions).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('rolls back the local extracting state when the chat request fails', async () => {
|
||||
const rollback = vi.fn();
|
||||
const ctx = createContext({
|
||||
attachments: ref([{
|
||||
id: 'notice-failed-send',
|
||||
kind: 'shipping_notice' as const,
|
||||
type: 'document' as const,
|
||||
uploadStatus: 'uploaded' as const,
|
||||
parseStatus: 'parsed' as const,
|
||||
uploadProgress: 100,
|
||||
originalFilename: 'orders.eml',
|
||||
fileSize: 100,
|
||||
intakeNo: 'SNI-FAILED-SEND',
|
||||
}]),
|
||||
getParsedIntakeNos: () => ['SNI-FAILED-SEND'],
|
||||
sendMessage: vi.fn(async () => { throw new Error('network failed'); }),
|
||||
rollbackOrderExtractionStarted: rollback,
|
||||
});
|
||||
const { tryHandleShippingAttachmentAutoFlow } = createShippingSendHandlers(ctx);
|
||||
|
||||
const consumed = await tryHandleShippingAttachmentAutoFlow(undefined, '', '');
|
||||
|
||||
expect(consumed).toBe(true);
|
||||
expect(rollback).toHaveBeenCalledWith(['SNI-FAILED-SEND']);
|
||||
expect(ctx.msg.warning).toHaveBeenCalledWith('network failed');
|
||||
});
|
||||
|
||||
it('rolls back extraction state when sendMessage reports a handled stream failure', async () => {
|
||||
const rollback = vi.fn();
|
||||
const ctx = createContext({
|
||||
attachments: ref([{
|
||||
id: 'notice-handled-failure',
|
||||
kind: 'shipping_notice' as const,
|
||||
type: 'document' as const,
|
||||
uploadStatus: 'uploaded' as const,
|
||||
parseStatus: 'parsed' as const,
|
||||
uploadProgress: 100,
|
||||
originalFilename: 'orders.eml',
|
||||
fileSize: 100,
|
||||
intakeNo: 'SNI-HANDLED-FAILURE',
|
||||
}]),
|
||||
getParsedIntakeNos: () => ['SNI-HANDLED-FAILURE'],
|
||||
sendMessage: vi.fn(async () => false),
|
||||
rollbackOrderExtractionStarted: rollback,
|
||||
});
|
||||
const { tryHandleShippingAttachmentAutoFlow } = createShippingSendHandlers(ctx);
|
||||
|
||||
const consumed = await tryHandleShippingAttachmentAutoFlow(undefined, '', '');
|
||||
|
||||
expect(consumed).toBe(true);
|
||||
expect(rollback).toHaveBeenCalledWith(['SNI-HANDLED-FAILURE']);
|
||||
expect(ctx.loadHistory).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user