Repository navigation
refactor(xtask): write the check receipt with serde_json - #11
Merged
Merged
Conversation
Build the receipt of `cargo xtask check` as a serde_json value and write it in serde_json's pretty form. The `preserve_order` feature keeps the fields in the order in which they are written, so the fields, their order, the format version and the values are as before: the expected text of `renders_every_field` is unchanged and the output matches it byte for byte. A duration is converted to a u64 count of milliseconds, capped at u64::MAX, a limit no run comes near. serde_json escapes strings itself, so the hand-written quoting and its test are removed. It writes U+0008 and U+000C as `\b` and `\f` rather than `\u0008` and `\u000c`, and leaves U+007F unescaped. This changes only how those characters are spelled in the text; a JSON reader gets the same strings back. A new test writes a receipt whose strings hold JSON specials and control characters and reads it back with serde_json. serde_json is pinned to 1.0.154 without its default features, as in krepi's tool workspace, and itoa is locked at 1.0.18, so the packages under serde_json in the lock file are the same as in krepi's.
The receipt writes the facts of a step as the members of one JSON object, and serde_json's map keeps one member per key, so a key that a step recorded twice would lose its earlier value. Run each step of the check, with its Cargo commands replaced by commands that exit at once, and require the keys of its facts to be distinct. The commits step finds its base from `CHECK_BASE` or from the merge base, and the environment decides which way the run above takes. The tests of the commits step require distinct keys too, so both ways are checked, whether they succeed or fail, in a scratch repository.
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.
Writes the check receipt with
serde_jsoninstead of a hand-written JSON writer. The receipt keeps its format number, its fields, their order and their values.xtask/src/receipt.rs: the receipt is built as aserde_json::Valueand printed pretty with a final newline; field order is kept by thepreserve_orderfeature.renders_every_fieldkeeps its expected text unchanged. The only differences in the written text are three escapes: U+0008 and U+000C are written as\band\f, and U+007F is no longer escaped; the strings read back are the same.serde_jsonand compares the values, includingnullfor an unknown working-tree state.xtask/Cargo.toml:serde_json =1.0.154without default features and withpreserve_order;Cargo.lockgains six packages (serde_json,indexmap,equivalent,itoa1.0.18,memchr,zmij).cargo xtask checkpasses locally, and each commit passes on its own.