horizon-prepare: OUTPUT_VERSION, the number of what it prepares, checked by CI

Launchers copy a player's prepared resources to a new release while its preparer declares the
same OUTPUT_VERSION (the launcher side is its own pull request). The number is bumped by hand;
CI keeps it honest: the parity job already prepares with every change to the preparer, and
tools/prepare_output.py check now fails when that preparation's digest is not the one
crates/horizon-prepare/output-versions.txt gives the current number, or when the file changed
other than by appending a version. The digest canonicalises what differs between two runs of
the same preparer (JSON key order, creative tab tag order, lambda class addresses, logs, the
sounds): 10 preparations by 5 preparer versions on the three Mac runners give one digest, and a Linux preparation by an older preparer gives the Mac runners' digest for it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Ludovic Marie
2026-10-25 22:48:43 +01:00
parent 74768d2eeb
commit 116a7f7dca
6 changed files with 283 additions and 0 deletions
@@ -0,0 +1,3 @@
# OUTPUT_VERSION (src/lib.rs) and the digest of what it prepares (python3 tools/prepare_output.py digest),
# one line per version, never edited: a change to the prepared files appends the next version.
1 0a608bf4115a8ed2e2c4f5f2b2609dc10c54e63479af8e56fabaa10af1060389
+32
View File
@@ -31,6 +31,15 @@ pub type Log<'a> = &'a dyn Fn(&str);
/// The manifest's `schema`: the prepared files' layout, which the launcher compares.
pub const SCHEMA: i64 = 7;
/// What this preparer makes. The launcher copies a prepared version's resources to a newly installed
/// version whose preparer has the same number (and the same pinned jars), so a release that changes
/// this crate without changing its output asks nobody to prepare again. Bump it, and append the new
/// digest to output-versions.txt, when the prepared files change: CI prepares with every change to
/// the preparer and fails when the output is not the one output-versions.txt gives this number
/// (`python3 tools/prepare_output.py check`). The launcher reads this line from the version
/// folder's sources: keep it on one line, as it is.
pub const OUTPUT_VERSION: u32 = 1;
/// Digest of this crate's sources (build.rs): the launcher prepares a version in-process when
/// that version ships these same sources, and runs the version's own binary otherwise.
pub const SOURCES_SHA256: &str = env!("HORIZON_PREPARE_SOURCES_SHA256");
@@ -1209,6 +1218,29 @@ mod tests {
fs::remove_dir_all(dir).unwrap();
}
#[test]
fn output_versions_end_at_the_output_version() {
let text = include_str!("../output-versions.txt");
let versions: Vec<(u32, &str)> = text
.lines()
.filter(|l| !l.trim().is_empty() && !l.starts_with('#'))
.map(|l| {
let (n, digest) = l.split_once(' ').unwrap();
(n.parse().unwrap(), digest.trim())
})
.collect();
let numbers: Vec<u32> = versions.iter().map(|v| v.0).collect();
assert_eq!(numbers, (1..=OUTPUT_VERSION).collect::<Vec<_>>());
for (i, (_, digest)) in versions.iter().enumerate() {
assert_eq!(digest.len(), 64);
assert!(!versions[..i].iter().any(|(_, d)| d == digest));
}
// The launcher finds the number with this line in a version folder's sources.
let lib = include_str!("lib.rs");
let line = format!("pub const OUTPUT_VERSION: u32 = {OUTPUT_VERSION};");
assert!(lib.lines().any(|l| l == line));
}
#[test]
fn the_source_digest_is_the_one_build_rs_computed() {
assert_eq!(