qualia_core_db/semantic_instruments/
manufacture.rs1use super::category::ContentCategory;
5use super::errors::InstrumentError;
6use super::package::open_collectable;
7
8#[derive(Debug, Clone, Copy, PartialEq, Eq)]
10pub enum AuthoringLayer {
11 Source,
12 Graph,
13 Executable,
14}
15
16#[derive(Debug, Clone, PartialEq, Eq)]
18pub struct PublishInspection {
19 pub release_id: String,
20 pub category: ContentCategory,
21 pub labelled: bool,
22 pub has_source_n3: bool,
23 pub has_graph_q42: bool,
24 pub has_visual_10d: bool,
25 pub round_trip_loss: bool,
26}
27
28pub const WASM_Q42_HELD: &str =
30 "held / not yet — native Q42 v3 volumes are not loadable on this WASM profile; N3/HCF remain inspectable";
31
32pub fn inspect_for_publish(bytes: &[u8]) -> Result<PublishInspection, InstrumentError> {
34 let opened = open_collectable(bytes)?;
35 let labelled = opened.manifest.content_category.requires_seed_label();
36 let has_n3 = !opened.definition_n3.is_empty();
37 let has_q42 = opened.small_q42.as_ref().is_some_and(|b| !b.is_empty());
38 Ok(PublishInspection {
39 release_id: opened.manifest.release_id,
40 category: opened.manifest.content_category,
41 labelled,
42 has_source_n3: has_n3,
43 has_graph_q42: has_q42,
44 has_visual_10d: !opened.visual_10d.is_empty(),
45 round_trip_loss: has_n3 && !has_q42,
47 })
48}
49
50pub fn assert_can_publish(inspection: &PublishInspection) -> Result<(), InstrumentError> {
52 if !inspection.has_source_n3 {
53 return Err(InstrumentError::MissingField(
54 "graphs/instrument-definition.n3",
55 ));
56 }
57 if inspection.category.requires_seed_label() && !inspection.labelled {
58 return Err(InstrumentError::DemoUnlabelled);
59 }
60 Ok(())
61}
62
63#[cfg(test)]
64mod tests {
65 use super::*;
66 use crate::semantic_instruments::demo::build_demo;
67
68 #[test]
69 fn demo_pack_inspects_and_may_publish() {
70 let bytes = build_demo("unit-convert").unwrap();
71 let insp = inspect_for_publish(&bytes).unwrap();
72 assert_eq!(insp.category, ContentCategory::Demo);
73 assert!(insp.labelled);
74 assert!(insp.has_source_n3);
75 assert!(insp.has_visual_10d);
76 assert_can_publish(&insp).unwrap();
77 }
78
79 #[test]
80 fn empty_bytes_cannot_publish() {
81 assert!(inspect_for_publish(&[]).is_err());
82 }
83}