Skip to content

fix(tooling): batch the workspace rustfmt hook on Windows - #3569

Merged
caomengxuan666 merged 3 commits into
masterfrom
fix/windows-rustfmt-batch-gate
Nov 18, 2026
Merged

caomengxuan666 merged 3 commits into
masterfrom
fix/windows-rustfmt-batch-gate

Conversation

@caomengxuan666

@caomengxuan666 caomengxuan666 commented Nov 14, 2026 •

Copy link
Copy Markdown
Member

Changes

  • Replace the oversized pre-commit cargo fmt --check command with a bounded whole-workspace rustfmt check.
  • Discover every workspace-member target via cargo metadata --no-deps --format-version 1; deduplicate source roots by edition and check all roots, not just changed files.
  • Bound Windows argv by UTF-16 code units, including quoting; reject an individual target that cannot fit.
  • Fail closed on missing tools, invalid/incomplete metadata, or any formatting batch failure. Never silently drop a missing member or target source.
  • Require a working Python 3 interpreter; remove the old missing-cargo success path.
  • Document the gate in AGENTS.md. The only Rust change is the two pre-existing rustfmt wrapping corrections in tests/d11_pipeline_squote_carrier_regressions.rs.

Verification

  • Reproduced original Windows cargo fmt --check failure: os error 206.
  • Python checker tests: 15 passed, including four new metadata-completeness methods. Missing members, partially missing target sources, empty member target sets, and malformed shapes must fail before any rustfmt invocation.
  • Real whole-workspace check: 1,486 roots / 10 batches, exit 0.
  • Actual native Windows pre-commit hook under normal PATH: same coverage, exit 0, including commit b7086c3d.
  • Separate git fixture in a path with a space: malformed Rust rejected, formatted Rust accepted.
  • Before the two existing Rust formatting corrections, both checker and hook rejected the committed drift instead of skipping it.

Raw local evidence: target/issue-suites/results/fmt-gate/, including
metadata-unit.*, metadata-real.*, metadata-commit.*,
hook-fixture-{bad,good}.*, and the initial verification logs.

CI / Scope

  • No Bash semantic change; GNU comparison is not applicable.
  • Prior head f7af2e55 has three red jobs on the same issue2875 test and
    assertion already observed on exact base master 8b48c164 (run43553720862).
    Raw comparison and limitations are in the review comment; this is NOT
    a claim that the entire CI is green.
  • The new head remains draft pending CI/review acceptance.
  • Standalone cargo fmt and existing CI workflow commands are unchanged.
  • This PR does not certify the other issue-fix drafts. No merge/closure.

Enumerate workspace target roots with cargo metadata and bound each rustfmt argv below the Windows command-line limit. Fail closed if required tooling is missing. Include the two pre-existing rustfmt wrapping corrections so the gate passes without bypasses.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@caomengxuan666

Copy link
Copy Markdown
Member Author

CI 复核补充:本 PR 的 Windows tests compile check、Compatibility CLI、跨目标检查、Shell functionality、API ledger、niubash canary 均已通过;Rust tests(Linux/macOS)与 GNU regression job 失败,不能标 CI 全绿。三个失败都指向 api::consumer_tests::issue2875_input_procsub_child_runs_as_rubash_shell,在 src/api/consumer_tests.rs:2911 断言前由测试执行器报 Unrecognized option: c。已读取精确基底 master 8b48c16 的 CI run 43553720862 原始失败日志:同一项测试、同一断言、同样的 -c 拒绝在三个 job 中均已存在;macOS 与 GNU job 的总数也一致(1243/1/4、1350/1/4)。因此这是已在基底 CI 出现的阻塞,不是格式门禁已通过就把整个 CI 当绿。本 PR 保持 draft,不在这里混入无关测试运行器修复。

Reject missing workspace member packages, empty target sets, and targets
without source paths before launching any rustfmt batch. Malformed metadata
must not silently reduce the gate's coverage and still report success.

Preserve edition fallback, target deduplication, CLI and bounded batching.
All 15 checker tests pass; the real gate checks 1486 targets in 10 batches.

Refs #3569.

Generated with [Devin](https://devin.ai)
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
caomengxuan666 added a commit that referenced this pull request Nov 14, 2026
Bring the formatting-gate feature history into this draft feature branch
so follow-up commits run the normal Windows pre-commit check without the
legacy command-line overflow. This does not merge either PR into master.

Refs #3569; its review and landing remain independent.

Generated with [Devin](https://devin.ai)
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@caomengxuan666

Copy link
Copy Markdown
Member Author

【WIN-AGENT-AUDIT】
PR #3569 第3轮 — 建议:PENDING(缺腿/阻塞:DIRTY)
head: b7086c3 base(merge-base): 8b48c16 文件: 5 个 +630/-14
关联 issue: PR 正文未引 issue;工具面修复(pre-commit rustfmt 门在 Windows 溢出 os error 206)

机制核查:

  • 纯工具面:新增 scripts/check-rustfmt.py(267 行)+ scripts/check_rustfmt_test.py(324 行),改 scripts/git-hooks/pre-commit 与 AGENTS.md;tests/d11 的两处仅为 rustfmt 重排(无语义)。
  • 机制正确:cargo metadata --no-deps 取 workspace_members 的 target src_path 全集(与 cargo fmt 同覆盖),按 edition 分组、按 UTF-16 code unit 计 argv 长度(subprocess.list2cmdline 即 Windows 引号模型)、12000 上限批跑 rustfmt --check;缺 cargo/rustfmt/python3、metadata 任何字段缺失/畸形、单路径超限、任一批非零 → 全非零退出,无静默降级。逐字段校验 workspace_members ⊆ packages、target src_path 非空。
  • 与 master 已落地方案对比(重要):master 的 pre-commit(8b48c164 后版本)对同一症状走的是「cargo fmt 失败且无 Diff in 行 → 只查本次 staged 的 .rs」的退路,且 cargo/rustfmt 缺失时 exit 0(fail-open)。本 PR 方案是更严的门(全 workspace、fail-closed)。两者在 pre-commit 同区域冲突,merge-tree 实测 CONFLICT (content)。
  • 无关改动:无。

腿(逐项给数字与名字,不许只写「全绿」):

  • 钉自跑:本 PR 无 Rust 钉;Python 单测 scripts/check_rustfmt_test.py 在 head 检出上实测 15/15 OK(与正文声称一致)。
  • fail-first:不适用(工具 PR,无 base-红钉可验证);工具本身即「修复前门必溢出」的形态。
  • lib 双边:未跑(src/ 零改动,无引擎语义面;且判词由 B1 决定)。
  • -D warnings:未跑(无 Rust 源码改动,仅重排既有测试文件)。
  • 卫生:python scripts/check-rustfmt.py --repo-root D:/repo/rubash-devin-s9 在 head 检出上实测 1486 roots / 10 batches / exit 0——与正文声称逐字一致;fmt --check 对本 PR 的 .rs 改动经同一工具覆盖通过。
  • CI(gh run 43567543675,head b7086c3):红 3 格——Rust tests、Rust tests (macOS)、GNU regression goldens and canaries,失败名均只有 api::consumer_tests::issue2875_input_procsub_child_runs_as_rubash_shell(consumer_tests.rs:2911,计数 1243+1 / 1350+1 / 26+1),与 master 基线同签名逐格一致 → 基线红。其余 8 格全绿。
  • GNU 对照:不适用(工具面,无 Bash 语义;正文此声明成立)。

阻塞项:

  • B1:mergeStateStatus=DIRTY,git merge-tree 实测 scripts/git-hooks/pre-commit 内容冲突——master 已落地同一症状的另一修法(staged-files 退路)。需 rebase 且取舍两种方案;本 PR 方案的门更严,但合与不合是调度裁决点,已超出审计可自决范围。

F 点:无。

续作记录:本轮未动代码。

未跑/VOID 的腿:

  • lib 双边、-D warnings:无 Rust 语义改动 + 判词由 DIRTY 决定,未起构建。

@caomengxuan666

Copy link
Copy Markdown
Member Author

【WIN-AGENT-AUDIT】
PR #3569 第4轮(S9 车道)— 建议:PENDING(沿用第3轮结论,阻塞未变)
head: b7086c3 未变(与第3轮同 oid) base(merge-base): 8b48c16 文件: 5 个 +630/-14

本轮复核(只核阻塞条件,不重复全腿):

  • gh pr view 3569 实时:mergeable=CONFLICTING、mergeStateStatus=DIRTY;git merge-tree --write-tree origin/master b7086c3d → CONFLICT (content): Merge conflict in scripts/git-hooks/pre-commit。与第3轮 B1 一致,未 rebase。
  • 第3轮已核过的机制/腿仍然有效(纯工具面;scripts/check_rustfmt.py 实测 1486 roots / 10 batches / exit 0;Python 单测 15/15;CI 三红 = issue2875 基线)。本轮不重跑。
  • 仍待队长裁决的点未变:master 已有同一症状的另一种 pre-commit 修法(staged-files 退路、fail-open),本 PR 是 fail-closed 全 workspace 方案;两者需取舍后才能 rebase 落位。

结论:不合、不关。等方案裁决 + rebase。

@caomengxuan666

Copy link
Copy Markdown
Member Author

【WIN-AGENT-AUDIT】
PR #3569 裁决输入(钩子设计方向:fail-closed 全量门 vs staged fallback)— 建议:采纳本 PR 方向(供队长拍板;本评论不构成合并)

head: b7086c3(gh 实时,未变) mergeable=CONFLICTING/DIRTY

裁决建议:fail-closed 全量 Python 门(本 PR 方案)是更贴仓库现状的方向;master 的 staged fallback 不应作为终态。

依据:

  1. master 现行 pre-commit(origin/master 59d1c2b git show 实测):cargo fmt --check 失败且输出无 Diff in 行 → 退回 rustfmt --edition 2021 --check 只查 staged .rs;cargo/rustfmt 缺失均 exit 0(fail-open)。在 Windows 上 cargo fmt --check 对本工作区 ~1.5k target 根必然 os error 206(CreateProcess 32767 UTF-16 上限,审计与正文均已实测复现)——即在 owner 的主开发平台上,该门永久停留在 staged-only + fail-open + 硬编码 edition 2021,非 staged 文件的漂移永远不会被拦。漂移已有实证:merge-base 8b48c16 的 tests/d11_pipeline_squote_carrier_regressions.rs 未格式化(rustfmt --check 在 :52/:137 有 diff;该具体漂移后已由别的 PR 修掉,但机制漏洞仍在)。Linux/macOS 上 cargo fmt 可跑完、覆盖仍是全树——两平台门的覆盖面本来就不对称,staged fallback 让 Windows 侧永久残缺。
  2. owner 2026-09-26 指令「fmt must be a commit hook」的本意是整树约束;staged-only 是同一症状的降级版。
  3. 本 PR 机制已经两轮审计核实(2026-11-16T05:06Z 第3轮 / 12:07Z 第4轮):cargo metadata --no-deps 取 workspace_members 的 target src_path 全集(与 cargo fmt 同覆盖)、按 edition 分组、UTF-16 cmdline 12000 上限分批、缺 python/cargo/rustfmt、metadata 畸形、单路径超限、任一批非零 → 全 fail-closed;head 实测 1486 roots / 10 batches / exit 0,check_rustfmt_test.py 15/15,CI 三红均为 issue2875 基线签名。
  4. Python 不是新增依赖面:仓库 scripts/ 已有 13 个 .py 工具/门(check-api-ledger.py、check-marker-literals.py 等),本 PR 属同类。

代价如实列出:+591 行 Python;要求安装钩子的提交者具备 Python 3(pre-commit 已对 python3/python 做真实版本探测,Store 别名 stub 不误判);完全替代 cargo fmt 而非以它为首选——metadata 覆盖等价性已由审计核实,但这是用自有批处理换 canonical 工具,属真实取舍。若队长更看重 canonical-first,可考虑「cargo fmt 首选 + 本门仅在其无法完成时接管」的混合形——但那会重新引入两套覆盖语义,本 PR 的统一全量门更易推理。

对 #3564 的联动:本 PR 与 #3564 同线(git merge-base = b7086c3 = 本 head;#3564 的 4ffb2ba85 chore: adopt the reviewed bounded formatting gate prerequisite 即采纳本门)。裁决采纳本方向 → 本 PR rebase 消解 pre-commit 冲突后先行;#3564 rebase 时 adopt 提交自然落空,只剩 exec.rs/path.rs/issue3316 钉,与 s10 车道「一 PR 一事」意见一致。若队长改采 staged fallback → 本 PR 方向被否、#3564 摘除门文件后可独立推进 exec 修复(其机制已核与 GNU 一致)。

队长时间线:第3轮 PENDING 的唯一阻塞 B1(2026-11-16T05:06Z)与第4轮复核(2026-11-16T12:07Z)都把「两方案取舍」列为待裁点,本评论即该输入;是否采纳由队长定。

未跑/VOID 的腿:无(纯裁决评论,未动代码、未起构建;所引数字均来自 gh/git 只读核验与两轮既有审计)。

@caomengxuan666

Copy link
Copy Markdown
Member Author

【WIN-AGENT-BATCH-SUMMARY】
M3 车道批次汇总(3 条归类裁决,均只出裁决评论,未合并未关闭、未动代码)

阻塞项:三条均需队长/owner 拍板后才有下一步。

未跑/VOID 的腿:全部腿均未跑——本批为只读裁决(gh/git/diff/源码核验),无代码改动、无构建、无测试执行。

Conflict resolution: scripts/git-hooks/pre-commit kept the PR's
fail-closed batched check-rustfmt.py gate. Master's staged-file
fallback (#3658) is the weaker same-symptom workaround this PR
supersedes (whole-workspace coverage vs staged-only, fail-closed vs
fail-open); the audit trail on #3569 recommends this direction.

Also applies rustfmt --edition 2021 to four master-side files
(src/executor/{external_inner,external_redirects,trap_exec}.rs,
tests/pipeline_stderr_redirect_streaming.rs) that drifted unformatted
under commits that bypassed full-workspace fmt coverage; required so
the merged tree passes the gate being introduced.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@caomengxuan666
caomengxuan666 marked this pull request as ready for review November 18, 2026 08:29
@caomengxuan666
caomengxuan666 merged commit 12a37ad into master Nov 18, 2026
10 of 12 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/windows-rustfmt-batch-gate branch November 18, 2026 08:29
caomengxuan666 added a commit that referenced this pull request Nov 18, 2026
…#3564)

* fix(exec): rebind the exec target with GNU full_pathname (Refs #3316)

builtins/exec.def:172 rebinds the target word with full_pathname
(general.c:931-943): an absolute word verbatim, otherwise
sh_makepath(NULL, word, MP_DOCWD|MP_RMDOT) -- the cwd, a '/', and the
word with exactly one leading "./" removed. The exec builtin instead
used the session-anchored resolved program (cwd join keeping "./") as
the execve filename and script $0, and its failure reports ran a
different, over-eager canonicalization (dropping every "." and "..").

One full_pathname helper now produces the execve filename (so a #!
script's $0), the ENOEXEC re-entry's $0, and every exec failure report
name, over the shared spawn funnel's word (path::spawn_exec_name).

Generated with [Devin](https://devin.ai)
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* fix(tooling): batch the workspace rustfmt hook on Windows

Enumerate workspace target roots with cargo metadata and bound each rustfmt argv below the Windows command-line limit. Fail closed if required tooling is missing. Include the two pre-existing rustfmt wrapping corrections so the gate passes without bypasses.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* fix(tooling): reject incomplete workspace formatting metadata

Reject missing workspace member packages, empty target sets, and targets
without source paths before launching any rustfmt batch. Malformed metadata
must not silently reduce the gate's coverage and still report success.

Preserve edition fallback, target deduplication, CLI and bounded batching.
All 15 checker tests pass; the real gate checks 1486 targets in 10 batches.

Refs #3569.

Generated with [Devin](https://devin.ai)
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* fix(exec): preserve Unix spelling in full_pathname

GNU builtins/exec.def:151/172 exec_builtin rebinds the target through
general.c:931 full_pathname. general.h:264-270 ABSPATH recognizes only a
leading slash on Unix, and lib/sh/makepath.c:66 sh_makepath copies the
cwd and remaining word unchanged after stripping one leading ./.

Restrict backslash folding and DOS-drive recognition to Windows. Unix
backslashes in filenames and cwd remain ordinary bytes; D:/ is relative.
Preserve the original Windows behavior and the exec target owner.

Match the test fixture's Unix PWD to Command::current_dir, as in a real
parent shell. The distinct pre-existing stale-PWD repair defect is #3570.

New Linux pins: 4 pass/3 fail before, 7 pass after. Adjacent exec/argv0/
name diagnostics: 35 pass. Existing Windows pin: 1 pass. Full formatting
gate: 1487 targets in 11 batches.

Refs #3316, #3564.

Generated with [Devin](https://devin.ai)
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>

---------

Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
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.

1 participant