Remove the two old FSMs ahead of the inheritance-based rewrite

Deletes the compile-time Void::StateMachine and the builder-based runtime
Void::Fsm (Definition/Machine/Event/PluginBehavior + their standalone
tests, the FSM behaviour plugins, and the FSM x Plugin integration test
and its CMake wiring). The general-purpose Plugin module and its stateful
hot-reload tests are untouched.

Both are being replaced by a single inheritance + coroutine workflow FSM
(next phase). 936 tests green (51 old FSM/StateMachine tests removed).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
faumarayandClaude Fable 5 committed 2026-06-14 00:26:30 +03:00
1 parent 6b5f61f00a
commit 04cf1998bd
20 files changed
+3 -3793

No files matched your search

-186
View File
@@ -1,186 +0,0 @@
#include <Void/Fsm/Definition.hpp>
#include <Void/Fsm/Machine.hpp>
#include <Void/Testing/Assert.hpp>
#include <Void/Testing/Test.hpp>
#include <memory>
#include <string>
using namespace Void::Fsm;
namespace
{
// work{ sub{ s1, s2 } }, pause — with deep history on work.
std::shared_ptr<const MachineDef> make_def()
{
Builder b;
auto work = b.state("work");
auto sub = b.state("sub", work);
auto s1 = b.state("s1", sub);
auto s2 = b.state("s2", sub);
auto pause = b.state("pause");
b.initial(work);
b.initial(sub);
b.initial(s1);
b.history(work, History::Deep);
b.transition(s1, b.event("next"), s2);
b.transition(work, b.event("stop"), pause);
b.transition(pause, b.event("resume"), work);
auto def = b.build();
Void::Testing::expect(def.has_value());
return *def;
}
} // namespace
Void::Testing::Test serialize_captures_leaves_by_name()
{
auto def = make_def();
Machine m{def, MachineOptions{.own_worker = false}};
m.start();
m.post(Event{*def->event_id("next"), {}});
m.run_pending();
const auto json = m.serialize_state();
Void::Testing::expect(json.is_object());
const auto& leaves = json["leaves"].as_array();
Void::Testing::expect_eq(leaves.size(), std::size_t{1});
Void::Testing::expect_eq(leaves[0].as_string(), std::string{"s2"});
}
Void::Testing::Test serialize_restore_round_trip()
{
auto def = make_def();
Void::Json::Value saved;
{
Machine m{def, MachineOptions{.own_worker = false}};
m.start();
m.post(Event{*def->event_id("next"), {}}); // s1 -> s2
m.run_pending();
saved = m.serialize_state();
m.stop();
}
Machine restored{def, MachineOptions{.own_worker = false}};
Void::Testing::expect(restored.restore_state(saved).has_value());
restored.start();
Void::Testing::expect(restored.is_in("s2"));
Void::Testing::expect(restored.is_in("work"));
Void::Testing::expect(!restored.is_in("s1"));
// The restored machine behaves identically: stop/resume goes back
// to s2 via deep history captured in the serialized state.
restored.post(Event{*def->event_id("stop"), {}});
restored.post(Event{*def->event_id("resume"), {}});
restored.run_pending();
Void::Testing::expect(restored.is_in("s2"));
}
Void::Testing::Test serialize_preserves_history_records()
{
auto def = make_def();
Void::Json::Value saved;
{
Machine m{def, MachineOptions{.own_worker = false}};
m.start();
m.post(Event{*def->event_id("next"), {}}); // -> s2
m.post(Event{*def->event_id("stop"), {}}); // -> pause, hist {s2}
m.run_pending();
saved = m.serialize_state();
m.stop();
}
Machine restored{def, MachineOptions{.own_worker = false}};
Void::Testing::expect(restored.restore_state(saved).has_value());
restored.start();
Void::Testing::expect(restored.is_in("pause"));
restored.post(Event{*def->event_id("resume"), {}});
restored.run_pending();
Void::Testing::expect(restored.is_in("s2")); // history survived
}
Void::Testing::Test restore_rejects_running_machine_and_garbage()
{
auto def = make_def();
Machine m{def, MachineOptions{.own_worker = false}};
Void::Testing::expect(
!m.restore_state(Void::Json::Value{42}).has_value());
m.start();
const auto state = m.serialize_state();
Void::Testing::expect(!m.restore_state(state).has_value());
}
Void::Testing::Test restore_with_unknown_states_falls_back_to_initial()
{
auto def = make_def();
auto bogus = Void::Json::parse(
R"({"__fsm":1,"leaves":["no_such_state"],"history":{}})");
Void::Testing::expect(bogus.has_value());
Machine m{def, MachineOptions{.own_worker = false}};
Void::Testing::expect(m.restore_state(*bogus).has_value());
m.start();
Void::Testing::expect(m.is_in("s1")); // initial configuration
}
// ── hot definition swap ───────────────────────────────────────────────────────
Void::Testing::Test swap_same_names_keeps_configuration()
{
auto def = make_def();
Machine m{def, MachineOptions{.own_worker = false}};
m.start();
m.post(Event{*def->event_id("next"), {}}); // -> s2
m.run_pending();
int entries = 0;
// New definition: same state names, one extra transition + an entry
// probe that must NOT run during a seamless swap.
Builder b;
auto work = b.state("work");
auto sub = b.state("sub", work);
auto s1 = b.state("s1", sub);
auto s2 = b.state("s2", sub);
auto pause = b.state("pause");
b.initial(work);
b.initial(sub);
b.initial(s1);
b.on_entry(s2, SyncAction{[&](Machine&, const Event&) {
++entries;
}});
b.transition(s2, b.event("back"), s1); // new behavior
b.transition(work, b.event("stop"), pause);
auto next_def = b.build();
Void::Testing::expect(next_def.has_value());
m.swap_definition(*next_def);
m.run_pending();
Void::Testing::expect(m.is_in("s2")); // configuration survived
Void::Testing::expect_eq(entries, 0); // no re-entry side effects
// New transition is live.
m.post(Event{*(*next_def)->event_id("back"), {}});
m.run_pending();
Void::Testing::expect(m.is_in("s1"));
}
Void::Testing::Test swap_with_missing_states_reenters_initial()
{
auto def = make_def();
Machine m{def, MachineOptions{.own_worker = false}};
m.start();
m.post(Event{*def->event_id("next"), {}}); // -> s2
m.run_pending();
Builder b;
(void)b.state("fresh_a");
(void)b.state("fresh_b");
auto next_def = b.build();
Void::Testing::expect(next_def.has_value());
m.swap_definition(*next_def);
m.run_pending();
Void::Testing::expect(m.is_in("fresh_a"));
}