feat(shipping-notice): 新增通用解析能力,优化性能并清理遗留废弃代码
This commit is contained in:
1 parent
935bf26fa6
commit
7cfd5d167e
230 files changed
+9337
-10989
No files matched your search
@@ -0,0 +1,112 @@
|
||||
/**
|
||||
* features/chat/api/shipping.api.request-dedupe.spec.ts
|
||||
* 用途:锁定重型订单抽取 Run 读取的同 key 在途请求合并契约。
|
||||
* 依赖:Vitest、shipping.api、统一 requestJson。
|
||||
* 逻辑:两个消费者同时读取同一 Run 时必须复用一个 HTTP 请求;请求结束后才允许下一次读取。
|
||||
*/
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
|
||||
const requestJson = vi.hoisted(() => vi.fn());
|
||||
|
||||
vi.mock('@/shared/api/client', () => ({
|
||||
BusinessError: class BusinessError extends Error {},
|
||||
requestJson,
|
||||
}));
|
||||
|
||||
import {
|
||||
getWorkspaceShippingOrderExtractionRun,
|
||||
getWorkspaceShippingProcessing,
|
||||
} from './shipping.api';
|
||||
|
||||
describe('getWorkspaceShippingOrderExtractionRun', () => {
|
||||
beforeEach(() => {
|
||||
requestJson.mockReset();
|
||||
// 模块级短缓存会跨用例保留;本文件的会话 ID 均唯一,避免上一用例污染下一用例。
|
||||
});
|
||||
|
||||
it('coalesces concurrent reads of the same Run into one HTTP request', async () => {
|
||||
let resolveRequest!: (value: { run_no: string }) => void;
|
||||
requestJson.mockImplementationOnce(() => new Promise((resolve) => {
|
||||
resolveRequest = resolve;
|
||||
}));
|
||||
|
||||
const first = getWorkspaceShippingOrderExtractionRun('SNER-SAME');
|
||||
const second = getWorkspaceShippingOrderExtractionRun('SNER-SAME');
|
||||
|
||||
// 关键断言:慢 Run 投影在途时,同一文件的第二个消费者不得再创建独立网络请求。
|
||||
expect(requestJson).toHaveBeenCalledTimes(1);
|
||||
resolveRequest({ run_no: 'SNER-SAME' });
|
||||
await expect(Promise.all([first, second])).resolves.toEqual([
|
||||
{ run_no: 'SNER-SAME' },
|
||||
{ run_no: 'SNER-SAME' },
|
||||
]);
|
||||
});
|
||||
|
||||
it('lets one caller stop waiting without aborting a shared Run request', async () => {
|
||||
let resolveRequest!: (value: { run_no: string }) => void;
|
||||
requestJson.mockImplementationOnce(() => new Promise((resolve) => {
|
||||
resolveRequest = resolve;
|
||||
}));
|
||||
const controller = new AbortController();
|
||||
|
||||
const cancelledCaller = getWorkspaceShippingOrderExtractionRun('SNER-SHARED', controller.signal);
|
||||
const activeCaller = getWorkspaceShippingOrderExtractionRun('SNER-SHARED');
|
||||
controller.abort();
|
||||
|
||||
// 关键断言:路由离开只结束当前消费者等待,不能中止其他组件复用的重型读取。
|
||||
await expect(cancelledCaller).rejects.toMatchObject({ name: 'AbortError' });
|
||||
expect(requestJson).toHaveBeenCalledTimes(1);
|
||||
resolveRequest({ run_no: 'SNER-SHARED' });
|
||||
await expect(activeCaller).resolves.toEqual({ run_no: 'SNER-SHARED' });
|
||||
});
|
||||
|
||||
it('reuses a successful conversation summary during the short refresh burst', async () => {
|
||||
requestJson.mockResolvedValue({
|
||||
conversation_id: 'conversation-summary-cache',
|
||||
work_items: [],
|
||||
conversation_processing: null,
|
||||
});
|
||||
|
||||
await getWorkspaceShippingProcessing('conversation-summary-cache');
|
||||
await getWorkspaceShippingProcessing('conversation-summary-cache');
|
||||
|
||||
// 关键断言:首屏 watcher 连续触发时必须复用刚完成的摘要,避免重复慢查询。
|
||||
expect(requestJson).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('binds every summary leaf to its status-group task for batch rendering', async () => {
|
||||
requestJson.mockResolvedValue({
|
||||
conversation_id: 'conversation-leaf-binding-20260822',
|
||||
conversation_processing: {
|
||||
summary: { total_tasks: 1, total_files: 1, processing: 0, needs_action: 1, completed: 0, history: 0 },
|
||||
status_groups: {
|
||||
failed: [],
|
||||
waiting_human: [{
|
||||
user_task_no: 'INTAKE:SNI-1', group: 'needs_action', status_label: 'waiting_human',
|
||||
file_count: 1, can_append: false,
|
||||
aggregate_children: [{
|
||||
work_item_type: 'order_task', work_item_no: 'DOCUMENT:1', source_type: 'eml',
|
||||
conversation_id: 'conversation-leaf-binding-20260822', intake_no: 'SNI-1', submission_no: 'SUB-1',
|
||||
// 同一邮件内另一 Candidate 的原始 OT 不能用作父卡关联键。
|
||||
root_order_task_no: 'OT-OTHER-CANDIDATE',
|
||||
status: 'waiting_human', stage: 'candidate_creating', progress_version: 1,
|
||||
source_summary: { document_id: 1, filename: 'order.pdf' },
|
||||
}],
|
||||
}],
|
||||
processing: [], completed: [], cancelled: [], archived: [],
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const response = await getWorkspaceShippingProcessing('conversation-leaf-binding-20260822');
|
||||
|
||||
// 关键断言:批次卡按父任务查实时叶子时,必须能找到本摘要组的文件。
|
||||
expect(response.conversation_processing?.status_groups?.waiting_human[0]?.aggregateChildren?.[0]).toMatchObject({
|
||||
workItemNo: 'DOCUMENT:1',
|
||||
});
|
||||
expect(response.conversation_processing?.status_groups?.waiting_human[0]?.aggregateChildren).toHaveLength(1);
|
||||
expect(response.work_items).toHaveLength(1);
|
||||
expect(response.work_items[0]?.rootOrderTaskNo).toBe('INTAKE:SNI-1');
|
||||
expect(response.work_items[0]?.sourceSummary.documentId).toBe(1);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user