Skip to content

rust2(port+wire): wc -> rust2 library + bridge (#1488) - #1881

Open
caomengxuan666 wants to merge 36 commits into
mainfrom
rust2/port-wc
Open

caomengxuan666 wants to merge 36 commits into
mainfrom
rust2/port-wc

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Mechanical replacement of wc into rust2/crates/winux-cmds/src/wc.rs (std-only, explicit Io/Ctx, zero process-global stdio) and wired via rust2_bridge in src/commands/wc.cpp + CMakeLists.txt.

  • Preserves all GNU coreutils 9.4 semantics and existing C++ fixes (-l/-w/-c/-m/-L, 7-bit ASCII fast path + multibyte UTF-8 carry decoder, invalid UTF-8 / control / wide-char / combining-char / POSIXLY_CORRECT word-separator rules, --total=WHEN argmatch before opening files, --files0-from=F with per-record error skipping, --debug, directory zero-count line + diagnostic, quote_name_for_output for newline-bearing names, WINUX_SHELL_GLOB=native, fsutil operand open).
  • Adds unit tests in wc.rs and 21 GNU oracle gate cases in rust2/gate/cases/wc.tsv.

@caomengxuan666

Copy link
Copy Markdown
Member Author

CAPTAIN-VERIFY — needs rework

Head a87b69b4 reviewed: code read + CI logs + GNU coreutils 9.4 tarball oracle probes (cloud ~/oracle/coreutils-9.4/bin/wc). One caveat up front: the review lane's devin-windows tree was stopped by an execution-risk flag before any build, so the Rust-side runtime differential is unverified — items below are labeled by evidence class. R0 blocks everything; once it is fixed I will run a re-review lane for the runtime confirmation.

CI — red on 7 checks (head unchanged)

  • 6 build failures, one root cause: error[E0503] in all four build-windows jobs, baseline, and rust-tests — identical error in every log.
  • i18n-drift red independently. rust2-gate and shards are skipping (no artifacts were ever built).

Rework list

  • R0 — E0503 compile error, blocks everything (CI-log proven): wc.rs:412 res.bytes += n conflicts with the process_chunk closure (line 321), which holds &mut res via consume_cp(cp, &mut res, …) at line 401 and is still called at line 414. Fix: accumulate bytes in a plain local u64 in the loop and assign to res.bytes after the loop (or restructure process_chunk as a free function). The two early fast paths compile fine — the bug is only in the general path. Also: 50 warnings in the lib build, including a requested_input_count dead assignment (616/680) — clean it while here.
  • R1 — i18n drift (CI red, keys traced): 5 new drift keys, all stale literals from the deleted C++ wc.cpp ('wc: -: Bad file descriptor', 'wc: debug: line count implementation: ', etc.). Fix: scripts/check_i18n_drift.py --update-baseline.
  • R2 — gate wiring (workflow-read): the text-lines shard is still head tail cut tr od paste — no wc. Once the build passes, the shipped wc.tsv (21 cases) would be reported UNCOVERED, exactly as nl was in rust2(port+wire): nl -> rust2 library + bridge (#1488) #1880. Fix: append wc.
  • R5 — --help / --version print nothing (code-read; GNU side oracle-proven): wc.rs:566 returns Ok(0) silently; no gnuhelp usage anywhere in the file. Gate wc20/wc21 are mode win with empty expected output, so CI would pass this gap silently. Fix per the [2.0 长线] 命令库化:显式 IO 的库形态命令集(Rust 重写候选)与机械替换路线 #1488 help-surface wave: implement both via gnuhelp (verbatim GNU text, cf. head.rs) + unit tests, and promote wc20/wc21 to strict. Scope note (same as rust2(port+wire): nl -> rust2 library + bridge (#1488) #1880): in the shipped exe the dispatcher intercepts --help/--version with branded help, so this is a driver/gate-parity gap, not a user-visible divergence.
  • R6 — long-option abbreviation unsupported (code-read; GNU side oracle-proven): the parser matches long names exactly. GNU accepts --byte s and --tot=al s (rc=0); the port returns rc=1 unrecognized option. Likely a parser-framework gap, not wc-specific — check whether siblings share it before fixing only in wc.
  • R7 — --debug text and shape wrong (code-read; GNU side oracle-proven, stderr separated): the Rust port prints wc: debug: line count implementation: … on stderr in every mode when --debug is set. GNU prints wc: using avx2 hardware support only in -l mode, and is silent for --debug in default/-c/-m/-L modes. Note: the exact GNU implementation string is CPU-dependent; the fix is about the shape (only -l, GNU's wc: using <impl> hardware support format), not the literal avx2. This is a pre-existing divergence inherited from the old C++ implementation, not a new port bug — still needs the fix.
  • C1 (minor) — Try 'wc --help' tail missing on two error paths (code-read; GNU side oracle-proven): the --total argmatch errors (wc.rs:607) and the --files0-from + operand conflict (wc.rs:623) use bare writeln! without the trailing Try 'wc --help' for more information. line. GNU's exact texts (including the Valid arguments are: list) were taken from the oracle.
  • C2 (minor, narrow) — number width, stdin with ≥10⁷ counts (code-read + GNU-side oracle-proven): 12 MB via stdin → GNU widens to 8 ( 2 2 12000004); the Rust compute_number_width caps stdin at 7. Fix: let the width floor account for the largest printed count, not only regular-file sizes.

What matches (code-read + oracle-side probes; no finding)

Counting core looks faithful: ASCII fast path + multibyte carry decoder, POSIXLY_CORRECT word-separator set, tab-to-8 and wide/combining display-width rules for -L, invalid-UTF-8 handling. Two of my first suspicions were disproved by the oracle: control characters are not word characters in GNU (\x01 alone counts 0 words), and the Rust handling matches. --total semantics (abbreviation/ambiguity/invalid), directory and missing operands, and the bridge wiring (lib.rs registry, CMakeLists.txt alphabetical insert, wc.cpp forwarding raw args) are all clean.

Rework, then re-request review — the re-review lane will run the Rust-side differential (R0 fix verification + runtime confirmation of R5–R7/C1/C2) once the tree is cleared for build. No captain decision needed — all items above are concrete.

@caomengxuan666

Copy link
Copy Markdown
Member Author

Captain re-review of 2e727b2d: still needs rework — only R0 is fixed.

Verified on devin-windows against the pristine GNU coreutils 9.4 tarball oracle; 46 probes, 33 byte-identical, 13 divergences, all mapping to the items below.

Fixed: R0 — the E0503 borrow error is gone; cargo build green and all 3 wc unit tests pass. The counting core survives the refactor intact (64 KiB multibyte split, control chars, invalid UTF-8, large-file width, files0-from — 33 cases identical).

Still open:

  • R1 i18n drift: the same 5 stale keys remain in the catalog; the catalog was untouched.
  • R2 gate shard: the text-lines shard still lists head tail cut tr od paste — no wc.
  • R5 --help/--version: still silent (return Ok(0)); GNU prints full help/version.
  • R6 abbreviation: --byte, --tot=al still rc=1; GNU accepts them.
  • R7 --debug: still prints in every mode; only -l mode matches GNU's shape (the literal differs — CPU-dependent, not judged).
  • C1 Try 'wc --help' tail: both error paths unchanged. New note: under a UTF-8 locale GNU quotes with ‘ ’ while Rust uses ASCII quotes.
  • C2 stdin large-count width: narrowed — only when stdin is a regular file (12 MB: GNU width 8, Rust width 7, confirmed with a real-file stdin probe); piped stdin matches at width 7 on both sides.
  • C3 (new): --files0-from=- column width — Rust widens by the listed files' sizes (width 2 for small files, 8 for large), GNU does not (width 1); with a file as the list both sides agree.

Not mergeable yet. Next rework is the same list: R1 run --update-baseline, R2 add the shard, R5 gnuhelp, R6 abbreviation support, R7 -l-only debug, C1 Try tails, C2 regular-file stdin width, C3 no widening for a stdin list.

Method note for the record: the oracle's stdin must be piped — redirecting a file makes GNU treat stdin as a regular file and changes its width arithmetic (my first pass counted 24 extra false divergences this way; the re-run corrected it).

@caomengxuan666

Copy link
Copy Markdown
Member Author

Captain re-review of bbce0b8c (round 2): still needs rework.

Build is green and the 3 wc unit tests pass; the counting core shows no regression. The new commit (treat WinuxCmd FIFO markers as non-regular in the width calculation) is itself correct — verified with a real FIFO marker (content !<fifo> + SYSTEM attribute, writer thread feeding x y\n): counts come through the pipe correctly and the width uses the floor of 7 instead of summing the 7-byte marker as a regular file. It may stay. But it is not on the rework list from my previous comment, and it does not touch C3 — C3 is about the files listed via --files0-from=-, not about - itself.

All eight items from the previous round are still open, re-verified at runtime on this head:

  • R1 — the 5 stale i18n keys are still in en-US-ls.json / en-US-mv.json; i18n-drift CI will still be red. Run --update-baseline.
  • R2 — the gate shard still reads "head tail cut tr od paste"; add wc.
  • R5 — --help / --version still silent (wc.rs still returns Ok(0) with no output). Route through gnuhelp and promote the gate cases to strict.
  • R6 — --byte / --tot=al still fail with rc 1 unrecognized; GNU accepts unambiguous abbreviations with rc 0.
  • R7 — --debug still prints in every mode; GNU prints only in -l mode, and the shape differs (the literal is CPU-dependent — match the shape, not the string).
  • C1 — no Try 'wc --help' tail anywhere; the f-f0-conflict / s-total-amb / s-total-bad probes still lack it. Under a UTF-8 locale GNU also quotes with ‘ ’ where the Rust side uses ASCII quotes.
  • C2 — regular-file stdin (12 MB) still computes width 7 vs GNU's 8; piped stdin agrees at 7. This one needs stdin metadata to cross the Io abstraction.
  • C3 — --files0-from=- still widens by the listed files' sizes: small list 2 vs GNU 1, 12 MB list 8 vs GNU 1. With a file as the list both sides agree.

46-case probe differential against the GNU coreutils 9.4 tarball oracle: 33/46 byte-identical, the same 13 divergences as the previous round (C1×3, R5×2, R6×2, R7×5, C3×1), plus the directed C2 and C3-big probes. The prescription is unchanged from the previous comment; please work the list itself next round.

@caomengxuan666

Copy link
Copy Markdown
Member Author

Captain re-review, round 3 — head d01bb825, verified on X299 against the tarball GNU coreutils 9.4 oracle.

This head contains one commit, and it is not on the rework list: the legacy C++ i18n probe switches from wc -l to expr 1 because wc no longer goes through the legacy translation path. That adaptation is reasonable and can stay — but wc.rs is byte-identical to the previous head (sha256 checked on both sides), so none of the eight rework items moved:

  • R1 — not fixed. All 5 stale keys still present in the ls/mv catalogs; i18n-drift still FAIL on this head.
  • R2 — not fixed. Gate shard still "head tail cut tr od paste"; rust2-gate aggregator still FAIL (wc.tsv UNCOVERED).
  • R5 — not fixed. No gnuhelp wiring; --help/--version still 0 bytes vs GNU's 1344; gate cases wc20/wc21 still win mode, not strict.
  • R6 — not fixed. --byte / --tot=al still rc 1 unrecognized (GNU rc 0).
  • R7 — not fixed. --debug still prints in all modes with the legacy literal; GNU prints only in -l mode, and with a different shape.
  • C1 — not fixed. No Try 'wc --help' tail anywhere in wc.rs; under a UTF-8 locale GNU uses ‘ ’ quotes, Rust still uses ASCII quotes.
  • C2 — not fixed. Regular-file stdin (12 MB): Rust width 7, GNU width 8. Piped stdin agrees at 7 on both sides.
  • C3 — not fixed. --files0-from=-: small list Rust 2 / GNU 1; 12 MB list Rust 8 / GNU 1.

46-probe differential: 33/46 byte-identical, the same 13 divergences as rounds 1–2 (C1×3, R5×2, R6×2, R7×5, C3×1), plus the directed C2 and C3-big probes diverging as before. The counting core has no regression, and last round's FIFO width fix is intact (re-verified with a real FIFO marker on X299).

Build is green and the 3 wc unit tests pass; what blocks this PR is R1/R2 on CI plus the six runtime items above. The prescription is unchanged from the two previous captain comments — please work the list itself in the next round; I will re-verify as soon as a head touches wc.rs, the catalogs, or the shard.

caomengxuan666 and others added 21 commits November 27, 2026 08:02
Windows filenames cross the narrow boundary as UTF-8 regardless of the
legacy system locale, while interactive ls defaults to shell-escape
quoting. Treating an unset POSIX locale as the C locale made ordinary
CJK names render as octal byte splices for typical Windows users.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
fix(ls): keep printable Unicode literal without POSIX locale
…rals

fix(csplit): preserve trailing literals and UTF-8 in suffix format
fix(fold): parse numeric width from current index in clustered short options
fix(od): mask high-order bit in named character output (-a / -t a)
…ents

fix(ls): merge adjacent $'...' segments in shell-escape quoting (Fixes #1890)
fix(ptx): slice context and fallback truncations on raw bytes like GNU
…nuxcmd

docs: adopt all-contributors, add dingyi580, ShiomiHC, qwased
…#1919)

parse_char_class's is_range required prev_takes_range, so every range
after the first in a bracket expression (or after a POSIX class /
collating element) degraded to literal members: [A-Za-z] lost a-z,
[A-Za-z_]+ silently mis-matched, [[:digit:]a-f] lost a-f. Regression
introduced in 1.2.2 (1.2.1 matches GNU grep 3.12 / sed 4.9).

Drop the prev_takes_range requirement from is_range (one line). The
flag's legitimate use — the Invalid-range-end check for [a-c-e],
[[:alpha:]-9], [[.a.]-z] — is untouched, and those shapes still error.

New pins in tests/issue1911_ranges.rs (14): multi-range classes in
both orders, range after POSIX class, negated multi-range, three
ranges, -i multi-range, BRE form, matches_entire (find -regex face),
plus the five regression faces above and [a-c-] / []-a].

Refs #1911
UNVERIFIED-BY-CAPTAIN
-n mapped to Interactive::AlwaysNo (cp.c:1070) instead of the Ubuntu
.deb's silent AlwaysSkip: an existing destination now reports
'not replacing <dst>' and fails the file (copy.c:2438), a fresh copy
under -n prints nothing, and the .deb-only deprecation warning is
gone (no_clobber_seen deleted; make_backups added for the cp.c:1220
--backup/--no-clobber mutual exclusion, set by -b/--backup and
-S/--suffix per cp.c:1027/1191). --update=none keeps the silent
AlwaysSkip form. New i18n keys: command.cp.error.not_replacing,
command.cp.error.backup_and_no_clobber (mv precedent).

Refs #1879 (not Fixes).
… .deb

The three -n-final rows were calibrated against the WSL distro's
Ubuntu .deb cp 9.4, whose -n is patched to a silent rc-0 skip. The
pristine coreutils 9.4 tarball oracle (this project's standard)
prints "cp: not replacing '<dst>'" and exits 1 for exactly these
combinations (-n, -nv, -nv --update=all, -v -i -n), matching the
port after this PR. The rows stay as record-only (note) so both
sides keep being measured without gating on the .deb divergence.
cp: -n is I_ALWAYS_NO per pristine GNU 9.4 (#1879)
caomengxuan666 and others added 8 commits November 30, 2026 01:56
… cwd (Refs #1980)

Refs #1980 (not Fixes).

The --parents intermediate loop walked every '\\' prefix of the
whole destination path, so for a backslash drive-absolute
destination the first prefix created was the bare drive designator
("C:"). Since #1874 a bare "C:" folds to the relative name
"C<U+F03A>" and landed as a stray directory in the cwd — silent
(copy correct, rc 0), and it fired even when no intermediate
directory needed creating, including $TEMP-derived destinations.
GNU's make_dir_parents_private creates only below the destination,
and the destination itself is required to exist (--parents, #1066),
so none of its prefixes ever needs creating here: start the scan
at destPath.size(). The #1874 fold itself is untouched (the
bare-"D:"-is-a-relative-name contract is deliberate).

Pin: cp_parents_backslash_drive_dest_leaves_no_drive_dir — the
reporter's 4-case repro verbatim (backslash drive-absolute dest
with/without trailing backslash, forward-slash control, no
--parents control) plus a $TEMP-derived destination case; each
asserts the copy, rc 0, and that the cwd listing is unchanged.
The five cwd-listing assertions used EXPECT_EQ on two
std::set<std::string> values; wctest::expect_eq_impl only
accepts strings (C2664 on the x64 default leg). Switch them to
EXPECT_TRUE(set == set). No production code touched.
fix(cp): --parents no longer creates the bare drive designator in the cwd (Refs #1980)
* rust2(port+wire): cat -> rust2 library + bridge (#1488)

* fix(cat): route /dev/stdin family operands to stdin

* fix(cat): honor WINUX_SHELL_GLOB=done, trailing-slash dir, and dir-on-stdin (#1803)

* fix(ls): keep printable Unicode literal without POSIX locale (#1883)

Windows filenames cross the narrow boundary as UTF-8 regardless of the
legacy system locale, while interactive ls defaults to shell-escape
quoting. Treating an unset POSIX locale as the C locale made ordinary
CJK names render as octal byte splices for typical Windows users.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* fix(ls): merge adjacent $'...' segments in shell-escape quoting (Fixes #1890)

* fix(ptx): align fallback context truncation to UTF-8 char boundaries

* fix(csplit): preserve trailing literals and UTF-8 in suffix format

* fix(fold): parse numeric width from current index in clustered short options

* fix(od): mask high-order bit in named character output (-a / -t a)

* fix(ptx): slice context and fallback truncations on raw bytes like GNU

* docs: adopt all-contributors, add dingyi580, ShiomiHC, qwased

* fix(canon): realpath -m relative .. ascends from cwd again (Refs #1908) (#1918)

* fix(winux-regex): restore ranges after the first in character classes (#1919)

parse_char_class's is_range required prev_takes_range, so every range
after the first in a bracket expression (or after a POSIX class /
collating element) degraded to literal members: [A-Za-z] lost a-z,
[A-Za-z_]+ silently mis-matched, [[:digit:]a-f] lost a-f. Regression
introduced in 1.2.2 (1.2.1 matches GNU grep 3.12 / sed 4.9).

Drop the prev_takes_range requirement from is_range (one line). The
flag's legitimate use — the Invalid-range-end check for [a-c-e],
[[:alpha:]-9], [[.a.]-z] — is untouched, and those shapes still error.

New pins in tests/issue1911_ranges.rs (14): multi-range classes in
both orders, range after POSIX class, negated multi-range, three
ranges, -i multi-range, BRE form, matches_entire (find -regex face),
plus the five regression faces above and [a-c-] / []-a].

Refs #1911
UNVERIFIED-BY-CAPTAIN

* fix(od): warn and fall back to the format-size LCM for a non-multiple -w width (#1951)

Refs #1943

* cp: -n is I_ALWAYS_NO per pristine GNU 9.4 (#1879)

-n mapped to Interactive::AlwaysNo (cp.c:1070) instead of the Ubuntu
.deb's silent AlwaysSkip: an existing destination now reports
'not replacing <dst>' and fails the file (copy.c:2438), a fresh copy
under -n prints nothing, and the .deb-only deprecation warning is
gone (no_clobber_seen deleted; make_backups added for the cp.c:1220
--backup/--no-clobber mutual exclusion, set by -b/--backup and
-S/--suffix per cp.c:1027/1191). --update=none keeps the silent
AlwaysSkip form. New i18n keys: command.cp.error.not_replacing,
command.cp.error.backup_and_no_clobber (mv precedent).

Refs #1879 (not Fixes).

* test(gate): cp32/cp34/cp39 record-only — gate GNU side is the patched .deb

The three -n-final rows were calibrated against the WSL distro's
Ubuntu .deb cp 9.4, whose -n is patched to a silent rc-0 skip. The
pristine coreutils 9.4 tarball oracle (this project's standard)
prints "cp: not replacing '<dst>'" and exits 1 for exactly these
combinations (-n, -nv, -nv --update=all, -v -i -n), matching the
port after this PR. The rows stay as record-only (note) so both
sides keep being measured without gating on the .deb divergence.

* fix(cp): --parents no longer creates the bare drive designator in the cwd (Refs #1980)

Refs #1980 (not Fixes).

The --parents intermediate loop walked every '\\' prefix of the
whole destination path, so for a backslash drive-absolute
destination the first prefix created was the bare drive designator
("C:"). Since #1874 a bare "C:" folds to the relative name
"C<U+F03A>" and landed as a stray directory in the cwd — silent
(copy correct, rc 0), and it fired even when no intermediate
directory needed creating, including $TEMP-derived destinations.
GNU's make_dir_parents_private creates only below the destination,
and the destination itself is required to exist (--parents, #1066),
so none of its prefixes ever needs creating here: start the scan
at destPath.size(). The #1874 fold itself is untouched (the
bare-"D:"-is-a-relative-name contract is deliberate).

Pin: cp_parents_backslash_drive_dest_leaves_no_drive_dir — the
reporter's 4-case repro verbatim (backslash drive-absolute dest
with/without trailing backslash, forward-slash control, no
--parents control) plus a $TEMP-derived destination case; each
asserts the copy, rc 0, and that the cwd listing is unchanged.

* fixup: EXPECT_EQ only takes strings in the test framework

The five cwd-listing assertions used EXPECT_EQ on two
std::set<std::string> values; wctest::expect_eq_impl only
accepts strings (C2664 on the x64 default leg). Switch them to
EXPECT_TRUE(set == set). No production code touched.

---------

Co-authored-by: caomengxuan666 <[email protected]>
Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: dingyi580 <[email protected]>
* test: pin #1874 per-component carrier-colon operand shapes

Fail-first pins for the per-component fold contract: winux-core unit
pins (non-final components, ADS-shaped spellings, mid-path designator
shapes, bare D: as a relative colon name), canon boundary pins through
prepare_operand, and C++ ls/stat applet pins against an on-disk
carrier tree. The bare-D: and canon pins are re-baselined to the
#1874 contract ruled with the rubash #4198 caliber and probed against
Git Bash on a real host.

* fix(path): fold carrier colons per component in both fold twins (#1874)

fold_carrier_colons (winux-core) and fold_carrier_colons_w
(native_path.cppm) encoded only the final component, so operands
with a literal colon in a non-final component (x:y/z, ./x:y/z,
C:\x:y\z) never resolved the carrier tree the shell creates.
Both folds now encode every component, byte-identically: the one
exemption is the path's own drive designator in its absolute form
(D:\ / D:/); a bare D: is a relative colon name and folds like
D:name (MSYS contract, probed against Git Bash); designator-shaped
components mid-path fold as ordinary components; verbatim/device
spellings keep passing through untouched.

* rust2(port+wire): uniq -> rust2 library + bridge (#1488)

* fix(uniq): align open_write_operand and invalid_option signatures

* fix(uniq): use u32 CmdResult and winux_core::test_support in tests

* fix(uniq): fix -1 +1 test assertion and support -D5 cluster digits

* fix(ls): keep printable Unicode literal without POSIX locale (#1883)

Windows filenames cross the narrow boundary as UTF-8 regardless of the
legacy system locale, while interactive ls defaults to shell-escape
quoting. Treating an unset POSIX locale as the C locale made ordinary
CJK names render as octal byte splices for typical Windows users.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* fix(ls): merge adjacent $'...' segments in shell-escape quoting (Fixes #1890)

* fix(ptx): align fallback context truncation to UTF-8 char boundaries

* fix(csplit): preserve trailing literals and UTF-8 in suffix format

* fix(fold): parse numeric width from current index in clustered short options

* fix(od): mask high-order bit in named character output (-a / -t a)

* fix(ptx): slice context and fallback truncations on raw bytes like GNU

* docs: adopt all-contributors, add dingyi580, ShiomiHC, qwased

* fix(canon): realpath -m relative .. ascends from cwd again (Refs #1908) (#1918)

* fix(winux-regex): restore ranges after the first in character classes (#1919)

parse_char_class's is_range required prev_takes_range, so every range
after the first in a bracket expression (or after a POSIX class /
collating element) degraded to literal members: [A-Za-z] lost a-z,
[A-Za-z_]+ silently mis-matched, [[:digit:]a-f] lost a-f. Regression
introduced in 1.2.2 (1.2.1 matches GNU grep 3.12 / sed 4.9).

Drop the prev_takes_range requirement from is_range (one line). The
flag's legitimate use — the Invalid-range-end check for [a-c-e],
[[:alpha:]-9], [[.a.]-z] — is untouched, and those shapes still error.

New pins in tests/issue1911_ranges.rs (14): multi-range classes in
both orders, range after POSIX class, negated multi-range, three
ranges, -i multi-range, BRE form, matches_entire (find -regex face),
plus the five regression faces above and [a-c-] / []-a].

Refs #1911
UNVERIFIED-BY-CAPTAIN

* fix(od): warn and fall back to the format-size LCM for a non-multiple -w width (#1951)

Refs #1943

* cp: -n is I_ALWAYS_NO per pristine GNU 9.4 (#1879)

-n mapped to Interactive::AlwaysNo (cp.c:1070) instead of the Ubuntu
.deb's silent AlwaysSkip: an existing destination now reports
'not replacing <dst>' and fails the file (copy.c:2438), a fresh copy
under -n prints nothing, and the .deb-only deprecation warning is
gone (no_clobber_seen deleted; make_backups added for the cp.c:1220
--backup/--no-clobber mutual exclusion, set by -b/--backup and
-S/--suffix per cp.c:1027/1191). --update=none keeps the silent
AlwaysSkip form. New i18n keys: command.cp.error.not_replacing,
command.cp.error.backup_and_no_clobber (mv precedent).

Refs #1879 (not Fixes).

* test(gate): cp32/cp34/cp39 record-only — gate GNU side is the patched .deb

The three -n-final rows were calibrated against the WSL distro's
Ubuntu .deb cp 9.4, whose -n is patched to a silent rc-0 skip. The
pristine coreutils 9.4 tarball oracle (this project's standard)
prints "cp: not replacing '<dst>'" and exits 1 for exactly these
combinations (-n, -nv, -nv --update=all, -v -i -n), matching the
port after this PR. The rows stay as record-only (note) so both
sides keep being measured without gating on the .deb divergence.

* fix(cp): --parents no longer creates the bare drive designator in the cwd (Refs #1980)

Refs #1980 (not Fixes).

The --parents intermediate loop walked every '\\' prefix of the
whole destination path, so for a backslash drive-absolute
destination the first prefix created was the bare drive designator
("C:"). Since #1874 a bare "C:" folds to the relative name
"C<U+F03A>" and landed as a stray directory in the cwd — silent
(copy correct, rc 0), and it fired even when no intermediate
directory needed creating, including $TEMP-derived destinations.
GNU's make_dir_parents_private creates only below the destination,
and the destination itself is required to exist (--parents, #1066),
so none of its prefixes ever needs creating here: start the scan
at destPath.size(). The #1874 fold itself is untouched (the
bare-"D:"-is-a-relative-name contract is deliberate).

Pin: cp_parents_backslash_drive_dest_leaves_no_drive_dir — the
reporter's 4-case repro verbatim (backslash drive-absolute dest
with/without trailing backslash, forward-slash control, no
--parents control) plus a $TEMP-derived destination case; each
asserts the copy, rc 0, and that the cwd listing is unchanged.

* fixup: EXPECT_EQ only takes strings in the test framework

The five cwd-listing assertions used EXPECT_EQ on two
std::set<std::string> values; wctest::expect_eq_impl only
accepts strings (C2664 on the x64 default leg). Switch them to
EXPECT_TRUE(set == set). No production code touched.

* rust2(port+wire): cat -> rust2 library + bridge (#1488) (#1882)

* rust2(port+wire): cat -> rust2 library + bridge (#1488)

* fix(cat): route /dev/stdin family operands to stdin

* fix(cat): honor WINUX_SHELL_GLOB=done, trailing-slash dir, and dir-on-stdin (#1803)

* fix(ls): keep printable Unicode literal without POSIX locale (#1883)

Windows filenames cross the narrow boundary as UTF-8 regardless of the
legacy system locale, while interactive ls defaults to shell-escape
quoting. Treating an unset POSIX locale as the C locale made ordinary
CJK names render as octal byte splices for typical Windows users.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* fix(ls): merge adjacent $'...' segments in shell-escape quoting (Fixes #1890)

* fix(ptx): align fallback context truncation to UTF-8 char boundaries

* fix(csplit): preserve trailing literals and UTF-8 in suffix format

* fix(fold): parse numeric width from current index in clustered short options

* fix(od): mask high-order bit in named character output (-a / -t a)

* fix(ptx): slice context and fallback truncations on raw bytes like GNU

* docs: adopt all-contributors, add dingyi580, ShiomiHC, qwased

* fix(canon): realpath -m relative .. ascends from cwd again (Refs #1908) (#1918)

* fix(winux-regex): restore ranges after the first in character classes (#1919)

parse_char_class's is_range required prev_takes_range, so every range
after the first in a bracket expression (or after a POSIX class /
collating element) degraded to literal members: [A-Za-z] lost a-z,
[A-Za-z_]+ silently mis-matched, [[:digit:]a-f] lost a-f. Regression
introduced in 1.2.2 (1.2.1 matches GNU grep 3.12 / sed 4.9).

Drop the prev_takes_range requirement from is_range (one line). The
flag's legitimate use — the Invalid-range-end check for [a-c-e],
[[:alpha:]-9], [[.a.]-z] — is untouched, and those shapes still error.

New pins in tests/issue1911_ranges.rs (14): multi-range classes in
both orders, range after POSIX class, negated multi-range, three
ranges, -i multi-range, BRE form, matches_entire (find -regex face),
plus the five regression faces above and [a-c-] / []-a].

Refs #1911
UNVERIFIED-BY-CAPTAIN

* fix(od): warn and fall back to the format-size LCM for a non-multiple -w width (#1951)

Refs #1943

* cp: -n is I_ALWAYS_NO per pristine GNU 9.4 (#1879)

-n mapped to Interactive::AlwaysNo (cp.c:1070) instead of the Ubuntu
.deb's silent AlwaysSkip: an existing destination now reports
'not replacing <dst>' and fails the file (copy.c:2438), a fresh copy
under -n prints nothing, and the .deb-only deprecation warning is
gone (no_clobber_seen deleted; make_backups added for the cp.c:1220
--backup/--no-clobber mutual exclusion, set by -b/--backup and
-S/--suffix per cp.c:1027/1191). --update=none keeps the silent
AlwaysSkip form. New i18n keys: command.cp.error.not_replacing,
command.cp.error.backup_and_no_clobber (mv precedent).

Refs #1879 (not Fixes).

* test(gate): cp32/cp34/cp39 record-only — gate GNU side is the patched .deb

The three -n-final rows were calibrated against the WSL distro's
Ubuntu .deb cp 9.4, whose -n is patched to a silent rc-0 skip. The
pristine coreutils 9.4 tarball oracle (this project's standard)
prints "cp: not replacing '<dst>'" and exits 1 for exactly these
combinations (-n, -nv, -nv --update=all, -v -i -n), matching the
port after this PR. The rows stay as record-only (note) so both
sides keep being measured without gating on the .deb divergence.

* fix(cp): --parents no longer creates the bare drive designator in the cwd (Refs #1980)

Refs #1980 (not Fixes).

The --parents intermediate loop walked every '\\' prefix of the
whole destination path, so for a backslash drive-absolute
destination the first prefix created was the bare drive designator
("C:"). Since #1874 a bare "C:" folds to the relative name
"C<U+F03A>" and landed as a stray directory in the cwd — silent
(copy correct, rc 0), and it fired even when no intermediate
directory needed creating, including $TEMP-derived destinations.
GNU's make_dir_parents_private creates only below the destination,
and the destination itself is required to exist (--parents, #1066),
so none of its prefixes ever needs creating here: start the scan
at destPath.size(). The #1874 fold itself is untouched (the
bare-"D:"-is-a-relative-name contract is deliberate).

Pin: cp_parents_backslash_drive_dest_leaves_no_drive_dir — the
reporter's 4-case repro verbatim (backslash drive-absolute dest
with/without trailing backslash, forward-slash control, no
--parents control) plus a $TEMP-derived destination case; each
asserts the copy, rc 0, and that the cwd listing is unchanged.

* fixup: EXPECT_EQ only takes strings in the test framework

The five cwd-listing assertions used EXPECT_EQ on two
std::set<std::string> values; wctest::expect_eq_impl only
accepts strings (C2664 on the x64 default leg). Switch them to
EXPECT_TRUE(set == set). No production code touched.

---------

Co-authored-by: caomengxuan666 <[email protected]>
Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: dingyi580 <[email protected]>

---------

Co-authored-by: caomengxuan666 <[email protected]>
Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: dingyi580 <[email protected]>
@caomengxuan666

Copy link
Copy Markdown
Member Author

Captain re-review, round 4 — head a74f9934, verified against the tarball GNU coreutils 9.4 oracle. Not mergeable — this round introduces a real regression.

Fixed this round:

  • R1 — fixed. The 5 stale keys are recorded in scripts/i18n-drift-baseline.json (zh-CN extra, verified), exactly as round 1 prescribed; i18n-drift now passes. The keys still physically sit in the catalogs — a future sync batch should remove them.

New regression — the merge blocker:

  • N2 — clone_stdin pruning is wrong; delete it. The new code zeroes any post-- operand naming the same file as stdin, claiming GNU prints 1 2 4 - / 0 0 0 f. The pristine 9.4 oracle says otherwise in every shape I probed: wc - fa < fa, wc fa - < fa, wc - ./fa < fa, wc - big1 < big1, wc fa fa < fa, and pipe stdin all count the named file in full (total 2 4 8 / 2400000 …). The only zeroing GNU does is a repeated - (wc - - < fa → second - is 0 0 0, stdin already consumed) — which the port already gets right without pruning. Round 3 matched GNU here; this head breaks it, and no unit test covers the pruning, so CI passes it silently. Fix: delete the pruning block and the now-unused same_file_as_stdin(), and add a differential pin for wc - f < f (both rows full).

Still open from round 3:

  • R2 — not fixed. The text-lines shard still lacks wc; rust2-gate fails on this head with UNCOVERED case tables: cat, uniq, wc. (cat/uniq are other PRs' debt; this PR only owes wc.)
  • R5 — not fixed. --help/--version still return silent Ok(0); no gnuhelp wiring; wc20/wc21 still win mode.
  • R6 — not fixed. Long options still exact-match only; --byte / --tot=al still rc 1 (GNU rc 0).
  • R7 — not fixed. --debug still prints the legacy literal in all modes; GNU prints only in -l, as wc: using <impl> hardware support.
  • C1 — not fixed. Both raw error paths still lack the Try 'wc --help' tail; under a UTF-8 locale GNU quotes the --total argument with ‘ ’, the port uses ASCII quotes.
  • C3 — not fixed. Files listed via --files0-from=- still feed the width basis (compute_number_width unchanged on that path); GNU prints width 1 for them regardless of size.

Verified good this round:

  • The new --files0-from record handling matches the oracle exactly: leading zero-length record diagnosed (-:1:), interior empty record diagnosed (-:2:), unterminated tail kept when nonempty (fa\0fa → fa twice, rc 0). One nit: the test-block comment says "(tail dropped)" — the oracle and the test itself say kept; please fix the comment.
  • C2's new code (regular-file stdin contributes its size via stdin_meta()) reads correctly against the oracle rule (redir width 8/2 vs pipe width 7, re-probed), but I could not run the port side this round — see below.

Procedural note: fetching this head into the devin-windows lane tree tripped an execution-risk check, so no build/test/probe ran on Windows this round; the R5/R6/R7/C1/C3 verdicts rest on code-read (those regions are unchanged since round 3, where the divergences were runtime-proven) plus oracle probes. The C2 fix and the N2 fix verification both need a Windows run once the tree is approved. The wc03-dash demotion to note is defensible given the harness's pipe-vs-file asymmetry, but its out-of-harness claim is unverified this round, and its comment's byte counts don't match the fixture (hello world\n is 12 bytes, GNU redir prints 1 2 12 -).

Build is green and the 3 new files0 unit tests pass; what blocks this PR is N2 first, then R2 on CI, then the six runtime items above.

@caomengxuan666

Copy link
Copy Markdown
Member Author

队长补充:C2 已实测修复、N2 已实测坐实(2026-12-01)

在批准的树(@ a74f9934,devin-windows,windows-gnu;oracle 侧本轮在 cloud pristine coreutils 9.4 复跑,与 r4 卷宗一致)上完成 r4 留待的两项实测:

  • C2 确认已修:重定向 stdin 与管道 stdin 两种介质都与 oracle 逐字节一致——12MB 文件重定向宽度 8、管道 7;12 字节文件重定向 1 2 12 -、管道 7 宽。N1 遗留的主张一并结清。
  • N2 确认是真回归(运行时):wc - fa < fa port 输出 0 0 0 fa,oracle 为 1 2 4 fa;wc - ./fa < fa 同形归零;wc - big1 < big1 归零且 total 减半。对照形(操作数在 - 之前、无 - 的重复、管道 stdin)均与 GNU 一致,合法的重复 - 归零对照正确。r4 的处方不变、现已附运行时证据:删掉 pruning 块与不再使用的 same_file_as_stdin(),并加 wc - f < f 差分 pin。

返工清单其余项不变(见 r4 复核 7285398765)。

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