refactor(shipping-notice): 重构货代发货通知状态管理,移除废弃的process_status字段
统一货代发货通知的业务阶段为四个标准阶段:接收解析、订单复核、发货准备、上传完成 设置 ui_state 为前端唯一状态数据源,不再依赖 process_status 驱动业务流程 删除 shipping_notices 表的废弃 process_status 列及对应复合索引,新增数据库迁移脚本 替换全栈代码中所有对 process_status 的引用为生命周期、上传状态等领域字段 更新相关文档、测试用例与前端展示逻辑适配新的状态管理规则
This commit is contained in:
1 parent
6684e7181a
commit
5ef8329bd8
178 files changed
+5091
-1734
No files matched your search
@@ -24,7 +24,7 @@ vi.mock('../api/chat.api', () => ({
|
||||
|
||||
const createConversationContext = () => {
|
||||
const conversationId = ref<string | null>('conv-a');
|
||||
const messages = ref([]);
|
||||
const messages = ref<any[]>([{ role: 'assistant', content: 'old-a' }]);
|
||||
const createNewChatView = vi.fn(() => {
|
||||
conversationId.value = null;
|
||||
messages.value = [];
|
||||
@@ -44,7 +44,10 @@ const createConversationContext = () => {
|
||||
activeRunId: ref(null),
|
||||
messages,
|
||||
isThinking: ref(false),
|
||||
loadConversationState: vi.fn(),
|
||||
loadConversationState: (id, loaded) => {
|
||||
conversationId.value = id;
|
||||
messages.value = loaded;
|
||||
},
|
||||
createNewChatView,
|
||||
clearPendingNoticeBatchRetry,
|
||||
onConversationIdChanging: vi.fn(),
|
||||
@@ -152,4 +155,62 @@ describe('useChatPageConversation', () => {
|
||||
await handleShippingAutoUploadNoticeBatch([file]);
|
||||
expect(enqueueNoticeFiles).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
|
||||
it('clears the previous conversation messages before an uncached history request resolves', async () => {
|
||||
let resolveMessages!: (value: any[]) => void;
|
||||
listChatMessages.mockImplementation(() => new Promise((resolve) => { resolveMessages = resolve; }));
|
||||
const { api, messages, conversationId } = createConversationContext();
|
||||
|
||||
const pending = api.loadConversation('conv-b', { force: true });
|
||||
|
||||
// 会话已切换但 B 尚无本地快照时,绝不能继续显示 A 的消息/订单卡。
|
||||
expect(conversationId.value).toBe('conv-b');
|
||||
expect(messages.value).toEqual([]);
|
||||
|
||||
resolveMessages([{ role: 'assistant', content: 'loaded-b' }]);
|
||||
await pending;
|
||||
expect(messages.value[0]?.content).toBe('loaded-b');
|
||||
});
|
||||
|
||||
it('restores cached messages immediately and discards a late response from an older selection', async () => {
|
||||
const pending = new Map<string, { resolve: (value: any[]) => void }>();
|
||||
listChatMessages.mockImplementation((id: string) => new Promise((resolve) => {
|
||||
pending.set(id, { resolve });
|
||||
}));
|
||||
const { api, messages, conversationId } = createConversationContext();
|
||||
|
||||
const firstB = api.loadConversation('conv-b', { force: true });
|
||||
pending.get('conv-b')!.resolve([{ role: 'assistant', content: 'cached-b' }]);
|
||||
await firstB;
|
||||
|
||||
const selectA = api.loadConversation('conv-a', { force: true });
|
||||
const returnB = api.loadConversation('conv-b', { force: true });
|
||||
expect(messages.value[0]?.content).toBe('cached-b');
|
||||
|
||||
pending.get('conv-a')!.resolve([{ role: 'assistant', content: 'late-a' }]);
|
||||
pending.get('conv-b')!.resolve([{ role: 'assistant', content: 'cached-b' }]);
|
||||
await Promise.all([selectA, returnB]);
|
||||
|
||||
expect(conversationId.value).toBe('conv-b');
|
||||
expect(messages.value[0]?.content).toBe('cached-b');
|
||||
});
|
||||
|
||||
it('keeps the rendered cached message array when revalidation is semantically unchanged', async () => {
|
||||
const pending = new Map<string, { resolve: (value: any[]) => void }>();
|
||||
listChatMessages.mockImplementation((id: string) => new Promise((resolve) => {
|
||||
pending.set(id, { resolve });
|
||||
}));
|
||||
const { api, messages } = createConversationContext();
|
||||
|
||||
const initial = api.loadConversation('conv-b', { force: true });
|
||||
pending.get('conv-b')!.resolve([{ chat_log_id: 91, role: 'assistant', content: 'stable-b' }]);
|
||||
await initial;
|
||||
|
||||
const revalidate = api.loadConversation('conv-b', { force: true });
|
||||
const renderedCache = messages.value;
|
||||
pending.get('conv-b')!.resolve([{ chat_log_id: 91, role: 'assistant', content: 'stable-b' }]);
|
||||
await revalidate;
|
||||
|
||||
expect(messages.value).toBe(renderedCache);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user