Repository navigation
fix(windows): normalize PATH casing in Executor::new() - #5
Merged
Merged
Conversation
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
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.
This was referenced Nov 6, 2026
Closed
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On Windows,
std::env::vars()returns the PATH environment variable asPath(capital P). Every rubash command-lookup site readsenv_vars.get("PATH")(all caps), which is a case-sensitive HashMap lookup — it misses on Windows. As a resultfind_user_commandreturnsNonefor every external command when rubash is embedded in a Windows shell host.Root cause
Executor::new()collectsstd::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-sidePathentry and insert it under the all-capsPATHkey, 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— setsPATH(all caps) and verifiesfind_user_command("cmd")finds the target.windows_find_user_command_fails_when_only_path_lower_is_set— sets onlyPath(lowercase) and confirmsNone(documenting that the init.rs workaround is required).cargo checkpasses with zero errors and zero warnings;cargo test --lib executor::pathpasses (Windows 11).Verification
Before the fix,
winuxsh -c "ls ."returned "command not found" on a Windows 11 system wherewinuxcmd.exeis on PATH. After the fix the same command correctly lists directory contents.