Files
crawler-plugin/frontend-vue/tests/task-progress-view-wiring.test.ts
T
huangzd1997 ee9a32a272 feat(brand): 失败任务「重新提交」入口+排队期显示执行方人话文案(3700 客户端半边)
- brand.ts:resubmitBrandTask 走桥 resubmit_brand_task(重跑必须本机客户端建单执行,
  线上 15126 无从替用户重跑;老客户端 available=false 提示升级);BrandLocalBridge 登记
  桥形状;BrandLineProgressInfo 补 progress_text 与 queued 档注释。
- BrandBrandTab.vue:failed/cancelled 行出「重新提交」按钮(确认框点名沿用策略与通道);
  排队期 extraLines 显示 progress_text(已等待 N 秒;同机 M/K 槽在用),countLabel 不再
  摆恒 0 的「0/265」——用户从「排队中/0 行」无从分辨排队与卡死。
- pywebview.ts:open_jd_login 注释改按自动链路口径(见下一笔,桥本身零改动)。
- 判据:brand-resubmit-entry.test.ts(桥形状+入口 wiring+源码绊线)+
  task-progress-view-wiring.test.ts +排队文案透出绊线+catch-silence 台账 blocks 334→335
  (resubmitTask 的 try/catch 有用户可见出口,非静默,silent 与 perFile 未动)。
2026-11-23 17:30:05 +08:00

92 lines
4.8 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { test } from 'node:test'
import assert from 'node:assert/strict'
import { readFileSync, readdirSync } from 'node:fs'
import { join } from 'node:path'
/**
* 任务卡片的「进度条接线」普查。
*
* 为什么要它:TaskItemView.progress 是可空字段,页面少写一行不会报错、不会红,
* 界面上就是安静地没有进度条。11 个任务页各写一处,漏哪一处全靠这条出声。
*
* 分母不手抄:扫 src/pages/brand/components 下所有写了 `to*TaskView(...): TaskItemView`
* 适配器的页面,清单由文件系统给出;再把总数硬钉住——新增页面没接进度、或有人把
* 适配器改名躲开扫描,都在这条上出声(只比总数会被「内部搬家」绕过,所以逐个点名)。
*/
const COMPONENTS = join(import.meta.dirname, '..', 'src', 'pages', 'brand', 'components')
const ADAPTER_PATTERN = /function (to\w*TaskView)\(/
/**
* 判据只看「适配器返回的对象里出现了 progress 属性」,两种写法都认:
* `progress: {…}` 与 ES6 简写 `progress,`(BrandBrandTab 用后者,只认冒号会把它误报成缺口,
* 而误报的尺子很快会被人当噪音绕过去)。
*/
const PROGRESS_KEY = /^\s*(?:progress\s*:|progress\s*,)/m
function adaptersOf(file: string) {
const lines = readFileSync(join(COMPONENTS, file), 'utf8').split(/\r?\n/)
const found: { name: string; start: number; end: number }[] = []
for (let index = 0; index < lines.length; index += 1) {
const matched = ADAPTER_PATTERN.exec(lines[index])
if (!matched) continue
let end = index
while (end + 1 < lines.length && lines[end + 1] !== '}') end += 1
found.push({ name: matched[1], start: index, end })
}
return found
}
const pages = readdirSync(COMPONENTS).filter((name) => name.endsWith('.vue'))
const seen = pages.flatMap((file) => adaptersOf(file).map((a) => ({ file, ...a })))
test('被扫描的任务卡适配器数量必须硬钉(少扫或多扫都说明扫描面变了)', () => {
assert.equal(seen.length, 16, `扫到 ${seen.length} 个 to*TaskView 适配器:${seen.map((s) => `${s.file}#${s.name}`).join(', ')}`)
})
test('每个任务卡适配器都必须给出进度读数,或明确给出 null', () => {
const offenders = seen
.filter((entry) => {
const lines = readFileSync(join(COMPONENTS, entry.file), 'utf8').split(/\r?\n/)
const body = lines.slice(entry.start, entry.end + 1).join('\n')
return !PROGRESS_KEY.test(body)
})
.map((entry) => `${entry.file}#${entry.name}`)
assert.deepEqual(offenders, [], '这些任务页画不出进度条:' + offenders.join(', '))
})
test('实时进度通道的写入点只有一个,且在 light 出口上', () => {
const sharedDir = join(import.meta.dirname, '..', 'src', 'shared', 'api')
const callers = readdirSync(sharedDir)
.filter((name) => name.endsWith('.ts') && name !== 'task-progress-live.ts')
.filter((name) => readFileSync(join(sharedDir, name), 'utf8').includes('rememberLiveProgress('))
assert.deepEqual(callers, ['progress-light.ts'],
'rememberLiveProgress 的调用者必须是 light 出口一处;多处写会让刷新时机和过期判定分家:' + callers.join(', '))
})
test('light 白名单与后端 VO 的进度三字段同名同形', () => {
const light = readFileSync(join(import.meta.dirname, '..', 'src', 'shared', 'api', 'progress-light.ts'), 'utf8')
const polling = readFileSync(join(import.meta.dirname, '..', 'src', 'shared', 'api', 'task-progress-polling.ts'), 'utf8')
for (const field of ['progressCurrent', 'progressTotal', 'progressLabel']) {
assert.ok(light.includes(`${field}?:`), `progress-light.ts 的白名单缺 ${field}`)
// toBatchItems 的键集是逐字段挑的,少挑一个就把后端给的数丢掉
assert.ok(polling.includes(`${field}: item.${field} ?? null`), `task-progress-polling.ts 归一时丢了 ${field}`)
}
})
/**
* 2026-11-23 任务 3700:品牌单排队 120 分钟后判死,界面全程只有「排队中 / 已处理 0 行」。
* 客户端心跳一直带着人话文案(progressText),后端 2026-11-23 起把它透出成 progress_text,
* 任务卡必须把它显示出来——否则用户无法分辨「在排队」还是「卡死」。
*/
test('品牌任务卡必须显示后端透出的排队文案 progress_text', () => {
const src = readFileSync(join(COMPONENTS, 'BrandBrandTab.vue'), 'utf8')
assert.match(src, /progress_text/, 'BrandBrandTab 必须读取 line_progress.info.progress_text')
assert.match(src, /phase === 'queued'/, '排队文案只在 queued 阶段替代行数行')
const types = readFileSync(
join(import.meta.dirname, '..', 'src', 'shared', 'api', 'types', 'modules', 'brand.ts'),
'utf8',
)
assert.match(types, /progress_text\?: string/, 'BrandLineProgressInfo 必须声明 progress_text')
})