feat(shipping-notice): 新增货代客户管理功能,支持客户导入、识别证据管理与客户确认
This commit is contained in:
1 parent
b595e157e9
commit
4fbaed2b4c
176 files changed
+14011
-994
No files matched your search
@@ -1,13 +1,43 @@
|
||||
/**
|
||||
* features/chat/composables/useChat.spec.ts
|
||||
* 用途:验证聊天流对发货通知 UI State SSE 事件的消息级回写行为。
|
||||
* 依赖:vitest、useChat 导出的纯函数、chat.types。
|
||||
* 逻辑:覆盖 batch_ui_state 到 focus_task_ui_state 的投影、focus 切换时按钮跟随更新,以及已消费按钮消息的防回挂保护。
|
||||
* 用途:验证聊天流对发货通知 UI State 与订单识别生命周期 SSE 的消息级回写行为。
|
||||
* 依赖:vitest、useChat/chat.api 导出的纯函数、chat.types。
|
||||
* 逻辑:覆盖任务状态投影、订单识别终态保护、terminal 后事件放行及历史 payload 恢复。
|
||||
*/
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { applyShippingUiStateToMessage } from './useChat';
|
||||
import {
|
||||
applyShippingOrderExtractionStateToMessage,
|
||||
applyShippingUiStateToMessage,
|
||||
createUserChatMessage,
|
||||
isAllowedAfterStreamTerminal,
|
||||
} from './useChat';
|
||||
import { hydrateShippingOrderExtractionState } from '../api/chat.api';
|
||||
import type { ChatMessage } from '../types/chat.types';
|
||||
|
||||
describe('useChat user attachment snapshots', () => {
|
||||
it('copies sent attachments onto the user message without inheriting them for text-only messages', () => {
|
||||
const attachments = [{
|
||||
id: 'attachment-1',
|
||||
name: 'purchase-order.pdf',
|
||||
size: 144_456,
|
||||
extension: 'pdf',
|
||||
type: 'document' as const,
|
||||
source: 'local' as const,
|
||||
}];
|
||||
|
||||
const message = createUserChatMessage('总结附件', attachments);
|
||||
attachments[0]!.name = 'changed.pdf';
|
||||
|
||||
expect(message).toMatchObject({
|
||||
role: 'user',
|
||||
content: '总结附件',
|
||||
attachments: [{ name: 'purchase-order.pdf', size: 144_456 }],
|
||||
});
|
||||
expect(message.attachments).not.toBe(attachments);
|
||||
expect(createUserChatMessage('仅重发文字')).toEqual({ role: 'user', content: '仅重发文字' });
|
||||
});
|
||||
});
|
||||
|
||||
const buildBatchUiStateEvent = (
|
||||
taskNo: string,
|
||||
batchNo: string,
|
||||
@@ -97,3 +127,93 @@ describe('useChat shipping_ui_state SSE', () => {
|
||||
.toBe('SN-FOCUS-B');
|
||||
});
|
||||
});
|
||||
|
||||
describe('useChat shipping_order_extraction_state SSE', () => {
|
||||
it('replaces extracting with persisted facts without overwriting Dify content', () => {
|
||||
const message: ChatMessage = {
|
||||
role: 'assistant',
|
||||
content: 'Dify 最终正文保持不变',
|
||||
payload: { existing_key: 'kept' },
|
||||
};
|
||||
|
||||
applyShippingOrderExtractionStateToMessage(message, {
|
||||
event: 'shipping_order_extraction_state',
|
||||
status: 'extracting',
|
||||
phase: 'llm_extraction',
|
||||
message: '正在识别邮件及附件中的订单',
|
||||
created_count: -1,
|
||||
terminal: false,
|
||||
});
|
||||
expect(message.shipping_order_extraction_state?.status).toBe('extracting');
|
||||
expect(message.shipping_order_extraction_state?.created_count).toBe(0);
|
||||
|
||||
applyShippingOrderExtractionStateToMessage(message, {
|
||||
event: 'shipping_order_extraction_state',
|
||||
status: 'completed',
|
||||
phase: 'result_persisted',
|
||||
message: '已创建 1 个发货任务',
|
||||
created_count: 1,
|
||||
opened_existing_count: 2,
|
||||
pending_count: 0,
|
||||
non_shipping_count: 3,
|
||||
created_with_missing_fields_count: 1,
|
||||
batch_no: 'SB-STATE-001',
|
||||
terminal: true,
|
||||
});
|
||||
|
||||
expect(message.content).toBe('Dify 最终正文保持不变');
|
||||
expect(message.shipping_order_extraction_state).toMatchObject({
|
||||
status: 'completed',
|
||||
created_count: 1,
|
||||
opened_existing_count: 2,
|
||||
non_shipping_count: 3,
|
||||
batch_no: 'SB-STATE-001',
|
||||
terminal: true,
|
||||
});
|
||||
expect((message.payload as Record<string, unknown>).existing_key).toBe('kept');
|
||||
expect((message.payload as { shipping_order_extraction_state?: { created_count?: number } })
|
||||
.shipping_order_extraction_state?.created_count).toBe(1);
|
||||
|
||||
// 关键断言:网络重排导致的迟到进行态不能覆盖已经展示的终态。
|
||||
applyShippingOrderExtractionStateToMessage(message, {
|
||||
status: 'extracting',
|
||||
phase: 'llm_extraction',
|
||||
message: '迟到事件',
|
||||
terminal: false,
|
||||
});
|
||||
expect(message.shipping_order_extraction_state?.status).toBe('completed');
|
||||
});
|
||||
|
||||
it('allows HXOPS domain states after the upstream terminal event', () => {
|
||||
expect(isAllowedAfterStreamTerminal('shipping_order_extraction_state')).toBe(true);
|
||||
expect(isAllowedAfterStreamTerminal('shipping_ui_state')).toBe(true);
|
||||
expect(isAllowedAfterStreamTerminal('agent_message')).toBe(false);
|
||||
});
|
||||
|
||||
it('hydrates persisted terminal state from ChatLog payload', () => {
|
||||
const message: ChatMessage = {
|
||||
role: 'assistant',
|
||||
content: '订单识别完成',
|
||||
payload: {
|
||||
shipping_order_extraction_state: {
|
||||
status: 'partially_completed',
|
||||
phase: 'result_persisted',
|
||||
message: '仍有 1 个订单需要补充信息',
|
||||
created_count: 1,
|
||||
opened_existing_count: 0,
|
||||
pending_count: 1,
|
||||
non_shipping_count: 0,
|
||||
created_with_missing_fields_count: 0,
|
||||
batch_no: 'SB-HISTORY-001',
|
||||
terminal: true,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
hydrateShippingOrderExtractionState(message);
|
||||
|
||||
expect(message.shipping_order_extraction_state?.status).toBe('partially_completed');
|
||||
expect(message.shipping_order_extraction_state?.pending_count).toBe(1);
|
||||
expect(message.shipping_order_extraction_state?.batch_no).toBe('SB-HISTORY-001');
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user