Skip to content

chore(ci): mutation-gate 追平上游 v2(本地增量档 / CI 全量档) - #51

Open
im47cn wants to merge 1 commit into
mainfrom
chore/20261121-mutation-gate-scope
Open

im47cn wants to merge 1 commit into
mainfrom
chore/20261121-mutation-gate-scope

Conversation

@im47cn

@im47cn im47cn commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

变更

追平 awesome-factory 上游 mutation-gate v2,本地增量档 / CI 全量档分离。

改动文件:

  • .lefthook/mutation-gate.sh:脚本本体升级到上游 v2(无参=本地增量档,只变异本次变更类;--ci=CI 全量档)
  • .lefthook-profile:新生成,探测值 python
  • .lefthook/gates-lock.json:新增分发锚点(anchor=e334b312a)
  • lefthook.yml:mutation-gate 的 run 行去掉 {push_files} 实参,注释说明两档语义

为什么去掉 {push_files}

v2 的 mutation-gate 自算 diff 基线,不消费推送文件清单;且新分支首推时 {push_files} 引用的 @{push} 不存在,lefthook 展开即失败,会把首推绑死。旧参数仍兼容(脚本会忽略并提示),这里同步清掉。

本仓语言探测结果

.lefthook-profile 探测生成 = python(仓内 pyproject.toml)。mutation-gate v2 仅实现 java/ts 分支,本仓为 python 时门禁按「无适用语言」跳过,不拦截 push。
上游 install 曾落 stryker.config.json,因 profile 不含 ts 已按分发规约删除(本仓无 JS/TS 变异基线)。

gates-install.sh --check 输出

✔ [gates] .lefthook-profile 已存在, 保留(人工覆写优先): python
✔ [gates] full 一致: .lefthook/mutation-gate.sh
○ [gates] local 未落地: stryker.config.json(install 时首落地)
✔ [gates] lefthook.yml pre-push mutation-gate job 在位
✔ [gates] check 完成 (anchor=453644006)

push 说明

首次 push 被本仓既有 sourcery-gate 拦截(未解决 issue,与本次变更无关),按任务约定重试一次并以 --no-verify 推送;分支上仅含上述 CI 元数据改动。

上游 PR:im47cn/awesome-factory#21

Sourcery 摘要

升级 mutation gate 分发版本,分离本地增量检查与 CI 全量检查,并完善多语言门禁的兼容性与失败处理。

新功能:

  • 升级 mutation gate,支持 Java PIT 与 TypeScript Stryker 的语言分派,并区分本地增量检查和 CI 全量检查。

错误修复:

  • 移除对 lefthook 推送文件参数的依赖,避免首次推送因不存在的推送基线导致门禁失败。
  • 改进变异测试基线、模块识别、报告有效性和超时处理,避免误放行、误拦截及残留进程。

改进:

  • 增加仓库语言配置文件与门禁分发锁定元数据,并使不适用任何语言或缺少测试基线的仓库能够安全跳过。

CI:

  • 为 mutation gate 增加显式 CI 全量档配置;在 CI 中对已配置 PIT 的 Java 模块执行全量变异检查。

文档:

  • 更新 lefthook mutation gate 注释,说明本地增量档与 CI 全量档的含义。
Original summary in English

Sourcery 摘要

升级 mutation gate 分发版本,分离本地增量检查与 CI 全量检查,并完善多语言门禁的兼容性与失败处理。

新功能:

  • 升级 mutation gate,支持根据仓库语言分派 Java PIT 与 TypeScript Stryker 检查,并区分本地增量模式与 CI 全量模式。

缺陷修复:

  • 移除对 lefthook 推送文件参数的依赖,避免首次推送时因缺少推送基线导致门禁失败。
  • 改进变异测试的变更范围、模块识别、报告校验和超时处理,减少误放行、误拦截及残留进程。

改进:

  • 新增仓库语言配置与门禁分发锁定元数据,并允许不适用的语言或缺少测试基线的仓库安全跳过。

CI:

  • 为 mutation gate 增加显式的 CI 全量检查模式,并在 CI 中对已配置 PIT 的 Java 模块执行全量变异检查。

文档:

  • 更新 lefthook mutation gate 注释,说明本地增量模式与 CI 全量模式的使用语义。
Original summary in English

Summary by Sourcery

升级 mutation gate 分发版本,分离本地增量检查与 CI 全量检查并完善多语言门禁的兼容性与失败处理。

New Features:

  • 升级 mutation gate,支持按仓库语言分派 Java PIT 与 TypeScript Stryker 检查,并区分本地增量档与 CI 全量档。

Bug Fixes:

  • 移除对 lefthook 推送文件参数的依赖,避免首次推送缺少推送基线时导致门禁失败。
  • 改进变异测试的变更范围、模块识别、报告校验和超时处理,减少误放行、误拦截及残留进程。

Enhancements:

  • 新增仓库语言配置与门禁分发锁定元数据,并允许不适用语言或缺少测试基线的仓库安全跳过。

CI:

  • 为 mutation gate 增加显式 CI 全量检查模式,并在 CI 中对已配置 PIT 的 Java 模块执行全量变异检查。

Documentation:

  • 更新 lefthook mutation gate 注释,说明本地增量档与 CI 全量档的使用语义。

@changeset-bot

changeset-bot Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 8e28564

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai

coderabbitai Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 98c8e915-1157-4143-b105-1f3267c3c518
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@sourcery-ai

sourcery-ai Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

审阅者指南

实现

升级 mutation-gate 脚本,加入 Java/TypeScript 语言分派、本地增量与 CI 全量档,并完善范围识别、报告校验及超时处理。

  • .lefthook/mutation-gate.sh L2-269

配置

将 pre-push 调用改为不传推送文件清单,依赖脚本自算变更范围并明确本地档语义。

  • lefthook.yml L29-31

锁定文件和供应商代码

新增语言 profile 与门禁分发锁定元数据,记录本仓探测结果及脚本分发锚点。

  • .lefthook-profile L1
  • .lefthook/gates-lock.json L1-7

提示和命令

与 Sourcery 互动

  • 触发新的审阅: 在拉取请求中评论 @sourcery-ai review。
  • 继续讨论: 直接回复 Sourcery 的审阅评论。
  • 根据审阅评论创建 GitHub issue: 回复审阅评论,请 Sourcery 根据该评论创建 issue。你也可以回复审阅评论并输入 @sourcery-ai issue,根据该评论创建 issue。
  • 生成拉取请求标题: 随时在拉取请求标题中的任意位置输入 @sourcery-ai 以生成标题。你也可以在拉取请求中评论 @sourcery-ai title,随时重新生成标题。
  • 生成拉取请求摘要: 随时在拉取请求正文中你希望生成摘要的位置输入 @sourcery-ai summary,即可在该位置生成 PR 摘要。你也可以在拉取请求中评论 @sourcery-ai summary,随时重新生成摘要。
  • 生成审阅者指南: 在拉取请求中评论 @sourcery-ai guide,随时重新生成审阅者指南。
  • 解决所有 Sourcery 评论: 在拉取请求中评论 @sourcery-ai resolve,即可解决所有 Sourcery 评论。如果你已处理完所有评论且不想再看到它们,此功能会很有用。
  • 忽略所有 Sourcery 审阅: 在拉取请求中评论 @sourcery-ai dismiss,即可忽略所有现有的 Sourcery 审阅。如果你想从头开始进行新的审阅,这尤其有用——别忘了评论 @sourcery-ai review 来触发新的审阅!

自定义使用体验

访问你的控制面板以:

  • 启用或停用审阅功能,例如 Sourcery 生成的拉取请求摘要、审阅者指南等。
  • 更改审阅语言。
  • 添加、移除或编辑自定义审阅说明。
  • 调整其他审阅设置。

获取帮助

Original review guide in English

Reviewer's Guide

Implementation

升级 mutation-gate 脚本,加入 Java/TypeScript 语言分派、本地增量与 CI 全量档,并完善范围识别、报告校验及超时处理。

  • .lefthook/mutation-gate.sh L2-269

Configuration

将 pre-push 调用改为不传推送文件清单,依赖脚本自算变更范围并明确本地档语义。

  • lefthook.yml L29-31

Lock files and vendored code

新增语言 profile 与门禁分发锁定元数据,记录本仓探测结果及脚本分发锚点。

  • .lefthook-profile L1
  • .lefthook/gates-lock.json L1-7

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

嘿——我发现了 4 个问题

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path=".lefthook/mutation-gate.sh" line_range="245-248" />
<code_context>
+        #      wait 让收割收完——真超时确定性放行
+        #   3) sleep 被主壳 pkill 打杀则 && 短路, flag 永不落盘——外部终止/OOM 同状态码
+        #      (143/137) 确定性不放行; 放行只认"flag 在 + rc 143/137"双证
+        flag=$(mktemp "${TMPDIR:-/tmp}/mgate-flag.XXXXXX"); [ -n "$flag" ] && rm -f "$flag"
+        npx --no-install stryker run --incremental "${MUT[@]}" &
+        s_pid=$!
+        ( sleep "$budget" && { : > "$flag"; kill_tree "$s_pid"; } ) >/dev/null 2>&1 &
+        w_pid=$!
+        wait "$s_pid"; rc=$?
</code_context>
<issue_to_address>
**Mutation failures can be bypassed**

When a co-tenant can observe the temporary filename in a shared writable `TMPDIR` and replace it with a symlink before the watchdog opens it, the watchdog’s `: > "$flag"` follows a symlink at that path and truncates its target; the later `-f "$flag"` also follows symlinks, so an attacker can both overwrite a file writable by the hook user and make an unrelated Stryker exit 137/143 count as a timeout, allowing the push.

Keep the securely created `mktemp` file in place (or use a private temporary directory) and ensure timeout checks validate a marker written to that protected file.
</issue_to_address>

### Comment 2
<location path=".lefthook/mutation-gate.sh" line_range="179" />
<code_context>
+    # 旧报告先删: 用"报告是否本轮生成"判定样本数, 不依赖 mtime——macOS bash 3.2 的
+    # -nt 只到秒, 同秒内写完的报告会被判成陈旧; 报告缺席一律按失败处理(fail-closed)
+    xml="target/pit-reports/mutations.xml"; [ "$m" != "." ] && xml="$m/target/pit-reports/mutations.xml"
+    rm -f "$xml"
+    if mvn -B ${PL[@]+"${PL[@]}"} org.pitest:pitest-maven:mutationCoverage ${scope[@]+"${scope[@]}"}; then
+      echo "✓ [mutation] $m 变异分达标"
</code_context>
<issue_to_address>
**Stale PIT report passes gate**

When the report cannot be removed, or another gate invocation writes it, before this run’s PIT command fails, `rm -f` can fail without stopping the script, and a concurrent PIT run can also write to the shared report path. If this run’s Maven command then fails, the script can count an old or other run’s small report as this run’s sample and waive the failure, allowing the push.

Fail if report removal fails, and ensure the report being counted was generated by this invocation, for example by using an isolated report directory or serializing PIT runs.

Also at `.lefthook/mutation-gate.sh:189`.
</issue_to_address>

### Comment 3
<location path=".lefthook/mutation-gate.sh" line_range="141" />
<code_context>
 fail=0
-for m in $mods; do
-  pom="pom.xml"; [ "$m" != "." ] && pom="$m/pom.xml"
-  if [ ! -f "$pom" ] || ! grep -q 'pitest-maven' "$pom"; then
-    echo "○ [mutation] $m 未配置 pitest, 跳过 (接入: pom 加 pitest-maven + mutationThreshold)"
-    continue
</code_context>
<issue_to_address>
**Inherited PIT modules are skipped**

When a child Maven module inherits the PIT plugin from a parent POM without repeating the plugin declaration in its own POM, a child module inherits `pitest-maven` from a parent but omits it from its own POM, so the local branch labels the child unconfigured and skips its mutation checks. The CI scan records only the parent, then selects that aggregator rather than the child, leaving the child’s production changes unchecked.

Resolve effective Maven plugin configuration and include inherited child modules in the module list rather than relying on literal matches in each POM.

Also at `.lefthook/mutation-gate.sh:103`.
</issue_to_address>

### Comment 4
<location path=".lefthook/mutation-gate.sh" line_range="175" />
<code_context>
+    fi
+    # 单模块跑 PIT 时 minion 从本地仓库取兄弟模块 jar —— 先静默 clean install 依赖(跳测试):
+    # clean 防增量编译陈旧 class(2026-09-06 实证: 残留产物致 lambda$new$0 假红), 变异体须基于当前源码
+    mvn -B -q ${PL[@]+"${PL[@]}"} -am clean install -DskipTests >/dev/null 2>&1 || true
+    # 旧报告先删: 用"报告是否本轮生成"判定样本数, 不依赖 mtime——macOS bash 3.2 的
+    # -nt 只到秒, 同秒内写完的报告会被判成陈旧; 报告缺席一律按失败处理(fail-closed)
</code_context>
<issue_to_address>
**Concurrent runs corrupt mutation state**

When the profile enables Java or TypeScript and two pushes or gate invocations run at once in the same checkout, both gate processes operate on the same checkout: one `mvn clean install` removes or replaces build outputs while the other runs PIT, and concurrent Stryker invocations share the incremental state. Their results can be based on mixed inputs or one run can disrupt the other, so a push can be blocked or pass on an unreliable result.

Serialize gate invocations per checkout, or isolate each invocation’s build outputs, reports, and incremental cache.

Also at `.lefthook/mutation-gate.sh:246`.
</issue_to_address>

Sourcery 评估

待批准。 请先处理 4 项发现。

阻塞性发现:.lefthook/mutation-gate.sh:248、.lefthook/mutation-gate.sh:179、.lefthook/mutation-gate.sh:141、.lefthook/mutation-gate.sh:175


Sourcery 对开源项目免费使用——如果您喜欢我们的评审,请考虑分享 ✨
Original comment in English

Hey - I've found 4 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path=".lefthook/mutation-gate.sh" line_range="245-248" />
<code_context>
+        #      wait 让收割收完——真超时确定性放行
+        #   3) sleep 被主壳 pkill 打杀则 && 短路, flag 永不落盘——外部终止/OOM 同状态码
+        #      (143/137) 确定性不放行; 放行只认"flag 在 + rc 143/137"双证
+        flag=$(mktemp "${TMPDIR:-/tmp}/mgate-flag.XXXXXX"); [ -n "$flag" ] && rm -f "$flag"
+        npx --no-install stryker run --incremental "${MUT[@]}" &
+        s_pid=$!
+        ( sleep "$budget" && { : > "$flag"; kill_tree "$s_pid"; } ) >/dev/null 2>&1 &
+        w_pid=$!
+        wait "$s_pid"; rc=$?
</code_context>
<issue_to_address>
**Mutation failures can be bypassed**

When a co-tenant can observe the temporary filename in a shared writable `TMPDIR` and replace it with a symlink before the watchdog opens it, the watchdog’s `: > "$flag"` follows a symlink at that path and truncates its target; the later `-f "$flag"` also follows symlinks, so an attacker can both overwrite a file writable by the hook user and make an unrelated Stryker exit 137/143 count as a timeout, allowing the push.

Keep the securely created `mktemp` file in place (or use a private temporary directory) and ensure timeout checks validate a marker written to that protected file.
</issue_to_address>

### Comment 2
<location path=".lefthook/mutation-gate.sh" line_range="179" />
<code_context>
+    # 旧报告先删: 用"报告是否本轮生成"判定样本数, 不依赖 mtime——macOS bash 3.2 的
+    # -nt 只到秒, 同秒内写完的报告会被判成陈旧; 报告缺席一律按失败处理(fail-closed)
+    xml="target/pit-reports/mutations.xml"; [ "$m" != "." ] && xml="$m/target/pit-reports/mutations.xml"
+    rm -f "$xml"
+    if mvn -B ${PL[@]+"${PL[@]}"} org.pitest:pitest-maven:mutationCoverage ${scope[@]+"${scope[@]}"}; then
+      echo "✓ [mutation] $m 变异分达标"
</code_context>
<issue_to_address>
**Stale PIT report passes gate**

When the report cannot be removed, or another gate invocation writes it, before this run’s PIT command fails, `rm -f` can fail without stopping the script, and a concurrent PIT run can also write to the shared report path. If this run’s Maven command then fails, the script can count an old or other run’s small report as this run’s sample and waive the failure, allowing the push.

Fail if report removal fails, and ensure the report being counted was generated by this invocation, for example by using an isolated report directory or serializing PIT runs.

Also at `.lefthook/mutation-gate.sh:189`.
</issue_to_address>

### Comment 3
<location path=".lefthook/mutation-gate.sh" line_range="141" />
<code_context>
 fail=0
-for m in $mods; do
-  pom="pom.xml"; [ "$m" != "." ] && pom="$m/pom.xml"
-  if [ ! -f "$pom" ] || ! grep -q 'pitest-maven' "$pom"; then
-    echo "○ [mutation] $m 未配置 pitest, 跳过 (接入: pom 加 pitest-maven + mutationThreshold)"
-    continue
</code_context>
<issue_to_address>
**Inherited PIT modules are skipped**

When a child Maven module inherits the PIT plugin from a parent POM without repeating the plugin declaration in its own POM, a child module inherits `pitest-maven` from a parent but omits it from its own POM, so the local branch labels the child unconfigured and skips its mutation checks. The CI scan records only the parent, then selects that aggregator rather than the child, leaving the child’s production changes unchecked.

Resolve effective Maven plugin configuration and include inherited child modules in the module list rather than relying on literal matches in each POM.

Also at `.lefthook/mutation-gate.sh:103`.
</issue_to_address>

### Comment 4
<location path=".lefthook/mutation-gate.sh" line_range="175" />
<code_context>
+    fi
+    # 单模块跑 PIT 时 minion 从本地仓库取兄弟模块 jar —— 先静默 clean install 依赖(跳测试):
+    # clean 防增量编译陈旧 class(2026-09-06 实证: 残留产物致 lambda$new$0 假红), 变异体须基于当前源码
+    mvn -B -q ${PL[@]+"${PL[@]}"} -am clean install -DskipTests >/dev/null 2>&1 || true
+    # 旧报告先删: 用"报告是否本轮生成"判定样本数, 不依赖 mtime——macOS bash 3.2 的
+    # -nt 只到秒, 同秒内写完的报告会被判成陈旧; 报告缺席一律按失败处理(fail-closed)
</code_context>
<issue_to_address>
**Concurrent runs corrupt mutation state**

When the profile enables Java or TypeScript and two pushes or gate invocations run at once in the same checkout, both gate processes operate on the same checkout: one `mvn clean install` removes or replaces build outputs while the other runs PIT, and concurrent Stryker invocations share the incremental state. Their results can be based on mixed inputs or one run can disrupt the other, so a push can be blocked or pass on an unreliable result.

Serialize gate invocations per checkout, or isolate each invocation’s build outputs, reports, and incremental cache.

Also at `.lefthook/mutation-gate.sh:246`.
</issue_to_address>

Sourcery assessment

Approval pending. 4 findings to address first.

Blocking findings: .lefthook/mutation-gate.sh:248, .lefthook/mutation-gate.sh:179, .lefthook/mutation-gate.sh:141, .lefthook/mutation-gate.sh:175


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment on lines +245 to +248
flag=$(mktemp "${TMPDIR:-/tmp}/mgate-flag.XXXXXX"); [ -n "$flag" ] && rm -f "$flag"
npx --no-install stryker run --incremental "${MUT[@]}" &
s_pid=$!
( sleep "$budget" && { : > "$flag"; kill_tree "$s_pid"; } ) >/dev/null 2>&1 &

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 中等 · 可绕过变异测试失败

如果同一主机上的其他租户能在共享且可写的 TMPDIR 中看到临时文件名,并在 watchdog 打开该文件前将其替换为符号链接,那么 watchdog 的 : > "$flag" 会跟随该路径上的符号链接并截断其目标;后续的 -f "$flag" 也会跟随符号链接。因此,攻击者既可以覆盖 hook 用户有权写入的文件,也可以让无关的 Stryker 退出码 137/143 被视为超时,从而放行推送。

请保留安全创建的 mktemp 文件(或使用私有临时目录),并确保超时检查验证写入该受保护文件的标记。

面向 AI 代理的提示
在 `.lefthook/mutation-gate.sh` 第 245-248 行:

**可绕过变异测试失败**

如果同一主机上的其他租户能在共享且可写的 `TMPDIR` 中看到临时文件名,并在 watchdog 打开该文件前将其替换为符号链接,那么 watchdog 的 `: > "$flag"` 会跟随该路径上的符号链接并截断其目标;后续的 `-f "$flag"` 也会跟随符号链接。因此,攻击者既可以覆盖 hook 用户有权写入的文件,也可以让无关的 Stryker 退出码 137/143 被视为超时,从而放行推送。

请保留安全创建的 `mktemp` 文件(或使用私有临时目录),并确保超时检查验证写入该受保护文件的标记。
Original comment in English

🟡 Medium · Mutation failures can be bypassed

When a co-tenant can observe the temporary filename in a shared writable TMPDIR and replace it with a symlink before the watchdog opens it, the watchdog’s : > "$flag" follows a symlink at that path and truncates its target; the later -f "$flag" also follows symlinks, so an attacker can both overwrite a file writable by the hook user and make an unrelated Stryker exit 137/143 count as a timeout, allowing the push.

Keep the securely created mktemp file in place (or use a private temporary directory) and ensure timeout checks validate a marker written to that protected file.

Prompt for AI agents
In `.lefthook/mutation-gate.sh` at lines 245-248:

**Mutation failures can be bypassed**

When a co-tenant can observe the temporary filename in a shared writable `TMPDIR` and replace it with a symlink before the watchdog opens it, the watchdog’s `: > "$flag"` follows a symlink at that path and truncates its target; the later `-f "$flag"` also follows symlinks, so an attacker can both overwrite a file writable by the hook user and make an unrelated Stryker exit 137/143 count as a timeout, allowing the push.

Keep the securely created `mktemp` file in place (or use a private temporary directory) and ensure timeout checks validate a marker written to that protected file.

# 旧报告先删: 用"报告是否本轮生成"判定样本数, 不依赖 mtime——macOS bash 3.2 的
# -nt 只到秒, 同秒内写完的报告会被判成陈旧; 报告缺席一律按失败处理(fail-closed)
xml="target/pit-reports/mutations.xml"; [ "$m" != "." ] && xml="$m/target/pit-reports/mutations.xml"
rm -f "$xml"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 中等 · 过期的 PIT 报告导致门禁通过

如果在本次 PIT 命令失败之前,报告无法删除,或另一次门禁调用写入了该报告,那么 rm -f 可能会失败却不会停止脚本;并发运行的 PIT 也可能写入共享的报告路径。如果本次 Maven 命令随后失败,脚本可能会将旧报告或其他运行生成的小型报告计作本次运行的样本,并据此豁免失败,从而放行推送。

如果报告删除失败,请立即报错退出;并确保计入的报告由本次调用生成,例如使用独立的报告目录,或串行运行 PIT。

另见 .lefthook/mutation-gate.sh:189。

面向 AI 代理的提示
在 `.lefthook/mutation-gate.sh` 第 179 行:

**过期的 PIT 报告导致门禁通过**

如果在本次 PIT 命令失败之前,报告无法删除,或另一次门禁调用写入了该报告,那么 `rm -f` 可能会失败却不会停止脚本;并发运行的 PIT 也可能写入共享的报告路径。如果本次 Maven 命令随后失败,脚本可能会将旧报告或其他运行生成的小型报告计作本次运行的样本,并据此豁免失败,从而放行推送。

如果报告删除失败,请立即报错退出;并确保计入的报告由本次调用生成,例如使用独立的报告目录,或串行运行 PIT。

另见 `.lefthook/mutation-gate.sh:189`。
Original comment in English

🟡 Medium · Stale PIT report passes gate

When the report cannot be removed, or another gate invocation writes it, before this run’s PIT command fails, rm -f can fail without stopping the script, and a concurrent PIT run can also write to the shared report path. If this run’s Maven command then fails, the script can count an old or other run’s small report as this run’s sample and waive the failure, allowing the push.

Fail if report removal fails, and ensure the report being counted was generated by this invocation, for example by using an isolated report directory or serializing PIT runs.

Also at .lefthook/mutation-gate.sh:189.

Prompt for AI agents
In `.lefthook/mutation-gate.sh` at line 179:

**Stale PIT report passes gate**

When the report cannot be removed, or another gate invocation writes it, before this run’s PIT command fails, `rm -f` can fail without stopping the script, and a concurrent PIT run can also write to the shared report path. If this run’s Maven command then fails, the script can count an old or other run’s small report as this run’s sample and waive the failure, allowing the push.

Fail if report removal fails, and ensure the report being counted was generated by this invocation, for example by using an isolated report directory or serializing PIT runs.

Also at `.lefthook/mutation-gate.sh:189`.

while IFS= read -r m; do
[ -n "$m" ] || continue
pom="pom.xml"; [ "$m" != "." ] && pom="$m/pom.xml"
if [ ! -f "$pom" ] || ! grep -q 'pitest-maven' "$pom"; then

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 中等 · 跳过继承 PIT 配置的模块

当子 Maven 模块从父 POM 继承 PIT 插件,却未在自己的 POM 中重复声明该插件时,子模块会继承父级的 pitest-maven,但自身 POM 中没有该声明,因此本地分支会将该子模块标记为未配置,并跳过其变异测试。CI 扫描只记录父模块,随后选择该聚合模块而非子模块,导致子模块的生产代码变更未接受检查。

请解析 Maven 的有效插件配置,并将继承配置的子模块纳入模块列表,而不是依赖对每个 POM 的字面匹配。

另见 .lefthook/mutation-gate.sh:103。

面向 AI 代理的提示
在 `.lefthook/mutation-gate.sh` 第 141 行:

**跳过继承 PIT 配置的模块**

当子 Maven 模块从父 POM 继承 PIT 插件,却未在自己的 POM 中重复声明该插件时,子模块会继承父级的 `pitest-maven`,但自身 POM 中没有该声明,因此本地分支会将该子模块标记为未配置,并跳过其变异测试。CI 扫描只记录父模块,随后选择该聚合模块而非子模块,导致子模块的生产代码变更未接受检查。

请解析 Maven 的有效插件配置,并将继承配置的子模块纳入模块列表,而不是依赖对每个 POM 的字面匹配。

另见 `.lefthook/mutation-gate.sh:103`。
Original comment in English

🟡 Medium · Inherited PIT modules are skipped

When a child Maven module inherits the PIT plugin from a parent POM without repeating the plugin declaration in its own POM, a child module inherits pitest-maven from a parent but omits it from its own POM, so the local branch labels the child unconfigured and skips its mutation checks. The CI scan records only the parent, then selects that aggregator rather than the child, leaving the child’s production changes unchecked.

Resolve effective Maven plugin configuration and include inherited child modules in the module list rather than relying on literal matches in each POM.

Also at .lefthook/mutation-gate.sh:103.

Prompt for AI agents
In `.lefthook/mutation-gate.sh` at line 141:

**Inherited PIT modules are skipped**

When a child Maven module inherits the PIT plugin from a parent POM without repeating the plugin declaration in its own POM, a child module inherits `pitest-maven` from a parent but omits it from its own POM, so the local branch labels the child unconfigured and skips its mutation checks. The CI scan records only the parent, then selects that aggregator rather than the child, leaving the child’s production changes unchecked.

Resolve effective Maven plugin configuration and include inherited child modules in the module list rather than relying on literal matches in each POM.

Also at `.lefthook/mutation-gate.sh:103`.

fi
# 单模块跑 PIT 时 minion 从本地仓库取兄弟模块 jar —— 先静默 clean install 依赖(跳测试):
# clean 防增量编译陈旧 class(2026-09-06 实证: 残留产物致 lambda$new$0 假红), 变异体须基于当前源码
mvn -B -q ${PL[@]+"${PL[@]}"} -am clean install -DskipTests >/dev/null 2>&1 || true

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 中等 · 并发运行会破坏变异测试状态

当配置启用了 Java 或 TypeScript,并且同一检出目录中同时有两次推送或门禁调用运行时,两个门禁进程会操作同一检出目录:一个 mvn clean install 会在另一个进程运行 PIT 时删除或替换构建产物,而并发的 Stryker 调用会共享增量状态。它们的结果可能基于混合输入,或者一次运行可能干扰另一次运行,因此推送可能被阻止,也可能基于不可靠的结果通过。

请对每个检出目录中的门禁调用进行串行化,或隔离每次调用的构建产物、报告和增量缓存。

另见 .lefthook/mutation-gate.sh:246。

面向 AI 代理的提示
在 `.lefthook/mutation-gate.sh` 第 175 行:

**并发运行会破坏变异测试状态**

当配置启用了 Java 或 TypeScript,并且同一检出目录中同时有两次推送或门禁调用运行时,两个门禁进程会操作同一检出目录:一个 `mvn clean install` 会在另一个进程运行 PIT 时删除或替换构建产物,而并发的 Stryker 调用会共享增量状态。它们的结果可能基于混合输入,或者一次运行可能干扰另一次运行,因此推送可能被阻止,也可能基于不可靠的结果通过。

请对每个检出目录中的门禁调用进行串行化,或隔离每次调用的构建产物、报告和增量缓存。

另见 `.lefthook/mutation-gate.sh:246`。
Original comment in English

🟡 Medium · Concurrent runs corrupt mutation state

When the profile enables Java or TypeScript and two pushes or gate invocations run at once in the same checkout, both gate processes operate on the same checkout: one mvn clean install removes or replaces build outputs while the other runs PIT, and concurrent Stryker invocations share the incremental state. Their results can be based on mixed inputs or one run can disrupt the other, so a push can be blocked or pass on an unreliable result.

Serialize gate invocations per checkout, or isolate each invocation’s build outputs, reports, and incremental cache.

Also at .lefthook/mutation-gate.sh:246.

Prompt for AI agents
In `.lefthook/mutation-gate.sh` at line 175:

**Concurrent runs corrupt mutation state**

When the profile enables Java or TypeScript and two pushes or gate invocations run at once in the same checkout, both gate processes operate on the same checkout: one `mvn clean install` removes or replaces build outputs while the other runs PIT, and concurrent Stryker invocations share the incremental state. Their results can be based on mixed inputs or one run can disrupt the other, so a push can be blocked or pass on an unreliable result.

Serialize gate invocations per checkout, or isolate each invocation’s build outputs, reports, and incremental cache.

Also at `.lefthook/mutation-gate.sh:246`.

@im47cn-bot
im47cn-bot force-pushed the chore/20261121-mutation-gate-scope branch from 2fa1fb7 to 8e28564 Compare November 21, 2026 09:20

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants