From 418ccfa82ce96e5f0860f5ea55fd063614311229 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 17 Nov 2026 00:16:23 +0000 Subject: [PATCH 1/2] =?UTF-8?q?fix(rhodibot):=20refuse=20unknown=20(rsr-pr?= =?UTF-8?q?ofile)=20sub-clauses;=20read=20(layout=20=E2=80=A6)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit J39 (standards A7) says every reader of (rsr-profile …) fails closed on a key the standards module does not define. rhodibot checked :keyword atoms only, so an unknown sub-clause such as (extras …) was skipped silently. * A list that does not follow a :keyword is a sub-clause, and must be one of RSR_PROFILE_CLAUSES = ["notes", "layout"], each at most once (deed_lint.js --rsr-profile-keys order, metadatastician/standards#1630). * (layout (module :gate "" :at ("" …))) is read into ProfileClause.layout. Its shape and keys are checked here (non-empty string :gate, non-empty string-list :at, :gate and :at only and once, each gate once); whether a gate names a real gate-table row, and what a path must be, stays with standards check-rsr-profile.sh. rhodibot's canon command does not score module paths, so its verdicts are unchanged. Tests: clause set pinned to the module's, unknown sub-clause refused, a list value after a key is not a sub-clause, the template's binding is read, eleven malformed layouts refused. cargo test (247), fmt, clippy -D warnings clean; removing the refusal fails the new test. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01J4QvDhtp4kVy7MGgY47YB3 --- bots/rhodibot/src/deed.rs | 176 +++++++++++++++++++++++++++++++++++++- 1 file changed, 173 insertions(+), 3 deletions(-) diff --git a/bots/rhodibot/src/deed.rs b/bots/rhodibot/src/deed.rs index 26f32efc..46586da3 100644 --- a/bots/rhodibot/src/deed.rs +++ b/bots/rhodibot/src/deed.rs @@ -131,7 +131,9 @@ impl Deed { }; let keys = RSR_PROFILE_KEYS; let members = clause.members(); - for node in members { + let mut seen_clauses = BTreeSet::new(); + let mut layout = Vec::new(); + for (index, node) in members.iter().enumerate() { if let Node::Atom(atom) = node && atom.starts_with(':') { @@ -141,6 +143,28 @@ impl Deed { capabilities and silently switch off every gated check" ); } + // A list right after a :keyword is that field's value. Any other + // list is a sub-clause, and J39 refuses one it does not know + // rather than skipping it. + let is_value = index > 0 + && matches!(&members[index - 1], Node::Atom(atom) if atom.starts_with(':')); + if let Node::List(_) = node + && !is_value + { + let head = node.head().unwrap_or(""); + ensure!( + RSR_PROFILE_CLAUSES.contains(&head), + "unknown clause ({head} ...) in (rsr-profile ...); J39 refuses a sub-clause \ + the standards module does not define" + ); + ensure!( + seen_clauses.insert(head.to_string()), + "(rsr-profile ...) carries ({head} ...) once" + ); + if head == "layout" { + layout = layout_bindings(node)?; + } + } } let list = |key: &str| -> Result> { match clause.field(key) { @@ -172,6 +196,7 @@ impl Deed { add: list(":add")?, remove: list(":remove")?, role: word(":role"), + layout, })) } @@ -185,10 +210,73 @@ impl Deed { } } +/// The members of `(rsr-profile (layout ...))`: one or more +/// `(module :gate "" :at ("" ...))` (standards rsr-profile.abnf +/// v1.1.0, owner ruling 2026-11-16). This reader checks the shape and keys; +/// whether a gate names a real row, and what each path must be, is standards' +/// `check-rsr-profile.sh` and `deed_lint.js --rsr-profile`. +fn layout_bindings(layout: &Node) -> Result> { + let modules = layout.members(); + ensure!( + !modules.is_empty(), + "(rsr-profile (layout ...)) binds at least one (module ...)" + ); + let mut out: Vec = Vec::new(); + for module in modules { + ensure!( + module.head() == Some("module"), + "(rsr-profile (layout ...)) holds (module ...) clauses only (J39)" + ); + let members = module.members(); + let mut index = 0; + let (mut gate, mut at) = (None, None); + while index < members.len() { + let key = match &members[index] { + Node::Atom(atom) if RSR_PROFILE_LAYOUT_KEYS.contains(&atom.as_str()) => atom, + other => bail!( + "(rsr-profile (layout (module ...))) holds :gate and :at only, not {other:?} \ + (J39)" + ), + }; + let value = members.get(index + 1); + match (key.as_str(), value) { + (":gate", Some(Node::Str(text))) if !text.is_empty() => { + ensure!(gate.is_none(), "(layout (module ...)) carries :gate once"); + gate = Some(text.clone()); + } + (":at", Some(Node::List(items))) + if !items.is_empty() && items.iter().all(|i| matches!(i, Node::Str(_))) => + { + ensure!(at.is_none(), "(layout (module ...)) carries :at once"); + at = Some( + items + .iter() + .filter_map(Node::text) + .map(str::to_string) + .collect::>(), + ); + } + (":gate", _) => bail!("(layout (module :gate ...)) must be a non-empty string"), + _ => bail!("(layout (module :at ...)) must be a non-empty list of strings"), + } + index += 2; + } + let gate = gate.ok_or_else(|| anyhow::anyhow!("(layout (module ...)) is missing :gate"))?; + let at = at.ok_or_else(|| anyhow::anyhow!("(layout (module ...)) is missing :at"))?; + ensure!( + out.iter().all(|binding| binding.gate != gate), + "(rsr-profile (layout ...)) binds :gate \"{gate}\" once" + ); + out.push(LayoutBinding { gate, at }); + } + Ok(out) +} + /// 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. +/// #1605, #1630). `(notes ...)` and `(layout ...)` are its sub-clauses +/// ([`RSR_PROFILE_CLAUSES`]); `(notes ...)` holds prose, so it is not scanned +/// here. Any other key or sub-clause fails closed. pub const RSR_PROFILE_KEYS: &[&str] = &[ ":version", ":spec", @@ -200,6 +288,21 @@ pub const RSR_PROFILE_KEYS: &[&str] = &[ ":remove", ]; +/// The sub-clauses of `(rsr-profile ...)`, in the order +/// `deed_lint.js --rsr-profile-keys` prints them after the keys. +pub const RSR_PROFILE_CLAUSES: &[&str] = &["notes", "layout"]; + +/// The keys of a `(layout (module ...))` binding. +pub const RSR_PROFILE_LAYOUT_KEYS: &[&str] = &[":gate", ":at"]; + +/// One `(module :gate ... :at ...)` of `(rsr-profile (layout ...))`: where this +/// repository keeps the module a gate-table row asks for. +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct LayoutBinding { + pub gate: String, + pub at: Vec, +} + /// The `(rsr-profile ...)` clause, before it is checked against the gate table. #[derive(Debug, Clone, PartialEq, Eq, Default)] pub struct ProfileClause { @@ -208,6 +311,8 @@ pub struct ProfileClause { pub add: Vec, pub remove: Vec, pub role: Option, + /// The `(layout ...)` bindings, in order; empty when there is none. + pub layout: Vec, } /// One `(bot :name ...)` entry of the `(bot-directives ...)` clause. @@ -518,6 +623,71 @@ mod module_alignment_tests { assert!(deed.rsr_profile().unwrap().is_some()); } + /// The sub-clauses standards' module reports after the keys. + #[test] + fn the_clause_set_is_the_modules() { + assert_eq!(RSR_PROFILE_CLAUSES, ["notes", "layout"]); + assert_eq!(RSR_PROFILE_LAYOUT_KEYS, [":gate", ":at"]); + } + + #[test] + fn an_unknown_sub_clause_is_refused_not_skipped() { + let deed = + Deed::parse("(repo-deed (rsr-profile :capabilities (\"rust\") (extras :x \"y\")))") + .unwrap(); + let err = deed.rsr_profile().unwrap_err().to_string(); + assert!(err.contains("unknown clause (extras"), "{err}"); + } + + #[test] + fn a_list_value_after_a_key_is_not_a_sub_clause() { + // ("rust") follows :capabilities, so it is that field's value. + let deed = Deed::parse("(repo-deed (rsr-profile :capabilities (\"rust\")))").unwrap(); + assert!(deed.rsr_profile().unwrap().is_some()); + } + + #[test] + fn the_template_layout_binding_is_read() { + let deed = Deed::parse( + "(repo-deed (rsr-profile :version \"1.0.0\" :role \"spine\" \ + :capabilities (\"abi\") \ + (layout (module :gate \"abi.ipkg\" :at (\"src/interface/abi.ipkg\"))) \ + (notes :omitted-rationale \"x\")))", + ) + .unwrap(); + let clause = deed.rsr_profile().unwrap().unwrap(); + assert_eq!( + clause.layout, + vec![LayoutBinding { + gate: "abi.ipkg".into(), + at: vec!["src/interface/abi.ipkg".into()] + }] + ); + } + + #[test] + fn malformed_layouts_are_refused() { + for body in [ + "(layout)", + "(layout :gate \"abi.ipkg\")", + "(layout (path :gate \"abi.ipkg\" :at (\"a/abi.ipkg\")))", + "(layout (module :gate \"abi.ipkg\" :at (\"a/abi.ipkg\") :why \"x\"))", + "(layout (module :at (\"a/abi.ipkg\")))", + "(layout (module :gate \"abi.ipkg\"))", + "(layout (module :gate \"abi.ipkg\" :at ()))", + "(layout (module :gate \"abi.ipkg\" :at \"a/abi.ipkg\"))", + "(layout (module :gate abi :at (\"a/abi.ipkg\")))", + "(layout (module :gate \"abi.ipkg\" :at (\"a\")) (module :gate \"abi.ipkg\" :at (\"b\")))", + "(layout (module :gate \"a\" :at (\"a\"))) (layout (module :gate \"b\" :at (\"b\")))", + ] { + let deed = Deed::parse(&format!( + "(repo-deed (rsr-profile :capabilities (\"abi\") {body}))" + )) + .unwrap(); + assert!(deed.rsr_profile().is_err(), "{body}"); + } + } + #[test] fn symbols_in_the_capability_lists_are_refused() { for text in [ From e44f1790ba231842659a2620f8c9f001171d1a86 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 17 Nov 2026 00:53:32 +0000 Subject: [PATCH 2/2] fix(rhodibot): check each (rsr-profile) key's value kind and uniqueness Codex on #687 (P1): the sub-clause check exempted any list that followed a :keyword, so (rsr-profile :preset (extras :x "y")) passed. The list satisfied the :capabilities-or-:preset requirement, word(":preset") turned it into None, and the profile resolved to no capabilities, switching every gated check off. * Only a list after a list key (:capabilities, :add, :remove) is a value; any other list is a sub-clause and must be (notes) or (layout). * A list key must take a list; every other key takes one string or symbol, never a list, a following :keyword or nothing. * Each key appears once: field() read only the first, so a second :capabilities was silently ignored. Tests: a_list_after_a_scalar_key_is_refused and a_list_key_takes_a_list_value both failed before this change and pass after. cargo test 249, fmt, clippy -D warnings clean; the template and standards deeds still resolve to 12 and 5 declared capabilities. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01J4QvDhtp4kVy7MGgY47YB3 --- bots/rhodibot/src/deed.rs | 61 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 57 insertions(+), 4 deletions(-) diff --git a/bots/rhodibot/src/deed.rs b/bots/rhodibot/src/deed.rs index 46586da3..65688c76 100644 --- a/bots/rhodibot/src/deed.rs +++ b/bots/rhodibot/src/deed.rs @@ -132,6 +132,7 @@ impl Deed { let keys = RSR_PROFILE_KEYS; let members = clause.members(); let mut seen_clauses = BTreeSet::new(); + let mut seen_keys = BTreeSet::new(); let mut layout = Vec::new(); for (index, node) in members.iter().enumerate() { if let Node::Atom(atom) = node @@ -142,12 +143,33 @@ impl Deed { "unknown key {atom} in (rsr-profile ...); a misspelt key would declare no \ capabilities and silently switch off every gated check" ); + ensure!( + seen_keys.insert(atom.clone()), + "(rsr-profile ...) carries {atom} once; a second one would be ignored" + ); + // Each key's value has its kind: a list for the list keys, a + // single value for the rest. A list after a scalar key is + // neither its value nor a sub-clause to skip. + let value = members.get(index + 1); + if RSR_PROFILE_LIST_KEYS.contains(&atom.as_str()) { + ensure!( + matches!(value, Some(Node::List(_))), + "(rsr-profile {atom} ...) must be a list" + ); + } else { + ensure!( + matches!(value, Some(Node::Str(_) | Node::Atom(_))) + && !matches!(value, Some(Node::Atom(next)) if next.starts_with(':')), + "(rsr-profile {atom} ...) takes one value, not a list or nothing" + ); + } } - // A list right after a :keyword is that field's value. Any other - // list is a sub-clause, and J39 refuses one it does not know - // rather than skipping it. + // Only a list key's value is exempt; any other list is a + // sub-clause, and J39 refuses one it does not know rather than + // skipping it. let is_value = index > 0 - && matches!(&members[index - 1], Node::Atom(atom) if atom.starts_with(':')); + && matches!(&members[index - 1], Node::Atom(atom) + if RSR_PROFILE_LIST_KEYS.contains(&atom.as_str())); if let Node::List(_) = node && !is_value { @@ -288,6 +310,10 @@ pub const RSR_PROFILE_KEYS: &[&str] = &[ ":remove", ]; +/// The keys of [`RSR_PROFILE_KEYS`] whose value is a list of strings; the +/// rest take one string (standards rsr-profile.abnf). +pub const RSR_PROFILE_LIST_KEYS: &[&str] = &[":capabilities", ":add", ":remove"]; + /// The sub-clauses of `(rsr-profile ...)`, in the order /// `deed_lint.js --rsr-profile-keys` prints them after the keys. pub const RSR_PROFILE_CLAUSES: &[&str] = &["notes", "layout"]; @@ -639,6 +665,33 @@ mod module_alignment_tests { assert!(err.contains("unknown clause (extras"), "{err}"); } + /// A list after a scalar key is neither that key's value nor a sub-clause + /// to skip: `:preset (extras ...)` once read as a missing preset and + /// switched every gated check off (Codex on #687). + #[test] + fn a_list_after_a_scalar_key_is_refused() { + for key in [":version", ":spec", ":declares-against", ":role", ":preset"] { + let deed = Deed::parse(&format!( + "(repo-deed (rsr-profile :capabilities (\"rust\") {key} (extras :x \"y\")))" + )) + .unwrap(); + assert!(deed.rsr_profile().is_err(), "{key}"); + } + let deed = Deed::parse("(repo-deed (rsr-profile :preset (extras :x \"y\")))").unwrap(); + assert!(deed.rsr_profile().is_err()); + } + + #[test] + fn a_list_key_takes_a_list_value() { + for key in [":capabilities", ":add", ":remove"] { + let deed = Deed::parse(&format!( + "(repo-deed (rsr-profile :preset \"p\" :capabilities (\"rust\") {key} \"rust\"))" + )) + .unwrap(); + assert!(deed.rsr_profile().is_err(), "{key}"); + } + } + #[test] fn a_list_value_after_a_key_is_not_a_sub_clause() { // ("rust") follows :capabilities, so it is that field's value.