fix(采集数据): 终态卡片把关键词缺口写出来,而不是把进度条画满
task 31253 的「已完成 + 总进度 25%」被当成显示 bug 报上来,实际那根条是卡片上 唯一说真话的一格:8 个关键词只处理了 2 个。强制 SUCCESS 显示 100% 会把提前结束 抹平,所以这里反过来——终态却没跑完时在卡片上补一行关键词缺口。 判据单独放 src/shared/utils/task-progress-readout.ts:.vue 在本套件挂不起来, 留在组件里就没法真测。终态词表复用 task-terminal 那份,不自建第二套 (tests/task-terminal-set-single-source.test.ts 抓到过一次)。
This commit is contained in:
@@ -172,6 +172,7 @@ import {
|
||||
import { getPollingProgressBatch } from '@/shared/api/task-progress-polling.ts'
|
||||
import { formatDateTime } from '@/shared/utils/datetime'
|
||||
import { taskStatusClass, taskStatusText } from '@/shared/utils/task-status-text'
|
||||
import { terminalKeywordShortfall } from '@/shared/utils/task-progress-readout'
|
||||
import { runBatchDelete } from '@/shared/utils/batch-delete'
|
||||
import { confirmTaskDeletion } from '@/shared/task-delete-confirm'
|
||||
|
||||
@@ -678,6 +679,7 @@ function toCollectTaskView(item: CollectDataHistoryItem): TaskItemView {
|
||||
const isActive = isCollectTaskActive(item)
|
||||
const keywordProgress = taskKeywordProgress(item)
|
||||
const stageProgress = taskStageProgress(item)
|
||||
const shortfall = terminalKeywordShortfall(item)
|
||||
const percent = taskProgressPercent(item)
|
||||
const finishedAt = item.finishedAt ? formatDateTime(item.finishedAt) : isActive ? '进行中' : '-'
|
||||
const extraLines: string[] = isActive
|
||||
@@ -693,6 +695,9 @@ function toCollectTaskView(item: CollectDataHistoryItem): TaskItemView {
|
||||
`不符合 ASIN 过滤:${item.invalidFilteredCount ?? 0}`,
|
||||
...(item.resultFilename ? [item.resultFilename] : []),
|
||||
...(taskFilterSummary(item) ? [`筛选统计:${taskFilterSummary(item)}`] : []),
|
||||
// 终态却没跑完全部关键词:把缺口写在卡片上。此前只有那根 25% 的进度条在说话,
|
||||
// 而卡片同时写着「已完成」,读起来像是进度条坏了,实际是它在报任务提前结束。
|
||||
...(shortfall ? [shortfall] : []),
|
||||
...(item.error ? [`错误:${userNotice(item.error)}`] : []),
|
||||
]
|
||||
return {
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
/**
|
||||
* 终态任务卡片的进度读数。
|
||||
*
|
||||
* 为什么单独放一个文件:这条判据只能从 .vue 里挂出来测(本套件没有 @vue/test-utils,
|
||||
* 见 tests/task-terminal-completed-behavior.test.ts 的说明),而它恰好是线上事故
|
||||
* (task 31253:已完成 + 总进度 25% + 下载空白)里唯一说真话的那一格。
|
||||
*
|
||||
* 铁律:**不许**因为状态是 SUCCESS 就把没跑完的关键词抹成 100%。
|
||||
* processedRows < totalRows 是「任务提前结束」的表征,把它显示出来是这条读数的用途,
|
||||
* 不是它的 bug。
|
||||
*/
|
||||
|
||||
import { isTerminalTaskStatus } from './task-terminal.ts'
|
||||
|
||||
export interface TerminalProgressItem {
|
||||
taskStatus?: string | null
|
||||
success?: boolean | null
|
||||
processedRows?: number | null
|
||||
totalRows?: number | null
|
||||
}
|
||||
|
||||
function isTerminal(item: TerminalProgressItem): boolean {
|
||||
return item.success === true || isTerminalTaskStatus(item.taskStatus || undefined)
|
||||
}
|
||||
|
||||
/**
|
||||
* 终态且关键词没跑完时返回一句缺口说明,否则返回空串。
|
||||
* 行数缺失(totalRows 非正数)时不猜,返回空串——没有分母就没有缺口可言。
|
||||
*/
|
||||
export function terminalKeywordShortfall(item: TerminalProgressItem): string {
|
||||
if (!isTerminal(item)) return ''
|
||||
const total = Number(item.totalRows)
|
||||
const processed = Number(item.processedRows ?? 0)
|
||||
if (!Number.isFinite(total) || total <= 0) return ''
|
||||
if (!Number.isFinite(processed) || processed >= total) return ''
|
||||
const status = (item.taskStatus || '').toUpperCase()
|
||||
const label = status === 'FAILED' ? '任务失败于' : '任务提前结束于'
|
||||
return `关键词缺口:${label} ${processed}/${total},还有 ${total - processed} 个关键词未采集`
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
// 终态进度读数的钉子(task 31253:已完成 + 总进度 25% + 下载空白)。
|
||||
//
|
||||
// 这条读数唯一不许被改坏的性质:**状态是 SUCCESS 不等于跑完了全部关键词**。
|
||||
// 当时卡片上只有 25% 那根条在说真话,却被当成显示 bug 报上来——所以这里钉的是
|
||||
// 「缺口必须出声」,而不是「成功就画满」。
|
||||
import { test } from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
|
||||
import { terminalKeywordShortfall } from '../src/shared/utils/task-progress-readout.ts'
|
||||
|
||||
test('成功态但关键词没跑完:缺口必须写在卡片上', () => {
|
||||
// 31253 的真实形状:8 个关键词只处理了 2 个,服务端却标了 SUCCESS。
|
||||
const line = terminalKeywordShortfall({ taskStatus: 'SUCCESS', processedRows: 2, totalRows: 8 })
|
||||
assert.match(line, /2\/8/, '要给出已处理/总数,用户才知道差多少')
|
||||
assert.match(line, /6 个关键词未采集/, '要给出缺口条数')
|
||||
assert.match(line, /提前结束/, '成功态下的提前结束要说清是提前结束,不是正常收尾')
|
||||
})
|
||||
|
||||
test('跑满的终态:不产生缺口说明', () => {
|
||||
assert.equal(terminalKeywordShortfall({ taskStatus: 'SUCCESS', processedRows: 8, totalRows: 8 }), '')
|
||||
assert.equal(terminalKeywordShortfall({ taskStatus: 'SUCCESS', processedRows: 9, totalRows: 8 }), '')
|
||||
})
|
||||
|
||||
test('失败态的缺口说「失败于」而不是「提前结束于」', () => {
|
||||
const line = terminalKeywordShortfall({ taskStatus: 'FAILED', processedRows: 1, totalRows: 4 })
|
||||
assert.match(line, /失败于 1\/4/)
|
||||
})
|
||||
|
||||
test('在跑的任务不归这条管:运行期缺口由关键词进度行负责', () => {
|
||||
assert.equal(terminalKeywordShortfall({ taskStatus: 'RUNNING', processedRows: 2, totalRows: 8 }), '')
|
||||
assert.equal(terminalKeywordShortfall({ taskStatus: 'PENDING', processedRows: 0, totalRows: 8 }), '')
|
||||
})
|
||||
|
||||
test('没有分母就不猜', () => {
|
||||
for (const totalRows of [null, undefined, 0, -1, Number.NaN]) {
|
||||
assert.equal(
|
||||
terminalKeywordShortfall({ taskStatus: 'SUCCESS', processedRows: 2, totalRows }),
|
||||
'',
|
||||
`totalRows=${String(totalRows)} 时不该编出一条缺口文案`,
|
||||
)
|
||||
}
|
||||
})
|
||||
|
||||
test('success 布尔位也算终态(老响应体没有 taskStatus)', () => {
|
||||
const line = terminalKeywordShortfall({ success: true, processedRows: 3, totalRows: 8 })
|
||||
assert.match(line, /3\/8/)
|
||||
})
|
||||
Reference in New Issue
Block a user