Skip to content

recover wave4b: restore the eight command sources + shared childproc spawner lost in the #1577 merge - #1589

Merged
caomengxuan666 merged 17 commits into
mainfrom
recover/wave4b-sources
Nov 12, 2026
Merged

caomengxuan666 merged 17 commits into
mainfrom
recover/wave4b-sources

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

What happened

PR #1577 (wave4b) was merged, but the merge only carried the gate-side files (gen-cases tables/TSVs/COVERAGE) — the eight command sources (factor/pathchk/ptx/shuf/csplit/nohup/groups/who.rs), the shared childproc spawner (childproc.rs), and the bre.rs forward-search extension never reached main (rebase-refstate archaeology: the branch tip at merge time was a gen-cases-graft commit, not the full delivery; the source commits were dropped when the branch was force-pushed mid-review).

What this restores

The full wave4b delivery from the original tip 59218e8, rebased onto current main (which already has the argopt fix, gen-cases graft, CMake single-set line, gate-posix, timeout child-resolution fix, sort, wave4a, borrow-algo, QC round 2):

Verification

  • cargo test -p winux-cmds green (full workspace suite)
  • gen-cases graft: 64 tables, ast-clean, --coverage runs (64 commands/1861 cases) with all referenced setup constants present

- childproc.rs: timeout.rs's execvp-shaped child resolver (PATH-only over
  normalized entries, PATHEXT completion, COMSPEC batches, image-dir
  sibling fallback) extracted so nohup shares one resolver; timeout
  rewired to the module, its 10 tests unchanged green.
- argopt: H_REJECT_SPEC + rejected_short_h for commands where GNU has no
  -h short option (getopt_long matches --help only as a long option;
  probed GNU 9.4: shuf/csplit/pathchk/groups/who/nohup all reject -h
  with "invalid option -- 'h'"). Additive; no existing command changes.
- bre.rs: search_forward/matches_anywhere (leftmost-longest re_search
  semantics) for csplit's /regexp/ line patterns.
- run-gate.sh: export MSYS_NO_PATHCONV=1 and the C++ package bin dir
  ($(dirname $CPP_BIN), the /usr/bin analog) inside both Windows-side
  run.sh scripts, so pattern operands reach the library raw and
  child-spawning commands resolve the same siblings both sides.
- join.rs: cargo fmt drift from the previous commit, now cleaned.
- 14 wave1/wave2 case TSVs regenerated from gen-cases.py: the committed
  tables had drifted from their definitions (wave2a hand-demoted
  --help/--version rows to win for the wired product exe while the
  definitions stayed strict for the driver); regeneration restores
  generator-backedness per the df.tsv precedent. Full 55-table gate
  re-ran green after the change: 1335 GNU-gated + 190 win-gated, 0 fail.

# Conflicts:
#	rust2/README.md
#	rust2/crates/winux-cmds/src/timeout.rs
#	rust2/gate/run-gate.sh
GNU contract (probed coreutils 9.4, target/probe/f1.sh+f2.sh): operands
skip leading spaces + one '+', digits only; 0/1 print bare; factors
ascending; -h/--exponents groups p^e (GNU 9.4 help surface); stdin
tokens split on exactly "\n\t " so \r stays inside the token; any bad
operand reports and exits 1 after processing everything.

Windows value model: little-endian base-2^64 biguint (parse/serialize,
small divmod, schoolbook mul, binary long division), trial division by
primes < 1024, Pollard-Brent rho with deterministic c-walk, Miller-Rabin
over the first 16 prime bases (deterministic far beyond gate operands;
GNU's extra Lucas test is a documented non-port). Performance boundary
(documented): rho needs ~sqrt(p) iterations — operands whose smallest
prime factor approaches 2^65 exceed the gate's 10 s envelope.

-e stays a documented WinuxCmd extension alias (GNU rejects, C++
accepts, win-classified row). 26 gate cases (25 strict + 1 win), all
GREEN byte-for-byte against GNU 9.4; C++ parity 24/26 (the two gaps are
the GNU-branded --help/--version text the driver prints).

GNU evidence: 18446744073709551615 = 3 5 17 257 641 65537 6700417,
F7-class operands excluded by the documented boundary, 25-digit
semiprime strict row pinned byte-for-byte.

# Conflicts:
#	rust2/crates/winux-cmds/src/lib.rs
#	rust2/gate/gen-cases.py
…1488 wave4b)

GNU contract (probed coreutils 9.4, target/probe/pk1.sh; pathchk.c
check order): leading dash (-P) -> empty name (-p/-P) -> portable
character scan (-p) or lstat probe (default) -> total length (_POSIX_
PATH_MAX 256) -> component length (_POSIX_NAME_MAX 14). Default mode
lstats the name: missing is fine, other failures carry the errno text
(regfile/file -> "Not a directory" via a component-chain walk, because
Win32 surfaces ERROR_DIRECTORY where POSIX lstat answers ENOTDIR — the
C++ differential pathchk/01 finding); '' -> "No such file or directory".

Windows subject-side rules belong to the default/-P modes and stay out
of pure-POSIX -p (probed: pathchk -p CON passes on GNU too): reserved
device names (CON..LPT9, stem-before-dot, case-insensitive, trailing
dots/spaces stripped) and invalid characters < > : " | ? * fail with
"invalid Windows filename" where GNU-on-ext4 accepts them — those rows
gate win against the C++ value model.

Probe goes through fs_win::api_path (\\?\ literal device names) plus
probe_dos_device for whole-operand devices and normalize_lex for the
\\?\-prefix lack of loader normalization (trailing separators, ./..).
30 gate cases (27 strict + 3 win) all GREEN against GNU 9.4 rc+stdout;
C++ parity 28/30 (two GNU-branded help/version rows).

# Conflicts:
#	rust2/crates/winux-cmds/src/lib.rs
#	rust2/gate/gen-cases.py
…gine (#1488 wave4b)

GNU contract (probed coreutils 9.4, target/probe/c1.sh; C++ value model
validated in audit #1462): segment files stream as each closing pattern
applies, byte counts print to stdout unless -s/-q; the whole pattern
list parses BEFORE any file is created; line numbers must be
non-decreasing (equal only warns); the LAST delimiter closes a regexp
(/a/b/ searches "a/b"); error paths flush the in-progress file (size
printed) except a negative-offset regexp, which buffers — created files
vanish unless -k; --suppress-matched drops the boundary line; -z elides
empty files; the final remainder always flushes even when empty.

Regexps run on the shared BRE engine (bre.rs search_forward added:
leftmost-longest re_search). Engine subset is documented (no \( \)
groups, \{m,n\} intervals, backreferences); gate regexp cases stay
inside the supported subset and are GNU-diffed. -b suffix formats
validate GNU's flag span at option-parse time (one diuoxX conversion;
# only with oxX, ' only with diu; message order flags-then-conversion
per check_format_conv_type) and render width/zero-pad/precision/alt
forms.

32 gate cases, all strict, all GREEN byte-for-byte against GNU 9.4
(sizes, rc, and the in-progress-flush behavior on every error path);
C++ parity 32/32.

# Conflicts:
#	rust2/crates/winux-cmds/src/lib.rs
#1488 wave4b)

GNU contract (probed coreutils 9.4, target/probe/s1.sh+s2.sh): records
split on \n (or NUL, -z) keeping a final unterminated record; -n 0
short-circuits (empty -o file still created); an overflowing -n count
is no limit; -r with no input dies "no lines to repeat"; the range
splits on the FIRST '-' with "invalid input range: 'V'" (+EOVERFLOW
suffix); usage errors carry the Try line.

--random-source is the strict gate: the entropy-recycling randint port
(state = state*256 + byte; entropy = entropy*256 + 255; margin split
with recursive tail) reproduces GNU 9.4 permutations BYTE-FOR-BYTE on
every seeded row (37/40 strict). Observed-exhaustion split pinned by
probe: a source running dry mid-SHUFFLE continues with identity draws
(4 lines / 1 byte seed -> "2 1 3 4" rc 0) while the repeat path errors
"'seed': end of file" — both behaviors ported exactly.

--random-seed stays the documented WinuxCmd extension: SHA3-256(seed)
keccak-f[1600] port seeds the reduced-round (12) ChaCha block stream,
byte-identical to the C++ DeterministicRng so win rows keep stdout
parity. Default-RNG rows classify exit (nondeterministic on both
sides). GNU has no -h (argopt H_REJECT_MARKER).

40 gate cases (37 strict + 1 exit + 2 win) all GREEN; C++ parity 37/40
(gaps: the seed-extension row and GNU-branded help/version).
…on (#1488 wave4b)

Port of the WinuxCmd ptx subset (src/commands/ptx.cpp, "ptx compatible
subset based on GNU coreutils ptx data flow"), probe base
target/probe/pt2.sh. Byte-strict against GNU 9.4 for the subset's
shapes: default dumb layout (half-grid, right-aligned before field,
gap), -O roff (.xx "" "before" "keyafter" ""), -T tex
(\xx {}{before}{key}{ after}{}), -M macro renames, --format=r|t
abbreviations, -i/-o word filters, -f sort-key folding, error wordings
(cannot open / Is a directory / invalid line width / invalid gap width
/ the --format invalid-argument block).

Documented divergences (win-classified rows, carried from the C++
value model): GNU's default format wraps context CIRCULARLY across the
whole input with head/tail truncation fields; the subset is line-bound
with -F truncation flags. -G switches GNU's OUTPUT format to the
traditional layout; here it only changes word splitting. -S/-W regexp
delimiters are validated but not applied. -t maps to roff. -C is the
WinuxCmd extension banner (GNU rejects). Multi-file inputs wrap across
the file boundary in GNU.

28 gate cases (19 strict + 9 win) all GREEN; C++ parity 26/28.
…1488 wave4b)

GNU contract (probed coreutils 9.4, target/probe/g1.sh+nh2.sh; C++
value model src/commands/nohup.cpp): missing operand exits 125 (127
under POSIXLY_CORRECT — ANY non-NULL value counts, the empty string
included, probed); children resolve execvp-style through the extracted
childproc module (PATH-only, PATHEXT completion, .cmd/.bat through
COMSPEC) with inherited stdio, the caller's env and cwd; resolution
failure is "failed to run command 'C': No such file or directory" rc
127, other spawn failures rc 126; the child's status is the run status.

nohup.c compiles getopt with optstring "+" — NO permutation: only
LEADING options parse, the first operand ends option processing, `--`
is consumed (probed: nohup true --bogus runs true rc 0; nohup --bogus
true dies usage 125; nohup -5 true invalid option 125; nohup -- alone
is missing operand 125; --version extra still prints version rc 0).
The pre-scan splits the leading option segment and hands only that to
argopt, with the usage status 125/127 applied to option errors.

Documented deferral: the terminal faces (stdin -> /dev/null, stdout ->
append nohup.out, stderr -> stdout and their notices) need observing
console-ness, which the injected-IO shape contract forbids ("no
GetStdHandle in the library"); the wiring wave must supply a
driver-side console probe (REPLACEMENT-RECIPE follow-up). The gate
runs both sides under pipes where GNU takes the same no-redirect path,
so every gate row is unaffected. Children named true/false have no
standalone Windows images: those rows gate win (Rust/C++ rc 127
parity). 24 gate cases (18 strict + 6 win) all GREEN; C++ parity 19/24.

# Conflicts:
#	rust2/crates/winux-cmds/src/lib.rs
…#1488 wave4b)

GNU contract (probed coreutils 9.4, target/probe/g1.sh): one
space-joined line per user; a username argument prefixes "user : ";
any per-user failure exits 1 after all users process; an unknown user
is "groups: 'U': no such user" (probed wording, rc 1); GNU has no -h
(argopt H_REJECT_MARKER) and --help/--version print the probed GNU
text.

Windows value model (C++ groups.cpp): membership comes from
NetUserGetGroups (netapi32 FFI, global group list), not the process
token; empty API names are skipped; the well-known "None" primary
group has no POSIX equivalent and prints as its numeric account id
through LookupAccountNameW + the win32_account_id_from_sid derivation
(RID; 0x30000+RID for S-1-5-21-... domain accounts; 0x60000+RID for
integrity SIDs — the same model winsys::sid_to_account applies).
NERR_UserNotFound (2221) maps to the GNU wording; other API failures
keep a system-text diagnostic (win rows).

20 gate cases (16 strict + 4 win) all GREEN against GNU rc+stdout
where the value model is GNU-shaped; C++ parity 16/20 (gaps are the
GNU-branded help/version rows).

# Conflicts:
#	rust2/crates/winux-cmds/src/lib.rs
…#1488 wave4b)

GNU contract (probe base target/probe/g1.sh; C++ value model
src/commands/who.cpp): operands are zero, one (utmp FILE) or two ("am
i" implies -m); a third operand is "who: extra operand 'C'" + try-help
rc 1 (probed); an unopenable FILE simply yields zero records and a
silent exit 0 (probed who /no/such/utmp); -q prints the space-joined
names plus "# users=N"; -H prints the heading through the same field
renderer; rows are %-8s user [ x] %-12s line %-12s time [idle+pid]
%-8s comment, trailing blanks stripped.

Windows value model: sessions enumerate through WTSEnumerateSessionsW
(Active/Disconnected) with WTSQuerySessionInformationW names/idle and
a toolhelp32 walk for the session-leader pid; no enumerable session
falls back to the current interactive user (the C++ simulation face);
mesg state is always '+' (no tty-writability bit); TIME column width
12 per the C++ model where GNU's C locale uses 16 (documented
deviation — even the -H heading gates win). The utmp record views (-a
-b -d -l -p -r -t --lookup --writable) are rejected with the C++
"option is not supported on Windows" diagnostic rc 1 (the option
grammar still accepts them; --message is the GNU -T alias). GNU has
no -h short option (H_REJECT_MARKER).

26 gate cases (6 strict + 20 win) all GREEN; C++ parity 24/26 (gaps
are the GNU-branded help/version rows).
GATE-REPORT.md gains the Wave4b section: per-command verdict table
(226 cases, 1335+190 full-suite green after the harness change, C++
parity 206/226 with every gap attributed), and the documented
deferrals for the wiring wave (nohup console probe, factor operand
size, ptx circular-context grid, shuf infinite -r).

gate/COVERAGE.md gains the wave4b addendum table (the wave3b rows are
likewise pending regeneration, so the addendum stays separate from the
stale total).

# Conflicts:
#	rust2/GATE-REPORT.md
#	rust2/gate/COVERAGE.md
… staging (#1488)

The progressive per-command staging wrote a stage snapshot that carried
a second copy of the ptx paragraph after the pathchk group; the
worktree file (the verified state behind the full 55-table green run)
has each group exactly once. This restores generator-backedness; the
regenerated TSVs are unchanged (28 ptx rows, 226 total).

# Conflicts:
#	rust2/gate/gen-cases.py
…s duplicate block (#1569 semantics preserved)

E0255: the restored wave4b childproc.rs and timeout.rs both defined
resolve_child / quote_windows_arg / ChildResolve. childproc.rs is the
single authority (the restored wave4b bodies were byte-identical to the
timeout.rs copies modulo pub visibility, so the #1569 win32_env_get
case-insensitive PATHEXT lookup and the package-sibling fallback are
unchanged). timeout.rs keeps only its timeout-specific logic and
delegates via the existing `use crate::childproc::{...}` import; nice.rs
re-points the same import from crate::timeout to crate::childproc.
Pinned by timeout::tests::path_env_casing_does_not_break_child_resolution.
…#1488 wave4b)

E0425 + E0308: the wave4b pathchk was written against pre-wave3b
signatures. probe_dos_device moved verbatim from fs_win to
winux_core::path::imp in the wave3b shell-namespace port (#1488), and
fs_win::api_path now takes &Ctx (it absolutizes against ctx.cwd
internally, the same value the old &cwd parameter carried). Call sites
updated; probe semantics unchanged — api_path still hands the probe a
bare device name or a \\?\ path verbatim, the same CreateFileW
GENERIC_READ open the wave4b pathchk was written against.
@caomengxuan666

Copy link
Copy Markdown
Member Author

队长复核在合入后完成(判词 FAIL,两项窄面返工;恢复本体已验真——八模块 + childproc + bre 与原 tip 59218e8 逐文件比对,5/8 模块逐字节同,余下 3 处为有据 recheck 适配;丢失属实)。两项缺陷现已在 master(6fc5ebf7)上,已另立 follow-up:

卷宗:~/workspace/review-winx-1589/CAPTAIN-VERIFY.md(返工范围 §9)。另:#1588 与本 PR 重叠 4 文件(childproc/nohup/timeout/nice),#1588 版为带 #1587 修复的超集,合入顺序上 #1588 应取其版本——队长另行裁断。

caomengxuan666 added a commit that referenced this pull request Nov 12, 2026
…#1587)

Resolve the #1588/#1589 overlap per the captain's union protocol
(~/workspace/review-winx-1588/UNION-PROTOCOL.md): the four code files
take #1588's version wholesale, lib.rs takes the union of both sides'
registrations, nohup.tsv/timeout.tsv take #1588's versions, gen-cases.py
takes the auto-merge result.

gen-cases.py dedup (captain-confirmed, MERGE-REPORT.md §10): drop the
duplicate shadowed second nohup_rows definition (24 rows, wave4b version)
so emit regenerates the committed 28-row nohup.tsv (nh25-nh28 kept);
the other duplicate *_rows groups are pre-existing master warts,
untouched.

Verified at union time: emit consistent (all TSVs byte-identical to
committed); old ChildResolve struct-variant Found { path, batch } zero;
lib.rs nine commands' pub mod + registrations each exactly once;
rustfmt --check clean on the five changed Rust files; cargo check
-p winux-cmds --lib --target x86_64-pc-windows-gnu green.
caomengxuan666 added a commit that referenced this pull request Nov 12, 2026
…d (winx#1590) (#1594)

## Summary

`rust2/gate/run-gate.sh` is a syntax error on master: `bash -n` fails with `line 368: syntax error near unexpected token 'fi'`. The gate script could not execute at all, and no workflow ever called it, so the defect lurked silently after #1589 was merged. This PR restores the four closers #1589's restore dropped and adds a `bash -n` parse check to CI so a future bad restore fails loudly.

Refs #1590

## Changes

- `rust2/gate/run-gate.sh`
  - Restores `done` closing the `for side in rust cpp` loop (line 368).
  - Restores the `if [ "$POSIX_MODE" -eq 1 ]; then` guard around the landing-leak check, with its closing `fi` (which had sat orphaned on master, now re-balanced). The guard is restored, not removed: the section is titled "(posix mode)", the deletion came in the same mangled hunk as the other three dropped closers with no evidence of deliberation, and the landfall concept (niubash#346) is posix-mode-specific.
  - Restores the two `fi` closers for `if [ -n "$setup" ]` and `if [ -e "$cand" ]`.
  - Moves the MSYS_NO_PATHCONV=1 / PATH lines out of the leak-check `while` loop (where they could only pollute gate stdout and never reach a `run.sh`) into the per-side `run.sh`-writing block, as its first two lines — matching `rust2/GATE-REPORT.md`, which documents them as "exported inside both Windows-side run.sh scripts".
  - Proof of scope: `git diff c2fa3db -- rust2/gate/run-gate.sh` on the fixed tree shows only the +11 MSYS lines; everything else is byte-identical to the reviewed pre-#1589 version.
- `.github/workflows/build-winuxcmd.yml`: new `Check gate shell scripts parse` step in the Windows job (right after Checkout) that runs `bash -n rust2/gate/run-gate.sh`.

## Verification

- `bash -n rust2/gate/run-gate.sh`: rc=0 on the fixed tree; rc=2 (`line 368: syntax error near unexpected token 'fi'`) on master `6fc5ebf7`; rc=0 on pre-#1589 base `c2fa3db0` (control).
- Generated `run.sh` content checked via a stubbed copy of the writing block: first two lines are `export MSYS_NO_PATHCONV=1` and `export PATH="$PATH:/d/winux/bin"`, then the command line.
- `bash rust2/gate/run-gate.sh --help`: rc=0, prints GATE SUMMARY (0/0 cases — no `--help.tsv` table); the script executes end to end.
- YAML validated (`yaml.safe_load` OK).
- Full gate run not done here: it needs Windows binaries plus the WSL GNU side, unavailable on the Linux lane machine; the gate's CI legs and the review round cover execution.

## 本 PR 删除了什么

- 无产品代码删除。本 PR 只恢复 `rust2/gate/run-gate.sh` 中被 #1589 误删的四个闭合结构(`done` / `if` / `fi` / `fi`),并把同 hunk 错置的 MSYS 两行从 `while` 循环内移到 `run.sh` 写出块;不删除任何命令实现、测试用例或文档内容。

UNVERIFIED-BY-CAPTAIN
@caomengxuan666
caomengxuan666 deleted the recover/wave4b-sources 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