feat(shipping-notice): 落地 XFA 拆分、版面签名、统一进度与处理域履约

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
hugoandCursor committed 2026-08-06 10:18:37 +08:00
1 parent 3a9fbac2fc
commit d2b3d74def
571 files changed
+78064 -24681

No files matched your search

@@ -1,8 +1,8 @@
/**
* features/chat/page/useChatPageConversation.spec.ts
* 用途:验证新建聊天与 Agent 切换时清理发货通知待重试建批幂等状态。
* 用途:验证新建聊天与 Agent 切换时清理发货通知外围状态。
* 依赖:vitest、vue refs/computed、useChatPageConversation、useChatShippingUploadHandler。
* 逻辑:覆盖 createNewChatView 不经 onConversationIdChanging 时仍生成新幂等键的回归场景。
* 逻辑:覆盖 createNewChatView / Agent 切换调用 peripheral reset;建批幂等已随 co8 下线。
*/
import { computed, ref } from 'vue';
import { beforeEach, describe, expect, it, vi } from 'vitest';
@@ -18,21 +18,10 @@ const { listChatMessages } = vi.hoisted(() => ({
listChatMessages: vi.fn(),
}));
const { computeNoticeFilesContentFingerprint } = vi.hoisted(() => ({
computeNoticeFilesContentFingerprint: vi.fn(async (files: File[]) => {
const content = await files[0]?.text();
return `fp-${content || 'empty'}`;
}),
}));
vi.mock('../api/chat.api', () => ({
listChatMessages,
}));
vi.mock('../shipping/shippingNoticeBatchIdempotency', () => ({
computeNoticeFilesContentFingerprint,
}));
const createConversationContext = () => {
const conversationId = ref<string | null>('conv-a');
const messages = ref([]);
@@ -41,6 +30,7 @@ const createConversationContext = () => {
messages.value = [];
});
const resetPeripheralState = vi.fn();
return {
conversationId,
messages,
@@ -68,18 +58,19 @@ const createConversationContext = () => {
input: ref(''),
resetCurrentAgent: vi.fn(),
copiedIndex: ref(null),
resetPeripheralState: vi.fn(),
resetPeripheralState,
filePreviewVisible: ref(false),
previewFile: ref(null),
previewFiles: ref([]),
currentPreviewIndex: ref(0),
}),
resetPeripheralState,
};
};
const createUploadContext = (
conversationId: ReturnType<typeof ref<string | null>>,
startChatTurn: ReturnType<typeof vi.fn>,
enqueueNoticeFiles: ReturnType<typeof vi.fn>,
): ShippingUploadHandlerContext => ({
conversationId,
currentAgentId: computed(() => 42),
@@ -97,35 +88,32 @@ const createUploadContext = (
shippingBatchTasks: ref([]),
shippingInventorySelectionActive: ref(false),
shippingInventorySelectionTaskId: ref(''),
shippingInventorySchemaPreviewCache: ref({}),
getActiveShippingTaskId: () => '',
startChatTurn,
startChatTurn: vi.fn(async () => true),
refreshShippingActions: vi.fn(async () => undefined),
msg: { warning: vi.fn() },
msg: { warning: vi.fn(), info: vi.fn() },
t: (key: string) => key,
enqueueNoticeFiles,
startOrderExtractionRun: vi.fn(async () => true),
sendTemporaryInventoryMessage: vi.fn(async () => undefined),
});
describe('useChatPageConversation', () => {
beforeEach(() => {
listChatMessages.mockReset();
computeNoticeFilesContentFingerprint.mockReset();
computeNoticeFilesContentFingerprint.mockImplementation(async (files: File[]) => {
const content = await files[0]?.text();
return `fp-${content || 'empty'}`;
});
resetShippingNoticeBatchSubmitStateForTests();
});
it('startNewChat clears pending notice batch retry and next upload uses a new idempotency key', async () => {
const startChatTurn = vi.fn(async () => false);
it('startNewChat clears peripheral state and subsequent notice upload still enqueues intakes', async () => {
const enqueueNoticeFiles = vi.fn(async () => undefined);
const { conversationId, createNewChatView, api } = createConversationContext();
const { handleShippingAutoUploadNoticeBatch } = createShippingUploadHandlers(
createUploadContext(conversationId, startChatTurn),
createUploadContext(conversationId, enqueueNoticeFiles),
);
const file = new File(['notice'], 'notice.pdf', { type: 'application/pdf' });
await handleShippingAutoUploadNoticeBatch([file]);
const firstKey = (startChatTurn.mock.calls[0]?.[0] as { payload?: Record<string, unknown> })?.payload?.idempotency_key;
expect(enqueueNoticeFiles).toHaveBeenCalledTimes(1);
api.startNewChat();
@@ -133,23 +121,28 @@ describe('useChatPageConversation', () => {
expect(conversationId.value).toBeNull();
await handleShippingAutoUploadNoticeBatch([file]);
const secondKey = (startChatTurn.mock.calls[1]?.[0] as { payload?: Record<string, unknown> })?.payload?.idempotency_key;
expect(firstKey).toBeTruthy();
expect(secondKey).toBeTruthy();
expect(secondKey).not.toBe(firstKey);
expect(enqueueNoticeFiles).toHaveBeenCalledTimes(2);
});
it('resetChatStateForAgentChange clears pending notice batch retry and next upload uses a new idempotency key', async () => {
const startChatTurn = vi.fn(async () => false);
it('startNewChat calls peripheral reset so a shipping Run cannot remain visible in the blank view', () => {
const { api, resetPeripheralState } = createConversationContext();
api.startNewChat();
// 关键断言:Shipping 状态在 useChatShipping.resetShippingConversationState 中随该回调清理。
expect(resetPeripheralState).toHaveBeenCalledTimes(1);
});
it('resetChatStateForAgentChange clears peripheral state and subsequent notice upload still enqueues intakes', async () => {
const enqueueNoticeFiles = vi.fn(async () => undefined);
const { conversationId, createNewChatView, api } = createConversationContext();
const { handleShippingAutoUploadNoticeBatch } = createShippingUploadHandlers(
createUploadContext(conversationId, startChatTurn),
createUploadContext(conversationId, enqueueNoticeFiles),
);
const file = new File(['notice'], 'notice.pdf', { type: 'application/pdf' });
await handleShippingAutoUploadNoticeBatch([file]);
const firstKey = (startChatTurn.mock.calls[0]?.[0] as { payload?: Record<string, unknown> })?.payload?.idempotency_key;
expect(enqueueNoticeFiles).toHaveBeenCalledTimes(1);
api.resetChatStateForAgentChange();
@@ -157,10 +150,6 @@ describe('useChatPageConversation', () => {
expect(conversationId.value).toBeNull();
await handleShippingAutoUploadNoticeBatch([file]);
const secondKey = (startChatTurn.mock.calls[1]?.[0] as { payload?: Record<string, unknown> })?.payload?.idempotency_key;
expect(firstKey).toBeTruthy();
expect(secondKey).toBeTruthy();
expect(secondKey).not.toBe(firstKey);
expect(enqueueNoticeFiles).toHaveBeenCalledTimes(2);
});
});