#include #include #include "libslic3r/Config.hpp" #include #include #include #include #include #include using namespace Slic3r; namespace { // A print preset carrying a "plugins" manifest and the one plugin-backed print option. Preset make_print_preset(const std::vector& manifest, const std::vector& pipeline) { Preset preset(Preset::TYPE_PRINT, "test-print"); const std::unique_ptr defaults( DynamicPrintConfig::new_from_defaults_keys({"plugins", "slicing_pipeline_plugin"})); preset.config = *defaults; preset.config.option("plugins")->values = manifest; preset.config.option("slicing_pipeline_plugin")->values = pipeline; return preset; } std::vector capability_names(const std::vector& refs) { std::vector names; for (const PluginCapabilityRef& ref : refs) names.push_back(ref.capability_name); return names; } } // namespace TEST_CASE("referenced_capabilities keeps only manifest entries an option points at", "[PluginResolver]") { // CapB is declared in the manifest but no option references it, so it is not in use. const Preset preset = make_print_preset({"acme;;CapA", "acme;;CapB"}, {"CapA"}); CHECK(capability_names(referenced_capabilities(Preset::TYPE_PRINT, preset)) == std::vector{"CapA"}); } TEST_CASE("referenced_capabilities matches every value of a vector option", "[PluginResolver]") { const Preset preset = make_print_preset({"acme;;CapA", "acme;;CapB", "acme;;CapC"}, {"CapA", "CapC"}); CHECK(capability_names(referenced_capabilities(Preset::TYPE_PRINT, preset)) == std::vector{"CapA", "CapC"}); } TEST_CASE("referenced_capabilities is empty when the manifest is empty", "[PluginResolver]") { const Preset preset = make_print_preset({}, {"CapA"}); CHECK(referenced_capabilities(Preset::TYPE_PRINT, preset).empty()); } TEST_CASE("referenced_capabilities ignores untracked preset types", "[PluginResolver]") { Preset preset = make_print_preset({"acme;;CapA"}, {"CapA"}); preset.type = Preset::TYPE_SLA_PRINT; CHECK(referenced_capabilities(Preset::TYPE_SLA_PRINT, preset).empty()); } TEST_CASE("referenced_capabilities skips malformed manifest entries", "[PluginResolver]") { // parse_capability_ref rejects entries that are not "name;uuid;capability". const Preset preset = make_print_preset({"garbage", "acme;;CapA"}, {"CapA"}); CHECK(capability_names(referenced_capabilities(Preset::TYPE_PRINT, preset)) == std::vector{"CapA"}); } TEST_CASE("A missing printer preset plugin is reported but does not block slicing", "[PluginResolver]") { const auto clear_missing = [] { for (const Preset::Type type : {Preset::TYPE_PRINT, Preset::TYPE_PRINTER, Preset::TYPE_FILAMENT}) refresh_missing_plugins(type, nullptr); }; clear_missing(); Preset printer(Preset::TYPE_PRINTER, "test-printer"); const std::unique_ptr defaults( DynamicPrintConfig::new_from_defaults_keys({"printer_agent", "printer_plugins"})); printer.config = *defaults; printer.config.option("printer_agent")->value = "agent"; printer.config.option("printer_plugins")->values = {"acme;;agent"}; refresh_missing_plugins(Preset::TYPE_PRINTER, printer.config.option("printer_plugins"), &printer); CHECK(has_missing_plugins()); CHECK_FALSE(has_blocking_plugins()); clear_missing(); } TEST_CASE("A missing process preset plugin blocks slicing", "[PluginResolver]") { const auto clear_missing = [] { for (const Preset::Type type : {Preset::TYPE_PRINT, Preset::TYPE_PRINTER, Preset::TYPE_FILAMENT}) refresh_missing_plugins(type, nullptr); }; clear_missing(); // The same unresolved reference blocks when it comes from the process preset: only printer preset // plugins (printer agents, printer assets) are exempt, so a capability that changes the sliced // result must still be installed first. const Preset print = make_print_preset({"acme;;CapA"}, {"CapA"}); refresh_missing_plugins(Preset::TYPE_PRINT, print.config.option("plugins"), &print); CHECK(has_missing_plugins()); CHECK(has_blocking_plugins()); clear_missing(); CHECK_FALSE(has_blocking_plugins()); }