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

-221
View File
@@ -1,221 +0,0 @@
#include <Void/Fsm/Definition.hpp>
#include <Void/Fsm/Machine.hpp>
#include <Void/Testing/Assert.hpp>
#include <Void/Testing/Test.hpp>
#include <atomic>
#include <thread>
#include <vector>
using namespace Void::Fsm;
#ifdef VOID_HAS_ENUM_REFLECTION
namespace
{
enum class Phase { Ping, Pong };
enum class Signal { Flip };
} // namespace
Void::Testing::Test enum_reflection_builds_states_and_events()
{
Builder b;
b.states_from_enum<Phase>();
b.initial(b.state_of(Phase::Ping));
const auto flip = b.event(Signal::Flip);
b.transition(b.state_of(Phase::Ping), flip, b.state_of(Phase::Pong));
b.transition(b.state_of(Phase::Pong), flip, b.state_of(Phase::Ping));
auto def = b.build();
Void::Testing::expect(def.has_value());
Void::Testing::expect((*def)->state_id("Ping").has_value());
Void::Testing::expect((*def)->event_id("Flip").has_value());
Machine m{*def, MachineOptions{.own_worker = false}};
m.start();
Void::Testing::expect(m.is_in("Ping"));
Void::Testing::expect(m.post(Signal::Flip));
m.run_pending();
Void::Testing::expect(m.is_in("Pong"));
// Serialized state uses enumerator names — stable across reloads.
const auto json = m.serialize_state();
Void::Testing::expect_eq(json["leaves"][0].as_string(),
std::string{"Pong"});
}
#endif // VOID_HAS_ENUM_REFLECTION
// @tag stress, concurrency
Void::Testing::Test concurrent_posts_all_processed_in_producer_order()
{
constexpr int producers = 8;
constexpr int per_producer = 10'000;
// counter state with an internal self-loop that consumes "bump"
// events carrying {producer, seq} payloads.
struct Payload {
int producer;
int seq;
};
std::vector<int> next_seq(producers, 0);
std::atomic<long long> handled{0};
bool order_ok = true;
Builder b;
auto counting = b.state("counting");
b.initial(counting);
const auto bump = b.event("bump");
b.internal(counting, bump)
.action(SyncAction{[&](Machine&, const Event& e) {
const auto p = std::any_cast<Payload>(e.payload);
// Per-producer FIFO must hold (single consumer).
if (next_seq[static_cast<std::size_t>(p.producer)] != p.seq) {
order_ok = false;
}
++next_seq[static_cast<std::size_t>(p.producer)];
++handled;
}});
auto def = b.build();
Void::Testing::expect(def.has_value());
Machine m{*def}; // own worker
m.start();
std::atomic<bool> go{false};
std::vector<std::thread> threads;
threads.reserve(producers);
for (int p = 0; p < producers; ++p) {
threads.emplace_back([&m, &go, bump, p] {
go.wait(false);
for (int i = 0; i < per_producer; ++i) {
while (!m.post(Event{bump, Payload{p, i}})) {
std::this_thread::yield();
}
}
});
}
go = true;
go.notify_all();
for (auto& t : threads) {
t.join();
}
// Everything posted before this send_wait is processed before it.
(void)m.send_wait(Event{bump, Payload{0, per_producer}});
++next_seq[0]; // account for the flush event
m.stop();
Void::Testing::expect_eq(
handled.load(),
static_cast<long long>(producers) * per_producer + 1);
Void::Testing::expect(order_ok);
}
// @tag stress, concurrency
Void::Testing::Test snapshot_reads_never_tear_under_load()
{
Builder b;
auto ping = b.state("ping");
auto pong = b.state("pong");
b.initial(ping);
const auto flip = b.event("flip");
b.transition(ping, flip, pong);
b.transition(pong, flip, ping);
auto def = b.build();
Void::Testing::expect(def.has_value());
Machine m{*def};
m.start();
std::atomic<bool> stop{false};
std::atomic<long long> reads{0};
bool sane = true;
std::vector<std::thread> readers;
readers.reserve(4);
for (int r = 0; r < 4; ++r) {
readers.emplace_back([&] {
while (!stop.load(std::memory_order_relaxed)) {
const auto snap = m.current();
// Exactly one leaf, and it is one of the two states.
if (snap.leaf_count != 1) {
sane = false;
}
++reads;
}
});
}
for (int i = 0; i < 20'000; ++i) {
m.post(Event{flip, {}});
}
(void)m.send_wait(Event{flip, {}});
stop = true;
for (auto& t : readers) {
t.join();
}
m.stop();
Void::Testing::expect(sane);
Void::Testing::expect(reads.load() > 0);
}
// @tag stress, concurrency
Void::Testing::Test hot_swap_under_sustained_load()
{
auto make = [](bool variant) {
Builder b;
auto ping = b.state("ping");
auto pong = b.state("pong");
b.initial(ping);
const auto flip = b.event("flip");
b.transition(ping, flip, pong);
b.transition(pong, flip, ping);
if (variant) {
// identical topology, extra no-op event
(void)b.event("extra");
}
auto def = b.build();
Void::Testing::expect(def.has_value());
return *def;
};
Machine m{make(false)};
m.start();
std::atomic<bool> stop{false};
std::vector<std::thread> producers;
producers.reserve(4);
const auto flip = *m.definition()->event_id("flip");
for (int p = 0; p < 4; ++p) {
producers.emplace_back([&m, &stop, flip] {
while (!stop.load(std::memory_order_relaxed)) {
(void)m.post(Event{flip, {}});
// Pace producers so the backlog stays bounded — the test
// exercises swap-under-load, not queue growth.
std::this_thread::yield();
}
});
}
for (int i = 0; i < 50; ++i) {
m.swap_definition(make(i % 2 == 1));
std::this_thread::sleep_for(std::chrono::microseconds{200});
}
stop = true;
for (auto& t : producers) {
t.join();
}
(void)m.send_wait(Event{flip, {}});
// Machine is still coherent: exactly one of the two states active.
const bool in_ping = m.is_in("ping");
const bool in_pong = m.is_in("pong");
Void::Testing::expect(in_ping != in_pong);
m.stop();
}