Files
crawler-plugin/frontend-vue/tests/jd-publish-tab.test.ts
T
huangzd1997 fce4c7322c fix(jd): 选品/建单归属闸从「只认建单人」改为「可见数据权限分组」作用域
客户实况(阿华112336,2026-11-25):上架页分类「3店」徽标写 3 个商品,展开列表
「该分类下暂无归属你账号的商品」、已选 0、上架按钮永久置灰——这 3 个商品是同组同事
(阿华普通账户测试)采的,服务端旧口径按 biz_jd_product.user_id 严格等于登录人过滤,
而分类下拉徽标数的是 V203 归属表行数,两套口径对不上,分类里永远选不到商品。

口径改:商品可见范围与分类下拉、徽标同源——本账号可见数据权限分组
(JdCategoryScopeService.resolveByUserId:自己带的组+所属组长的组+管理链上溯祖先组,
公司维隔离)下的分类归属行。组内谁采的都能由组内成员上架;跨公司/跨组仍 fail-closed。

改法:分类与可见组合成同一条 V203 EXISTS(SQL 侧下推),不先取 id 集再回主表;
商品上架页(/api/jd-publish/products)按可见作用域分页,建单归属闸改读同一份可见集
(resolveVisibleProductIds,归属表按 product_id IN + owner_group_id IN 查,空集不查库
直接 403)。后管只读页口径不变(visibleGroupIds 为空=不过滤)。配额闸语义未动。

判据:JdProductQueryServiceUserPageTest 7 支(作用域下推/同一支谓词/空作用域不查库/
页码钳制)、JdProductScopeSqlPinTest 2 支(XML 快照钉住 EXISTS 与 owner_group_id IN,
禁 p.user_id)、JdPublishTaskServiceTest 三支建单归属闸(同组同事放行、跨组 403 点名、
可见分组空不查归属表);AdminJdProductControllerTest 27 处调用点补参。逆向验证过:
把谓词改回 p.user_id、把可见组条件删掉、把建单闸改回 Objects.equals 三刀各自当场红。
2026-11-25 21:39:33 +08:00

98 lines
5.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 assert from 'node:assert/strict'
import test from 'node:test'
import { existsSync, readFileSync, readdirSync } from 'node:fs'
import { join } from 'node:path'
/** v1.5 京东发布用户端契约(蓝图 docs/ITERATION_PLAN.md §1 AC-9 / §3 / §4 Phase 4)。
*
* 两组:
* 1. **立即生效**(AC-9 前端绊线,B113-01):`/api/jd-collect/groups` 是京东分类的
* 唯一读取口——全 src 不得出现第三个裸 URL 消费点;发布页要分类数据必须走
* endpoints.jdCollect.groups 的既有 fetch 函数(出现第二个分类口即红)。
* 2. **Phase 4 契约**(2026-11-18 随 Phase 4 落地移除 skip 正式激活):JdPublishTab
* (分类→商品→改价→建单→实时面板)的 5 支验收契约,蓝图 §4 Phase 4【待激活验收测试】清单。
*/
const ROOT = process.cwd()
function read(relativePath: string, what: string): string {
const path = join(ROOT, relativePath)
assert.ok(existsSync(path), `${what} 尚未落地(蓝图 §4 Phase 4):${path}`)
return readFileSync(path, 'utf8')
}
/** 递归收集 src 下 .ts/.vue 源文件 */
function collectSourceFiles(dir: string, acc: string[] = []): string[] {
for (const entry of readdirSync(dir, { withFileTypes: true })) {
const full = join(dir, entry.name)
if (entry.isDirectory()) collectSourceFiles(full, acc)
else if (/\.(ts|vue)$/.test(entry.name)) acc.push(full)
}
return acc
}
// ---------------------------------------------------------- AC-9 前端绊线(立即生效)
test('AC-9: 京东分类读取口全 src 唯一(B113-01 绊线)', () => {
const hits = collectSourceFiles(join(ROOT, 'src'))
.filter((f) => readFileSync(f, 'utf8').includes('jd-collect/groups'))
.map((f) => f.replace(/\\/g, '/').replace(ROOT.replace(/\\/g, '/') + '/', ''))
assert.deepEqual(hits.sort(), [
'src/shared/api/endpoints.ts',
'src/shared/api/types/modules/jd-collect.ts',
], 'B113-01:/api/jd-collect/groups 是京东分类唯一读取口——发布页要分类必须消费 endpoints.jdCollect.groups 既有出口,不得新增裸 URL 消费点')
})
// ---------------------------------------------------------- Pending Phase 4
test('AC-9: JdPublishTab 分类选择消费唯一 groups 出口', () => {
const tab = read('src/pages/jd/JdPublishTab.vue', '商品上架页')
assert.ok(tab.includes('jdCollect'), 'JdPublishTab 的分类数据必须走 endpoints.jdCollect/groups 既有 fetch(AC-9),不得自拼 URL')
assert.ok(!tab.includes('jd-collect/groups'), 'JdPublishTab 不得裸写分类 URL(B113-01 绊线)')
})
test('选品作用域:建单带 productIds,文案与作用域口径一致(2026-11-25)', () => {
const tab = read('src/pages/jd/JdPublishTab.vue', '商品上架页')
assert.ok(tab.includes('productIds') || tab.includes('productId'),
'JdPublishTab 建单提交必须携带勾选的商品 id 集合(服务端按可见分类作用域校验)')
// 口径改:同组同事采集的商品也能上架——文案不得再写「归属你账号」,空态与说明同步。
assert.ok(!tab.includes('归属你账号'), '文案不得再写「归属你账号」:起作用域是可见分类,不是建单人')
assert.ok(tab.includes('该分类下暂无商品'), '空态文案必须与作用域口径一致')
assert.ok(tab.includes('同组同事采集的也能上架'), '分类说明必须点名「同组同事采集的也能上架」')
})
test('建单请求体形状:categoryId + productIds + priceRule{mode,value}', () => {
const tab = read('src/pages/jd/JdPublishTab.vue', '商品上架页')
// 蓝图 §3 死契约:POST /api/jd-publish/tasks 请求体 {categoryId, productIds[], priceRule:{mode,value?}}
assert.ok(tab.includes('categoryId'), '建单体缺 categoryId(所选自定义分类)')
assert.ok(tab.includes('priceRule'), '建单体缺 priceRule(统一改价规则;mode: none|percent|fixed)')
assert.ok(tab.includes("'percent'") && tab.includes("'fixed'") && tab.includes("'none'"),
'priceRule.mode 三档(none/percent/fixed)必须与蓝图 §3 同值')
})
test('endpoints 注册 jdPublish 端点组(建单/items/chunk 三件)', () => {
const endpoints = read('src/shared/api/endpoints.ts', 'endpoints.ts')
assert.ok(endpoints.includes('jdPublish'), 'endpoints.ts 缺 jdPublish 端点组')
assert.ok(endpoints.includes('/api/jd-publish/tasks'), 'jdPublish 组缺建单端点 /api/jd-publish/tasks')
})
test('商品上架占位卡转正式:jd-publish 卡挂 /jd-publish 路由', () => {
const catalog = read('src/pages/jd/tool-catalog.ts', 'jd/tool-catalog.ts')
const router = read('src/router/index.ts', 'router/index.ts')
assert.ok(/id:\s*'jd-publish'[\s\S]*?href:\s*'\/jd-publish'/.test(catalog),
'jd-publish 卡须补 href 指向 /jd-publish(转正式)')
assert.ok(router.includes("path: '/jd-publish'"), 'router 缺 /jd-publish 路由')
})
// ---------------------------------------------------------- 分类空态点名(2026-11-25)
test('分类空态文案单出口:判据 computed+两常量定义存在,模板按名引用不内联第二份', () => {
const tab = read('src/pages/jd/JdPublishTab.vue', '商品上架页')
assert.ok(tab.includes('const GROUPS_EMPTY_DROPDOWN_TEXT'), '下拉空态文案必须定义在常量单出口')
assert.ok(tab.includes('const GROUPS_EMPTY_HINT_TEXT'), '块下动作句文案必须定义在常量单出口')
assert.ok(tab.includes('const groupsEmpty = computed'),
'空态判据=拉取完成且集合为空(groupsLoading 结束+length===0),不许拿加载中也当空')
assert.ok(tab.includes('{{ GROUPS_EMPTY_HINT_TEXT }}') && tab.includes(':empty-text="groupsEmpty ? GROUPS_EMPTY_DROPDOWN_TEXT'),
'模板两处都必须引用常量——内联第二份文案就是口径漂移的开始')
})