Skip to main content

dkp_core/validate/
gates.rs

1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
4pub enum Gate {
5    /// Machine usability — schemas, required files, graph edge resolution
6    Gate4 = 4,
7    /// Evaluation — eval_set.jsonl present and achieves min_eval_delta
8    Gate7 = 7,
9    /// OKF conformance — frontmatter, link resolution, bundle signature
10    Gate8 = 8,
11}
12
13#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
14pub enum GateStatus {
15    Pass,
16    Fail,
17    /// Gate was not run (e.g., optional asset not present)
18    Skipped,
19    /// Gate not applicable (e.g., OKF layer absent for gate 8)
20    NotApplicable,
21}
22
23#[derive(Debug, Clone, Serialize, Deserialize)]
24pub struct GateResult {
25    pub gate: u8,
26    pub status: GateStatus,
27    pub checks: Vec<CheckResult>,
28    #[serde(skip_serializing_if = "Option::is_none")]
29    pub message: Option<String>,
30}
31
32#[derive(Debug, Clone, Serialize, Deserialize)]
33pub struct CheckResult {
34    pub description: String,
35    pub status: GateStatus,
36    #[serde(skip_serializing_if = "Option::is_none")]
37    pub detail: Option<String>,
38}
39
40impl CheckResult {
41    pub fn pass(description: impl Into<String>) -> Self {
42        Self {
43            description: description.into(),
44            status: GateStatus::Pass,
45            detail: None,
46        }
47    }
48
49    pub fn fail(description: impl Into<String>, detail: impl Into<String>) -> Self {
50        Self {
51            description: description.into(),
52            status: GateStatus::Fail,
53            detail: Some(detail.into()),
54        }
55    }
56
57    pub fn skip(description: impl Into<String>) -> Self {
58        Self {
59            description: description.into(),
60            status: GateStatus::Skipped,
61            detail: None,
62        }
63    }
64}
65
66#[derive(Debug, Serialize, Deserialize)]
67pub struct ValidationReport {
68    pub pack_name: String,
69    pub pack_version: String,
70    pub gates: Vec<GateResult>,
71    pub overall: GateStatus,
72    pub conformance: ConformanceLevel,
73    pub reviewed: bool,
74}
75
76#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
77pub enum ConformanceLevel {
78    /// Gates 4 and 8 passed
79    DkpConformant,
80    /// Gates 4, 7, and 8 passed; review_notes attests human editorial review
81    DkpReviewed,
82    /// Not conformant
83    NonConformant,
84}