Skip to content

fix(declare): declare -p emits diagnostics and listings in operand order on merged streams (rubash#3408) - #3758

Merged
caomengxuan666 merged 1 commit into
masterfrom
ai-fix/rubash-3408
Nov 16, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
ai-fix/rubash-3408

Conversation

@arookieofc-ai

Copy link
Copy Markdown
Contributor

Fixes #3408.

GNU's declare -p walks its operands once, printing each name's listing or reporting it not found as it goes (builtins/setattr.def set_or_show_attributes), so on a merged stream (2>&1 | cat, >f 2>&1, \$(... 2>&1)) the diagnostic for BADNAME precedes the listing for v. Rubash printed every listing first: the per-name loop wrote listings straight to stdout while the not found diagnostic sat in the Diag pending queue until the dispatcher flushed after the call, and the buffered pair route then emitted the whole stdout block before the whole stderr block.

Fix in two halves, following the established #2699/#3324 pattern:

  • print_declare_names flushes pending diagnostics before each name's listing (the same flush-before-immediate-write rule bare_diag_line follows), so diagnostics are WRITTEN in operand order;
  • execute_declare runs against one OrderedOutputLog and flushes through write_buffered_builtin_output_chunks, so the chunks route in log order through the resolved fd state (including the pipeline stage's pre-wired fd-2-onto-fd-1 capture).

Note: the in-builtin flush alone does not fix the piped shape — the fail-first run proved the pair route reorders even after the flush, which is why the dispatch half is needed.

Regression pin: tests/issue3408_declare_p_merged_order_regressions.rs (8 tests: pipe/file/comsub merged shapes, both orders, sandwich, two-bad, typeset alias, exit code + split streams). Fail-first: 4 failed on the baseline binary before the fix.

Verification (Simular box, master 8100d76):

Known adjacent gap, not fixed here: local -p shows the same reversal through its own dispatch (execute_local) and needs its own follow-up.

…der on merged streams (rubash#3408)

GNU's declare -p walks its operands once, printing each name's
listing or reporting it not found as it goes (builtins/setattr.def
set_or_show_attributes), so on a merged stream (2>&1 | cat, >f
2>&1, $(... 2>&1)) the diagnostic for BADNAME precedes the listing
for v. Rubash printed every listing first: the per-name loop wrote
listings straight to stdout while the not-found diagnostic sat in
the Diag pending queue until the dispatcher flushed after the call,
and the buffered pair route then emitted the whole stdout block
before the whole stderr block.

Fix in two halves, following the established #2699/#3324 pattern:
- print_declare_names flushes pending diagnostics before each
  name's listing (the same flush-before-immediate-write rule
  bare_diag_line follows), so diagnostics are WRITTEN in operand
  order;
- execute_declare runs against one OrderedOutputLog and flushes
  through write_buffered_builtin_output_chunks, so the chunks route
  in log order through the resolved fd state (including the
  pipeline stage's pre-wired fd-2-onto-fd-1 capture).

Regression pin: tests/issue3408_declare_p_merged_order_regressions.rs
(8 tests: pipe/file/comsub merged shapes, both orders, sandwich,
two-bad, typeset alias, exit code + split streams). Fail-first:
4 failed on the baseline binary before the fix.

Verified on the Simular box (master 8100d76): new suite 8/8,
cargo test --lib 1249 passed / 0 failed, neighbours #3324 18/18,
#3338 8/8, #77 7/7, rustfmt --check and git diff --check clean.
Known adjacent gap, not fixed here: local -p shows the same
reversal through its own dispatch (execute_local) and needs its
own follow-up.
@caomengxuan666 caomengxuan666 added the bug Something isn't working label Nov 16, 2026
@caomengxuan666 caomengxuan666 self-assigned this Nov 16, 2026
@caomengxuan666 caomengxuan666 added gnu-baseline Tracked by the GNU Bash 5.3.0 true-baseline ledger P3-low 低:优化、文档、远期规划,有机会再做 area:fd redirection, fd table, /dev/* emulation, dup/close ordering labels Nov 16, 2026
@caomengxuan666

Copy link
Copy Markdown
Member

Thanks for the fix — and for the fail-first note. Per the owner's rule, external PRs are reviewed by the captain first; this is a first-pass review from intake, not a merge decision, and I am not requesting changes.

What I checked (diff fully read):

CI, checked by name (main run 43793370999, canary 43793370868):

  • The three red legs (Rust tests Linux, Rust tests macOS, goldens) fail on exactly one test, api::consumer_tests::issue2875_input_procsub_child_runs_as_rubash_shell — the known baseline/ledger-drift cell, also red on master. No PR-specific failure is named in the failed logs. The goldens leg stopped at the lib-test step, so its regression suite did not run here.
  • The niu-canary leg fails only at the ledger-coverage check (the same known drift); the API ledger tripwire itself passes.
  • CLI tests, shell functionality tests, both cross-target checks and the Windows compile check are green.
  • One caveat: CI's selected nextest table does not execute the new [bug] declare -p mixed diagnostic/output still reversed on a merged stream (follow-up to #3324) #3408 stem, so the reported 8/8 rests on the author's local run; the captain will re-run the new stem at review.

Two things for the captain's review queue:

  1. Overlap with the owner's pin-only PR test: pin declare -p merged-stream order (Refs #3408) #3618 (open, tests/issue3408_declare_p_merged_stream_order.rs, 7 shapes, marked UNVERIFIED-BY-CAPTAIN, fix pending). This PR adds a second pin file for the same shapes under a different name; whether test: pin declare -p merged-stream order (Refs #3408) #3618's file is absorbed, dropped, or kept alongside is a captain call — I am not closing or superseding anything.
  2. Fixes #3408 in the body means merging auto-closes [bug] declare -p mixed diagnostic/output still reversed on a merged stream (follow-up to #3324) #3408; the known adjacent gap (local -p through its own execute_local dispatch) is recorded in the body as a follow-up, not fixed here.

Queued for captain review with CI watched.

@caomengxuan666

Copy link
Copy Markdown
Member

队长裁决(2026-11-16):本 PR 为 #3408 的先行实现(fix carrier),按外部 PR 优先规矩不另派实现车道。CI 已按名核实:主 run 43793370999 三腿唯一红皆 issue2875 基线格,canary 唯一红为已知 ledger 漂移(MISSING Session::cwd),无 PR 专属红。已入 Wave 2 复核队列(钉 fail-first 实测、邻居 #3324/#3338/#77、lib 双边、-D warnings、守卫扫描)。

定序两点:

  1. 本 PR 触 src/executor/declare_local.rs,与 fix(builtins): print function definitions in bare declare/set listings (Refs #3487) #3530(合入轮待发)同文件相撞——合入须待 fix(builtins): print function definitions in bare declare/set listings (Refs #3487) #3530 先合后 rebase。
  2. 另有 pin-only PR test: pin declare -p merged-stream order (Refs #3408) #3618(同 [bug] declare -p mixed diagnostic/output still reversed on a merged stream (follow-up to #3324) #3408,7 形钉)与本 PR 的 8 形钉形状重叠:本 PR 合入后,队长逐格比对两钉,test: pin declare -p merged-stream order (Refs #3408) #3618 的独有格以 pin-only 形吸收、重复格丢弃。

正文缺「本 PR 删除了什么」节,合入时由队长在 merge body 补。

@caomengxuan666
caomengxuan666 merged commit 364478d into master Nov 16, 2026
11 of 15 checks passed
@caomengxuan666

Copy link
Copy Markdown
Member

【WIN-AGENT-AUDIT】s2

PR #3758 第1轮 — 建议:PASS(已合并 364478d)
head: ee7fd38;base(merge-base): 8100d76;文件 3 个 +187/-4
关联 issue: #3408(open → 合并后 closed)

机制核查:

腿:

  • 钉自跑:issue3408_declare_p_merged_order_regressions 8/8(Windows 上需把测试的路径归一化扩展到 rubash 的 /c/... prolog 形;仅 harness 适配,断言语义未动,临时副本已删)。
  • fail-first:base 8100d76 同文件 2 passed / 6 failed(红名 = {merged_diag_first, merged_sandwich, merged_two_bad_then_good, merged_typeset_alias, merged_file_redirect, merged_comsub});PR 正文称 base 4 红,实测 6 红 —— 方向一致且更强,记差异不改判。
  • lib 双边:head {issue2084_session_end_restores_host_process_state} / base {issue2084..., pathmatrix_bridge_legacy_dialect_restores_funnel} → 差集 ∅。
  • -D warnings:bin+lib 与 PR stem 0 警告;全仓 --tests 的 issue1794/2278 dead-code 为基线。
  • 卫生:rustfmt 三文件 0 差异;marker-lint OK;utf8 clean。
  • CI(run 43793370999):Rust tests = issue2875;macOS 1245/1 = issue2875;GNU goldens 1351/1 = issue2875;niubash = MISSING Session::cwd(ci: unmask master-red — issue2875 out/ resolver + masked test/corpus fixes #3750 面);其余绿。无 PR 专属红。
  • GNU 对照(WSL GNU bash 5.3.20(1)):declare -p BADNAME v 2>&1|cat、declare -p v BADNAME w 2>&1|cat、declare -p BADNAME v >out.txt 2>&1、out=$(declare -p BADNAME v 2>&1)、typeset -p BADNAME v 2>&1|cat 五个形状,输出顺序(诊断/lising 交错)与 rubash 字节一致(仅路径前缀不同)。探针 target/s2/probes/d3408/{a..e}.sh。

F 点:无

合并:364478d760ee383fa0075d0273eb5fd31da8f0ca(squash,未删分支)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:fd redirection, fd table, /dev/* emulation, dup/close ordering bug Something isn't working gnu-baseline Tracked by the GNU Bash 5.3.0 true-baseline ledger P3-low 低:优化、文档、远期规划,有机会再做

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] declare -p mixed diagnostic/output still reversed on a merged stream (follow-up to #3324)

2 participants