d22a9e2164
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 抓到过一次)。
48 lines
2.3 KiB
TypeScript
48 lines
2.3 KiB
TypeScript
// 终态进度读数的钉子(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/)
|
||
})
|