Actions: recording into an empty loaded set keeps its exact name (CodeRabbit review on crates/engine/src/cmd/atn_cmds/files.rs:65)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
Hector VillarrealandClaude Opus 5.5 committed 2026-11-01 00:59:36 -06:00
1 parent 8a5ce6fa24
commit b544021d49
2 files changed
+20 -3

No files matched your search

+3 -3
View File
@@ -374,9 +374,9 @@ fn record(s: &mut Session, p: &Value) -> Result<Value> {
}
let set = match p.get("set") {
None | Some(Value::Null) => None,
// An existing set keeps its exact name (an older actions.json may pad it); a new one
// is trimmed.
Some(Value::String(n)) if s.actions.list.iter().any(|a| a.set.as_deref() == Some(n.as_str())) => Some(n.clone()),
// An existing set, empty ones included, keeps its exact name (an older actions.json or
// a `.atn` may pad it); a new one is trimmed.
Some(Value::String(n)) if crate::actions_edit_cmds::set_names(s).contains(n) => Some(n.clone()),
Some(Value::String(n)) if !n.trim().is_empty() => Some(n.trim().to_string()),
Some(_) => return Err(bad("actions.record", "\"set\" must be a set name or null")),
};
@@ -1191,3 +1191,20 @@ fn record_keeps_an_existing_sets_exact_name() {
s.execute("actions.stop", json!({})).unwrap();
assert_eq!(set_of(&s, "Fresh").as_deref(), Some("Print"), "a new set is trimmed");
}
/// CodeRabbit review on #10459: an empty set loaded from a `.atn` (or made by New Set) keeps its
/// exact name too, so the first action recorded into it lands in that folder and saves with it.
#[test]
fn record_keeps_an_empty_loaded_sets_exact_name() {
let mut src = Session::new();
src.actions.sets.push(" Web ".into());
let saved = src.execute("actions.save", json!({"set": " Web "})).unwrap();
let mut s = Session::new();
assert_eq!(s.execute("actions.load", json!({"data": saved["data"]})).unwrap()["set"], " Web ");
s.execute("actions.record", json!({"name": "First", "set": " Web "})).unwrap();
s.execute("actions.stop", json!({})).unwrap();
let set = s.actions.list.iter().find(|a| a.name == "First").and_then(|a| a.set.clone());
assert_eq!(set.as_deref(), Some(" Web "));
assert_eq!(crate::actions_edit_cmds::set_names(&s), [" Web "], "one folder, not a trimmed second one");
assert_eq!(s.execute("actions.save", json!({"set": " Web "})).unwrap()["actions"], json!(["First"]));
}