Files
crawler-plugin/frontend-vue/tests/task-board-poll-resilience.test.ts
T
huangzd1997 6d52b95d85 fix(task-board): 任务卡片假死自救——轮询失败退避重试+面板刷新按钮+补检轮进度文案
task 31769:外观专利任务后端 18:08 已 SUCCESS,但页面卡片冻在「正在组装 xlsx 92%」
一天多——Patent 轮询配的 propagate 让一次瞬时错误永久杀死轮询,且无自救出口。
- useLiveTaskBoard 摘除 pollErrorMode:失败一律吞掉重试,连续失败按倍数降频(封顶 5x)
- TaskCenterPanel 头部新增「刷新」按钮,外观专利/货源查询两页接上(强拉 history+dashboard)
- 补检轮触发时进度文案改「有 N 行未完成检测,补检中」,不再停在「正在组装 xlsx」假死
- 回归:AppearancePatentRecheckProgressMessageTest+task-board-poll-resilience.test.ts
2026-10-22 15:34:36 +08:00

57 lines
3.0 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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('两个任务面板页都接了手动刷新', () => {
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\('刷新失败/, '刷新失败必须给用户可见出口,不得静默')
})