aa7e17f95c
用户点名「只要是任务的功能都要加上」:TaskCenterPanel 的 on-refresh 按各自骨架接线 ——useLiveTaskBoard 两页强拉 history+dashboard+进度;手写 fetch 五页 allSettled (history+dashboard+refreshTaskBatch);useHistoryPolling 三页 refreshTaskViews+活跃进度; useTaskProgressLoop 两页加 progressLoop.refreshOnce;一次性拉取三页直挂各自 load 函数; 品牌检测复用既有 syncTasksAndResumePolling。接线守卫测试扩到 16 页。
72 lines
3.8 KiB
TypeScript
72 lines
3.8 KiB
TypeScript
import { test } from 'node:test'
|
||
import assert from 'node:assert/strict'
|
||
import { readFileSync } from 'node:fs'
|
||
import { fileURLToPath } from 'node:url'
|
||
import { dirname, join } from 'node:path'
|
||
|
||
/**
|
||
* 任务面板轮询韧性守卫(task 31769):
|
||
* 外观专利的任务实际 18:08 已 SUCCESS、文件已可下载,但页面卡片冻在
|
||
* 「正在组装 xlsx 92%」一天多——因为 Patent 的轮询配了 'propagate',
|
||
* 一次瞬时请求失败就把轮询永久杀死,卡片假死且无任何自救出口。
|
||
* 这里钉住三件事:①轮询错误必须吞掉并退避重试(pollErrorMode 不得回流);
|
||
* ②面板头部必须有手动「刷新」按钮;③刷新失败要有可见出口。
|
||
*/
|
||
const ROOT = join(dirname(fileURLToPath(import.meta.url)), '..')
|
||
|
||
function sourceOf(rel: string) {
|
||
return readFileSync(join(ROOT, rel), 'utf8')
|
||
}
|
||
|
||
const BOARD = 'src/shared/composables/useLiveTaskBoard.ts'
|
||
const PATENT = 'src/pages/brand/components/BrandAppearancePatentTab.vue'
|
||
const SIMILAR = 'src/pages/brand/components/BrandSimilarAsinTab.vue'
|
||
const PANEL = 'src/shared/components/tasks/TaskCenterPanel.vue'
|
||
|
||
test('轮询异常必须吞掉并重试,propagate 模式不得回流', () => {
|
||
const board = sourceOf(BOARD)
|
||
assert.ok(!board.includes('pollErrorMode'),
|
||
'useLiveTaskBoard 不得再有 pollErrorMode 开关(propagate 会把轮询永久杀死)')
|
||
// catch 里必须有失败计数语句:吞掉 ≠ 空吞,连续失败要进入降频
|
||
assert.match(board, /catch\s*\{[^}]*consecutivePollFailures\s*\+=/,
|
||
'runPollCycle 的 catch 里必须累加失败计数(退避重试的依据)')
|
||
// 后续轮询间隔必须乘以失败倍数(连续失败降频,成功后计数清零恢复原速)
|
||
assert.match(board, /getTaskPollIntervalMs\(\)\s*\*\s*stretch/,
|
||
'scheduleFollowUp 必须按失败倍数拉长轮询间隔')
|
||
assert.match(board, /consecutivePollFailures\s*=\s*0/,
|
||
'轮询成功后必须清零失败计数,否则一次抖动会把间隔永久拉长')
|
||
})
|
||
|
||
test('全部任务面板页都接了手动刷新(用户点名:只要是任务的功能都要有)', () => {
|
||
const PANELS_DIR = join(ROOT, 'src/pages/brand/components')
|
||
const PAGES = [
|
||
'BrandAppearancePatentTab.vue', 'BrandSimilarAsinTab.vue', 'BrandShopMatchTab.vue',
|
||
'BrandProductRiskTab.vue', 'BrandCollectDataTab.vue', 'BrandPriceTrackTab.vue',
|
||
'BrandQueryAsinTab.vue', 'BrandPatrolDeleteTab.vue', 'BrandDeleteBrandTab.vue',
|
||
'BrandShopDataCrawlTab.vue', 'BrandPublishTab.vue', 'BrandWithdrawTab.vue',
|
||
'BrandSplitTab.vue', 'BrandDedupeTab.vue', 'BrandConvertTab.vue', 'BrandBrandTab.vue',
|
||
]
|
||
for (const page of PAGES) {
|
||
const source = readFileSync(join(PANELS_DIR, page), 'utf8')
|
||
assert.ok(source.includes(':on-refresh="'), `${page} 没有给 TaskCenterPanel 传 on-refresh`)
|
||
}
|
||
})
|
||
|
||
test('两个 live 任务面板页的 refreshBoard 实现符合骨架契约', () => {
|
||
for (const [rel, name] of [[PATENT, '外观专利'], [SIMILAR, '货源查询']] as const) {
|
||
const source = sourceOf(rel)
|
||
assert.ok(source.includes(':on-refresh="refreshBoard"'), `${name} 页没有给 TaskCenterPanel 传 on-refresh`)
|
||
assert.match(source, /async function refreshBoard\(\)/, `${name} 页缺少 refreshBoard 实现`)
|
||
assert.match(source, /loadHistory\(\{\s*force:\s*true\s*\}\)/,
|
||
`${name} 的 refreshBoard 必须强拉历史(不带 force 会被 3s 缓存挡掉)`)
|
||
}
|
||
})
|
||
|
||
test('面板刷新按钮存在且失败有可见出口', () => {
|
||
const panel = sourceOf(PANEL)
|
||
assert.match(panel, /onRefresh\?:/, 'TaskCenterPanel 缺少 onRefresh prop')
|
||
assert.match(panel, /panel-refresh/, 'TaskCenterPanel 缺少刷新按钮样式/类名')
|
||
assert.match(panel, /refreshing\s*\?\s*'刷新中/, '刷新中要有按钮态反馈')
|
||
assert.match(panel, /ElMessage\.error\('刷新失败/, '刷新失败必须给用户可见出口,不得静默')
|
||
})
|