refactor: rewrite zc in Rust - #15
Merged
Merged
Conversation
The tool had outgrown shell: 3129 lines of bash, 24 jq filters and two large awk programs doing semver classification, API-path grouping, changelog rendering and a nested JSON schema that nothing enforced. Git, Cargo, rustdoc and cargo-public-api stay subprocesses, so ref, feature and worktree semantics are unchanged. Rust replaces the parsing, classification and rendering layer above them: - The --json document is now serde-derived, so it cannot drift from the human report. - Cargo metadata and rustdoc JSON are parsed with serde_json, keeping the previous contract that an unstable-format change yields zero rows rather than an error. - The grouping and changelog awk programs became pure functions, unit-tested in isolation for the first time. Behaviour, output text, exit codes and cache file names are unchanged. Output was diffed against the previous implementation across every mode.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Rewrites zc in Rust. Behaviour, output text, exit codes and cache file names are unchanged.
Why
The tool had outgrown shell: 3129 lines of bash, 24
jqfilters and two largeawkprograms doing semver classification, API-path grouping, changelog rendering, and a nested
--jsonschema that only a header comment enforced.What changed
Git, Cargo, rustdoc and cargo-public-api stay subprocesses, so ref resolution, feature
resolution and worktree semantics are untouched. Rust replaces the layer above them:
--jsondocument is serde-derived from the same values the human report uses, so thetwo cannot drift.
serde_json, keeping the previouscontract that an unstable-format change yields zero rows rather than an error. The
nightly/format compatibility strategy is unchanged:
ZC_TOOLCHAINplus the rustdoc-JSONcache fingerprint.
awkprograms are now pure functions, unit-tested inisolation for the first time.
jqand bash 4+ are no longer runtime requirements;cargo-public-apiand a nightlytoolchain still are. The composite action builds the binary with
cargo install --path.tests/run.shis kept as the behavioural contract and now runs against the built binary(
ZCstill overrides). Its 17 sourcedclassify_bumpcases moved intosrc/version_req/tests.rs, along with the wildcard and operator-swap cases.Verification
Ran locally before pushing, on the committed tree:
stderr, same exit codes, in all seven modes (default,
--with-values,--with-lock,--by-type,--flat,--json,--changelog) on a fixture covering added/removeditems, a new enum variant, trait impls, a new module, a
pub constvalue change, adoc-comment change, an MSRV bump and a major runtime dependency bump. Also identical on a
real crate's build-failure path.
tests/run.shwith a freshly built release binary: 118 passed, 0 failed.cargo fmt --all -- --check;cargo clippy --all-targets --all-features -- -D warnings;cargo check --locked --all-features --all-targets;cargo test --locked --all-features(30 tests);
cargo doc --no-deps --all-features --document-private-items;cargo +1.82 check --locked --all-features --all-targets(declared MSRV);cargo hack check --workspace --feature-powerset;cargo udepsclean.cargo deny checkwas not run to completion: the installed version rejects the advisorydatabase's CVSS 4.0 entries, which is unrelated to this change.