3d12689349
后端已把心跳里的 current/total 透到 progress/light,但 TaskItemView.progress 是可空字段:
页面少写一行不会报错也不会红,界面上就是安静地没有进度条——11 类客户端任务里 7 类正是这样。
- 新增 src/shared/api/task-progress-live.ts:进度走独立通道,模块级缓存 + 60s 新鲜窗口
为什么不并进任务对象:各页 {...prev.task, ...detail.task} 合并里有 5 处带「变更签名」守卫
(rowsVersion|status|fileStatus|fileReady)。进度每轮都在动,而签名在「正在翻页、还没攒够一批
回传」的时段不变——照那条路走,进度条会一路停在上一次回传的数字上,看着像卡死
- 写入点挂在 light 出口(progress-light.ts)而不是聚合层:4 个页面直接调 getModuleProgressLight
不经过 getPollingProgressBatch,挂聚合层它们永远拿不到;命中缓存也要刷一遍读数,
否则进度会在缓存窗口里被自己的新鲜判定踢掉、凭空消失
- toBatchItems 与 LightPollingItem 补三字段:这里的键集是逐字段挑的,少挑一个就把后端给的数丢掉
- 10 页接 liveProgress:解决风控、跟价、定时匹配、状态查询、提款、巡店删除、商品管理采集等
- Convert/Dedupe/Split 三页写死 progress: null 并说明原因:它们卡列的是完成记录、没有可数的分母。
显式 null 与省略字段在代码里必须长得不一样,否则下一个人无法区分「没得画」和「忘了接」
- 新增 tests/task-progress-view-wiring.test.ts:适配器清单由文件系统给出、总数硬钉 16,
判据同时认 `progress:` 与 ES6 简写 `progress,`(只认冒号把 BrandBrandTab 误报成缺口,
而误报的尺子会被人当噪音绕过去);变异自证三处全 KILLED——抽掉跟价页的接线、
摘掉批次白名单的 progressTotal、去掉分母塌 0 时的旧读数清理,还原后字节哈希一致
- tests/task-progress-polling.test.ts 的整份形状断言同步加三字段(它本来就该在我改白名单时红)
64 lines
2.1 KiB
TypeScript
64 lines
2.1 KiB
TypeScript
import { test } from 'node:test'
|
|
import assert from 'node:assert/strict'
|
|
import { pickPollingBatch, toBatchItems } from '../src/shared/api/task-progress-polling.ts'
|
|
|
|
test('轻量项归一为重型 batch 的嵌套形状', () => {
|
|
const items = toBatchItems([
|
|
{ taskId: 7, status: 'RUNNING', fileStatus: 'PENDING', fileReady: false, updatedAt: '2026-09-14T06:00:00' },
|
|
])
|
|
|
|
assert.equal(items.length, 1)
|
|
assert.deepEqual(items[0].task, {
|
|
id: 7,
|
|
status: 'RUNNING',
|
|
statusCode: null,
|
|
fileStatus: 'PENDING',
|
|
fileError: null,
|
|
fileReady: false,
|
|
updatedAt: '2026-09-14T06:00:00',
|
|
progressCurrent: null,
|
|
progressTotal: null,
|
|
progressLabel: null,
|
|
})
|
|
})
|
|
|
|
test('心跳进度三字段照抄进嵌套 task,不被白名单丢掉', () => {
|
|
const items = toBatchItems([
|
|
{ taskId: 8, status: 'RUNNING', progressCurrent: 12, progressTotal: 50, progressLabel: 'US(3/5)' },
|
|
])
|
|
|
|
assert.equal(items[0].task?.progressCurrent, 12)
|
|
assert.equal(items[0].task?.progressTotal, 50)
|
|
assert.equal(items[0].task?.progressLabel, 'US(3/5)')
|
|
})
|
|
|
|
test('缺少 taskId 的项被丢弃,非法 taskId 同样丢弃', () => {
|
|
const items = toBatchItems([{ status: 'RUNNING' }, { taskId: 0, status: 'RUNNING' }, { taskId: 3 }])
|
|
|
|
assert.equal(items.length, 1)
|
|
assert.equal(items[0].task?.id, 3)
|
|
})
|
|
|
|
test('有条目时返回可用结果', () => {
|
|
const picked = pickPollingBatch([{ taskId: 9, status: 'SUCCESS' }], [])
|
|
|
|
assert.notEqual(picked, null)
|
|
assert.equal(picked?.items.length, 1)
|
|
assert.deepEqual(picked?.missingTaskIds, [])
|
|
})
|
|
|
|
test('只有 missing 列表也算可用结果(任务已删除场景)', () => {
|
|
const picked = pickPollingBatch([], [11, 12])
|
|
|
|
assert.notEqual(picked, null)
|
|
assert.equal(picked?.items.length, 0)
|
|
assert.deepEqual(picked?.missingTaskIds, [11, 12])
|
|
})
|
|
|
|
test('空响应返回 null,调用方据此回退重型端点', () => {
|
|
assert.equal(pickPollingBatch([], []), null)
|
|
assert.equal(pickPollingBatch(null, null), null)
|
|
assert.equal(pickPollingBatch(undefined, undefined), null)
|
|
assert.equal(pickPollingBatch([{ status: 'RUNNING' }], []), null, '全是非法项时同样回退')
|
|
})
|