import { test } from 'node:test' import assert from 'node:assert/strict' import { readFileSync } from 'node:fs' import { fileURLToPath } from 'node:url' import { resolve, dirname } from 'node:path' import { taskStatusClass } from '../src/shared/utils/task-status-text.ts' const here = dirname(fileURLToPath(import.meta.url)) const tabSource = readFileSync( resolve(here, '../src/pages/brand/components/BrandPriceTrackTab.vue'), 'utf-8', ) function functionBody(name: string): string { const match = tabSource.match(new RegExp(`function ${name}\\([\\s\\S]*?\\n\\}`)) assert.ok(match, `找不到函数 ${name}`) return match[0] } /** 只留代码行:注释里会出现 "item.success" 这类字面量,不剥掉的话顺序判据抓的是注释。 */ function codeOnly(name: string): string { return functionBody(name) .split('\n') .filter((line) => !line.trim().startsWith('//')) .join('\n') } // 跟价历史行的色块读的是**结果行**的 success(biz_file_result.success=1), // 而文案读的是任务状态。任务判死时结果行往往已经出了部分文件(现网 32889: // 跟到第 53/54 页掉登录,陈先锋.xlsx 已生成、任务是 FAILED),旧写法先认 // `item.success` ⇒ 绿点配"失败"文案,同一格说谎(2026-10-30 用户点名)。 test('test_failed_class_wins_over_row_success', () => { const body = codeOnly('statusClass') const failedIdx = body.indexOf("=== 'FAILED'") const successShortcutIdx = body.indexOf('item.success') assert.ok(failedIdx >= 0, 'statusClass 缺少 FAILED 分支') assert.ok(successShortcutIdx >= 0, 'statusClass 不再引用 item.success:判据要看的是两者先后') assert.ok(failedIdx < successShortcutIdx, 'FAILED 必须先于 item.success 判为 failed 样式') assert.match(body, /taskStatusClass\('FAILED'\)/, 'FAILED 样式必须由公共映射产出') assert.equal(taskStatusClass('FAILED'), 'failed', '公共映射里 FAILED 应产出 failed 样式') }) test('test_color_guard_is_not_vacuous', () => { // 反向自证:抹掉 FAILED 那条早退,顺序判据必须立刻判红(否则上面那条可能是空的) const body = functionBody('statusClass').replace(/if \(st === 'FAILED'\)[\s\S]*?\n/, '') const failedIdx = body.indexOf("=== 'FAILED'") const successShortcutIdx = body.indexOf('item.success') assert.ok(failedIdx === -1 || failedIdx > successShortcutIdx, '抹掉 FAILED 早退仍判得过 ⇒ 色块判据是恒真的') }) test('test_failed_row_keeps_download_button', () => { // 颜色改红不许顺手把部分结果的下载口封掉:这是"起码失败了也可以下载"的既有口径 const body = functionBody('canDownload') assert.match(body, /st === 'FAILED'/, 'FAILED 行必须仍可下载已跑出来的部分结果') })