Skip to content

#1488 wave4b: rust2 library-form batch — factor pathchk ptx shuf csplit nohup groups who - #1577

Merged
caomengxuan666 merged 1 commit into
mainfrom
rust2/wave4b
Nov 12, 2026
Merged

caomengxuan666 merged 1 commit into
mainfrom
rust2/wave4b

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

#1488 wave4b — next 8 rust2 library-form commands + differential gates

8 commands implemented under the rust2 shape contract (explicit IO/env/cwd injection, no process globals, status returned not exited), each with >=20 gate cases (226 total) and a three-way differential gate (Rust driver / GNU coreutils 9.4 under WSL / C++ Debug dispatcher). Full 55-table suite green: 1335 GNU-gated + 190 win-gated, 0 fail. cargo test 420+16+5 green, cargo fmt clean.

command cases strict exit win GNU-gated C++ parity
factor 26 25 0 1 GREEN 24/26
pathchk 30 27 0 3 GREEN 28/30
ptx 28 19 0 9 GREEN 26/28
shuf 40 37 1 2 GREEN 37/40
csplit 32 32 0 0 GREEN 32/32
nohup 24 18 0 6 GREEN 19/24
groups 20 16 0 4 GREEN 16/20
who 26 6 0 20 GREEN 24/26

Highlights

  • shuf — the GNU randint entropy-recycling port reproduces coreutils 9.4 permutations byte-for-byte on every --random-source row (37/40 strict). Observed-and-pinned exhaustion split: dry source mid-shuffle continues with identity draws; dry source in repeat errors "end of file". --random-seed stays the documented WinuxCmd extension (SHA3-256 + ChaCha12, byte-identical to the C++ DeterministicRng).
  • csplit — GNU-streaming segments (sizes to stdout, in-progress-file flush rules on error paths, -k keeps them), BRE engine reuse (bre.rs gained leftmost-longest forward search). 32/32 strict.
  • factor — std-only biguint: trial division + Pollard-Brent + Miller-Rabin (16 prime bases). ~sqrt(p) rho cost documented as a performance boundary (F7-class operands out of the 10 s gate envelope).
  • nohup — childproc spawning with GNU's + optstring (LEADING options only: nohup true --bogus runs true; nohup --bogus true dies 125). Terminal faces (nohup.out, /dev/null stdin) are a documented deferral: console-ness cannot come through injected IO — wiring wave needs a driver-side probe.
  • pathchk — POSIX checks strict against GNU rc (order per pathchk.c, ENOTDIR via component-chain walk); Windows subject-side rules (reserved names, invalid chars) win-classified against the C++ value model.
  • ptx — the C++ subset data flow; byte-strict for single-line/roff/tex/macro/error shapes, with GNU's circular-context grid, -G traditional layout and -S/-W regexp delimiting documented as win-classified subset deviations.
  • groups/who — Windows value models (NetUserGetGroups + [gap] groups/id/stat: unresolvable group name prints literal 'None' #1024 None-as-numeric-id; WTS sessions + toolhelp32 leader pids), GNU-shaped rc errors strict-gated, content win-gated vs the C++ exe.

Shared infra (first commit)

  • childproc.rs: timeout's execvp-shaped resolver extracted so nohup shares it (timeout tests unchanged green).
  • argopt: H_REJECT_SPEC/rejected_short_h — commands where GNU has no -h (getopt_long matches --help only as a long option; probed GNU 9.4).
  • bre.rs: forward search (leftmost-longest) for csplit patterns.
  • run-gate.sh: raw argv for Windows sides (MSYS_NO_PATHCONV=1) + the C++ package bin dir on PATH (the /usr/bin analog) for child-spawning parity; full suite re-verified green after the change. 14 wave1/wave2 TSVs regenerated to restore generator-backedness (committed tables had drifted from their definitions).

Honest boundaries (documented in module docs + GATE-REPORT)

nohup console faces (wiring-wave driver probe), factor F7-class operand time, ptx circular-context/-G/-S/-W subset deviations, shuf infinite -r (untestable in the bounded harness).

Docs: rust2/GATE-REPORT.md Wave4b section, rust2/gate/COVERAGE.md addendum, rust2/README.md wave note. Not merged by this branch — review + product-side wiring follow REPLACEMENT-RECIPE.md.

…s/who) with their setup constants onto main's generator
@caomengxuan666
caomengxuan666 merged commit 566923b into main Nov 12, 2026
7 of 10 checks passed
caomengxuan666 added a commit that referenced this pull request Nov 12, 2026
recover wave4b: restore the eight command sources + shared childproc spawner lost in the #1577 merge
caomengxuan666 added a commit that referenced this pull request Nov 12, 2026
…ets (#1587) (#1588)

Fixes #1587 (WinuxCmd 2.0 / rust2 wave — the 1.x C++ spawner keeps its own tracking; this lane touches only the rust2 tree).

## What

`timeout`, `nohup` and `nice` resolved children with a CreateProcess-shaped extension allow-list: any existing target without a `.exe/.com/.cmd/.bat` extension — a shebang script, `.js`, `.ps1`, an npm/pnpm-style extensionless shim — exited **126 silently**. The new shared chain in `rust2/crates/winux-cmds/src/childproc.rs` (extracted from `timeout.rs`; the wave4b module shape — PR #1577 carried only the gen-cases graft to main, so `nohup.rs`/`childproc.rs` land here) resolves like `execvp`:

1. as given → PATHEXT variants → PATH search (unchanged native chain);
2. the hit is classified: `.cmd`/`.bat` → COMSPEC (`cmd /d /s /c "..."`); `MZ` magic → native image; `#!` → **`[interpreter, optional-arg, script, ...argv]`** with the interpreter resolved recursively (binfmt_script.c value model: first space/tab splits, ONE optional arg, CR kept — a CRLF shebang misses its interpreter, probed ENOENT);
3. a POSIX-rooted spelling the native chain missed (`/bin/sh`, `/usr/bin/env`) resolves through the product's shell-namespace mapper (`winux-core::path::shell_tree_to_native`), then through its leaf name on PATH;
4. a file with neither magic is the execvp ENOEXEC analog: **126 `Exec format error`** (C-locale GNU wording, byte-probed under WSL coreutils 9.4; ASCII quotes like the rest of the product's diagnostics).

Diagnostics follow the measured GNU shapes (WSL coreutils 9.4, `rust2/target/probe-1587/gnu-probe*.sh`):

| case | GNU (probed) | WinuxCmd 2.0 now |
| --- | --- | --- |
| `timeout 5 ./hi.sh` (`#!/bin/sh`) | `hi`, rc 0 | `hi`, rc 0 |
| missing command | 127 `failed to run command 'X': No such file or directory` | same |
| shebang with missing interpreter | 127 `... 'X': No such file or directory` (kernel ENOENT) | same |
| directory operand | 126 `... 'X': Permission denied` | same |
| found file, no MZ/`#!` (`./x.js`, plain text) | 126 `Exec format error`* | 126 `Exec format error` |
| `timeout 1 sleep 5` | 124 | 124 |

\* glibc's execvp additionally retries ENOEXEC through `/bin/sh` (probed: a text file "runs", an empty file exits 0 under WSL GNU). That is a libc extension, not execvp/kernel semantics; per the issue contract WinuxCmd reports `Exec format error` instead. Association-run scripts (.js/.ps1 with no shebang) are the same class — GNU-on-msys launches them through Windows associations, which pure execvp resolution cannot; they now get the diagnostic instead of silence.

Also fixed in passing (same extraction): `normalize_entry` required the slash after the drive letter (C++ `childproc.cppm` `is_drive_form`), so `/bin/sh` is no longer mangled into `B:in\sh`; and `nice` rides the shared chain (`build_child_command` keeps its CREATE_SUSPENDED ordering, #1359) so its non-PE children get the same fix. `nohup` lands on main with its spawn family — `-h` now rejects like GNU (`invalid option -- 'h'`, rc 125, probed).

## Verification

- Repro matrix (issue + shebang variants + PATHEXT edges), driver-run: `rust2/target/probe-1587/repro-matrix.sh` — hi.sh → `hi` rc 0; hi.cmd rc 0; no-such 127 + message; `timeout 1 sleep 5` = 124; x.js/x.ps1/plain 126 + `Exec format error`; extensionless shim rc 0; `#!/bin/echo` / `#!/bin/echo -n` argv shapes; absolute path; bare name resolving to a `.cmd` on PATH; directory 126; `#!/usr/bin/env sh` chain via a `__RUBASH_SHELL_ROOT` fixture (batch `env.bat` interpreter → `sh` → script, rc 0).
- Gate: `timeout` 38 GNU + 3 win, `nohup` 21 GNU + 7 win, `nice` 21 GNU — all GREEN; 15 new rows (tm31–tm41, nh25–nh28) in `gate/gen-cases.py`; ledger `rust2/target/gate/ledger.tsv` (e.g. `tm31 rc(r/g/c)=3/3/126` — the script's exit status now propagates on the rust side while C++ still shows the old silent 126).
- `cargo test -p winux-cmds` 489 green; `cargo fmt --check` clean.

## 本 PR 删除了什么

- `timeout.rs` 内联的 execvp 形解析器约 323 行(旧 `ChildResolve` enum、`normalize_entry`、`normalize_path_entries`、`pathext_candidates` 及旧解析函数):逻辑原样移入共享 `childproc.rs`,非功能删除(另修 `normalize_entry` 的 drive 斜杠条件,见上)。
- `nice.rs` 内联的 COMSPEC batch 拼装:改走共享 `build_child_command`,行为不变。
- 其余为新增(`childproc.rs`、`nohup.rs`、gate 新行),无产品功能删除。
@caomengxuan666
caomengxuan666 deleted the rust2/wave4b branch November 18, 2026 05:50
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