Skip to content

Commit 5a770ad

Browse files
fstandhartingerclaude
andcommitted
rustfmt the RLM code
The chutes-rlm crate was written without a compiler in the loop and never went through rustfmt; this brings it and the new core modules in line with the workspace style so the next diff is about behaviour rather than whitespace. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 9834914 commit 5a770ad

12 files changed

Lines changed: 358 additions & 107 deletions

File tree

codex-rs/chutes-rlm/src/harness.rs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,12 @@ pub enum HarnessError {
110110
and are capped at {cap} bytes. Shorten it, or make it a skill instead — skill bodies are \
111111
only loaded when you ask for them."
112112
)]
113-
TooLarge { kind: &'static str, name: String, actual: usize, cap: usize },
113+
TooLarge {
114+
kind: &'static str,
115+
name: String,
116+
actual: usize,
117+
cap: usize,
118+
},
114119
}
115120

116121
/// A two-layer harness store. Project entries shadow global ones by name.
@@ -122,7 +127,10 @@ pub struct Harness {
122127

123128
impl Harness {
124129
pub fn new(global_root: PathBuf, project_root: Option<PathBuf>) -> Self {
125-
Self { global_root, project_root }
130+
Self {
131+
global_root,
132+
project_root,
133+
}
126134
}
127135

128136
fn root(&self, scope: Scope) -> Option<&Path> {
@@ -279,15 +287,22 @@ impl Harness {
279287
)
280288
}
281289

282-
pub fn delete(&self, kind: Kind, name: &str, scope: Option<Scope>) -> Result<bool, HarnessError> {
290+
pub fn delete(
291+
&self,
292+
kind: Kind,
293+
name: &str,
294+
scope: Option<Scope>,
295+
) -> Result<bool, HarnessError> {
283296
validate_name(name)?;
284297
let scopes = match scope {
285298
Some(s) => vec![s],
286299
None => vec![Scope::Project, Scope::Global],
287300
};
288301
let mut removed = false;
289302
for s in scopes {
290-
let Some(path) = self.path_for(kind, name, s) else { continue };
303+
let Some(path) = self.path_for(kind, name, s) else {
304+
continue;
305+
};
291306
if !path.exists() {
292307
continue;
293308
}

codex-rs/chutes-rlm/src/harness_tests.rs

Lines changed: 122 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ use tempfile::TempDir;
55
fn harness() -> (TempDir, TempDir, Harness) {
66
let global = TempDir::new().unwrap();
77
let project = TempDir::new().unwrap();
8-
let h = Harness::new(global.path().to_path_buf(), Some(project.path().to_path_buf()));
8+
let h = Harness::new(
9+
global.path().to_path_buf(),
10+
Some(project.path().to_path_buf()),
11+
);
912
(global, project, h)
1013
}
1114

@@ -16,18 +19,34 @@ fn no_meta() -> BTreeMap<String, String> {
1619
#[test]
1720
fn create_then_get_round_trips() {
1821
let (_g, _p, h) = harness();
19-
h.create(Kind::Memory, "flaky-test", "retry three times", "", Scope::Global, &no_meta())
20-
.unwrap();
21-
let got = h.get(Kind::Memory, "flaky-test").expect("entry should exist");
22+
h.create(
23+
Kind::Memory,
24+
"flaky-test",
25+
"retry three times",
26+
"",
27+
Scope::Global,
28+
&no_meta(),
29+
)
30+
.unwrap();
31+
let got = h
32+
.get(Kind::Memory, "flaky-test")
33+
.expect("entry should exist");
2234
assert_eq!(got.body.trim(), "retry three times");
2335
assert_eq!(got.scope, Scope::Global);
2436
}
2537

2638
#[test]
2739
fn description_survives_front_matter() {
2840
let (_g, _p, h) = harness();
29-
h.create(Kind::Skill, "release", "1. bump\n2. tag", "cut a release", Scope::Global, &no_meta())
30-
.unwrap();
41+
h.create(
42+
Kind::Skill,
43+
"release",
44+
"1. bump\n2. tag",
45+
"cut a release",
46+
Scope::Global,
47+
&no_meta(),
48+
)
49+
.unwrap();
3150
let got = h.get(Kind::Skill, "release").unwrap();
3251
assert_eq!(got.description, "cut a release");
3352
assert_eq!(got.body.trim(), "1. bump\n2. tag");
@@ -36,8 +55,24 @@ fn description_survives_front_matter() {
3655
#[test]
3756
fn project_shadows_global_by_name() {
3857
let (_g, _p, h) = harness();
39-
h.create(Kind::Note, "style", "global style", "", Scope::Global, &no_meta()).unwrap();
40-
h.create(Kind::Note, "style", "project style", "", Scope::Project, &no_meta()).unwrap();
58+
h.create(
59+
Kind::Note,
60+
"style",
61+
"global style",
62+
"",
63+
Scope::Global,
64+
&no_meta(),
65+
)
66+
.unwrap();
67+
h.create(
68+
Kind::Note,
69+
"style",
70+
"project style",
71+
"",
72+
Scope::Project,
73+
&no_meta(),
74+
)
75+
.unwrap();
4176

4277
let got = h.get(Kind::Note, "style").unwrap();
4378
assert_eq!(got.body.trim(), "project style");
@@ -51,18 +86,30 @@ fn project_shadows_global_by_name() {
5186
#[test]
5287
fn list_covers_every_kind() {
5388
let (_g, _p, h) = harness();
54-
h.create(Kind::Note, "n", "n", "", Scope::Global, &no_meta()).unwrap();
55-
h.create(Kind::Memory, "m", "m", "", Scope::Global, &no_meta()).unwrap();
56-
h.create(Kind::Skill, "s", "s", "d", Scope::Global, &no_meta()).unwrap();
57-
h.create(Kind::Subagent, "a", "a", "d", Scope::Global, &no_meta()).unwrap();
89+
h.create(Kind::Note, "n", "n", "", Scope::Global, &no_meta())
90+
.unwrap();
91+
h.create(Kind::Memory, "m", "m", "", Scope::Global, &no_meta())
92+
.unwrap();
93+
h.create(Kind::Skill, "s", "s", "d", Scope::Global, &no_meta())
94+
.unwrap();
95+
h.create(Kind::Subagent, "a", "a", "d", Scope::Global, &no_meta())
96+
.unwrap();
5897
assert_eq!(h.list(None).len(), 4);
5998
assert_eq!(h.list(Some(Kind::Skill)).len(), 1);
6099
}
61100

62101
#[test]
63102
fn update_preserves_scope_and_description() {
64103
let (_g, _p, h) = harness();
65-
h.create(Kind::Note, "n", "one", "the note", Scope::Project, &no_meta()).unwrap();
104+
h.create(
105+
Kind::Note,
106+
"n",
107+
"one",
108+
"the note",
109+
Scope::Project,
110+
&no_meta(),
111+
)
112+
.unwrap();
66113
let updated = h.update(Kind::Note, "n", Some("two"), None).unwrap();
67114
assert_eq!(updated.body.trim(), "two");
68115
assert_eq!(updated.description, "the note");
@@ -73,13 +120,26 @@ fn update_preserves_scope_and_description() {
73120
fn delete_removes_the_whole_skill_directory() {
74121
let (_g, _p, h) = harness();
75122
let e = h
76-
.create(Kind::Skill, "release", "body", "d", Scope::Global, &no_meta())
123+
.create(
124+
Kind::Skill,
125+
"release",
126+
"body",
127+
"d",
128+
Scope::Global,
129+
&no_meta(),
130+
)
77131
.unwrap();
78-
let dir = std::path::Path::new(&e.path).parent().unwrap().to_path_buf();
132+
let dir = std::path::Path::new(&e.path)
133+
.parent()
134+
.unwrap()
135+
.to_path_buf();
79136
std::fs::write(dir.join("helper.sh"), "echo hi").unwrap();
80137

81138
assert!(h.delete(Kind::Skill, "release", None).unwrap());
82-
assert!(!dir.exists(), "an emptied skill dir would still show up in listings");
139+
assert!(
140+
!dir.exists(),
141+
"an emptied skill dir would still show up in listings"
142+
);
83143
assert!(h.get(Kind::Skill, "release").is_none());
84144
}
85145

@@ -98,7 +158,10 @@ fn oversized_note_is_refused_with_an_actionable_message() {
98158
.expect_err("a note over the cap must be refused, not truncated");
99159
let msg = err.to_string();
100160
assert!(msg.contains("every request"), "{msg}");
101-
assert!(msg.contains("skill"), "the error should point at the cheaper alternative: {msg}");
161+
assert!(
162+
msg.contains("skill"),
163+
"the error should point at the cheaper alternative: {msg}"
164+
);
102165
}
103166

104167
#[test]
@@ -114,7 +177,8 @@ fn names_cannot_escape_the_harness_directory() {
114177
let (_g, _p, h) = harness();
115178
for bad in ["../escape", "a/b", "..", ".", "", "with space"] {
116179
assert!(
117-
h.create(Kind::Note, bad, "x", "", Scope::Global, &no_meta()).is_err(),
180+
h.create(Kind::Note, bad, "x", "", Scope::Global, &no_meta())
181+
.is_err(),
118182
"{bad:?} should be rejected as a harness entry name"
119183
);
120184
}
@@ -123,8 +187,15 @@ fn names_cannot_escape_the_harness_directory() {
123187
#[test]
124188
fn front_matter_values_cannot_forge_extra_keys() {
125189
let (_g, _p, h) = harness();
126-
h.create(Kind::Skill, "s", "body", "line one\ndescription: injected", Scope::Global, &no_meta())
127-
.unwrap();
190+
h.create(
191+
Kind::Skill,
192+
"s",
193+
"body",
194+
"line one\ndescription: injected",
195+
Scope::Global,
196+
&no_meta(),
197+
)
198+
.unwrap();
128199
let got = h.get(Kind::Skill, "s").unwrap();
129200
assert_eq!(got.description, "line one description: injected");
130201
assert_eq!(got.body.trim(), "body");
@@ -139,8 +210,24 @@ fn empty_harness_renders_nothing() {
139210
#[test]
140211
fn render_inlines_notes_and_memories_but_only_indexes_skills() {
141212
let (_g, _p, h) = harness();
142-
h.create(Kind::Note, "style", "prefer small diffs", "", Scope::Global, &no_meta()).unwrap();
143-
h.create(Kind::Memory, "flaky", "retry test_net 3x", "", Scope::Global, &no_meta()).unwrap();
213+
h.create(
214+
Kind::Note,
215+
"style",
216+
"prefer small diffs",
217+
"",
218+
Scope::Global,
219+
&no_meta(),
220+
)
221+
.unwrap();
222+
h.create(
223+
Kind::Memory,
224+
"flaky",
225+
"retry test_net 3x",
226+
"",
227+
Scope::Global,
228+
&no_meta(),
229+
)
230+
.unwrap();
144231
h.create(
145232
Kind::Skill,
146233
"release",
@@ -167,11 +254,21 @@ fn render_stops_inlining_once_the_budget_is_spent() {
167254
let chunk = "y".repeat(MAX_INLINE_BYTES - 1);
168255
// 12 near-cap memories comfortably exceed the 32 KiB total budget.
169256
for i in 0..12 {
170-
h.create(Kind::Memory, &format!("m{i}"), &chunk, "", Scope::Global, &no_meta())
171-
.unwrap();
257+
h.create(
258+
Kind::Memory,
259+
&format!("m{i}"),
260+
&chunk,
261+
"",
262+
Scope::Global,
263+
&no_meta(),
264+
)
265+
.unwrap();
172266
}
173267
let block = h.render_prompt_block().unwrap();
174-
assert!(block.contains("budget is full"), "over-budget entries should say so: {block}");
268+
assert!(
269+
block.contains("budget is full"),
270+
"over-budget entries should say so: {block}"
271+
);
175272
assert!(
176273
block.len() < MAX_INLINE_TOTAL_BYTES * 2,
177274
"the rendered block must stay bounded, got {} bytes",

0 commit comments

Comments
 (0)