3987b8d7fe
- 此前全树 0 处全局错误处理器:装 app.config.errorHandler + window error + unhandledrejection, 每条都留可诊断记录、界面只出中文、处理器自身异常不重抛也不白屏(9 例判据)。 - safeHttpUrl 未覆盖的 3 处(两个品牌 Tab 与 useVersionUpdate 直装服务端 file_url)收口; 令牌键 aiimage_auth_token 由 4 处各自定义 + 2 处内联收成唯一定义点。 - 「localStorage 有 uid 就免校验」改走 auth-gate 单点,剩余例外台账化且同口径必须能抓到 评审点名的原写法(6 例);卸载配对 3 处补齐 + 全树判据(7 例)。 - task-status-text 把 CANCELLED 显示成"执行中"改对,CANCELED/CANCELLED 两拼写都映射(4 例)。 - 主审计补的四处修复:新判据里两处拿数组和 0 比(怎么写都红);静默 catch 的"用户可见出口" 符号表认不出本仓 userNotice 与注入式 notify,把真报了用户的 catch 判成静默; 新错误出口带来的 2 个 try/catch 按棘轮合同写理由进基线(296→298,silent 一格没涨)。 - 验收:node --test 820 例 0 红、npx vue-tsc --noEmit rc=0。
103 lines
5.9 KiB
TypeScript
103 lines
5.9 KiB
TypeScript
import { test } from 'node:test'
|
||
import assert from 'node:assert/strict'
|
||
import { readdirSync, readFileSync } from 'node:fs'
|
||
import { fileURLToPath } from 'node:url'
|
||
import { dirname, join, resolve } from 'node:path'
|
||
import {
|
||
CANCELLED_STATUS_TEXT,
|
||
CANCELLED_STATUS_WORDS,
|
||
RUNNING_UNTIL_DONE_STATUS_OPTIONS,
|
||
TASK_STATUS_CLASS,
|
||
TASK_STATUS_TEXT,
|
||
taskStatusClass,
|
||
taskStatusText,
|
||
} from '../src/shared/utils/task-status-text.ts'
|
||
|
||
/**
|
||
* 取消态不得显示为进行中(2026-10-09 评审流程面 5.5 的那条:`CANCELLED` 在 3 个页面被念成「执行中」)。
|
||
*
|
||
* 成因不在映射表写错,而在 `RUNNING_UNTIL_DONE_STATUS_OPTIONS` 的 `replace: true`:
|
||
* 它只列了 SUCCESS/COMPLETED/FAILED 三行,`replace` 又把默认表整个丢掉,
|
||
* 于是 CANCELLED 掉进 `textFallback: '执行中'`——任务早被撤掉了,界面还在说"正在跑"。
|
||
*
|
||
* 判据三层:① 真值表行为钉子(import 真函数跑);② 非终态照旧显示执行中(防止把修复做成"取消也回退成等待中");
|
||
* ③ 全树扫描"取消词 → 进行中文案"的形状,配注入自证与硬分母。
|
||
*/
|
||
|
||
const here = dirname(fileURLToPath(import.meta.url))
|
||
const SRC = resolve(here, '../src')
|
||
|
||
function sourceFiles(dir: string): string[] {
|
||
const out: string[] = []
|
||
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
||
const full = join(dir, entry.name)
|
||
if (entry.isDirectory()) out.push(...sourceFiles(full))
|
||
else if (entry.name.endsWith('.vue') || entry.name.endsWith('.ts')) out.push(full)
|
||
}
|
||
return out
|
||
}
|
||
|
||
/** 「取消词被映射成进行中」的形状:`CANCELLED: '执行中'` / `CANCELED: "正在执行"`。 */
|
||
const CANCELLED_AS_RUNNING_TEXT = /\b(?:CANCELLED|CANCELED)\s*:\s*['"`]?\s*(?:执行中|正在执行|运行中|进行中)/
|
||
|
||
/** 取消词的全部拼写(词面本身也是分母的一部分)。 */
|
||
const CANCELLED_WORD = /\b(?:CANCELLED|CANCELED)\b/g
|
||
|
||
/** 找出源码里把取消态念成进行中的行(判据与注入自证共用同一个函数)。 */
|
||
function cancelledShownAsRunning(source: string): string[] {
|
||
return source.split(/\r?\n/).filter((line) => CANCELLED_AS_RUNNING_TEXT.test(line))
|
||
}
|
||
|
||
test('共用表上取消态是「已取消」,两种拼写都认', () => {
|
||
for (const word of ['CANCELLED', 'CANCELED', 'cancelled', 'canceled', ' CANCELLED ']) {
|
||
assert.equal(taskStatusText(word), CANCELLED_STATUS_TEXT, `${word} 的文案判错`)
|
||
assert.equal(taskStatusClass(word), 'failed', `${word} 的样式类判错`)
|
||
}
|
||
assert.deepEqual([...CANCELLED_STATUS_WORDS].sort(), ['CANCELED', 'CANCELLED'], '取消态词表少了拼写')
|
||
// 默认表里两种拼写都在(美式/英式并存,Java 侧两种都发得出)
|
||
assert.ok('CANCELLED' in TASK_STATUS_TEXT && 'CANCELED' in TASK_STATUS_TEXT, '默认文案表少了一种取消拼写')
|
||
assert.ok('CANCELLED' in TASK_STATUS_CLASS && 'CANCELED' in TASK_STATUS_CLASS, '默认样式表少了一种取消拼写')
|
||
})
|
||
|
||
test('出问题的那 3 页(replace 表):取消态不得是「执行中」,非终态照旧是「执行中」', () => {
|
||
assert.equal(taskStatusText('CANCELLED', RUNNING_UNTIL_DONE_STATUS_OPTIONS), '已取消')
|
||
assert.equal(taskStatusText('CANCELED', RUNNING_UNTIL_DONE_STATUS_OPTIONS), '已取消')
|
||
assert.equal(taskStatusClass('CANCELLED', RUNNING_UNTIL_DONE_STATUS_OPTIONS), 'failed')
|
||
// 反过来也得钉住:这张表的本职是"没到终态就说执行中",不能顺手把等待中也改了
|
||
for (const running of ['RUNNING', 'PENDING', 'SCHEDULED', 'QUEUED', 'WHATEVER_NEW']) {
|
||
assert.equal(taskStatusText(running, RUNNING_UNTIL_DONE_STATUS_OPTIONS), '执行中', `${running} 该仍显示执行中`)
|
||
assert.equal(taskStatusClass(running, RUNNING_UNTIL_DONE_STATUS_OPTIONS), 'running', `${running} 该仍是 running`)
|
||
}
|
||
assert.equal(taskStatusText('SUCCESS', RUNNING_UNTIL_DONE_STATUS_OPTIONS), '已完成')
|
||
assert.equal(taskStatusText('FAILED', RUNNING_UNTIL_DONE_STATUS_OPTIONS), '失败')
|
||
})
|
||
|
||
test('全树扫描:没有任何一处把取消态映射成进行中文案', () => {
|
||
const offenders: string[] = []
|
||
let cancelledWordSites = 0
|
||
for (const file of sourceFiles(SRC)) {
|
||
const rel = file.slice(SRC.length + 1).replace(/\\/g, '/')
|
||
const source = readFileSync(file, 'utf-8')
|
||
cancelledWordSites += (source.match(CANCELLED_WORD) ?? []).length
|
||
for (const line of cancelledShownAsRunning(source)) {
|
||
offenders.push(`${rel}: ${line.trim().slice(0, 120)}`)
|
||
}
|
||
}
|
||
// 分母硬钉:取消词在树上的出现次数(改文案前实测 20+),塌了说明扫描器失明
|
||
assert.ok(cancelledWordSites >= 15, `全树只扫到 ${cancelledWordSites} 处取消词(下限 15)——此刻的"零违规"不作数`)
|
||
assert.deepEqual(offenders, [], `这些行把取消态念成了进行中:\n${offenders.join('\n')}`)
|
||
})
|
||
|
||
test('注入自证:尺子抓得住自己造的违例,也放得过合法写法', () => {
|
||
const planted = " text: { SUCCESS: '已完成', CANCELLED: '执行中' },"
|
||
assert.deepEqual(cancelledShownAsRunning(planted).length, 1, '造出来的违例没被抓到,上面那条"零违规"是恒绿')
|
||
const plantedUs = " return taskStatusText(st, { text: { CANCELED: '正在执行' } })"
|
||
assert.deepEqual(cancelledShownAsRunning(plantedUs).length, 1, '美式拼写的违例没被抓到')
|
||
// 合法写法:取消态映射成别的中文、或进行中词映射成进行中
|
||
assert.equal(cancelledShownAsRunning(" CANCELLED: '已取消',").length, 0, '合法文案被判成了违例')
|
||
assert.equal(cancelledShownAsRunning(" RUNNING: '执行中',").length, 0, '非取消词不该被这条尺子管')
|
||
// 真源码里也验一遍:改坏了立刻能在这里现形,而不是在页面截图里
|
||
const real = readFileSync(join(SRC, 'shared/utils/task-status-text.ts'), 'utf-8')
|
||
assert.deepEqual(cancelledShownAsRunning(real), [], 'task-status-text.ts 自己就把取消态写成了进行中')
|
||
})
|