Protect action identity from mutation

Keep action identity and display metadata
constructor-set so registry keys cannot drift
from the objects they index.

Require sources to publish unique ownership while
the registry retains shared keepalive for runs.

Preserve opaque IDs and persisted state keys.
This commit is contained in:
Andrew
2026-07-13 17:32:16 +08:00
parent b4c9747f09
commit 87c9ab138c
6 changed files with 71 additions and 31 deletions

View File

@@ -4,7 +4,11 @@
#include "slic3r/GUI/IActionSource.hpp"
#include <memory>
#include <string>
#include <type_traits>
using Slic3r::GUI::AppAction;
using Slic3r::GUI::AppActionRunResult;
using Slic3r::GUI::ActionRegistry;
using Slic3r::GUI::IActionSource;
@@ -21,8 +25,39 @@ private:
bool& m_started;
};
// AppAction is abstract; this minimal concrete action lets the tests exercise
// its constructor-set definition without involving a plugin runner.
class TestAppAction final : public AppAction
{
public:
TestAppAction() : AppAction("action-id", "Action title", "Action source") {}
AppActionRunResult run() const override { return {}; }
};
} // namespace
TEST_CASE("AppAction definitions are immutable after construction", "[speeddial][actions]")
{
using StringAccessor = const std::string& (AppAction::*)() const;
STATIC_CHECK(std::is_same_v<decltype(&AppAction::id), StringAccessor>);
STATIC_CHECK(std::is_same_v<decltype(&AppAction::title), StringAccessor>);
STATIC_CHECK(std::is_same_v<decltype(&AppAction::source), StringAccessor>);
const TestAppAction action;
CHECK(action.id() == "action-id");
CHECK(action.title() == "Action title");
CHECK(action.source() == "Action source");
}
TEST_CASE("ActionRegistry takes exclusive ownership of published actions", "[speeddial][actions]")
{
using ExpectedUpsert = void (ActionRegistry::*)(std::unique_ptr<AppAction>);
STATIC_CHECK(std::is_same_v<decltype(&ActionRegistry::upsert), ExpectedUpsert>);
}
TEST_CASE("ActionRegistry starts registered action sources", "[speeddial][actions]")
{
bool started = false;