Files
OrcaSlicer/tests/slic3rutils/CMakeLists.txt
9b886b5346 Resource printer asset plugins for portable bed models and textures, with a printer preset plugin manifest (#16814)
* fix(plugins): show missing-plugin notices on preset switch; printer plugin manifest

Missing-plugin notices were rebuilt only when a plate was validated, so
switching to a preset that needs an absent plugin showed nothing on an
empty plate, and new_project() removed the notices for good (their
shown-signature stayed set). They are now refreshed on every preset
change, when a plugin loads, unloads, is disabled, deleted or
unsubscribed, and after a new project, and pushed again whenever they
are no longer on screen.

Printer presets get their own manifest key, printer_plugins: the full
print config applies the printer preset after the process preset, so a
shared "plugins" key would replace the process manifest, and printer
presets dropped "plugins" on load. Plugins referenced by the printer
preset (e.g. a Python printer agent) are reported but never block
slicing, since they do not change the sliced result. Saving a preset on
a machine that lacks one of its plugins keeps that plugin's manifest
entry, so other machines are still offered it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* feat(plugins): resource printer asset plugins for portable bed models and textures

A printer preset's bed_custom_model / bed_custom_texture hold the
author's absolute local paths, so the custom bed is lost on every other
machine and for every bundle subscriber (#15217). A resource printer
asset plugin is a pack of bed models (.stl) and textures (.png/.svg)
installed like a resource texture pack; the preset then stores a
portable reference, orcacloud-asset/<plugin id>/<file>, that each
machine resolves to its own installed copy.

- New capability type ResourcePrinterAsset ("resource-printer-asset",
  orca.resource_printer_asset) with get_asset_dir(), validated at load
  like ResourceTexture: inside the plugin folder, regular files only,
  .stl/.png/.svg, at most 16, sorted so every file system keeps the same.
- PluginPrinterAssets tracks loaded packs and resolves references;
  Plater::set_bed_shape draws the vendor bed while a pack is missing.
- Bed Shape dialog: "From asset pack..." next to each Load button.
- The hidden plugin-backed option printer_asset_plugins names the packs
  the bed files come from, so the printer manifest lists them and the
  missing-plugin notices offer to install or activate a missing pack
  (non-blocking). A before-save hook re-derives it on every printer
  preset save, and transfers between presets carry the manifest along.
- References are OS-neutral: no colon or backslash, and Windows device
  names are rejected.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Remove the missing-plugin notice changes from this PR

They moved to a separate PR (#16897) so this branch only carries the
printer preset plugin manifest and the slicing block rule.

Removed here: the notice refresh hooks in GUI_App and PluginsDialog,
Plater::refresh_missing_plugin_notifications, the preset-switch and
new-project refresh calls, and NotificationManager::has_notification_of_type.
The has_blocking_plugins() changes in Plater.cpp stay.

* Close the unresolved_plugin_capabilities test case

The merge with main dropped the closing brace of the new test.

* Use one manifest-key rule and cover printer plugins in tests

ConfigBase::plugin_manifest_key() is now the only definition of which key
holds a config's plugin manifest; PluginResolver used its own copy keyed by
preset type. The resolver calls the config's method instead.

Tests: a printer config keeps its printer_plugins entry for a capability not
loaded here, and a missing printer-preset plugin is reported without blocking
slicing. Comments that named the "plugins" option for every preset now say
plugin manifest.

* fix(plugins): build the missing-plugin search link without a running app

A missing local plugin gets a "Find on OrcaCloud" link, whose base URL
came from GUI::wxGetApp().getAgent(). With no app (unit tests, headless
callers) that dereferenced null and crashed refresh_missing_plugins.
Keep the default cloud URL when there is no app.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test: check the printer manifest key through ConfigBase::plugin_manifest_key

PluginResolver no longer has its own preset-type helper; the config's
method is the single rule.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Include wx/app.h for wxTheApp in PluginResolver

clang-tidy's misc-include-cleaner wants the header that declares
wxTheApp included directly.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Replace the Resource Printer Asset Plugin Type With a Generic Resource Pack

A resource pack ships one folder of files, and each file declares the kinds
it serves (bed_model, bed_texture, displacement_texture) in Python through
get_resource_kinds(). Consumers list only the files of their kind, so one
PNG can be both a bed texture and a displacement texture.

PluginResourcePacks replaces PluginPrinterAssets and also serves the
existing resource-texture type as displacement_texture files, which retires
PluginResourceTextures. The resource-texture capability, its Python API,
type id, 64-file cap and extension list are unchanged.

Printer asset references stay kind-less; resolve() takes the kind of the
field being resolved, and only resource-pack entries resolve references.
The texture picker groups pack sections by pack_key so a ResourceTexture
and a ResourcePack with the same name stay separate.

Not built or run locally.

* Include the headers clang-tidy asks for in the resource pack code

misc-include-cleaner wants PythonPluginInterface.hpp (PluginCapabilityType)
in TextureLibrary.cpp, <string_view> in PluginResourcePacks.cpp,
ResourcePackKinds.hpp (ResourceKindMap) in the resource pack trampoline,
and <cstdint> in the resource pack test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Keep the Resource Printer Asset Capability and Infer File Kinds From the Extension

Orca Cloud builds resource pack wheels from uploaded files, stores no
per-file metadata, and names its types resource-textures and
resource-printer-assets. Authors write no Python, so a pack cannot declare
the kinds of its files.

Restore the resource-printer-asset capability (get_asset_dir) and keep
resource-texture (get_texture_dir) as it is. PluginResourcePacks still
serves both from one registry, indexed by kind: bed_model (.stl) and
bed_texture (.png, .svg) for a printer asset pack, displacement_texture
for a texture pack. Each kind is capped at 16 (64 for textures) after
sorting. Only printer asset packs resolve printer asset references.

Drop get_resource_kinds, the resource-pack capability and its type id.
Rewrite docs/HLSD/resource-packs.md for the two types.

Not built or run locally.

* Keep the Texture and Printer Asset Plugin Types Separate

Orca Cloud treats resource-textures and resource-printer-assets as
independent types with no per-file kinds, so the slicer keeps them
independent too. Each has its own capability, registry, loader branch and
tests.

Restore PluginPrinterAssets as a registry of its own with a plain file
list and the extension helpers the Bed Shape dialog uses, and put the
resource texture code (PluginResourceTextures, the texture picker, its
callbacks and tests) back as it was on main. Remove the shared
PluginResourcePacks registry, the kind index and pack_key.

Replace docs/HLSD/resource-packs.md with docs/HLSD/resource-printer-assets.md.

Not built or run locally.

* Keep the Printer Plugin Keys Out of the G-code Config Dump

printer_asset_plugins and printer_plugins are newly-registered printer keys
with empty defaults, so append_full_config() would write
"; printer_asset_plugins = " and "; printer_plugins = " into every printer's
config block, machines that never install a pack included. Both are read
from the preset and never parsed back out of the dump, so ban them like
farthest_point_timelapse and the IMEX keys.

Not built or run locally.

* Move a Printer Preset's Legacy Plugins Manifest Into printer_plugins

A printer preset written before printer_plugins existed stores its plugin
references under the process preset's key, plugins. That key is not a
printer option, so remove_invalid_keys() reported it as an incorrect key and
dropped it on every start, taking with it the reference the missing-plugin
notice needs for a plugin this machine lacks.

Rename it before the validation, and merge rather than replace: a child
preset's file holds only the references it added, while the parent's
manifest already sits in the config it was built from. A config holding both
keys is a printer preset's, so the migration needs no type argument.

Cover the merge and the untouched process preset in test_config, and the
file path in test_preset_bundle_loading. Document the migration in the HLSD.

Not built or run locally.

* Say Which Presets Block Slicing in the Plugin Gate Comments

has_blocking_plugins() replaced has_missing_plugins() as the slicing gate:
only a plugin referenced by the process or filament preset blocks, while a
printer preset's plugins (printer agents, printer assets) only notify. Three
comments still described the old, type-agnostic rule: the cached
missing-plugin signature block in Plater::priv, refresh_missing_plugin_block's
return value, and plugins_block_slicing.

Not built or run locally.

* Test That a Missing Process Preset Plugin Blocks Slicing

Every existing assertion on has_blocking_plugins() is a negative one, so a
body that returned false would keep the suite green while slicing stopped
being blocked for a missing slicing-pipeline plugin -- the behavior this
change kept. Load an unresolved reference from a process preset: the gate
reports it missing and blocks, and clearing the missing-plugin sets unblocks.

Not built or run locally.

* Keep Inherited Plugin References in a Child Preset's Manifest

Preset::save wrote a diff against the parent, and save_to_json derived the
plugin manifest from that diff. A child that changed only printer_agent lost
the parent's bed pack reference, and the shortened manifest replaced the
parent's on reload. save_to_json now takes a manifest_source, and Preset::save
passes the whole resolved config.

A legacy "plugins" key in the file of a printer preset that inherits a parent
was dropped by the parent merge. The user, project-embedded and cloud load
paths and Preset::reload now move it into printer_plugins, merged with the
parent's manifest.

* Write the Printer Plugin Keys to the G-code Config Dump When Set

The config block is read back by config_from_gcode, so a printer imported from
a G-code that used a printer asset pack kept the bed reference but lost the
pack names and the manifest. The two keys are now written when they are not
empty, so a printer without packs keeps an unchanged block.

* Copy the Printer Plugin Keys When Creating a Nozzle Preset

The nozzle flow copied bed_custom_model and bed_custom_texture from the source
printer without printer_asset_plugins and printer_plugins, so a reference to a
pack that is not installed here was saved with an empty manifest.

* Describe the Manifest Derivation and the Pack Constraints in the HLD

* Redraw the Bed After a Printer Asset Pack Loads or Unloads

A texture-only change goes through update_logo_texture_filename, which does
not mark the canvas dirty, so the old texture stayed until the next paint.
The pack callback now requests an extra frame, as Plater::on_config_change does.

* Match a Printer Asset Pack by File and Keep Unusable Names Out of the Cap

capability_name() returned the first capability of the plugin whatever file
the reference named, so with two capabilities in one plugin the manifest could
name the wrong one. It now matches the file against the pack's listing, as
resolve() does, through one shared helper.

update_printer_asset_plugins rebuilt the manifest through a resolver that finds
a capability by name alone, so a loaded plugin with a capability of the same
name replaced the entry of a pack that is not loaded here. The pack's own entry
is put back.

The 16-file cap counted files a reference cannot name (spaces, device names),
which the Bed Shape dialog skips, so a pack could list nothing usable. The
listing now drops those names before the cap.

* Document the Printer Asset Capability's Python Bindings

The capability's pybind11 class and its two methods had no docstrings, so
script_list_api and script_describe_api listed them bare and "every public
member of the orca package has documentation and named parameters" failed
in slic3rutils_tests on every platform.

Say what a pack holds and how a preset refers to its files, and what
get_asset_dir must return: the checks its folder goes through once at load,
and that a rejected folder or a raised exception costs the pack its files.
Worded as resource_texture's bindings are.

* Harden the Printer Asset Pack Code Against Locale, Preset Type and a Failing Sweep

The reference charset used <cctype>, whose predicates follow LC_CTYPE. The
app pins LC_NUMERIC only and GUI_App constructs a default wxLocale, so
LC_CTYPE is the user's: on a single-byte Windows codepage a pack file named
bed_é.stl passes validation, is stored as raw UTF-8, and then parses as a
plain path on a machine with a UTF-8 or C locale, drawing the vendor bed
with no diagnostic. The HLD promises A-Z a-z 0-9 . _ -. Check those ranges
explicitly instead, in is_segment, is_windows_device_name and iends_with.

The legacy migration ran for every preset type and asked only that both
keys be present. A print or filament file carrying both had its "plugins"
moved into "printer_plugins" and erased, and the validation loop then
stripped "printer_plugins" as a non-print option: both manifests gone,
where main kept "plugins". Only a printer config has "printer_plugins" in
its defaults, so gate on that, and say so where the comment claimed a
config holding both keys must be a printer preset's.

initial_sweep() was called straight from GUI_App::on_init, outside the
loader's and the manager's guards, and it lists files. A pack file whose
name cannot be converted to the Windows ANSI code page throws
filesystem_error out of OnInit and terminates the app. Catch per
capability and log, so a fault costs the pack its files, as it does on the
loader's path.

on_cap_register() also reported a change unconditionally, so a disable and
re-enable redrew the bed for an entry nothing had altered. Compare the
rebuilt entry against the stored one: pack id, name, folder and file list.

Cover the three with tests: non-ASCII and out-of-set characters refused,
the 128-character boundary, an escaping and a dangling symlink skipped,
and the change flag staying false across a rebuild and turning true when a
file is added or removed.

* clang tidy missing header

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Lam Wei Lun <weilun.lam@gmail.com>
2026-12-03 16:22:54 +08:00

180 lines
6.7 KiB
CMake

get_filename_component(_TEST_NAME ${CMAKE_CURRENT_LIST_DIR} NAME)
add_executable(${_TEST_NAME}_tests
${_TEST_NAME}_tests_main.cpp
mcp_test_utils.hpp
test_bambu_filament_ids.cpp
test_bbl_cert_dir.cpp
test_bed_exclusion_fields.cpp
test_cloud_delete_queue.cpp
test_config_value_formatter.cpp
test_creality_cfs_match.cpp
test_creality_print.cpp
test_dev_mapping.cpp
test_dev_extruder_system.cpp
test_device_access.cpp
test_moonraker_printer_agent.cpp
test_moonraker_filament_sources.cpp
test_snapmaker_filament_match.cpp
test_network_discovery.cpp
test_filament_bitmap_utils.cpp
test_colour_picker_field.cpp
test_field_number_text.cpp
test_filament_color_picker.cpp
test_ams_materials_setting.cpp
test_gcode_preview_colors.cpp
# The reduced toolpath set's end bands, from libvgcode's layer table.
test_libvgcode_layers.cpp
# The vertex that stands for a role when the solid model takes the toolpaths' colours.
test_libvgcode_sampling.cpp
test_device_progress.cpp
test_device_manager_integration.cpp
test_web_media_controller.cpp
test_part_plate.cpp
test_scene_raycaster.cpp
test_scene_benchmark.cpp
test_preview_frame_rate_monitor.cpp
test_lazy.cpp
test_labeled_static_box.cpp
test_mcp_activity_log.cpp
test_mcp_config.cpp
test_mcp_core.cpp
test_operations.cpp
test_mcp_protocol.cpp
test_mcp_recording.cpp
test_mcp_scene.cpp
test_mcp_tools.cpp
test_mcp_ui.cpp
test_mcp_web.cpp
test_mcp_results.cpp
test_prebuild_queue.cpp
test_staged_build.cpp
test_network_versions.cpp
test_orca_cloud_agent.cpp
test_action_source.cpp
test_command_catalog.cpp
test_option_state_registry.cpp
test_plugin_host_api.cpp
# Exercise seam enums and predicates through the embedded Python host API.
test_precise_seam_plugin.cpp
test_plugin_capability_config.cpp
test_plugin_config.cpp
test_plugin_capabilities_in_use.cpp
test_plugin_status.cpp
test_orca_mqtt_connection.cpp
test_printer_agent.cpp
test_qidi_printer_agent.cpp
test_plugin_install.cpp
test_plugin_update.cpp
test_plugin_lifecycle.cpp
test_plugin_wheel_install.cpp
test_plugin_resource_texture.cpp
test_plugin_printer_asset.cpp
test_plugin_printer_agent.cpp
test_post_processor.cpp
test_printhost.cpp
test_slicing_pipeline_bindings.cpp
test_slicing_pipeline_config.cpp
test_plugin_sort.cpp
test_plugin_cloud_metadata.cpp
test_plugin_audit.cpp
test_python_script_runner.cpp
test_plugin_operations.cpp
test_plugin_json_depth.cpp
test_plugin_permission_validation.cpp
test_shortcuts.cpp
test_speed_dial_dismiss.cpp
test_speed_dial_position.cpp
test_texture_color_palette.cpp
test_texture_island_view.cpp
test_timelapse_codecs.cpp
test_toolbar_layout.cpp
test_file_url.cpp
test_imgui_wrapper.cpp
test_user_manager.cpp
test_sequential_clearance.cpp
test_object_list.cpp
test_geometry_import.cpp
../fff_print/test_helpers.cpp
)
if (SLIC3R_CAD)
target_sources(${_TEST_NAME}_tests PRIVATE test_design_sketch_tool.cpp)
# The Design tab's commands.
target_sources(${_TEST_NAME}_tests PRIVATE test_mcp_cad.cpp)
endif ()
if (MSVC)
target_link_libraries(${_TEST_NAME}_tests Setupapi.lib)
endif ()
target_link_libraries(${_TEST_NAME}_tests test_common libslic3r_gui libslic3r pybind11::embed Catch2::Catch2WithMain)
if (SLIC3R_PCH AND NOT SLIC3R_SYNTAXONLY)
add_precompiled_header(${_TEST_NAME}_tests ${CMAKE_SOURCE_DIR}/src/slic3r/pchheader.hpp FORCEINCLUDE)
endif ()
set_property(TARGET ${_TEST_NAME}_tests PROPERTY FOLDER "tests")
orcaslicer_copy_test_dlls(${_TEST_NAME}_tests)
if (WIN32)
add_custom_command(TARGET ${_TEST_NAME}_tests POST_BUILD
COMMAND ${CMAKE_COMMAND} "-DSOURCE=${CMAKE_PREFIX_PATH}/libpython"
"-DDESTINATION=$<TARGET_FILE_DIR:${_TEST_NAME}_tests>/python"
"-DSTAMP=${CMAKE_CURRENT_BINARY_DIR}/python_runtime_$<CONFIG>.stamp"
-P "${CMAKE_SOURCE_DIR}/cmake/modules/StagePythonRuntime.cmake"
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${CMAKE_PREFIX_PATH}/libpython/python${_bundled_python_abi}.dll"
"${CMAKE_PREFIX_PATH}/libpython/vcruntime140.dll"
"${CMAKE_PREFIX_PATH}/libpython/vcruntime140_1.dll"
"$<TARGET_FILE_DIR:${_TEST_NAME}_tests>"
COMMENT "Copying Python runtime for slic3rutils plugin host API tests"
VERBATIM
)
elseif (NOT FLATPAK)
# The CI unit-test runner only receives the build/tests tree, so both the
# interpreter and the libpython the test binary links have to travel next to
# the executable; find_bundled_python_home() picks the copy up from there.
if (APPLE)
target_link_options(${_TEST_NAME}_tests PRIVATE
"LINKER:-rpath,@executable_path/python/lib")
else ()
set_property(TARGET ${_TEST_NAME}_tests APPEND PROPERTY BUILD_RPATH "$ORIGIN/python/lib")
endif ()
add_custom_command(TARGET ${_TEST_NAME}_tests POST_BUILD
COMMAND ${CMAKE_COMMAND} -E rm -rf
"$<TARGET_FILE_DIR:${_TEST_NAME}_tests>/python"
COMMAND ${CMAKE_COMMAND} -E copy_directory
"${CMAKE_PREFIX_PATH}/libpython"
"$<TARGET_FILE_DIR:${_TEST_NAME}_tests>/python"
COMMENT "Copying Python runtime for the plugin host API tests"
VERBATIM
)
elseif (FLATPAK)
# Same <testdir>/python home as WIN32/APPLE; symlink since /app/libpython
# already ships in the flatpak (the test exe links libpython3.12.so from it).
add_custom_command(TARGET ${_TEST_NAME}_tests POST_BUILD
COMMAND ${CMAKE_COMMAND} -E rm -rf
"$<TARGET_FILE_DIR:${_TEST_NAME}_tests>/python"
COMMAND ${CMAKE_COMMAND} -E create_symlink
"${CMAKE_PREFIX_PATH}/libpython"
"$<TARGET_FILE_DIR:${_TEST_NAME}_tests>/python"
COMMENT "Linking Python runtime for flatpak plugin host API tests"
VERBATIM
)
endif()
# scripts/run_unit_tests.sh installs the tests' numpy into that runtime with this uv,
# staged where the app build tree keeps it (<exe dir>/tools/uv, see src/CMakeLists.txt).
if (ORCA_BUNDLED_UV_EXECUTABLE)
add_custom_command(TARGET ${_TEST_NAME}_tests POST_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory "$<TARGET_FILE_DIR:${_TEST_NAME}_tests>/tools/uv"
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${ORCA_BUNDLED_UV_EXECUTABLE}"
"$<TARGET_FILE_DIR:${_TEST_NAME}_tests>/tools/uv/${ORCA_BUNDLED_UV_FILENAME}"
COMMENT "Copying uv for the plugin host API tests"
VERBATIM
)
endif()
orcaslicer_discover_tests(${_TEST_NAME}_tests)