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 carry one filing state.
45    KiFiling,
46    /// Known-issue records walk the mechanism.
47    KiMechanismWalkthrough,
48    /// Filed known-issue records carry their report body.
49    KiReportBody,
50    /// Known-issue records carry a retirement condition.
51    KiRetireWhen,
52    /// Known-issue records carry one state.
53    KiState,
54    /// Files carry no absolute path into a person's home directory.
55    NoPersonalPath,
56    /// Documents state the present rather than narrate their edits.
57    NoSelfNarration,
58    /// Paragraphs occupy one source line rather than hard-wrap.
59    ProseStaysUnwrapped,
60    /// Spec requirements carry all five parts.
61    SpecRequirementParts,
62    /// Rule IDs are unique across the local specs.
63    SpecRuleIdUnique,
64    /// Specs stay within their line cap and carry a TOC when long.
65    SpecSizeCap,
66    /// Spec verification lines name hooks that exist.
67    SpecVerifyHooksExist,
68    /// Suppression comments name a known-issue case.
69    SuppressionNamesItsCase,
70}
71
72impl GateId {
73    /// Every delivered gate, in id order.
74    pub const ALL: &'static [Self] = &[
75        Self::AdrCitesALiveRule,
76        Self::AdrFilenameShape,
77        Self::AdrWordCap,
78        Self::AgentsDigestSize,
79        Self::ChapterSizeCap,
80        Self::ComparisonDatedTables,
81        Self::ComparisonEscapedPipes,
82        Self::ComparisonLegend,
83        Self::ComparisonOneReferencePerCell,
84        Self::ComparisonVerdictWord,
85        Self::GateMessageCitesARule,
86        Self::InstanceManifest,
87        Self::KiBugzillaReportWidth,
88        Self::KiFilenameShape,
89        Self::KiFiling,
90        Self::KiMechanismWalkthrough,
91        Self::KiReportBody,
92        Self::KiRetireWhen,
93        Self::KiState,
94        Self::NoPersonalPath,
95        Self::NoSelfNarration,
96        Self::ProseStaysUnwrapped,
97        Self::SpecRequirementParts,
98        Self::SpecRuleIdUnique,
99        Self::SpecSizeCap,
100        Self::SpecVerifyHooksExist,
101        Self::SuppressionNamesItsCase,
102    ];
103
104    /// The kebab-case id used on the command line and as the hook id.
105    #[must_use]
106    pub const fn as_str(self) -> &'static str {
107        match self {
108            Self::AdrCitesALiveRule => "adr-cites-a-live-rule",
109            Self::AdrFilenameShape => "adr-filename-shape",
110            Self::AdrWordCap => "adr-word-cap",
111            Self::AgentsDigestSize => "agents-digest-size",
112            Self::ChapterSizeCap => "chapter-size-cap",
113            Self::ComparisonDatedTables => "comparison-dated-tables",
114            Self::ComparisonEscapedPipes => "comparison-escaped-pipes",
115            Self::ComparisonLegend => "comparison-legend",
116            Self::ComparisonOneReferencePerCell => "comparison-one-reference-per-cell",
117            Self::ComparisonVerdictWord => "comparison-verdict-word",
118            Self::GateMessageCitesARule => "gate-message-cites-a-rule",
119            Self::InstanceManifest => "instance-manifest",
120            Self::KiBugzillaReportWidth => "ki-bugzilla-report-width",
121            Self::KiFilenameShape => "ki-filename-shape",
122            Self::KiFiling => "ki-filing",
123            Self::KiMechanismWalkthrough => "ki-mechanism-walkthrough",
124            Self::KiReportBody => "ki-report-body",
125            Self::KiRetireWhen => "ki-retire-when",
126            Self::KiState => "ki-state",
127            Self::NoPersonalPath => "no-personal-path",
128            Self::NoSelfNarration => "no-self-narration",
129            Self::ProseStaysUnwrapped => "prose-stays-unwrapped",
130            Self::SpecRequirementParts => "spec-requirement-parts",
131            Self::SpecRuleIdUnique => "spec-rule-id-unique",
132            Self::SpecSizeCap => "spec-size-cap",
133            Self::SpecVerifyHooksExist => "spec-verify-hooks-exist",
134            Self::SuppressionNamesItsCase => "suppression-names-its-case",
135        }
136    }
137}
138
139impl std::str::FromStr for GateId {
140    type Err = String;
141
142    fn from_str(s: &str) -> Result<Self, Self::Err> {
143        Self::ALL
144            .iter()
145            .copied()
146            .find(|gate| gate.as_str() == s)
147            .ok_or_else(|| format!("unknown gate: {s}"))
148    }
149}
150
151impl fmt::Display for GateId {
152    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
153        f.write_str(self.as_str())
154    }
155}
156
157#[cfg(test)]
158mod tests {
159    use super::*;
160
161    #[test]
162    fn all_lists_every_variant_once() {
163        let mut seen = std::collections::BTreeSet::new();
164        for gate in GateId::ALL {
165            assert!(seen.insert(gate.as_str()), "{gate} is duplicated");
166        }
167        assert_eq!(GateId::ALL.len(), 27);
168    }
169
170    #[test]
171    fn clap_value_matches_as_str() {
172        for gate in GateId::ALL {
173            let value = gate.to_possible_value().unwrap();
174            assert_eq!(value.get_name(), gate.as_str());
175        }
176    }
177}