From af179f1b340a4e41becab1db32b8875d737b199d Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 15 Nov 2026 10:42:19 +0000 Subject: [PATCH] fix(rhodibot): take the rsr-profile key set from standards' module standards#1605 defines (rsr-profile ...) keys as :version :spec :declares-against :role :preset :capabilities :add :remove, with (notes ...) as the one nested clause (`deed_lint.js --rsr-profile-keys`). Drop the keys rhodibot had added for other clauses (:policy belongs to (anchor ...) and (egress ...), :omitted-rationale to (notes ...), :schema-version to none), and refuse symbols in :capabilities/:add/:remove, which the module requires to be strings. Tests pin the set, the refused keys, notes, and string-only lists. Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_0136P7ZmM7wgb8pXfyFEuRHQ --- bots/rhodibot/src/canon/report.rs | 4 +- bots/rhodibot/src/deed.rs | 100 ++++++++++++++++++++++++------ 2 files changed, 83 insertions(+), 21 deletions(-) diff --git a/bots/rhodibot/src/canon/report.rs b/bots/rhodibot/src/canon/report.rs index 9cfa1e5d..1f578414 100644 --- a/bots/rhodibot/src/canon/report.rs +++ b/bots/rhodibot/src/canon/report.rs @@ -943,7 +943,7 @@ mod tests { #[test] fn the_deed_profile_declares_capabilities() { - let deed = "(repo-deed (rsr-profile :capabilities (governance-tier)))"; + let deed = "(repo-deed (rsr-profile :capabilities (\"governance-tier\")))"; let report = report_for(&["widgets_chora.deed"], Some(deed), None); assert_eq!( report.declared_capabilities, @@ -953,7 +953,7 @@ mod tests { #[test] fn a_misspelt_deed_capability_is_refused() { - let deed = "(repo-deed (rsr-profile :capabilities (governence-tier)))"; + let deed = "(repo-deed (rsr-profile :capabilities (\"governence-tier\")))"; assert!( CanonReport::build_with( "acme/widgets", diff --git a/bots/rhodibot/src/deed.rs b/bots/rhodibot/src/deed.rs index ba8ddb90..26f32efc 100644 --- a/bots/rhodibot/src/deed.rs +++ b/bots/rhodibot/src/deed.rs @@ -129,26 +129,14 @@ impl Deed { let Some(clause) = self.clause("rsr-profile") else { return Ok(None); }; - const KEYS: &[&str] = &[ - ":preset", - ":capabilities", - ":add", - ":remove", - ":role", - ":spec", - ":declares-against", - ":policy", - ":omitted-rationale", - ":schema-version", - ":version", - ]; + let keys = RSR_PROFILE_KEYS; let members = clause.members(); for node in members { if let Node::Atom(atom) = node && atom.starts_with(':') { ensure!( - KEYS.contains(&atom.as_str()), + keys.contains(&atom.as_str()), "unknown key {atom} in (rsr-profile ...); a misspelt key would declare no \ capabilities and silently switch off every gated check" ); @@ -159,10 +147,12 @@ impl Deed { None => Ok(Vec::new()), Some(Node::List(items)) => items .iter() - .map(|item| { - item.text().map(str::to_string).ok_or_else(|| { - anyhow::anyhow!("(rsr-profile {key} ...) holds a nested list") - }) + .map(|item| match item { + Node::Str(text) => Ok(text.clone()), + _ => bail!( + "(rsr-profile {key} ...) holds a non-string; capabilities, :add \ + and :remove are lists of strings and symbols are refused" + ), }) .collect(), Some(_) => bail!("(rsr-profile {key} ...) must be a list"), @@ -195,6 +185,21 @@ impl Deed { } } +/// The top-level keys of `(rsr-profile ...)`, as the standards module defines +/// them (`bun 1-formats/deed/tools/deed_lint.js --rsr-profile-keys`, standards +/// #1605). `(notes ...)` is the one nested clause; it is not a key, and it holds +/// prose, so it is not scanned here. Any other key fails closed. +pub const RSR_PROFILE_KEYS: &[&str] = &[ + ":version", + ":spec", + ":declares-against", + ":role", + ":preset", + ":capabilities", + ":add", + ":remove", +]; + /// The `(rsr-profile ...)` clause, before it is checked against the gate table. #[derive(Debug, Clone, PartialEq, Eq, Default)] pub struct ProfileClause { @@ -366,7 +371,7 @@ mod tests { :repo-uuid #u8"gv-clade-index:github.com/o/r" ; trailing comment (meta :version "0.1.0") (anchor :id "x") - (rsr-profile :preset library :add (rust) :remove ()) + (rsr-profile :preset library :add ("rust") :remove ()) (bot-directives (bot :name panicbot :allow (assail)) (bot :name rhodibot (config :community-doc-format md)))) @@ -468,3 +473,60 @@ mod profile_shape_tests { assert!(empty.rsr_profile().is_err()); } } + +#[cfg(test)] +mod module_alignment_tests { + use super::*; + + /// The set standards' module reports (`deed_lint.js --rsr-profile-keys`). + #[test] + fn the_key_set_is_the_modules() { + assert_eq!( + RSR_PROFILE_KEYS, + [ + ":version", + ":spec", + ":declares-against", + ":role", + ":preset", + ":capabilities", + ":add", + ":remove" + ] + ); + } + + #[test] + fn keys_that_belong_to_other_clauses_are_refused() { + // :policy belongs to (anchor ...) and (egress ...); :omitted-rationale + // belongs inside (notes ...). + for key in [":policy", ":omitted-rationale", ":schema-version"] { + let deed = Deed::parse(&format!( + "(repo-deed (rsr-profile :capabilities (\"rust\") {key} \"x\"))" + )) + .unwrap(); + assert!(deed.rsr_profile().is_err(), "{key}"); + } + } + + #[test] + fn omitted_rationale_inside_notes_is_fine() { + let deed = Deed::parse( + "(repo-deed (rsr-profile :capabilities (\"rust\") (notes :omitted-rationale \"why\")))", + ) + .unwrap(); + assert!(deed.rsr_profile().unwrap().is_some()); + } + + #[test] + fn symbols_in_the_capability_lists_are_refused() { + for text in [ + "(repo-deed (rsr-profile :capabilities (rust)))", + "(repo-deed (rsr-profile :preset \"p\" :add (rust)))", + "(repo-deed (rsr-profile :preset \"p\" :remove (rust)))", + ] { + let deed = Deed::parse(text).unwrap(); + assert!(deed.rsr_profile().is_err(), "{text}"); + } + } +}