Files
crawler-plugin/frontend-vue/tests/brand-rows-version-wiring.test.ts
T
huangzd1997 11ad68eea4 feat(phase-4/5 用户端): 恢复巡店删除与指定删除ASIN两个功能页与全部表件
用户口径:这两个功能是随 fdaae3c5 连带删错(该退役的只有紫鸟新版/旧版选项控件),
本次按历史逐字找回并摘掉紫鸟引用。

- 页面:BrandDeleteBrandTab.vue(1740行) / BrandPatrolDeleteTab.vue(1370行) 从 fdaae3c5~1 找回,
  两页各摘 5 处 ZiniaoVersionSetting/useZiniaoVersion 引用与 1 个 ziniao_version 载荷字段
  (checkQueuePayload 只钉 taskId,摘掉不触闸;全树其余读点 0 处)
- 表件:router 两条路由、tool-catalog 18→20 工具与四条图标/详情、BrandTopBar 导航两条、
  endpoints 两块(deleteBrand 10 键 / patrolDelete 16 键)、progress-light 10→12、
  java-modules re-export、module-templates 联合、withdraw.ts 巡店段整文件找回(513 行,
  含两个 ProductRisk*Vo import)
- 测试面:9 支退役时改过的用例从 fdaae3c5~1 逐字找回(含 modules-delete-brand.test.ts 167 行/11 例)
- 自证:npm test 854/854 绿(基线 840+找回 14 例)、vue-tsc --noEmit 与 vite build 通过
- 未触碰他人在飞件:BrandSimilarAsinTab.vue / task-status-text.ts / similar-asin-fake-completed.test.ts

注:恢复后的三支大文件将顶破 ops 侧 readability 棘轮,基线随本轮在 ops 仓重锚并登记。
2026-10-16 20:04:40 +08:00

65 lines
3.3 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 } from 'node:fs'
import { fileURLToPath } from 'node:url'
import { dirname, join } from 'node:path'
/**
* 「行数据按需拉取」接线守卫(审查 F5 后续):
* 5 个品牌工具页用轻量端点的结果行版本跳过重型 batch;这里守住两件最容易写错的事
* ——①接线没被误删;②跳过分支的返回值必须符合调用方契约(曾经把 shopDataCrawl 写成裸 return,
* 而调用方 waitForTerminal 把 falsy 当「任务已消失 → FAILED」,会误杀正在跑的任务)。
*/
const PAGES_DIR = join(dirname(fileURLToPath(import.meta.url)), '../src/pages/brand/components')
const WIRED_PAGES = [
'BrandQueryAsinTab.vue',
'BrandWithdrawTab.vue',
'BrandPatrolDeleteTab.vue',
'BrandShopDataCrawlTab.vue',
'BrandAppearancePatentTab.vue',
]
function sourceOf(page: string) {
return readFileSync(join(PAGES_DIR, page), 'utf8')
}
test('已接线的品牌工具页仍使用结果行版本跳过重型 batch', () => {
for (const page of WIRED_PAGES) {
const source = sourceOf(page)
assert.ok(source.includes('createRowsVersionTracker'), `${page} 缺少版本跟踪器声明`)
assert.ok(source.includes('selectTasksNeedingRows'), `${page} 缺少按需拉取判断`)
assert.ok(source.includes('getModuleProgressLight'), `${page} 缺少轻量端点调用`)
}
})
test('轻量请求失败必须回退为全量拉取(不得因此少拉任务)', () => {
// 多任务页:catch 里把 heavyIds 还原成全部任务
// 回退必须写在 catch 体内:用 [^}] 锁住,否则窗口会跨过 catch 的右花括号,
// 把后面正常分支的 return(如 { taskIds, force: true })当成回退,断言恒真。
for (const page of ['BrandQueryAsinTab.vue', 'BrandWithdrawTab.vue', 'BrandPatrolDeleteTab.vue']) {
assert.match(sourceOf(page), /catch\s*\{[^}]{0,200}?heavyIds = ids/, `${page} 缺少轻量失败回退`)
}
assert.match(sourceOf('BrandAppearancePatentTab.vue'),
/catch\s*\{[^}]{0,240}?(heavyIds = taskIds|return \{ taskIds,)/,
'BrandAppearancePatentTab 缺少轻量失败回退(catch 里必须把全部任务交给重型 batch)')
// 单任务页:catch 里不能有 return(直接落到批量拉取)
const shopDataCrawl = sourceOf('BrandShopDataCrawlTab.vue')
const catchBlock = shopDataCrawl.match(/catch\s*\{([^}]*)\}/)?.[1] ?? ''
assert.ok(catchBlock.length > 0, 'BrandShopDataCrawlTab 未找到 catch 分支')
assert.ok(!catchBlock.includes('return'), 'BrandShopDataCrawlTab 轻量失败时不得提前返回,必须照旧拉批量')
})
test('跳过分支的返回值符合调用方契约', () => {
const shopDataCrawl = sourceOf('BrandShopDataCrawlTab.vue')
// waitForTerminal: `if (!exists) return 'FAILED'` —— 任务仍在时必须返回 true
assert.match(shopDataCrawl, /selectTasksNeedingRows\([\s\S]{0,200}?return true/,
'BrandShopDataCrawlTab 跳过分支必须 return true(false/undefined 会被当成任务已消失)')
const patrolDelete = sourceOf('BrandPatrolDeleteTab.vue')
// waitForTaskTerminal: `missingTaskIds.includes(taskId)` —— 未消失时返回空数组
assert.match(patrolDelete, /selectTasksNeedingRows\([\s\S]{0,300}?return \[\]/,
'BrandPatrolDeleteTab 跳过分支必须返回空 missingTaskIds 数组')
})