Skip to main content

made_core/entities/
validator_report.rs

1use serde::{Deserialize, Serialize};
2
3use crate::error::DomainError;
4use crate::value_objects::Attributes;
5
6/// A single adapter-defined validator result for one proposal.
7#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
8pub struct ValidatorReport {
9    kind: String,
10    passed: bool,
11    summary: String,
12    details: Attributes,
13}
14
15impl ValidatorReport {
16    pub fn new(
17        kind: impl Into<String>,
18        passed: bool,
19        summary: impl Into<String>,
20        details: Attributes,
21    ) -> Result<Self, DomainError> {
22        let kind = kind.into();
23        if kind.trim().is_empty() {
24            return Err(DomainError::EmptyField {
25                field: "validator_report.kind",
26            });
27        }
28        Ok(Self {
29            kind,
30            passed,
31            summary: summary.into(),
32            details,
33        })
34    }
35
36    #[must_use]
37    pub fn kind(&self) -> &str {
38        &self.kind
39    }
40
41    #[must_use]
42    pub fn passed(&self) -> bool {
43        self.passed
44    }
45
46    #[must_use]
47    pub fn summary(&self) -> &str {
48        &self.summary
49    }
50
51    #[must_use]
52    pub fn details(&self) -> &Attributes {
53        &self.details
54    }
55}
56
57#[cfg(test)]
58mod tests {
59    use super::*;
60
61    #[test]
62    fn empty_kind_is_rejected() {
63        let error = ValidatorReport::new("  ", true, "", Attributes::empty()).unwrap_err();
64        assert!(matches!(
65            error,
66            DomainError::EmptyField {
67                field: "validator_report.kind"
68            }
69        ));
70    }
71
72    #[test]
73    fn arbitrary_kind_is_accepted() {
74        for kind in [
75            "lint",
76            "policy",
77            "dry-run",
78            "clinical-safety",
79            "sourcing-feasibility",
80            "fact-check",
81        ] {
82            let report = ValidatorReport::new(kind, true, "summary", Attributes::empty()).unwrap();
83            assert_eq!(report.kind(), kind);
84        }
85    }
86}