Write the cache manifest in a deterministic order !14

merged merged by cmc on 2026-10-18 20:47 UTC · krz/orgo:reproducible-cache-manifest into main

Discussion

cmc

<out>/.orgo-cache.json was the one file in the output tree that was not byte-reproducible: Manifest.pages and both DepGraph edge maps were HashMap/HashSet, so serde wrote their entries in map iteration order and two builds of the same input with the same binary disagreed on ordering.

BTreeMap/BTreeSet throughout, plus Ord on TargetId. No schema change — same field names, same JSON types, object keys and array elements merely ordered — and CACHE_FORMAT_VERSION stays at 7. Checked against a manifest written by 0.24.1: the new binary loads it and reports 0 rendered, 2 cached.

New test cache_manifest_is_byte_identical_across_builds builds a 24-page cross-linked site four times with --no-cache and compares manifest bytes. It fails before this change. No existing test asserted on manifest contents; the byte-equivalence helper in tests/incremental.rs skips .orgo-cache.json, which is why this went unnoticed.

This makes the whole output tree reproducible. Three --no-cache builds of docs/ into separate directories are now identical under diff -r, manifest included, and an incremental rebuild over a populated cache produces the same 20 files byte for byte. Nothing else in the tree varies: the other hash inputs (config, templates, site structure, resolved links) were already sorted before hashing, and Config contains no unordered maps.