Skip to content

fix(describe): report the PATH file for env off Windows (Refs #2642) - #3451

Merged
caomengxuan666 merged 2 commits into
masterfrom
fix/2642-command-v-env
Nov 15, 2026
Merged

caomengxuan666 merged 2 commits into
masterfrom
fix/2642-command-v-env

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

根因

#2514 的残差。#2514 把 describe 面的仿真注册表披露门限到 Windows 面,但 env 不是仿真注册表 claim——它是 builtin 表的一行(src/executor/builtin_table.rs 的 BuiltinRow { name: "env", handler: H::Env }),所以 describe 面在 is_enabled_shell_builtin_name("env") 处短路,command -v env 印裸名、command -V env 印 env is a shell builtin,从未走到 PATH 分支。

GNU 锚点

GNU bash 5.3 没有 env builtin(无 builtins/env.def,env 是 coreutils 程序):describe_command(builtins/type.def:211,command 在 builtins/command.def:113 调用、type 在 builtins/type.def:180 调用)按 alias → keyword → posix special builtin → function → builtin → 磁盘文件顺序解析,env 落到磁盘文件分支:command -v env → /usr/bin/env,command -V env → env is /usr/bin/env,type -t env → file。

修法(本 PR 第二提交)

  • builtin_table.rs 新增单一典范集 NON_GNU_BUILTIN_NAMES = &["env"](GNU 表没有的行,目前仅 env);compgen -A command 的 [completion] compgen -A command 把 env 列为内建候选,GNU 无此内建(#1795 残面) #2538 过滤改引该集(行为不变)。
  • lookup_paths.rs::is_enabled_shell_builtin_name:非 Windows 上该集名字不视为 describe builtin。codegraph 核实该谓词全仓仅两个调用者,都是 describe 面(describe_name_with_io / describe_name_all_with_io),所以门控恰为 describe-only;执行路由、enable -n env、compgen -b、builtin env、help env 均不动。
  • docs/builtins.md 散文同步(§1 披露段、§2 清单说明、§3 混合形态段)。

本 PR 删除了什么

未删除任何产品行为或公开面:仅 describe 面在非 Windows 上对 env 的回答由 builtin 形改为 PATH 文件形;删除的是一处已钉死的错误期望(issue2036_introspection_env_reports_builtin 翻转为文件答案,文件本身为 unix-only;Windows 面行为由 issue2036_s2_introspection_windows 另钉,不动)。

验证(UNVERIFIED-BY-CAPTAIN)

  • 新钉 tests/issue2642_command_v_env_regressions.rs(5 测试:fakebin 精确路径形、ambient PATH 与 GNU 同形、空 PATH 未找到形、执行面仍进程内形、enable -n env 仍可禁用形)。
  • 待队长复核轮在 box 上直跑:基底 fail-first(新钉红)→ 头全绿、全量 lib/base 对齐、RUSTFLAGS="-D warnings" check、hygiene + fmt。

Refs #2642

GNU describe_command (builtins/type.def:211) has no env builtin —
env is a coreutils program — so on unix the describe faces must
report the PATH file (command -v env -> /usr/bin/env,
command -V env -> 'env is /usr/bin/env', type -t env -> file).
This nail currently fails on master 3ef22b8, where the faces
report the bare name / 'env is a shell builtin' because the
builtin-table row short-circuits the PATH branch (#2514 fixed the
emulation-registered names but missed this row).

Refs #2642
#2514 residual: #2514 gated the emulation-registry disclosure to
the Windows face, but env is not a registry claim — it is a
builtin-table row (BuiltinRow { name: "env", handler: H::Env }),
so the describe faces short-circuited on
is_enabled_shell_builtin_name("env") and never reached the PATH
branch: command -v env printed the bare name, command -V env
printed 'env is a shell builtin'.

GNU anchor: bash 5.3 has no env builtin (no builtins/env.def;
env is coreutils), so describe_command (builtins/type.def:211,
called by command at builtins/command.def:113 and by type at
builtins/type.def:180) resolves it as a disk file: command -v env
-> /usr/bin/env, command -V env -> 'env is /usr/bin/env',
type -t env -> file.

Fix, describe-only (the #2514 shape):
- builtin_table.rs gains the single canonical set
  NON_GNU_BUILTIN_NAMES = &["env"] (table rows GNU does not ship;
  currently only env, the Windows emulation face for a platform
  with no /usr/bin/env). compgen -A command's #2538 filter now
  references it (behavior unchanged).
- lookup_paths.rs::is_enabled_shell_builtin_name returns false for
  that set off Windows. Codegraph-verified, the predicate has exactly
  two callers in the tree, both describe faces
  (describe_name_with_io / describe_name_all_with_io), so the gate
  is exactly describe-only; dispatch, enable -n env, compgen -b,
  builtin env and help env keep the unified projection.
- docs/builtins.md prose synced (§1 disclosure, §2 list note, §3
  hybrid-form paragraph).

Refs #2642
@caomengxuan666

Copy link
Copy Markdown
Member Author

【WIN-AGENT-AUDIT】
PR #3451 第1轮 — 建议:PASS
head: 84e1b06 base(merge-base): 3ef22b8 文件: 6 个 +305/-21
关联 issue: #2642(状态:open,我核过的时间:2026-11-15 08:4x CST)

机制核查:

  • is_enabled_shell_builtin_name 新增 !cfg!(windows) && NON_GNU_BUILTIN_NAMES.contains(&name) 早退(lookup_paths.rs):我核实了该谓词全部 4 个调用点都在 type_describe.rs 的 describe_name_with_io/describe_name_all_with_io 内——确为 describe-only,dispatch/enable/compgen -b/builtin env 不受影响,与正文声称一致。
  • GNU 锚点成立:GNU bash 无 env builtin(无 builtins/env.def),describe_command(builtins/type.def:211)落盘文件分支;compgen -A command 过滤改引同一 NON_GNU_BUILTIN_NAMES 规范集(complete.rs),单一典范无双份名单。
  • Windows 面按设计保留 builtin 答案(cfg!(windows) 在 Windows 编译期为真,分支整体失效)——与 issue2036_s2_introspection_windows 钉口径一致。
  • diff 逐文件通读:docs/builtins.md 为散文同步;无顺手无关改动;无桥接/翻译层。
  • 可疑点:无。

腿(逐项给数字与名字):

  • 钉自跑:issue2642_command_v_env_regressions 与 issue2036_precedence_introspection_regressions 均 #![cfg(unix)](且用 std::os::unix::fs::PermissionsExt + #!/bin/sh fake env)——本机 running 0 tests,VOID。head 的 CI「Rust tests」(Linux)pass,该 stem 在 Linux CI 真实跑绿。
  • fail-first:本机无法复现(unix-only 钉 + 修法被 cfg!(windows) 门控,Windows 二进制两侧行为相同)。间接证据:base 上 issue2036 旧钉期望 env is a shell builtin/t=builtin/v=env 在 unix base 是绿的(本 PR 正是翻转它),即 base+unix 必然输出 builtin 答案 = 新钉断言的反面;head+unix 绿由 CI 证。unix 侧 fail-first 建议队长 Linux 复核轮直跑补齐。
  • lib 双边:head 失败名集 {api::consumer_tests::issue2084_session_end_restores_host_process_state}(1349/1/4)/ base 失败名集 {同一名}(1349/1/4)/ 差集 ∅(issue2084 为本机既有环境失败,fix(parser): token-level errors preempt compound EOF reports (#3405) #3423 轮已在两侧复现)。
  • -D warnings:RUSTFLAGS="-D warnings" cargo check --locked --lib --bins rc=0。
  • 卫生:rustfmt --check 5 个 PR 文件全 OK;marker-lint rc=0;utf8-hygiene clean。
  • CI:head 84e1b06 全绿(Rust tests / Rust tests (macOS) / GNU regression goldens and canaries / Cross-target darwin / Cross-target linux/android / Compatibility CLI tests / Shell functionality tests / Windows tests compile check / API ledger tripwire / niubash builds)——无红腿。
  • GNU 对照:WSL bash = GNU bash 5.3.20(1)-release(script-file,target/probe-env-gnu.sh):command -v env→/usr/bin/env、command -V env→env is /usr/bin/env、type -t env→file、type env→env is /usr/bin/env、type -a env→仅文件行、type -p/-P env→/usr/bin/env——与钉期望一致。Windows 面探针(target/probe-env.sh):head 与 base 输出逐字相同(env/env is a shell builtin/builtin/env is a shell builtin),Windows 行为不变已证。

F 点:无

续作记录:无

未跑/VOID 的腿:

  • unix 侧钉自跑与 fail-first 本机 VOID(cfg(unix) + cfg!(windows) 门控);head 绿已由 Linux CI 覆盖,fail-first 建议队长 Linux 复核轮补直跑。
  • 正文含 UNVERIFIED-BY-CAPTAIN 标注(作者自标待复核),本报告即复核输入。

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