mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
Fix/7381 action worker failure 20261018t2254jkt (#7465)
* fix(actions): stop resumed playback when a dialog's worker fails * test(actions): reject suffix after failing background dialog filter * fix(actions): propagate the failed worker result through dialog confirmation * fix(dialogs): return action worker failures to callers * Collapse the nested if in actions::resume (clippy::collapsible_if) Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Brandon Thomas <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2 files changed
+50
-5
No files matched your search
@@ -435,21 +435,29 @@ pub fn insert_stop_confirm(app: &mut PhotocraftApp, fields: &serde_json::Map<Str
|
||||
pub const RESUME: &str = "__resumeAction";
|
||||
|
||||
/// A step dialog confirmed: continue the action after it (`dialogs::confirm` calls this).
|
||||
pub fn resume(app: &mut PhotocraftApp, fields: &serde_json::Map<String, Value>) {
|
||||
let Some(r) = fields.get(RESUME) else { return };
|
||||
pub fn resume(app: &mut PhotocraftApp, fields: &serde_json::Map<String, Value>) -> Result<(), String> {
|
||||
let Some(r) = fields.get(RESUME) else { return Ok(()) };
|
||||
// The dialog's command may run as a background job; the next step needs its result.
|
||||
if let Some(doc) = app.session.active().map(|d| d.doc.id)
|
||||
&& let Some(job) = app.session.job_on(doc)
|
||||
&& let Err(e) = app.session.wait_job(job.id)
|
||||
{
|
||||
let _ = app.session.wait_job(job.id);
|
||||
let template = "Action playback failed: {error}";
|
||||
app.ui.status = crate::i18n::fmt(tl!(template), &[("error", &e.to_string())]);
|
||||
app.ui.status_error = true;
|
||||
return Err(e.to_string());
|
||||
}
|
||||
let params = json!({"action": r.get("action").cloned().unwrap_or(Value::Null), "from": r.get("from").cloned().unwrap_or(Value::Null)});
|
||||
match play(app, ¶ms) {
|
||||
Ok(v) => report_play(app, &v),
|
||||
Ok(v) => {
|
||||
report_play(app, &v);
|
||||
Ok(())
|
||||
}
|
||||
Err(e) => {
|
||||
let template = "Action playback failed: {error}";
|
||||
app.ui.status = crate::i18n::fmt(tl!(template), &[("error", &e)]);
|
||||
app.ui.status_error = true;
|
||||
Err(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1543,6 +1551,43 @@ mod tests {
|
||||
assert_eq!(app.session.actions.list[0].steps.len(), 3);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn dialog_worker_failure_stops_action_before_following_steps() {
|
||||
for (background, locked) in [(true, true), (false, true), (true, false)] {
|
||||
let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());
|
||||
app.run("file.new", json!({"width": 8, "height": 6, "background": "#203040"})).unwrap();
|
||||
let mut action = Action::new(
|
||||
"Worker Result",
|
||||
vec![
|
||||
("layer.setProps".into(), json!({"name": "Prefix", "locks": {"pixels": locked}})),
|
||||
("filter.blur.gaussianBlur".into(), json!({"radius": 1.5})),
|
||||
("layer.new.layer".into(), json!({"name": "Suffix"})),
|
||||
],
|
||||
);
|
||||
action.dialogs.insert(1);
|
||||
app.session.actions.list.push(action);
|
||||
app.background_jobs = background;
|
||||
let paused = play(&mut app, &json!({"action": "Worker Result"})).unwrap();
|
||||
let dialog = paused["paused"]["dialog"].as_u64().unwrap();
|
||||
let result = crate::dialogs::confirm(&mut app, dialog);
|
||||
let suffix = app.session.active().unwrap().doc.walk().iter().any(|(_, _, layer)| layer.name == "Suffix");
|
||||
|
||||
assert_eq!(suffix, !locked, "background={background}, locked={locked}: {result:?}");
|
||||
if locked && background {
|
||||
assert!(result.as_ref().is_err_and(|e| e.contains("locked")), "failed worker must fail the dialog confirmation: {result:?}");
|
||||
assert!(app.ui.status_error, "the action must report the worker failure");
|
||||
assert!(app.ui.status.contains("locked"), "{}", app.ui.status);
|
||||
assert_eq!(app.session.jobs_with_recent()[0].state, "failed");
|
||||
} else if locked {
|
||||
assert!(result.is_err(), "the foreground command rejects the locked layer");
|
||||
} else {
|
||||
assert!(result.is_ok(), "the successful worker lets the action continue: {result:?}");
|
||||
}
|
||||
assert_eq!(app.session.actions.playing, 0);
|
||||
assert!(app.session.actions.playback_stack.is_empty());
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_dialog_toggled_step_pauses_playback_and_resumes_on_ok() {
|
||||
let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());
|
||||
|
||||
@@ -664,7 +664,7 @@ pub fn confirm(app: &mut PhotocraftApp, id: u64) -> Result<Value, String> {
|
||||
if result.is_ok() {
|
||||
crate::filter_dialog::remember(app, &cmd, &d.fields);
|
||||
// A step dialog of a playing action: the action continues after it.
|
||||
crate::actions::resume(app, &d.fields);
|
||||
crate::actions::resume(app, &d.fields)?;
|
||||
}
|
||||
result
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user