test(公司tab): Task 10 修复轮 1——G1 把"5 处发送口"拆成 5 条钉,订正两处"声称保护而不保护"的注释
评审 I-1:G1 原本用 2 条文件级 shape 钉这一页的 5 处发送口,而判据是整文件 RegExp.test、不数次数 ⇒ 删掉任何一处(含 brief 点名的 `fetchTaskCenterTaskDetail` 少带 `company_id`)双双仍为 true。 `vue-tsc` 也救不了:tsconfig 只开 strict、没开 noUnusedParameters ⇒ 删一行留个没人用的形参,编译器不响。 现按 `admin_shop_manage` 的先例拆成 5 条"一函数一钉"(`function <fn>(…)` 锚 + 320 字符实测有界窗口), 另按路线 ② 补一条"逐文件钉数 == 发送口条数"闸门(api=3 / model=2,用 `occurrences()`)⇒ 加第六处发送口而没钉也红。 M-2:watch 体看守原把锚写死在 `ShopManagePage.vue` 的 `filter.groupId = null` 上,同形不同页 ⇒ 抽成 (file, token) 两对,本任务加的 `TaskCenterBoardPage.vue` 那条 `filter.shop = ''` 从此有尺子。 页码复位刻意没钉(判据收在能钉住的那一档,取舍写在 :309-312)。 I-2:`AdminTaskCenterController:38-44` 的类 javadoc 原话"抽走出口行即 A/C/D 三只都红"被它自己的 MUT-A 读数否证: 真相是 1 红 2 不响(A 红且 fail-fast 只点名 /overview;C 的门槛 :485 因体内不再出现 readScope( 而根本不评估; D 因 hasScopeCall() 认 resolveScope( 且 companyId 在其实参表里而绿)。改成实测口径,代码结构零改动。 I-3:`legacySuperAdminIsNotLeftUnfiltered` 的 .as 消息许了"两把尺子单边改了红这条",但它只碰 service 侧 ⇒ 对同一 fixture 补一行 `DeviceSessionPolicy.resolveRole(...)` 断言,两把尺子同框(既有 8 支单参用例方向未动)。 M-4:一参委托 `resolve(Long operatorId)` 补一行 javadoc 点名它背后挂着的 8 个测试调用点(裁决 3 保留,没删)。 变异自证(worktree D:/tmp-wt-t10f @aef79069):前端 12 轮——两轮不注入对照 7/7 rc=0,M1–M5 各删一处发送口全 KILLED (红消息点名"发送口 N/5"),M6/M7 各红 1 条落在 watch 体那对,M8/M9 用 `shop-manage-api.ts` 补的第三支文件各红 2 条, M10 删表一行红在补集闸门;`vue-tsc --noEmit` rc=0。后端 4 轮——B0 15/0 rc=0;B1-mutA guard 2/1 红在 A、service 13/0; B2-mutL1 service 13/2;B3-mutL2 13/1 只红在新补那行、guard 2/0。每轮注入前读进内存的字节原样写回并核 md5。 两支 .java 的改动逐行验过是非注释行零改动(git diff -U0 滤注释后为空)。
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import test from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
import { existsSync, readFileSync, readdirSync } from 'node:fs'
|
||||
import { readSource } from './helpers.ts'
|
||||
import { occurrences, readSource } from './helpers.ts'
|
||||
import { adminPages } from '../src/router/routes.ts'
|
||||
import { COMPANY_SCOPED_PAGES, SUPER_ADMIN_ONLY_MENU_KEYS } from '../src/config/company-scope.ts'
|
||||
|
||||
@@ -29,6 +29,47 @@ const read = (p: string) => {
|
||||
*/
|
||||
type CompanyIdPin = { readonly file: string; readonly shape: RegExp | null; readonly note: string }
|
||||
|
||||
/** 任务看板这一页发送口的共同形状:五处都是「函数自己那行把 companyId 塞进 query」(缩进两格,逐字相同)。 */
|
||||
const TASK_CENTER_SEND_LINE = 'if (companyId != null) query.company_id = companyId'
|
||||
|
||||
/** 一条钉 = 一个发送口:窗口上界。实测「函数开行 → 它自己那行」的距离是 154/147/196/238/244,
|
||||
* 「函数开行 → 下一个发送口那行」的距离是 471/726/(无)/877/(无)⇒ 320 既够得着自己的行,
|
||||
* 又够不到隔壁:删掉任一处,那条 shape 就匹配不出(不是"文件里还有别人在发"就算过)。 */
|
||||
const TASK_CENTER_WINDOW = 320
|
||||
|
||||
/**
|
||||
* 这一页的 5 处 `company_id` 发送口(2026-10-05 修复轮 1,复评 I-1)。
|
||||
*
|
||||
* <p>为什么从 2 条文件级钉拆成 5 条:`shape` 的求值是整文件 `RegExp.test`(不数次数),
|
||||
* 评审实测「删掉 5 处里的任何一处」在两条文件级钉下**双双仍为 true**——包括 brief
|
||||
* `task-10-brief.md:14` 点名的那一处(`fetchTaskCenterTaskDetail` 少带参数 ⇒ 超管在别家 tab 下按
|
||||
* taskNo 读别家详情照样 200,这一页的护栏恰好全落在前端)。`vue-tsc` 也救不了:tsconfig 没开
|
||||
* `noUnusedParameters`,删了塞键那一行、留一个没人用的形参,编译器不响。</p>
|
||||
*
|
||||
* <p>选「拆条」而不是「计数」(`occurrences()` 数 api=3 / model=2):计数不回答「哪三处」,
|
||||
* 把一处重复写三遍、另一处删掉,计数照样绿;函数名锚 + 有界窗口才把判据绑到发送口自己的身份上。
|
||||
* 形状照 `admin_shop_manage` 的先例(同一个文件两条 pin,「两条各管一处取值口,不许合成一条 alternation」)。</p>
|
||||
*
|
||||
* <p>`shape` 与取样样本同源于这张表(都由 fn/window 现算),不会出现「钉改了、自检还测旧串」的漂移。</p>
|
||||
*/
|
||||
const TASK_CENTER_SEND_POINTS: ReadonlyArray<{ readonly file: string; readonly fn: string; readonly title: string }> = [
|
||||
{ file: 'src/api/task-center.ts', fn: 'fetchTaskCenterOverview', title: 'GET /overview 汇总卡' },
|
||||
{ file: 'src/api/task-center.ts', fn: 'fetchTaskCenterShopOptions', title: 'GET /shop-options 店铺候选' },
|
||||
{ file: 'src/api/task-center.ts', fn: 'fetchTaskCenterTaskDetail', title: 'GET /tasks/detail 详情(brief 点名那一处)' },
|
||||
{ file: 'src/pages/task-center/task-center-model.ts', fn: 'buildTaskQuery', title: '任务列表 query 构造器' },
|
||||
{ file: 'src/pages/task-center/task-center-model.ts', fn: 'buildVariantQuery', title: '变体采集 query 构造器' },
|
||||
]
|
||||
|
||||
/** 一个发送口一条钉:锚在自己的函数开行上,要求窗口内出现「塞键」那一行。 */
|
||||
function sendPointShape(fn: string): RegExp {
|
||||
return new RegExp(`function ${fn}\\([\\s\\S]{0,${TASK_CENTER_WINDOW}}company_id\\s*=\\s*companyId\\b`)
|
||||
}
|
||||
|
||||
/** 正样本用的迷你源码:函数开行 + 它自己那行塞键(缩进、形状逐字照抄真实发送口)。 */
|
||||
function sendPointCompliant(fn: string): string {
|
||||
return `function ${fn}(companyId?: number | null) {\n const query: QueryParams = {}\n ${TASK_CENTER_SEND_LINE}\n`
|
||||
}
|
||||
|
||||
const COMPANY_ID_SOURCE_PINS: Readonly<Record<string, readonly CompanyIdPin[]>> = {
|
||||
admin_history: [
|
||||
{
|
||||
@@ -47,23 +88,15 @@ const COMPANY_ID_SOURCE_PINS: Readonly<Record<string, readonly CompanyIdPin[]>>
|
||||
note: 'filter 走 toImageVideoQuery 白名单构造,公司值只能落在 companyId 形参上',
|
||||
},
|
||||
],
|
||||
admin_task_center: [
|
||||
{
|
||||
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',
|
||||
},
|
||||
],
|
||||
// 五个发送口五条钉(一函数一条),不是一条文件级钉数五处:判据形状见 TASK_CENTER_SEND_POINTS 的举证。
|
||||
// 这一页也不许套 Task 8 的 `params.companyId` 形——api 侧 `tasks`/`variant-tasks` 是 `params: QueryParams`
|
||||
// 直传、没有 params.companyId 这个口,公司键由 model 那两个 builder 补进同一个对象。
|
||||
admin_task_center: TASK_CENTER_SEND_POINTS.map((p, i) => ({
|
||||
file: p.file,
|
||||
shape: sendPointShape(p.fn),
|
||||
note: `发送口 ${i + 1}/5 ${p.title}(${p.fn}):null 由发送口自己丢(不依赖 axios 丢 null),`
|
||||
+ '右半边必须是本函数自己的形参 companyId;删掉这一处的塞键那一行就红在这一条上',
|
||||
})),
|
||||
admin_user_secret_usage: [
|
||||
{
|
||||
file: 'src/api/user-secret-usage.ts',
|
||||
@@ -192,6 +225,46 @@ test('正向:声明 companyScoped 的页,其 api 文件必须真的带 company
|
||||
assert.ok(COMPANY_ID_SOURCE_PINS.admin_history.some((p) => p.shape !== null)
|
||||
&& COMPANY_ID_SOURCE_PINS.admin_image_video_tasks.some((p) => p.shape !== null),
|
||||
'Task 8 已接线的两页在登记表里的 shape 被改回 null 了:严格判据对这两页不再起作用(正样本归零)')
|
||||
|
||||
// —— I-1 拆条那 5 条钉的取样自检(全局约束 15:反向钉必须自带同支正样本,
|
||||
// 不许让另一支用例替我证明"这串本来就会被匹配到";登记表条目被顺手删成 4 条也红在这里)。
|
||||
// ⚠ 身份要说清:下面这几条是对**字面量字符串**求值的探针,只证明判据形状没写坏
|
||||
// (正样本匹配得出 ⇒ 不恒红;窗口外的负样本不匹配 ⇒ 窗口真有界,删一处不会靠隔壁过关),
|
||||
// 任何代码注入都不会让它们红。真覆盖 = 上面 loop 里那 5 条 shape 对真实文件的求值 + 变异自证。
|
||||
assert.equal(COMPANY_ID_SOURCE_PINS.admin_task_center.length, TASK_CENTER_SEND_POINTS.length,
|
||||
`任务看板登记了 ${TASK_CENTER_SEND_POINTS.length} 处发送口,登记表里却只有 ${COMPANY_ID_SOURCE_PINS.admin_task_center.length} 条钉 —— 有一处没人看守`)
|
||||
for (const p of TASK_CENTER_SEND_POINTS) {
|
||||
const shape = sendPointShape(p.fn)
|
||||
const compliant = sendPointCompliant(p.fn)
|
||||
assert.ok(shape.test(compliant),
|
||||
`(拆条取样自检·正样本)${p.fn} 的合规样本都匹配不出 ${shape} ⇒ 这条钉恒红,删没删发送口都会红,等于没看守`)
|
||||
const deleted = compliant.replace(` ${TASK_CENTER_SEND_LINE}\n`, '')
|
||||
+ ' '.repeat(TASK_CENTER_WINDOW + 1) + TASK_CENTER_SEND_LINE
|
||||
assert.equal(shape.test(deleted), false,
|
||||
`(拆条取样自检·负样本)${p.fn} 删掉自己那一行、只剩窗口外的隔壁发送口却仍然匹配 ⇒ 窗口够得到了隔壁,删一处不会红`)
|
||||
}
|
||||
|
||||
// 拆条的补集(复评 I-1 的另一半):一条钉管一个发送口 ⇒ 每个文件登记的钉数必须等于该文件里发送口的实际条数。
|
||||
// 上面那 5 条 shape 杀的是「删源码里的塞键那一行」(变异自证 M1–M5 就是这一形);
|
||||
// 这一条杀的是「把 TASK_CENTER_SEND_POINTS 删剩 4 行」——少一条钉就等于少一处看守,而 5 条 shape 谁都不会红。
|
||||
// 路线 ②(occurrences 计数)在这里只当"钉数与发送口条数对平"的闸门,不当"是哪一处"的判据:
|
||||
// 计数回答不了"哪三处"(把一处重复写三遍、另一处删掉,计数照样对平),所以主判据仍是路线 ① 的函数名锚 + 有界窗口。
|
||||
const pinnedPerFile = new Map<string, number>()
|
||||
for (const p of TASK_CENTER_SEND_POINTS) {
|
||||
pinnedPerFile.set(p.file, (pinnedPerFile.get(p.file) ?? 0) + 1)
|
||||
}
|
||||
assert.equal(pinnedPerFile.size, 2,
|
||||
`发送口表应当只覆盖 api + model 这 2 个文件,现在却有 ${pinnedPerFile.size} 个 —— 表被改形状了,对平判据失去分母`)
|
||||
for (const [file, pinned] of pinnedPerFile) {
|
||||
const actual = occurrences(stripComments(read(file)), TASK_CENTER_SEND_LINE)
|
||||
assert.equal(pinned, actual,
|
||||
`${file} 里实际有 ${actual} 处「${TASK_CENTER_SEND_LINE}」,登记表却只钉了 ${pinned} 条 —— `
|
||||
+ '有一处发送口脱管(一函数一钉:钉数必须与该文件的发送口条数逐文件对平)')
|
||||
}
|
||||
// 同支正样本(全局约束 15:计数判据不许"0 == 0 也算对平"就当自己成立):字面样本里有两条,occurrences 必须数得出 2。
|
||||
assert.equal(occurrences(sendPointCompliant('f') + sendPointCompliant('g'), TASK_CENTER_SEND_LINE), 2,
|
||||
'(计数取样自检·正样本)occurrences 连两条字面发送口都数不出来 ⇒ 上面那条逐文件对平恒真,等于没看守')
|
||||
|
||||
assert.deepEqual(problems, [],
|
||||
`公司 tab 接线缺口(逐页列全;批次 1 的 8 页到 Task 10 已全部接线,谁再退回未接线就红在这里):\n`
|
||||
+ problems.map((p) => ` - ${p}`).join('\n'))
|
||||
@@ -211,62 +284,118 @@ test('反向:把 company_id 当查询参数用的取数模块必须被清单
|
||||
})
|
||||
|
||||
/**
|
||||
* 切公司必须把「上一家选中的分组」一起清掉(TaskList #22,控制方 2026-10-05 点名)。
|
||||
* 切公司必须把「上一家选中的筛选项」一起清掉(TaskList #22,控制方 2026-10-05 点名;
|
||||
* 2026-10-05 修复轮 1 复评 M-2 把它抽成 (file, token) 两对,见下面 WATCH_BODY_PINS)。
|
||||
*
|
||||
* <p>为什么单独钉这一处:`filter.groupId` 是**用户选中的值**,不是每次请求重算的。切到另一家公司后,
|
||||
* 上一家选中的 groupId 在新一家的可见集里根本不存在,列表于是被 `groupId=` 筛成空页——症状是
|
||||
* 「tab 一切页面就白」,而请求、后端、权限三处全对。G1 的 pageFiles 只断「watch 了 activeId」,
|
||||
* <p>为什么单独钉 watch 体:体里那些赋值是**用户选中的值**,不是每次请求重算的。切到另一家公司后,
|
||||
* 上一家选中的 `filter.groupId` / `filter.shop` 在新一家的可见集与候选字典里根本不存在,列表于是被
|
||||
* 一个不存在的值筛成空页——症状是「tab 一切页面就白」,而请求、后端、权限三处全对。
|
||||
* G1 的 pageFiles 只断「watch 了 activeId」与「读过 requestCompanyId」(正向那条用例的末尾两行),
|
||||
* 看不见 watch 体里到底做了什么,所以体内容必须单独钉。</p>
|
||||
*
|
||||
* <p>M-2 的洞:这条看守原本把锚写死在 `ShopManagePage.vue:108` 的 `filter.groupId = null` 上,
|
||||
* 同形不同页——任务看板页自己那条 `filter.shop = ''`(裁决 1 加的,`TaskCenterBoardPage.vue:176`)
|
||||
* 当时没有任何看守:删掉那一行时 G1 只断「存在 watch」、G2 不扫 `.vue`、后端用例不涉及前端文本 ⇒ 全绿,
|
||||
* 症状回到裁决 1 想避免的那一型。</p>
|
||||
*
|
||||
* <p>判据形状:从 `watch(() => companyTab.activeId, …)` 那**一条语句**取文本(正则在第一个
|
||||
* `}` + `)` 处收口 ⇒ 单层,体内再嵌对象字面量会截早;这一页今天没有那种写法,由下面的取样自检兜着)。
|
||||
* 反向钉与正样本同支(全局约束 15,三条前提不成立就是探针失效、当场红,不许静默空跑):
|
||||
* `}` + `)` 处收口 ⇒ 单层,体内再嵌对象字面量会截早;两页今天都没有那种写法,由下面的取样自检兜着)。
|
||||
* 反向钉与正样本同支(全局约束 15,三条前提不成立就是探针失效、当场红,不许静默空跑),**每一对**都各跑一遍:
|
||||
* ① 合规样本必须匹配得出且含两把 token ⇒ 判据不恒红;
|
||||
* ② 删掉 `filter.groupId = null` 的样本必须不含 ⇒ 判据能红(变异自证走的就是这一条);
|
||||
* ② 删掉那一句的样本必须不含 ⇒ 判据能红(变异自证走的就是这一条);
|
||||
* ③ 把同一串 token 挪到 watch 之外的样本必须不含 ⇒ 钉的是**位置**,不是「文件里出现过」。
|
||||
* 末尾还配了一条同链前提:这一页的两个发送口仍在发 `company_id`,清组才有意义。</p>
|
||||
* 每对末尾还配了一条同链前提:那一页的发送口仍在发 `company_id`,清筛选项才有意义。</p>
|
||||
*
|
||||
* <p>刻意没钉的部分(判据收在"钉得住"那一档):`taskPage.value = 1` / `variantPage.value = 1`——
|
||||
* `= 1` 这一形在 watch 体外满篇都是(search/changeTaskPage/resetFilter 都写它),
|
||||
* 用 `matches[0].includes('taskPage.value = 1')` 只会把判据做成"这一行在不在体内"的第二个 filter.shop,
|
||||
* 而页码回 1 的红利是观感不是越权,本轮不扩围。</p>
|
||||
*/
|
||||
const WATCH_ACTIVE_ID = /watch\(\(\)\s*=>\s*companyTab\.activeId\s*,\s*\(\)\s*=>\s*\{([\s\S]*?)\}\s*\)/
|
||||
|
||||
/**
|
||||
* (文件, 必须出现在 watch 体内的赋值) 两对,同一条 test 里逐对钉。
|
||||
* `premise` 是这一对的反向钉前提:这一页的发送口今天还在发 `company_id`,清筛选项才有意义;
|
||||
* 哪天发送口退回不带参,watch 看守就变成"清了一个没人用的筛选项",必须一起红。
|
||||
*/
|
||||
const WATCH_BODY_PINS: ReadonlyArray<{
|
||||
readonly file: string
|
||||
readonly token: string
|
||||
readonly why: string
|
||||
readonly premise: ReadonlyArray<{ readonly file: string; readonly shapes: readonly RegExp[] }>
|
||||
}> = [
|
||||
{
|
||||
file: 'src/pages/shop/ShopManagePage.vue',
|
||||
token: 'filter.groupId = null',
|
||||
why: '上一家选中的 groupId 在新一家的可见集里根本不存在,列表会被它筛成空页',
|
||||
premise: [
|
||||
{
|
||||
file: 'src/pages/shop/shop-manage-api.ts',
|
||||
shapes: [/company_id\s*=\s*params\.companyId\b/, /company_id\s*:\s*companyId\b/],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
file: 'src/pages/task-center/TaskCenterBoardPage.vue',
|
||||
token: "filter.shop = ''",
|
||||
why: 'shop 的候选字典 /shop-options 现在按公司下传,上一家选中的店铺名在新一家不存在 ⇒ 切 tab 后首屏被筛成「暂无符合条件的任务」',
|
||||
premise: [
|
||||
{ file: 'src/api/task-center.ts', shapes: [/company_id\s*=\s*companyId\b/] },
|
||||
{ file: 'src/pages/task-center/task-center-model.ts', shapes: [/company_id\s*=\s*companyId\b/] },
|
||||
],
|
||||
},
|
||||
]
|
||||
|
||||
/** 取「`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 ⇒ 下面两条断言无从判定')
|
||||
test('切公司的 watch 体:每对 (file, token) 都要在该页 watch 体内出现(店铺管理清 groupId、任务看板清 shop)', () => {
|
||||
assert.ok(WATCH_BODY_PINS.length >= 2,
|
||||
'watch 体看守被删到只剩一对 ⇒ 这一族又退回"只钉 ShopManagePage",任务看板那行 filter.shop 再次没人看守')
|
||||
const pinnedFiles = new Set(WATCH_BODY_PINS.map((pin) => pin.file))
|
||||
for (const pin of WATCH_BODY_PINS) {
|
||||
// ① 正样本(判据不恒红)——逐字就是这一页今天 watch 体里的那一行。
|
||||
const positive = watchStatement(`watch(() => companyTab.activeId, () => { ${pin.token}; void loadGroups(); void load() })`)
|
||||
assert.ok(positive, `探针失效(${pin.file}):合规样本都匹配不出 watch 语句 ⇒ 判据恒红,这条看守等于没写`)
|
||||
assert.ok(positive.includes('companyTab.activeId') && positive.includes(pin.token),
|
||||
`探针失效(${pin.file}):合规样本没同时含两把 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 还判它含 ⇒ 这条看守杀不了变异')
|
||||
// ② 负样本 1(判据能红):删掉清筛选项那一句——变异自证注入的就是这一形。
|
||||
const dropped = watchStatement('watch(() => companyTab.activeId, () => { void loadGroups(); void load() })')
|
||||
assert.ok(dropped, `探针失效(${pin.file}):负样本 1 匹配不出 watch 语句,无从判定它该红`)
|
||||
assert.equal(dropped.includes(pin.token), false,
|
||||
`负样本 1 失效(${pin.file}):删掉 ${pin.token} 还判它含 ⇒ 这条看守杀不了变异`)
|
||||
|
||||
// ③ 负样本 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 被算成了体内 ⇒ 判据退化成"文件里出现过就行"')
|
||||
// ③ 负样本 2(钉位置不钉全文):token 在同一个文件里、但不在 watch 体内。
|
||||
const elsewhere = watchStatement(`function resetAll() { ${pin.token} }\nwatch(() => companyTab.activeId, () => { void load() })`)
|
||||
assert.ok(elsewhere, `探针失效(${pin.file}):负样本 2 匹配不出 watch 语句,无从判定它该红`)
|
||||
assert.equal(elsewhere.includes(pin.token), false,
|
||||
`负样本 2 失效(${pin.file}):watch 体外的 ${pin.token} 被算成了体内 ⇒ 判据退化成"文件里出现过就行"`)
|
||||
|
||||
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 看起来"坏了",而请求、后端、权限三处都没错,最难查的那一型)')
|
||||
const source = stripComments(readSource(pin.file))
|
||||
const matches = source.match(new RegExp(WATCH_ACTIVE_ID.source, 'g')) ?? []
|
||||
assert.equal(matches.length, 1,
|
||||
`${pin.file} 里匹配到 ${matches.length} 条 watch(() => companyTab.activeId, () => {…}):`
|
||||
+ '0 条 = watch 换了写法(判据失明)或被拆成多条,都得先核对再动判据')
|
||||
assert.ok(matches[0].includes(pin.token),
|
||||
`切公司没清掉上一家选中的筛选项 ${pin.token}:${pin.why}`
|
||||
+ '(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 看守的前提没了')
|
||||
// 同链前提(反向钉不许独自成立):这一页的发送口仍然在发 company_id。
|
||||
// 哪天发送口退回不带参,上面这条 watch 看守就变成"清了一个没人用的筛选项"——前提必须一起在场。
|
||||
for (const link of pin.premise) {
|
||||
const api = stripComments(read(link.file))
|
||||
for (const shape of link.shapes) {
|
||||
assert.ok(shape.test(api),
|
||||
`${link.file} 不再带 company_id(要求 ${shape}):${pin.file} 那条 watch 看守的前提没了`)
|
||||
}
|
||||
}
|
||||
}
|
||||
// 覆盖性自检(表别被顺手删空,也别只钉上一对)。
|
||||
assert.equal(pinnedFiles.size, WATCH_BODY_PINS.length, 'WATCH_BODY_PINS 里出现了重复 file ⇒ 有一对被覆盖掉了')
|
||||
})
|
||||
|
||||
test('两张清单不许重叠:超管专属页不可能同时是按公司看数据的页', () => {
|
||||
|
||||
+6
-2
@@ -36,8 +36,12 @@ import java.util.List;
|
||||
* {@link DataReadScope#readScope} 算成员集,再交给 {@code TaskCenterScopeService.resolve} 与既有口径
|
||||
* 求交——一处收窄,五个出口天然同宽(详情走 {@code scope.visible()},用的就是同一条集合)。
|
||||
* 那一行之所以在五个 handler 里各写一遍而不是抽进私有方法:护栏
|
||||
* {@code CompanyIdParamGoesThroughReadScopeTest} 的断言 A/C/D 认的就是「handler 体内」出现过出口、
|
||||
* 结果被接住当实参传出去、且 {@code company_id} 那个值真进了出口实参列表,抽走即三只都红。</p>
|
||||
* {@code CompanyIdParamGoesThroughReadScopeTest} 的断言 A 认的是「这支 handler 体内出现过 readScope(」,
|
||||
* 抽走之后**只有 A 会红**(且因为 A 是 fail-fast,只点名第一支);C 根本不响——它的门槛就是「体内含
|
||||
* readScope(」,体内没了就连评估都不评估;D 绿——它认 {@code resolveScope(},而 {@code companyId} 正好
|
||||
* 还在那条私有委托的实参表里。所以逐字重复买到的是「A 这一记看守在每支 handler 上各站一次」,
|
||||
* 不是三重红:别把它当成「C/D 也兜着」而去试 A 拦得住之外的形状(2026-10-05 复评 I-2 订正,
|
||||
* 原话「抽走即三只都红」与 MUT-A 的实测读数 2 tests / 1 failure 不符)。</p>
|
||||
*/
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
|
||||
+1
@@ -29,6 +29,7 @@ public class TaskCenterScopeService {
|
||||
private final ShopManageGroupMapper shopManageGroupMapper;
|
||||
private final CompanyScopeSupport companyScopeSupport;
|
||||
|
||||
/** 一参委托不是死代码:main 侧零调用点(controller 只走两参),活着只因 TaskCenterScopeServiceTest 的 8 处单参调用 service.resolve(id)(:58/:73/:83/:98/:112/:124/:130/:131,行号会漂移,计数以 grep「service.resolve( 单参」= 8 为准),裁决 3 指定保留,删这一行红那 8 支用例。 */
|
||||
public ScopeContext resolve(Long operatorId) {
|
||||
return resolve(operatorId, null);
|
||||
}
|
||||
|
||||
+12
@@ -4,6 +4,7 @@ import com.nanri.aiimage.common.exception.BusinessException;
|
||||
import com.nanri.aiimage.common.mapper.AdminUserMapper;
|
||||
import com.nanri.aiimage.common.mapper.ShopManageGroupMapper;
|
||||
import com.nanri.aiimage.common.model.entity.AdminUserEntity;
|
||||
import com.nanri.aiimage.common.security.DeviceSessionPolicy;
|
||||
import com.nanri.aiimage.common.service.CompanyScopeSupport;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -163,6 +164,17 @@ class TaskCenterScopeServiceTest {
|
||||
legacy.setCreatedById(null);
|
||||
when(adminUserMapper.selectById(2L)).thenReturn(legacy);
|
||||
|
||||
// 两把尺子同框(2026-10-05 复评 I-3):这一支原本只喂 service 那一侧(TaskCenterScopeService.isSuperAdmin),
|
||||
// 而 controller 那侧认历史超管走的是 AdminAuthSupport.currentRole → DeviceSessionPolicy.resolveRole
|
||||
// (「role 为空 + isAdmin=1 + createdById 为空 ⇒ super_admin」那条推断)——单边改掉 resolveRole 时
|
||||
// 本用例一行都不碰,五个 handler 的 superAdmin 却已经恒 false(公司 tab 对他失效)。
|
||||
// 现在把**同一份 fixture** 直接喂给 resolveRole,改任何一侧都红在这一支(既有的全局钉子
|
||||
// AdminAuthSupportTest:45 / DeviceSessionPolicyTest:40 继续钉 resolveRole 本体,不是被这里替掉)。
|
||||
assertEquals("super_admin",
|
||||
DeviceSessionPolicy.resolveRole(legacy.getRole(), legacy.getIsAdmin(), legacy.getCreatedById()),
|
||||
"controller 那侧的历史超管推断(role 空 + isAdmin=1 + createdById 空)不许单边改:"
|
||||
+ "它一改,五个 handler 就不再给这个账号算公司成员集,本用例的 service 断言抓不到那一侧");
|
||||
|
||||
TaskCenterScopeService.ScopeContext scope = service.resolve(2L, List.of(31L));
|
||||
|
||||
assertFalse(scope.allUsers(), "controller 那侧认这把的是 AdminAuthSupport.currentRole→resolveRole,"
|
||||
|
||||
Reference in New Issue
Block a user