Skip to content

env-import: BASH_FUNC import diagnostic split; lock imported LINES child-env parity (wave N1) (Refs #2728, #2565) - #3134

Merged
caomengxuan666 merged 5 commits into
masterfrom
fix/N1-wave1
Nov 10, 2026
Merged

caomengxuan666 merged 5 commits into
masterfrom
fix/N1-wave1

Conversation

@caomengxuan666

@caomengxuan666 caomengxuan666 commented Nov 8, 2026 •

Copy link
Copy Markdown
Member

N1 组(180 单令第一波):#2728 修复 + #2565 回归锁。基底 88047f50。

Refs #2728
Refs #2565

#2728 — BASH_FUNC_*%% 导入的静默/诊断劈分与形状检查

GNU 决策树(variables.c initialize_shell_variables :395-446 + builtins/evalstring.c SEVAL_FUNCDEF :465-486、SEVAL_ONECMD :577):

  • 原始值过不了 STREQN("() {", string, 4) 前缀检查(variables.c:404,不 trim)→ 根本没进入函数导入:静默、函数未定义、$?=0。旧 rubash 先 trim 再剥 (),(){ echo OK; } 与前导空格形都被当成定义接受(lax shape)。
  • 进入导入但解析失败 → 打印解析器自己的诊断(近 token 类带出错行回显、EOF 类带 from \{' command on line 0形),再跟一行error importing function definition,且 last_command_exit_value = EXECUTION_FAILURE(variables.c:440)使 $?=1。旧 rubash 把这类与下一类合并成 warning+error 一对、且 $?` 恒 0。
  • 解析成功但不是恰好一个直定义(ShellShock 形)→ 只打 warning: <name>: ignoring function definition attempt + error 行;SEVAL_ONECMD 下后续行的内容根本不读,多行值里第二行的命令不影响定义成立。

修法(src/executor/function_env.rs、src/executor/init.rs):新增 classify_exported_function_value 按上树分类(NotAFunctionValue / ParseFailure / IgnoredAttempt / Defined),合成文本用真名 name + " " + value 解析;解析诊断从解析器 marker 规格转换到 GNU 的字符串输入行号(首行 = line 0),近 token 类按 GNU 形回显出错行;导入失败经 ImportedFunctionFailure 枚举回传,init 按类打印,并把任一失败映射到 Executor 初始 exit_code = 1。parse_exported_function_body 保留为 carrier 对比调用方的 defined-or-not 薄封装。

钉 tests/issue2728_bash_func_import_diagnostic_split.rs(11 格):静默三格(非函数值 / 无空格 / 前导空格)、garbage 与 if; 的解析诊断三行形、ShellShock warning-only 形、未闭合 EOF 诊断形、合法定义运行、尾 ;/重定向仍定义、换行后命令不读、多行函数体导入。头上 11/0;fail-first 移植基底 88047f50 实跑 3 过 / 8 红,红格恰为缺陷格(见车道 REPORT)。

#2565 — 导入的 exported LINES 不达子环境

在基底 88047f50 上已不可复现:captain 立单时验收形态(env LINES=999 COLUMNS=200 <engine> -c 'env'、外部子进程 /usr/bin/env、脚本文件、-l、仅 LINES、赋值后)逐一实测,LINES 与 COLUMNS 同步到达子环境、declare -p 两名都在。判断为 env 导入/快照种子面在 #3083/#3101 一线合入后被顺手修掉(本组不动代码)。本 PR 只交回归钉 tests/issue2565_imported_lines_child_env.rs(4 格:env 内建面、真实子进程面、declare -p 导出绑定面、展开面),把该行为锁死防再退。关单与否请队长按「已修待锁」口径裁。

本 PR 删除了什么

  • function_env.rs 里旧的手工形状检查链:先 trim、剥 ()、trim_start、再对闭合括号后的尾随内容做词法复检的整段(被 classify_exported_function_value 的 GNU 决策树分类替代);导入失败回传通道由 Vec<String> 改为类型化枚举,旧的字符串通道随之删除。
  • init.rs 里「所有导入失败统一 warning+error 两行」的旧打印块(改为按失败类打印)。
  • 无其他删除;未删除任何测试。

验证(车道本地,队长复核为准)

  • 钉:issue2728 头 11/0、基底 3/8(fail-first 红格恰为缺陷格);issue2565 头 4/0、基底 4/0(基底已不可复现,钉为回归锁)。
  • 邻茎:issue1276 2/0、issue2723 2/0、issue2212 15/0。
  • RUSTFLAGS="-D warnings" cargo check(lib+bins)零警告;cargo fmt --check 干净;python3 scripts/check-marker-literals.py OK。
  • GNU 探针对照矩阵全格 SAME(stderr 逐行、DEFINED/UNDEF、$?)。
  • lib 双边:基底 1206/0/4;头部 1204 过 / 2 红 / 4 忽略,两红(dap_pause_during_a_free_run 时序 flake、spawn_whitelisted_keeps_extra_handles_at_their_numbers fd 压力形)隔离复跑均绿,实效 1206/0/4,双边总数同为 1210、无新失败名。

GNU splits a failed BASH_FUNC_*%% import three ways (variables.c
initialize_shell_variables + builtins/evalstring.c SEVAL_FUNCDEF):
a value that fails the raw () { prefix check is silently not a
function; a value that engages the import but fails to parse prints
the parser diagnostics plus the error line and seeds $? = 1; a
value that parses to something other than one straight definition
prints the ignoring-attempt warning plus the error line.

Refs #2728
An imported exported LINES must reach the child environment
exactly like COLUMNS (variables.c binds both with
att_exported|att_imported; the exported rebuild treats the two
names identically). On the current master these pins already pass;
they lock the behaviour the issue reported broken.

Refs #2565
classify_exported_function_value mirrors the GNU decision tree
(variables.c:395-446): the () { check runs on the RAW value (no
trim, so (){ and a leading space never engage the import and stay
silent); the rebuilt definition name + space + value is parsed and
a parse failure surfaces the parser's own diagnostics converted to
GNU's string-input line numbering (first line is line 0), with the
offending line echoed for the near-token class; a value that parses
to anything other than one straight definition takes the
SEVAL_FUNCDEF warning path (evalstring.c:465-486), with
SEVAL_ONECMD's later-lines-are-never-read rule for multi-line
values. Any failed import seeds $? = 1 (variables.c:440
last_command_exit_value = EXECUTION_FAILURE).

The import now returns ImportedFunctionFailure (Parse with
diagnostics, or IgnoredAttempt) and init.rs prints exactly the
lines GNU prints per class before the single shared error line.
parse_exported_function_body stays as a thin defined-or-not wrapper
for the carrier-comparison caller.

Refs #2728
@caomengxuan666 caomengxuan666 changed the title fix(env-import): BASH_FUNC import diagnostic split; lock imported LINES child-env parity (wave N1) env-import: BASH_FUNC import diagnostic split; lock imported LINES child-env parity (wave N1) (Refs #2728, #2565) Nov 10, 2026
@caomengxuan666
caomengxuan666 marked this pull request as ready for review November 10, 2026 03:56
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