Skip to content

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

Merged
caomengxuan666 merged 33 commits into
mainfrom
rust2/port-uniq
Nov 30, 2026
Merged

caomengxuan666 merged 33 commits into
mainfrom
rust2/port-uniq

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

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

  • Preserves all GNU coreutils 9.4 semantics and existing C++ fixes (-c/-d/-D[=METHOD]/--group[=METHOD] with argmatch prefix matching, -f/-s/-w size_opt clamping, obsolete -NUM / +NUM, -z, streaming group window, WINUX_SHELL_GLOB=native, fsutil::open_read_operand/open_write_operand).
  • Adds unit tests in uniq.rs and 27 GNU oracle gate cases in rust2/gate/cases/uniq.tsv.

caomengxuan666 and others added 5 commits November 25, 2026 14:54
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.
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.
fix(path): fold carrier colons per component in both fold twins (#1874)
@caomengxuan666

Copy link
Copy Markdown
Member Author

CAPTAIN REVIEW — needs rework. Verified locally against the PR head; three rework items, then three captain rulings on the inherited faces.

R1 — the PR does not compile (hard blocker). CI is 8 fail / 2 pass; every failure traces to two roots. uniq.rs:652: Ok(rc) with rc: i32 against CmdResult = Result<u32, …> (E0308), plus four errors in the test module (:673 missing host field, :675 env type, :678 tuple rc type). Reproduced locally with cargo check -p winux-cmds --lib --tests --target x86_64-pc-windows-gnu; the fix is mechanical (rc as u32, test helper to Ctx::new/MapEnv, rc as i32 in the tuple) — verified with a temporary patch, then reverted, so the tree is clean for you.

R2 — i18n drift (procedural blocker). Three new zh-CN extra entries, each traced by FNV-1a hash to strings this PR moved from C++ to Rust (printing all duplicated lines…, --group is mutually exclusive…, error reading '-': Bad file descriptor). Run check_i18n_drift.py --update-baseline inside the PR and commit the regenerated baseline.

R3 — same-file input/output semantics regress. GNU 9.4 and the old C++ both open (truncate) the output first and stream, so uniq f f leaves an empty file; this PR reads the whole input first and then writes, emitting deduplicated content. Restore streaming — that also removes the full-input buffering (see C3).

Captain rulings on the inherited faces (not blockers for this PR):

  • C1 (+NUM after -- is swallowed as skip-chars; GNU treats it as a filename error): inherited from the old C++ — filed separately, not this PR's debt.
  • C2 (two conflict errors lack the Try 'uniq --help' line): inherited from the old cp::report_error, but these are exactly the strings being moved for R2 — add the Try line in this rework while you're in there.
  • C3 (full-input buffering vs the old streaming): same root as R3; R3's fix resolves it.

Verified correct by spot-check against a real GNU 9.4 (not the cloud box — see below): \n as field separator, -N accumulation, +N overriding -s, -f overriding -N, --group= empty-value error verbatim, group-exclusivity reported first when three options collide, and the bridge wiring (CMake insertion order, lib.rs registration, REGISTER_COMMAND metadata, -NUM/--group) all line up.

Note on the oracle: the cloud box's /usr/bin/cat|ls|touch|sort|head are uutils coreutils 0.8.0 symlinks (only cp is GNU). Do not use them as the GNU reference for this port — the review used a real GNU 9.4. The nightly harvest's WinuxCmd baseline is being re-pointed to a real GNU coreutils build on the same box.

@caomengxuan666

Copy link
Copy Markdown
Member Author

CAPTAIN RE-REVIEW (eadfed52) — still needs rework. R1 is done; R2/R3/C2 are untouched.

  • R1 compile — fixed. rust-tests pass, build-windows arm64 + x64 full pass, baseline/compare/oracle pass. (x64 default build was still pending at read time, ~40 min in, not failed.)
  • R2 i18n — not fixed. i18n-drift is still red with the same 3 hashes; the baseline was not regenerated. Run check_i18n_drift.py --update-baseline in the PR and commit the result.
  • R3 same-file semantics — not fixed. run_uniq still reads the whole input (:240/:244) before opening the output (:248); uniq f f still emits deduplicated content instead of an empty file. The full-input buffering (C3) is the same root and is also still there.
  • C2 Try line — not fixed. Both conflict errors (:609 group exclusivity, :615 -c -D conflict) are still bare writeln! with no Try 'uniq --help' line. (The argmatch error on --group already carries its own Try line — that is not this item.)

No regression in the rework: the diff is local to uniq.rs (49+/42−), and the new -D5 handling (digits set check_chars, i.e. -D -w 5) matches GNU.

Note: local verification (cargo check + runtime probes) was blocked by a runtime execution-risk flag on the review tree, so R3/C2 above are code-reading conclusions, R1 rests on CI. The captain will re-run the local probes once the tree is cleared.

@caomengxuan666

Copy link
Copy Markdown
Member Author

CAPTAIN RE-REVIEW — runtime evidence (devin-windows, head eadfed52, GNU reference = pristine coreutils 9.4). R1 confirmed fixed locally; R3/C2 confirmed not fixed at runtime; one new rework item from this head.

  • R1 — fixed, locally confirmed. cargo check -p winux-cmds --lib --tests --target x86_64-pc-windows-gnu finishes clean; the E0308 and the four test-module errors are gone. The uniq lib tests pass 7/7.
  • R3 — not fixed (runtime). uniq f f with f = b\nb\na\n: winuxcmd rewrites f to the deduplicated content (4 bytes); GNU 9.4 leaves an empty file (0 bytes). Same root: the driver buffers the whole input — a 108 MB input peaks at ~181 MB working set (file operand) / ~206 MB (stdin) against a 4.5 MB small-input baseline, so C3 stands as well.
  • C2 — not fixed (runtime). --group -c and -c -D print the same message text as GNU but both still lack the Try 'uniq --help' … line (rc=1 both sides).
  • R4 — NEW, introduced by this head: -D5 semantics are inverted. GNU treats -D5 as -D -5 (the obsolete skip-fields form): on an all-aaaaa input it prints all 3 lines, on a fielded input 0 lines. This head treats the cluster digits as check_chars (-D -w 5) and prints 2 lines on both discriminating inputs — the opposite reading in both cases. (The previous review round's probe input was non-discriminating between the two readings; the discriminating probes here overturn that earlier "matches GNU" note.) Fix: cluster digits after -D follow the same obsolete -NUM skip-fields path as elsewhere.

Regression face otherwise holds: -1, +1, -f 1, --group= empty-value argmatch error, explicit -D -5 and -D -w 5 all match GNU.

caomengxuan666 and others added 19 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).
caomengxuan666 and others added 7 commits November 29, 2026 19:35
… .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)
… 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]>
…help hint

Merge origin/main into rust2/port-uniq and bring the port to green.

Merge resolution
  CMakeLists.txt: main added `cat` to WINUXCMD_RUST2_COMMANDS (#1882)
  while this branch added `uniq`; the merged list is main's plus `uniq`
  in alphabetical position. No other conflicts.

i18n drift ratchet
  The port retires three C++ `std::unexpected(...)` literals from
  src/commands/uniq.cpp, which the extractor keys as `legacy.<fnv16>`.
  The zh-CN catalog still carries the translations of exactly those
  three strings, so they become orphaned catalog entries and the drift
  gate reports them as new `extra` drift:
    legacy.a0cbddde67919c3c  --group is mutually exclusive with -c/-d/-D/-u
    legacy.2e4c769ef70e0ea1  printing all duplicated lines and repeat counts is meaningless
    legacy.fcaaa04efd6c264e  error reading '-': Bad file descriptor
  Recorded per the sanctioned ratchet action with
  `scripts/check_i18n_drift.py --update-baseline`; the resulting baseline
  diff is additive only (3 keys + timestamp), no existing entry removed.

GNU oracle fix (uniq.c 9.4)
  Both post-parse conflicts are reported through GNU's usage(), so each
  diagnostic is followed by the try-help line. The port printed only the
  first line. Verified on coreutils 9.4:

    $ uniq --group -c
    uniq: --group is mutually exclusive with -c/-d/-D/-u
    Try 'uniq --help' for more information.
    $ uniq -c -D
    uniq: printing all duplicated lines and repeat counts is meaningless
    Try 'uniq --help' for more information.

  Both now route through usage_error(), which appends the catalogued
  try-help line. Wording is unchanged; the existing test asserted only
  `!err.is_empty()` and now pins the exact two-line stderr.

  rustfmt applied to uniq.rs (file-local, not repo-wide).

Verification
  cargo build -p winuxcmd-driver                     ok
  cargo test -p winux-cmds                            1114 passed, 0 failed
  cargo gate uniq                                     25/25 GNU strict+exit, 2/2 win, 0 fail
                                                      (oracle: uniq (GNU coreutils) 9.4, Ubuntu 24.04.4)
  check_i18n_drift.py                                 OK (204 recorded, none new)

Scope
  Issue #1878 (uniq `-- +NUM`) is tracked separately and is NOT touched
  here.
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