Repository navigation
docs(audit): fast-path differential catalogue and harness (niubash#383) - #706
Conversation
Map every rubash in-process fast path against its WinuxCmd fallback and GNU coreutils at the byte level, with a repeatable Python harness. Inventory: 12 pipeline-stage arms (pipeline_exec.rs), 8 command-substitution filter arms (command_substitution_values.rs), the documented sleep/dirname/ basename/uname/arch behaviours, and in-process env. Confirmed rubash fast-path divergences, filed as #707 (tr [:cntrl:]), #708 (head flag parsing), #709 (dirname/basename // and empty operand), #710 (command_substitution_values.rs arms unreachable); WinuxCmd#1196 (true, dirname ///). The wc carrier class is already tracked (niubash#383 / PR #695); the dirname /a/b -> A: translation is niubash#346 (fixed by rubash#649). Harness: scripts/fast-path-differential.py (180 cases, FAST vs absolute WinuxCmd vs GNU; exits non-zero on regression or a known case going green).
c2a7c24 to
b76288d
Compare
|
Re: making the arm set registered rather than restated. Reading
The 20 inline arms are the one route family with no registry row and no guard, which this PR's own inventory documents ("undocumented and outside the doc-sync guard"). The arm table lives in prose in the catalogue while the real list lives in two source files, so an arm can land without a catalogue row. Three asks, cheapest first: 1. Derive the arm set instead of restating it. A test that unions the arms from 2. Give the harness a third verdict. It already fails on 3. Record reachability next to the arm. #710 shows the 8 substitution-filter arms are unreachable on One more: the Filed the context dimension separately as #713 — no overlap with this catalogue (this is the route axis, that is the context axis). I've also commented there narrowing it after reading §1 of the taxonomy doc. |
|
Case
So the case's verdict flips with the console locale, which means it will intermittently report a false regression or a false "fixed". Suggest pinning a locale for the EXT/GNU invocation of this case (or splitting it into |
caomengxuan666
left a comment
There was a problem hiding this comment.
Adversarial review of the audit artefacts (I ran the harness and the catalogue against the installed toolchain; nothing here edited the PR's files). Verdict up front: the science is real, and the harness can fail — merge after three small fixes.
Verified (what I ran)
- Full run reproduces the claimed result exactly.
python scripts/fast-path-differential.pyon niu 1.4.0/e785c3c8, WinuxCmd 1.1.12, D:/Git coreutils:cases=180 pass=146 known=28 extbugs=2 regressions=0 fixed=0, exit 0. Scratch files (fpd-large-*,fpd-plain.txt,fpd-esc.txt) are removed at both normal exit and--jsonexit. - Catalogue↔harness consistency is exact. Appendix A has 180 rows,
--listemits 180 unique ids, and the two sets are identical; every row's recorded result (146 PASS / 28 KNOWN / 2 EXTBUG / 4 INFO) matches a live run row-for-row — no missing or phantom case. - Inventory claims check out in source.
execute_pipeline_stage_inneratpipeline_exec.rs:2567,match nameat:2807with the 12 arms;grep:3100,sed:3089,cat:2898,trap:2840,printf:2823,head:2865;wcat:3154(as_bytes:3166,split_whitespace:3168, default:3181-3185);translate_tr:3413(walkschars()),inline_expand_tr_set:3435;head_line_count:3383with the caller'sunwrap_or(10). Substitution filter fn atcommand_substitution_values.rs:5with 8 arms +_fallback; the reachability chain (trivialgatecommand_substitution.rs:792/:2217rejects|) is genuine — the dead-arm finding is sound. Carrier encoding (substitution_metadata.rsE000+E0xx pairs) matches §3.1. - Byte-for-byte re-run of 21 divergence rows (independent script, raw child bytes, foreign to the harness plumbing):
wc -c/-w/defaulton CTRL/FF,wc -cwithecho/printfproducers,sub wc -c ctrl,head -n -1/-n abc,sub head -n -1,tr [:cntrl:]/[:space:]/mixed,dirname /a/b/c // /// '',basename '' //,uname -s— every FAST/EXT/GNU triple matches the doc's table, including both EXTBUGs (true -xrc 1,dirname ///→//) and the sharedbasename //non-divergence. I also reproduced §4's uncased claimhead -n +2(FAST=EXT=GNU). - Selectors work.
--listexit 0;--only(substring semantics) still computes and propagates the exit code (demonstrations below use--only);--jsonis semantically stable across two full runs (statuses and all captured bytes identical).
Demonstrations (exact commands and output)
Real-regression detection — a copy of the script with the FAST leg corrupted for the inline sed arm (simulating the product breaking -e support), run unmodified-comparator:
$ python copy_regress.py --only sed_e
[DIVERGE] sed_e
FAST out=b'Omega\nbetA\ngAmma\n' rc=0
EXT out=b'Alpha\nbetA\ngAmma\n' rc=0
GNU out=b'Alpha\nbetA\ngAmma\n' rc=0
cases=2 pass=1 known=0 extbugs=0 regressions=1 fixed=0
REGRESSIONS: sed_e
(exit 1)
Silent-fix detection — how it works in code: match = stdout== && rc== (plus stderr for the 5 stderr= cases); if case["known"] and match → status FIXED? and appended to quietly_fixed; else status KNOWN; plain DIVERGE → regressions. Exit 1 iff regressions or quietly_fixed.
Demo 1, a known divergence starts matching (copy simulating head -n abc now erroring like its fallback):
$ python copy_fixed.py --only head_badnum
[FIXED? ] head_badnum flag parsing: accepted, rc 0 vs error rc 1
[FIXED? ] sub_head_badnum flag parsing
cases=2 pass=0 known=0 extbugs=0 regressions=0 fixed=2
KNOWN CASES NOW MATCHING (update expectations): head_badnum, sub_head_badnum
(exit 1) — substring --only also caught sub_head_badnum
Demo 2, expectation updated to demand a match while the bug still exists (same copy with known flag removed from head_negn1):
$ python copy_expect.py --only head_negn1
[DIVERGE] head_negn1 GNU -n -1 = all but last line (expectation now demands a match)
cases=2 pass=0 known=1 extbugs=0 regressions=1 fixed=0
REGRESSIONS: head_negn1
(exit 1)
Blocking
B1 — Concurrent runs silently false-PASS. The two file-fixture cases use fixed paths (fpd-plain.txt, fpd-esc.txt) and each run deletes them at exit. Two harness instances sharing the same temp root step on each other, and the failure mode is the worst possible one: all three legs agree on the error, so the case stays green. Reproduced deliberately (full run in background, foreground run cleaning up mid-flight): cat_file/cat_file_ctrl/cat_file_n all recorded PASS with empty stdout and cat: ...fc\pd-plain.txt: No such file or directory on stderr. Sequential runs are clean — this only bites two operators/CI jobs at once — but "idempotent, safe to re-run" (§7) is not true concurrently. Fix is small: mkstemp/per-PID fixture names (like fpd-large-*) and, belt-and-braces, assert the fixture-backed cases' stderr is empty so a fixturing failure can never masquerade as agreement.
B2 — The stated comparison contract is stronger than the code. §1 (line 30) and the PR body say "stdout, stderr and exit status are compared as raw bytes", but stderr is compared only for the five stderr=True cases (script lines 732–734; the script's own docstring correctly says stdout + exit status). Demonstrated: simulated stderr-only chatter on the FAST leg of printf … | wc -l → cases=5 pass=5, regressions=0, exit 0 — undetected. For a differential inventory, a fast path that starts shouting on stderr while stdout stays identical would pass. Either compare stderr everywhere (noisy on fallback diagnostics that legitimately differ, e.g. dirname: invalid option vs unknown option) or fix the §1/PR-body wording to "stdout and exit status; stderr for the cases that print diagnostics".
Non-blocking
N1 — Missing toolchains degrade badly. NIU pointing at a nonexistent file → raw FileNotFoundError traceback (no message). WX_BIN missing → ext_cmd silently returns None, the reference quietly becomes GNU, and e.g. wc_m (FAST 13 vs GNU 23) is reported as a rubash DIVERGE that is really "winuxcmd not found" (the EXT line even prints GNU's output). A startup sanity check with one clear fatal message per missing tool would fix both.
N2 — --only that matches nothing runs cases=0 ... and exits 0; a warning (or nonzero) would prevent a mistaken green.
N3 — No finally around fixture cleanup: an exception mid-run leaks the scratch files (they're overlay-created next run, so cosmetic after B1's naming fix).
N4 — Machine-specific defaults (C:\\Users\\cmx\\…, D:\\Git) are committed; the env overrides exist but aren't mentioned in §7 — one sentence in the doc (plus deriving the default from NIU_SHELL/WINUXCMD_HOME) would make the script portable-by-intent.
Nits
dirname_letteris a straight duplicate ofdirname_simple(disclosed in its note) — it inflates the pass count by 1.grep_utf8_iis labelled "unicode case fold" but all three legs return rc 1 — nothing in the matrix actually case-folds the accented pattern, so the note reads as a pass-verified fold it isn't.- When there is no EXT counterpart, the
DIVERGE/FIXED?block prints the GNU values twice (once as the "reference", once as GNU).
The catalogue's science is reproducible end to end (including the unreachable-arms finding and both EXTBUG rows). Fix B1/B2 (a few lines + two sentences) and this is ready.
…706 review) B1: fixtures now live in a per-PID scratch dir created with mkdtemp, cleaned in a finally, with an integrity gate and a stderr-empty guard on the fixture-backed cat cases so a fixturing error can never be recorded as FAST/EXT agreement. B2: the comparison contract now reads stdout + exit status, with stderr compared only for the four diagnostic cases (stderr=True) and asserted empty for the fixture cases; Appendix A gains a stderr column. grep_utf8_i pins LC_ALL=C/LANG=C for all three legs, removing the console-locale nondeterminism (under C none of the installed legs fold). Cheap fixes: missing NIU/WX_BIN is a fatal exit-2 diagnostic (--no-ext opts out explicitly and is recorded in the run header); --only with no match exits 1; the duplicate dirname_letter case is removed. Totals re-synced: cases=179 pass=146 known=27 extbugs=2 info=4 regressions=0 fixed=0.
ed40910 to
b666d5e
Compare
…706 review) B1: fixtures now live in a per-PID scratch dir created with mkdtemp, cleaned in a finally, with an integrity gate and a stderr-empty guard on the fixture-backed cat cases so a fixturing error can never be recorded as FAST/EXT agreement. B2: the comparison contract now reads stdout + exit status, with stderr compared only for the four diagnostic cases (stderr=True) and asserted empty for the fixture cases; Appendix A gains a stderr column. grep_utf8_i pins LC_ALL=C/LANG=C for all three legs, removing the console-locale nondeterminism (under C none of the installed legs fold). Cheap fixes: missing NIU/WX_BIN is a fatal exit-2 diagnostic (--no-ext opts out explicitly and is recorded in the run header); --only with no match exits 1; the duplicate dirname_letter case is removed. Totals re-synced: cases=179 pass=146 known=27 extbugs=2 info=4 regressions=0 fixed=0.
…706 review) B1: fixtures now live in a per-PID scratch dir created with mkdtemp, cleaned in a finally, with an integrity gate and a stderr-empty guard on the fixture-backed cat cases so a fixturing error can never be recorded as FAST/EXT agreement. B2: the comparison contract now reads stdout + exit status, with stderr compared only for the four diagnostic cases (stderr=True) and asserted empty for the fixture cases; Appendix A gains a stderr column. grep_utf8_i pins LC_ALL=C/LANG=C for all three legs, removing the console-locale nondeterminism (under C none of the installed legs fold). Cheap fixes: missing NIU/WX_BIN is a fatal exit-2 diagnostic (--no-ext opts out explicitly and is recorded in the run header); --only with no match exits 1; the duplicate dirname_letter case is removed. Totals re-synced: cases=179 pass=146 known=27 extbugs=2 info=4 regressions=0 fixed=0.
b666d5e to
4f57579
Compare
|
Thanks for the adversarial pass — all four named items are in B1 — concurrent fixtures (blocking)Fixtures now live in a per-process scratch directory created with Two full instances run concurrently (two Before this change two instances sharing the temp root deleted each other's B2 — stderr contract (blocking)Fixed by wording, not by widening coverage (conservative): the docstring, §1 and grep_utf8_i determinism (nit + real observation)Pinned
So under Cheap list
New totals: (180→179 and 28→27 are the duplicate removal; Deliberately not changed
|
…ith doc-sync guards PR #706's differential audit (docs/audit/fast-path-differential.md, included here so the links resolve) inventoried three layers of in-process fast paths, but docs/builtins.md recorded only the hidden-builtin one (sleep/dirname/ basename + uname/arch). The other two were invisible to the doc-sync test: - 12 pipeline-stage arms (execute_pipeline_stage_inner, pipeline_exec.rs `match name`): true, :, false, echo, printf, trap, head, cat, sed, grep, wc, tr — the stage runs in-process on the pipe until the arm declines a shape (head -c, regex metacharacters in grep, '-'-words in tr, ...), then falls back to the external winuxcmd binary. - 8 command-substitution filter arms (command_substitution_pipeline_filter, command_substitution_values.rs): sort, sed, tr, head, grep, wc, tail, uniq (+ generic-external fallback). Audit §2.5 additionally shows these are unreachable for ordinary $( … | … ) bodies after rubash#117's triviality gate, so the table describes code shape, not observable behaviour. docs/builtins.md gains §3.1 with both lists inside two new machine blocks (pipeline-fastpath-list, substitution-fastpath-list) in the same fenced grammar the doc-sync test parses, plus one honest sentence per group and a link to the audit's divergence catalogue (§3) and tracking table (§8). The doc-sync test in builtin_names.rs gets two new cases pinning each list against a frozen expected set (the arms are inline match branches, so the expected set cannot be derived from a table); adding, removing or renaming an arm without updating the doc now fails `cargo test --lib builtin_names`. cargo test --lib builtin_names: 8 passed, 0 failed.
…t-path arms, guarded (#722) * docs(builtins): fast-path arms in pipelines and $(…) substitutions, with doc-sync guards PR #706's differential audit (docs/audit/fast-path-differential.md, included here so the links resolve) inventoried three layers of in-process fast paths, but docs/builtins.md recorded only the hidden-builtin one (sleep/dirname/ basename + uname/arch). The other two were invisible to the doc-sync test: - 12 pipeline-stage arms (execute_pipeline_stage_inner, pipeline_exec.rs `match name`): true, :, false, echo, printf, trap, head, cat, sed, grep, wc, tr — the stage runs in-process on the pipe until the arm declines a shape (head -c, regex metacharacters in grep, '-'-words in tr, ...), then falls back to the external winuxcmd binary. - 8 command-substitution filter arms (command_substitution_pipeline_filter, command_substitution_values.rs): sort, sed, tr, head, grep, wc, tail, uniq (+ generic-external fallback). Audit §2.5 additionally shows these are unreachable for ordinary $( … | … ) bodies after rubash#117's triviality gate, so the table describes code shape, not observable behaviour. docs/builtins.md gains §3.1 with both lists inside two new machine blocks (pipeline-fastpath-list, substitution-fastpath-list) in the same fenced grammar the doc-sync test parses, plus one honest sentence per group and a link to the audit's divergence catalogue (§3) and tracking table (§8). The doc-sync test in builtin_names.rs gets two new cases pinning each list against a frozen expected set (the arms are inline match branches, so the expected set cannot be derived from a table); adding, removing or renaming an arm without updating the doc now fails `cargo test --lib builtin_names`. cargo test --lib builtin_names: 8 passed, 0 failed. * docs: repoint gap-ledger authority to tracker + git history instead of dangling TASK-BOARD path (#716) --------- Co-authored-by: cmx <[email protected]>
What
Audit-only. Maps every rubash in-process fast path against its WinuxCmd
fallback and GNU coreutils at the byte level, adds a repeatable differential
harness, and records the results. No engine code is changed.
docs/audit/fast-path-differential.md— inventory, reachability, theconfirmed divergence table (with byte evidence, classification and code
locations), the clean-shape list, systemic classes, and a full 179-case
appendix.
scripts/fast-path-differential.py— the matrix runner.Inventory (from the code)
pipeline_exec.rs:true/:/false/echo/printf/trap/head/cat/sed/grep/wc/tr.command_substitution_values.rs:sort/sed/tr/head/grep/wc/tail/uniq.sleep/dirname/basename/uname/archandin-process
env.docs/builtins.mdonly listssleep/dirname/basename(+uname/archinthe rubash copy); the 20 inline arms are undocumented and outside the doc-sync
guard. The substitution filter arms are additionally unreachable for ordinary
$( … | … )bodies afterrubash#117's triviality gate — the observable$()behaviour comes from the pipeline arms via the real executor.
Confirmed divergences (not already tracked)
printf 'a\033b\nc\n' | tr '[:cntrl:]' Xa\x1bbXcXaXbXcXprintf 'a\nb\nc\n' | head -n abca\nb\nc\nrc 0printf 'a\nb\nc\n' | head -n -1a\nbdirname /////basename ''/Already tracked (not re-filed): the
wccarrier class — niubash#383 / #695;dirname /a/b → A:— niubash#346, fixed by #649 + niubash#371.Harness
Runs against the installed
niu, the absolute WinuxCmd binaries, andGit-for-Windows GNU coreutils. stdout and exit status are compared byte for
byte; stderr is compared only for the four diagnostic cases
(
sleep_missing,sleep_invalid,sleep_badunit,basename_extra) andasserted empty for the fixture-backed
catcases (Appendix A tags both). APython script (not a Rust
#[test]) is used because the matrix must spawn threeexternal toolchains and diff raw child bytes.
Fixes applied after the adversarial review:
mkdtemp), removed in afinally; an integrity gate plus a stderr-empty guard so a missing fixturecan never be recorded as FAST/EXT agreement.
NIU/WX_BINis a fatal exit-2 diagnostic;--no-extopts out explicitly and the run header recordsEXT=DISABLED (--no-ext). Toolchains are overridable viaNIU/WX_BIN/GNU_BASH/GNU_PATH/AUDIT_TMP.--onlywith no match exits 1 with a message.grep_utf8_ilocale pin (LC_ALL=C/LANG=Cfor all legs) so theconsole locale cannot flip the verdict.
dirname_lettercase removed.Observed on the installed toolchain (niu 1.4.0 / e785c3c, WinuxCmd 1.1.12):
EXTBUG= the fast path is right and only the WinuxCmd fallback is wrong(
true -xrc 1,dirname ///→//).