From c1bf987314774d135316d95480baeb6eb7e1dc70 Mon Sep 17 00:00:00 2001 From: tv Date: Thu, 19 Nov 2026 13:48:39 +0000 Subject: release: --version says what decides which builds work together `continuum --version` and `continuum-party --version` say, after the release, the wire versions the build speaks, the federation and the revisions of it it knows (with the `federation` feature), and the Automerge version it makes documents with: continuum 1.0.0 wire versions 52 to 52 federation 1: the base revision, revision 1 (merge-events) automerge 0.12.0 `-V` says the release alone, as before; continuum-party had no version at all. The Automerge version is the one the crate itself reports (`document::engine_version`), so it follows Cargo.lock. --- src/release.rs | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 src/release.rs (limited to 'src/release.rs') diff --git a/src/release.rs b/src/release.rs new file mode 100644 index 0000000..fe0df3b --- /dev/null +++ b/src/release.rs @@ -0,0 +1,65 @@ +//! What this build of continuum is, as `--version` says it: its release, the wire versions +//! it speaks, the federation and the revisions of it it knows, and the Automerge it makes +//! documents with; what decides which builds work together in one swarm +//! (`docs/operations.md`, Upgrading). Its peers say theirs with their handshakes +//! (`swarm::speaking`). + +use std::sync::OnceLock; + +use crate::transport::wire; + +/// What `--version` says after the program's name: the release, then a line each. +pub(crate) fn described() -> &'static str { + static DESCRIBED: OnceLock = OnceLock::new(); + DESCRIBED.get_or_init(|| { + let mut lines = vec![ + env!("CARGO_PKG_VERSION").to_owned(), + format!("wire versions {} to {}", wire::OLDEST, wire::VERSION), + ]; + lines.extend(federation()); + lines.push(format!("automerge {}", crate::document::engine_version())); + lines.join("\n") + }) +} + +/// The federation this build knows, and its revisions, the base revision first. +#[cfg(feature = "federation")] +fn federation() -> Option { + use crate::federation::revision::Revision; + let revisions: Vec = Revision::known() + .map(|revision| revision.to_string()) + .collect(); + Some(format!( + "federation {}: {}", + crate::federation::version::FEDERATION, + revisions.join(", ") + )) +} + +#[cfg(not(feature = "federation"))] +fn federation() -> Option { + None +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn a_build_says_what_decides_whom_it_works_with() { + let lines: Vec<&str> = described().lines().collect(); + assert_eq!(lines[0], env!("CARGO_PKG_VERSION")); + assert_eq!( + lines[1], + format!("wire versions {} to {}", wire::OLDEST, wire::VERSION) + ); + #[cfg(feature = "federation")] + assert!( + lines[2].starts_with("federation 1: the base revision"), + "{}", + lines[2] + ); + let automerge = lines.last().expect("lines"); + assert!(automerge.starts_with("automerge 0."), "{automerge}"); + } +} -- cgit v1.3.1