Skip to content

[Bug 批量·第三轮] oil spec 大规模差分: alias 展开语义/语法错误接受度/数组赋值族/算术错误码/jobs-dirs 内置 - 219+ 项差异(已跑 1/2 套件) #22

Closed

Description

@caomengxuan666

[Bug 批量·第三轮] oil spec 大规模差分: alias 展开语义 / 语法错误接受度 / 数组赋值族 / 算术错误码 / jobs-dirs 内置 —— 219+ 项差异(已跑 1/2 套件, 后台继续中)

方法与规模

延续差分测试方法,这次引入 oilshell/oil 官方 spec 套件(228 个 .test.sh 文件、数千用例,社区维护、覆盖 bash/dash/mksh/zsh/ksh93 多 shell 行为)作为差分输入:驱动 spec-difftest.sh 逐个用例在 GNU Bash(Git Bash 5.2)与 winuxsh 0.10.2 下运行,逐字节对比 stdout + 退出码(以 bash 实际输出为基准;## BUG bash 用例与文件头无 bash 的用例跳过;argv.py 辅助已用 bash 重写保证两侧一致)。

已跑约一半套件(字母序到 builtin-),产出 219 项 DIFF;剩余文件(case/expansion/glob/heredoc/io/jobs/loop/quoting/redirect/subshell/tilde/var- 等)后台继续运行,完成后补充。 完整清单见 winuxsh 仓库 scripts/probe/suites/diffs.txt。

已人工复现确认(最小用例, 双侧对照)

A. 单引号中的 alias 也被展开(bash 只展开未引用词)

shopt -s expand_aliases
alias hi='echo hello world'
'hi' || echo 'expected failure'
# bash: hi: command not found / expected failure (单引号不展开)
# rubash: hello world (!!) — 单引号词也被 alias 展开
  • 影响:所有用引号防御 alias 展开的脚本('git' 这类安全写法)失效。

B. 接受 bash 报语法错误的输入(语法宽松度)

a= (1 2)
# bash: syntax error near unexpected token `('  (rc=2)
# rubash: rc=0, 静默接受
  • 同类(bash rc=2 / rubash rc=0):array.test.sh: space before ( in array initialization、bugs.test.sh: First word like foo$x()、builtin-echo.test.sh: echo builtin should disallow typed args、bool-parse.test.sh: Not allowed: [[ ) ]]、assign-deferred: is 'builtin' prefix and array allowed?。rubash 对一批 bash 拒绝的语法静默放行——解析器过度宽松,错误脚本会悄悄跑出错误结果。

按主题分类的代表差异(diffs.txt 统计)

1. alias 语义(15 项, alias.test.sh)—— 新领域

  • Basic alias、define and use alias on a single line、Expansion of alias with variable、Alias must be an unquoted word(B/A 两段已见 A 项单引号问题)、Alias with a quote in the middle(bash rc=2 语法错误, rubash rc=0)、Two aliases in pipeline(bash 正常, rubash rc=127 管道中 alias 完全失效)、alias with redirects(rubash rc=1)、unalias -a(rubash rc=1)、alias without args lists all aliases(rubash rc=1)等。

2. 数组赋值族(约 60 项, append/array-assign/array-basic/array-compat/array-sparse/array)

  • +=(s+=(my array)、myarray+=s、array-sparse: += rc=1)、稀疏数组负索引 a[i]=v(rc=1)、${@:offset:length}(bash rc=1 / rubash rc=0)、Multiple subscripts not allowed(bash rc=1 / rubash rc=0)、declare builtin doesn't allow spaces(rubash rc=1)、value.BashArray internal representation(rubash rc=1)、Regression: ${a[@]@Q} crash(两侧都 127 但行为不同)等。
  • 注意多数 rc 两侧为 0,差异在输出内容(如空数组插值 4 ways to interpolate empty array)。

3. 算术错误语义(约 25 项, arith/arith-context/arith-dynamic)

  • Constant with quotes like '1'、No floating point、Negative exponent、nounset with arithmetic、undef[0] with nounset、Increment undefined variables with nounset:bash 报错 rc=1(并有错误消息), rubash rc=0 静默——算术错误被吞。
  • Comment not allowed in multiline arithmetic 等两侧 rc=127 但输出不同。

4. background/jobs(17 项, background.test.sh)

  • wait -n(两侧 rc=0 输出不同)、Builtin in background(rubash rc=1)、External command in background(rc=1)、Wait for job and PIPESTATUS(rubash rc=55)、jobs prints one line per job(bash rc=127 / rubash rc=1)、jobs -p(rubash rc=1)、Async for loop(rc=1)。jobs 内建族整体异常。

5. builtin-dirs(12 项, builtin-dirs.test.sh)

  • pushd/popd 返回错误(rubash rc=1)、dirs -v(rc=1)、dirs -p(rc=1, 简化复现 rc=0 需栈上下文)、dirs tilde 转换(rc 126/127)等——目录栈内建(pushd/popd/dirs -p/-v)整体异常。

6. brace-expansion(16 项)

  • expansion with command sub/arith sub/escaped literals、partial leading expansion、Empty alternative(两侧 rc=0 输出不同)、no expansion with RHS assignment(bash rc=127 / rubash rc=0)、Tilde expansion with brace expansion(两侧 rc=127 输出不同)。

7. 其他

  • builtin-echo: \0377 octal 边界 等(两侧 rc=127 但输出不同——echo 转义细节)、bugs: assign readonly(bash rc=1 / rubash rc=0——只读赋值错误被吞)、bugs: echo/printf fail on writing to full disk(rubash rc=1)、bool-parse: test 内置 ( = )(两侧 rc=0 输出不同)、blog1: ${###} 系列(参数展开细节)、assign-deferred: typeset a[3]=4(两侧 rc=0 输出不同)、ble-*(bash 5.1 新特性, rubash 不支持, 兼容差距)。

与既有 ISSUE 的关系

附:复现方式

# winuxsh 仓库内
bash scripts/probe/suites/spec-difftest.sh 'alias.test.sh'   # 单文件
bash scripts/probe/suites/spec-difftest.sh                   # 全部 228 文件
# 输出: [PASS]/[DIFF] + 两侧 stdout/stderr 对比; 汇总行

套件:scripts/probe/suites/oil/spec/(sparse checkout)、scripts/probe/suites/bin/argv.py(bash 版辅助)、scripts/probe/suites/spec-difftest.sh(驱动)。mksh check.t(14526 行)与 ksh93 tests/(58 文件)已拉取,可作第四轮差分输入。

注:任务后台运行中,完成后的完整差异清单(预计 400+ 项)会补充到本 ISSUE 评论或新 ISSUE。

Activity

  1. caomengxuan666 commented on Aug 12, 2026

    @caomengxuan666
    MemberAuthor

    2026-08-12 update: Oil spec 已用 Python3 转换副本跑完 spec/*.test.sh(不改上游 checkout)。为让旧 Python2 harness 在 Windows/Python3 下可跑,转换副本补了 Tokenizer.next、subprocess text=True、去掉 preexec_fn、去掉 json.loads encoding,并展开 sparse checkout 的 doctools/vendor。当前 222 个 spec 文件中 12 个文件无 fatal/traceback/timeout:assign-dialects、builtin-times、comments、empty-bodies、if_、known-differences、let、loop、nocasematch-match、redirect、ysh-old、ysh-options;其余 210 个文件有差异或失败。结果目录:target/issue-suites/results/oils-spec-logs 和 oils-spec.status。

  2. arookieofc commented on Aug 13, 2026

    @arookieofc
    Member

    修复进展:jobs/wait 根因切片已修复。wait -n 回收的子进程状态现在会保留,后续显式 wait PID 可再次取得 Bash 兼容的退出码;新增 part_036 回归测试。验证:cargo test --test executor_tests command_chaining::part_036,27/27 通过。完整 oil 套件仍有其他未归因差异,本 issue 暂不关闭。

  3. arookieofc commented on Aug 14, 2026

    @arookieofc
    Member

    Fixed in commit aee928d. Non-interactive alias expansion now honors expand_aliases (off by default, enabled explicitly with shopt -s). Arithmetic expansion errors such as division by zero and invalid base literals now abort the shell with status 1, matching GNU Bash. Focused alias (74) and arithmetic (14) tests pass.

  4. arookieofc commented on Aug 14, 2026

    @arookieofc
    Member

    2026-08-14 follow-up: associative-array expanded/quoted subscript assignments and malformed conditional parsing are now aligned in the executor slice. Verification: executor 1523/1523 and CLI 155/155. Broader oil/mksh differences remain open.

  5. arookieofc commented on Aug 16, 2026

    @arookieofc
    Member

    2026-08-17 follow-up: fixed one bridge-free arithmetic-for parser root cause in commit d68d8b9. A malformed braced parameter word in an arithmetic-for header (for (( \u0024{ case x in x) esac; };; )); ...) is now rejected with Bash-compatible status 2 instead of executing and continuing. stdin batch execution now stops on parser errors without conflating ordinary status-1 failures. Evidence: target/issue-suites/results/native-bash-20260817-arith-for/; CLI arithmetic_for 3/3; parser arithmetic-for 4/4; lib 200/200. Issue #22 remains open for its other suite families.

  6. caomengxuan666 commented on Aug 28, 2026

    @caomengxuan666
    MemberAuthor

    关闭说明

    oil spec 测试环境未搭建 (Python3 兼容性问题),无法有效复现。基础设施问题已在 #40 中跟踪。关闭历史 issue。

  7. added
    bug
    gnu-baseline
    on Oct 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    buggnu-baseline

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions