Skip to content

fix(builtins): #859 — pushd -n with no operand is a silent no-op (rc 0), not the swap arm - #889

Merged
caomengxuan666 merged 1 commit into
masterfrom
arookieofc/fix-859-pushd-n-noop
Oct 19, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
arookieofc/fix-859-pushd-n-noop

Conversation

@arookieofc

Copy link
Copy Markdown
Member

Closes #859 (the reproducible half).

pushd -n with no operand — GNU pushd.def:290-291: the option walk consumes -n and leaves list == 0, so the builtin returns EXECUTION_SUCCESS silently. The bare-pushd swap arm (:195-213, "no other directory") only runs when the list is empty with no options consumed. rubash collapsed both empty-list forms into Swap, so pushd -n errored rc 1. parse_pushd_operand now distinguishes them via a new PushdOperand::NoOp.

popd -N fresh-stack — does NOT reproduce as described. WSL GNU 5.3.0 prints popd: directory stack empty rc 1 for popd -0 / popd -5 / popd +0 on a fresh stack (pushd_error offset==0 → builtin_error, pushd.def:390-394 → 540-546). That is byte-identical to rubash's current output, so there is no divergence to fix. If the issue meant a different operand shape (e.g. popd -n alone, or a non-fresh stack), I can re-probe — but every ±N form on an empty stack reports the diagnostic in GNU.

Byte-for-byte verified vs WSL GNU 5.3.0 (pushd -n on empty and live stacks, dirs state, fresh popd ±N faces). New regression pushd_no_cd_with_no_operand_is_a_silent_noop; dirstack family (844/848/830/509) stays green.

…0), not the swap arm

GNU pushd.def:290-291: the option walk consumes `-n` and leaves
`list == 0`, reaching `return (EXECUTION_SUCCESS)` — a silent no-op.
The bare-`pushd` swap arm (pushd.def:195-213) only runs when the list is
empty with NO options consumed, and errors "no other directory" when the
stack is short. rubash collapsed both empty-list forms into Swap, so
`pushd -n` reported "no other directory" rc 1.

parse_pushd_operand now distinguishes them: options consumed + no
operand -> PushdOperand::NoOp (silent rc 0); no options at all -> Swap.

popd note: the second half of #859 ("fresh popd -N silent rc 1") does not
reproduce — WSL GNU 5.3.0 prints "popd: directory stack empty" rc 1 for
`popd -0`/`-5`/`+0` on a fresh stack (pushd_error offset==0 -> builtin_error,
pushd.def:390-394 -> 540-546), byte-identical to rubash's current output.
No divergence there; only pushd -n needed the fix.

Verified byte-for-byte vs WSL GNU 5.3.0 across pushd -n (empty + live
stack), dirs state, and fresh popd ±N faces. Regression test
pushd_no_cd_with_no_operand_is_a_silent_noop added; dirstack family
(844/848/830/509) stays green.
@github-actions

Copy link
Copy Markdown
Contributor

欢迎!这是你的第一个 PR 🎉 请确认已跑过本地测试套件;CI 通过后维护者会 review。

@caomengxuan666

Copy link
Copy Markdown
Member

独立评审:APPROVE-WITH-NITS(含 #855 CR 预言闭环确认)

评审方式:fetch origin/master (78952f58) 与 PR head (ea6b3d5f) 后自建 detached worktree 评审,未触碰其他会话的树,未合并;评审后两棵评审树已删除并重列 git worktree list 复核。本评审不采信 PR 描述中的对拍记录,所有行为主张由评审者在本机 WSL /usr/local/bin/bash GNU 5.3.0(1) 独立重跑(另以 5.2.21 做同形差分)。

#855 CR 预言闭环:已闭环

master(base)上 pushd -n 无操作数确实经 Swap 臂发声,逐形实测:

形 GNU 5.3.0 rubash base (master) rubash PR
pushd -n fresh 静默 rc 0 pushd: no other directory rc 1 逐字节一致
pushd -n live(2条) 静默 rc 0,栈不动 rc 0 且静默把栈 swap 掉 逐字节一致
readonly PWD/OLDPWD + live + pushd -n 静默 rc 0,无诊断 <VAR>: readonly variable rc 1(#855 bindpwd_write 误伤,即 CR 预言的形) 逐字节一致,诊断消失
readonly + fresh + pushd -n 静默 rc 0 no other directory rc 1 逐字节一致

实现上 PushdOperand::NoOp 在 bindpwd_write/save_stack/display 之前提前返回,readonly 诊断在该形结构性不可达——CR 预言的发声被消除而非掩盖。

票面②(fresh popd -N):PR 的"不可复现"判断正确

GNU 5.3.0(1) 实测 popd +0/-0/+1/-1/+5/-5、裸 popd、popd -n 在 fresh 栈上全部发 popd: directory stack empty rc 1,与 rubash 逐字节一致;票面"GNU 静默 rc 1"的前提不成立。源码坐实(5.3.0 正式版树):pushd.def:390-394 的空栈判落入 pushd_error:539-546 的 offset==0 分支。PR 不改 popd、如实记录,处理得当;该形已有回归守住(issue830 的 popd +0 用例、issue844_848 的 popd +5 -n 用例)。

行为验证协议与结果

  • stdin 脚本模式双侧驱动,stdout+stderr 分别逐字节 cmp;归一化仅两处且对称施加于双侧:argv0 派生的报错前导(GNU get_name_for_error 与 rubash 同规则、不同串)与沙箱根路径 token。
  • 票内 17 形(票① 7 形 + fresh popd 8 形 + pushd -n ../sub2 raw-入栈对照、pushd -n /tmp x 多余操作数对照[GNU 静默忽略 x,/tmp 照常 raw 入栈] 等):PR 与 GNU 5.3.0 全部逐字节一致。
  • 5.2.21 vs 5.3.0 差分:17 形零分歧 → 见下条。

关于贡献者环境为 5.2.0 的提醒(owner 确认)

  • PR 描述声称 "WSL GNU 5.3.0",与贡献者实际环境(5.2.0)不符:该对拍记录降级为未验证,本评审不采信。
  • 但本评审独立在 5.3.0(1) 重验全部成立,且 5.2/5.3 在本票全部形上行为完全一致——即使 PR 按 5.2 oracle 编码,结果在 5.3.0 下同样正确。不构成 REQUEST-CHANGES 依据;建议后续 PR 的验证记录写明实际 oracle 版本。

回归与体检

NITS(不阻塞)

  1. 新注释引用的 GNU 行号有 ±1–2 漂移:静默 return 实为 pushd.def:289-290(注释写 290-291);无参 swap 臂实为 192-212(注释写 195-213)。纯注释,可随缘修。
  2. PR 描述的 oracle 版本声明与实际环境不符(见上),非代码问题。

越界观察(非本 PR 引入,建议另开票)

GNU pushd.def:184-190 有初始 --/- 预扫 + skipopt 抑制选项游走的机制,rubash 的 parse_stack_options 无此概念:pushd -- -n 在 GNU 5.3.0/5.2 为 pushd: -n: No such file or directory rc 1(走 Dir 臂 cd),rubash(base=PR 同)为 invalid number + usage rc 2;pushd - 亦疑似同族分歧。不在本票范围,建议干净探针后另开票。

结论:APPROVE-WITH-NITS。 票面①修复经 5.3.0 独立重验成立、#855 CR 预言闭环确认;票面②按"不可复现"如实关闭有据。不合并不阻塞,nits 随缘。

@caomengxuan666
caomengxuan666 merged commit c9e1421 into master Oct 19, 2026
8 checks passed
arookieofc added a commit that referenced this pull request Oct 19, 2026
…dash family

PR #889 fixed rubash#859 (pushd -n silent no-op) while this branch fixed
rubash#896 (full dash family). The #896 superset already contains the #859
behavior; resolution keeps the #896 option walk verbatim and adopts the
merged NoOp spelling. pushd.def:288-291, cd.def:326-330.
@caomengxuan666
caomengxuan666 deleted the arookieofc/fix-859-pushd-n-noop branch October 21, 2026 07:58
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.

pushd/popd 空栈与 -n 无操作数边角两分歧(#855 CR 备注):pushd -n 无词应静默 no-op rc 0;fresh popd -N 应静默 rc 1

2 participants