Skip to content

fix(executor): name the node kind in emulated cp failed-create diagnostic - #3636

Merged
caomengxuan666 merged 2 commits into
masterfrom
fix/3635-cp-create-kind-diagnostic
Nov 16, 2026
Merged

caomengxuan666 merged 2 commits into
masterfrom
fix/3635-cp-create-kind-diagnostic

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Summary

The emulated cp printed a bare cp: cannot create 'N': <errno> at all three failed-create faces; GNU coreutils copy.c copy_internal names the node kind — cannot create regular file for file targets, cannot create directory for the tree branch. This drops in the kind word (selected by source.is_dir() on the shared Err branch), closing the builtins.tests cp /dev/null /zero-length-file-$$ residual in the run-builtins lane (#2666).

Pinned by tests/issue3635_cp_create_kind_diagnostics.rs (fail-first verified vs master).

Refs #3635, Refs #2666

…nostic (Refs #3635)

GNU coreutils copy.c copy_internal names what it failed to create —
'cannot create regular file' for file targets, 'cannot create
directory' for the recursive-tree branch. The emulation printed a
bare 'cannot create' at all three faces (null-source precreate, the
per-unit write_bytes path, and the main cp_copy_file/cp_copy_tree
result), dropping the kind word — the builtins.tests
'cp /dev/null /zero-length-file-$$' residual in the run-builtins
lane (#2666). The shared Err branch now selects the kind by
source.is_dir() so the tree copy keeps 'directory'.

Refs #3635, Refs #2666

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

Copy link
Copy Markdown
Member Author

【WIN-AGENT-AUDIT】
PR #3636 第1轮 — 建议:FAIL(产品修法正确;钉本身有两处硬伤)
head: dc5abc7 base(merge-base): 8eb0787 文件: 2 个 +89/-3
关联 issue: #3635(状态:open,我核过的时间:2026-11-16 23:05 本地)

机制核查:

  • 与 GNU 一致:coreutils 9.4 cp 的失败诊断带节点类型 —— 文件目标 cannot create regular file '<dst>',目录目标 cannot create directory '<dst>'(src/executor/external_file_builtins.rs:1658/1774 直接补 regular file,1890 的共享 Err 分支按 source.is_dir() 选 kind)。head 在非 root 环境与 GNU 逐字节一致(含 rc=1,见 GNU 对照)。
  • 无关改动:无。未碰 src/lexer/continuation.rs。
  • 残差(既存,非本 PR 账,建议另开 issue):cp_copy_tree(external_file_builtins.rs:4990-5034)把嵌套节点的 io::Error 直接 ? 抛到顶层,外层再用顶层目标路径 + source.is_dir() 的 kind 报告;GNU 是在失败节点上按该节点类型报自己的路径。所以“目标目录创建成功、子文件创建失败”的形状(如目标内含只读子目录)head 会报 cannot create directory '<top>'(kind 与路径都不是失败节点)—— base 也错,但 base 不带 kind,head 多了一个可能错的 kind 词。不阻断本 PR 的单点目标,建议后续 issue 把诊断下沉到 cp_copy_tree/cp_copy_file 的失败节点。

腿(本机 WSL Linux 为 root,钉写 / 的 EACCES 形状必须先降权;用 setpriv --reuid=65534 复现,且每次清掉 /zero-length-file-x3635、/zero-dir-x3635):

  • 钉自跑(head,--test-threads=1):issue3635_cp_create_kind_diagnostics 2 passed / 0 failed
  • 钉自跑(head,默认并行):3 次连跑分别 0 passed / 2 failed、1/1、1/1 —— 红且不稳定(F1)
  • fail-first:base 8eb0787 同钉(--test-threads=1、同降权)0 passed / 2 failed,红态正是缺 kind 的 cannot create '…'
  • lib 双边(Windows 本机):head 1351 passed / 1 failed(失败名 {api::consumer_tests::issue2084_session_end_restores_host_process_state})/ base 8eb0787 1351 passed / 1 failed(同一名)/ 差集 ∅
  • -D warnings:cargo check --lib --bins 在 Windows clean;但 RUSTFLAGS="-D warnings" cargo test --no-run --test issue3635_cp_create_kind_diagnostics 在 Linux 上失败:error: unused imports: PathBuf and Path(钉第 21 行)→ 本 PR 新增警告(F2)
  • 卫生:rustfmt --check 2 文件 clean;marker-lint OK;utf8 clean
  • CI(run 43617506188,head dc5abc7):红 3 项,唯一红均为 api::consumer_tests::issue2875_input_procsub_child_runs_as_rubash_shell(基线);其余全绿。注意本 PR 的钉不在 CI 执行面内(Rust tests 只跑 lib)。
  • GNU 对照:GNU bash 5.3.20 + coreutils 9.4(WSL x86_64,setpriv --reuid=65534 非 root)。脚本 target/probe-3636-gnu.sh:
    cp /dev/null /zero-length-file-x3635 → GNU cp: cannot create regular file '/zero-length-file-x3635': Permission denied + rc=1;rubash head 逐字节同。
    cp -r /tmp/rb3636-src/a /zero-dir-x3635 → GNU cp: cannot create directory '/zero-dir-x3635': Permission denied + rc=1;rubash head 逐字节同。diff 两文件 → IDENTICAL。

F 点:

  • F1(阻断,钉质量):两格共用同一 scratch 目录名(rubash-3635-<pid>,无 per-test tag)且都写 script.sh;默认并行执行时互相覆盖脚本,head 上 3 连跑出现 0/2、1/1、1/1。复现:setpriv --reuid=65534 --regid=65534 --clear-groups <test-bin>(默认线程数)。修法:tempdir(format!("rubash-3635-{tag}-{pid}")),两格各用独立 tag(同目录测试一律如此)。
  • F2(阻断,卫生/警告门):tests/issue3635_cp_create_kind_diagnostics.rs:21 use std::path::{Path, PathBuf}; 在 Linux 上未使用 → RUSTFLAGS="-D warnings" cargo test --no-run --test issue3635_cp_create_kind_diagnostics 编译失败(Windows 因 #![cfg(unix)] 空 crate 而不报,所以容易被漏掉)。修法:删掉该 import。
  • F3(残差,不阻断):嵌套树失败时的诊断节点/kind 见「机制核查」末条。

续作记录:本轮未动代码(按分工,FAIL 只发报告)。
未跑/VOID 的腿:无(root 环境导致的首次跑已用降权重跑,非 VOID)。

@caomengxuan666

Copy link
Copy Markdown
Member Author

【WIN-AGENT-AUDIT】PR #3636 第2轮 — REWORK 完成,建议:PASS(待 CI 复核)
head: 29fd2ac base(merge-base): 8eb0787 文件: 2 个 +90/-3
关联 issue: #3635(状态:open)

续作记录:

  • 29fd2ac test: isolate issue3635 scratch dirs per case, drop dead import (Refs #3635) —— F1+F2 合并修复(同一文件,测试纪律向)。push 前已 fetch 复核远端 head 仍为 dc5abc7,未 force-push。

F 点逐条回应:

  • F1(已改):run_rubash 增加 tag: &str 参数,scratch 目录改 rubash-3635-{tag}-{pid},两格分别用 regular-file / directory —— 与同目录测试惯例一致,并行不再互踩 script.sh。验证:WSL /root/rubash-wsl-t3(cargo 1.98.1)以 setpriv --reuid=65534 --regid=65534 --clear-groups(非 root,复现 EACCES 形状)跑默认并行 3 连:2 passed; 0 failed ×3(修复前 head 上为 0/2、1/1、1/1 不稳定红)。
  • F2(已改):删 use std::path::{Path, PathBuf};(整行未用——temp_dir().join() 不需具名导入)。验证:RUSTFLAGS="-D warnings" cargo test --locked --test issue3635_cp_create_kind_diagnostics --no-run(Linux)→ clean,0 警告(修复前 E0432 级 unused import error)。
  • F3(残差,维持不阻断):嵌套树失败时诊断节点/kind 仍报顶层目标 —— 既存面非本 PR 账,建议另开 issue(第 1 轮已述,本轮不动)。

腿(本轮增量;产品面零改动):

  • 钉自跑:head 29fd2ac Linux 非 root 默认并行 3× 2/0;--test-threads=1 形态第 1 轮已 2/0。
  • fail-first:第 1 轮 base 8eb0787 已跑 0/2 全红(缺 kind 的 cannot create '…'),与声称一致;本轮 diff 不触产品代码,结论沿用。
  • lib 双边:仅 tests/ 文件改动,不进 lib;第 1 轮差集 ∅ 沿用。
  • -D warnings:见 F2,Linux test compile clean;lib/bins 第 1 轮 clean。
  • 卫生:staged-file rustfmt fallback clean;marker/utf8 面未触。
  • CI:新 head run 进行中,出结果后补记;预期仅剩基线 issue2875。
  • GNU 对照:第 1 轮已核(GNU bash 5.3.20 + coreutils 9.4,setpriv 非 root):cp /dev/null /zero-length-file-x3635 → cp: cannot create regular file '…': Permission denied rc=1;cp -r …/a /zero-dir-x3635 → cannot create directory '…' rc=1,rubash head 逐字节一致。本轮产品零改动,结论沿用。

未跑/VOID 的腿:无。

@caomengxuan666

Copy link
Copy Markdown
Member Author

【WIN-AGENT-AUDIT】
PR #3636 第3轮 — 建议:PASS
head: 29fd2ac base(merge-base): 8eb0787 文件: 2 个 +90/-3
关联 issue: #3635(状态:open,我核过的时间:2026-11-16 本地)

机制核查:

  • emulated cp 的三处 failed-create 诊断补上 kind 词:regular file(两处非递归目标)与按 source.is_dir() 分派的 directory/regular file(递归树分支)。对照 GNU coreutils 9.4 copy_internal 实测三形状全部一致:cp /dev/null /x → cannot create regular file;cp -r dir/a /x(dst 不存在)→ cannot create directory '/x';cp -r file /x → cannot create regular file(file 源走 regular file,is_dir() 分派正确)。rc 均 1。
  • diff 无无关改动;无桥接/翻译层。

腿:

  • 钉自跑:issue3635_cp_create_kind_diagnostics — WSL(以 nobody 身份跑,root 会绕过 / 写权限使钉假红)2 passed / 0 failed;Windows 编译通过、cfg(unix) 下 0 tests(预期)。
  • fail-first:merge-base 8eb0787 + 钉文件 — 0 passed / 2 failed,红名 = {cp_regular_file_create_failure_names_regular_file, cp_directory_create_failure_names_directory},均报旧串 cannot create '<dst>'(无 kind 词),与 PR 声称一致。
  • lib 双边:head 1249 passed / 0 failed / 4 ignored;base 同 1249/0/4;差集 ∅。
  • -D warnings:本 PR 两文件 0 警告;crate 级仅存量基线警告 unused import std::io::Read(src/executor/command_substitution_values.rs:4,来自 merge-base 上的 12aa434,非本 PR)。
  • 卫生:rustfmt --check 两文件 clean;marker-lint OK;utf8-boundary clean。
  • CI(head 29fd2ac):红 = {GNU regression goldens and canaries, Regression pin stem census};已与 master HEAD 8a83879 的同名 job 逐一核对——master 上同两 job 同样红(census 列出的是一批待修 pin 的存量红),归因基线,非本 PR。Rust tests / macOS / cross-target / niubash builds 全绿(基线 issue2875 本轮未复现)。
  • GNU 对照:coreutils 9.4(WSL,nobody 身份,脚本 target/probe3635-gnu.sh)三形状与 rubash head 逐字一致。

F 点:无。

续作记录:本轮未动代码(29fd2acf6 的 scratch per-test tag + 删未用 import 已在远端 head 上,我独立复核了全部腿)。

未跑/VOID 的腿:无(注:cargo fmt --check 在本机旧 hook 下触发 os error 206,已用 rustfmt --edition 2021 --check 逐文件替代并通过)。

@caomengxuan666
caomengxuan666 marked this pull request as ready for review November 16, 2026 15:29
@caomengxuan666
caomengxuan666 merged commit cee9edc into master Nov 16, 2026
10 of 12 checks passed
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