Files
OrcaSlicer/tools/mcp/tests/layers.json
T
SoftFever d64e10f4dd Regroup the slicer's MCP commands and let each run from its arguments
Outside the Design tab an agent had 175 commands, 50 of them in the tool
list. There are now 118, named by what they act on (`object_`, `plate_`,
`preset_`, `filament_`, `plugin_` and so on), and 115 are listed. Each takes
its target and values in the call, acts on the selection when it names no
target and says what it acted on; an old name is refused. Printers and
system filaments install and uninstall, preferences read and write, plugins
enable, reload, uninstall and refresh, and objects reorder, with no dialog
to drive.

The Speed Dial keeps its 129 tiles under the same ids. Eight defects in the
rows these commands share with the menus are fixed. For a person: an object
row that cannot run says why instead of "Select an object first.", rows
that failed no longer claim success, Duplicate Plate can be undone, and
Refresh Plugins picked while a refresh runs now runs after it instead of
beside it.
2026-11-18 16:50:32 +08:00

241 lines
19 KiB
JSON

// Layer-based edits: height range modifiers set with object_set_height_ranges and their settings with settings_set
// (target height_range), and variable layer height profiles set with object_set_variable_layer_height, read back
// through object_list, each change undone in one step,
// sliced, and kept by a 3MF; and a plate's layer G-codes set with plate_set_custom_gcode, read back from its
// replies, edited, sliced, and kept by a 3MF. Run on a live app:
// python3 tools/mcp/orca_mcp.py run-replay tools/mcp/tests/layers.json --out <dir>
// A refusal can't be asserted directly (a failed step stops the run), so each one is an optional
// step followed by a check that nothing changed.
{
"orca_replay_version": "0.2.0",
"name": "layer-based edits",
"vars": {"cube": "${replay_dir}/../../../resources/handy_models/OrcaCube_v2.drc",
"benchy": "${replay_dir}/../../../resources/handy_models/3DBenchy.drc"},
"steps": [
{"tool": "app_wait", "args": {"for": "ready"}},
{"tool": "project_new", "args": {"discard_changes": true}},
{"tool": "window_set", "args": {"size": [1600, 900]}},
{"tool": "view_set", "args": {"tab": "prepare"}},
{"tool": "project_import", "args": {"paths": ["${vars.cube}"]}, "expect": {"/added": {"eq": 1}}},
{"tool": "object_transform", "args": {"object": 0, "size": [20, 20, 20]}},
{"tool": "settings_set", "args": {"type": "process", "values": {"layer_height": 0.2, "initial_layer_print_height": 0.2}}},
{"tool": "object_list", "expect": {"/plates/0/objects/0/layer_config_ranges": {"exists": false}}},
// ---- Two ranges, given in any order, at the object's layer height and filament; then the lower half at 40 %
// infill, the upper half at 0.1 mm ----
{"tool": "object_set_height_ranges",
"args": {"object": 0, "ranges": [{"min_z": 10, "max_z": 20}, {"min_z": 0, "max_z": 10}]},
"expect": {"/height": {"ge": 19.99, "le": 20.01},
"/layer_config_ranges/0/max_z": {"eq": 10},
"/layer_config_ranges/0/values/layer_height": {"eq": "0.2"},
"/layer_config_ranges/1/min_z": {"eq": 10},
"/layer_config_ranges/1/values/layer_height": {"eq": "0.2"},
"/layer_config_ranges/1/values/extruder": {"eq": "0"},
"/warnings": {"exists": false}}},
{"tool": "settings_set", "args": {"target": "height_range", "object": 0, "min_z": 0, "max_z": 10,
"values": {"sparse_infill_density": "40%"}},
"expect": {"/applied/sparse_infill_density": {"eq": "40%"}, "/height_range/max_z": {"eq": 10}}},
{"tool": "settings_set", "args": {"target": "height_range", "object": 0, "min_z": 10, "max_z": 20, "values": {"layer_height": 0.1}},
"expect": {"/applied/layer_height": {"eq": "0.1"}, "/height_range/min_z": {"eq": 10}}},
{"tool": "object_list", "expect": {"/plates/0/objects/0/layer_config_ranges/0/values/sparse_infill_density": {"eq": "40%"},
"/plates/0/objects/0/layer_config_ranges/1/values/layer_height": {"eq": "0.1"},
"/plates/0/objects/0/layer_config_ranges/2": {"exists": false}}},
// Ranges are not the object's own overrides.
{"tool": "settings_get", "args": {"target": "object", "object": 0, "keys": ["sparse_infill_density"], "include_meta": false},
"expect": {"/items/0/value": {"eq": null}}},
// ---- Each change one undo step; the same ranges again keep their settings and add none ----
{"tool": "action_run", "args": {"id": "orca_command:undo:orca"}},
{"tool": "object_list", "expect": {"/plates/0/objects/0/layer_config_ranges/1/values/layer_height": {"eq": "0.2"},
"/plates/0/objects/0/layer_config_ranges/0/values/sparse_infill_density": {"eq": "40%"}}},
{"tool": "action_run", "args": {"id": "orca_command:redo:orca"}},
{"tool": "object_set_height_ranges",
"args": {"object": 0, "ranges": [{"min_z": 0, "max_z": 10}, {"min_z": 10, "max_z": 20}]},
"expect": {"/layer_config_ranges/0/values/sparse_infill_density": {"eq": "40%"},
"/layer_config_ranges/1/values/layer_height": {"eq": "0.1"}}},
{"tool": "action_run", "args": {"id": "orca_command:undo:orca"}},
{"tool": "object_list", "expect": {"/plates/0/objects/0/layer_config_ranges/1/values/layer_height": {"eq": "0.2"}}},
{"tool": "action_run", "args": {"id": "orca_command:redo:orca"}},
{"tool": "object_list", "expect": {"/plates/0/objects/0/layer_config_ranges/1/values/layer_height": {"eq": "0.1"}}},
// ---- The slicer prints them: 50 layers of 0.2 mm, then 100 of 0.1 mm ----
{"tool": "plate_slice", "expect": {"/status": {"eq": "done"}, "/plates/0/outcome": {"eq": "ok"}}},
{"tool": "view_set", "args": {"tab": "preview", "layer": 1}, "expect": {"/layers/2": {"ge": 149, "le": 151}}},
// ---- Refusals change nothing: an overlap, a layer height beyond the printer's, a filament the
// project lacks, an object setting, an empty range ----
{"tool": "object_set_height_ranges", "args": {"object": 0, "ranges": [{"min_z": 0, "max_z": 15}, {"min_z": 12, "max_z": 20}]},
"optional": true},
{"tool": "settings_set", "args": {"target": "height_range", "object": 0, "min_z": 0, "max_z": 10, "values": {"layer_height": 0.5}},
"optional": true},
{"tool": "settings_set", "args": {"target": "height_range", "object": 0, "min_z": 0, "max_z": 10, "values": {"extruder": 9}},
"optional": true},
{"tool": "settings_set", "args": {"target": "height_range", "object": 0, "min_z": 0, "max_z": 10, "values": {"enable_support": true}},
"optional": true},
{"tool": "object_set_height_ranges", "args": {"object": 0, "ranges": [{"min_z": 5, "max_z": 5}]}, "optional": true},
{"tool": "object_list", "expect": {"/plates/0/objects/0/layer_config_ranges/0/max_z": {"eq": 10},
"/plates/0/objects/0/layer_config_ranges/0/values/layer_height": {"eq": "0.2"},
"/plates/0/objects/0/layer_config_ranges/0/values/extruder": {"eq": "0"},
"/plates/0/objects/0/layer_config_ranges/0/values/enable_support": {"exists": false},
"/plates/0/objects/0/layer_config_ranges/1/values/layer_height": {"eq": "0.1"},
"/plates/0/objects/0/layer_config_ranges/2": {"exists": false}}},
// ---- A range printed with the second filament, above the object's top ----
{"tool": "view_set", "args": {"tab": "prepare"}},
{"tool": "widget_click", "args": {"target": {"label": "Add one filament"}}},
{"tool": "object_set_height_ranges",
"args": {"object": 0, "ranges": [{"min_z": 0, "max_z": 10}, {"min_z": 10, "max_z": 20}, {"min_z": 20, "max_z": 30}]},
"expect": {"/height": {"le": 20.01}, "/layer_config_ranges/0/values/sparse_infill_density": {"eq": "40%"},
"/layer_config_ranges/2/values/extruder": {"eq": "0"}}},
{"tool": "settings_set", "args": {"target": "height_range", "object": 0, "min_z": 20, "max_z": 30, "values": {"extruder": 2}},
"expect": {"/applied/extruder": {"eq": "2"}}},
// ---- A 3MF keeps them ----
{"tool": "project_save", "args": {"path": "${out_dir}/layers.3mf", "overwrite": true}},
{"tool": "project_new", "args": {"discard_changes": true}},
// Loading a project asks about preset edits an earlier replay left; the project brings its own.
{"tool": "dialog_auto_answer", "args": {"rules": [{"match": "unsaved changes", "button": "Discard"}]}},
{"tool": "project_open", "args": {"path": "${out_dir}/layers.3mf", "discard_changes": true}},
{"tool": "object_list", "expect": {"/plates/0/objects/0/layer_config_ranges/0/values/sparse_infill_density": {"eq": "40%"},
"/plates/0/objects/0/layer_config_ranges/1/values/layer_height": {"eq": "0.1"},
"/plates/0/objects/0/layer_config_ranges/2/values/extruder": {"eq": "2"}}},
// ---- [] removes them all ----
{"tool": "object_set_height_ranges", "args": {"object": 0, "ranges": []}, "expect": {"/layer_config_ranges": {"eq": []}}},
{"tool": "object_list", "expect": {"/plates/0/objects/0/layer_config_ranges": {"exists": false}}},
{"tool": "plate_slice", "expect": {"/status": {"eq": "done"}, "/plates/0/outcome": {"eq": "ok"}}},
{"tool": "view_set", "args": {"tab": "preview", "layer": 1}, "expect": {"/layers/2": {"eq": 100}}},
// ---- Variable layer height on a Benchy (48 mm; 240 layers at 0.2 mm), called from the Preview tab ----
{"tool": "project_new", "args": {"discard_changes": true}},
{"tool": "project_import", "args": {"paths": ["${vars.benchy}"]}, "expect": {"/added": {"eq": 1}}},
{"tool": "settings_set", "args": {"type": "process", "values": {"layer_height": 0.2, "initial_layer_print_height": 0.2}}},
{"tool": "object_list", "expect": {"/plates/0/objects/0/layer_height_profile": {"exists": false}}},
{"tool": "plate_slice", "expect": {"/status": {"eq": "done"}, "/plates/0/outcome": {"eq": "ok"}}},
{"tool": "object_set_variable_layer_height", "args": {"object": 0, "action": "adaptive"},
"expect": {"/height": {"ge": 47.99, "le": 48.01},
"/layer_height_profile/points": {"gt": 250},
"/layer_height_profile/min_height": {"lt": 0.2},
"/layer_height_profile/max_height": {"gt": 0.2},
"/warnings": {"exists": false}}},
{"tool": "app_state", "expect": {"/tab": {"eq": "prepare"}}},
{"tool": "object_list", "expect": {"/plates/0/objects/0/layer_height_profile/points": {"gt": 250}}},
// Toward quality more layers, toward speed fewer.
{"tool": "object_set_variable_layer_height", "args": {"object": 0, "action": "adaptive", "quality": 0},
"expect": {"/layer_height_profile/points": {"gt": 380}}},
{"tool": "object_set_variable_layer_height", "args": {"object": 0, "action": "adaptive", "quality": 1},
"expect": {"/layer_height_profile/points": {"lt": 320}}},
// The slicer prints the profile, not 240 layers of 0.2 mm.
{"tool": "plate_slice", "expect": {"/status": {"eq": "done"}, "/plates/0/outcome": {"eq": "ok"}}},
{"tool": "view_set", "args": {"tab": "preview", "layer": 1}, "expect": {"/layers/2": {"gt": 245}}},
// ---- Smooth is one undo step; Reset removes the profile, and again changes nothing ----
{"tool": "object_set_variable_layer_height", "args": {"object": 0, "action": "smooth", "radius": 10, "keep_min": true},
"expect": {"/layer_height_profile/max_height": {"lt": 0.28}}},
{"tool": "action_run", "args": {"id": "orca_command:undo:orca"}},
{"tool": "object_list", "expect": {"/plates/0/objects/0/layer_height_profile/max_height": {"eq": 0.28}}},
{"tool": "action_run", "args": {"id": "orca_command:redo:orca"}},
{"tool": "object_list", "expect": {"/plates/0/objects/0/layer_height_profile/max_height": {"lt": 0.28}}},
{"tool": "object_set_variable_layer_height", "args": {"object": 0, "action": "reset"}, "expect": {"/layer_height_profile": {"exists": false}}},
{"tool": "object_list", "expect": {"/plates/0/objects/0/layer_height_profile": {"exists": false}}},
{"tool": "object_set_variable_layer_height", "args": {"object": 0, "action": "reset"}},
{"tool": "action_run", "args": {"id": "orca_command:undo:orca"}},
{"tool": "object_list", "expect": {"/plates/0/objects/0/layer_height_profile/max_height": {"lt": 0.28}}},
{"tool": "object_set_variable_layer_height", "args": {"object": 0, "action": "reset"}},
// ---- Refusals change nothing: an argument of another action, the assemble view ----
{"tool": "object_set_variable_layer_height", "args": {"object": 0, "action": "smooth", "quality": 0.3}, "optional": true},
{"tool": "view_set", "args": {"canvas": "assemble"}},
{"tool": "object_set_variable_layer_height", "args": {"object": 0, "action": "adaptive"}, "optional": true},
{"tool": "view_set", "args": {"canvas": "3d"}},
{"tool": "object_list", "expect": {"/plates/0/objects/0/layer_height_profile": {"exists": false}}},
// ---- With height ranges: Smooth starts from the ranges' heights, Adaptive keeps them inside each
// range, and the profile then decides ----
{"tool": "object_set_height_ranges",
"args": {"object": 0, "ranges": [{"min_z": 0, "max_z": 20}, {"min_z": 20, "max_z": 48}]}},
{"tool": "settings_set", "args": {"target": "height_range", "object": 0, "min_z": 0, "max_z": 20, "values": {"layer_height": 0.12}}},
{"tool": "settings_set", "args": {"target": "height_range", "object": 0, "min_z": 20, "max_z": 48, "values": {"layer_height": 0.28}}},
{"tool": "object_set_variable_layer_height", "args": {"object": 0, "action": "smooth"},
"expect": {"/layer_height_profile/min_height": {"eq": 0.12},
"/layer_height_profile/max_height": {"eq": 0.28},
"/warnings/0": {"contains": "decides its layer heights"}}},
{"tool": "object_set_variable_layer_height", "args": {"object": 0, "action": "adaptive", "quality": 0},
"expect": {"/layer_height_profile/min_height": {"eq": 0.12}}},
{"tool": "object_list", "expect": {"/plates/0/objects/0/layer_config_ranges/1/values/layer_height": {"eq": "0.28"},
"/plates/0/objects/0/layer_height_profile/min_height": {"eq": 0.12}}},
// ---- A 3MF keeps the profile ----
{"tool": "project_save", "args": {"path": "${out_dir}/profile.3mf", "overwrite": true}},
{"tool": "project_new", "args": {"discard_changes": true}},
{"tool": "project_open", "args": {"path": "${out_dir}/profile.3mf", "discard_changes": true}},
{"tool": "object_list", "expect": {"/plates/0/objects/0/layer_height_profile/min_height": {"eq": 0.12},
"/plates/0/objects/0/layer_height_profile/points": {"gt": 100}}},
{"tool": "plate_slice", "expect": {"/status": {"eq": "done"}, "/plates/0/outcome": {"eq": "ok"}}},
// ---- Layer G-codes on a 20 mm cube of 100 layers of 0.2 mm: none before a slice ----
{"tool": "project_new", "args": {"discard_changes": true}},
{"tool": "project_import", "args": {"paths": ["${vars.cube}"]}, "expect": {"/added": {"eq": 1}}},
{"tool": "object_transform", "args": {"object": 0, "size": [20, 20, 20]}},
{"tool": "settings_set", "args": {"type": "process", "values": {"layer_height": 0.2, "initial_layer_print_height": 0.2}}},
{"tool": "plate_set_custom_gcode", "args": {"add": [{"layer": 26, "type": "pause"}]}, "optional": true},
{"tool": "app_state", "expect": {"/tab": {"eq": "prepare"}, "/slicing": {"eq": false}}},
{"tool": "plate_slice", "expect": {"/status": {"eq": "done"}, "/plates/0/outcome": {"eq": "ok"}}},
// ---- From Prepare: a pause by layer and custom G-code by a height between layers, which goes on
// the layer whose top is above it; the call shows the Preview ----
{"tool": "view_set", "args": {"tab": "prepare"}},
{"tool": "plate_set_custom_gcode", "args": {"add": [{"layer": 26, "type": "pause"}, {"z": 10.1, "type": "custom", "gcode": "M104 S215"}]},
"expect": {"/plate": {"eq": 0}, "/layers": {"eq": 100}, "/changed": {"eq": true},
"/layer_gcode/0/type": {"eq": "pause"}, "/layer_gcode/0/layer": {"eq": 26}, "/layer_gcode/0/z": {"eq": 5.2},
"/layer_gcode/1/type": {"eq": "custom"}, "/layer_gcode/1/layer": {"eq": 51}, "/layer_gcode/1/z": {"eq": 10.2},
"/layer_gcode/1/gcode": {"eq": "M104 S215"}, "/layer_gcode/2": {"exists": false},
"/note": {"contains": "slice it again"}}},
{"tool": "app_state", "expect": {"/tab": {"eq": "preview"}, "/project/dirty": {"eq": true}}},
// ---- The plate stays editable while the Preview shows it: the same codes change nothing, and in one
// call the pause goes (by its height) and the custom text is replaced ----
{"tool": "plate_set_custom_gcode", "args": {"add": [{"z": 5.2, "type": "pause"}]},
"expect": {"/changed": {"eq": false}, "/layer_gcode/0/layer": {"eq": 26}, "/layer_gcode/1/layer": {"eq": 51}}},
{"tool": "plate_set_custom_gcode", "args": {"remove": [{"z": 5.2}], "add": [{"layer": 51, "type": "custom", "gcode": "M104 S220"}]},
"expect": {"/changed": {"eq": true}, "/layer_gcode/0/layer": {"eq": 51}, "/layer_gcode/0/gcode": {"eq": "M104 S220"},
"/layer_gcode/1": {"exists": false}}},
// ---- Refusals change nothing: a layer above the top, another code where one is, nothing to remove,
// a filament the project lacks (it has the two the height ranges above used), a plate it lacks ----
{"tool": "plate_set_custom_gcode", "args": {"add": [{"layer": 101, "type": "pause"}]}, "optional": true},
{"tool": "plate_set_custom_gcode", "args": {"add": [{"layer": 51, "type": "pause"}]}, "optional": true},
{"tool": "plate_set_custom_gcode", "args": {"remove": [{"layer": 30}]}, "optional": true},
{"tool": "plate_set_custom_gcode", "args": {"add": [{"layer": 30, "type": "change_filament", "filament": 9}]}, "optional": true},
{"tool": "plate_set_custom_gcode", "args": {"plate": 1, "add": [{"layer": 30, "type": "pause"}]}, "optional": true},
{"tool": "plate_set_custom_gcode", "args": {"add": [{"layer": 51, "type": "custom", "gcode": "M104 S220"}]},
"expect": {"/changed": {"eq": false}, "/layer_gcode/0/gcode": {"eq": "M104 S220"}, "/layer_gcode/1": {"exists": false}}},
// ---- Changed since its slice and not shown: refused without starting a slice ----
{"tool": "view_set", "args": {"tab": "prepare"}},
{"tool": "plate_set_custom_gcode", "args": {"add": [{"layer": 30, "type": "pause"}]}, "optional": true},
{"tool": "app_state", "expect": {"/tab": {"eq": "prepare"}, "/slicing": {"eq": false}}},
// ---- A filament change to the second filament ----
{"tool": "plate_slice", "expect": {"/status": {"eq": "done"}, "/plates/0/outcome": {"eq": "ok"}}},
{"tool": "plate_set_custom_gcode", "args": {"add": [{"layer": 76, "type": "change_filament", "filament": 2}]},
"expect": {"/layer_gcode/0/layer": {"eq": 51}, "/layer_gcode/1/layer": {"eq": 76}, "/layer_gcode/1/z": {"eq": 15.2},
"/layer_gcode/1/type": {"eq": "change_filament"}, "/layer_gcode/1/filament": {"eq": 2},
"/layer_gcode/1/color": {"exists": true}}},
{"tool": "plate_slice", "expect": {"/status": {"eq": "done"}, "/plates/0/outcome": {"eq": "ok"}}},
// ---- A 3MF keeps them ----
{"tool": "project_save", "args": {"path": "${out_dir}/layer_gcode.3mf", "overwrite": true}},
{"tool": "project_new", "args": {"discard_changes": true}},
{"tool": "project_open", "args": {"path": "${out_dir}/layer_gcode.3mf", "discard_changes": true}},
{"tool": "plate_slice", "expect": {"/status": {"eq": "done"}, "/plates/0/outcome": {"eq": "ok"}}},
{"tool": "plate_set_custom_gcode", "args": {"add": [{"layer": 76, "type": "change_filament", "filament": 2}]},
"expect": {"/changed": {"eq": false}, "/layer_gcode/0/gcode": {"eq": "M104 S220"},
"/layer_gcode/1/filament": {"eq": 2}, "/layer_gcode/2": {"exists": false}}},
// ---- clear removes them all ----
{"tool": "plate_set_custom_gcode", "args": {"clear": true}, "expect": {"/changed": {"eq": true}, "/layer_gcode": {"eq": []}}},
{"tool": "plate_slice", "expect": {"/status": {"eq": "done"}, "/plates/0/outcome": {"eq": "ok"}}}
]
}