// 终态进度读数的钉子(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/) })