103 lines
4.4 KiB
TypeScript
103 lines
4.4 KiB
TypeScript
/**
|
|
* 外观专利删除链路的守卫(2026-10-29 现网「删不了」)。
|
|
*
|
|
* 现网证据:失败任务被自动克隆重试后(克隆件复制源结果行、开始时间逐字相同、
|
|
* 后几代克隆连结果行都没有),旧口径只给 RUNNING 删任务、其余只删结果行——
|
|
* 没有结果行的任务在列表里既没有删除按钮,批量全选删到它也静默跳过只弹「已删除」,
|
|
* 用户看到的就是「删不了」。这与巡店删除页已经收敛的正确口径不一致。
|
|
*
|
|
* 这里钉住四件事:
|
|
* ①外观专利改为「有任务就删任务」,不再用 RUNNING 当门;
|
|
* ②历史行只要有任务/结果标识就出删除按钮;
|
|
* ③缺标识必须显式报错,不允许假报「已删除」;
|
|
* ④批量删除只弹一次确认,不再逐条二次弹框。
|
|
*
|
|
* 跑法:`node --test tests/appearance-patent-task-delete.test.ts`
|
|
*/
|
|
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'
|
|
|
|
const here = dirname(fileURLToPath(import.meta.url))
|
|
const tabSource = readFileSync(
|
|
resolve(here, '../src/pages/brand/components/BrandAppearancePatentTab.vue'),
|
|
'utf-8',
|
|
)
|
|
const boardSource = readFileSync(
|
|
resolve(here, '../src/shared/composables/useLiveTaskBoard.ts'),
|
|
'utf-8',
|
|
)
|
|
|
|
function slot(name: string): string {
|
|
const match = tabSource.match(
|
|
new RegExp(`<template #${name}="\\{ item \\}">([\\s\\S]*?)</template>`),
|
|
)
|
|
assert.ok(match, `找不到 #${name} 插槽`)
|
|
return match[1]
|
|
}
|
|
|
|
test('外观专利删任务不再限定 RUNNING:有 taskId 就删任务', () => {
|
|
const match = tabSource.match(/shouldDeleteTask:\s*\(item\)\s*=>\s*([^,\n]+),/)
|
|
assert.ok(match, '找不到 shouldDeleteTask 谓词')
|
|
assert.match(match[1], /item\.taskId\s*!=\s*null/, '谓词必须认 taskId')
|
|
assert.doesNotMatch(match[1], /RUNNING/, '用 RUNNING 当门会让失败/克隆任务永远删不掉')
|
|
})
|
|
|
|
test('历史行有任务或结果标识就要出删除按钮(克隆件没有结果行)', () => {
|
|
const history = slot('history-item-actions')
|
|
assert.match(
|
|
history,
|
|
/v-if="itemSource\(item\)\.taskId \|\| itemSource\(item\)\.resultId"/,
|
|
'只按 resultId 出按钮时,没有结果行的任务在列表里无法删除',
|
|
)
|
|
})
|
|
|
|
test('缺标识必须报错而不是假报已删除', () => {
|
|
assert.match(boardSource, /resolveTaskDeleteTarget\(/, '删除目标必须走统一判定')
|
|
assert.match(
|
|
boardSource,
|
|
/throw new Error\('该记录缺少任务\/结果标识/,
|
|
'none 分支必须抛错,否则点击删除既不请求也不报错,用户以为删掉了',
|
|
)
|
|
})
|
|
|
|
test('记录已不存在时自愈:同步移除本地记录而不是报删除失败', () => {
|
|
assert.match(boardSource, /isRecordMissingError\(e\)/, '必须识别「任务不存在/记录不存在」')
|
|
assert.match(boardSource, /记录已不存在,已同步移除本地记录/, '记录已不存在要有可见的同步提示')
|
|
})
|
|
|
|
test('批量删除不再逐条弹二次确认', () => {
|
|
assert.match(
|
|
boardSource,
|
|
/deleteTaskRecord\(.*\{ skipConfirm: true, silent: true \}\)/,
|
|
'批量入口已确认过一次,逐条再弹框(确认框或成功提示)会让用户以为批量删除没生效',
|
|
)
|
|
})
|
|
|
|
test('批量删除只报一次总数,不逐条弹成功提示', () => {
|
|
const fn = boardSource.slice(
|
|
boardSource.indexOf('async function batchDeleteHistory'),
|
|
boardSource.indexOf('function dispose'),
|
|
)
|
|
assert.ok(fn.includes('runBatchDelete'), '批量入口必须走 runBatchDelete')
|
|
assert.match(
|
|
fn,
|
|
/已删除 \$\{total\} 条历史记录/,
|
|
'删完只报一次总数(含失败时报告成功/失败条数)',
|
|
)
|
|
assert.match(
|
|
fn,
|
|
/Promise\.allSettled\(\[loadDashboard\(\), loadHistory/,
|
|
'批量删完统一刷新一次列表,不逐条刷新',
|
|
)
|
|
// 逐条成功提示必须被 silent 挡住:silent 模式下单条函数不再弹「已删除」
|
|
const single = boardSource.slice(
|
|
boardSource.indexOf('async function deleteTaskRecord'),
|
|
boardSource.indexOf('async function batchDeleteHistory'),
|
|
)
|
|
assert.match(single, /if \(opts\.silent\) return/, 'silent 模式必须跳过逐条刷新与成功提示')
|
|
assert.match(single, /if \(opts\.silent\) throw e/, 'silent 模式下单条失败要抛错交给批量计数')
|
|
})
|