diff --git a/src/slic3r/plugin/PluginHooks.cpp b/src/slic3r/plugin/PluginHooks.cpp index 0088bc1477..347687a20b 100644 --- a/src/slic3r/plugin/PluginHooks.cpp +++ b/src/slic3r/plugin/PluginHooks.cpp @@ -1,6 +1,7 @@ #include "PluginHooks.hpp" #include "PluginManager.hpp" +#include "PluginResolver.hpp" #include "PythonInterpreter.hpp" #include "PythonPluginInterface.hpp" #include "pluginTypes/slicingPipeline/SlicingPipelinePluginCapability.hpp" @@ -33,24 +34,8 @@ namespace { void install_capability_resolver() { ConfigBase::set_resolve_capability_fn([](const std::string& cap_name, const std::string& cap_type) { - PluginManager& plugin_mgr = PluginManager::instance(); - const PluginCapabilityType type = plugin_capability_type_from_string(cap_type); - // only_enabled = false: this resolves the reference a preset STORES, which must stay - // resolvable whether or not the user currently has the capability enabled. Filtering on - // the enable flag here would quietly drop the reference out of the preset's manifest. - auto plugin_cap = plugin_mgr.get_plugin_capability(cap_name, type, /*only_enabled=*/false); - if (!plugin_cap) - return std::string(); - - PluginDescriptor descriptor; - if (!plugin_mgr.try_get_plugin_descriptor_for_capability(cap_name, type, descriptor)) - return std::string(); - - // Cloud plugins are resolved at runtime via the UUID in the middle field, so the first - // field keeps the friendly display name. Local plugins are looked up by plugin_key (the - // first field, with an empty UUID), so emit the plugin_key to keep them resolvable. - const std::string identity = descriptor.is_cloud_plugin() ? descriptor.name : descriptor.plugin_key; - return identity + ';' + descriptor.cloud_uuid() + ';' + cap_name; + const auto ref = PluginManager::instance().resolve_capability_ref(cap_name, plugin_capability_type_from_string(cap_type)); + return ref ? create_full_ref(*ref) : std::string(); }); } diff --git a/src/slic3r/plugin/PluginManager.cpp b/src/slic3r/plugin/PluginManager.cpp index a2f2834166..fb0166c214 100644 --- a/src/slic3r/plugin/PluginManager.cpp +++ b/src/slic3r/plugin/PluginManager.cpp @@ -5,6 +5,7 @@ #include #include #include +#include "libslic3r/Config.hpp" #include "libslic3r/LifecycleEvents.hpp" #include #include @@ -570,6 +571,24 @@ bool PluginManager::try_get_plugin_descriptor_for_capability(const std::string& return false; } +std::optional PluginManager::resolve_capability_ref(const std::string& capability_name, + PluginCapabilityType type) const +{ + // only_enabled = false: a stored reference must stay resolvable whether or not the user + // currently has the capability enabled; the dispatchers report "disabled" separately. + if (!get_plugin_capability(capability_name, type, /*only_enabled=*/false)) + return std::nullopt; + + PluginDescriptor descriptor; + if (!try_get_plugin_descriptor_for_capability(capability_name, type, descriptor)) + return std::nullopt; + + // Cloud plugins are resolved at runtime via the UUID, so the name field keeps the friendly + // display name. Local plugins are looked up by plugin_key with an empty UUID. + const std::string identity = descriptor.is_cloud_plugin() ? descriptor.name : descriptor.plugin_key; + return PluginCapabilityRef{identity, capability_name, descriptor.cloud_uuid()}; +} + std::string PluginManager::get_storage_dir(const std::string& plugin_key) const { namespace fs = boost::filesystem; diff --git a/src/slic3r/plugin/PluginManager.hpp b/src/slic3r/plugin/PluginManager.hpp index e8769e3afd..58db6a996d 100644 --- a/src/slic3r/plugin/PluginManager.hpp +++ b/src/slic3r/plugin/PluginManager.hpp @@ -190,6 +190,9 @@ public: bool try_get_plugin_descriptor_for_capability(const std::string& capability_name, PluginCapabilityType type, PluginDescriptor& out) const; + // The "name;uuid;capability" reference for a loaded capability, as stored in a preset's + // "plugins" manifest; std::nullopt when no loaded package provides it. + std::optional resolve_capability_ref(const std::string& capability_name, PluginCapabilityType type) const; // Per-plugin storage directory under orca_plugins/plugin_data, created if missing. Throws // std::runtime_error if the plugin is unregistered, the key is invalid, or (cloud plugins) // no user is logged in yet. @@ -489,6 +492,15 @@ void execute_capabilities_from_refs(const ConfigOptionStrings& capabilities, } } + // The manifest is derived from the picker value only when that value changes, so it can be + // stale or empty (e.g. derived before the plugin finished loading) even though the + // capability is loaded now. Resolve it by name instead of silently skipping the step. + if (!ref) { + ref = plugin_mgr.resolve_capability_ref(capability, type); + if (ref) + BOOST_LOG_TRIVIAL(warning) << tag << ": capability '" << capability << "' missing from the plugins manifest; resolved by name"; + } + if (!ref) { BOOST_LOG_TRIVIAL(warning) << tag << ": no plugin reference found for capability '" << capability << "'; skipping"; continue; diff --git a/tests/slic3rutils/test_slicing_pipeline_config.cpp b/tests/slic3rutils/test_slicing_pipeline_config.cpp index 73a3840577..ef8614fb9b 100644 --- a/tests/slic3rutils/test_slicing_pipeline_config.cpp +++ b/tests/slic3rutils/test_slicing_pipeline_config.cpp @@ -107,6 +107,19 @@ fs::path write_plugin(const std::string& stem, const std::string& source) return plugin_dir; } +void load_config_probe(PluginManager& manager) +{ + write_plugin("ConfigProbe", CONFIG_PROBE_SOURCE); + manager.get_config().load(); // reset the singleton's store against the empty temp data dir + manager.discover_plugins(/*async=*/false, /*clear=*/true); + + std::string error; + manager.load_plugin("ConfigProbe", /*skip_deps=*/true, {}); + REQUIRE(manager.wait_for_plugin_load("ConfigProbe", std::chrono::seconds(120), error)); + INFO("load error: " << error); + REQUIRE(manager.is_plugin_loaded("ConfigProbe")); +} + } // namespace TEST_CASE("slicing-pipeline dispatch delivers the stored config to self.get_config()", "[slicing_pipeline][PluginConfig][Python]") @@ -116,17 +129,8 @@ TEST_CASE("slicing-pipeline dispatch delivers the stored config to self.get_conf SKIP("Bundled Python interpreter unavailable: " + PythonInterpreter::instance().last_error()); ScopedDataDir data_dir_guard("pipeline-config"); - write_plugin("ConfigProbe", CONFIG_PROBE_SOURCE); - PluginManager& manager = PluginManager::instance(); - manager.get_config().load(); // reset the singleton's store against the empty temp data dir - manager.discover_plugins(/*async=*/false, /*clear=*/true); - - std::string error; - manager.load_plugin("ConfigProbe", /*skip_deps=*/true, {}); - REQUIRE(manager.wait_for_plugin_load("ConfigProbe", std::chrono::seconds(120), error)); - INFO("load error: " << error); - REQUIRE(manager.is_plugin_loaded("ConfigProbe")); + load_config_probe(manager); const PluginCapabilityId id{PluginCapabilityType::SlicingPipeline, "ConfigEcho", "ConfigProbe"}; @@ -164,3 +168,39 @@ TEST_CASE("slicing-pipeline dispatch delivers the stored config to self.get_conf manager.unload_plugin("ConfigProbe"); } + +TEST_CASE("slicing-pipeline dispatch runs a selected capability missing from the plugins manifest", "[slicing_pipeline][Python]") +{ + ScopedPluginManager plugin_system; + if (!plugin_system.initialized) + SKIP("Bundled Python interpreter unavailable: " + PythonInterpreter::instance().last_error()); + + ScopedDataDir data_dir_guard("pipeline-no-manifest"); + PluginManager& manager = PluginManager::instance(); + load_config_probe(manager); + + // The interpreter outlives each test case, so clear what an earlier run of the probe left behind. + { + PythonGILState gil; + REQUIRE(static_cast(gil)); + pybind11::module_ orca = pybind11::module_::import("orca"); + if (pybind11::hasattr(orca, "_probe_config")) + pybind11::delattr(orca, "_probe_config"); + } + + Print print; + Model model; + auto config = DynamicPrintConfig::full_print_config(); + config.set_key_value("slicing_pipeline_plugin", new ConfigOptionStrings({"ConfigEcho"})); + config.set_key_value("plugins", new ConfigOptionStrings()); + init_print({cube(20)}, print, model, config); + print.process(); + + { + PythonGILState gil; + REQUIRE(static_cast(gil)); + CHECK(pybind11::hasattr(pybind11::module_::import("orca"), "_probe_config")); + } + + manager.unload_plugin("ConfigProbe"); +}