Skip to content

Commit e53ef2f

Browse files
fix(rhodibot): refuse unknown (rsr-profile) sub-clauses; read (layout …) (#687)
Follow-up to metadatastician/standards#1630 (owner ruling 2026-11-16, made while working on hyperpolymath/rsr-template-repo#421). That PR adds `(layout (module :gate "<row>" :at ("<path>" …)))` to `(rsr-profile …)`. ## What was wrong J39 (standards A7) says every reader of `(rsr-profile …)` fails closed on a key the standards module does not define. `Deed::rsr_profile` checked only `:keyword` atoms. Any sub-clause, known or not (`(extras …)`, now `(layout …)`), was skipped silently. A list after a scalar key, and a repeated key, also slipped through (Codex P1, fixed in e44f179). ## Change (`bots/rhodibot/src/deed.rs`) - Only a list after a list key (`:capabilities`, `:add`, `:remove`) is that key's value. Any other list is a sub-clause, and it must be one of `RSR_PROFILE_CLAUSES = ["notes", "layout"]`, each at most once. That is the order `deed_lint.js --rsr-profile-keys` prints them in. - Each key appears once, and its value is checked as the walk reaches it. A list key takes a list. Every other key takes one string or symbol, never a list, a following `:keyword`, or nothing. - `(layout …)` is read into `ProfileClause.layout`. This reader checks: - `:gate` is a non-empty string, and each gate appears once; - `:at` is a non-empty list of strings; - a module carries `:gate` and `:at` only, each once. Whether a gate names a real gate-table row, and what each path must be, stays with standards `check-rsr-profile.sh` and `deed_lint.js --rsr-profile`. - `rhodibot canon` does not score module paths, so its verdicts are unchanged. ## Evidence - `cargo test`: 249 passed (lib 179). `cargo fmt --check` and `cargo clippy --all-targets -- -D warnings` are clean. - Mutation check: replacing the sub-clause refusal with `true` fails `an_unknown_sub_clause_is_refused_not_skipped`. - `a_list_after_a_scalar_key_is_refused` and `a_list_key_takes_a_list_value` fail before e44f179 and pass after it. - `rhodibot canon --path` on rsr-template-repo branch `claude/determined-fermi-h8ojbr`, whose deed carries `(layout)`: reads the profile, 12 declared capabilities. On standards: unchanged, 5 declared. - CI on e44f179: all green. ## Merge order Any order is safe. This accepts `(layout)` with or without standards#1630, and it refuses only sub-clauses that the old and new standards modules both refuse. ## Follow-up: moved - **rhodibot still scores retired `.a2ml` paths** (11 high-severity findings on hyperpolymath/echo-types#378). **Moved.** The owner made `.a2ml` retirement a priority-1, bot-driven task through kyX (D313). That task now belongs to the session "gitbot-fleet: fix red main + P1 auto-retire .a2ml via kyX", including reversing rhodibot's `.a2ml` expectation. This PR stays limited to deed-clause reading. Leads handed over: - `bots/rhodibot/canon/rsr-criteria-v2.a2ml` still names `.a2ml` paths; - `src/canon/overlay.rs` has no deed form for CLADE (3.1.9); - `src/canon/local.rs` keeps the legacy `rsr-profile.a2ml` read fallback. --- _Generated by [Claude Code](https://claude.ai/code/session_01J4QvDhtp4kVy7MGgY47YB3)_ <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit * **New Features** * Profiles can now include layout bindings that associate a named gate with one or more paths. * **Bug Fixes** * Profile data is checked more strictly: duplicate entries, invalid value types, unknown clauses, and incomplete or malformed layouts are rejected. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 7907099 commit e53ef2f

1 file changed

Lines changed: 226 additions & 3 deletions

File tree

‎bots/rhodibot/src/deed.rs‎

Lines changed: 226 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,10 @@ impl Deed {
131131
};
132132
let keys = RSR_PROFILE_KEYS;
133133
let members = clause.members();
134-
for node in members {
134+
let mut seen_clauses = BTreeSet::new();
135+
let mut seen_keys = BTreeSet::new();
136+
let mut layout = Vec::new();
137+
for (index, node) in members.iter().enumerate() {
135138
if let Node::Atom(atom) = node
136139
&& atom.starts_with(':')
137140
{
@@ -140,6 +143,49 @@ impl Deed {
140143
"unknown key {atom} in (rsr-profile ...); a misspelt key would declare no \
141144
capabilities and silently switch off every gated check"
142145
);
146+
ensure!(
147+
seen_keys.insert(atom.clone()),
148+
"(rsr-profile ...) carries {atom} once; a second one would be ignored"
149+
);
150+
// Each key's value has its kind: a list for the list keys, a
151+
// single value for the rest. A list after a scalar key is
152+
// neither its value nor a sub-clause to skip.
153+
let value = members.get(index + 1);
154+
if RSR_PROFILE_LIST_KEYS.contains(&atom.as_str()) {
155+
ensure!(
156+
matches!(value, Some(Node::List(_))),
157+
"(rsr-profile {atom} ...) must be a list"
158+
);
159+
} else {
160+
ensure!(
161+
matches!(value, Some(Node::Str(_) | Node::Atom(_)))
162+
&& !matches!(value, Some(Node::Atom(next)) if next.starts_with(':')),
163+
"(rsr-profile {atom} ...) takes one value, not a list or nothing"
164+
);
165+
}
166+
}
167+
// Only a list key's value is exempt; any other list is a
168+
// sub-clause, and J39 refuses one it does not know rather than
169+
// skipping it.
170+
let is_value = index > 0
171+
&& matches!(&members[index - 1], Node::Atom(atom)
172+
if RSR_PROFILE_LIST_KEYS.contains(&atom.as_str()));
173+
if let Node::List(_) = node
174+
&& !is_value
175+
{
176+
let head = node.head().unwrap_or("");
177+
ensure!(
178+
RSR_PROFILE_CLAUSES.contains(&head),
179+
"unknown clause ({head} ...) in (rsr-profile ...); J39 refuses a sub-clause \
180+
the standards module does not define"
181+
);
182+
ensure!(
183+
seen_clauses.insert(head.to_string()),
184+
"(rsr-profile ...) carries ({head} ...) once"
185+
);
186+
if head == "layout" {
187+
layout = layout_bindings(node)?;
188+
}
143189
}
144190
}
145191
let list = |key: &str| -> Result<Vec<String>> {
@@ -172,6 +218,7 @@ impl Deed {
172218
add: list(":add")?,
173219
remove: list(":remove")?,
174220
role: word(":role"),
221+
layout,
175222
}))
176223
}
177224

@@ -185,10 +232,73 @@ impl Deed {
185232
}
186233
}
187234

235+
/// The members of `(rsr-profile (layout ...))`: one or more
236+
/// `(module :gate "<row>" :at ("<path>" ...))` (standards rsr-profile.abnf
237+
/// v1.1.0, owner ruling 2026-11-16). This reader checks the shape and keys;
238+
/// whether a gate names a real row, and what each path must be, is standards'
239+
/// `check-rsr-profile.sh` and `deed_lint.js --rsr-profile`.
240+
fn layout_bindings(layout: &Node) -> Result<Vec<LayoutBinding>> {
241+
let modules = layout.members();
242+
ensure!(
243+
!modules.is_empty(),
244+
"(rsr-profile (layout ...)) binds at least one (module ...)"
245+
);
246+
let mut out: Vec<LayoutBinding> = Vec::new();
247+
for module in modules {
248+
ensure!(
249+
module.head() == Some("module"),
250+
"(rsr-profile (layout ...)) holds (module ...) clauses only (J39)"
251+
);
252+
let members = module.members();
253+
let mut index = 0;
254+
let (mut gate, mut at) = (None, None);
255+
while index < members.len() {
256+
let key = match &members[index] {
257+
Node::Atom(atom) if RSR_PROFILE_LAYOUT_KEYS.contains(&atom.as_str()) => atom,
258+
other => bail!(
259+
"(rsr-profile (layout (module ...))) holds :gate and :at only, not {other:?} \
260+
(J39)"
261+
),
262+
};
263+
let value = members.get(index + 1);
264+
match (key.as_str(), value) {
265+
(":gate", Some(Node::Str(text))) if !text.is_empty() => {
266+
ensure!(gate.is_none(), "(layout (module ...)) carries :gate once");
267+
gate = Some(text.clone());
268+
}
269+
(":at", Some(Node::List(items)))
270+
if !items.is_empty() && items.iter().all(|i| matches!(i, Node::Str(_))) =>
271+
{
272+
ensure!(at.is_none(), "(layout (module ...)) carries :at once");
273+
at = Some(
274+
items
275+
.iter()
276+
.filter_map(Node::text)
277+
.map(str::to_string)
278+
.collect::<Vec<_>>(),
279+
);
280+
}
281+
(":gate", _) => bail!("(layout (module :gate ...)) must be a non-empty string"),
282+
_ => bail!("(layout (module :at ...)) must be a non-empty list of strings"),
283+
}
284+
index += 2;
285+
}
286+
let gate = gate.ok_or_else(|| anyhow::anyhow!("(layout (module ...)) is missing :gate"))?;
287+
let at = at.ok_or_else(|| anyhow::anyhow!("(layout (module ...)) is missing :at"))?;
288+
ensure!(
289+
out.iter().all(|binding| binding.gate != gate),
290+
"(rsr-profile (layout ...)) binds :gate \"{gate}\" once"
291+
);
292+
out.push(LayoutBinding { gate, at });
293+
}
294+
Ok(out)
295+
}
296+
188297
/// The top-level keys of `(rsr-profile ...)`, as the standards module defines
189298
/// them (`bun 1-formats/deed/tools/deed_lint.js --rsr-profile-keys`, standards
190-
/// #1605). `(notes ...)` is the one nested clause; it is not a key, and it holds
191-
/// prose, so it is not scanned here. Any other key fails closed.
299+
/// #1605, #1630). `(notes ...)` and `(layout ...)` are its sub-clauses
300+
/// ([`RSR_PROFILE_CLAUSES`]); `(notes ...)` holds prose, so it is not scanned
301+
/// here. Any other key or sub-clause fails closed.
192302
pub const RSR_PROFILE_KEYS: &[&str] = &[
193303
":version",
194304
":spec",
@@ -200,6 +310,25 @@ pub const RSR_PROFILE_KEYS: &[&str] = &[
200310
":remove",
201311
];
202312

313+
/// The keys of [`RSR_PROFILE_KEYS`] whose value is a list of strings; the
314+
/// rest take one string (standards rsr-profile.abnf).
315+
pub const RSR_PROFILE_LIST_KEYS: &[&str] = &[":capabilities", ":add", ":remove"];
316+
317+
/// The sub-clauses of `(rsr-profile ...)`, in the order
318+
/// `deed_lint.js --rsr-profile-keys` prints them after the keys.
319+
pub const RSR_PROFILE_CLAUSES: &[&str] = &["notes", "layout"];
320+
321+
/// The keys of a `(layout (module ...))` binding.
322+
pub const RSR_PROFILE_LAYOUT_KEYS: &[&str] = &[":gate", ":at"];
323+
324+
/// One `(module :gate ... :at ...)` of `(rsr-profile (layout ...))`: where this
325+
/// repository keeps the module a gate-table row asks for.
326+
#[derive(Debug, Clone, PartialEq, Eq)]
327+
pub struct LayoutBinding {
328+
pub gate: String,
329+
pub at: Vec<String>,
330+
}
331+
203332
/// The `(rsr-profile ...)` clause, before it is checked against the gate table.
204333
#[derive(Debug, Clone, PartialEq, Eq, Default)]
205334
pub struct ProfileClause {
@@ -208,6 +337,8 @@ pub struct ProfileClause {
208337
pub add: Vec<String>,
209338
pub remove: Vec<String>,
210339
pub role: Option<String>,
340+
/// The `(layout ...)` bindings, in order; empty when there is none.
341+
pub layout: Vec<LayoutBinding>,
211342
}
212343

213344
/// One `(bot :name ...)` entry of the `(bot-directives ...)` clause.
@@ -518,6 +649,98 @@ mod module_alignment_tests {
518649
assert!(deed.rsr_profile().unwrap().is_some());
519650
}
520651

652+
/// The sub-clauses standards' module reports after the keys.
653+
#[test]
654+
fn the_clause_set_is_the_modules() {
655+
assert_eq!(RSR_PROFILE_CLAUSES, ["notes", "layout"]);
656+
assert_eq!(RSR_PROFILE_LAYOUT_KEYS, [":gate", ":at"]);
657+
}
658+
659+
#[test]
660+
fn an_unknown_sub_clause_is_refused_not_skipped() {
661+
let deed =
662+
Deed::parse("(repo-deed (rsr-profile :capabilities (\"rust\") (extras :x \"y\")))")
663+
.unwrap();
664+
let err = deed.rsr_profile().unwrap_err().to_string();
665+
assert!(err.contains("unknown clause (extras"), "{err}");
666+
}
667+
668+
/// A list after a scalar key is neither that key's value nor a sub-clause
669+
/// to skip: `:preset (extras ...)` once read as a missing preset and
670+
/// switched every gated check off (Codex on #687).
671+
#[test]
672+
fn a_list_after_a_scalar_key_is_refused() {
673+
for key in [":version", ":spec", ":declares-against", ":role", ":preset"] {
674+
let deed = Deed::parse(&format!(
675+
"(repo-deed (rsr-profile :capabilities (\"rust\") {key} (extras :x \"y\")))"
676+
))
677+
.unwrap();
678+
assert!(deed.rsr_profile().is_err(), "{key}");
679+
}
680+
let deed = Deed::parse("(repo-deed (rsr-profile :preset (extras :x \"y\")))").unwrap();
681+
assert!(deed.rsr_profile().is_err());
682+
}
683+
684+
#[test]
685+
fn a_list_key_takes_a_list_value() {
686+
for key in [":capabilities", ":add", ":remove"] {
687+
let deed = Deed::parse(&format!(
688+
"(repo-deed (rsr-profile :preset \"p\" :capabilities (\"rust\") {key} \"rust\"))"
689+
))
690+
.unwrap();
691+
assert!(deed.rsr_profile().is_err(), "{key}");
692+
}
693+
}
694+
695+
#[test]
696+
fn a_list_value_after_a_key_is_not_a_sub_clause() {
697+
// ("rust") follows :capabilities, so it is that field's value.
698+
let deed = Deed::parse("(repo-deed (rsr-profile :capabilities (\"rust\")))").unwrap();
699+
assert!(deed.rsr_profile().unwrap().is_some());
700+
}
701+
702+
#[test]
703+
fn the_template_layout_binding_is_read() {
704+
let deed = Deed::parse(
705+
"(repo-deed (rsr-profile :version \"1.0.0\" :role \"spine\" \
706+
:capabilities (\"abi\") \
707+
(layout (module :gate \"abi.ipkg\" :at (\"src/interface/abi.ipkg\"))) \
708+
(notes :omitted-rationale \"x\")))",
709+
)
710+
.unwrap();
711+
let clause = deed.rsr_profile().unwrap().unwrap();
712+
assert_eq!(
713+
clause.layout,
714+
vec![LayoutBinding {
715+
gate: "abi.ipkg".into(),
716+
at: vec!["src/interface/abi.ipkg".into()]
717+
}]
718+
);
719+
}
720+
721+
#[test]
722+
fn malformed_layouts_are_refused() {
723+
for body in [
724+
"(layout)",
725+
"(layout :gate \"abi.ipkg\")",
726+
"(layout (path :gate \"abi.ipkg\" :at (\"a/abi.ipkg\")))",
727+
"(layout (module :gate \"abi.ipkg\" :at (\"a/abi.ipkg\") :why \"x\"))",
728+
"(layout (module :at (\"a/abi.ipkg\")))",
729+
"(layout (module :gate \"abi.ipkg\"))",
730+
"(layout (module :gate \"abi.ipkg\" :at ()))",
731+
"(layout (module :gate \"abi.ipkg\" :at \"a/abi.ipkg\"))",
732+
"(layout (module :gate abi :at (\"a/abi.ipkg\")))",
733+
"(layout (module :gate \"abi.ipkg\" :at (\"a\")) (module :gate \"abi.ipkg\" :at (\"b\")))",
734+
"(layout (module :gate \"a\" :at (\"a\"))) (layout (module :gate \"b\" :at (\"b\")))",
735+
] {
736+
let deed = Deed::parse(&format!(
737+
"(repo-deed (rsr-profile :capabilities (\"abi\") {body}))"
738+
))
739+
.unwrap();
740+
assert!(deed.rsr_profile().is_err(), "{body}");
741+
}
742+
}
743+
521744
#[test]
522745
fn symbols_in_the_capability_lists_are_refused() {
523746
for text in [

0 commit comments

Comments
 (0)