refactor(gem): decompose default handlers per GEM capability + YAML role bindings

register_default_handlers was a relocated app main(): one 1086-line function,
all-or-nothing. It is now 15 per-capability registration functions along the
lines GEM itself defines (S1F19): identification, equipment constants, clock,
event reports, remote commands, trace/limits, spooling, alarms, exceptions,
material tracking (E90/E116/E157), carriers (E87), recipes, object services
(E39), jobs (E40/E94), terminal services. A sensor-class tool registers three
functions instead of carrying carrier/job handlers it doesn't have;
register_default_handlers composes all 15. Each function derives exactly the
runtime aliases its handlers use (generated programmatically from the moved
bodies with boundary/substitution guards — zero hand-retyping).

Magic constants are gone: the control-state/clock SVIDs (were hardcoded 1/2)
and the CJ Executing/Completed CEIDs (were 400/401) now come from a "roles:"
block in equipment.yaml via EquipmentDescriptor, with historical defaults
when absent, loader parsing, and validation (CEID roles must name declared
events). The coupling is now visible in ONE file instead of silently split
between YAML and C++ — the exact drift class this repo's spec-as-data
philosophy exists to kill.

Tests: capability subsetting, role-driven SVID refresh via S1F3, roles
loader (shipped/custom/absent). Battery: core 473/3087 incl. the 53-handler
conformance sweep, daemon 125/125, live GEM300 demo (client exit 0), daemon
interop 20/20 vs secsgem-py.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
2026-06-10 22:43:41 +02:00
parent cf230d4119
commit 912304966f
9 changed files with 822 additions and 527 deletions
+28
View File
@@ -71,3 +71,31 @@ TEST_CASE("register_default_handlers: unknown command is rejected, hook not invo
CHECK(reply->stream == 2);
CHECK(reply->function == 42); // still an S2F42, carrying an error HCACK
}
TEST_CASE("capability registration is subsettable (the point of the decomposition)") {
gem::EquipmentRuntime rt(test_config());
gem::register_identification(rt);
gem::register_terminal_services(rt);
// What we registered answers...
CHECK(rt.router().has_handler(1, 1)); // S1F1
CHECK(rt.router().has_handler(1, 13)); // S1F13
CHECK(rt.router().has_handler(10, 1)); // S10F1
// ...and what we didn't, doesn't: a sensor-class tool with no remote
// commands, jobs, or carriers simply never registers them.
CHECK_FALSE(rt.router().has_handler(2, 41)); // remote commands
CHECK_FALSE(rt.router().has_handler(16, 11)); // E40 jobs
CHECK_FALSE(rt.router().has_handler(3, 17)); // E87 carriers
}
TEST_CASE("role bindings drive the CJ state-change CEIDs and SVID refresh") {
gem::EquipmentRuntime rt(test_config());
gem::register_default_handlers(rt);
// The shipped roles block binds control_state_svid: 1 — S1F3 refreshes it.
auto reply = rt.router().dispatch(gem::s1f3_selected_status_request({1}));
REQUIRE(reply.has_value());
auto sv = rt.model().svids.value(1);
REQUIRE(sv.has_value());
CHECK(sv->as_ascii() == std::string("HostOffline")); // initial control state
}
+35
View File
@@ -166,3 +166,38 @@ TEST_CASE("alarm optional name: parsed when present, empty when absent") {
CHECK(m2.alarms.get(9)->name.empty());
std::filesystem::remove(path);
}
TEST_CASE("roles block: parsed when present, defaults when absent") {
gem::EquipmentDataModel m;
auto desc = config::load_equipment(SECSGEM_DATA_DIR "/equipment.yaml", m);
CHECK(desc.control_state_svid == 1);
CHECK(desc.clock_svid == 2);
CHECK(desc.cj_executing_ceid == 400);
CHECK(desc.cj_completed_ceid == 401);
const auto path = std::filesystem::temp_directory_path() / "roles_custom.yaml";
{
std::ofstream f(path);
f << "device: {id: 0, model_name: M, software_rev: R}\n"
"roles: {control_state_svid: 11, clock_svid: 12,\n"
" cj_executing_ceid: 910, cj_completed_ceid: 911}\n";
}
gem::EquipmentDataModel m2;
auto d2 = config::load_equipment(path.string(), m2);
CHECK(d2.control_state_svid == 11);
CHECK(d2.clock_svid == 12);
CHECK(d2.cj_executing_ceid == 910);
CHECK(d2.cj_completed_ceid == 911);
std::filesystem::remove(path);
const auto path2 = std::filesystem::temp_directory_path() / "roles_absent.yaml";
{
std::ofstream f(path2);
f << "device: {id: 0, model_name: M, software_rev: R}\n";
}
gem::EquipmentDataModel m3;
auto d3 = config::load_equipment(path2.string(), m3);
CHECK(d3.control_state_svid == 1); // historical defaults preserved
CHECK(d3.cj_completed_ceid == 401);
std::filesystem::remove(path2);
}