Repository navigation
fix(declare): declare -p emits diagnostics and listings in operand order on merged streams (rubash#3408) - #3758
Conversation
…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.
|
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):
Two things for the captain's review queue:
Queued for captain review with CI watched. |
|
队长裁决(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、守卫扫描)。 定序两点:
正文缺「本 PR 删除了什么」节,合入时由队长在 merge body 补。 |
|
【WIN-AGENT-AUDIT】s2 PR #3758 第1轮 — 建议:PASS(已合并 364478d) 机制核查:
腿:
F 点:无 合并:364478d760ee383fa0075d0273eb5fd31da8f0ca(squash,未删分支) |
Fixes #3408.
GNU's
declare -pwalks its operands once, printing each name's listing or reporting it not found as it goes (builtins/setattr.defset_or_show_attributes), so on a merged stream (2>&1 | cat,>f 2>&1,\$(... 2>&1)) the diagnostic forBADNAMEprecedes the listing forv. Rubash printed every listing first: the per-name loop wrote listings straight to stdout while thenot founddiagnostic sat in theDiagpending 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_namesflushes pending diagnostics before each name's listing (the same flush-before-immediate-write rulebare_diag_linefollows), so diagnostics are WRITTEN in operand order;execute_declareruns against oneOrderedOutputLogand flushes throughwrite_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):cargo test --lib1249 passed / 0 failed / 4 ignoredrustfmt --checkandgit diff --checkcleanBASH_VERSINFO5.2.21 vs 5.3.20 version stringKnown adjacent gap, not fixed here:
local -pshows the same reversal through its own dispatch (execute_local) and needs its own follow-up.