feat(公司tab): 任务看板五个端点按公司筛(一处 resolve 收窄,detail 靠 scope.visible 同宽)

This commit is contained in:
2026-10-05 19:14:51 +08:00
parent b80addfdb4
commit 965e969076
7 changed files with 348 additions and 35 deletions
@@ -21,7 +21,8 @@ const read = (p: string) => {
* 这正是本批次要杀的那类静默失效,尺子却看不见。
* <p>于是每页登记一条"company_id 右侧的根标识符**必须**是该页 api 函数自己的入参"的形状:
* `shape` 为 `RegExp` 时,对**剥完注释的源码**求值,不匹配即红并点名文件;`shape` 为 `null` 是
* "这一页还没接线"的显式声明(今天 6 页如此,它们本来就在缺口清单里)。
* "这一页还没接线"的显式声明(批次 1 的 8 页到 Task 10 全部登记完,今天表里没有 null 项了;
* 这一档留着是给将来新页先进清单、后接线的中间状态用的,不是默认分支)。
* <p>两道不留缝:① `COMPANY_SCOPED_PAGES` 里每一页都必须在表里有条目,缺条目直接红;
* ② 一旦某个文件真的出现了 `company_id` 下传而它的 `shape` 还是 `null`,同样红——
* 所以"新页接线时顺手不改登记表"过不去,也**没有**"没登记就退回宽松判据"的默认分支。
@@ -47,8 +48,21 @@ const COMPANY_ID_SOURCE_PINS: Readonly<Record<string, readonly CompanyIdPin[]>>
},
],
admin_task_center: [
{ file: 'src/api/task-center.ts', shape: null, note: 'Task 10 未接线(已在缺口清单里);谁接线谁把 null 换成本函数真实取值口' },
{ file: 'src/pages/task-center/task-center-model.ts', shape: null, note: '同上:这一页有两个取数模块,两个都得登记' },
{
file: 'src/api/task-center.ts',
// 三个自己构造 query 的发送口(overview / shop-options / tasks/detail)都写成
// `if (companyId != null) query.company_id = companyId`;另外两支(tasks / variant-tasks)
// 是 `params: QueryParams` 直传、没有中间构造对象,公司键由 model 那两个 builder 补。
// 所以这一页不许套 Task 8 的 `params.companyId` 形——这一页的 api 根本没有 params.companyId 这个口。
shape: /company_id\s*=\s*companyId\b/,
note: 'null 由发送口自己丢(不依赖 axios 丢 null);右半边必须是本函数自己的形参 companyId',
},
{
file: 'src/pages/task-center/task-center-model.ts',
// buildTaskQuery / buildVariantQuery 的第 4 形参就叫 companyId ⇒ 与 api 侧同一形。
shape: /company_id\s*=\s*companyId\b/,
note: '这一页有两个取数模块(api + model),两条各钉一处取值口,不许合成一条 alternation',
},
],
admin_user_secret_usage: [
{
@@ -105,8 +119,8 @@ let strictPinsPassed = 0
test('正向:声明 companyScoped 的页,其 api 文件必须真的带 company_id,页面组件必须 watch activeId', () => {
// 循环里**收集**、循环后一次性断言:Task 8-12 是 5 个任务共用这把尺子,fail-fast 时做完自己那页的同事
// 仍然只看到一句指向**别人页**的红(今天只报 src/api/task-center.ts),判断不出本页是否已收敛。
// 这条不改变"Task 12 之前必红"的既定性质,只是让尺子可诊断——红消息里 8 页缺口逐页列全。
// 仍然只看到一句指向**别人页**的红,判断不出本页是否已收敛。
// 这条只是让尺子可诊断——红消息里 8 页缺口逐页列全(批次 1 到 Task 10 已全部接线,今天这支应绿)。
const problems: string[] = []
for (const page of COMPANY_SCOPED_PAGES) {
const gaps: string[] = []
@@ -179,7 +193,7 @@ test('正向:声明 companyScoped 的页,其 api 文件必须真的带 company
&& COMPANY_ID_SOURCE_PINS.admin_image_video_tasks.some((p) => p.shape !== null),
'Task 8 已接线的两页在登记表里的 shape 被改回 null 了:严格判据对这两页不再起作用(正样本归零)')
assert.deepEqual(problems, [],
`公司 tab 接线缺口(逐页列全;Task 8-12 补齐后这支自动收敛,本轮刻意留红):\n`
`公司 tab 接线缺口(逐页列全;批次 1 的 8 页到 Task 10 已全部接线,谁再退回未接线就红在这里):\n`
+ problems.map((p) => ` - ${p}`).join('\n'))
})
@@ -196,6 +210,65 @@ test('反向:把 company_id 当查询参数用的取数模块必须被清单
}
})
/**
* 切公司必须把「上一家选中的分组」一起清掉(TaskList #22,控制方 2026-10-05 点名)。
*
* <p>为什么单独钉这一处:`filter.groupId` 是**用户选中的值**,不是每次请求重算的。切到另一家公司后,
* 上一家选中的 groupId 在新一家的可见集里根本不存在,列表于是被 `groupId=` 筛成空页——症状是
* 「tab 一切页面就白」,而请求、后端、权限三处全对。G1 的 pageFiles 只断「watch 了 activeId」,
* 看不见 watch 体里到底做了什么,所以体内容必须单独钉。</p>
*
* <p>判据形状:从 `watch(() => companyTab.activeId, …)` 那**一条语句**取文本(正则在第一个
* `}` + `)` 处收口 ⇒ 单层,体内再嵌对象字面量会截早;这一页今天没有那种写法,由下面的取样自检兜着)。
* 反向钉与正样本同支(全局约束 15,三条前提不成立就是探针失效、当场红,不许静默空跑):
* ① 合规样本必须匹配得出且含两把 token ⇒ 判据不恒红;
* ② 删掉 `filter.groupId = null` 的样本必须不含 ⇒ 判据能红(变异自证走的就是这一条);
* ③ 把同一串 token 挪到 watch 之外的样本必须不含 ⇒ 钉的是**位置**,不是「文件里出现过」。
* 末尾还配了一条同链前提:这一页的两个发送口仍在发 `company_id`,清组才有意义。</p>
*/
const WATCH_ACTIVE_ID = /watch\(\(\)\s*=>\s*companyTab\.activeId\s*,\s*\(\)\s*=>\s*\{([\s\S]*?)\}\s*\)/
/** 取「`watch(() => companyTab.activeId, () => { … })`」这一条语句的原文;匹配不出返回 null(由调用方判探针失效)。 */
function watchStatement(source: string): string | null {
const m = WATCH_ACTIVE_ID.exec(source)
return m ? m[0] : null
}
test('切公司的 watch 体:ShopManagePage 体内必须同时出现 companyTab.activeId 与 filter.groupId = null', () => {
// ① 正样本(判据不恒红)——逐字就是 ShopManagePage.vue 今天那一行。
const positive = watchStatement('watch(() => companyTab.activeId, () => { filter.groupId = null; void loadGroups(); void load() })')
assert.ok(positive, '探针失效:合规样本都匹配不出 watch 语句 ⇒ 判据恒红,这条看守等于没写')
assert.ok(positive.includes('companyTab.activeId') && positive.includes('filter.groupId = null'),
'探针失效:合规样本没同时含两把 token ⇒ 下面两条断言无从判定')
// ② 负样本 1(判据能红):删掉清组那一句——变异自证注入的就是这一形。
const dropped = watchStatement('watch(() => companyTab.activeId, () => { void loadGroups(); void load() })')
assert.ok(dropped, '探针失效:负样本 1 匹配不出 watch 语句,无从判定它该红')
assert.equal(dropped.includes('filter.groupId = null'), false,
'负样本 1 失效:删掉 filter.groupId = null 还判它含 ⇒ 这条看守杀不了变异')
// ③ 负样本 2(钉位置不钉全文):token 在同一个文件里、但不在 watch 体内。
const elsewhere = watchStatement('function resetAll() { filter.groupId = null }\nwatch(() => companyTab.activeId, () => { void load() })')
assert.ok(elsewhere, '探针失效:负样本 2 匹配不出 watch 语句,无从判定它该红')
assert.equal(elsewhere.includes('filter.groupId = null'), false,
'负样本 2 失效:watch 体外的 filter.groupId = null 被算成了体内 ⇒ 判据退化成"文件里出现过就行"')
const source = stripComments(readSource('src/pages/shop/ShopManagePage.vue'))
const matches = source.match(new RegExp(WATCH_ACTIVE_ID.source, 'g')) ?? []
assert.equal(matches.length, 1,
`ShopManagePage 里匹配到 ${matches.length} 条 watch(() => companyTab.activeId, () => {…}):`
+ '0 条 = watch 换了写法(判据失明)或被拆成多条,都得先核对再动判据')
assert.ok(matches[0].includes('filter.groupId = null'),
'切公司没清掉上一家选中的分组:列表会被一个在新一家根本不存在的 groupId 筛成空页'
+ '(tab 看起来"坏了",而请求、后端、权限三处都没错,最难查的那一型)')
// 同链前提(反向钉不许独自成立):这一页的两个发送口仍然在发 company_id。
// 哪天发送口退回不带参,上面这条 watch 看守就变成"清了一个没人用的筛选项"——前提必须一起在场。
const api = stripComments(read('src/pages/shop/shop-manage-api.ts'))
assert.ok(/company_id\s*=\s*params\.companyId\b/.test(api) && /company_id\s*:\s*companyId\b/.test(api),
'店铺管理的两个发送口(列表 + 分组下拉)不再带 company_id:上面那条 watch 看守的前提没了')
})
test('两张清单不许重叠:超管专属页不可能同时是按公司看数据的页', () => {
const scoped = new Set(COMPANY_SCOPED_PAGES.map((p) => p.menuKey))
for (const key of SUPER_ADMIN_ONLY_MENU_KEYS) assert.equal(scoped.has(key), false)