From 7930dd0adf3ab27a09d39aca81df93b5944964e5 Mon Sep 17 00:00:00 2001 From: BFlat Date: Wed, 7 Oct 2026 07:59:39 +0700 Subject: [PATCH] serve: `methods` lists jobs.list and jobs.cancel (#414) (#438) The headless server dispatched `jobs.list` and `jobs.cancel` but left them out of `METHODS`, so a client discovering the server through `methods` couldn't find the job methods `engine.execute {"wait": false}` depends on. Add them, and name them in the rpc.rs module doc and the `photocraft-cli serve` usage text. A test checks that the job methods are listed and that every listed name is dispatched. Co-authored-by: Claude Opus 5.5 --- apps/photocraft-cli/src/lib.rs | 5 +++-- crates/automation/src/rpc.rs | 21 ++++++++++++++++++++- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/apps/photocraft-cli/src/lib.rs b/apps/photocraft-cli/src/lib.rs index 7def236d54..72898b389d 100644 --- a/apps/photocraft-cli/src/lib.rs +++ b/apps/photocraft-cli/src/lib.rs @@ -33,8 +33,9 @@ USAGE: photocraft-cli serve [--port ] [--control-token <64-hex> | --control-token-file ] [--automation-read-root ] [--automation-write-root ] Keep one headless session open and answer JSON lines ({\"id\",\"method\",\"params\"}) on stdio, - or on 127.0.0.1:. Methods: engine.execute, engine.commands, doc.open/new/save/inspect/render/ - select/close, session.list, batch, methods (docs/control-protocol.md#headless-server). + or on 127.0.0.1:. Methods: engine.execute, jobs.list/cancel, engine.commands, + doc.open/new/save/inspect/render/select/close, session.list, batch, methods + (docs/control-protocol.md#headless-server). "; struct Args { diff --git a/crates/automation/src/rpc.rs b/crates/automation/src/rpc.rs index 5cf871b4d6..677cb90482 100644 --- a/crates/automation/src/rpc.rs +++ b/crates/automation/src/rpc.rs @@ -5,7 +5,8 @@ //! loopback TCP port. //! //! Methods (camelCase params): -//! - `engine.execute {command, params?}` / `engine.commands {filter?}` +//! - `engine.execute {command, params?, wait?}` / `engine.commands {filter?}` +//! - `jobs.list` / `jobs.cancel {job?}`: background jobs (#210) //! - `session.list`, `doc.open {path}`, `doc.new {…file.new params}`, //! `doc.save {path?, format?, quality?, index?}`, `doc.inspect {index?}`, //! `doc.render {index?, maxSide?, path?}` (writes a PNG to `path`, else @@ -30,6 +31,8 @@ use crate::{AutomationError, Headless}; /// Method names served by [`Headless::handle`]. pub const METHODS: &[&str] = &[ "engine.execute", + "jobs.list", + "jobs.cancel", "engine.commands", "session.list", "doc.open", @@ -471,6 +474,22 @@ mod tests { assert_eq!(photocraft_codecs::decode(&png).unwrap().dimensions(), (2049, 1)); } + #[test] + fn methods_lists_the_job_methods_and_every_listed_name_is_served() { + let mut h = Headless::new(); + let listed = h.handle("methods", Value::Null).unwrap(); + let listed: Vec<&str> = listed.as_array().unwrap().iter().map(|m| m.as_str().unwrap()).collect(); + assert_eq!(listed, METHODS); + // The job methods `engine.execute {"wait": false}` depends on are discoverable (#414). + assert!(listed.contains(&"jobs.list") && listed.contains(&"jobs.cancel")); + for m in METHODS { + if let Err(e) = h.handle(m, Value::Null) { + assert!(!e.to_string().contains("unknown method"), "{m} is listed but not served: {e}"); + } + } + assert!(h.handle("jobs.nope", Value::Null).unwrap_err().to_string().contains("unknown method")); + } + #[test] fn batch_response_budget_stops_later_steps_even_when_stop_on_error_is_false() { let mut h = Headless::new();