git-ents.gitmain
⌘K
foforge
entity.rs60 lines · 2.0 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 this crate's own domain — see [`super::resolve`]
16/// for the [`super::Recipe`] structure `recipe` parses into.
17///
18/// # Examples
19///
20/// ```
21/// use ents_kiln::Toolchain;
22///
23/// let toolchain = Toolchain {
24/// name: "rust-stable".to_owned(),
25/// recipe: "rustup component add ... pinned to 1.90.0".to_owned(),
26/// };
27/// let (id, store) = facet_git_tree::serialize(&toolchain).expect("serialize");
28/// let back: Toolchain = facet_git_tree::deserialize(&id, &store).expect("deserialize");
29/// assert_eq!(back, toolchain);
30/// ```
31// @relation(model.toolchain, meta-ref.typed-tree, model.extensibility, scope=file)
32#[derive(Debug, Clone, PartialEq, Eq, Facet)]
33pub struct Toolchain {
34 /// The toolchain's name — the last segment of its ref.
35 pub name: String,
36 /// Opaque provenance needed to reproduce the execution environment.
37 pub recipe: String,
38}
39
40#[cfg(test)]
41mod tests {
42 #![allow(clippy::expect_used, reason = "unit test")]
43
44 use facet_git_tree::{deserialize, serialize};
45 use rstest::rstest;
46
47 use super::*;
48
49 #[rstest]
50 // @relation(model.toolchain, meta-ref.typed-tree, scope=function, role=Verifies)
51 fn toolchain_round_trips_through_a_tree() {
52 let toolchain = Toolchain {
53 name: "rust-stable".to_owned(),
54 recipe: "recipe text".to_owned(),
55 };
56 let (id, store) = serialize(&toolchain).expect("serialize");
57 let back: Toolchain = deserialize(&id, &store).expect("deserialize");
58 assert_eq!(back, toolchain);
59 }
60}