13 KiB
13 KiB
Core Path Normalization, CLI Stdin Config, JSON Format Output, and CLI Test Hardening (Round 5A)
Goal
Deliver the Round 5A core path, CLI stdin config discovery, structured format JSON output, and CLI test hardening items (#1, #11, #55):
- Unified lexical path normalization (
#1): Extractlucisv_core::path::{normalize, normalize_under}incrates/lucisv_core/src/path.rs(re-exported viacrates/lucisv_core/src/lib.rs) and replace the duplicate private normalization copies incrates/lucisv_core/src/filelist.rs,crates/lucisv_core/src/config.rs,crates/lucisv_server/src/includes.rs, andcrates/lucisv/src/main.rswhile preserving exact caller semantics across Unix and Windows prefixes/roots. - CLI stdin config discovery &
#55: Ensure CLI stdin mode (-/--stdin-filename <path>) discovers and applieslucisv.toml/.lucisv.tomlconsistently in bothformatandcheck(including[lint] selectand[lint] ignoreprecedence inrun_check_stdin, rejecting empty--stdin-filename ""), and strengthena_stdin_buffer_reads_the_rule_options_tooincrates/lucisv/tests/cli.rsto assert explicit exit codes alongside stdout. - Structured
--output-format jsonfor CLI format mode (#11): Extend--output-format <text|json>to format mode (lucisv/lucisv --check/lucisv format), emitting a single-line JSON report with top-levelstatus,exit_code,summary, and per-filefilesentries (filename,status,cached,error: {category, line, column, message} | null) while preserving existing text output and frozen0/1/2exit codes. Wiretools/corpus_check.shandscripts/score.shcleanly to consume--output-format jsonwhenjqis present (with text fallback), preserving identical TSVs and814/6corpus output.
Assumptions
- Lexical normalization must never call
std::fs::canonicalizeso symlinks stay unfollowed and non-existent paths (--stdin-filename, rename targets) normalize identically to existing ones. - Leading/excess
..components on relative paths (and unrooted Windows drive-relative paths likeC:a\..\..) are preserved, while..after a root directory (/orC:\or\\server\share\) clamps at the root. - In format mode,
--output-format jsonconflicts with--diff,--stdout, and stdin without--check(exiting2), matching--diffvs--stdoutmutual exclusion so stdout is strictly one valid JSON document whenever JSON output is requested.
Handshakes
crates/lucisv_core/src/path.rs↔crates/lucisv_core/src/{filelist.rs,config.rs},crates/lucisv_server/src/includes.rs,crates/lucisv/src/main.rs:includes::normalizere-exportslucisv_core::path::normalizesocrates/lucisv_server/src/file_ops.rscontinues usingcrate::includes::normalizewithout cross-lane edits.filelist::Reader,config::Discovery, andlucisv::identitycalllucisv_core::path::normalize_under.
crates/lucisv/src/{args.rs,main.rs,lint.rs}↔tools/corpus_check.sh,scripts/score.sh:- Format JSON schema:
{"status":"ok|would-reformat|reformatted|error","exit_code":0|1|2,"summary":{"changed":N,"unchanged":N,"cached":N,"errors":N},"files":[{"filename":...,"status":"unchanged|cached|would-reformat|reformatted|error","cached":bool,"error":null|{"category":"parse-error|lex-error|verification-error|io-error|selection-error|panic","line":u32|null,"column":u32|null,"message":...}}]}. - Frozen
0/1/2CLI exit codes, stderr error/summary formatting, andcorpus_check.sh/score.shTSV and stdout formats are preserved identically (814/6, byte-identical TSV rows).
- Format JSON schema:
crates/lucisv/tests/cli.rs:#55closed by explicit exit-code assertions (0under matching config,1without config) ina_stdin_buffer_reads_the_rule_options_too, plus regression tests for stdin config discovery (formatandcheck) and format--output-format json.
Status / TODO
- Implement
lucisv_core::path::{normalize, normalize_under}and replace duplicate copies infilelist.rs,config.rs,includes.rs, andmain.rs - Fix stdin
[lint] select/ignorediscovery and empty--stdin-filenamehandling; strengthen#55and add stdin format/check discovery tests - Implement format-mode
--output-format json(args.rs,main.rs, sharinglint::quote/lint::pick), wiretools/corpus_check.shandscripts/score.sh, and add CLI JSON tests - Enforce
<= 600non-blank non-comment prod lines beforemod tests,0.unwrap()/.expect()/panic!/unsafein library code, author stamps, and full verification gates
Work log
2026-11-26 — dev (Round 5A)
- Created
crates/lucisv_core/src/path.rs(normalize,normalize_under) and exportedpub mod pathincrates/lucisv_core/src/lib.rs, with Unix, Windows prefix/root/drive-relative, and platform-independent unit tests. - Replaced duplicate lexical normalization loops in
crates/lucisv_core/src/filelist.rs,crates/lucisv_core/src/config.rs,crates/lucisv_server/src/includes.rs(pub use lucisv_core::path::normalize), andcrates/lucisv/src/main.rs(normalize_under). - Fixed
crates/lucisv/src/main.rs::run_check_stdinto honor[lint] select/[lint] ignorevialint::pick, rejected empty--stdin-filename ""incrates/lucisv/src/args.rs(with.filter(|s| !s.is_empty())defense instdin_config), and strengtheneda_stdin_buffer_reads_the_rule_options_too(#55) plus new relative/../stdin config discovery tests incrates/lucisv/tests/cli.rs. - Added
--output-format jsonsupport to format mode (crates/lucisv/src/{args.rs,main.rs,lint.rs}), wiredtools/corpus_check.shandscripts/score.shto consume--output-format jsonwhenjqis present (preserving text fallback and byte-identical TSV /814/6output), and added comprehensive CLI JSON tests (unchanged,would-reformat,reformatted,cached,parse-error,lex-error,io-error, stdin--check, and flag conflicts). - Verified production line counts before
#[cfg(test)]/mod tests(path.rs39,lib.rs7,filelist.rs160,config.rs313,includes.rs342,args.rs444,main.rs550,lint.rs495) and0.unwrap()/.expect()/panic!/unsafein non-test production code.
2026-11-26 — dev (Round 5A QA fix)
- Fixed
tools/corpus_check.shexit-2 fallback whenuse_json=1(jqpresent) receives empty stdout (e.g. a pre-process_filegathererror such as a brokenlucisv.toml) or empty/unparseable JSON error detail: extracted sharedclassify_text_errorand re-ran"$lucisv" --check "$file" 2>&1whenevermsgis empty, aligning withscripts/score.sh. - Verified broken
lucisv.tomlrepro (exit 2, non-empty column-3 error message preserved) and corpus parity both withjqand withjqabsent fromPATH, plus./tools/gates.sh --only corpus(814/6),bash -n tools/corpus_check.sh scripts/score.sh, andpython3 tools/stamp_author.py --check.
QA log
2026-11-26 — QA (Round 5A)
Verdict: FAIL (one defect in tools/corpus_check.sh exit-2 fallback when use_json=1 and stdout is empty).
- Ownership & invariants (PASS):
git status --short/git diff --stat: only Lane 5A files touched (crates/lucisv_core/src/{lib.rs,path.rs,filelist.rs,config.rs},crates/lucisv_server/src/includes.rs,crates/lucisv/src/{args.rs,lint.rs,main.rs},crates/lucisv/tests/cli.rs,scripts/score.sh,tools/corpus_check.sh,docs/features/cli-path-r5/README.md).- Non-blank, non-comment production lines before
mod tests:path.rs38,lib.rs7,filelist.rs159,config.rs312,includes.rs341,args.rs443,lint.rs494,main.rs549 (all<= 600), with0.unwrap(),.expect(),panic!, orunsafein non-test production code.
- Adversarial requirement audit:
#1(lucisv_core::path— PASS): Verifiednormalizeandnormalize_underincrates/lucisv_core/src/path.rs(./..folding withoutcanonicalize, preserving leading/excess..on relative and Windows drive-relative paths likeC:a\..\..\b, clamping..at Unix/Windows/UNC roots,./a/..->.,""->""), and verified duplicate lexical loops were removed fromfilelist.rs,config.rs,includes.rs(re-exportinglucisv_core::path::normalize), andmain.rs(normalize_under).git grep "Component::" crates/confirmed no remaining duplicate normalization loops inlucisv_core,lucisv_server, orlucisv.- Stdin config &
#55(PASS): Verifiedrun_check_stdin,stdin_config,args.rs,lint::pick, andcrates/lucisv/tests/cli.rs(a_stdin_buffer_reads_the_rule_options_tooasserts explicit0/1exit codes;stdin_discovers_config_relative_to_stdin_filename_across_cwd_and_subcommandscovers relative/../discovery forformatandcheck,[lint] select/ignore, unknown config rule exit2, and empty--stdin-filename ""rejection). Adversarial binary probes confirmed CLI-over-config precedence (--select,--ignore,--no-config) in stdincheckmode. #11(--output-format json— FAIL ontools/corpus_check.shfallback):args.rs/main.rs/tests/cli.rs: single-line JSON schema (status,exit_code,summary,files) verified across clean (exit 0), dirty (--checkexit 1), in-place (reformatted,exit 0), cached (cached: true,exit 0),parse-error/lex-error/verification-error/io-error/selection-error/panic(exit 2), stdin--check, and conflict rejections (--diff,--stdout, non---checkstdin).scripts/score.sh&tools/corpus_check.shparity: on~/.cache/lucisv-corpus(820 files,814/6), both scripts produced byte-identical TSVs and outputs withjqvs text fallback (PATHwithoutjq).- Defect (
tools/corpus_check.sh:57-102): Whenuse_json=1(jqpresent) andlucisv --check --output-format json "$file" 2>/dev/nullexits2with empty stdout (for example, a pre-process_filegathererror such as a brokenlucisv.tomlin a directory),if [ "$use_json" -eq 1 ] && [ -n "$out" ];evaluates false and enters theelsebranch, grepping the empty$outinstead of re-running"$lucisv" --check "$file" 2>&1(unlikescripts/score.sh:184-193). Verified with a brokenlucisv.tomlprobe:scripts/score.shrecorded the full error message in column 4, whiletools/corpus_check.shemitted an empty column 3 (other-error\t<file>\t). Likewise, ifjqsucceeds with an emptymsgor fails (lines 86-92),corpus_check.shhardcodesoutcome=other-errorinstead of classifying the fallback text output uniformly.
- Executed checks (all in worktree):
python3 tools/stamp_author.py --check: PASS (would stamp 0 files; left 249 untouched)cargo fmt --all -- --check: PASSbash -n tools/corpus_check.sh scripts/score.sh: PASScargo clippy -p lucisv_core -p lucisv -p lucisv_server --all-targets -- -D warnings: PASScargo check --target x86_64-pc-windows-gnu --all-targets -p lucisv_core(withstable-aarch64-apple-darwinrustup toolchain): PASS./tools/guard.sh -m 8 -t 600 -- cargo test -p lucisv_core -p lucisv -p lucisv_server --all-targets: PASS (lucisvunit 35 passed,cli117 passed,style_cli5 passed;lucisv_core122 passed;lucisv_serverunit 2082 passed / 47 ignored,e2e106 passed / 3 ignored,grammar3 passed,ifdef_folding1 passed,opentitan_references0 passed / 2 ignored)./tools/gates.sh --only corpus,cross: PASS (corpus814/6,crossWindows + Linux musl check pass)
2026-11-26 — QA re-verification (Round 5A)
Verdict: PASS.
- Diff & ownership check: Confirmed
git diff --statchanged onlytools/corpus_check.sh(+5 lines vs prior audit) anddocs/features/cli-path-r5/README.md; all Rust files (crates/lucisv_core/src/**,crates/lucisv_server/src/includes.rs,crates/lucisv/src/**,crates/lucisv/tests/cli.rs) andscripts/score.share unchanged since the prior PASS checks. - Fix inspection (
tools/corpus_check.sh:40-108): Extractedclassify_text_errorand wiredif [ -z "$msg" ]; thento re-run"$lucisv" --check "$file" 2>&1whenuse_json=1and classify viaclassify_text_erroracross empty$out, invalid JSON, and emptymsg. - Repro & parity verification:
- Broken
lucisv.toml(exit 2, empty JSON stdout) with and withoutjqonPATH: both emitted identical TSV rows (other-error .../a.sv .../lucisv.toml:1: unknown key \bogus` ...),diff -u` clean. - Invalid-JSON fallback probe (
not-valid-jsonwithexit 2) with and withoutjqonPATH: both classified identically viaclassify_text_error(parse-error .../a.sv parse error: 9:1: synthetic fallback error),diff -uclean.
- Broken
- Re-executed gates:
bash -n tools/corpus_check.sh scripts/score.sh: PASSpython3 tools/stamp_author.py --check: PASS (would stamp 0 files; left 249 untouched)./tools/gates.sh --only corpus: PASS (814/6,corpuspass)
Review
Lead Self-Inspect (2026-11-26): APPROVED for trunk commit.
- Merged Lane 5A onto trunk after Round 5A QA PASS (including
tools/corpus_check.shclassify_text_errorfallback fix on exit 2 empty-stdout / bad-JSON cases). - Verified
#1(lucisv_core::path::{normalize,normalize_under}replacingfilelist,config,includes,main), stdin config +[lint] select/ignore+#55exit codes, and#11(--output-format json+ byte-identical814/6corpus TSV parity).