test(公司tab): 两把尺子补洞——范围"算过"要"用出去",company_id 要写明取值口
评审用变异证明现有护栏各有半个洞,而这两个洞接下来会被 Task 9–12 六页照抄,
所以在本任务收口,不留到批次尾。
- G2 断言 C:handler 里 `readScope(` 的结果必须先赋给变量、再出现在另一条方法调用的
实参列表里。原来只断"体内出现了 readScope(",于是 `listHistory(…, scoped)` 改成
`listHistory(…, null)` 时 20 支用例一支不红(控制方实测 rc=0)——范围算了又丢掉,
页面照样看全量。`if (scoped != null) throw` 这类装饰不算接住。带 2 支负探针 + 1 支
正探针 + 第二形探针,分母三条自检(取样集非空 / 走完两步的支数为正 / 射程必须覆盖
已接线的两页),不许恒绿也不许恒红。
- G1 取值口登记表:`/company_id\s*[:=]/` 对"右半边从哪个对象读"是瞎的,
`= normalized.companyId` 与 baseline 缺口清单逐字相同(normalizeHistoryParams 是
白名单构造,运行时恒 undefined)。每页登记该页 api 函数自己的入参形状;8 页全覆盖、
缺条目红、接了线没登记同样红——没有"未登记就退回宽松判据"的默认分支。
- helpers.readSource 归一行尾:仓库 autocrlf=true,新检出是 CRLF 而源码 blob 是 LF,
`[\s\S]{0,N}` 这类有界窗口会被多出来的 `\r` 挤红——同一份 company-tab store
(LF 3565B / CRLF 3629B,内容等价)在干净检出树上多红一条无关用例。归一后实测
CRLF 树回到 6/5/1(只剩批次那条刻意留红)。
读数:后端全量 3663/0/0 Skipped 7 BUILD SUCCESS(最终字节亲跑);定向 9/0,变异
`scoped`→`null` 后 1 Failures 红在 CompanyIdParamGoesThroughReadScopeTest:393;
前端全量 1726/1725/1、`vue-tsc` rc=0;`= normalized.companyId`(连守卫一起换的静默变体)
实测红且点名 admin_history。产品码一支未动。
This commit is contained in:
@@ -7,9 +7,70 @@ import { COMPANY_SCOPED_PAGES, SUPER_ADMIN_ONLY_MENU_KEYS } from '../src/config/
|
||||
|
||||
const read = (p: string) => {
|
||||
assert.ok(existsSync(p), `护栏读不到 ${p}:api 文件改名了,清单必须同步(别把用例改成"不存在就跳过")`)
|
||||
return readFileSync(p, 'utf8')
|
||||
// 与 helpers.readSource 同口径归一行尾(CRLF 检出树会把有界窗口判据挤红,见 helpers 里的注释)。
|
||||
return readFileSync(p, 'utf8').replace(/\r\n/g, '\n')
|
||||
}
|
||||
|
||||
/**
|
||||
* 取值口登记表(2026-10-05 修复轮 1,复评 I-2)。上面那条正向判据原本只问「有没有把 company_id 当成查询
|
||||
* 参数下传」,`/company_id\s*[:=]/` 对**右半边从哪儿取值**是瞎的:评审把
|
||||
* `history-api.ts` 的 `query.company_id = params.companyId` 改成 `= normalized.companyId` 之后,
|
||||
* 缺口清单与 baseline **逐字相同**(`admin_history` 都不出现)、`vue-tsc` 也不红
|
||||
* (`normalizeHistoryParams` 的返回类型就是 `HistoryListParams`,本轮刚给它加了 `companyId?: number | null`,
|
||||
* 所以 `normalized.companyId` 类型合法、运行时恒 `undefined`)。tab 画了、请求发了、参数没有——
|
||||
* 这正是本批次要杀的那类静默失效,尺子却看不见。
|
||||
* <p>于是每页登记一条"company_id 右侧的根标识符**必须**是该页 api 函数自己的入参"的形状:
|
||||
* `shape` 为 `RegExp` 时,对**剥完注释的源码**求值,不匹配即红并点名文件;`shape` 为 `null` 是
|
||||
* "这一页还没接线"的显式声明(今天 6 页如此,它们本来就在缺口清单里)。
|
||||
* <p>两道不留缝:① `COMPANY_SCOPED_PAGES` 里每一页都必须在表里有条目,缺条目直接红;
|
||||
* ② 一旦某个文件真的出现了 `company_id` 下传而它的 `shape` 还是 `null`,同样红——
|
||||
* 所以"新页接线时顺手不改登记表"过不去,也**没有**"没登记就退回宽松判据"的默认分支。
|
||||
*/
|
||||
type CompanyIdPin = { readonly file: string; readonly shape: RegExp | null; readonly note: string }
|
||||
|
||||
const COMPANY_ID_SOURCE_PINS: Readonly<Record<string, readonly CompanyIdPin[]>> = {
|
||||
admin_history: [
|
||||
{
|
||||
file: 'src/pages/records/history-api.ts',
|
||||
// fetchHistoryList(params: Partial<HistoryListParams>):唯一入参对象是 params(history-api.ts:15 的形状)。
|
||||
shape: /company_id\s*=\s*params\.companyId\b/,
|
||||
note: 'normalizeHistoryParams 是白名单构造(只点名 page/pageSize/userId/timeStart/timeEnd),从 normalized 读 companyId 恒 undefined',
|
||||
},
|
||||
],
|
||||
admin_image_video_tasks: [
|
||||
{
|
||||
file: 'src/pages/tasks/image-video-api.ts',
|
||||
// fetchImageVideoTasks(filter, page, pageSize, companyId):公司值的入参就是第 4 个形参本身(:19 的形状),
|
||||
// 不是 filter 的字段——toImageVideoQuery 同样是白名单构造。
|
||||
shape: /company_id\s*=\s*companyId\b/,
|
||||
note: 'filter 走 toImageVideoQuery 白名单构造,公司值只能落在 companyId 形参上',
|
||||
},
|
||||
],
|
||||
admin_task_center: [
|
||||
{ file: 'src/api/task-center.ts', shape: null, note: 'Task 9 未接线(已在缺口清单里);谁接线谁把 null 换成本函数真实取值口' },
|
||||
{ file: 'src/pages/task-center/task-center-model.ts', shape: null, note: '同上:这一页有两个取数模块,两个都得登记' },
|
||||
],
|
||||
admin_user_secret_usage: [
|
||||
{ file: 'src/api/user-secret-usage.ts', shape: null, note: 'Task 10 未接线(已在缺口清单里)' },
|
||||
],
|
||||
admin_user_secrets: [
|
||||
{ file: 'src/api/user-secrets.ts', shape: null, note: 'Task 10 未接线(已在缺口清单里)' },
|
||||
],
|
||||
admin_device_logs: [
|
||||
{ file: 'src/api/device-logs.ts', shape: null, note: 'Task 10 未接线(已在缺口清单里)' },
|
||||
],
|
||||
admin_group_manage: [
|
||||
{ file: 'src/pages/account/shop-group-api.ts', shape: null, note: 'Task 11 未接线(已在缺口清单里)' },
|
||||
],
|
||||
admin_shop_manage: [
|
||||
{ file: 'src/pages/shop/shop-manage-api.ts', shape: null, note: 'Task 11 未接线(已在缺口清单里)' },
|
||||
],
|
||||
}
|
||||
|
||||
/** 严格判据的分母由本轮实扫得出(修完不许恒绿也不许恒红):求值了几条 shape、其中几条通过。 */
|
||||
let strictPinsEvaluated = 0
|
||||
let strictPinsPassed = 0
|
||||
|
||||
test('正向:声明 companyScoped 的页,其 api 文件必须真的带 company_id,页面组件必须 watch activeId', () => {
|
||||
// 循环里**收集**、循环后一次性断言:Task 8-12 是 5 个任务共用这把尺子,fail-fast 时做完自己那页的同事
|
||||
// 仍然只看到一句指向**别人页**的红(今天只报 src/api/task-center.ts),判断不出本页是否已收敛。
|
||||
@@ -29,6 +90,31 @@ test('正向:声明 companyScoped 的页,其 api 文件必须真的带 company
|
||||
gaps.push(`${file} 没把 company_id 当成查询参数下传`)
|
||||
}
|
||||
}
|
||||
// 取值口登记(复评 I-2):光"把 company_id 塞进查询对象"不够,右半边必须取自**本函数自己的入参**。
|
||||
for (const pin of COMPANY_ID_SOURCE_PINS[page.menuKey] ?? []) {
|
||||
if (!page.apiFiles.includes(pin.file)) {
|
||||
gaps.push(`${pin.file} 登记在 ${page.menuKey} 名下,但 COMPANY_SCOPED_PAGES 的 apiFiles 里没有它:登记表与清单两处口径打架`)
|
||||
continue
|
||||
}
|
||||
const src = stripComments(read(pin.file))
|
||||
const wired = /company_id\s*[:=]/.test(src)
|
||||
if (pin.shape === null) {
|
||||
// 没登记取值口却已经下传了参数 = 这一页的取值口径没人看守(洞就是这么留下的)。
|
||||
if (wired) gaps.push(`${pin.file} 已经把 company_id 当下传参数了,登记表里 shape 却还是 null —— 把它换成"company_id 右侧 = 本函数入参"的正则`)
|
||||
continue
|
||||
}
|
||||
strictPinsEvaluated++
|
||||
if (!wired) {
|
||||
gaps.push(`${pin.file} 登记了取值口 ${pin.shape},文件里却一个 company_id 都没下传:登记表与代码漂移(要么接线回来,要么把 shape 改回 null)`)
|
||||
continue
|
||||
}
|
||||
if (!pin.shape.test(src)) {
|
||||
gaps.push(`${pin.file} 的 company_id 右半边不是本函数入参(登记表要求 ${pin.shape};${pin.note})`
|
||||
+ '—— tab 画了、请求发了、参数没有;编译器不一定看得见(normalizeHistoryParams 的返回类型里就有这个字段)')
|
||||
continue
|
||||
}
|
||||
strictPinsPassed++
|
||||
}
|
||||
for (const file of page.pageFiles) {
|
||||
// 与 api 侧同口径先剥注释(约束 6:注释里出现字面量不算接线)——否则一句
|
||||
// `// 这里读 companyTab.requestCompanyId` 就能同时骗过下面两条断言。
|
||||
@@ -43,8 +129,23 @@ test('正向:声明 companyScoped 的页,其 api 文件必须真的带 company
|
||||
gaps.push(`${file} 没读 companyTab.requestCompanyId(页面取公司值的唯一出口)`)
|
||||
}
|
||||
}
|
||||
// 覆盖性自检:清单里每一页都必须在登记表里有条目。**没有**"没登记就退回宽松判据"这条路。
|
||||
if (!(page.menuKey in COMPANY_ID_SOURCE_PINS)) {
|
||||
gaps.push(`${page.menuKey} 在 COMPANY_ID_SOURCE_PINS 里没有条目:接线的页必须登记取值口,护栏不许留默认分支`)
|
||||
}
|
||||
if (gaps.length) problems.push(`${page.menuKey}:${gaps.join(';')}`)
|
||||
}
|
||||
// 正样本自检:求值了却一条都没通过 ⇒ 严格判据恒红(或形状不认),红在缺口清单里、不抢本页的诊断信息。
|
||||
if (strictPinsEvaluated > 0 && strictPinsPassed === 0) {
|
||||
problems.push(`(取值口取样自检)shape 求值了 ${strictPinsEvaluated} 条、通过 0 条 —— 判据恒红或形状不认,不可信`)
|
||||
}
|
||||
// 严格半支的取样自检:登记表是空的、或一页都没走完 shape 求值 ⇒ 这半支等于没写,用例自己红。
|
||||
assert.ok(strictPinsEvaluated >= 2,
|
||||
`取值口严格判据本轮只求值了 ${strictPinsEvaluated} 条(登记表里 admin_history / admin_image_video_tasks 两条 shape 都在,`
|
||||
+ `求值数不可能低于已接线页数)——判据空转,normalized-vs-params 那个洞又没人看守了`)
|
||||
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 了:严格判据对这两页不再起作用(正样本归零)')
|
||||
assert.deepEqual(problems, [],
|
||||
`公司 tab 接线缺口(逐页列全;Task 8-12 补齐后这支自动收敛,本轮刻意留红):\n`
|
||||
+ problems.map((p) => ` - ${p}`).join('\n'))
|
||||
|
||||
@@ -6,9 +6,17 @@ const SRC = join(ROOT, 'src')
|
||||
const EXTENSIONS = ['', '.ts', '.tsx', '.vue', '.js', '.json']
|
||||
const INDEX_CANDIDATES = ['/index.ts', '/index.tsx', '/index.vue', '/index.js']
|
||||
|
||||
/** 读取工程内源码文件(相对工程根)。 */
|
||||
/**
|
||||
* 读取工程内源码文件(相对工程根)。
|
||||
*
|
||||
* 行尾一律归一成 LF:仓库 `core.autocrlf=true`,新检出的工作树是 CRLF 而源码 blob 是 LF,
|
||||
* 而本仓多数判据是 `[\s\S]{0,N}` 这类**有界窗口**(例如 company-tab-wiring 里 catch→this.error→throw
|
||||
* 那记 420 字符的钉子)。每个换行多背一个 `\r` 就把窗口预算吃掉一截——实测同一份 `src/stores/company-tab.ts`
|
||||
* (内容逐字节等价,主树 LF 3565 B / 新检出 CRLF 3629 B)在干净检出树上会多红一条与本任务无关的用例。
|
||||
* 归一之后判据只取决于内容,不取决于在哪台机器、哪个 worktree 里跑。
|
||||
*/
|
||||
export function readSource(rel: string): string {
|
||||
return readFileSync(join(ROOT, rel), 'utf8')
|
||||
return readFileSync(join(ROOT, rel), 'utf8').replace(/\r\n/g, '\n')
|
||||
}
|
||||
|
||||
/** 统计非重叠子串出现次数(幂等、只读)。 */
|
||||
|
||||
Reference in New Issue
Block a user