Skip to content

refactor(xtask): write the check receipt with serde_json - #11

Merged
erthoaers merged 2 commits into
mainfrom
feat/receipt-serde-json
Nov 14, 2026
Merged

erthoaers merged 2 commits into
mainfrom
feat/receipt-serde-json

Conversation

@erthoaers

Copy link
Copy Markdown
Contributor

Writes the check receipt with serde_json instead 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 a serde_json::Value and printed pretty with a final newline; field order is kept by the preserve_order feature. renders_every_field keeps its expected text unchanged. The only differences in the written text are three escapes: U+0008 and U+000C are written as \b and \f, and U+007F is no longer escaped; the strings read back are the same.
  • A round-trip test writes a receipt whose strings hold JSON specials, control characters, leading and trailing blanks and non-ASCII text, reads it back with serde_json and compares the values, including null for an unknown working-tree state.
  • A new test checks that every step records each fact key once, since a JSON object keeps one member per key; the commits step's tests check the same on both ways of finding the base.
  • xtask/Cargo.toml: serde_json =1.0.154 without default features and with preserve_order; Cargo.lock gains six packages (serde_json, indexmap, equivalent, itoa 1.0.18, memchr, zmij).

cargo xtask check passes locally, and each commit passes on its own.

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.
@erthoaers
erthoaers merged commit 1cf95eb into main Nov 14, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant