address review: check the script step limit before charging skipped playback steps

This commit is contained in:
Dylan M. Taylor committed 2026-11-10 22:32:48 +00:00
1 parent 6fb778d056
commit 82a86c1a78
2 files changed
+15

No files matched your search

+4
View File
@@ -523,6 +523,10 @@ pub fn begin_playback(s: &mut Session, action: &Action, from: usize) -> Result<O
// The steps that run are charged one by one as they run; the ones walked past are charged
// here ([`playback_plan`] checked that the whole action fits).
let skipped = skipped_steps(action, from);
let max = crate::automate_cmds::MAX_SCRIPT_STEPS;
if s.actions.script_depth > 0 && s.actions.script_steps.saturating_add(skipped) > max {
return Err(bad("actions.play", format!("the script ran more than {max} steps in all")));
}
s.actions.playback_steps = s.actions.playback_steps.saturating_add(skipped);
if s.actions.script_depth > 0 {
s.actions.script_steps = s.actions.script_steps.saturating_add(skipped);
@@ -1250,3 +1250,14 @@ fn record_keeps_an_empty_loaded_sets_exact_name() {
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"]));
}
#[test]
fn skipped_steps_count_against_the_script_limit() {
let mut s = Session::new();
s.actions.list.push(Action::new("A", (0..3).map(|_| ("select.all".to_string(), json!({}))).collect()));
s.actions.script_depth = 1;
s.actions.script_steps = crate::automate_cmds::MAX_SCRIPT_STEPS - 1;
let e = s.execute("actions.play", json!({"action": "A", "from": 3})).err().map(|e| e.to_string());
assert!(e.is_some_and(|e| e.contains("the script ran more than")));
assert_eq!(s.actions.playing, 0);
}