feat(shipping-notice): 增加发货通知建单幂等性支持及内容哈希校验

This commit is contained in:
hugo committed 2026-07-14 00:28:52 +08:00
1 parent 0a9bd6415d
commit 143e054d86
39 files changed
+1750 -80

No files matched your search

@@ -0,0 +1,74 @@
/**
* features/chat/shipping/useChatShippingSendHandler.spec.ts
* 用途:验证建批提交中发送拦截不会回退到普通聊天发送。
*/
import { computed, ref } from 'vue';
import { beforeEach, describe, expect, it, vi } from 'vitest';
import { createShippingSendHandlers, type ShippingSendHandlerContext } from './useChatShippingSendHandler';
const isShippingNoticeBatchSubmitting = vi.hoisted(() => vi.fn(() => false));
vi.mock('./useChatShippingUploadHandler', () => ({
isShippingNoticeBatchSubmitting,
}));
const createContext = (
overrides: Partial<ShippingSendHandlerContext> = {},
): ShippingSendHandlerContext => ({
isShippingNoticeAgent: computed(() => true),
isThinking: ref(false),
isUploadingAttachments: ref(false),
messages: ref([]),
conversationId: ref('conv-send'),
history: ref([]),
input: ref(''),
attachments: ref([{ kind: 'local', file: new File(['notice'], 'notice.txt', { type: 'text/plain' }) }]),
shippingAutoFlowRequested: ref(true),
resolvedShippingTaskId: ref(''),
getActiveShippingBatchNo: () => '',
currentAgentId: computed(() => 1),
selectedKb: ref(''),
attachmentPolicy: computed(() => ({ anyEnabled: true })),
getActiveShippingTaskId: () => '',
lastAssistantMessageContent: () => '',
lastAssistantShippingActions: () => [],
sendMessage: vi.fn(async () => undefined),
buildFileSpecsForSend: vi.fn(async () => []),
loadHistory: vi.fn(async () => undefined),
sendShippingMenuMessage: vi.fn(async () => undefined),
startChatTurn: vi.fn(async () => true),
openShippingInventoryPicker: vi.fn(() => true),
executeShippingDecision: vi.fn(async () => true),
executeShippingManualUpload: vi.fn(async () => true),
handleShippingMenuAction: vi.fn(async () => undefined),
handleShippingAutoUploadFile: vi.fn(async () => undefined),
handleShippingAutoUploadNoticeBatch: vi.fn(async () => undefined),
isShippingNoticeBatchSubmitting: () => isShippingNoticeBatchSubmitting(),
refreshShippingActions: vi.fn(async () => undefined),
shippingSuggestedPrompt: computed(() => ''),
isShippingShortageQueryIntent: () => false,
queryShippingShortageDetails: vi.fn(async () => true),
msg: { warning: vi.fn(), info: vi.fn() },
t: (key: string) => key,
...overrides,
});
describe('useChatShippingSendHandler', () => {
beforeEach(() => {
isShippingNoticeBatchSubmitting.mockReset();
isShippingNoticeBatchSubmitting.mockReturnValue(false);
});
it('consumes send while notice batch is submitting and does not call sendMessage', async () => {
isShippingNoticeBatchSubmitting.mockReturnValue(true);
const ctx = createContext();
const { tryHandleShippingAttachmentAutoFlow } = createShippingSendHandlers(ctx);
const consumed = await tryHandleShippingAttachmentAutoFlow(undefined, '', '');
expect(consumed).toBe(true);
expect(ctx.sendMessage).not.toHaveBeenCalled();
expect(ctx.handleShippingAutoUploadNoticeBatch).not.toHaveBeenCalled();
expect(ctx.msg.info).toHaveBeenCalledWith('chat.shippingNoticeBatchSubmitting');
});
});