Skip to main content

spec_driven_docs/domain/
gate_id.rs

1//! Gate identifiers: one variant per delivered gate.
2//!
3//! A gate ID names an executable check a consumer wires as a pre-commit hook
4//! and invokes as `sdd gate <id>`. This enum is only the identity; what a
5//! gate checks, how it is wired, and its display name live in the gate
6//! registry, and canon-only checks are cargo tests rather than variants here.
7
8use std::fmt;
9
10use clap::ValueEnum;
11
12/// A delivered gate, addressable as `sdd gate <id>` and as a pre-commit hook id.
13#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, ValueEnum)]
14#[value(rename_all = "kebab-case")]
15pub enum GateId {
16    /// Decision record citations resolve to a live rule.
17    AdrCitesALiveRule,
18    /// Decision record filenames are dated-free slugs.
19    AdrFilenameShape,
20    /// Decision record bodies stay within the word cap.
21    AdrWordCap,
22    /// Agent digests stay within their line budgets.
23    AgentsDigestSize,
24    /// Chapters and catalogs stay within their line caps.
25    ChapterSizeCap,
26    /// Comparison tables carry a verification date.
27    ComparisonDatedTables,
28    /// Comparison table pipes are escaped inside cells.
29    ComparisonEscapedPipes,
30    /// Comparison documents carry a legend.
31    ComparisonLegend,
32    /// Comparison cells carry at most one reference.
33    ComparisonOneReferencePerCell,
34    /// Comparison verdicts carry their word.
35    ComparisonVerdictWord,
36    /// Every rule ID a gate can print resolves to a local requirement.
37    GateMessageCitesARule,
38    /// The instance manifest is present and coherent.
39    InstanceManifest,
40    /// Bugzilla-bound report bodies fit the tracker's width.
41    KiBugzillaReportWidth,
42    /// Known-issue filenames are slugged case IDs.
43    KiFilenameShape,
44    /// Known-issue records walk the mechanism.
45    KiMechanismWalkthrough,
46    /// Filed known-issue records carry their report body.
47    KiReportBody,
48    /// Known-issue records carry a retirement condition.
49    KiRetireWhen,
50    /// Files carry no absolute path into a person's home directory.
51    NoPersonalPath,
52    /// Documents state the present rather than narrate their edits.
53    NoSelfNarration,
54    /// Paragraphs occupy one source line rather than hard-wrap.
55    ProseStaysUnwrapped,
56    /// Spec requirements carry all five parts.
57    SpecRequirementParts,
58    /// Rule IDs are unique across the local specs.
59    SpecRuleIdUnique,
60    /// Specs stay within their line cap and carry a TOC when long.
61    SpecSizeCap,
62    /// Spec verification lines name hooks that exist.
63    SpecVerifyHooksExist,
64    /// Suppression comments name a known-issue case.
65    SuppressionNamesItsCase,
66}
67
68impl GateId {
69    /// Every delivered gate, in id order.
70    pub const ALL: &'static [Self] = &[
71        Self::AdrCitesALiveRule,
72        Self::AdrFilenameShape,
73        Self::AdrWordCap,
74        Self::AgentsDigestSize,
75        Self::ChapterSizeCap,
76        Self::ComparisonDatedTables,
77        Self::ComparisonEscapedPipes,
78        Self::ComparisonLegend,
79        Self::ComparisonOneReferencePerCell,
80        Self::ComparisonVerdictWord,
81        Self::GateMessageCitesARule,
82        Self::InstanceManifest,
83        Self::KiBugzillaReportWidth,
84        Self::KiFilenameShape,
85        Self::KiMechanismWalkthrough,
86        Self::KiReportBody,
87        Self::KiRetireWhen,
88        Self::NoPersonalPath,
89        Self::NoSelfNarration,
90        Self::ProseStaysUnwrapped,
91        Self::SpecRequirementParts,
92        Self::SpecRuleIdUnique,
93        Self::SpecSizeCap,
94        Self::SpecVerifyHooksExist,
95        Self::SuppressionNamesItsCase,
96    ];
97
98    /// The kebab-case id used on the command line and as the hook id.
99    #[must_use]
100    pub const fn as_str(self) -> &'static str {
101        match self {
102            Self::AdrCitesALiveRule => "adr-cites-a-live-rule",
103            Self::AdrFilenameShape => "adr-filename-shape",
104            Self::AdrWordCap => "adr-word-cap",
105            Self::AgentsDigestSize => "agents-digest-size",
106            Self::ChapterSizeCap => "chapter-size-cap",
107            Self::ComparisonDatedTables => "comparison-dated-tables",
108            Self::ComparisonEscapedPipes => "comparison-escaped-pipes",
109            Self::ComparisonLegend => "comparison-legend",
110            Self::ComparisonOneReferencePerCell => "comparison-one-reference-per-cell",
111            Self::ComparisonVerdictWord => "comparison-verdict-word",
112            Self::GateMessageCitesARule => "gate-message-cites-a-rule",
113            Self::InstanceManifest => "instance-manifest",
114            Self::KiBugzillaReportWidth => "ki-bugzilla-report-width",
115            Self::KiFilenameShape => "ki-filename-shape",
116            Self::KiMechanismWalkthrough => "ki-mechanism-walkthrough",
117            Self::KiReportBody => "ki-report-body",
118            Self::KiRetireWhen => "ki-retire-when",
119            Self::NoPersonalPath => "no-personal-path",
120            Self::NoSelfNarration => "no-self-narration",
121            Self::ProseStaysUnwrapped => "prose-stays-unwrapped",
122            Self::SpecRequirementParts => "spec-requirement-parts",
123            Self::SpecRuleIdUnique => "spec-rule-id-unique",
124            Self::SpecSizeCap => "spec-size-cap",
125            Self::SpecVerifyHooksExist => "spec-verify-hooks-exist",
126            Self::SuppressionNamesItsCase => "suppression-names-its-case",
127        }
128    }
129}
130
131impl std::str::FromStr for GateId {
132    type Err = String;
133
134    fn from_str(s: &str) -> Result<Self, Self::Err> {
135        Self::ALL
136            .iter()
137            .copied()
138            .find(|gate| gate.as_str() == s)
139            .ok_or_else(|| format!("unknown gate: {s}"))
140    }
141}
142
143impl fmt::Display for GateId {
144    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
145        f.write_str(self.as_str())
146    }
147}
148
149#[cfg(test)]
150mod tests {
151    use super::*;
152
153    #[test]
154    fn all_lists_every_variant_once() {
155        let mut seen = std::collections::BTreeSet::new();
156        for gate in GateId::ALL {
157            assert!(seen.insert(gate.as_str()), "{gate} is duplicated");
158        }
159        assert_eq!(GateId::ALL.len(), 25);
160    }
161
162    #[test]
163    fn clap_value_matches_as_str() {
164        for gate in GateId::ALL {
165            let value = gate.to_possible_value().unwrap();
166            assert_eq!(value.get_name(), gate.as_str());
167        }
168    }
169}