feat(daemon): alarms by name + RequestControlState + WatchHealth (Phase A complete)
A2 — alarms: optional 'name:' on alarm config (a LOCAL key — SEMI only
defines numeric ALID + freetext ALTX; field appended last so existing
{id, text, category} brace-inits compile unchanged), parsed by the loader,
checked by the validator, shipped in equipment.yaml. SetAlarm/ClearAlarm
RPCs resolve config name OR stringified ALID via a constructor snapshot.
A3 — control state + health: RequestControlState fires operator events on
the io thread (read_sync) and reports what the E30 table actually did —
ACCEPT iff the equipment landed in the requested state, CANNOT_DO_NOW naming
the actual state otherwise (the shipped table has no operator path to
EquipmentOffline; the test pins that honesty). ATTEMPT_ONLINE is rejected as
transient. WatchHealth streams an immediate snapshot then pushes on link/
control-state changes via service observers (add_link_observer +
add_control_state_observer — the HandlerSlot work paying off), spool depth
sampled at the 500ms poll; ends on cancel or engine stop.
Tests: daemon suite 61 -> 101 assertions (alarm lifecycle by name/id/unknown,
WatchHealth initial + change push, all four RequestControlState semantics);
loader test for the alarm name (present + absent fallback); core 467/3055.
Interop now 15 checks incl. gRPC SetAlarm -> host receives S5F1 ALCD=0x84
ALID=1, and RequestControlState(HOST_OFFLINE) -> GetControlState confirms.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -125,6 +125,30 @@ TEST_CASE("Equipment gRPC service over an in-process channel") {
|
||||
check_all(rt.model().dvids.all());
|
||||
}
|
||||
|
||||
SUBCASE("SetAlarm / ClearAlarm by config name, by stringified id, unknown rejected") {
|
||||
auto call = [&](auto method, const std::string& name) {
|
||||
grpc::ClientContext ctx;
|
||||
pb::Alarm req;
|
||||
pb::Ack resp;
|
||||
req.set_name(name);
|
||||
REQUIRE((stub.get()->*method)(&ctx, req, &resp).ok());
|
||||
return resp.code();
|
||||
};
|
||||
// By config name.
|
||||
CHECK(call(&pb::Equipment::Stub::SetAlarm, "chiller_temp_high") == pb::Ack::ACCEPT);
|
||||
rt.poll();
|
||||
CHECK(rt.model().alarms.active(1));
|
||||
CHECK(call(&pb::Equipment::Stub::ClearAlarm, "chiller_temp_high") == pb::Ack::ACCEPT);
|
||||
rt.poll();
|
||||
CHECK_FALSE(rt.model().alarms.active(1));
|
||||
// By stringified ALID — always works, even for unnamed alarms.
|
||||
CHECK(call(&pb::Equipment::Stub::SetAlarm, "2") == pb::Ack::ACCEPT);
|
||||
rt.poll();
|
||||
CHECK(rt.model().alarms.active(2));
|
||||
// Unknown name.
|
||||
CHECK(call(&pb::Equipment::Stub::SetAlarm, "no_such_alarm") == pb::Ack::PARAMETER_INVALID);
|
||||
}
|
||||
|
||||
SUBCASE("FireEvent accepts a known event and rejects an unknown one") {
|
||||
{
|
||||
grpc::ClientContext ctx;
|
||||
@@ -205,6 +229,58 @@ TEST_CASE("GetVariables round-trip under run_async (production threading mode)")
|
||||
CHECK(st.error_message().find("definitely_not_a_var") != std::string::npos);
|
||||
}
|
||||
|
||||
SUBCASE("RequestControlState walks the E30 table; WatchHealth pushes the change") {
|
||||
// Open the health stream first: the initial snapshot arrives immediately.
|
||||
grpc::ClientContext health_ctx;
|
||||
pb::Empty empty;
|
||||
auto reader = stub->WatchHealth(&health_ctx, empty);
|
||||
pb::Health h;
|
||||
REQUIRE(reader->Read(&h));
|
||||
CHECK(h.link() == pb::Health::DISCONNECTED); // no HSMS host in this test
|
||||
CHECK(h.control_state() == pb::ControlState::HOST_OFFLINE);
|
||||
CHECK(h.spool_depth() == 0);
|
||||
|
||||
auto request = [&](pb::ControlState::State desired) {
|
||||
grpc::ClientContext ctx;
|
||||
pb::ControlStateRequest req;
|
||||
pb::Ack resp;
|
||||
req.set_desired(desired);
|
||||
REQUIRE(stub->RequestControlState(&ctx, req, &resp).ok());
|
||||
return resp;
|
||||
};
|
||||
|
||||
// HostOffline --operator_online--> (AttemptOnline) --> OnlineLocal.
|
||||
CHECK(request(pb::ControlState::ONLINE_LOCAL).code() == pb::Ack::ACCEPT);
|
||||
CHECK(rt.control_state() == gem::ControlState::OnlineLocal);
|
||||
|
||||
// The stream pushes the change (well inside its 500ms poll interval).
|
||||
REQUIRE(reader->Read(&h));
|
||||
CHECK(h.control_state() == pb::ControlState::ONLINE_LOCAL);
|
||||
|
||||
// OnlineLocal --operator_remote--> OnlineRemote.
|
||||
CHECK(request(pb::ControlState::ONLINE_REMOTE).code() == pb::Ack::ACCEPT);
|
||||
CHECK(rt.control_state() == gem::ControlState::OnlineRemote);
|
||||
|
||||
// Transient state is not requestable.
|
||||
CHECK(request(pb::ControlState::ATTEMPT_ONLINE).code() == pb::Ack::PARAMETER_INVALID);
|
||||
|
||||
// The shipped table has NO operator path to EquipmentOffline:
|
||||
// operator_offline lands HostOffline — the API must say so honestly.
|
||||
auto resp = request(pb::ControlState::EQUIPMENT_OFFLINE);
|
||||
CHECK(resp.code() == pb::Ack::CANNOT_DO_NOW);
|
||||
CHECK(resp.message().find("HostOffline") != std::string::npos);
|
||||
CHECK(rt.control_state() == gem::ControlState::HostOffline);
|
||||
|
||||
// Requesting HOST_OFFLINE (the state operators actually get) succeeds —
|
||||
// idempotently, since we're already there.
|
||||
CHECK(request(pb::ControlState::HOST_OFFLINE).code() == pb::Ack::ACCEPT);
|
||||
|
||||
health_ctx.TryCancel();
|
||||
pb::Health drain;
|
||||
while (reader->Read(&drain)) {}
|
||||
(void)reader->Finish(); // CANCELLED — expected
|
||||
}
|
||||
|
||||
server->Shutdown();
|
||||
rt.stop();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include <doctest/doctest.h>
|
||||
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
|
||||
@@ -144,3 +145,24 @@ TEST_CASE("loader: control_job_state.yaml -> non-empty table") {
|
||||
REQUIRE(row->to.has_value());
|
||||
CHECK(*row->to == gem::ControlJobState::Completed);
|
||||
}
|
||||
|
||||
TEST_CASE("alarm optional name: parsed when present, empty when absent") {
|
||||
gem::EquipmentDataModel m;
|
||||
config::load_equipment(SECSGEM_DATA_DIR "/equipment.yaml", m);
|
||||
// data/equipment.yaml names both alarms.
|
||||
CHECK(m.alarms.get(1)->name == "chiller_temp_high");
|
||||
CHECK(m.alarms.get(2)->name == "door_open");
|
||||
|
||||
// A config without `name:` yields an empty name (back-compat).
|
||||
const auto path = std::filesystem::temp_directory_path() / "alarm_noname.yaml";
|
||||
{
|
||||
std::ofstream f(path);
|
||||
f << "device: {id: 0, model_name: M, software_rev: R}\n"
|
||||
"alarms:\n"
|
||||
" - {id: 9, text: \"Unnamed\", category: 1}\n";
|
||||
}
|
||||
gem::EquipmentDataModel m2;
|
||||
config::load_equipment(path.string(), m2);
|
||||
CHECK(m2.alarms.get(9)->name.empty());
|
||||
std::filesystem::remove(path);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user