Skip to content

fix(windows): normalize PATH casing in Executor::new() - #5

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix/windows-path-casing
Jul 13, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix/windows-path-casing

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Problem

On Windows, std::env::vars() returns the PATH environment variable as Path (capital P). Every rubash command-lookup site reads env_vars.get("PATH") (all caps), which is a case-sensitive HashMap lookup — it misses on Windows. As a result find_user_command returns None for every external command when rubash is embedded in a Windows shell host.

Root cause

Executor::new() collects std::env::vars() into a HashMap with Windows-OS casing (Path), but all lookup sites use "PATH" (all caps). Affected sites:

  • src/executor/path.rs:find_user_command (the for-loop)
  • src/executor/path.rs:find_shell (indirect)
  • src/executor/command_no_alias.rs (save/restore)
  • src/executor/type_builtin.rs (save/restore)

Fix

Normalize casing once in Executor::new(): remove the OS-side Path entry and insert it under the all-caps PATH key, gated with #[cfg(windows)]. Every existing lookup site stays unchanged.

Testing

Two new regression tests in src/executor/path.rs:

  • windows_find_user_command_works_with_mixed_case_path — sets PATH (all caps) and verifies find_user_command("cmd") finds the target.
  • windows_find_user_command_fails_when_only_path_lower_is_set — sets only Path (lowercase) and confirms None (documenting that the init.rs workaround is required).

cargo check passes with zero errors and zero warnings; cargo test --lib executor::path passes (Windows 11).

Verification

Before the fix, winuxsh -c "ls ." returned "command not found" on a Windows 11 system where winuxcmd.exe is on PATH. After the fix the same command correctly lists directory contents.

On Windows, std::env::vars() returns the PATH environment variable as
"Path" (capital P). Every rubash command-lookup site reads
env_vars.get("PATH") (all caps), which is a casesensitive HashMap
lookup that misses on Windows.

Mirror the OS-side value into the all-caps key once during
Executor::new(). This is a onetime cost at construction and keeps
every existing lookup site (find_user_command, command_path, etc.)
unchanged.

Adds two regression tests in path.rs:
- windows_find_user_command_works_with_mixed_case_path: verifies that
  the all-caps PATH key works after init.rs normalization.
- windows_find_user_command_fails_when_only_path_lower_is_set:
  documents that find_user_command itself cannot see the lowercase key
  without the init.rs workaround.
@caomengxuan666
caomengxuan666 merged commit f08d6d6 into master Jul 13, 2026
3 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/windows-path-casing branch July 27, 2026 03:05
caomengxuan666 added a commit that referenced this pull request Sep 10, 2026
history.tests 284 -> 243 drift lines vs GNU 5.3.0. Ported from
builtins/history.def:190-262 + bashhist.c bash_delete_history_range +
readline remove_history_range:

- separator scan starts after a leading '-': -2-4 = start -2, end 4
- negative numbers count back from the list end (-1 = last entry)
- positive numbers are displayed numbers, offset by history_base
- inclusive range deletion; first > last fails silently (rc=1, no
  message) per remove_history_range
- out-of-range reports "history: {side}: history position out of
  range" where side is the offending END's text -- the C code NUL
  terminates the '-' in place, so start errors print the start text
  and end errors the end text
- valid_number is strtoimax base 10 (general.c:248): 0xaf is INVALID
  and reports the whole argument with the separator restored

Both history backends updated (session history_exec.rs + provider
job_builtins.rs). Probe: target/forms/hist-d.sh -- H1-H5 byte-identical
to GNU 5.3.0 modulo the stderr shell prefix (ledger-noted).

Regression: executor_tests failset identical (114); array.tests drift
unchanged at 436 lines. Docs: census #4/#5 ledger entry -- assoc key
ORDER verified identical across GNU 5.2/5.3/rubash (census #4 premise
refuted for basic shapes); the real assoc.tests gap is compound-
assignment key quoting/splitting (323 lines, next batch).
caomengxuan666 added a commit that referenced this pull request Sep 26, 2026
…winuxcmd probes and nohash misses (rubash#159)

Problem (target-perf/REPORT.md #5): a unique-name PATH miss cost
~14.2ms (22.7x GNU) -- one stat per PATH directory x PATHEXT extension
plus, in niu-host production, one `winuxcmd help <name>` child process
per miss. Hits and same-name misses were already cached
(CommandLookupCache).

GNU anchors (third_party/bash/findcmd.c @ Bash-5.3 p15):
- findcmd.c:623 find_user_command_in_path -- walk shape (first match in
  PATH order, FS_EXEC_PREFERRED|FS_NODIRS); the Windows port keeps the
  collapsed first-existing-file tier from rubash#144. The unix branch
  (findcmd.c:580-586 / 591 / 695 file_to_lose_on) is unchanged.
- findcmd.c:348-427 search_for_command -- phash is skipped entirely when
  hashing is disabled or PATH is in the temp env; rubash#159 memoizes
  only misses on those paths (positives keep re-scan semantics, so a
  removed file is observed thanks to the live is_file confirmation).
- builtins/hash.def:150 phash_flush -- `hash -r` drops listings, probes,
  scaffold and results together via CommandLookupCache::reset.

Fix (src/executor/path.rs):
1. Negative cache: misses are memoized process-internally on the
   nohash/temp-PATH bypass paths too, keyed by the existing env
   fingerprint (PATH/PATHEXT/dispatcher vars). Documented divergence
   boundary: bash has no negative cache, but its miss is a ~us stat;
   rubash's is ms, so staleness is bounded to "file created inside an
   already-listed PATH directory without a PATH change/hash -r is not
   found" (probe artifacts: target/issue-suites/results/rubash159/).
2. Merged scan: one read_dir per PATH directory (lowercased name set,
   cached per fingerprint) replaces the per-extension stat grid;
   candidate order stays byte-identical to executable_candidate()
   (PATHEXT extensions first for extensionless names), and every
   listing hit is confirmed with a live is_file() so directories and
   dangling symlinks claiming a name keep the stat walk's exact
   semantics. The split+translated PATH directories and parsed PATHEXT
   order are cached per fingerprint (scan scaffold), removing the
   per-lookup shell_path_to_windows cost (its pinned-tools-dir is_dir
   stat x PATH length dominated the residual ms).
3. Dispatcher probe cache: `winuxcmd help NAME` outcomes remembered per
   dispatch name for the fingerprint's lifetime (fingerprint covers the
   WINUXCMD*/COREUTILS_PATH variables that select the dispatcher).

Measurement (release, Git Bash harness, target-perf bench.sh):
unique-name miss 15.0ms -> ~1.0ms gross, marginal (miss100-miss10)/90
= 0.85ms, pure lookup component ~0.4ms (rest is builtin/exec machinery
outside #159); hit/same-miss/miss-same paths unchanged (s_true, miss_same
parity with baseline). Full ledger:
target/issue-suites/results/rubash159/perf-ledger.txt.

Verification: 456/456 lib tests green (3 new: merged-scan order +
case-insensitivity, negative-cache boundary with hash -r / PATH-change
escape hatches, nohash misses-not-hits memoization); findcmd semantics
matrix byte-identical to the baseline binary and matching WSL GNU Bash
5.3.0 on 127/miss, hit, command -v, PATH reorder, hash -r; 126-semantics
probe (rubash#144 collapse) byte-identical to baseline.
caomengxuan666 added a commit that referenced this pull request Nov 15, 2026
_check-api-ledger.py _child_module() only inspected the single line
immediately above a 'mod name;' declaration when looking for a
#[path = "..."] attribute. Rust allows doc comments and blank lines
between attributes and the declaration, so a ledger tree using that
layout resolved the fallback <name>.rs instead of the attributed file.
Walk back over contiguous attribute/comment/blank lines instead.

Also reword docs/api-ledger.md #5: the tripwire no longer proves
presence 'by declaration patterns only' — since #3556 it resolves real
export paths (pub mod steps + pub use re-exports, #[path] honored).
The niubash copy of the ledger still needs the same rewording (the
byte-identical cmp check in niu-canary job pairing enforces pairing).

GNU cite: n/a — tooling, not shell semantics.
Refs #3571, #3572

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
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