Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,55 @@
| 两个靶点变异 | 各自 KILLED |


## [Unreleased] — 2026-11-24 — `mutate.mjs` 从来没被任何门禁跑过

> 70 条变异,每条都写了「改坏后用户看到什么」—— 从上线起 `local-gate.ps1` 与 CI 里
> 都是 **0 次引用**。它存在的理由就是那次 `StatusExportsTest` 恒真断言事故,
> 结果它自己成了没人跑的东西。

### Added — `mutate.mjs --changed [<ref>]`

全量 70 条实测 **约 32 分钟**(单条 27 秒)。这个成本决定它不能进每 PR 的 CI。
`--changed` 只跑「本分支改到的源文件」对应的变异,通常只有个位数。

三个决定:

| 决定 | 理由 |
|---|---|
| 拿不到改动面时**报错退出**(exit 2) | 不能静默退化成「跑全量」(突然半小时),也不能退化成「跑 0 条」(**假绿**) |
| 命中 0 条时打印「无事可做(不是通过,也不是失败)」 | 读日志的人必须能分清「没有」与「没跑」 |
| `--list` 不再被「工作树必须干净」拦住 | 想先看清单再决定跑哪条,还得先 stash,那正好是它最该好用的时刻 |

### Added — 接进 `local-gate.ps1` 的 L3

- **不进 L1/L2**:L2 是每次提交都跑的,几分钟的变异会让它变成「大家都会跳过」的步骤。
- **不进 CI 每 PR**:同理,且 CI 里未必有 `origin/main` 的完整历史,`--changed` 会失败。
- **放 L3(发布前)**——那是唯一「值得花几分钟换确定性」的时刻。
- 标 `-Advisory`:脏树时它会自己退出,不该因此拖垮整个 gate。

### Fixed — `local-gate.ps1` 有两处调用没传 `--repo`

`check-bstats-buckets` 与 `check-reload-rebuild` 在脚本里是裸调用,而同一脚本里其余门禁都传了
`--repo $RepoRoot`。后果:`-RepoRoot <别的路径>` 时这两个仍查本仓库 —— 正是前面给它们加
`--repo` 想消除的失效模式,只是从「脚本写死」降级成了「调用方不传」。

### 踩到的一个坑(不是本项目首次,值得记)

给 L3 加步骤时,我写的**中文注释**让 PowerShell 解析器在第 313 行报「表达式或语句中有意外的
标记 `}`」。括号是平衡的、结构也对;把那段注释换成英文后 `PARSE OK`。
`local-gate.ps1` 里其它中文注释是能跑的,所以触发条件与具体字符有关(未深究)。
**实践结论**:改 `local-gate.ps1` 时,新增注释优先写英文;报「意外的 `}`」时先怀疑注释编码。

### 验证

| 项 | 结果 |
|---|---|
| `--list`(脏树) | 正常列出 70 条 |
| `--changed origin/main --list` | 「改动 2 个文件,命中 0 / 70」+ 明确的「无事可做」 |
| `local-gate.ps1 -L1` | **13/13 PASS** |
| `local-gate.ps1 -L3 -SkipBuild` | mutation 步骤正常出现,脏树时降级为 advisory WARN |


## [Unreleased] — 2026-11-24 — 三个门禁的恒真断言与静默放行

> 由门禁有效性审计(`.GATE-AUDIT.md`)发现,每一条都做了「改坏 → 该红 → 修好后能红」的双向验证。
Expand Down
18 changes: 16 additions & 2 deletions tools/local-gate.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,9 @@ if ($null -ne $node) {
# "50000+" label). That class of bug is silent: no exception, no log, only a
# misleading graph on the bStats dashboard. So it gets a source-level gate.
Invoke-Step 'L1 bStats bucket selection' {
& $node (Join-Path $PSScriptRoot 'check-bstats-buckets.mjs')
# --repo 必须传:两个门禁原先写死 HERE/..,于是 -RepoRoot 指向别处时它们仍查本仓库,
# 而 CI/换机器下路径解析失败会被读成"通过"。同一脚本里其余门禁都传了,只有这两处漏了。
& $node (Join-Path $PSScriptRoot 'check-bstats-buckets.mjs') '--repo' $RepoRoot
}
# reload() must rebuild its tasks even when config loading failed. The javadoc says so
# ("无论 load 成败,任务必须重建:绝不允许「采集停了不重建」的半途冻结态") but nothing
Expand All @@ -211,7 +213,7 @@ if ($null -ne $node) {
# dataFolder, cleanOldReports() writes to disk, startPrometheus() binds a port), so the
# constraint goes to the source layer instead.
Invoke-Step 'L1 reload rebuilds even when load fails' {
& $node (Join-Path $PSScriptRoot 'check-reload-rebuild.mjs')
& $node (Join-Path $PSScriptRoot 'check-reload-rebuild.mjs') '--repo' $RepoRoot
}
# Cross-repo threshold consistency with the Velocity proxy. The two panels cannot share code
# (Paper plugin vs Velocity plugin, two repos, two JVMs), so "same operator" can only be kept
Expand Down Expand Up @@ -289,6 +291,18 @@ if ($Artifact -ne '') {
# L3
# ======================================================================================
if ($tier -ge 3) {
# Mutation subset. Full run is 70 variants / ~32 min, so this runs only the ones whose
# source file this branch touched (--changed). That step needs a clean tree; if there are
# uncommitted changes it exits and explains why instead of discarding them.
Invoke-Step 'L3 mutation subset (tools/mutate.mjs --changed)' {
Push-Location -LiteralPath $RepoRoot
try {
& node 'tools/mutate.mjs' '--changed' 'origin/main'
# A non-zero exit means at least one mutant SURVIVED -- that is the failure.
if ($LASTEXITCODE -ne 0) { throw "mutate.mjs 退出码 $LASTEXITCODE" }
} finally { Pop-Location }
} -Advisory

Write-Step ''
Write-Step 'L3 extra requirements (not automated here; each is a manual gate):' 'HEAD'
Write-Host ' [ ] full scenario regression: all 16 perfscope-* scenarios, both languages'
Expand Down
51 changes: 49 additions & 2 deletions tools/mutate.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,29 @@ const MUTATIONS = [
const args = process.argv.slice(2);
const only = args.includes('--only') ? args[args.indexOf('--only') + 1] : null;
const listOnly = args.includes('--list');
// --changed [<ref>]:只跑「这些源码文件被改过」的那些变异。
// 不带值默认与 origin/main 比(CI 里就是本 PR 的改动面)。
// 用途:全量 70 条要跑半个多小时,放进每个 PR 的 CI 会拖垮流水线;
// 而「本 PR 改到的文件」对应的变异通常只有个位数,几分钟内能跑完。
const changedIdx = args.indexOf('--changed');
const changedRef = changedIdx >= 0 ? (args[changedIdx + 1] && !args[changedIdx + 1].startsWith('--')
? args[changedIdx + 1] : 'origin/main') : null;

/**
* 本 PR 改动过的源码文件(相对仓库根,`/` 分隔)。
*
* <p>用 `--diff-filter=d` 排除纯删除的文件:删掉的文件没有东西可变异。
* 失败时返回 {@code null} 并让调用方报错——「拿不到改动面」不能静默退化成「跑全量」
* (那会突然变成半小时),也不能退化成「跑 0 条」(那是假绿)。</p>
*/
function changedFiles() {
try {
const out = run(`git diff --name-only --diff-filter=d ${changedRef}...HEAD`);
return out.split('\n').map(s => s.trim()).filter(Boolean);
} catch (e) {
return null;
}
}

function run(cmd, opts = {}) {
return execSync(cmd, { cwd: ROOT, encoding: 'utf8', stdio: 'pipe', ...opts });
Expand Down Expand Up @@ -827,18 +850,42 @@ function runTests(classes) {
}

function main() {
if (!gitClean()) {
// `--list` 只打印清单、不碰任何文件,因此不该被"工作树必须干净"拦住。
// 否则想先看看有哪些变异、再决定跑哪一条,还得先去 stash——那正好是它最该好用的时刻。
if (!listOnly && !gitClean()) {
console.error('工作树不干净,拒绝运行。');
console.error('变异验证会 git checkout 还原文件——未提交的改动会被一起抹掉。');
console.error('请先提交或 stash。');
process.exit(2);
}

const targets = only ? MUTATIONS.filter(m => m.id === only) : MUTATIONS;
let targets = only ? MUTATIONS.filter(m => m.id === only) : MUTATIONS;
if (targets.length === 0) {
console.error(`没有编号为 ${only} 的变异`);
process.exit(2);
}
// `--changed` 先过滤,`--list` 后展示:这样 `--changed --list` 能预览「本 PR 会跑哪几条」,
// 而单独的 `--list` 仍然列出全部(changedRef 为 null 时跳过过滤)。
if (changedRef) {
const files = changedFiles();
if (files === null) {
// 拿不到改动面时**必须报错退出**,不能静默跑全量(半小时)也不能跑 0 条(假绿)。
console.error(`无法算出改动面(git diff --name-only --diff-filter=d ${changedRef}...HEAD 失败)。`);
console.error('检查 ref 是否存在:git rev-parse --verify ' + changedRef);
process.exit(2);
}
const touched = new Set(files);
const before = targets.length;
targets = targets.filter(m => touched.has(m.file));
console.log(`--changed ${changedRef}: 改动 ${touched.size} 个文件,`
+ `命中 ${targets.length} / ${before} 条变异`);
if (targets.length === 0) {
// 这不是失败:本 PR 可能确实没碰任何"有变异覆盖"的文件。
// 但要把话说清楚,否则读日志的人分不清"没有"和"没跑"。
console.log('本 PR 没有改到任何被变异覆盖的文件——这一项无事可做(不是通过,也不是失败)。');
return;
}
}
if (listOnly) {
for (const m of targets) {
console.log(`${m.id} ${m.expect}`);
Expand Down
Loading