git-ents.gitmain
⌘K
foforge
toolchain.rs62 lines · 2.1 KB · rusthistorycomment on this file
1//! The Toolchain entity: a hash-pinned execution-environment manifest.
2//!
3//! Spec coverage: `model.toolchain`.
4
5use facet::Facet;
6
7/// A toolchain manifest, living at `refs/meta/toolchains/<name>`
8/// (`namespace::toolchain_ref`).
9///
10/// Content addressing makes the manifest hash-pinned for free: its own
11/// tree object id, produced by `facet-git-tree` serialization, already
12/// names the exact bytes `recipe` holds. `recipe` carries whatever
13/// provenance is needed to reproduce the execution environment; its
14/// internal structure (toolchain kind, download vs. embedded binaries,
15/// pinned versions) is `ents-effect`'s domain (phase 5, not started here)
16/// — `model.toolchain` asks only that the manifest exist under this
17/// namespace and carry that provenance, not for a particular schema for
18/// it.
19///
20/// # Examples
21///
22/// ```
23/// use ents_model::Toolchain;
24///
25/// let toolchain = Toolchain {
26/// name: "rust-stable".to_owned(),
27/// recipe: "rustup component add ... pinned to 1.90.0".to_owned(),
28/// };
29/// let (id, store) = facet_git_tree::serialize(&toolchain).expect("serialize");
30/// let back: Toolchain = facet_git_tree::deserialize(&id, &store).expect("deserialize");
31/// assert_eq!(back, toolchain);
32/// ```
33// @relation(model.toolchain, meta-ref.typed-tree, model.extensibility, scope=file)
34#[derive(Debug, Clone, PartialEq, Eq, Facet)]
35pub struct Toolchain {
36 /// The toolchain's name — the last segment of its ref.
37 pub name: String,
38 /// Opaque provenance needed to reproduce the execution environment.
39 pub recipe: String,
40}
41
42#[cfg(test)]
43mod tests {
44 #![allow(clippy::expect_used, reason = "unit test")]
45
46 use facet_git_tree::{deserialize, serialize};
47 use rstest::rstest;
48
49 use super::*;
50
51 #[rstest]
52 // @relation(model.toolchain, meta-ref.typed-tree, scope=function, role=Verifies)
53 fn toolchain_round_trips_through_a_tree() {
54 let toolchain = Toolchain {
55 name: "rust-stable".to_owned(),
56 recipe: "recipe text".to_owned(),
57 };
58 let (id, store) = serialize(&toolchain).expect("serialize");
59 let back: Toolchain = deserialize(&id, &store).expect("deserialize");
60 assert_eq!(back, toolchain);
61 }
62}