From 916a46bdb261db7f8b5b734685d9ff99d0782f02 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 17 Nov 2026 03:15:59 +0000 Subject: [PATCH 1/3] feat(rhodibot): any .a2ml is a priority-1 finding; stop expecting retired forms Owner directive (2026-11-17): rid the estate of A2ML, and make any .a2ml a priority-1 finding in the relevant bots, rhodibot first. canon (the report-back path): - New severity `retired`, ranked above `missing`. Every tracked *.a2ml is one `rhodibot.no-a2ml` finding (tier P1) at its own path, so the grid can place it against a change. Each names the deed form its family maps to under the standards mapping specs and whether kyX can convert it today (only ECOSYSTEM.a2ml, D313); none asks for an .a2ml or a hand conversion. - counts.retired, a "P1:" summary line, and --fail-on retired (clap and FailOn); a tree with an .a2ml exits 1, a clean one 0. - The legacy read fallback is unchanged: the criterion an old file would satisfy is still "migrate" (relocated), never "missing". GitHub App check (rsr.rs): - `no-*.a2ml` (RSR-A2ML-001): any .a2ml in the default-branch tree is a Required failure under every policy pack; .rsr.toml cannot skip or downgrade it. An unlistable or truncated tree is a Skip naming the reason, never a pass. - RSR-015 (.machine_readable/bot_directives/) is retired: its files were .a2ml and the directives are the chora deed's (bot-directives ...) clause, so demanding the directory demanded a retired form. The legacy .bot_directives/ advice now points at the deed clause. Report-back: `retired` -> `critical` (above `error` -> high). Dogfood: `rhodibot canon --path .` on this repository reports 42 P1 findings, 3 of them (the ECOSYSTEM files) routable to kyX. deed.rs is untouched (#687 owns it). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01J4QvDhFeexmokLqLRfZNce --- bots/rhodibot/README.adoc | 27 ++- bots/rhodibot/src/canon.rs | 1 + bots/rhodibot/src/canon/a2ml.rs | 225 +++++++++++++++++++++++ bots/rhodibot/src/canon/report.rs | 59 +++++- bots/rhodibot/src/canon/verdict.rs | 8 + bots/rhodibot/src/fleet.rs | 8 +- bots/rhodibot/src/main.rs | 6 +- bots/rhodibot/src/rsr.rs | 65 +++++-- bots/rhodibot/tests/integration_tests.rs | 117 +++++++++++- docs/REPORT-BACK.adoc | 2 +- scripts/fleet-report-back.sh | 7 +- tests/fleet-report-back-test.sh | 7 +- 12 files changed, 493 insertions(+), 39 deletions(-) create mode 100644 bots/rhodibot/src/canon/a2ml.rs diff --git a/bots/rhodibot/README.adoc b/bots/rhodibot/README.adoc index cce54ff4..da2a69b9 100644 --- a/bots/rhodibot/README.adoc +++ b/bots/rhodibot/README.adoc @@ -104,14 +104,12 @@ Each RSR check has a severity (Required, Recommended, Optional) that varies by p | CONTRIBUTING.md | Optional | Recommended | Required | Required | CODE_OF_CONDUCT.md | Optional | Optional | Recommended | Required | .claude/CLAUDE.md | Optional | Optional | Recommended | Required -| STATE.scm | Optional | Recommended | Required | Required -| META.scm | Optional | Recommended | Required | Required -| ECOSYSTEM.scm | Optional | Optional | Recommended | Required +| `_chora.deed` | Optional | Recommended | Required | Required | .editorconfig | Optional | Recommended | Required | Required | .gitattributes | Optional | Recommended | Required | Required | .gitignore | Optional | Recommended | Required | Required | Justfile | Optional | Optional | Recommended | Required -| .bot_directives | Optional | Optional | Recommended | Required +| any `*.a2ml` (`no-*.a2ml`, P1) | Required | Required | Required | Required |=== Repositories can override severity or skip checks entirely via `.rsr.toml`: @@ -205,9 +203,11 @@ Options: | .gitattributes | Structure | 2 | .gitignore | Structure | 2 | Justfile | Structure | 2 -| .bot_directives | Structure | 2 |=== +RSR-015 (`.machine_readable/bot_directives/`) is retired: its files were `.a2ml`, and +the bot directives are the chora deed's `(bot-directives ...)` clause. + === Banned Patterns (6) [cols="2,3"] @@ -235,9 +235,20 @@ A2ML is retired. The repo facts that used to be `.a2ml` files (manifest, state, meta, ecosystem, agentic, neurosym, playbook, anchor, rsr-profile) are clauses of `_chora.deed`, or of a descriptile deed (`STATE.deed`, `META.deed`, `ECOSYSTEM.deed`, `AGENTIC.deed`). Rhodibot requires the chora deed and never -demands or suggests an `.a2ml` file. A legacy `.a2ml` that is still present is -read only as a fallback after the deed, and is reported as "migrate", never as -"missing". Whether a deed *conforms* is `deed_lint.js`'s job in +demands or suggests an `.a2ml` file. + +*Any `.a2ml` file is a priority-1 finding.* `canon` reports each tracked `.a2ml` +as `rhodibot.no-a2ml` with severity `retired` (above `missing`; `--fail-on +retired` gates on it), naming the deed form its family maps to under the +standards mapping specs and whether kyX can convert it today (only +`ECOSYSTEM.a2ml`, D313). The fleet report-back carries it as `critical`. The +GitHub App check reports `no-*.a2ml` (RSR-A2ML-001) as a Required failure in every +policy pack; `.rsr.toml` cannot skip or downgrade it. Rhodibot only reports: +conversion is `scripts/fix-a2ml-via-kyx.sh`, never by hand. + +Separately, a legacy `.a2ml` that is still present is read only as a fallback +after the deed, and the criterion it would satisfy is reported as "migrate", +never as "missing". Whether a deed *conforms* is `deed_lint.js`'s job in `metadatastician/standards`; rhodibot only reads its structure. The vendored criteria canon is itself still an `.a2ml` file; its deed form is a diff --git a/bots/rhodibot/src/canon.rs b/bots/rhodibot/src/canon.rs index d78bec95..35452560 100644 --- a/bots/rhodibot/src/canon.rs +++ b/bots/rhodibot/src/canon.rs @@ -39,6 +39,7 @@ //! The failure mode to avoid is the quiet one: a rule set that silently shrinks //! and reports every repository as compliant. +pub mod a2ml; pub mod local; pub mod overlay; pub mod profile; diff --git a/bots/rhodibot/src/canon/a2ml.rs b/bots/rhodibot/src/canon/a2ml.rs new file mode 100644 index 00000000..241f39ef --- /dev/null +++ b/bots/rhodibot/src/canon/a2ml.rs @@ -0,0 +1,225 @@ +// SPDX-License-Identifier: MPL-2.0 + +//! Any `.a2ml` file is a priority-1 finding. +//! +//! A2ML is retired (owner rulings D99, D269c, D312, D313): no `.a2ml` file +//! should exist anywhere in a repository. Rhodibot used to *expect* some of +//! them; now every tracked `*.a2ml` is reported as [`Severity::Retired`], the +//! worst a canon report holds, one finding per file so a grid can place each +//! one against a change. +//! +//! Each finding names the form the file's facts belong in, from the standards +//! mapping specs (`metadatastician/standards` `1-formats/deed/mappings/`), and +//! says how it gets there: conversion is kyX's front end (D313), never a hand +//! conversion, and a family with no mapping spec waits for one. Rhodibot only +//! reports; the fleet's `fix-a2ml-via-kyx.sh` is what tries the conversion. +//! +//! This is the report, not the read path: the legacy read fallback in +//! [`super::overlay`] (a legacy file read as "migrate" when its deed form is +//! absent) is unchanged. + +use super::report::Finding; +use super::verdict::Severity; + +/// The finding id. Not a canon criterion: a rhodibot rule on top of it. +pub const NO_A2ML_ID: &str = "rhodibot.no-a2ml"; + +/// Where one A2ML family's facts go, and whether kyX can take them there. +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct Destination { + /// The deed form, as a report names it. + pub form: &'static str, + /// The mapping spec that decides it, or `None` when there is none yet. + pub spec: Option<&'static str>, + /// Whether kyX has a front end for the family today. + pub kyx: bool, +} + +/// The family a path belongs to, by its file name (and, for bot directives and +/// contractiles, its directory). +pub fn destination(path: &str) -> Destination { + let lower = path.to_ascii_lowercase(); + let name = lower.rsplit('/').next().unwrap_or(&lower); + let d = |form, spec, kyx| Destination { form, spec, kyx }; + match name { + "ecosystem.a2ml" => d( + ".machine_readable/descriptiles/ECOSYSTEM.deed, or the chora (ecosystem ...) clause", + Some("meta-ecosystem-to-repo-deed.adoc"), + true, + ), + "meta.a2ml" => d( + ".machine_readable/descriptiles/META.deed, or the chora (meta ...) clause", + Some("meta-ecosystem-to-repo-deed.adoc"), + false, + ), + "state.a2ml" => d( + ".machine_readable/descriptiles/STATE.deed, or the chora (status ...) clause", + Some("state-v1-decision.adoc"), + false, + ), + "agentic.a2ml" | "neurosym.a2ml" | "playbook.a2ml" => d( + "the chora (agentic ...) / (neurosym ...) / (playbook ...) clause", + Some("agentic-neurosym-playbook-to-repo-deed.adoc"), + false, + ), + "clade.a2ml" => d( + "the chora (identity ...) (clade ...) (forges ...) (lineage ...) clauses", + Some("clade-to-repo-deed.adoc"), + false, + ), + "0-ai-manifest.a2ml" => d( + "the chora (manifest ...) clause", + Some("ai-manifest-decision.adoc"), + false, + ), + "anchor.a2ml" => d("the chora (anchor ...) clause", None, false), + "rsr-profile.a2ml" => d("the chora (rsr-profile ...) clause", None, false), + "rsr-criteria-v2.a2ml" => d( + "a criteria praxis deed", + Some("rsr-criteria-to-praxis-deed.adoc"), + false, + ), + _ if lower.contains("bot_directives/") => { + d("the chora (bot-directives ...) clause", None, false) + } + _ if name.ends_with("file.a2ml") => d( + "a contractile deed (file.deed) attesting its .k9.ncl contract", + None, + false, + ), + _ => d("a deed form a mapping spec has yet to decide", None, false), + } +} + +/// Whether a tracked path is an A2ML file. +pub fn is_a2ml(path: &str) -> bool { + path.to_ascii_lowercase().ends_with(".a2ml") +} + +/// One [`Severity::Retired`] finding per `.a2ml` file, in path order. +pub fn findings(files: &[String]) -> Vec { + let mut paths: Vec<&String> = files.iter().filter(|p| is_a2ml(p)).collect(); + paths.sort(); + paths.dedup(); + paths + .into_iter() + .map(|path| { + let dest = destination(path); + let how = match (dest.spec, dest.kyx) { + (Some(spec), true) => format!( + "convert it with kyX under {spec} (D313); a refusal is a P1 issue, never a \ + hand conversion" + ), + (Some(spec), false) => format!( + "{spec} decides it, but kyX has no front end for it yet: it waits for kyX \ + (D313); do not hand-convert" + ), + (None, _) => "no mapping spec decides it yet: it waits for one and for kyX \ + (D313); do not hand-convert" + .to_string(), + }; + Finding { + id: NO_A2ML_ID.to_string(), + name: "A2ML is retired (D99, D269c, D312, D313)".to_string(), + tier: "P1".to_string(), + severity: Severity::Retired, + canon_keeps_it_at: None, + expected: vec![dest.form.to_string()], + found: vec![path.clone()], + deprecated_copies: Vec::new(), + details: vec![format!( + "{path}: retired A2ML; its facts belong in {}; {how}", + dest.form + )], + } + }) + .collect() +} + +#[cfg(test)] +mod tests { + use super::*; + + fn files(paths: &[&str]) -> Vec { + paths.iter().map(|p| p.to_string()).collect() + } + + #[test] + fn every_a2ml_is_one_retired_finding_and_nothing_else_is() { + let got = findings(&files(&[ + "README.adoc", + ".machine_readable/descriptiles/STATE.a2ml", + "0-AI-MANIFEST.a2ml", + "x_chora.deed", + "deep/nested/Thing.A2ML", + ".machine_readable/descriptiles/STATE.a2ml", + ])); + let paths: Vec<&str> = got.iter().map(|f| f.found[0].as_str()).collect(); + assert_eq!( + paths, + [ + ".machine_readable/descriptiles/STATE.a2ml", + "0-AI-MANIFEST.a2ml", + "deep/nested/Thing.A2ML" + ] + ); + for f in &got { + assert_eq!(f.severity, Severity::Retired); + assert_eq!(f.id, NO_A2ML_ID); + assert_eq!(f.tier, "P1"); + // Never asks for an .a2ml, never suggests a hand conversion. + assert!(f.expected.iter().all(|e| !e.ends_with(".a2ml")), "{f:?}"); + assert!(f.details[0].contains("D313"), "{f:?}"); + } + } + + #[test] + fn only_ecosystem_is_routed_to_kyx_today() { + assert!(destination(".machine_readable/descriptiles/ECOSYSTEM.a2ml").kyx); + assert!(destination(".machine_readable/6a2/ECOSYSTEM.a2ml").kyx); + for path in [ + "STATE.a2ml", + "META.a2ml", + "AGENTIC.a2ml", + "CLADE.a2ml", + "0-AI-MANIFEST.a2ml", + ".machine_readable/bot_directives/coverage.a2ml", + "contractiles/must/Mustfile.a2ml", + "audits/assail-classifications.a2ml", + ] { + assert!(!destination(path).kyx, "{path}"); + } + } + + #[test] + fn families_name_their_deed_form() { + assert!( + destination("x/bot_directives/debt.a2ml") + .form + .contains("(bot-directives") + ); + assert!( + destination("contractiles/trust/Trustfile.a2ml") + .form + .contains("contractile deed") + ); + assert!(destination("STATE.a2ml").form.contains("STATE.deed")); + assert_eq!(destination("odd.a2ml").spec, None); + } + + #[test] + fn a_finding_says_ecosystem_goes_through_kyx_and_others_wait() { + let got = findings(&files(&["ECOSYSTEM.a2ml", "META.a2ml", "odd.a2ml"])); + assert!( + got[0].details[0].contains("convert it with kyX"), + "{:?}", + got[0] + ); + assert!(got[1].details[0].contains("waits for kyX"), "{:?}", got[1]); + assert!( + got[2].details[0].contains("no mapping spec"), + "{:?}", + got[2] + ); + } +} diff --git a/bots/rhodibot/src/canon/report.rs b/bots/rhodibot/src/canon/report.rs index 1f578414..23276a5d 100644 --- a/bots/rhodibot/src/canon/report.rs +++ b/bots/rhodibot/src/canon/report.rs @@ -59,6 +59,8 @@ pub struct Counts { pub deprecated: usize, pub missing: usize, pub manual: usize, + /// `.a2ml` files present (one per file, not per criterion). + pub retired: usize, } impl Counts { @@ -68,6 +70,7 @@ impl Counts { Severity::Relocated => self.relocated += 1, Severity::Deprecated => self.deprecated += 1, Severity::Missing => self.missing += 1, + Severity::Retired => self.retired += 1, Severity::Manual => self.manual += 1, } } @@ -112,6 +115,8 @@ pub enum FailOn { Relocated, Deprecated, Missing, + /// Only a retired format (`.a2ml`), the priority-1 finding. + Retired, } impl FailOn { @@ -122,6 +127,7 @@ impl FailOn { Self::Relocated => Some(Severity::Relocated), Self::Deprecated => Some(Severity::Deprecated), Self::Missing => Some(Severity::Missing), + Self::Retired => Some(Severity::Retired), } } @@ -131,9 +137,10 @@ impl FailOn { "relocated" => Ok(Self::Relocated), "deprecated" => Ok(Self::Deprecated), "missing" => Ok(Self::Missing), + "retired" => Ok(Self::Retired), other => anyhow::bail!( "unknown --fail-on value {other:?}; expected one of none, relocated, deprecated, \ - missing" + missing, retired" ), } } @@ -144,6 +151,7 @@ impl FailOn { Self::Relocated => "relocated", Self::Deprecated => "deprecated", Self::Missing => "missing", + Self::Retired => "retired", } } @@ -299,6 +307,15 @@ impl CanonReport { report.record(&criterion, &verdict); } + // Priority 1: every tracked `.a2ml` file, one finding each. These are + // not criteria, so they count in `counts.retired` and not in `scored`. + // The real file list only: the overlay's virtual paths are deed + // clauses, never `.a2ml`. + for finding in super::a2ml::findings(&input.files) { + report.counts.retired += 1; + report.findings.push(finding); + } + // Worst first, and stable, so equal severities stay in canon order -- // which is category order, and the order a reader expects. report @@ -348,6 +365,12 @@ impl CanonReport { self.counts.deprecated, self.counts.missing )); + if self.counts.retired > 0 { + out.push_str(&format!( + " P1: {} retired .a2ml file(s) present (A2ML is retired; convert with kyX, D313)\n", + self.counts.retired + )); + } if !self.declared_capabilities.is_empty() { out.push_str(&format!( @@ -926,6 +949,40 @@ mod tests { ); } + #[test] + fn every_a2ml_is_a_p1_finding_ranked_first_and_trips_fail_on_retired() { + let report = report_for( + &[ + "widgets_chora.deed", + ".machine_readable/descriptiles/STATE.a2ml", + "contractiles/must/Mustfile.a2ml", + ], + Some("(repo-deed)"), + None, + ); + let p1: Vec<&Finding> = report + .findings + .iter() + .filter(|f| f.id == super::super::a2ml::NO_A2ML_ID) + .collect(); + assert_eq!(p1.len(), 2, "{:#?}", report.findings); + assert_eq!(report.counts.retired, 2); + // Worst first: the P1 findings lead the report. + assert_eq!(report.findings[0].severity, Severity::Retired); + assert_eq!(report.findings[1].severity, Severity::Retired); + // The legacy read is unchanged: 3.1.2 still reads it as "migrate". + assert_eq!( + finding(&report, "3.1.2").map(|f| f.severity), + Some(Severity::Relocated) + ); + assert!(FailOn::Retired.breached_by(&report)); + assert!(report.render().contains("P1: 2 retired .a2ml")); + // A repository with no .a2ml has no P1 finding and does not trip. + let clean = report_for(&["widgets_chora.deed"], Some("(repo-deed)"), None); + assert_eq!(clean.counts.retired, 0); + assert!(!FailOn::Retired.breached_by(&clean)); + } + #[test] fn a_legacy_profile_is_read_only_when_the_deed_declares_none() { let legacy = "[rsr-profile]\nversion = \"1.0.0\"\ncapabilities = [\"governance-tier\"]\n"; diff --git a/bots/rhodibot/src/canon/verdict.rs b/bots/rhodibot/src/canon/verdict.rs index c6e068c8..8308751c 100644 --- a/bots/rhodibot/src/canon/verdict.rs +++ b/bots/rhodibot/src/canon/verdict.rs @@ -235,6 +235,10 @@ pub enum Severity { Deprecated, /// Not present. Missing, + /// A retired format is present: an `.a2ml` file (D99, D269c, D312, D313). + /// Priority 1, worse than a missing file, because it is a live record in a + /// form nothing may read or extend; see [`super::a2ml`]. + Retired, } impl Severity { @@ -245,6 +249,7 @@ impl Severity { Self::Relocated => "relocated", Self::Deprecated => "deprecated", Self::Missing => "missing", + Self::Retired => "retired", } } @@ -384,6 +389,9 @@ impl Verdict { Severity::Relocated => "elsewhere", Severity::Deprecated => "deprecated location", Severity::Missing => "absent", + // A criterion's verdict never computes to Retired (see severity()); + // only the per-file `.a2ml` rule uses it. + Severity::Retired => "retired format", } } diff --git a/bots/rhodibot/src/fleet.rs b/bots/rhodibot/src/fleet.rs index 36cc5ff3..351183aa 100644 --- a/bots/rhodibot/src/fleet.rs +++ b/bots/rhodibot/src/fleet.rs @@ -60,7 +60,9 @@ fn rule_id(check_name: &str) -> String { ".gitattributes" => format!("{}-012", RULE_PREFIX), ".gitignore" => format!("{}-013", RULE_PREFIX), "justfile" | "Justfile" => format!("{}-014", RULE_PREFIX), - ".machine_readable/bot_directives" => format!("{}-015", RULE_PREFIX), + // RSR-015 (.machine_readable/bot_directives/) is retired: the bot + // directives are the chora deed's (bot-directives ...) clause. + crate::rsr::A2ML_CHECK => format!("{}-A2ML-001", RULE_PREFIX), name if name.ends_with("_chora.deed") => format!("{}-016", RULE_PREFIX), "www/.well-known/security.txt" => format!("{}-017", RULE_PREFIX), ".machine_readable/root-allow.txt" => format!("{}-018", RULE_PREFIX), @@ -94,8 +96,8 @@ fn suggestion_for(check_name: &str) -> Option { ".gitattributes" => Some("Add .gitattributes for line ending and diff config".to_string()), ".gitignore" => Some("Add .gitignore for build artifacts".to_string()), "Justfile" | "justfile" => Some("Add a Justfile as the primary build system".to_string()), - ".machine_readable/bot_directives" => Some("Create .machine_readable/bot_directives/ for bot configs".to_string()), - "no-.bot_directives" => Some("Migrate legacy .bot_directives/ to .machine_readable/bot_directives/".to_string()), + "no-.bot_directives" => Some("Migrate legacy .bot_directives/ into the chora deed's (bot-directives ...) clause; do not recreate .machine_readable/bot_directives/".to_string()), + crate::rsr::A2ML_CHECK => Some("P1: A2ML is retired. Convert each .a2ml with kyX under the standards mapping specs (D313); where kyX refuses or has no front end, the fleet opens a P1 issue. Never hand-convert".to_string()), name if name.ends_with("_chora.deed") => Some(format!( "Add {name} (the chora deed): the repository's identity and facts, including its manifest, meta, ecosystem, agentic, anchor, rsr-profile and bot-directives clauses; check it with deed_lint.js from metadatastician/standards" )), diff --git a/bots/rhodibot/src/main.rs b/bots/rhodibot/src/main.rs index ebb2192a..2c772f46 100644 --- a/bots/rhodibot/src/main.rs +++ b/bots/rhodibot/src/main.rs @@ -75,7 +75,8 @@ enum Command { /// skips the criteria the repository's chora deed `(rsr-profile ...)` /// clause does not declare a capability for, and reports what is present where the /// canon records it, present elsewhere, present under a location the canon - /// has retired, or absent. + /// has retired, or absent. Every tracked `.a2ml` file is also reported, as a + /// `retired` (priority-1) finding: A2ML is retired (D99, D269c, D312, D313). /// /// **Advisory by default**: exits 0 whatever it finds. The canon names /// hypatia's `rsr-conformance` the single normative checker, so a second @@ -102,7 +103,8 @@ enum Command { format: String, /// Exit non-zero when a finding at or above this severity is present - #[arg(long, default_value = "none", value_parser = ["none", "relocated", "deprecated", "missing"])] + /// (none < relocated < deprecated < missing < retired) + #[arg(long, default_value = "none", value_parser = ["none", "relocated", "deprecated", "missing", "retired"])] fail_on: String, }, diff --git a/bots/rhodibot/src/rsr.rs b/bots/rhodibot/src/rsr.rs index b0bf0ad1..3915af53 100644 --- a/bots/rhodibot/src/rsr.rs +++ b/bots/rhodibot/src/rsr.rs @@ -8,6 +8,7 @@ use anyhow::{Context, Result}; use serde::{Deserialize, Serialize}; use std::collections::HashMap; +use crate::canon::a2ml; use crate::config::Config; use crate::deed::{Deed, DocFormat}; use crate::github::GitHubClient; @@ -172,6 +173,9 @@ pub async fn check_candidates_exist( (false, candidates[0].clone()) } +/// The name of the priority-1 check for retired `.a2ml` files. +pub const A2ML_CHECK: &str = "no-*.a2ml"; + /// Required files for RSR compliance with policy-based severity pub const REQUIRED_FILES: &[CheckDef] = &[ // NOTE ON THE 2026-09-18 REVISION @@ -331,19 +335,9 @@ pub const REQUIRED_FILES: &[CheckDef] = &[ Severity::Required, ), }, - CheckDef { - name: ".machine_readable/bot_directives", - alternates: &[], - description: "Bot directives directory in canonical machine-readable location", - category: CheckCategory::Structure, - points: 2, - severity: ( - Severity::Optional, - Severity::Optional, - Severity::Recommended, - Severity::Required, - ), - }, + // RSR-015 (.machine_readable/bot_directives/) is retired: its files were + // .a2ml, and the bot directives are the chora deed's (bot-directives ...) + // clause now. Requiring the directory demanded a retired form. CheckDef { // Entered the template 2026-08-26; 59/269 as of 2026-09-18. Either // canonical spelling is accepted (see check-root-shape.sh). @@ -405,7 +399,7 @@ impl BannedPattern { pub const BANNED_PATTERNS: &[BannedPattern] = &[ BannedPattern { name: ".bot_directives", - description: "Legacy bot directives directory at repo root (use .machine_readable/bot_directives)", + description: "Legacy bot directives directory at repo root (use the chora deed's (bot-directives ...) clause)", category: CheckCategory::Structure, severity: ( Severity::Optional, @@ -789,6 +783,49 @@ pub async fn check_compliance_with_policy( } } + // Priority 1: any `.a2ml` file anywhere in the tree. A2ML is retired (D99, + // D269c, D312, D313), so this is Required in every policy pack and a repo + // config can neither skip nor downgrade it. A tree that cannot be listed is + // reported as skipped with the reason, never as a pass. + match client.tree_paths(owner, repo).await { + Ok(paths) => { + let found: Vec<&String> = paths.iter().filter(|p| a2ml::is_a2ml(p)).collect(); + if !found.is_empty() { + required_passed = false; + let shown: Vec<&str> = found.iter().take(10).map(|p| p.as_str()).collect(); + let more = found.len().saturating_sub(shown.len()); + checks.push(Check { + name: A2ML_CHECK.to_string(), + category: CheckCategory::Structure, + severity: Severity::Required, + status: CheckStatus::Fail, + points: 0, + max_points: 0, + message: format!( + "P1: {} retired .a2ml file(s) present: {}{} - A2ML is retired; convert \ + with kyX (D313), never by hand", + found.len(), + shown.join(", "), + if more > 0 { + format!(" (+{more} more)") + } else { + String::new() + } + ), + }); + } + } + Err(error) => checks.push(Check { + name: A2ML_CHECK.to_string(), + category: CheckCategory::Structure, + severity: Severity::Required, + status: CheckStatus::Skip, + points: 0, + max_points: 0, + message: format!("could not list the tree to look for .a2ml files: {error}"), + }), + } + // Check for workflow files let workflow_severity = match policy { PolicyPack::Minimal => Severity::Optional, diff --git a/bots/rhodibot/tests/integration_tests.rs b/bots/rhodibot/tests/integration_tests.rs index 20cf93c0..6d12b28d 100644 --- a/bots/rhodibot/tests/integration_tests.rs +++ b/bots/rhodibot/tests/integration_tests.rs @@ -305,6 +305,17 @@ mod rsr_tests { // A bare repository under the strictest policy: everything missing. let report = check_with(&[], None, PolicyPack::Enterprise).await; for check in &report.checks { + // The one check that names .a2ml FORBIDS it (priority 1); it never + // asks for one. + if check.name == A2ML_CHECK { + let m = check.message.to_lowercase(); + assert!( + !m.contains("add ") && !m.contains("create"), + "{}", + check.message + ); + continue; + } assert!( !check.name.contains("a2ml") && !check.name.ends_with(".scm") @@ -809,15 +820,111 @@ mod rsr_tests { assert!(jf_check.is_some(), "should have justfile check"); assert_eq!(jf_check.unwrap().status, CheckStatus::Pass); - let bd_check = report + // RSR-015 is retired: its files were .a2ml, and the bot directives are + // the chora deed's (bot-directives ...) clause, so the directory is + // neither demanded nor scored. + assert!( + report + .checks + .iter() + .all(|c| c.name != ".machine_readable/bot_directives"), + "RSR-015 must not be demanded" + ); + } + + /// Serve a repository listing (default branch `main`) and its tree. + async fn mount_tree(server: &MockServer, paths: &[&str]) { + Mock::given(method("GET")) + .and(path("/repos/test-org/test-repo")) + .respond_with( + ResponseTemplate::new(200).set_body_json(repo_json(Some("mpl-2.0"), None)), + ) + .mount(server) + .await; + let tree: Vec = paths + .iter() + .map(|p| serde_json::json!({ "path": p, "type": "blob" })) + .collect(); + Mock::given(method("GET")) + .and(path("/repos/test-org/test-repo/git/trees/main")) + .respond_with( + ResponseTemplate::new(200) + .set_body_json(serde_json::json!({ "truncated": false, "tree": tree })), + ) + .mount(server) + .await; + } + + async fn report_for_tree(paths: &[&str], policy: PolicyPack) -> ComplianceReport { + let server = MockServer::start().await; + let config = mock_config(&server.uri()); + mount_file_mocks(&server, "test-org", "test-repo", &[]).await; + mount_tree(&server, paths).await; + let repo_config = RepoConfig { + policy, + ..Default::default() + }; + check_compliance_with_policy(&config, "test-org", "test-repo", &repo_config) + .await + .expect("compliance check should succeed") + } + + #[tokio::test] + async fn any_a2ml_is_a_required_failure_under_every_policy() { + for policy in [ + PolicyPack::Minimal, + PolicyPack::Standard, + PolicyPack::Strict, + PolicyPack::Enterprise, + PolicyPack::Custom, + ] { + let report = report_for_tree( + &[ + "README.adoc", + ".machine_readable/descriptiles/STATE.a2ml", + "deep/x.A2ML", + ], + policy, + ) + .await; + let check = report + .checks + .iter() + .find(|c| c.name == A2ML_CHECK) + .unwrap_or_else(|| panic!("{policy:?}: an a2ml check")); + assert_eq!(check.status, CheckStatus::Fail, "{policy:?}"); + assert_eq!(check.severity, Severity::Required, "{policy:?}"); + assert!( + check.message.starts_with("P1: 2 retired"), + "{}", + check.message + ); + assert!(check.message.contains("deep/x.A2ML"), "{}", check.message); + assert!(!report.required_passed, "{policy:?}"); + } + } + + #[tokio::test] + async fn a_tree_without_a2ml_has_no_a2ml_check() { + let report = report_for_tree(&["README.adoc", "x_chora.deed"], PolicyPack::Strict).await; + assert!(report.checks.iter().all(|c| c.name != A2ML_CHECK)); + } + + #[tokio::test] + async fn an_unlistable_tree_is_skipped_with_its_reason_never_passed() { + // No tree mock: the listing fails. + let report = check_with(&[], None, PolicyPack::Strict).await; + let check = report .checks .iter() - .find(|c| c.name == ".machine_readable/bot_directives"); + .find(|c| c.name == A2ML_CHECK) + .expect("the check is reported"); + assert_eq!(check.status, CheckStatus::Skip); assert!( - bd_check.is_some(), - "should have .machine_readable/bot_directives check" + check.message.starts_with("could not list the tree"), + "{}", + check.message ); - assert_eq!(bd_check.unwrap().status, CheckStatus::Pass); } #[tokio::test] diff --git a/docs/REPORT-BACK.adoc b/docs/REPORT-BACK.adoc index b84b89a5..c476d21a 100644 --- a/docs/REPORT-BACK.adoc +++ b/docs/REPORT-BACK.adoc @@ -113,7 +113,7 @@ that emits a path-less finding; rhodibot and seambot already comply. | rhodibot | `rhodibot canon --path --format json` | File-presence criteria against the vendored RSR canon. `satisfied` rows are - not findings; `missing` → error, `deprecated` → warning, `relocated` → info. + not findings; `retired` (a tracked `.a2ml`, priority 1) → critical, `missing` → error, `deprecated` → warning, `relocated` → info. Advisory by rhodibot's own design: hypatia's `rsr-conformance` is the normative checker. diff --git a/scripts/fleet-report-back.sh b/scripts/fleet-report-back.sh index 6b2a2135..6c14f81d 100755 --- a/scripts/fleet-report-back.sh +++ b/scripts/fleet-report-back.sh @@ -639,8 +639,9 @@ run_member() { case "$m" in rhodibot) # canon --path: file-presence criteria against the vendored RSR canon. - # "satisfied" rows are not findings; missing > deprecated > relocated; a - # "manual" row (not verifiable from files) is carried as info. + # "satisfied" rows are not findings; retired > missing > deprecated > + # relocated; a "manual" row (not verifiable from files) is carried as + # info. "retired" is a tracked .a2ml file: priority 1, so critical. run_adapter "$bin" canon --path "$repo" --format json translate_or_error "$m" "$SHAPE_OBJ_FINDINGS"' [ .findings[] @@ -652,7 +653,7 @@ run_member() { file: ((if .severity == "missing" then (.canon_keeps_it_at // (.expected // [])[0] // "") else ((.found // [])[0] // .canon_keeps_it_at // (.expected // [])[0] // "") end) | tostring), line: 0, - severity: ({missing: "error", deprecated: "warning", relocated: "info", manual: "info"}[.severity] // .severity), + severity: ({retired: "critical", missing: "error", deprecated: "warning", relocated: "info", manual: "info"}[.severity] // .severity), message: ("\(.name): \(.severity)" + (if (.details // []) | length > 0 then " — " + ((.details // []) | join("; ")) else "" end)) } | .file |= rel ]' ;; panicbot) diff --git a/tests/fleet-report-back-test.sh b/tests/fleet-report-back-test.sh index ffd96600..52c07c81 100755 --- a/tests/fleet-report-back-test.sh +++ b/tests/fleet-report-back-test.sh @@ -82,7 +82,8 @@ cat <&2; exit 9; } command -v panic-attack >/dev/null || { echo "Error: Failed to run panic-attack assail" >&2; exit 1; } @@ -139,9 +140,11 @@ check "...and says so" yes "$(grep -q 'enrolment manifest unreadable' "$TMP/o1c. # 2. translation ─────────────────────────────────────────────────────────────── r="$TMP/o1/rhodibot.json" -check "rhodibot: satisfied rows are not findings" 2 "$(field "$r" '.findings | length')" +check "rhodibot: satisfied rows are not findings" 3 "$(field "$r" '.findings | length')" check "rhodibot: missing is error" error "$(field "$r" '.findings[] | select(.rule_id == "1.1.2") | .severity')" check "rhodibot: relocated is info" info "$(field "$r" '.findings[] | select(.rule_id == "4.1") | .severity')" +check "rhodibot: a retired .a2ml is critical (P1)" critical "$(field "$r" '.findings[] | select(.rule_id == "rhodibot.no-a2ml") | .severity')" +check "rhodibot: a retired .a2ml is named where it is" .machine_readable/descriptiles/STATE.a2ml "$(field "$r" '.findings[] | select(.rule_id == "rhodibot.no-a2ml") | .file')" check "rhodibot: a missing file is named where the canon keeps it" Justfile "$(field "$r" '.findings[] | select(.rule_id == "1.1.2") | .file')" check "rhodibot: a relocated file is named where it was found, so the diff can match it" .well-known/security.txt "$(field "$r" '.findings[] | select(.rule_id == "4.1") | .file')" check "rhodibot: title comes from the manifest" "rhodibot (RSR compliance)" "$(field "$r" .title)" From f3c07a0d8075e0b85ad945025fe7269c1694dc0b Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 17 Nov 2026 03:31:58 +0000 Subject: [PATCH 2/3] test(report-back): a P1 .a2ml makes rhodibot's grid row purple CI's "The grid accepts the envelopes" failed: the real renderer (standards scripts/verdict-grid.sh) now grades rhodibot's stubbed row purple, because the stub carries a P1 retired .a2ml finding (critical) and critical outranks red. That is the intended effect of this PR, so the check now expects purple and pins the critical count; error -> red stays pinned by ponsbot's row. Reproduced and fixed locally with STANDARDS_DIR set: 228/1 before, 229/0 after. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01J4QvDhFeexmokLqLRfZNce --- tests/fleet-report-back-test.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/fleet-report-back-test.sh b/tests/fleet-report-back-test.sh index 52c07c81..7aa91e2e 100755 --- a/tests/fleet-report-back-test.sh +++ b/tests/fleet-report-back-test.sh @@ -676,7 +676,10 @@ if [ -n "${STANDARDS_DIR:-}" ] && [ -f "$GRID" ]; then ( cd "$REPO" && bash "$GRID" render --out "$TMP/grid" --hypatia /dev/null --panic /dev/null --pons /dev/null \ --report-backs "$TMP/o1" --enrolment .gitbot-fleet/enrolment.json --sha 0000000 >/dev/null ) rowstate() { jq -r --arg id "$1" '.reporters[] | select(.id == $id) | .state' "$TMP/grid/report.json"; } - check "renderer: rhodibot's error finding is a red row" red "$(rowstate rhodibot)" + # rhodibot carries a P1 retired .a2ml (critical) as well as an error, and + # critical outranks red. error -> red stays pinned by ponsbot's row above. + check "renderer: rhodibot's P1 (critical) .a2ml finding makes its row purple" purple "$(rowstate rhodibot)" + check "renderer: rhodibot's P1 .a2ml is counted as critical" 1 "$(jq -r '.reporters[] | select(.id == "rhodibot") | .counts.critical' "$TMP/grid/report.json")" check "renderer: glambot's info finding is a blue row" blue "$(rowstate glambot)" check "renderer: panicbot's warning is a yellow row" yellow "$(rowstate panicbot)" check "renderer: echidnabot not_run is orange" orange "$(rowstate echidnabot)" From 2dc241e52bea898597e528175392ad559d43188f Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 17 Nov 2026 05:06:30 +0000 Subject: [PATCH 3/3] fix(rhodibot): the P1 .a2ml check scans the reported head and fails closed Review findings on #690: - A push or PR check now scans the tree at the head it reports on (check_compliance_at / tree_paths_at), not the default branch, so a PR that adds an .a2ml fails on that PR. - A tree that cannot be listed fails the Required check and clears required_passed, instead of a Skip that left the run green. - The report carries the retired paths (retired_a2ml), and the fleet gets one finding per file at its real path, never one at the wildcard. - Displayed paths are escaped (control characters, then Markdown) before they reach the check-run text; matching uses the raw path. - canon's git listing uses ls-files -z, so a C-quoted name cannot slip past the .a2ml suffix test. - *file.a2ml routes to a contractile deed only under a contractiles/ path. - The README names kyX's invocation and #691 instead of a script this PR does not add. Each fix has a test; the head-SHA and ls-files tests were mutation-checked. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01J4QvDhFeexmokLqLRfZNce --- bots/rhodibot/README.adoc | 7 +- bots/rhodibot/src/canon/a2ml.rs | 11 +- bots/rhodibot/src/canon/local.rs | 39 +++++-- bots/rhodibot/src/fleet.rs | 28 ++++++ bots/rhodibot/src/rsr.rs | 96 +++++++++++++++--- bots/rhodibot/src/webhook.rs | 6 +- bots/rhodibot/tests/integration_tests.rs | 123 ++++++++++++++++++++++- 7 files changed, 278 insertions(+), 32 deletions(-) diff --git a/bots/rhodibot/README.adoc b/bots/rhodibot/README.adoc index da2a69b9..9f24537e 100644 --- a/bots/rhodibot/README.adoc +++ b/bots/rhodibot/README.adoc @@ -243,8 +243,11 @@ retired` gates on it), naming the deed form its family maps to under the standards mapping specs and whether kyX can convert it today (only `ECOSYSTEM.a2ml`, D313). The fleet report-back carries it as `critical`. The GitHub App check reports `no-*.a2ml` (RSR-A2ML-001) as a Required failure in every -policy pack; `.rsr.toml` cannot skip or downgrade it. Rhodibot only reports: -conversion is `scripts/fix-a2ml-via-kyx.sh`, never by hand. +policy pack; `.rsr.toml` cannot skip or downgrade it, it scans the push or PR +head it reports on, and a tree it cannot list fails it closed. Rhodibot only +reports: conversion is kyX's (`kyx a2ml ecosystem SRC --chora CHORA ...`, D313), +run by the fleet's opportunistic fixer once that lands (proposed in #691), never +by hand. Separately, a legacy `.a2ml` that is still present is read only as a fallback after the deed, and the criterion it would satisfy is reported as "migrate", diff --git a/bots/rhodibot/src/canon/a2ml.rs b/bots/rhodibot/src/canon/a2ml.rs index 241f39ef..4433b525 100644 --- a/bots/rhodibot/src/canon/a2ml.rs +++ b/bots/rhodibot/src/canon/a2ml.rs @@ -82,7 +82,7 @@ pub fn destination(path: &str) -> Destination { _ if lower.contains("bot_directives/") => { d("the chora (bot-directives ...) clause", None, false) } - _ if name.ends_with("file.a2ml") => d( + _ if name.ends_with("file.a2ml") && lower.contains("contractiles/") => d( "a contractile deed (file.deed) attesting its .k9.ncl contract", None, false, @@ -205,6 +205,15 @@ mod tests { ); assert!(destination("STATE.a2ml").form.contains("STATE.deed")); assert_eq!(destination("odd.a2ml").spec, None); + // A name ending in "file" outside a contractiles directory is not a + // contractile: it waits for a mapping spec like any other stray file. + for stray in ["docs/profile.a2ml", "data/myfile.a2ml"] { + assert!( + destination(stray).form.contains("yet to decide"), + "{stray}: {}", + destination(stray).form + ); + } } #[test] diff --git a/bots/rhodibot/src/canon/local.rs b/bots/rhodibot/src/canon/local.rs index 1d465d4c..18430506 100644 --- a/bots/rhodibot/src/canon/local.rs +++ b/bots/rhodibot/src/canon/local.rs @@ -113,6 +113,7 @@ fn tracked_files(root: &Path) -> Option> { .arg("-C") .arg(root) .arg("ls-files") + .arg("-z") .output() .ok()?; @@ -120,12 +121,14 @@ fn tracked_files(root: &Path) -> Option> { return None; } - let listing = String::from_utf8(output.stdout).ok()?; - let mut files: Vec = listing - .lines() - .map(str::trim) - .filter(|line| !line.is_empty()) - .map(str::to_string) + // NUL-separated and raw: without `-z`, git C-quotes an unusual name (a + // newline, a quote, non-ASCII), and a quoted `"x.a2ml"` would slip past a + // suffix test. A name that is not UTF-8 is kept, lossily, rather than lost. + let mut files: Vec = output + .stdout + .split(|b| *b == 0) + .filter(|name| !name.is_empty()) + .map(|name| String::from_utf8_lossy(name).into_owned()) .collect(); files.sort(); files.dedup(); @@ -229,6 +232,30 @@ mod tests { ); } + #[test] + fn git_listing_keeps_unusual_names_raw() { + // Without `ls-files -z`, git C-quotes a name with a newline in it and + // the quoted form no longer ends in `.a2ml`. + let scratch = Scratch::new("ls-files-z"); + scratch.write("evil\nname.a2ml", "x"); + scratch.write("plain.adoc", "x"); + let git = |args: &[&str]| { + let ok = Command::new("git") + .arg("-C") + .arg(scratch.path()) + .args(args) + .output() + .map(|o| o.status.success()) + .unwrap_or(false); + assert!(ok, "git {args:?}"); + }; + git(&["init", "-q"]); + git(&["add", "-A"]); + let files = tracked_files(scratch.path()).expect("git can list the index"); + assert!(files.contains(&"evil\nname.a2ml".to_string()), "{files:?}"); + assert!(files.contains(&"plain.adoc".to_string()), "{files:?}"); + } + #[test] fn a_profile_is_read_from_either_allowed_path() { let estate = Scratch::new("profile-estate"); diff --git a/bots/rhodibot/src/fleet.rs b/bots/rhodibot/src/fleet.rs index 351183aa..95efef5e 100644 --- a/bots/rhodibot/src/fleet.rs +++ b/bots/rhodibot/src/fleet.rs @@ -160,6 +160,34 @@ pub fn report_to_findings(report: &ComplianceReport) -> Vec { .with_rule_name(&check.name) .with_category(category); + // The priority-1 A2ML check: one finding per retired file, at its real + // path, so a downstream bot can match it to a changed file. With no + // paths (the tree could not be listed) it stays one fileless finding, + // never a finding at the literal wildcard. + if check.name == crate::rsr::A2ML_CHECK && !report.retired_a2ml.is_empty() { + let suggestion = suggestion_for(&check.name); + for path in &report.retired_a2ml { + let mut one = Finding::new( + BotId::Rhodibot, + &rid, + fleet_severity, + &format!("P1: retired .a2ml file {path}"), + ) + .with_rule_name(&check.name) + .with_category(category) + .with_file(PathBuf::from(path)); + if let Some(s) = &suggestion { + one = one.with_suggestion(s); + } + findings.push(one); + } + continue; + } + if check.name == crate::rsr::A2ML_CHECK { + findings.push(finding); + continue; + } + // Set file path for file-based checks if !check.name.starts_with("license-type") && !check.name.starts_with("no-") { finding = finding.with_file(PathBuf::from(&check.name)); diff --git a/bots/rhodibot/src/rsr.rs b/bots/rhodibot/src/rsr.rs index 3915af53..d7276561 100644 --- a/bots/rhodibot/src/rsr.rs +++ b/bots/rhodibot/src/rsr.rs @@ -176,6 +176,23 @@ pub async fn check_candidates_exist( /// The name of the priority-1 check for retired `.a2ml` files. pub const A2ML_CHECK: &str = "no-*.a2ml"; +/// A tracked path as it may be shown in Markdown check output: control +/// characters (a newline could forge a check row) are escaped, then the +/// Markdown metacharacters [`crate::sanitize::sanitize_markdown`] covers. +pub fn display_path(path: &str) -> String { + let flat: String = path + .chars() + .flat_map(|c| -> Box> { + if c.is_control() { + Box::new(c.escape_debug()) + } else { + Box::new(std::iter::once(c)) + } + }) + .collect(); + crate::sanitize::sanitize_markdown(&flat) +} + /// Required files for RSR compliance with policy-based severity pub const REQUIRED_FILES: &[CheckDef] = &[ // NOTE ON THE 2026-09-18 REVISION @@ -503,6 +520,10 @@ pub struct ComplianceReport { pub required_passed: bool, pub checks: Vec, pub summary: String, + /// Every retired `.a2ml` path the priority-1 check found, raw and in tree + /// order, so the fleet gets one finding per file rather than a wildcard. + #[serde(default, skip_serializing_if = "Vec::is_empty")] + pub retired_a2ml: Vec, } /// Individual compliance check @@ -561,21 +582,47 @@ pub async fn check_compliance( config: &Config, owner: &str, repo: &str, +) -> Result { + check_compliance_at(config, owner, repo, None).await +} + +/// Check repository compliance, scanning the tree at `reference` (a commit SHA +/// or ref) for retired `.a2ml` files instead of the default branch. A push or +/// pull-request check passes the head it reports on, so a PR that adds an +/// `.a2ml` file fails and one that removes the last of them passes. +pub async fn check_compliance_at( + config: &Config, + owner: &str, + repo: &str, + reference: Option<&str>, ) -> Result { let client = GitHubClient::new(config); // Load repo-specific configuration let repo_config = load_repo_config(&client, owner, repo).await; - check_compliance_with_policy(config, owner, repo, &repo_config).await + check_compliance_with_policy_at(config, owner, repo, &repo_config, reference).await } -/// Check repository compliance with a specific policy configuration +/// Check repository compliance with a specific policy configuration, scanning +/// the default branch for retired `.a2ml` files. pub async fn check_compliance_with_policy( config: &Config, owner: &str, repo: &str, repo_config: &RepoConfig, +) -> Result { + check_compliance_with_policy_at(config, owner, repo, repo_config, None).await +} + +/// [`check_compliance_with_policy`], scanning the tree at `reference` (the +/// default branch when `None`) for retired `.a2ml` files. +pub async fn check_compliance_with_policy_at( + config: &Config, + owner: &str, + repo: &str, + repo_config: &RepoConfig, + reference: Option<&str>, ) -> Result { let client = GitHubClient::new(config); let policy = repo_config.policy; @@ -584,6 +631,7 @@ pub async fn check_compliance_with_policy( let mut total_score = 0u8; let mut max_score = 0u8; let mut required_passed = true; + let mut retired_a2ml: Vec = Vec::new(); // The chora deed holds the repo facts and the bot directives. A deed that // is present but does not read is an error, not "no directives". @@ -785,14 +833,23 @@ pub async fn check_compliance_with_policy( // Priority 1: any `.a2ml` file anywhere in the tree. A2ML is retired (D99, // D269c, D312, D313), so this is Required in every policy pack and a repo - // config can neither skip nor downgrade it. A tree that cannot be listed is - // reported as skipped with the reason, never as a pass. - match client.tree_paths(owner, repo).await { + // config can neither skip nor downgrade it. The tree scanned is the one at + // `reference` (the head a push or PR check reports on), else the default + // branch. A tree that cannot be listed FAILS the check, closed: an + // unknowable answer to a P1 question is not a pass. + let listing = match reference { + Some(reference) => client.tree_paths_at(owner, repo, reference).await, + None => client.tree_paths(owner, repo).await, + }; + match listing { Ok(paths) => { - let found: Vec<&String> = paths.iter().filter(|p| a2ml::is_a2ml(p)).collect(); + retired_a2ml = paths.into_iter().filter(|p| a2ml::is_a2ml(p)).collect(); + let found = &retired_a2ml; if !found.is_empty() { required_passed = false; - let shown: Vec<&str> = found.iter().take(10).map(|p| p.as_str()).collect(); + // A path is contributor-controlled and this message is rendered + // as Markdown in the check run: show it escaped, match it raw. + let shown: Vec = found.iter().take(10).map(|p| display_path(p)).collect(); let more = found.len().saturating_sub(shown.len()); checks.push(Check { name: A2ML_CHECK.to_string(), @@ -815,15 +872,21 @@ pub async fn check_compliance_with_policy( }); } } - Err(error) => checks.push(Check { - name: A2ML_CHECK.to_string(), - category: CheckCategory::Structure, - severity: Severity::Required, - status: CheckStatus::Skip, - points: 0, - max_points: 0, - message: format!("could not list the tree to look for .a2ml files: {error}"), - }), + Err(error) => { + required_passed = false; + checks.push(Check { + name: A2ML_CHECK.to_string(), + category: CheckCategory::Structure, + severity: Severity::Required, + status: CheckStatus::Fail, + points: 0, + max_points: 0, + message: format!( + "could not list the tree to look for .a2ml files, so the P1 check fails \ + closed: {error}" + ), + }); + } } // Check for workflow files @@ -1105,6 +1168,7 @@ pub async fn check_compliance_with_policy( required_passed, checks, summary, + retired_a2ml, }) } diff --git a/bots/rhodibot/src/webhook.rs b/bots/rhodibot/src/webhook.rs index c889e9ef..0eff0883 100644 --- a/bots/rhodibot/src/webhook.rs +++ b/bots/rhodibot/src/webhook.rs @@ -60,7 +60,7 @@ pub async fn handle_push(config: &Config, body: &str) -> Result<()> { // Run compliance check let client = GitHubClient::new(config); - let report = rsr::check_compliance(config, owner, repo_name).await?; + let report = rsr::check_compliance_at(config, owner, repo_name, Some(&event.after)).await?; // Create check run - fail if required checks didn't pass let conclusion = if !report.required_passed { @@ -115,7 +115,9 @@ pub async fn handle_pull_request(config: &Config, body: &str) -> Result<()> { // Run compliance check let client = GitHubClient::new(config); - let report = rsr::check_compliance(config, owner, repo_name).await?; + let report = + rsr::check_compliance_at(config, owner, repo_name, Some(&event.pull_request.head.sha)) + .await?; // Create check run - fail if required checks didn't pass let conclusion = if !report.required_passed { diff --git a/bots/rhodibot/tests/integration_tests.rs b/bots/rhodibot/tests/integration_tests.rs index 6d12b28d..2e793e32 100644 --- a/bots/rhodibot/tests/integration_tests.rs +++ b/bots/rhodibot/tests/integration_tests.rs @@ -120,6 +120,7 @@ mod rsr_tests { mount_file_mocks(&server, "test-org", "test-repo", files).await; mount_deed(&server, "(repo-deed :schema-version \"1.0.0\")").await; + mount_tree_only(&server, &[]).await; // Mock repository info with approved license Mock::given(method("GET")) @@ -568,6 +569,7 @@ mod rsr_tests { // Only README and LICENSE - minimal policy should be satisfied let files = &["README.adoc", "LICENSE"]; mount_file_mocks(&server, "test-org", "test-repo", files).await; + mount_tree_only(&server, &[]).await; Mock::given(method("GET")) .and(path("/repos/test-org/test-repo")) @@ -841,12 +843,24 @@ mod rsr_tests { ) .mount(server) .await; + mount_tree_only(server, paths).await; + } + + /// Serve the default branch's (`main`) tree, without the repository listing. + async fn mount_tree_only(server: &MockServer, paths: &[&str]) { + mount_tree_at(server, "main", paths).await; + } + + /// Serve the tree at one ref. + async fn mount_tree_at(server: &MockServer, reference: &str, paths: &[&str]) { let tree: Vec = paths .iter() .map(|p| serde_json::json!({ "path": p, "type": "blob" })) .collect(); Mock::given(method("GET")) - .and(path("/repos/test-org/test-repo/git/trees/main")) + .and(path(format!( + "/repos/test-org/test-repo/git/trees/{reference}" + ))) .respond_with( ResponseTemplate::new(200) .set_body_json(serde_json::json!({ "truncated": false, "tree": tree })), @@ -855,6 +869,43 @@ mod rsr_tests { .await; } + #[tokio::test] + async fn a_pull_request_check_scans_its_head_not_the_default_branch() { + // main is clean; the PR head adds an .a2ml file. The check reports on + // the head, so it must see the head's tree. + const HEAD: &str = "0123456789abcdef0123456789abcdef01234567"; + let server = MockServer::start().await; + let config = mock_config(&server.uri()); + mount_file_mocks(&server, "test-org", "test-repo", &[]).await; + mount_tree(&server, &["README.adoc"]).await; + mount_tree_at(&server, HEAD, &["README.adoc", "STATE.a2ml"]).await; + + let at_head = check_compliance_with_policy_at( + &config, + "test-org", + "test-repo", + &RepoConfig::default(), + Some(HEAD), + ) + .await + .expect("compliance check should succeed"); + let check = at_head + .checks + .iter() + .find(|c| c.name == A2ML_CHECK) + .expect("the head's .a2ml is found"); + assert_eq!(check.status, CheckStatus::Fail); + assert!(check.message.contains("STATE.a2ml"), "{}", check.message); + assert!(!at_head.required_passed); + + // Negative control: the same repository's default branch is clean. + let at_main = + check_compliance_with_policy(&config, "test-org", "test-repo", &RepoConfig::default()) + .await + .expect("compliance check should succeed"); + assert!(at_main.checks.iter().all(|c| c.name != A2ML_CHECK)); + } + async fn report_for_tree(paths: &[&str], policy: PolicyPack) -> ComplianceReport { let server = MockServer::start().await; let config = mock_config(&server.uri()); @@ -911,15 +962,18 @@ mod rsr_tests { } #[tokio::test] - async fn an_unlistable_tree_is_skipped_with_its_reason_never_passed() { - // No tree mock: the listing fails. - let report = check_with(&[], None, PolicyPack::Strict).await; + async fn an_unlistable_tree_fails_the_p1_check_closed() { + // No tree mock: the listing fails, and an unknowable answer to a P1 + // question is a failure, never a pass or a quiet skip. + let report = check_with(&[], None, PolicyPack::Minimal).await; let check = report .checks .iter() .find(|c| c.name == A2ML_CHECK) .expect("the check is reported"); - assert_eq!(check.status, CheckStatus::Skip); + assert_eq!(check.status, CheckStatus::Fail); + assert_eq!(check.severity, Severity::Required); + assert!(!report.required_passed); assert!( check.message.starts_with("could not list the tree"), "{}", @@ -1562,6 +1616,7 @@ mod report_tests { }, ], summary: "Partial RSR compliance (standard) - improvements needed".to_string(), + retired_a2ml: vec![], } } @@ -1714,9 +1769,67 @@ mod fleet_tests { }, ], summary: "RSR standard policy: Required checks failed".to_string(), + retired_a2ml: vec![], + } + } + + fn a2ml_check() -> Check { + Check { + name: A2ML_CHECK.to_string(), + category: CheckCategory::Structure, + severity: Severity::Required, + status: CheckStatus::Fail, + points: 0, + max_points: 0, + message: "P1: 2 retired .a2ml file(s) present".to_string(), } } + #[test] + fn each_retired_a2ml_is_its_own_finding_at_its_real_path() { + let mut report = sample_report_with_issues(); + report.checks = vec![a2ml_check()]; + report.retired_a2ml = vec![ + ".machine_readable/descriptiles/STATE.a2ml".to_string(), + "deep/x.A2ML".to_string(), + ]; + let findings = fleet::report_to_findings(&report); + let files: Vec = findings + .iter() + .map(|f| { + f.file + .as_ref() + .expect("a path") + .to_string_lossy() + .into_owned() + }) + .collect(); + assert_eq!(files, report.retired_a2ml); + assert_ne!(findings[0].id, findings[1].id, "distinct findings"); + assert!( + findings + .iter() + .all(|f| f.file.as_deref() != Some(std::path::Path::new("*.a2ml"))) + ); + } + + #[test] + fn an_unlisted_tree_is_one_fileless_a2ml_finding_never_a_wildcard() { + let mut report = sample_report_with_issues(); + report.checks = vec![a2ml_check()]; + let findings = fleet::report_to_findings(&report); + assert_eq!(findings.len(), 1); + assert!(findings[0].file.is_none()); + } + + #[test] + fn displayed_paths_cannot_forge_markdown() { + let shown = display_path("a\n## forged [x](http://e).a2ml"); + assert!(!shown.contains('\n'), "{shown}"); + assert!(!shown.contains("[x]"), "{shown}"); + assert!(!shown.contains('<'), "{shown}"); + } + #[test] fn test_findings_only_for_failures() { let report = sample_report_with_issues();