import { test } from 'node:test' import assert from 'node:assert/strict' import { existsSync, readFileSync } from 'node:fs' import { join } from 'node:path' /** 京麦「店内分类」快照契约(2026-11-16 真机取证,建单页采集分类多选的选项集)。 * * 快照是纯前端静态数据(getShopCategoryList 的 label/value 对,扁平单层)。判据钉四件: * ① 快照非空且形状齐(label/value 都非空字符串);② label 不重复(多选以 label 下发, * 重名会让客户端过滤语义歧义);③ 取证出处注释在位(后人按原路重抓,防止当它错改); * ④ 建单页消费快照(对手面 jd-collect-tab.test.ts 的发送口断言)。 */ const SNAPSHOT = join(process.cwd(), 'src', 'pages', 'jd', 'jd-shop-category.ts') function readIfExists(path: string, what: string): string { assert.ok(existsSync(path), `${what} 尚未落地:${path}`) return readFileSync(path, 'utf8') } test('店内分类快照非空且每项 label/value 齐全', async () => { const mod = await import('../src/pages/jd/jd-shop-category.ts') const { JD_SHOP_CATEGORY_SNAPSHOT } = mod as { JD_SHOP_CATEGORY_SNAPSHOT: { label: string; value: string }[] } assert.ok(Array.isArray(JD_SHOP_CATEGORY_SNAPSHOT) && JD_SHOP_CATEGORY_SNAPSHOT.length > 0, '快照不得为空(2026-11-16 取证 9 个)') for (const item of JD_SHOP_CATEGORY_SNAPSHOT) { assert.ok(typeof item.label === 'string' && item.label.trim().length > 0, `label 必须是非空字符串: ${JSON.stringify(item)}`) assert.ok(typeof item.value === 'string' && item.value.trim().length > 0, `value(京麦分类 id)必须是非空字符串: ${JSON.stringify(item)}`) } }) test('快照 label 不重复(多选按 label 下发,重名会让过滤语义歧义)', async () => { const mod = await import('../src/pages/jd/jd-shop-category.ts') const { JD_SHOP_CATEGORY_SNAPSHOT } = mod as { JD_SHOP_CATEGORY_SNAPSHOT: { label: string }[] } const labels = JD_SHOP_CATEGORY_SNAPSHOT.map((item) => item.label) assert.equal(new Set(labels).size, labels.length, `label 有重复: ${labels.join(', ')}`) }) test('取证出处与边界注释在位(防后人当它错改)', () => { const body = readIfExists(SNAPSHOT, 'jd-shop-category.ts') assert.ok(body.includes('getShopCategoryList'), '快照文件必须写明数据来源接口(ShopCategoryReadViewService.getShopCategoryList)') assert.ok(body.includes('2026-11-16'), '快照文件必须带取证日期') assert.ok(body.includes('shopCategorys') || body.includes('shopCategoryPath'), '快照文件必须写明行级过滤键(shopCategorys/shopCategoryPath/groupId)') assert.ok(body.includes('0/450') || body.includes('没给商品挂分类'), '快照文件必须写明「采样店铺 0 商品挂分类」的现状边界(选分类=0 行命中是已知形状)') })