From cbf5226d13a788884281f3932afe54d94d3de30b Mon Sep 17 00:00:00 2001 From: SoftFever Date: Thu, 19 Nov 2026 22:58:34 +0800 Subject: [PATCH] Let MCP clients read the connected printer's status and pause, resume or stop its print printer_status reads what the Device tab shows of the printer it is connected to: its state, progress, layer, the file printing and the temperatures, with no serial number and nothing sent to the printer. print_pause, print_resume and print_stop do what the tab's buttons do, and are refused, saying why, where the printer's state does not allow them or a job can be resumed only at the printer. --- scripts/check_operation_calls.py | 2 + src/slic3r/GUI/DeviceManager.cpp | 7 +- src/slic3r/GUI/DeviceManager.hpp | 3 + src/slic3r/GUI/Mcp/McpReplaySummary.cpp | 5 +- src/slic3r/GUI/Mcp/McpTools.hpp | 7 +- src/slic3r/GUI/Mcp/McpToolsPrinter.cpp | 95 +++++++++++ src/slic3r/GUI/Operations/PrinterOps.cpp | 112 +++++++++++++ src/slic3r/GUI/Operations/PrinterOps.hpp | 64 ++++++- tests/automation/test_mcp_replay_summary.cpp | 7 +- tests/data/command_catalog.json | 138 ++++++++++++++++ tests/slic3rutils/test_command_catalog.cpp | 33 ++-- .../test_device_manager_integration.cpp | 156 +++++++++++++++++- tests/slic3rutils/test_mcp_cad.cpp | 5 +- tests/slic3rutils/test_mcp_tools.cpp | 6 +- tests/slic3rutils/test_operations.cpp | 2 +- tools/mcp/TESTS.md | 5 +- tools/mcp/sweep.json | 1 + tools/mcp/test_printer_commands.py | 42 +++++ 18 files changed, 659 insertions(+), 31 deletions(-) create mode 100644 tools/mcp/test_printer_commands.py diff --git a/scripts/check_operation_calls.py b/scripts/check_operation_calls.py index 7c4b9fe80c..252f971d56 100644 --- a/scripts/check_operation_calls.py +++ b/scripts/check_operation_calls.py @@ -77,6 +77,8 @@ BANNED = { "replace_part": ["replace_part_with_file", "replace_with_stl"], # The Print button's handlers run the print dialogs through it, as its Print and Send open them. "open_print_dialog": ["send_gcode_legacy", "send_to_printer"], + # The Device tab's job buttons send the same commands; the operation adds the checks a call needs without the tab. + "send_job_command": ["command_task_pause", "command_task_resume", "command_task_abort"], "sync_presets": ["restart_sync_user_preset", "start_sync_user_preset"], "add_filament_slot": ["add_filament"], "delete_filament_slot": ["delete_filament", "change_filament"], diff --git a/src/slic3r/GUI/DeviceManager.cpp b/src/slic3r/GUI/DeviceManager.cpp index 9fe22c8c80..200d1add86 100644 --- a/src/slic3r/GUI/DeviceManager.cpp +++ b/src/slic3r/GUI/DeviceManager.cpp @@ -1735,9 +1735,14 @@ int MachineObject::command_set_chamber(int temp) return this->publish_json(j, 1); } +bool MachineObject::resume_only_at_printer() const +{ + return jobState_ > 1; +} + int MachineObject::check_resume_condition() { - if (jobState_ > 1) { + if (resume_only_at_printer()) { GUI::wxGetApp().show_dialog(_L("To ensure your safety, certain processing tasks (such as laser) can only be resumed on printer.")); return 1; } diff --git a/src/slic3r/GUI/DeviceManager.hpp b/src/slic3r/GUI/DeviceManager.hpp index 8944a769d0..ea0f296243 100644 --- a/src/slic3r/GUI/DeviceManager.hpp +++ b/src/slic3r/GUI/DeviceManager.hpp @@ -801,6 +801,9 @@ public: int command_set_nozzle_new(int nozzle_id, int temp); int command_refresh_nozzle(); int command_set_chamber(int temp); + // Whether the job may be resumed only at the printer, as certain processing tasks (such as laser) are: + // check_resume_condition()'s rule, which it tells the person in a dialog. + bool resume_only_at_printer() const; int check_resume_condition(); // ams controls //int command_ams_switch(int tray_index, int old_temp = 210, int new_temp = 210); diff --git a/src/slic3r/GUI/Mcp/McpReplaySummary.cpp b/src/slic3r/GUI/Mcp/McpReplaySummary.cpp index 2e2619af9b..bea9ce4d70 100644 --- a/src/slic3r/GUI/Mcp/McpReplaySummary.cpp +++ b/src/slic3r/GUI/Mcp/McpReplaySummary.cpp @@ -134,8 +134,9 @@ void flag_effects(Builder& b, const std::string& key, const json& args) const bool preset_bundle = key == "window_open" && args.is_object() && args.value("window", std::string()) == "preset_bundle"; if (one_of(key, {"preset_import", "preset_sync"}) || preset_bundle) b.flag(StepFlag::ChangesPresets); - // Their dialogs print on a printer or send it a file; printer_test_host only asks the host whether it answers. - if (one_of(key, {"print_start", "printer_send"})) + // Their dialogs print on a printer or send it a file, and the job commands pause, resume or stop its print; + // printer_test_host only asks the host whether it answers, and printer_status reads what the app holds. + if (one_of(key, {"print_start", "printer_send", "print_pause", "print_resume", "print_stop"})) b.flag(StepFlag::SendsToPrinter); } diff --git a/src/slic3r/GUI/Mcp/McpTools.hpp b/src/slic3r/GUI/Mcp/McpTools.hpp index 2dbcff3a13..6981fe6819 100644 --- a/src/slic3r/GUI/Mcp/McpTools.hpp +++ b/src/slic3r/GUI/Mcp/McpTools.hpp @@ -52,6 +52,7 @@ class Plater; namespace Ops { struct ExportTicket; +struct PrinterStatus; struct Preference; struct Refusal; enum class PresetChanges; @@ -83,8 +84,12 @@ void register_gizmo_tools(CommandCatalog& catalog); // A gizmo command's acting arguments: a call with any of them does the job and opens no gizmo; a call with none opens // it. Empty for a command that only opens, and for any other command. const std::vector& gizmo_acting_args(const std::string& command); -// print_start, printer_send and printer_test_host (McpToolsPrinter.cpp). +// print_start, printer_send, printer_test_host, printer_status, print_pause, print_resume and print_stop +// (McpToolsPrinter.cpp). void register_printer_tools(CommandCatalog& catalog); +// printer_status's reply: {"connected": false} with no printer, else the status's fields, a name the Device tab would +// not give being null. +nlohmann::json printer_status_reply(const std::optional& status); // The plates argument of print_start and printer_send, as project_export takes it: a plate's index into `plate`, // "all" as `all`, or "current" (also when left out) as neither. Returns what is wrong with it, else empty. std::string read_print_plates(const nlohmann::json& args, std::optional& plate, bool& all); diff --git a/src/slic3r/GUI/Mcp/McpToolsPrinter.cpp b/src/slic3r/GUI/Mcp/McpToolsPrinter.cpp index 57c11345e4..e5ca0adc64 100644 --- a/src/slic3r/GUI/Mcp/McpToolsPrinter.cpp +++ b/src/slic3r/GUI/Mcp/McpToolsPrinter.cpp @@ -1,6 +1,8 @@ // The printing commands: print_start and printer_send open the dialog the Print button's Print and Send open for the // selected printer, and printer_test_host asks the printer's print host whether it answers, as the Test button of its // connection dialog does. What is printed or sent is left to the dialog, which a client answers with the dialog tools. +// printer_status reads what the Device tab shows of the printer it is connected to, and print_pause, print_resume and +// print_stop send that printer the tab's job commands. #include "McpTools.hpp" @@ -24,6 +26,36 @@ using nlohmann::json; namespace { +json temperature(const Ops::Temperature& t) +{ + return {{"current", t.current ? json(*t.current) : json()}, {"target", t.target ? json(*t.target) : json()}}; +} + +// print_pause, print_resume or print_stop: `command` sent to the connected printer. +NativeCommand job_command(const char* name, const char* title, Ops::JobCommand command, const std::string& description, + const char* examples, bool destructive) +{ + NativeCommand job = mutate_tool( + name, title, + description + " The printer's new state arrives when it reports: read it with printer_status. Reply: printer (its " + "name), state (the state it was in) and sent. A replay sends the command again.", + object_schema({}), + [command](const json&, ToolContext& ctx) { + json reply = ctx.run_ui([command] { + const Ops::Outcome sent = Ops::send_job_command(Ops::connected_printer(), command); + if (!sent) + throw refused(sent.refusal()); + return json{{"printer", sent.value().printer}, {"state", sent.value().state}, {"sent", true}}; + }); + return ToolResult::ok(std::move(reply)); + }, + destructive); + // It sends the printer a command. + job.open_world = true; + job.examples = json::parse(examples); + return reaching({"send_job_command"}, std::move(job)); +} + json plates_prop(const char* all) { return {{"type", {"string", "integer"}}, @@ -33,6 +65,30 @@ json plates_prop(const char* all) } // namespace +json printer_status_reply(const std::optional& status) +{ + if (!status) + return {{"connected", false}}; + json nozzles = json::array(); + for (const Ops::Temperature& nozzle : status->nozzles) + nozzles.push_back(temperature(nozzle)); + return {{"connected", true}, + {"name", status->name}, + {"model", status->model.empty() ? json() : json(status->model)}, + {"printer_type", status->printer_type}, + {"online", status->online}, + {"state", status->state}, + {"stage", status->stage}, + {"percent", status->percent}, + {"remaining_seconds", status->remaining_seconds}, + {"layer", status->layer}, + {"total_layers", status->total_layers}, + {"file", status->file}, + {"error_code", status->error_code}, + {"temperatures", + {{"nozzles", std::move(nozzles)}, {"bed", temperature(status->bed)}, {"chamber", temperature(status->chamber)}}}}; +} + std::string read_print_plates(const json& args, std::optional& plate, bool& all) { plate.reset(); @@ -130,6 +186,45 @@ void register_printer_tools(CommandCatalog& catalog) {"tool": "settings_set", "args": {"type": "printer", "values": {"host_type": "octoprint", "print_host": "192.168.1.20"}}}, {"tool": "printer_test_host", "args": {}}]}])json"); catalog.add(reaching({"test_print_host"}, std::move(test_host))); + + NativeCommand status = inspect_tool( + "printer_status", L("Printer status"), + "Read what the Device tab shows of the printer it is connected to, without sending it anything. Reply: connected; " + "with a printer, name, model (null where the tab would say Unknown), printer_type (the model's id), online, state " + "(IDLE, PREPARE, RUNNING, PAUSE, FINISH, FAILED...), stage (a number), percent, remaining_seconds, layer, " + "total_layers, file (the job's name), error_code, and temperatures: nozzles (one {current, target} each), bed and " + "chamber, null where the tab shows none. With no printer connected the reply is {\"connected\": false}, which is no " + "error. The values are what the printer last reported.", + object_schema({}), [](const json&, ToolContext& ctx) { + return ToolResult::ok(ctx.run_ui([] { return printer_status_reply(Ops::printer_status(Ops::connected_printer())); })); + }); + status.examples = json::parse(R"json([ + {"title": "Read the connected printer's state and temperatures", "calls": [{"tool": "printer_status", "args": {}}]}])json"); + catalog.add(std::move(status)); + + catalog.add(job_command( + "print_pause", L("Pause the print"), Ops::JobCommand::Pause, + "Pause the print running on the printer the Device tab is connected to, as the tab's Pause button does. Refused: " + "no_printer_connected with no printer connected, printer_state, naming the state, unless it is RUNNING.", + R"json([{"title": "Pause the print once printer_status reads RUNNING", "calls": [ + {"tool": "printer_status", "args": {}}, {"tool": "print_pause", "args": {}}]}])json", + false)); + catalog.add(job_command( + "print_resume", L("Resume the print"), Ops::JobCommand::Resume, + "Resume the paused print on the printer the Device tab is connected to, as the tab's Resume button does. Refused: " + "no_printer_connected with no printer connected, printer_state, naming the state, unless it is PAUSE, and " + "resume_at_printer, in the app's own sentence, for a job (such as laser processing) that resumes only at the printer.", + R"json([{"title": "Resume the print once printer_status reads PAUSE", "calls": [ + {"tool": "printer_status", "args": {}}, {"tool": "print_resume", "args": {}}]}])json", + false)); + catalog.add(job_command( + "print_stop", L("Stop the print"), Ops::JobCommand::Stop, + "Stop the print on the printer the Device tab is connected to, as the tab's Stop button does, but without its " + "question \"Are you sure you want to stop this print?\": it asks nothing, and a stopped print cannot be resumed. " + "Refused: no_printer_connected with no printer connected, printer_state, naming the state, unless it is RUNNING, " + "PAUSE, PREPARE or SLICING.", + R"json([{"title": "Stop the print", "calls": [{"tool": "print_stop", "args": {}}]}])json", + true)); } }}} // namespace Slic3r::GUI::Mcp diff --git a/src/slic3r/GUI/Operations/PrinterOps.cpp b/src/slic3r/GUI/Operations/PrinterOps.cpp index 0d1b7c02a4..c5eb5437d1 100644 --- a/src/slic3r/GUI/Operations/PrinterOps.cpp +++ b/src/slic3r/GUI/Operations/PrinterOps.cpp @@ -3,6 +3,13 @@ #include "Outcome.hpp" #include "PlateOps.hpp" +#include "slic3r/GUI/DeviceCore/DevBed.h" +#include "slic3r/GUI/DeviceCore/DevConfig.h" +#include "slic3r/GUI/DeviceCore/DevConfigUtil.h" +#include "slic3r/GUI/DeviceCore/DevDefs.h" +#include "slic3r/GUI/DeviceCore/DevExtruderSystem.h" +#include "slic3r/GUI/DeviceCore/DevManager.h" +#include "slic3r/GUI/DeviceManager.hpp" #include "slic3r/GUI/Event.hpp" #include "slic3r/GUI/GLToolbar.hpp" #include "slic3r/GUI/GUI.hpp" @@ -11,6 +18,7 @@ #include "slic3r/GUI/MainFrame.hpp" #include "slic3r/GUI/PartPlate.hpp" #include "slic3r/GUI/Plater.hpp" +#include "slic3r/Utils/IPrinterAgent.hpp" #include "slic3r/Utils/PrintHost.hpp" #include "libslic3r/Config.hpp" @@ -25,6 +33,7 @@ #include #include +#include #include #include #include @@ -153,4 +162,107 @@ Outcome test_print_host() return HostTested{ok, into_u8(ok ? host->get_test_ok_msg() : host->get_test_failed_msg(message))}; } +MachineObject* connected_printer() +{ + assert(wxThread::IsMain()); + DeviceManager* devices = wxGetApp().getDeviceManager(); + return devices != nullptr ? devices->get_selected_machine() : nullptr; +} + +std::optional job_command_refusal(MachineObject* printer, JobCommand command) +{ + if (printer == nullptr) + return Refusal{RefusalKind::Precondition, "no_printer_connected", + L("No printer is connected. Connect one on the Device tab.")}; + // The state the Device tab's buttons are enabled in, each with its own sentence. + switch (command) { + case JobCommand::Pause: + if (!printer->can_pause()) + return Refusal{RefusalKind::Precondition, "printer_state", L("The printer's state is %1%, in which its print cannot be paused."), + {printer->print_status}}; + break; + case JobCommand::Resume: + if (!printer->can_resume()) + return Refusal{RefusalKind::Precondition, "printer_state", L("The printer's state is %1%, in which no print is paused to resume."), + {printer->print_status}}; + if (printer->resume_only_at_printer()) + return Refusal{RefusalKind::Precondition, "resume_at_printer", + L("To ensure your safety, certain processing tasks (such as laser) can only be resumed on printer.")}; + break; + case JobCommand::Stop: + if (!printer->can_abort()) + return Refusal{RefusalKind::Precondition, "printer_state", L("The printer's state is %1%, in which no print runs to stop."), + {printer->print_status}}; + break; + } + return std::nullopt; +} + +Refusal job_command_failure(int published) +{ + if (published == ORCA_NETWORK_ERR_CMD_NOT_SUPPORTED || published == ORCA_NETWORK_ERR_CAP_NOT_AVAILABLE) + return Refusal{RefusalKind::Failed, "command_not_supported", L("The printer does not support this command.")}; + return Refusal{RefusalKind::Failed, "not_sent", L("The command was not sent to the printer (error %1%)."), {std::to_string(published)}}; +} + +Outcome send_job_command(MachineObject* printer, JobCommand command) +{ + if (std::optional refusal = job_command_refusal(printer, command)) + return *refusal; + JobCommandSent sent{printer->get_dev_name(), printer->print_status}; + const int published = command == JobCommand::Pause ? printer->command_task_pause() : + command == JobCommand::Resume ? printer->command_task_resume() : + printer->command_task_abort(); + if (published != 0) + return job_command_failure(published); + return sent; +} + +std::string printer_model_name(const MachineObject& printer, const PresetBundle* bundle) +{ + // As MachineObject::get_printer_type_display_str() names it, without its translated "Unknown". + std::string name = DevPrinterConfigUtil::get_printer_display_name(printer.printer_type); + if (name.empty() && bundle != nullptr) + for (const auto& [vendor_id, vendor] : bundle->vendors) + for (const auto& model : vendor.models) + if (model.model_id == printer.printer_type) + name = model.name; + if (name.empty() && printer.printer_type == "orcasonar") + name = "OrcaSonar Printer"; + return name; +} + +std::optional printer_status(MachineObject* printer) +{ + if (printer == nullptr) + return std::nullopt; + PrinterStatus status; + status.name = printer->get_dev_name(); + // The app's preset bundle, which a unit test, with no app of OrcaSlicer's, has none of. + const GUI_App* app = dynamic_cast(wxTheApp); + status.model = printer_model_name(*printer, app != nullptr ? app->preset_bundle : nullptr); + status.printer_type = printer->printer_type; + status.online = printer->is_online(); + status.state = printer->print_status; + status.stage = printer->mc_print_stage; + status.percent = printer->mc_print_percent; + status.remaining_seconds = printer->mc_left_time; + status.layer = printer->curr_layer; + status.total_layers = printer->total_layers; + status.file = printer->subtask_name; + status.error_code = printer->print_error; + // The Device tab's temperature fields: a nozzle per extruder, the bed, and the chamber's current temperature on the + // X1 series and its target where the printer lets it be set, blank otherwise. + if (const DevExtderSystem* extruders = printer->GetExtderSystem()) + for (int id = 0; id < extruders->GetTotalExtderCount(); ++id) + status.nozzles.push_back({float(extruders->GetNozzleTempCurrent(id)), float(extruders->GetNozzleTempTarget(id))}); + if (DevBed* bed = printer->GetBed()) + status.bed = {bed->GetBedTemp(), bed->GetBedTempTarget()}; + if (printer->get_printer_series() == PrinterSeries::SERIES_X1) + status.chamber.current = printer->chamber_temp; + if (const DevConfig* config = printer->GetConfig(); config != nullptr && config->SupportChamberEdit()) + status.chamber.target = printer->chamber_temp_target; + return status; +} + }}} // namespace Slic3r::GUI::Ops diff --git a/src/slic3r/GUI/Operations/PrinterOps.hpp b/src/slic3r/GUI/Operations/PrinterOps.hpp index a2688803c7..1ad005bf93 100644 --- a/src/slic3r/GUI/Operations/PrinterOps.hpp +++ b/src/slic3r/GUI/Operations/PrinterOps.hpp @@ -9,11 +9,14 @@ #include namespace Slic3r { +class MachineObject; +class PresetBundle; class PrintHost; } -// Printing and the printer: the dialogs the Print button opens, and the print host's connection test. Each does what -// the button, or the connection dialog's Test button, does for a person, for the printer selected as it stands. +// Printing and the printer: the dialogs the Print button opens, the print host's connection test, and the job and status +// of the printer the Device tab is connected to. Each does what the button, the connection dialog's Test button, or the +// Device tab's controls do for a person, for the printer selected as it stands. namespace Slic3r { namespace GUI { namespace Ops { // The dialog a print or send call opens: the Print dialog of a printer on the Bambu network or with printer agents @@ -66,4 +69,61 @@ struct HostTested // Refuses: what host_test_refusal() gives. Outcome test_print_host(); +// The printer the Device tab is connected to (DeviceManager::get_selected_machine()), or null with none. UI thread. +MachineObject* connected_printer(); + +// The Device tab's job buttons. +enum class JobCommand { Pause, Resume, Stop }; + +// Why `command` is not sent to `printer`, or none: no_printer_connected (null), printer_state (its state, print_status, +// does not allow the command: can_pause(), can_resume() or can_abort()), resume_at_printer (a job that resumes only at +// the printer, in the sentence the Device tab's Resume shows for it). +std::optional job_command_refusal(MachineObject* printer, JobCommand command); + +struct JobCommandSent +{ + std::string printer; // its name + std::string state; // the state it was in when the command was sent +}; +// Sends `command` to `printer` as the Device tab's button does, without the tab's question before a stop. The printer's +// new state arrives when it reports. UI thread. +// Refuses: what job_command_refusal() gives, what job_command_failure() gives for a command not sent. +Outcome send_job_command(MachineObject* printer, JobCommand command); + +// What a non-zero return of MachineObject::publish_json() means: command_not_supported for a command the printer's agent +// has no translation for, or a capability the printer lacks (for which publish_json() has shown the app's notice, as for +// a person's click), else not_sent with the code. +Refusal job_command_failure(int published); + +// The printer's model as the Device tab names it, untranslated, or empty where the tab would say "Unknown". The vendors' +// models are read only through a `bundle` that is not null. +std::string printer_model_name(const MachineObject& printer, const PresetBundle* bundle); + +// A temperature the Device tab shows, and its target; none where the tab shows a blank. +struct Temperature +{ + std::optional current, target; +}; + +// What the Device tab's status shows for the connected printer. +struct PrinterStatus +{ + std::string name; + std::string model; // printer_model_name(); empty: unknown + std::string printer_type; // the model's id, as the printer reports it + bool online = false; + std::string state; // print_status: IDLE, PREPARE, RUNNING, PAUSE, FINISH, FAILED... + int stage = 0; // mc_print_stage, a number: its name is translated + int percent = 0; + int remaining_seconds = 0; + int layer = 0, total_layers = 0; + std::string file; // the job's name (subtask_name) + int error_code = 0; + std::vector nozzles; // one per nozzle + Temperature bed, chamber; +}; +// What `printer` holds for the Device tab, read without publishing anything; none with no printer. The serial number is +// not in it. UI thread. +std::optional printer_status(MachineObject* printer); + }}} // namespace Slic3r::GUI::Ops diff --git a/tests/automation/test_mcp_replay_summary.cpp b/tests/automation/test_mcp_replay_summary.cpp index 4f02f1faea..5f54fd9811 100644 --- a/tests/automation/test_mcp_replay_summary.cpp +++ b/tests/automation/test_mcp_replay_summary.cpp @@ -229,13 +229,18 @@ TEST_CASE("a call with other arguments than an action's is described by its argu CHECK(flags_of(describe(json{{"tool", "preset_import"}, {"args", {{"path", abs_path("a.json")}}}}.dump())) == Flags{"changes_presets"}); } -TEST_CASE("the print and send commands send to a printer and the host test sends nothing", "[Mcp]") +TEST_CASE("the print, send and job commands send to a printer, and the host test and the status send nothing", "[Mcp]") { CHECK(flags_of(describe(R"({"tool": "print_start"})")) == Flags{"sends_to_printer"}); CHECK(flags_of(describe(R"({"tool": "print_start", "args": {"plates": 1}})")) == Flags{"sends_to_printer"}); // printer_send with a plate is no action's call, and sends all the same. CHECK(flags_of(describe(R"({"tool": "printer_send", "args": {"plates": 1}})")) == Flags{"sends_to_printer"}); CHECK(flags_of(describe(R"({"tool": "printer_test_host"})")).empty()); + for (const char* job : {"print_pause", "print_resume", "print_stop"}) { + INFO(job); + CHECK(flags_of(describe(json{{"tool", job}}.dump())) == Flags{"sends_to_printer"}); + } + CHECK(flags_of(describe(R"({"tool": "printer_status"})")).empty()); } TEST_CASE("an action that collects a value is described with it, and a call without it is no action's call", "[Mcp]") diff --git a/tests/data/command_catalog.json b/tests/data/command_catalog.json index 1653976a6e..0cac6a215f 100644 --- a/tests/data/command_catalog.json +++ b/tests/data/command_catalog.json @@ -6527,6 +6527,144 @@ "read_only": false, "title": "Test the print host" }, + { + "completion": "immediate", + "description": "Read what the Device tab shows of the printer it is connected to, without sending it anything. Reply: connected; with a printer, name, model (null where the tab would say Unknown), printer_type (the model's id), online, state (IDLE, PREPARE, RUNNING, PAUSE, FINISH, FAILED...), stage (a number), percent, remaining_seconds, layer, total_layers, file (the job's name), error_code, and temperatures: nozzles (one {current, target} each), bed and chamber, null where the tab shows none. With no printer connected the reply is {\"connected\": false}, which is no error. The values are what the printer last reported.", + "destructive": false, + "examples": [ + { + "calls": [ + { + "args": {}, + "tool": "printer_status" + } + ], + "title": "Read the connected printer's state and temperatures" + } + ], + "group": "Printers and prints", + "guard": "inspect", + "has_own_action": false, + "idempotent": true, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "printer_status", + "listed": true, + "open_world": false, + "operations": [], + "read_only": true, + "title": "Printer status" + }, + { + "completion": "immediate", + "description": "Pause the print running on the printer the Device tab is connected to, as the tab's Pause button does. Refused: no_printer_connected with no printer connected, printer_state, naming the state, unless it is RUNNING. The printer's new state arrives when it reports: read it with printer_status. Reply: printer (its name), state (the state it was in) and sent. A replay sends the command again.", + "destructive": false, + "examples": [ + { + "calls": [ + { + "args": {}, + "tool": "printer_status" + }, + { + "args": {}, + "tool": "print_pause" + } + ], + "title": "Pause the print once printer_status reads RUNNING" + } + ], + "group": "Printers and prints", + "guard": "mutate", + "has_own_action": false, + "idempotent": false, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "print_pause", + "listed": true, + "open_world": true, + "operations": [ + "send_job_command" + ], + "read_only": false, + "title": "Pause the print" + }, + { + "completion": "immediate", + "description": "Resume the paused print on the printer the Device tab is connected to, as the tab's Resume button does. Refused: no_printer_connected with no printer connected, printer_state, naming the state, unless it is PAUSE, and resume_at_printer, in the app's own sentence, for a job (such as laser processing) that resumes only at the printer. The printer's new state arrives when it reports: read it with printer_status. Reply: printer (its name), state (the state it was in) and sent. A replay sends the command again.", + "destructive": false, + "examples": [ + { + "calls": [ + { + "args": {}, + "tool": "printer_status" + }, + { + "args": {}, + "tool": "print_resume" + } + ], + "title": "Resume the print once printer_status reads PAUSE" + } + ], + "group": "Printers and prints", + "guard": "mutate", + "has_own_action": false, + "idempotent": false, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "print_resume", + "listed": true, + "open_world": true, + "operations": [ + "send_job_command" + ], + "read_only": false, + "title": "Resume the print" + }, + { + "completion": "immediate", + "description": "Stop the print on the printer the Device tab is connected to, as the tab's Stop button does, but without its question \"Are you sure you want to stop this print?\": it asks nothing, and a stopped print cannot be resumed. Refused: no_printer_connected with no printer connected, printer_state, naming the state, unless it is RUNNING, PAUSE, PREPARE or SLICING. The printer's new state arrives when it reports: read it with printer_status. Reply: printer (its name), state (the state it was in) and sent. A replay sends the command again.", + "destructive": true, + "examples": [ + { + "calls": [ + { + "args": {}, + "tool": "print_stop" + } + ], + "title": "Stop the print" + } + ], + "group": "Printers and prints", + "guard": "mutate", + "has_own_action": false, + "idempotent": false, + "input_schema": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "key": "print_stop", + "listed": true, + "open_world": true, + "operations": [ + "send_job_command" + ], + "read_only": false, + "title": "Stop the print" + }, { "completion": "immediate", "description": "The plugins, as the Plugins window lists them: each with its key (which the other plugin commands take), name, version (the one installed, else the latest offered), installed (a package is on disk), enabled (loaded: the row's switch), status (Activated, Error, RuntimeError, Inactive or Loading), source (local, subscribed, mine or orphaned), capabilities (a loaded plugin's: name, type, enabled) and error.", diff --git a/tests/slic3rutils/test_command_catalog.cpp b/tests/slic3rutils/test_command_catalog.cpp index 0e55b4c932..bbd8647234 100644 --- a/tests/slic3rutils/test_command_catalog.cpp +++ b/tests/slic3rutils/test_command_catalog.cpp @@ -143,13 +143,13 @@ std::string first_difference(const std::string& actual, const std::string& expec } // The design's command set outside the Design tab, heading by heading in the order tools/list gives them, Driving the -// GUI last, after the Design tab's commands: the 127 commands of the catalog, its typed tools, the commands made from +// GUI last, after the Design tab's commands: the 131 commands of the catalog, its typed tools, the commands made from // menu items, the seven Parts 4a to 4c add (Printable, Fix Model, Auto Drop, Clone, Reload from disk, Replace 3D file, // Add Mixed Filament), the three of Part 5a (the Printer Selection dialog's list, install and uninstall), the two of // Part 5b (the System Filaments dialog's install and uninstall), Part 5c's write of the Preferences dialog's preferences // and the four of Part 5d (the Plugins window's list, a switch, Delete or Unsubscribe, and Reload), the seven gizmo -// commands (Paint, Measure, Simplify, Mesh Boolean, Cut, Lay on Face and Brim Ears), and the Print button's Print and -// the print host's test. +// commands (Paint, Measure, Simplify, Mesh Boolean, Cut, Lay on Face and Brim Ears), and the six printing commands (the +// Print button's Print, the print host's test, and the Device tab's status, Pause, Resume and Stop). // A part that adds a command adds it here. const std::vector>> kPlaces{ {"Tools and actions", {"tool_search", "tool_call", "action_search", "action_run"}}, @@ -175,7 +175,8 @@ const std::vector>> kPlaces{ {"Filaments", {"filament_add", "filament_delete", "filament_sync_ams", "filament_add_mixed", "filament_install", "filament_uninstall"}}, {"Printers and prints", - {"printer_send", "printer_list_models", "printer_install", "printer_uninstall", "print_start", "printer_test_host"}}, + {"printer_send", "printer_list_models", "printer_install", "printer_uninstall", "print_start", "printer_test_host", + "printer_status", "print_pause", "print_resume", "print_stop"}}, {"Plugins", {"plugin_list", "plugin_install_local", "plugin_enable", "plugin_reload", "plugin_uninstall", "plugin_refresh"}}, {"View and windows", {"view_set", "window_list", "window_set", "window_open"}}, {"Recordings, replays and scripts", @@ -451,9 +452,9 @@ TEST_CASE("outside the Design tab the catalog has its commands and 129 actions", CHECK(c.action_group == section.at(c.key)); } // The commands outside the Design tab: the typed tools, the commands made from menu items, the seven Parts 4a to 4c - // add, Part 5a's three, Part 5b's two, Part 5c's one, Part 5d's four, the seven gizmo commands and the two printing - // commands (print_start, printer_test_host). - CHECK(commands == 127); + // add, Part 5a's three, Part 5b's two, Part 5c's one, Part 5d's four, the seven gizmo commands and the six printing + // commands. + CHECK(commands == 131); // The eight commands named as their menu items keep an action of their own; the other 121 actions are items. CHECK(own == std::set{"plate_add", "plate_delete", "plate_duplicate", "plate_rename", "filament_add", "filament_delete", "undo", "redo"}); @@ -480,7 +481,7 @@ TEST_CASE("the commands outside the Design tab are the design's, under its headi commands += keys.size(); } CHECK(by_heading.size() == kPlaces.size()); - CHECK(commands == 127); + CHECK(commands == 131); // tool_search's group says which there are. const NativeCommand* search = NativeCommands::find("tool_search"); @@ -521,8 +522,8 @@ TEST_CASE("every command that runs from arguments is in the tool list, by place" // The three menu items with no argument form, which tool_search finds and tool_call runs. CHECK(unlisted == std::set{"window_save_screenshot", "script_toggle_panel", "settings_toggle_developer_mode"}); // Task 3's 98, the seven Parts 4a to 4c add, Part 5a's three, Part 5b's two, Part 5c's one, Part 5d's four, the - // seven gizmo commands and the two printing commands. - CHECK(listed.size() == 124); + // seven gizmo commands and the six printing commands. + CHECK(listed.size() == 128); // The search, the generic call and the app's state first; then each heading's commands together, in the // design's order, Driving the GUI last. @@ -544,22 +545,24 @@ TEST_CASE("every command that runs from arguments is in the tool list, by place" CHECK(group_runs(with_design, std::vector(keys.begin() + 3, keys.end())) == with_design_headings); } -TEST_CASE("only deleting a preset and uninstalling a plugin are labelled destructive", "[CommandCatalog]") +TEST_CASE("only deleting a preset, uninstalling a plugin and stopping a print are labelled destructive", "[CommandCatalog]") { // The reads: they change nothing in the app or the project. const std::set reads{"app_state", "app_wait", "app_log", "tool_search", "preset_list", "settings_list", "settings_get", "preferences_get", "plate_get_settings", "project_get_settings", "plate_list", "object_list", "window_screenshot", "plate_slice_stats", "script_search_api", "action_search", - "window_list", "widget_list", "printer_list_models", "plugin_list"}; + "window_list", "widget_list", "printer_list_models", "plugin_list", + "printer_status"}; // The commands made from menu items whose item reaches a printer, the cloud account or the network. const std::set menu_items_reaching_out{"printer_send", "preset_sync", "filament_sync_ams", "app_check_for_updates", "app_open_web_page", "plugin_refresh"}; // The plugin commands that run a plugin's code or reach the cloud account: a plugin switched on or loaded again // runs its code, a cloud plugin is downloaded, and Unsubscribe ends a subscription. const std::set plugins_reaching_out{"plugin_enable", "plugin_reload", "plugin_uninstall"}; - // The printing commands: the Print button's dialogs print on a printer, and the host test asks the print host. - const std::set printing_reaching_out{"print_start", "printer_test_host"}; + // The printing commands: the Print button's dialogs print on a printer, the host test asks the print host, and the + // job commands send the printer a command. printer_status reads what the app holds and reaches nothing. + const std::set printing_reaching_out{"print_start", "printer_test_host", "print_pause", "print_resume", "print_stop"}; std::set destructive, read_only; for (const NativeCommand& c : NativeCommands::instance().commands()) { if (c.group == Slic3r::GUI::kDesignGroup) @@ -574,7 +577,7 @@ TEST_CASE("only deleting a preset and uninstalling a plugin are labelled destruc CHECK(c.input_schema.value("type", std::string()) == "object"); } } - CHECK(destructive == std::set{"preset_delete", "plugin_uninstall"}); + CHECK(destructive == std::set{"preset_delete", "plugin_uninstall", "print_stop"}); CHECK(read_only == reads); std::set reaching_out = menu_items_reaching_out; reaching_out.insert(plugins_reaching_out.begin(), plugins_reaching_out.end()); diff --git a/tests/slic3rutils/test_device_manager_integration.cpp b/tests/slic3rutils/test_device_manager_integration.cpp index 2994ca6793..20f496243f 100644 --- a/tests/slic3rutils/test_device_manager_integration.cpp +++ b/tests/slic3rutils/test_device_manager_integration.cpp @@ -1,9 +1,25 @@ +// McpTools.hpp reaches wx's MSW headers through GLCanvas3D.hpp after OCCT has hidden the USER and GDI +// declarations they need; the Windows headers first keep them, as in test_mcp_tools.cpp. +#ifdef WIN32 + #ifndef WIN32_LEAN_AND_MEAN + #define WIN32_LEAN_AND_MEAN + #endif + #ifndef NOMINMAX + #define NOMINMAX + #endif + #include + #include +#endif + #include #include #include #include #include +#include +#include +#include #include #include "slic3r/Utils/IPrinterAgent.hpp" #include "slic3r/Utils/CloudProvider.hpp" @@ -16,6 +32,7 @@ #include #include +#include #include #include #include @@ -56,7 +73,7 @@ public: { published_device = std::move(dev_id); published_message = json::parse(json_str); - return 0; + return reply; } int send_message_to_printer(std::string dev_id, std::string json_str, int qos, int flag) override @@ -73,6 +90,7 @@ public: std::string published_device; json published_message; std::string connected_ca_file; + int reply = 0; // what a send returns: 0 when the printer took the message private: AgentInfo m_info; @@ -382,3 +400,139 @@ TEST_CASE("AMS filament settings default a supplied single-color list to type tw CHECK(payload.at("cols").get>() == colors); CHECK(payload.at("ctype") == 2); } + +namespace { + +// A printer in `state`, connected through the printer agent double, whose serial number (dev_id) is SERIAL-0123. +struct ConnectedPrinter +{ + ScopedAppConfig app_config; + std::shared_ptr agent = std::make_shared("integration-agent"); + NetworkAgent network{nullptr, agent}; + DeviceManager manager{&network, false, &app_config.config}; + MachineObject printer{&manager, &network, "Test printer", "SERIAL-0123", "192.0.2.10"}; + + explicit ConnectedPrinter(const std::string& state) + { + printer.print_status = state; + printer.dev_connection_type = "lan"; + } +}; + +// The code of the refusal of `command` to `printer`, or "" for none. +std::string refusal_code(MachineObject* printer, GUI::Ops::JobCommand command) +{ + const std::optional refusal = GUI::Ops::job_command_refusal(printer, command); + return refusal ? refusal->code : ""; +} + +} // namespace + +TEST_CASE("A job command is refused unless the printer's state allows it", "[DeviceManager][Printer]") +{ + using GUI::Ops::JobCommand; + CHECK(refusal_code(nullptr, JobCommand::Pause) == "no_printer_connected"); + CHECK(refusal_code(nullptr, JobCommand::Resume) == "no_printer_connected"); + CHECK(refusal_code(nullptr, JobCommand::Stop) == "no_printer_connected"); + + // Pause, Resume and Stop, as the Device tab enables its buttons: can_pause(), can_resume(), can_abort(). + const auto [state, pause, resume, stop] = GENERATE(table({ + {"RUNNING", "", "printer_state", ""}, + {"PAUSE", "printer_state", "", ""}, + {"IDLE", "printer_state", "printer_state", "printer_state"}, + })); + INFO(state); + ConnectedPrinter p(state); + CHECK(refusal_code(&p.printer, JobCommand::Pause) == pause); + CHECK(refusal_code(&p.printer, JobCommand::Resume) == resume); + CHECK(refusal_code(&p.printer, JobCommand::Stop) == stop); + // A refusal by the state names it. + if (const std::optional refusal = GUI::Ops::job_command_refusal(&p.printer, JobCommand::Resume)) + CHECK(refusal->args == std::vector{state}); +} + +TEST_CASE("Resume is refused where the job resumes only at the printer, and nothing is published", "[DeviceManager][Printer]") +{ + ConnectedPrinter p("PAUSE"); + // A processing task such as laser, which check_resume_condition() tells the person to resume at the printer. + p.printer.jobState_ = 2; + REQUIRE(p.printer.resume_only_at_printer()); + const GUI::Ops::Outcome sent = GUI::Ops::send_job_command(&p.printer, GUI::Ops::JobCommand::Resume); + REQUIRE_FALSE(sent); + CHECK(std::string(sent.refusal().code) == "resume_at_printer"); + CHECK(p.agent->published_message.is_null()); +} + +TEST_CASE("Pause, resume and stop publish the printer's command", "[DeviceManager][Printer]") +{ + using GUI::Ops::JobCommand; + const auto [state, command, published] = GENERATE(table({ + {"RUNNING", JobCommand::Pause, "pause"}, + {"PAUSE", JobCommand::Resume, "resume"}, + {"PAUSE", JobCommand::Stop, "stop"}, + })); + INFO(published); + ConnectedPrinter p(state); + const GUI::Ops::Outcome sent = GUI::Ops::send_job_command(&p.printer, command); + REQUIRE(sent); + CHECK(sent.value().printer == "Test printer"); + CHECK(sent.value().state == state); + CHECK(p.agent->published_device == "SERIAL-0123"); + CHECK(p.agent->published_message.at("print").at("command") == published); +} + +TEST_CASE("A job command the printer did not take is not reported sent", "[DeviceManager][Printer]") +{ + ConnectedPrinter p("RUNNING"); + p.agent->reply = -1; + const GUI::Ops::Outcome sent = GUI::Ops::send_job_command(&p.printer, GUI::Ops::JobCommand::Pause); + REQUIRE_FALSE(sent); + CHECK(std::string(sent.refusal().code) == "not_sent"); + CHECK(sent.refusal().args == std::vector{"-1"}); +} + +TEST_CASE("A command the printer's agent cannot send is named unsupported", "[DeviceManager][Printer]") +{ + CHECK(std::string(GUI::Ops::job_command_failure(ORCA_NETWORK_ERR_CMD_NOT_SUPPORTED).code) == "command_not_supported"); + CHECK(std::string(GUI::Ops::job_command_failure(ORCA_NETWORK_ERR_CAP_NOT_AVAILABLE).code) == "command_not_supported"); + CHECK(std::string(GUI::Ops::job_command_failure(-1).code) == "not_sent"); +} + +TEST_CASE("The printer's status is read from the machine, publishes nothing and leaves out its serial number", "[DeviceManager][Printer]") +{ + CHECK(GUI::Mcp::printer_status_reply(GUI::Ops::printer_status(nullptr)) == json{{"connected", false}}); + + ConnectedPrinter p("RUNNING"); + p.printer.printer_type = "test-model"; + p.printer.mc_print_stage = 2; + p.printer.mc_print_percent = 42; + p.printer.mc_left_time = 600; + p.printer.curr_layer = 3; + p.printer.total_layers = 100; + p.printer.subtask_name = "cube"; + p.printer.print_error = 0; + const json reply = GUI::Mcp::printer_status_reply(GUI::Ops::printer_status(&p.printer)); + INFO(reply.dump()); + CHECK(reply.at("connected") == true); + CHECK(reply.at("name") == "Test printer"); + CHECK(reply.at("printer_type") == "test-model"); + // No preset bundle and no printer file names the model, so it is unknown. + CHECK(reply.at("model").is_null()); + CHECK(reply.at("state") == "RUNNING"); + CHECK(reply.at("stage") == 2); + CHECK(reply.at("percent") == 42); + CHECK(reply.at("remaining_seconds") == 600); + CHECK(reply.at("layer") == 3); + CHECK(reply.at("total_layers") == 100); + CHECK(reply.at("file") == "cube"); + CHECK(reply.at("error_code") == 0); + CHECK(reply.at("temperatures").at("nozzles").is_array()); + CHECK(reply.at("temperatures").contains("bed")); + CHECK(reply.at("temperatures").contains("chamber")); + CHECK(reply.dump().find("SERIAL-0123") == std::string::npos); + CHECK(p.agent->published_message.is_null()); + + // A model the tab names without a bundle. + p.printer.printer_type = "orcasonar"; + CHECK(GUI::Ops::printer_model_name(p.printer, nullptr) == "OrcaSonar Printer"); +} diff --git a/tests/slic3rutils/test_mcp_cad.cpp b/tests/slic3rutils/test_mcp_cad.cpp index 07d6c45c83..33ab4d5d3b 100644 --- a/tests/slic3rutils/test_mcp_cad.cpp +++ b/tests/slic3rutils/test_mcp_cad.cpp @@ -1951,8 +1951,9 @@ TEST_CASE("every example passes its command's schema", "[Mcp][CAD]") // The 83 Design commands with a silent form, undo and redo, the six object and part commands of Parts 4a and 4b, // Part 4c's filament_add_mixed, Part 5a's printer_list_models, printer_install and printer_uninstall, Part 5b's // filament_install and filament_uninstall, Part 5c's preferences_set, Part 5d's plugin_list, plugin_enable, - // plugin_reload and plugin_uninstall, the seven gizmo commands, and print_start and printer_test_host. - CHECK(described == 111); + // plugin_reload and plugin_uninstall, the seven gizmo commands, and the six printing commands (print_start, + // printer_test_host, printer_status, print_pause, print_resume and print_stop). + CHECK(described == 115); } TEST_CASE("an example's argument goes by a name its command takes", "[Mcp][CAD]") diff --git a/tests/slic3rutils/test_mcp_tools.cpp b/tests/slic3rutils/test_mcp_tools.cpp index 44c13aba9b..12cf535269 100644 --- a/tests/slic3rutils/test_mcp_tools.cpp +++ b/tests/slic3rutils/test_mcp_tools.cpp @@ -650,14 +650,14 @@ TEST_CASE("a tool of the old vocabulary is no command", "[Mcp]") CHECK(first_sentence(command->description) == r.first_sentence); } - // Outside the Design group 124 commands are listed: every one that runs from its arguments, all but the three menu + // Outside the Design group 128 commands are listed: every one that runs from its arguments, all but the three menu // items that take none (Task 3's 98, the seven Parts 4a to 4c add, Part 5a's three, Part 5b's two, Part 5c's one, - // Part 5d's four, the seven gizmo commands and the two printing commands). + // Part 5d's four, the seven gizmo commands and the six printing commands). std::size_t listed = 0; for (const NativeCommand& c : catalog.commands()) if (c.listed && c.group != Slic3r::GUI::kDesignGroup) ++listed; - CHECK(listed == 124); + CHECK(listed == 128); } TEST_CASE("opening a project and importing models are two commands", "[Mcp]") diff --git a/tests/slic3rutils/test_operations.cpp b/tests/slic3rutils/test_operations.cpp index dfbb9562c2..1949aa4f8e 100644 --- a/tests/slic3rutils/test_operations.cpp +++ b/tests/slic3rutils/test_operations.cpp @@ -2058,7 +2058,7 @@ const std::set kOperations = { "printer_models", "install_printers", "uninstall_printers", "install_filaments", "uninstall_filaments", "set_preferences", "set_plugin_enabled", "uninstall_plugin", "reload_plugin", "start_plugin_refresh", "reorder_objects", "sync_filaments_from_ams", "open_gizmo", "cut_object", - "lay_on_face", "set_brim_ears", "test_print_host", + "lay_on_face", "set_brim_ears", "test_print_host", "send_job_command", }; // What an exception is, so that the reason reads the same for every entry of a kind. diff --git a/tools/mcp/TESTS.md b/tools/mcp/TESTS.md index d214e41f28..0c972326df 100644 --- a/tools/mcp/TESTS.md +++ b/tools/mcp/TESTS.md @@ -120,13 +120,13 @@ until they leave the sweep. | [Gizmos and canvas input](test-entries/gizmos.md) | [`test_gizmos`](test-entries/gizmos.md#test_gizmos), [`test_gizmo_commands`](test-entries/gizmos.md#test_gizmo_commands) | — | | [GUI automation tools](test-entries/gui_tools.md) | [`test_gui_tools`](test-entries/gui_tools.md#test_gui_tools), [`test_recording`](test-entries/gui_tools.md#test_recording), [`test_call_forms`](test-entries/gui_tools.md#test_call_forms) | — | | [Commands, preferences, installs and plugins](test-entries/commands.md) | [`test_every_action`](test-entries/commands.md#test_every_action), [`test_menu_items_refusals`](test-entries/commands.md#test_menu_items_refusals), [`test_additions_refusals`](test-entries/commands.md#test_additions_refusals), [`test_person_forms`](test-entries/commands.md#test_person_forms), [`test_preferences`](test-entries/commands.md#test_preferences), [`test_install_printers`](test-entries/commands.md#test_install_printers), [`test_install_filaments`](test-entries/commands.md#test_install_filaments), [`test_plugin_commands`](test-entries/commands.md#test_plugin_commands), [`test_plugin_tools`](test-entries/commands.md#test_plugin_tools), [`test_operation_routes`](test-entries/commands.md#test_operation_routes) | — | -| [Windows, views, printers and web pages](test-entries/windows_web.md) | [`test_printer_extruders`](test-entries/windows_web.md#test_printer_extruders), [`test_project_open_settings`](test-entries/windows_web.md#test_project_open_settings), [`test_sidebar_floating`](test-entries/windows_web.md#test_sidebar_floating), [`test_set_window`](test-entries/windows_web.md#test_set_window), [`test_set_view_preview`](test-entries/windows_web.md#test_set_view_preview), [`test_set_view_camera`](test-entries/windows_web.md#test_set_view_camera), [`test_speed_dial_open`](test-entries/windows_web.md#test_speed_dial_open), [`test_send_gcode`](test-entries/windows_web.md#test_send_gcode), [`test_web_ui`](test-entries/windows_web.md#test_web_ui), [`test_webview_modal`](test-entries/windows_web.md#test_webview_modal) | — | +| [Windows, views, printers and web pages](test-entries/windows_web.md) | [`test_printer_extruders`](test-entries/windows_web.md#test_printer_extruders), [`test_project_open_settings`](test-entries/windows_web.md#test_project_open_settings), [`test_sidebar_floating`](test-entries/windows_web.md#test_sidebar_floating), [`test_set_window`](test-entries/windows_web.md#test_set_window), [`test_set_view_preview`](test-entries/windows_web.md#test_set_view_preview), [`test_set_view_camera`](test-entries/windows_web.md#test_set_view_camera), [`test_speed_dial_open`](test-entries/windows_web.md#test_speed_dial_open), [`test_send_gcode`](test-entries/windows_web.md#test_send_gcode), [`test_printer_commands`](test-entries/windows_web.md#test_printer_commands), [`test_web_ui`](test-entries/windows_web.md#test_web_ui), [`test_webview_modal`](test-entries/windows_web.md#test_webview_modal) | — | | [Runtime, command line and harness](test-entries/runtime.md) | [`test_command_line`](test-entries/runtime.md#test_command_line), [`test_runtime_lifecycle`](test-entries/runtime.md#test_runtime_lifecycle), [`test_stdio_bridge`](test-entries/runtime.md#test_stdio_bridge), [`test_orca_mcp_attach`](test-entries/runtime.md#test_orca_mcp_attach), [`test_run_sweep`](test-entries/runtime.md#test_run_sweep), [`test_recovery_under_load`](test-entries/runtime.md#test_recovery_under_load), [`test_worker_admission`](test-entries/runtime.md#test_worker_admission), [`test_cancel_pending_slice`](test-entries/runtime.md#test_cancel_pending_slice), [`test_export_running_job`](test-entries/runtime.md#test_export_running_job), [`test_action_replay_hidden`](test-entries/runtime.md#test_action_replay_hidden), [`test_list_windows`](test-entries/runtime.md#test_list_windows), [`test_ref_locator_export`](test-entries/runtime.md#test_ref_locator_export) | [`smoke_test`](test-entries/runtime.md#smoke_test) | | [Design tab](test-entries/design.md) | [`test_cad_replay`](test-entries/design.md#test_cad_replay), [`test_cad_slow_build`](test-entries/design.md#test_cad_slow_build), [`test_cad_failed_job`](test-entries/design.md#test_cad_failed_job), [`test_cad_examples`](test-entries/design.md#test_cad_examples), [`test_cad_click_edit`](test-entries/design.md#test_cad_click_edit), [`test_cad_commands`](test-entries/design.md#test_cad_commands), [`test_cad_sketching`](test-entries/design.md#test_cad_sketching), [`test_cad_context_menu`](test-entries/design.md#test_cad_context_menu) | [`cad_sketch_to_solid`](test-entries/design.md#cad_sketch_to_solid), [`cad_sketch_edit`](test-entries/design.md#cad_sketch_edit), [`cad_topology_targets`](test-entries/design.md#cad_topology_targets), [`cad_features`](test-entries/design.md#cad_features), [`cad_doc`](test-entries/design.md#cad_doc), [`cad_canvas`](test-entries/design.md#cad_canvas) | ## All tests -The 61 tests `sweep.json` lists: 45 Strong, 14 Partial, 2 Smoke. +The 62 tests `sweep.json` lists: 45 Strong, 15 Partial, 2 Smoke. | Test | Area | Kind | Strength | |---|---|---|---| @@ -162,6 +162,7 @@ The 61 tests `sweep.json` lists: 45 Strong, 14 Partial, 2 Smoke. | [`test_set_view_camera`](test-entries/windows_web.md#test_set_view_camera) | [Windows, views, printers and web pages](test-entries/windows_web.md) | Python | Partial | | [`test_speed_dial_open`](test-entries/windows_web.md#test_speed_dial_open) | [Windows, views, printers and web pages](test-entries/windows_web.md) | Python | Partial | | [`test_send_gcode`](test-entries/windows_web.md#test_send_gcode) | [Windows, views, printers and web pages](test-entries/windows_web.md) | Python | Strong | +| [`test_printer_commands`](test-entries/windows_web.md#test_printer_commands) | [Windows, views, printers and web pages](test-entries/windows_web.md) | Python | Partial | | [`test_web_ui`](test-entries/windows_web.md#test_web_ui) | [Windows, views, printers and web pages](test-entries/windows_web.md) | Python | Strong | | [`test_webview_modal`](test-entries/windows_web.md#test_webview_modal) | [Windows, views, printers and web pages](test-entries/windows_web.md) | Python | Partial | | [`test_command_line`](test-entries/runtime.md#test_command_line) | [Runtime, command line and harness](test-entries/runtime.md) | Python | Strong | diff --git a/tools/mcp/sweep.json b/tools/mcp/sweep.json index 86ea46979d..647a983342 100644 --- a/tools/mcp/sweep.json +++ b/tools/mcp/sweep.json @@ -51,6 +51,7 @@ "test_menu_items_refusals": {"path": "test_menu_items_refusals.py"}, "test_run_sweep": {"path": "test_run_sweep.py", "launch": "none"}, "test_runtime_lifecycle": {"path": "test_runtime_lifecycle.py", "launch": "own", "args": ["--bin", "{bin}"], "locks": ["port-13694"], "why": "both serve on the fixed port 13694"}, + "test_printer_commands": {"path": "test_printer_commands.py"}, "test_send_gcode": {"path": "test_send_gcode.py"}, "test_set_view_camera": {"path": "test_set_view_camera.py", "cad": true}, "test_set_view_preview": {"path": "test_set_view_preview.py"}, diff --git a/tools/mcp/test_printer_commands.py b/tools/mcp/test_printer_commands.py new file mode 100644 index 0000000000..ee6ba6d838 --- /dev/null +++ b/tools/mcp/test_printer_commands.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python3 +"""printer_status, print_pause, print_resume and print_stop with no printer connected, as the test_printer_commands +entry of tools/mcp/test-entries/windows_web.md designs them. + + tools/mcp/orca_mcp.py launch + tools/mcp/test_printer_commands.py + +A scratch datadir is not cut off from the account it may be signed in to, so the test reads printer_status first and +goes on only when it says no printer is connected: otherwise it fails, naming the printer it found, and calls nothing +else. Then each job command is refused no_printer_connected, and printer_status still reads no printer and no dialog +is open. It sends nothing to any printer, and exits 0 when every check passes. +""" + +import os +import sys + +sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) +import orca_mcp # noqa: E402 +from checks import Checks, dialogs # noqa: E402 + +NO_PRINTER = {"connected": False} + + +def main(): + client, _session = orca_mcp.session_client() + t = Checks() + + # The guard: no job command is called while a printer is connected. + status = client.call("printer_status") + if not t.equal("no printer is connected", status, NO_PRINTER): + print(f"printer_status found {status.get('name')!r} ({status.get('model')!r}); the test calls nothing else", flush=True) + return t.exit_code() + + for command in ("print_pause", "print_resume", "print_stop"): + t.refused(f"{command}: refused", lambda: client.call(command), code="no_printer_connected") + t.equal(f"{command}: printer_status still reads no printer", client.call("printer_status"), NO_PRINTER) + t.equal(f"{command}: no dialog", dialogs(client), []) + return t.exit_code() + + +if __name__ == "__main__": + sys.exit(main())