Skip to content

pushd: route the Dir operand through cd's search funnel and preserve the // prefix - #3259

Merged
caomengxuan666 merged 5 commits into
masterfrom
fix-W-DIRS-pushd
Nov 10, 2026
Merged

caomengxuan666 merged 5 commits into
masterfrom
fix-W-DIRS-pushd

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Refs #3196
Refs #3197

What this changes

pushd's Dir operand now goes through cd's own directory-search funnel, and the exactly-two-slashes prefix survives in the spelling pushd stores on the stack and binds to $PWD.

  • pushd 不查 CDPATH(cd 同形正常) #3196 face: GNU routes the operand through cd_builtin (builtins/pushd.def:296-302), whose CDPATH loop (builtins/cd.def:353-388) and cdable_vars fallback decide the spelling. pushd previously normalized the raw operand itself and never searched CDPATH. cd.rs gains a pub(crate) wrapper (resolve_search_operand / SearchResolution) over cd's existing private resolve_cdpath and resolve_cdable_vars stages, run in cd's order over a Target built the way cd builds a plain operand; pushd consumes the outcome and announces hits the way cd announces them (a non-empty CDPATH unit echoes the found directory, cdable_vars echoes the variable's raw value, before the dirs listing). cd's own logic is untouched.
  • pushd // 被归一化成 /(dirs 顶与 PWD 均错) #3197 face: normalize_stack_dir rebuilt the path from components under a hardcoded single-/ prefix, so a // prefix could never survive. It now re-applies the prefix through cd's existing preserve_leading_double_slash (cd/paths.rs, the cd inside un-redirected command substitution resolves against startup cwd after the shell has cd'd #2211 mechanism), with the slash evidence taken from the spelling the path was built from — the operand itself for an absolute operand, the base $PWD for a relative one — never the joined text. GNU anchor: change_to_directory (builtins/cd.def:522ff) canonicalizes via sh_canonpath; exactly two leading slashes are preserved, three or more collapse to one (oracle-verified: pushd // binds //, pushd //tmp/../tmp binds //tmp).

Regression pins

  • tests/issue3196_pushd_cdpath_regressions.rs — 6 cells: seed CDPATH form, unit forms, CDPATH-beats-cwd and slash operands, empty-unit silent hit, miss/dot-led/-n controls, cdable_vars through pushd.
  • tests/issue3197_pushd_double_slash_regressions.rs — 3 cells: // root form plus popd return, single/triple-slash and cd // controls, components/dotdot/relative-from-// forms.

One pin-harness note: the 3197 pin's scratch-path normalization originally replaced the bare scratch spelling first; because the scratch itself starts with /, that match began at the second slash of a preserved // value and consumed the prefix under test, so the components cell reported a product failure that byte-level probes disproved (raw child stdout is //<scratch>/sub verbatim, and the instrumented bindpwd/stack values carry // end to end). The harness now replaces the fused /<scratch> form first. Expectations and assertions are unchanged, and the base fail-first shape is preserved (see below).

本 PR 删除了什么

  • src/builtins/pushd.rs: the Dir arm's direct normalize_stack_dir(&dir, …) call on the raw operand (superseded by cd-funnel resolution before normalization).
  • src/builtins/pushd/stack.rs: the prefix-arm lines inside normalize_stack_dir that rebuilt the result under a single-/ prefix with no way to represent // (superseded by re-applying the prefix through cd's preservation helper).
  • src/builtins/cd/paths.rs: the pub(super) visibility specifier on preserve_leading_double_slash, widened to pub(crate) so pushd reuses the one implementation; the function's logic is unchanged.
  • tests/issue3197_pushd_double_slash_regressions.rs: the single-expression scratch replacement in run_script, superseded by the two-stage replacement described above.
  • No function, feature, or test is removed.

Verification (Simular box, serial cargo lock, CARGO_INCREMENTAL=0, -j 2)

Base 9ec03556 with only the pins added (fail-first, matching the pin design cell for cell):

  • 3196 pin: 4 red / 2 green — red: seed_plain_cdpath, unit_forms, cdpath_beats_cwd_and_slash_operand, cdable_vars_through_pushd.
  • 3197 pin: 2 red / 1 green — red: pushd_double_slash_root, double_slash_with_components.

Head f45d120b:

  • 3196 pin: 6 passed / 0 failed.
  • 3197 pin: 3 passed / 0 failed.
  • Neighboring cd/pushd/dirstack/pwd stems (23 stems, each with its own test result line): all green, except issue423_interactive_cd_child_cwd_regressions at 0 passed / 2 failed with the identical two test names red on the base commit — an environment shape (missing PTY harness binary), not a regression of this change. The Windows-gated stems in the set run 0 tests on Linux.
  • lib: head 1207 passed / 0 failed / 4 ignored; base 1207 passed / 0 failed / 4 ignored; the head and base failure name sets are both empty.
  • RUSTFLAGS="-D warnings" check over lib and bins: rc 0.
  • cargo fmt --check on the working tree: rc 0.
  • python3 scripts/check-marker-literals.py: rc 0.

…tion

Pins only, no product change. Expectations byte-verified against the GNU bash 5.3.20 oracle with script-file probes.

Refs #3196

Refs #3197
… // prefix

GNU pushd_builtin delegates its Dir operand to cd_builtin (builtins/pushd.def:296-302), so cd's CDPATH loop (builtins/cd.def:353-388) and the cdable_vars fallback are pushd's own resolution too. cd gains a pub(crate) wrapper (resolve_search_operand) over its existing private resolve_cdpath/resolve_cdable_vars stages, run in cd's order over a Target built the way resolve_target builds a plain operand; pushd consumes the funnel and keeps its own failure diagnostics. cd's existing logic is unchanged.

For the // face: pushd's normalize_stack_dir rebuilt paths from components under a hardcoded single-slash prefix, so exactly two leading slashes could never survive. It now re-applies the prefix through cd's preserve_leading_double_slash (visibility widened pub(super) -> pub(crate), logic unchanged), taking the evidence spelling from the operand itself for absolute operands and from $PWD for relative ones, never from the joined text (the rubash#2211 rule).

Refs #3196

Refs #3197
…e // prefix

The components cell read as a product failure (PWD and stack top
showing a single slash), but instrumented probes on the head build
show normalize_stack_dir, bindpwd and the saved stack all carrying
//<scratch>/sub verbatim, and the raw child stdout is byte-exact
//<scratch>/sub — the GNU form (cd.def change_to_directory via
sh_canonpath). The slash was lost in the pin's own run_script
normalization: the scratch spelling starts with `/`, so
replace(scratch, "WORK") matches from the second slash of a preserved
// prefix and consumes it. Replace the fused /<scratch> form first
(-> //WORK), then the bare scratch. Expectations unchanged; the base
fail-first shape is preserved (base output carries no // to fuse, so
the cell still reads WORK/sub against the //WORK/sub expectation).

Refs #3197
@caomengxuan666
caomengxuan666 marked this pull request as ready for review November 10, 2026 13:00
@caomengxuan666
caomengxuan666 merged commit 9e92668 into master Nov 10, 2026
11 checks passed
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