perf(shipping-notice): 优化发货任务性能,修复上传流程与终态问题

This commit is contained in:
hugo committed 2026-08-27 19:25:16 +08:00
1 parent 434c04ed2d
commit bcdd8285ae
29 files changed
+1074 -128

No files matched your search

@@ -16,8 +16,63 @@ vi.mock('@/shared/api/client', () => ({
import {
getWorkspaceShippingOrderExtractionRun,
getWorkspaceShippingProcessing,
getWorkspaceShippingTask,
} from './shipping.api';
describe('getWorkspaceShippingTask', () => {
beforeEach(() => {
requestJson.mockReset();
});
it('coalesces concurrent reads of the same task detail into one HTTP request', async () => {
let resolveRequest!: (value: { task_no: string }) => void;
requestJson.mockImplementationOnce(() => new Promise((resolve) => {
resolveRequest = resolve;
}));
const first = getWorkspaceShippingTask('SN-DEDUPE-1');
const second = getWorkspaceShippingTask('SN-DEDUPE-1');
// 关键断言:重型任务详情在途时,同 task_no 的并行消费者(工作台 loadFormalTaskDetail
// 与对话侧 syncActiveShippingTaskDetail)必须复用一个网络请求,禁止重复拉取。
expect(requestJson).toHaveBeenCalledTimes(1);
resolveRequest({ task_no: 'SN-DEDUPE-1' });
await expect(Promise.all([first, second])).resolves.toEqual([
{ task_no: 'SN-DEDUPE-1' },
{ task_no: 'SN-DEDUPE-1' },
]);
});
it('does not cache a completed task detail across a later read', async () => {
requestJson.mockResolvedValueOnce({ task_no: 'SN-FRESH-1' });
requestJson.mockResolvedValueOnce({ task_no: 'SN-FRESH-1' });
// 单飞去重只合并「在途」请求;完成后不得返回过期快照,保证 Gate 动作后的新鲜重读。
await getWorkspaceShippingTask('SN-FRESH-1');
await getWorkspaceShippingTask('SN-FRESH-1');
expect(requestJson).toHaveBeenCalledTimes(2);
});
it('keys dedup by view so workbench and full projections do not merge', async () => {
requestJson.mockResolvedValue({ task_no: 'SN-VIEW-1' });
// 关键断言:workbench(裁剪)与 full 是两个不同响应体,缺省 view 与 view=workbench
// 共享同一个 task_no 时不能合并成一个请求,否则会把裁剪版响应交给 full 消费者。
const full = getWorkspaceShippingTask('SN-VIEW-1');
const wb = getWorkspaceShippingTask('SN-VIEW-1', { view: 'workbench' });
const wbAgain = getWorkspaceShippingTask('SN-VIEW-1', { view: 'workbench' });
// 两个视图各一次、workbench 同视图合并:共 2 次底层请求。
expect(requestJson).toHaveBeenCalledTimes(2);
expect(requestJson).toHaveBeenNthCalledWith(1, '/api/workspace/shipping-tasks/SN-VIEW-1');
expect(requestJson).toHaveBeenNthCalledWith(
2,
'/api/workspace/shipping-tasks/SN-VIEW-1?view=workbench',
);
await Promise.allSettled([full, wb, wbAgain]);
});
});
describe('getWorkspaceShippingOrderExtractionRun', () => {
beforeEach(() => {
requestJson.mockReset();