265f31681f
评审用变异证明现有护栏各有半个洞,而这两个洞接下来会被 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。产品码一支未动。
72 lines
2.8 KiB
TypeScript
72 lines
2.8 KiB
TypeScript
import { existsSync, readFileSync } from 'node:fs'
|
||
import { dirname, join, resolve } from 'node:path'
|
||
|
||
const ROOT = process.cwd()
|
||
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').replace(/\r\n/g, '\n')
|
||
}
|
||
|
||
/** 统计非重叠子串出现次数(幂等、只读)。 */
|
||
export function occurrences(text: string, token: string): number {
|
||
if (!token) return 0
|
||
let count = 0
|
||
let index = text.indexOf(token)
|
||
while (index !== -1) {
|
||
count += 1
|
||
index = text.indexOf(token, index + token.length)
|
||
}
|
||
return count
|
||
}
|
||
|
||
/** 从源码里抓出所有 @/ 别名 import 说明符(含 import type)。 */
|
||
export function aliasImports(source: string): string[] {
|
||
const specs = new Set<string>()
|
||
const re = /(?:import\s+type\s+)?[^'"]*from\s*['"](@\/[^'"]+)['"]/g
|
||
let match: RegExpExecArray | null
|
||
while ((match = re.exec(source))) specs.add(match[1])
|
||
// 处理动态 import('@/...') 与直接裸 @/ 引用
|
||
const dyn = /(?:import|import\s*\(\s*)['"](@\/[^'"]+)['"]/g
|
||
while ((match = dyn.exec(source))) specs.add(match[1])
|
||
return [...specs]
|
||
}
|
||
|
||
/** 把 import 说明符解析为存在的模块文件;解析不到返回 null(含可操作路径)。 */
|
||
export function resolveModuleSpec(spec: string, fromRel: string): string | null {
|
||
let base: string
|
||
if (spec.startsWith('@/')) {
|
||
base = join(SRC, spec.slice(2))
|
||
} else {
|
||
base = resolve(dirname(join(ROOT, fromRel)), spec)
|
||
}
|
||
for (const ext of EXTENSIONS) {
|
||
if (existsSync(base + ext)) return base + ext
|
||
}
|
||
for (const idx of INDEX_CANDIDATES) {
|
||
if (existsSync(base + idx)) return base + idx
|
||
}
|
||
return null
|
||
}
|
||
|
||
/** 校验一个源文件的所有 @/ import 都能解析;返回缺失清单(空 = 全部可解析)。 */
|
||
export function missingImports(rel: string): string[] {
|
||
const source = readSource(rel)
|
||
const missing: string[] = []
|
||
for (const spec of aliasImports(source)) {
|
||
if (!resolveModuleSpec(spec, rel)) missing.push(`${rel} 无法解析 import: ${spec}`)
|
||
}
|
||
return missing
|
||
}
|