Skip to main content

spec_driven_docs/gates/
ki_state.rs

1//! Gate: a known-issue record carries one state.
2//!
3//! The state says how this project handles the defect, and it is the field
4//! every other reading of the record hangs from: a masked record owes a
5//! retire condition where a mitigated one owes none. A word outside the
6//! vocabulary answers with a handling the method never defined, so the
7//! value is judged here and consulted everywhere else.
8
9use crate::domain::rule_id::RuleId;
10use crate::gates::ki_record::{STATES, judge};
11use crate::gates::{GateCtx, GateResult};
12
13/// The rules this gate can cite.
14pub const CITES: &[RuleId] = &[RuleId::RecordCarriesOneState];
15
16/// Judge every known-issue record under the resolved roots.
17///
18/// # Errors
19///
20/// [`crate::gates::GateError::Io`] when a record cannot be read.
21pub fn run(ctx: &GateCtx, args: &[String]) -> GateResult {
22    judge(ctx, args, "state", &STATES, RuleId::RecordCarriesOneState)
23}
24
25#[cfg(test)]
26mod tests {
27    use super::*;
28    use crate::gates::tests_support::ki_fixture_state;
29
30    fn run_on(state: &str) -> Vec<String> {
31        let dir = ki_fixture_state(state, "retire_when: release >= 2.0\n");
32        let ctx = GateCtx::new(dir.path().to_str().unwrap());
33        run(&ctx, &[])
34            .unwrap()
35            .iter()
36            .map(ToString::to_string)
37            .collect()
38    }
39
40    #[test]
41    fn accepts_every_state_the_method_defines() {
42        for state in STATES {
43            assert!(run_on(state).is_empty(), "{state} was rejected");
44        }
45    }
46
47    #[test]
48    fn rejects_a_state_the_method_does_not_define() {
49        let out = run_on("closed");
50        assert_eq!(out.len(), 1);
51        assert!(out[0].starts_with("FAIL known-issues:a-record-carries-one-state "));
52    }
53}