|
| 1 | +// SPDX-License-Identifier: MPL-2.0 |
| 2 | + |
| 3 | +//! Any `.a2ml` file is a priority-1 finding. |
| 4 | +//! |
| 5 | +//! A2ML is retired (owner rulings D99, D269c, D312, D313): no `.a2ml` file |
| 6 | +//! should exist anywhere in a repository. Rhodibot used to *expect* some of |
| 7 | +//! them; now every tracked `*.a2ml` is reported as [`Severity::Retired`], the |
| 8 | +//! worst a canon report holds, one finding per file so a grid can place each |
| 9 | +//! one against a change. |
| 10 | +//! |
| 11 | +//! Each finding names the form the file's facts belong in, from the standards |
| 12 | +//! mapping specs (`metadatastician/standards` `1-formats/deed/mappings/`), and |
| 13 | +//! says how it gets there: conversion is kyX's front end (D313), never a hand |
| 14 | +//! conversion, and a family with no mapping spec waits for one. Rhodibot only |
| 15 | +//! reports; the fleet's `fix-a2ml-via-kyx.sh` is what tries the conversion. |
| 16 | +//! |
| 17 | +//! This is the report, not the read path: the legacy read fallback in |
| 18 | +//! [`super::overlay`] (a legacy file read as "migrate" when its deed form is |
| 19 | +//! absent) is unchanged. |
| 20 | +
|
| 21 | +use super::report::Finding; |
| 22 | +use super::verdict::Severity; |
| 23 | + |
| 24 | +/// The finding id. Not a canon criterion: a rhodibot rule on top of it. |
| 25 | +pub const NO_A2ML_ID: &str = "rhodibot.no-a2ml"; |
| 26 | + |
| 27 | +/// Where one A2ML family's facts go, and whether kyX can take them there. |
| 28 | +#[derive(Debug, Clone, PartialEq, Eq)] |
| 29 | +pub struct Destination { |
| 30 | + /// The deed form, as a report names it. |
| 31 | + pub form: &'static str, |
| 32 | + /// The mapping spec that decides it, or `None` when there is none yet. |
| 33 | + pub spec: Option<&'static str>, |
| 34 | + /// Whether kyX has a front end for the family today. |
| 35 | + pub kyx: bool, |
| 36 | +} |
| 37 | + |
| 38 | +/// The family a path belongs to, by its file name (and, for bot directives and |
| 39 | +/// contractiles, its directory). |
| 40 | +pub fn destination(path: &str) -> Destination { |
| 41 | + let lower = path.to_ascii_lowercase(); |
| 42 | + let name = lower.rsplit('/').next().unwrap_or(&lower); |
| 43 | + let d = |form, spec, kyx| Destination { form, spec, kyx }; |
| 44 | + match name { |
| 45 | + "ecosystem.a2ml" => d( |
| 46 | + ".machine_readable/descriptiles/ECOSYSTEM.deed, or the chora (ecosystem ...) clause", |
| 47 | + Some("meta-ecosystem-to-repo-deed.adoc"), |
| 48 | + true, |
| 49 | + ), |
| 50 | + "meta.a2ml" => d( |
| 51 | + ".machine_readable/descriptiles/META.deed, or the chora (meta ...) clause", |
| 52 | + Some("meta-ecosystem-to-repo-deed.adoc"), |
| 53 | + false, |
| 54 | + ), |
| 55 | + "state.a2ml" => d( |
| 56 | + ".machine_readable/descriptiles/STATE.deed, or the chora (status ...) clause", |
| 57 | + Some("state-v1-decision.adoc"), |
| 58 | + false, |
| 59 | + ), |
| 60 | + "agentic.a2ml" | "neurosym.a2ml" | "playbook.a2ml" => d( |
| 61 | + "the chora (agentic ...) / (neurosym ...) / (playbook ...) clause", |
| 62 | + Some("agentic-neurosym-playbook-to-repo-deed.adoc"), |
| 63 | + false, |
| 64 | + ), |
| 65 | + "clade.a2ml" => d( |
| 66 | + "the chora (identity ...) (clade ...) (forges ...) (lineage ...) clauses", |
| 67 | + Some("clade-to-repo-deed.adoc"), |
| 68 | + false, |
| 69 | + ), |
| 70 | + "0-ai-manifest.a2ml" => d( |
| 71 | + "the chora (manifest ...) clause", |
| 72 | + Some("ai-manifest-decision.adoc"), |
| 73 | + false, |
| 74 | + ), |
| 75 | + "anchor.a2ml" => d("the chora (anchor ...) clause", None, false), |
| 76 | + "rsr-profile.a2ml" => d("the chora (rsr-profile ...) clause", None, false), |
| 77 | + "rsr-criteria-v2.a2ml" => d( |
| 78 | + "a criteria praxis deed", |
| 79 | + Some("rsr-criteria-to-praxis-deed.adoc"), |
| 80 | + false, |
| 81 | + ), |
| 82 | + _ if lower.contains("bot_directives/") => { |
| 83 | + d("the chora (bot-directives ...) clause", None, false) |
| 84 | + } |
| 85 | + _ if name.ends_with("file.a2ml") && lower.contains("contractiles/") => d( |
| 86 | + "a contractile deed (<Verb>file.deed) attesting its .k9.ncl contract", |
| 87 | + None, |
| 88 | + false, |
| 89 | + ), |
| 90 | + _ => d("a deed form a mapping spec has yet to decide", None, false), |
| 91 | + } |
| 92 | +} |
| 93 | + |
| 94 | +/// Whether a tracked path is an A2ML file. |
| 95 | +pub fn is_a2ml(path: &str) -> bool { |
| 96 | + path.to_ascii_lowercase().ends_with(".a2ml") |
| 97 | +} |
| 98 | + |
| 99 | +/// One [`Severity::Retired`] finding per `.a2ml` file, in path order. |
| 100 | +pub fn findings(files: &[String]) -> Vec<Finding> { |
| 101 | + let mut paths: Vec<&String> = files.iter().filter(|p| is_a2ml(p)).collect(); |
| 102 | + paths.sort(); |
| 103 | + paths.dedup(); |
| 104 | + paths |
| 105 | + .into_iter() |
| 106 | + .map(|path| { |
| 107 | + let dest = destination(path); |
| 108 | + let how = match (dest.spec, dest.kyx) { |
| 109 | + (Some(spec), true) => format!( |
| 110 | + "convert it with kyX under {spec} (D313); a refusal is a P1 issue, never a \ |
| 111 | + hand conversion" |
| 112 | + ), |
| 113 | + (Some(spec), false) => format!( |
| 114 | + "{spec} decides it, but kyX has no front end for it yet: it waits for kyX \ |
| 115 | + (D313); do not hand-convert" |
| 116 | + ), |
| 117 | + (None, _) => "no mapping spec decides it yet: it waits for one and for kyX \ |
| 118 | + (D313); do not hand-convert" |
| 119 | + .to_string(), |
| 120 | + }; |
| 121 | + Finding { |
| 122 | + id: NO_A2ML_ID.to_string(), |
| 123 | + name: "A2ML is retired (D99, D269c, D312, D313)".to_string(), |
| 124 | + tier: "P1".to_string(), |
| 125 | + severity: Severity::Retired, |
| 126 | + canon_keeps_it_at: None, |
| 127 | + expected: vec![dest.form.to_string()], |
| 128 | + found: vec![path.clone()], |
| 129 | + deprecated_copies: Vec::new(), |
| 130 | + details: vec![format!( |
| 131 | + "{path}: retired A2ML; its facts belong in {}; {how}", |
| 132 | + dest.form |
| 133 | + )], |
| 134 | + } |
| 135 | + }) |
| 136 | + .collect() |
| 137 | +} |
| 138 | + |
| 139 | +#[cfg(test)] |
| 140 | +mod tests { |
| 141 | + use super::*; |
| 142 | + |
| 143 | + fn files(paths: &[&str]) -> Vec<String> { |
| 144 | + paths.iter().map(|p| p.to_string()).collect() |
| 145 | + } |
| 146 | + |
| 147 | + #[test] |
| 148 | + fn every_a2ml_is_one_retired_finding_and_nothing_else_is() { |
| 149 | + let got = findings(&files(&[ |
| 150 | + "README.adoc", |
| 151 | + ".machine_readable/descriptiles/STATE.a2ml", |
| 152 | + "0-AI-MANIFEST.a2ml", |
| 153 | + "x_chora.deed", |
| 154 | + "deep/nested/Thing.A2ML", |
| 155 | + ".machine_readable/descriptiles/STATE.a2ml", |
| 156 | + ])); |
| 157 | + let paths: Vec<&str> = got.iter().map(|f| f.found[0].as_str()).collect(); |
| 158 | + assert_eq!( |
| 159 | + paths, |
| 160 | + [ |
| 161 | + ".machine_readable/descriptiles/STATE.a2ml", |
| 162 | + "0-AI-MANIFEST.a2ml", |
| 163 | + "deep/nested/Thing.A2ML" |
| 164 | + ] |
| 165 | + ); |
| 166 | + for f in &got { |
| 167 | + assert_eq!(f.severity, Severity::Retired); |
| 168 | + assert_eq!(f.id, NO_A2ML_ID); |
| 169 | + assert_eq!(f.tier, "P1"); |
| 170 | + // Never asks for an .a2ml, never suggests a hand conversion. |
| 171 | + assert!(f.expected.iter().all(|e| !e.ends_with(".a2ml")), "{f:?}"); |
| 172 | + assert!(f.details[0].contains("D313"), "{f:?}"); |
| 173 | + } |
| 174 | + } |
| 175 | + |
| 176 | + #[test] |
| 177 | + fn only_ecosystem_is_routed_to_kyx_today() { |
| 178 | + assert!(destination(".machine_readable/descriptiles/ECOSYSTEM.a2ml").kyx); |
| 179 | + assert!(destination(".machine_readable/6a2/ECOSYSTEM.a2ml").kyx); |
| 180 | + for path in [ |
| 181 | + "STATE.a2ml", |
| 182 | + "META.a2ml", |
| 183 | + "AGENTIC.a2ml", |
| 184 | + "CLADE.a2ml", |
| 185 | + "0-AI-MANIFEST.a2ml", |
| 186 | + ".machine_readable/bot_directives/coverage.a2ml", |
| 187 | + "contractiles/must/Mustfile.a2ml", |
| 188 | + "audits/assail-classifications.a2ml", |
| 189 | + ] { |
| 190 | + assert!(!destination(path).kyx, "{path}"); |
| 191 | + } |
| 192 | + } |
| 193 | + |
| 194 | + #[test] |
| 195 | + fn families_name_their_deed_form() { |
| 196 | + assert!( |
| 197 | + destination("x/bot_directives/debt.a2ml") |
| 198 | + .form |
| 199 | + .contains("(bot-directives") |
| 200 | + ); |
| 201 | + assert!( |
| 202 | + destination("contractiles/trust/Trustfile.a2ml") |
| 203 | + .form |
| 204 | + .contains("contractile deed") |
| 205 | + ); |
| 206 | + assert!(destination("STATE.a2ml").form.contains("STATE.deed")); |
| 207 | + assert_eq!(destination("odd.a2ml").spec, None); |
| 208 | + // A name ending in "file" outside a contractiles directory is not a |
| 209 | + // contractile: it waits for a mapping spec like any other stray file. |
| 210 | + for stray in ["docs/profile.a2ml", "data/myfile.a2ml"] { |
| 211 | + assert!( |
| 212 | + destination(stray).form.contains("yet to decide"), |
| 213 | + "{stray}: {}", |
| 214 | + destination(stray).form |
| 215 | + ); |
| 216 | + } |
| 217 | + } |
| 218 | + |
| 219 | + #[test] |
| 220 | + fn a_finding_says_ecosystem_goes_through_kyx_and_others_wait() { |
| 221 | + let got = findings(&files(&["ECOSYSTEM.a2ml", "META.a2ml", "odd.a2ml"])); |
| 222 | + assert!( |
| 223 | + got[0].details[0].contains("convert it with kyX"), |
| 224 | + "{:?}", |
| 225 | + got[0] |
| 226 | + ); |
| 227 | + assert!(got[1].details[0].contains("waits for kyX"), "{:?}", got[1]); |
| 228 | + assert!( |
| 229 | + got[2].details[0].contains("no mapping spec"), |
| 230 | + "{:?}", |
| 231 | + got[2] |
| 232 | + ); |
| 233 | + } |
| 234 | +} |
0 commit comments