Skip to content

WIP: cd-face trio — comsub empty operands, logical pwd rendering, cdable_vars diagnostic name - #2230

Merged
caomengxuan666 merged 4 commits into
masterfrom
fix/cd-face-2219-2221
Oct 30, 2026
Merged

caomengxuan666 merged 4 commits into
masterfrom
fix/cd-face-2219-2221

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

WIP: cd-face trio — empty comsub operands (#2219), logical pwd rendering (#2220), cdable_vars diagnostic name (#2221)

Cluster branch for the three cd-face divergences filed from the #2211 probes. One commit per issue; Refs-only.

Overlap note: PR #2218 (the #2211 fix) edits the same command_substitution_cd_pwd_output_impl. #2218 restructures the operand gating (session-cwd anchoring + its own decline gates) and fixes logical_destination_display's // seam in src/builtins/cd/paths.rs; this branch deliberately does not touch paths.rs and builds on the helper. Whichever lands second takes a master merge-in; the full gate adjudicates. On this base the fast path agrees with the builtin on every probed cell (they share the helper); the cd // + relative-operand cells additionally depend on #2218's helper fix.

Verification so far (local, Linux): pins 23/23 green on the fixed tree; baseline (src stashed) 14 red / 9 green across the three targets; --lib 983 passed / 0 failed; issue1415 adjacency green; probe batteries byte-identical to the GNU bash 5.3.20 oracle except the #2218-owned //-seam cells documented in the pins.

Refs #2219
Refs #2220
Refs #2221

…es empty/splitting operands

split_shell_words_with_quote_info dropped a word whenever its accumulated
text was empty, so a quoted empty string ("" or '') vanished from the word
list. In GNU, quotation produces a word even when it expands to nothing —
the empty word disappears only later, when an UNQUOTED expansion yields no
fields (subst.c expand_word_list_internal / expand_string: a quoted empty
expansion stays as one empty field; cd then rejects the empty operand with
"cd: null directory", builtins/cd.def:333). Track word-started in the
splitter (quote opens, including the $".." locale form, and the $'..'
ANSI-C form, which the splitter already marks quoted) and push a started
word at separators and at end of input.

The $(cd X && pwd) fast path took words.get(1) as its operand, so
$(cd "" && pwd) looked operand-less and silently performed the $HOME
move. It now reads the operand through the quote-aware splitter and
declines (returns None, so the real executor runs the genuine cd/pwd
pair) whenever the word is empty before expansion, empty after expansion,
or an unquoted expansion containing blanks (field splitting is the real
parser's mechanism, not this model's).

Blast radius of the splitter change, audited per consumer: the comsub
word shortcut is gated by a char whitelist that excludes quotes; the
embedded-mutation function-call gate excludes quotes and requires
non-empty words; env -S splitting gains exactly the empty arguments GNU
coreutils env -S preserves; the alias splice and heredoc-delimiter
extraction move toward GNU's re-parse shapes. Pins: 9 tests in
tests/issue2219_comsub_cd_empty_operand_regressions.rs (7 red on master,
2 controls green both ways).

Refs #2219
…ub cd fast path

The $(cd X && pwd) fast path returned canonicalize() output — the physical
path — for both pwd spellings. GNU's pwd_builtin with no -P prints $PWD,
the logical chain cd_builtin maintains (builtins/cd.def: bindpwd stores
the logical spelling; the -L default keeps `..` and symlink components
unresolved). So $(cd link && pwd) printed the resolved target directory
where GNU prints the path through the link, and $(cd //etc && pwd) lost
the POSIX double-slash root.

The physical probe still gates the fast path (existence / is-dir), but
the bare-pwd rendering now goes through the builtin's own chain —
logical_destination_display over validated_logical_pwd, exposed from the
cd module as logical_destination_display_from — so the fast path cannot
drift from the builtin it models; pwd -P keeps the physical rendering.
Rendering (rather than declining logical spellings) also avoids
re-expanding the operand: declining would run a side-effecting operand
twice (once in the fast path's probe expansion, once in the real
executor).

Known stacking dependency: logical_destination_display itself carries a
// seam on master (old="/" + relative operand manufactures //, old="//"
+ relative collapses); PR #2218 fixes that helper. On this base the fast
path and the builtin agree on every probed cell because they share the
helper; the cd // session cells verify fully once #2218 is in the base.

Pins: 9 tests in
tests/issue2220_comsub_pwd_logical_rendering_regressions.rs (5 red on
master, 4 controls green both ways; symlink fixtures are unix-only,
matching the #2211 cluster's local-dev test target).

Refs #2220
…ed value

NOTE — the issue prose has the direction swapped; the oracle is
unambiguous. GNU (builtins/cd.def, cd_builtin error tail) prints
sh_whence / printable_filename(dirname) where dirname is the OPERAND as
given: the CDPATH/cdable_vars attempts bind a separate temp and never
reassign dirname; only the errno comes from the last attempt. Verified
against bash 5.3.20: cdable_vars=1 CDPATH= DEST=dest with dest a shell
variable holding /no/such/dir-xyz gives "cd: dest: No such file or
directory" — the operand's name with the value's errno. The two cases
where GNU names the value are different mechanisms: the cdable SUCCESS
message prints the substituted path (LCD_DOVARS), and `cd -` reassigns
dirname = $OLDPWD before the attempts.

rubash named the substituted value because resolve_cdable_vars had
already replaced target.display with the value's Target before the
canonicalize probe failed. Keep the operand's display name
(dirname_display) before resolve_cdpath / resolve_cdable_vars run and
use it in the probe-failure diagnostic; the errno still comes from
probing the attempted value.

Pins: 5 tests in tests/issue2221_cdable_vars_diag_regressions.rs (2 red
on master; controls pin the success-message and cd - exceptions plus a
plain missing operand).

Refs #2221
Master carries PR #2218 (rubash#2211: comsub cd session-cwd anchoring, operand decline gates, logical_destination_display // seam fix in paths.rs), PR #2224 (census) and PR #2226 (walker) since this branch forked at 01836d3.

One conflict, in command_substitution_cd_pwd_output_impl (src/executor/command_substitution.rs), resolved as the union of both sides per the cluster REPORT overlap map:
- operand read stays quote-aware (split_shell_words_with_quote_info, #2219): the raw-empty decline is decided pre-expansion;
- #2211's post-expansion declines kept (leading '-', CDPATH search, expanded-empty) and operand_form is set only after every decline has passed;
- #2219's unquoted-blank (field-splitting) decline kept;
- downstream untouched: session-cwd anchoring (#2211), the cdable decline keyed on operand_form, and the #2220 logical rendering tail over paths.rs's seam-fixed logical_destination_display.

Re-verified on the merged tree (Linux): issue2219 9/9, issue2220 9/9 (incl. the //etc pin), issue2221 5/5, issue1415 adjacency 1/1, issue2211 14/14 (the session-// + relative-operand seam cells are pinned there), --lib 983 pass / 0 fail.
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