Skip to main content

made_api/
authoring_views.rs

1use serde::{Deserialize, Serialize};
2
3use crate::DefinitionDefectView;
4
5/// What analysis found — all of it.
6///
7/// Every defect at once, never the first one (ADR-002 upstream): fixing
8/// defects one at a time spends the author's attention on round trips.
9#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
10pub struct DefinitionAnalysisView {
11    /// Identity declared by the parsed draft.
12    pub definition_name: String,
13    pub definition_version: String,
14    /// Whether the draft, as analyzed, could be published.
15    pub publishable: bool,
16    /// Canonical hex digest the executable definition will publish with.
17    ///
18    /// Present exactly when the draft is publishable. This is the same
19    /// identity [`PublishedDefinitionView::digest`] returns and ceremony
20    /// instances bind to; it is not a hash of the source bytes.
21    pub definition_digest: Option<String>,
22    pub defects: Vec<DefinitionDefectView>,
23}
24
25#[cfg(test)]
26mod tests {
27    use super::*;
28    use crate::PublishedDefinitionView;
29
30    #[test]
31    fn an_analysis_survives_the_wire() {
32        let analysis = DefinitionAnalysisView {
33            definition_name: "scope_discovery".to_owned(),
34            definition_version: "1.0".to_owned(),
35            publishable: false,
36            definition_digest: None,
37            defects: vec![DefinitionDefectView {
38                severity: "error".to_owned(),
39                locus: "state `ORPHAN`".to_owned(),
40                defect: "state is unreachable".to_owned(),
41                blocking: true,
42            }],
43        };
44        let bytes = serde_json::to_vec(&analysis).expect("serializes");
45        assert_eq!(
46            serde_json::from_slice::<DefinitionAnalysisView>(&bytes).expect("deserializes"),
47            analysis
48        );
49    }
50
51    #[test]
52    fn a_publication_names_what_an_instance_will_bind_to() {
53        let published = PublishedDefinitionView {
54            name: "scope_discovery".to_owned(),
55            version: "1.0".to_owned(),
56            digest: "abc123".to_owned(),
57            already_published: false,
58        };
59        assert!(
60            !published.digest.is_empty(),
61            "a publication without a digest cannot be bound to, only believed"
62        );
63    }
64}