mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-11-27 07:39:40 -05:00
fix: overlapping permission dialogs (#17318)
* fix: queue permissions dialogs * fix: serialize plugin permission dialogs across prompt types * fix: unit tests * fix: move audit prompt stuff to PluginAuditManager * fix: discard pending permission requests when plugin load is cancelled * fix: simplify audit prompt cancellation and align denial tests with prod * fix: queued permission prompts lost after plugin load failure
This commit is contained in:
1 parent
4c714ac95e
commit
0aa479f27c
8 files changed
+1616
-142
No files matched your search
@@ -94,6 +94,26 @@ class EchoPackage(orca.base):
|
||||
orca.register_capability(Echo)
|
||||
)PY";
|
||||
|
||||
// A plugin whose registration always fails after the module imported. The failure is ordinary:
|
||||
// neither cancellation nor unload, so its queued runtime prompts stay actionable for a retry.
|
||||
const char* const BROKEN_PLUGIN_SOURCE = R"PY(# /// script
|
||||
# requires-python = ">=3.12"
|
||||
#
|
||||
# [tool.orcaslicer.plugin]
|
||||
# name = "Broken Plugin"
|
||||
# description = "Plugin whose registration always fails."
|
||||
# author = "tests"
|
||||
# version = "1.0"
|
||||
# type = "script"
|
||||
# ///
|
||||
import orca
|
||||
|
||||
@orca.plugin
|
||||
class BrokenPackage(orca.base):
|
||||
def register_capabilities(self):
|
||||
raise RuntimeError("registration failed")
|
||||
)PY";
|
||||
|
||||
// A minimal printer-agent plugin exposing exactly one PrinterConnection capability.
|
||||
const char* const PRINTER_AGENT_PLUGIN_SOURCE = R"PY(# /// script
|
||||
# requires-python = ">=3.12"
|
||||
@@ -1003,6 +1023,7 @@ class SlowPackage(orca.base):
|
||||
// The key is registered before the worker is spawned, so this is not a race.
|
||||
REQUIRE(manager.is_plugin_load_in_progress("Slow_Load_Plugin"));
|
||||
REQUIRE(manager.cancel_plugin_load("Slow_Load_Plugin"));
|
||||
CHECK(manager.is_plugin_load_cancelled("Slow_Load_Plugin"));
|
||||
|
||||
// Cancelling must not release the worker's slot. shutdown() unloads everything and GUI_App
|
||||
// finalizes the interpreter as soon as this wait returns, so reporting "no loads in progress"
|
||||
@@ -1013,7 +1034,10 @@ class SlowPackage(orca.base):
|
||||
// The worker releases the slot itself, once it has unwound.
|
||||
CHECK(manager.wait_for_all_plugin_loads(std::chrono::seconds(60)));
|
||||
CHECK_FALSE(manager.is_plugin_load_in_progress("Slow_Load_Plugin"));
|
||||
CHECK_FALSE(manager.is_plugin_load_cancelled("Slow_Load_Plugin"));
|
||||
CHECK_FALSE(manager.is_plugin_loaded("Slow_Load_Plugin"));
|
||||
// A cancellation is not an ordinary failure, so no prompt is kept actionable for a retry.
|
||||
CHECK_FALSE(manager.is_plugin_load_failed("Slow_Load_Plugin"));
|
||||
}
|
||||
|
||||
TEST_CASE("Loading an unknown plugin key records an error instead of crashing", "[PluginLifecycle][Python]")
|
||||
@@ -1037,6 +1061,62 @@ TEST_CASE("Loading an unknown plugin key records an error instead of crashing",
|
||||
CHECK(manager.get_plugin_capabilities("No_Such_Plugin").empty());
|
||||
}
|
||||
|
||||
TEST_CASE("An ordinary load failure stays recorded until the plugin is unloaded", "[PluginLifecycle][Python]")
|
||||
{
|
||||
ScopedPluginManager plugin_system;
|
||||
if (!plugin_system.initialized)
|
||||
SKIP("Bundled Python interpreter unavailable: " + PythonInterpreter::instance().last_error());
|
||||
|
||||
// Registration raises after the module imported, which is an ordinary failure: the user can
|
||||
// approve a queued runtime prompt and retry. Cancelling or unloading is different.
|
||||
ScopedDataDir data_dir_guard("lifecycle-load-failed");
|
||||
write_plugin(data_dir_guard, "Broken_Plugin", BROKEN_PLUGIN_SOURCE);
|
||||
|
||||
PluginManager& manager = PluginManager::instance();
|
||||
manager.discover_plugins(/*async=*/false, /*clear=*/true);
|
||||
|
||||
std::string error;
|
||||
CHECK_FALSE(load_and_wait(manager, "Broken_Plugin", error));
|
||||
INFO("load error: " << error);
|
||||
CHECK_FALSE(error.empty());
|
||||
CHECK_FALSE(manager.is_plugin_loaded("Broken_Plugin"));
|
||||
CHECK_FALSE(manager.is_plugin_load_in_progress("Broken_Plugin"));
|
||||
CHECK_FALSE(manager.is_plugin_load_cancelled("Broken_Plugin"));
|
||||
CHECK(manager.is_plugin_load_failed("Broken_Plugin"));
|
||||
|
||||
// An explicit unload clears the state a queued prompt would otherwise rely on.
|
||||
REQUIRE(manager.unload_plugin("Broken_Plugin"));
|
||||
CHECK_FALSE(manager.is_plugin_load_failed("Broken_Plugin"));
|
||||
}
|
||||
|
||||
TEST_CASE("Rediscovering a removed failed plugin does not revive its failure state", "[PluginLifecycle][Python]")
|
||||
{
|
||||
ScopedPluginManager plugin_system;
|
||||
if (!plugin_system.initialized)
|
||||
SKIP("Bundled Python interpreter unavailable: " + PythonInterpreter::instance().last_error());
|
||||
|
||||
ScopedDataDir data_dir_guard("lifecycle-failed-removed");
|
||||
const fs::path plugin_dir = write_plugin(data_dir_guard, "Removed_Plugin", BROKEN_PLUGIN_SOURCE);
|
||||
|
||||
PluginManager& manager = PluginManager::instance();
|
||||
manager.discover_plugins(/*async=*/false, /*clear=*/true);
|
||||
|
||||
std::string error;
|
||||
REQUIRE_FALSE(load_and_wait(manager, "Removed_Plugin", error));
|
||||
REQUIRE(manager.is_plugin_load_failed("Removed_Plugin"));
|
||||
|
||||
// Removing the missing package must drop the state, not leave it keyed by the old package.
|
||||
fs::remove_all(plugin_dir);
|
||||
manager.discover_plugins(/*async=*/false, /*clear=*/true);
|
||||
manager.remove_missing_plugins({"Removed_Plugin"});
|
||||
CHECK_FALSE(manager.is_plugin_load_failed("Removed_Plugin"));
|
||||
|
||||
// Rediscovery starts from a clean failure state even when the key is reused.
|
||||
write_plugin(data_dir_guard, "Removed_Plugin", BROKEN_PLUGIN_SOURCE);
|
||||
manager.discover_plugins(/*async=*/false, /*clear=*/true);
|
||||
CHECK_FALSE(manager.is_plugin_load_failed("Removed_Plugin"));
|
||||
}
|
||||
|
||||
TEST_CASE("The startup auto-load list only contains packages whose sidecar enables them", "[PluginLifecycle][Python]")
|
||||
{
|
||||
ScopedPluginManager plugin_system;
|
||||
|
||||
Reference in new issue
Block a user