#!/usr/bin/env python3 """The exported protocol enums must stay in lockstep with the proto, and the typo-safe resolver must reject bad values with a helpful message. Plain asserts — run directly.""" import sys from secsgem_client import JobState, Milestone, ModuleState from secsgem_client._client import _enum_value from secsgem_client._proto import equipment_pb2 as pb def members(e): return {m.value for m in e} def main() -> int: # Each enum mirrors its proto source exactly — no drift, no missing member. assert members(Milestone) == set(pb.SubstrateReport.Milestone.keys()) assert members(ModuleState) == set(pb.ModuleReport.State.keys()) assert members(JobState) == set(pb.ProcessJobState.State.keys()) # A member IS its wire name, so enum and plain string are interchangeable. assert Milestone.ARRIVED == "ARRIVED" assert _enum_value(pb.SubstrateReport.Milestone, Milestone.ARRIVED, "milestone") \ == _enum_value(pb.SubstrateReport.Milestone, "ARRIVED", "milestone") # A typo raises ValueError (client-side, not a daemon round-trip) and the # message offers the close match instead of leaking a raw protobuf error. try: _enum_value(pb.SubstrateReport.Milestone, "AT_WROK", "milestone") raise SystemExit("expected ValueError for a misspelled milestone") except ValueError as e: assert "AT_WORK" in str(e), str(e) print("enums: proto-sync + typo-safety checks passed") return 0 if __name__ == "__main__": sys.exit(main())