Repository navigation
feat(comm): add comm with -1/-2/-3 and --output-delimiter - #301
ferdingler wants to merge 4 commits into
Conversation
|
@strandly-the-agent Please review this PR |
strandly-the-agent
left a comment
There was a problem hiding this comment.
Approve. comm matches GNU comm 9.1 byte for byte (stdout, stderr, exit status). In 1,500 random differential cases and about 30 hand-written scripts I found no divergence. CI is green (rollup SUCCESS, CI Gate passed).
One 🟡, inline: two GNU behaviours the PR description calls out have no test. I removed both on purpose and all 7 comm_* tests still passed. The fix is to add two tests.
@ferdingler, as you asked. Fits #207 (P1 missing commands → comm).
What I checked
All at head c7663be.
- Differential fuzz against GNU 9.1 (
LC_ALL=C). 3 seeds × 500 cases, 0 mismatches. Each case had two random files of 0–8 lines, using the lines"",a,A,b,ab,a\x01,\xffandc\r. Files were sorted, unsorted or had duplicates, and some had no final newline. Options were a random mix of-1/-2/-3,--check-order,--nocheck-order,--output-delimiter=Xand--output-delimiter=, with-as one of the files. GNU warned and exited 1 in about 22% of cases, so the order-check paths were exercised. - Hand-written scripts. About 30, each run in both bash+GNU and
strands-shell -c. They covered every column combination, the end-of-file recheck, options placed after the files,--, missing operands and extra operands. - Tests.
cargo test --test shell_integrationpassed 1970/1970,cargo test --test differentialpassed, andcargo fmt --checkwas clean. Runningcomm_columns.shunder GNU 9.1 reproducescomm_columns.expectedexactly. - Mutation check. I changed
comm.rs:171to(check == CheckOrder::Default)and removed the NUL push at:98.cargo test --test shell_integration comm_still passed 7/7. - Speed. With
comm big bigon 100k lines (debug build), comm took about 0.55s, against about 0.72s forsort big. - Conventions and docs. Argument parsing, help, stdin and open errors follow the same pattern as
uniq.rsandcut.rs. The README now says 34 commands, which matchesmod.rs. The WASM/binlist invfs.rsincludescomm.
Questions (non-blocking)
README.md:256links to the command reference on strandsagents.com, and the PR's "Documentation PR" section is empty. Is a docs-site PR planned that addscommand notes that--totaland-zare missing?
Reading order: src/commands/comm.rs (step() at :67, then the main loop at :140–188), then tests/shell_integration.rs.
Appendix: non-blocking (2)
- ⚪
comm.rs:94-99: if--output-delimiteris given twice, the last value wins. GNU fails withmultiple output delimiters specifiedand exits 1. This is unlikely in practice. - ⚪
comm.rs:72-73:step()copies two lines on every step, even under--nocheck-order. This is cheap enough at 100k lines that it doesn't matter.
I didn't count comm - - (the help text says "not both"; GNU errors too) or the wording of missing-file and directory errors (it comes from the shared io::open, the same as uniq, cut and sort).
|
Thanks. The two tests are in (reply inline). Docs: the command reference lives in the docs site repo, so I'll add |
# Conflicts: # README.md # src/vfs.rs # tests/shell_integration.rs
|
@strandly-the-agent Please review this PR Merged origin/main into the branch (7f5269f) to clear conflicts in README.md (command count now 38), src/vfs.rs (WASM /bin list, comm kept in alphabetical order) and tests/shell_integration.rs (kept main's tests, comm section appended). No comm code changes. fmt, clippy and the full test suite pass locally, including the comm differential case. |
strandly-the-agent
left a comment
There was a problem hiding this comment.
Approve. The merge at 7f5269f resolves the conflicts cleanly, and the 🟡 from my last review is fixed. The red Rust (windows-latest) check doesn't come from this PR. It's a stack overflow in compound_pipe_into_function_redirected_from_cli, a test from #384 on main. Every recent PR's Windows Rust job fails the same way, and #411 (still open) fixes it.
@ferdingler, as you asked.
What I checked
- Previous finding: fixed. Commit
27866f4addscomm_unsorted_but_fully_paired_input_is_silentandcomm_empty_output_delimiter_is_nul. I made the same two changes as last time (dropped&& seen_unpairableatcomm.rs:171and the NUL push at:98), and both new tests failed, with 7/9 passing. Restoring the code brought it back to 9/9. - The merge.
git diff origin/main 7f5269ftouches only comm files and the registration points.comm.rsis unchanged since27866f4. The README now says 38 commands, which matches the 38 arms inlookup()inmod.rs. In the WASM/binlist invfs.rs,commis in alphabetical order. The same 9comm_*tests exist before and after the merge, and main's tests are kept (--remerge-diffshows only additions around them). - Tests on Linux (aarch64).
cargo test --workspace --all-targetspassed, including 2090/2090 inshell_integrationand the differential suite.cargo fmt --checkwas clean, andcargo clippyreports nothing in comm. The 4-D warningserrors are insrc/builtins/lua.rs, which this PR doesn't touch, and CI doesn't gate on clippy. - CI on
7f5269f. Everything is green except Windows Rust. Its only failure isthread 'main' has overflowed its stackin the #384 test above, the same as on #353, #355 and #407–#410.
Description
There's no
commin the shell, so comparing two sorted lists (which lines are only in the first, only in the second, or in both) fails with command not found.This adds
commwith its three columns and-1,-2and-3in any combination to hide them, plus--output-delimiter. Either file can be-for stdin. Unsorted input is handled the way GNU handles it. By default it warns once per file, but only after it has seen a line that doesn't pair up, then keeps going and exits 1.--check-orderstops at the first out-of-order line, and--nocheck-orderturns the check off. Lines are compared byte by byte, like GNU in the C locale. I left out--totaland-z.I compared about 35 invocations against GNU comm 8.32 on this machine, covering every column combination, delimiters (including an empty one, which GNU turns into a NUL byte), empty files, stdin, unterminated lines, unsorted input in each file under all three check modes, and operand errors. Stdout, the warnings and the exit status all match. I added a recorded differential case and integration tests that check the warnings exactly. The full Rust suite passes. I didn't run the Python or Node suites since the bindings are unchanged. This touches the same command lists as the other new-command PRs for #207, so whichever lands second will need a small rebase.
Related Issues
Part of #207
Documentation PR
Type of Change
New feature
Testing
How have you tested the change? Verify that the changes do not break functionality or introduce new warnings.
cargo test --workspace --all-targets,pytest tests/python,npm test)cargo fmtandcargo clippyChecklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.