visual_rubric/
deterministic.rs1use serde::{Deserialize, Serialize};
4
5pub const DETERMINISTIC_EVIDENCE_SCHEMA_VERSION: u32 = 1;
7
8#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq)]
10pub struct DeterministicEvidenceV1 {
11 pub schema_version: u32,
13 #[serde(default)]
15 pub observations: Vec<DeterministicObservationV1>,
16}
17
18#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq)]
20pub struct DeterministicObservationV1 {
21 pub kind: String,
23 pub summary: String,
25}
26
27impl DeterministicEvidenceV1 {
28 pub fn validate(&self) -> Result<(), Vec<String>> {
30 let mut issues = Vec::new();
31 if self.schema_version != DETERMINISTIC_EVIDENCE_SCHEMA_VERSION {
32 issues.push(format!(
33 "unsupported deterministic evidence schema_version {}; expected {}",
34 self.schema_version, DETERMINISTIC_EVIDENCE_SCHEMA_VERSION
35 ));
36 }
37 for (index, observation) in self.observations.iter().enumerate() {
38 if observation.kind.trim().is_empty() {
39 issues.push(format!(
40 "deterministic observation {index} has an empty kind"
41 ));
42 }
43 if observation.summary.trim().is_empty() {
44 issues.push(format!(
45 "deterministic observation {} has an empty summary",
46 observation.kind
47 ));
48 }
49 }
50 if issues.is_empty() {
51 Ok(())
52 } else {
53 Err(issues)
54 }
55 }
56}
57
58#[cfg(test)]
59mod tests {
60 use super::*;
61
62 #[test]
63 fn accepts_a_clear_envelope() {
64 DeterministicEvidenceV1 {
65 schema_version: DETERMINISTIC_EVIDENCE_SCHEMA_VERSION,
66 observations: Vec::new(),
67 }
68 .validate()
69 .expect("clear evidence");
70 }
71
72 #[test]
73 fn rejects_empty_observation_fields() {
74 let issues = DeterministicEvidenceV1 {
75 schema_version: DETERMINISTIC_EVIDENCE_SCHEMA_VERSION,
76 observations: vec![DeterministicObservationV1 {
77 kind: String::new(),
78 summary: String::new(),
79 }],
80 }
81 .validate()
82 .expect_err("empty fields");
83 assert_eq!(issues.len(), 2);
84 }
85}