From b7b054aee95a06b240d3d7558da2e1f16d7fbebe Mon Sep 17 00:00:00 2001 From: serversdown Date: Thu, 22 Oct 2026 17:47:25 -0400 Subject: [PATCH] fix(micromate): the gate refuses an uncatalogued SUB whatever it is told Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01SyJ2ip3Krb6dtdv2cXua44 --- micromate/opcodes.py | 17 ++++++++++------- tests/test_micromate_opcodes.py | 8 +++++++- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/micromate/opcodes.py b/micromate/opcodes.py index 74ee7c1..820bf90 100644 --- a/micromate/opcodes.py +++ b/micromate/opcodes.py @@ -39,7 +39,9 @@ _WRITE_SUBS: Dict[int, str] = { 0xDA: "setup push: file name", } -# Same bytes, opposite consequence on the other series. Never transmitted on +# Same SUB, opposite consequence on the other series (not the same bytes: +# Series III's CONFIRM ERASE carries offset 0x0000 and token 0xFE, THOR's 0xA2 +# carries offset 0xFFFF). Never transmitted on # Series IV, allowed or not: if a Series-III unit is at the address (a moved # modem, a stale IP), it would execute the other meaning. Lifting an entry is # a spec change, not a parameter. @@ -87,17 +89,18 @@ def check_transmit(sub: int, allowed_writes: FrozenSet[int] = frozenset()) -> No """Raise OpcodeRefused unless `sub` may go on the wire. Precedence: (1) a cross-series collision is refused always; (2) a - catalogued write is refused unless in `allowed_writes`; (3) a SUB in - neither READ_SUBS nor `allowed_writes` is unknown and refused. + SUB in neither READ_SUBS nor WRITE_SUBS is unknown and refused whatever + `allowed_writes` says; (3) a catalogued write is refused unless in + `allowed_writes`. """ if sub in CROSS_SERIES_COLLISIONS: raise OpcodeRefused( f"refused to transmit SUB 0x{sub:02X}: {CROSS_SERIES_COLLISIONS[sub]}") + if sub not in READ_SUBS and sub not in WRITE_SUBS: + raise OpcodeRefused( + f"refused to transmit SUB 0x{sub:02X}: unknown opcode -- not in " + "micromate.opcodes; catalogue it first (allowing it does not help)") if sub in WRITE_SUBS and sub not in allowed_writes: raise OpcodeRefused( f"refused to transmit SUB 0x{sub:02X} ({WRITE_SUBS[sub]}): writes are " "not enabled on this connection") - if sub not in READ_SUBS and sub not in allowed_writes: - raise OpcodeRefused( - f"refused to transmit SUB 0x{sub:02X}: unknown opcode -- not in " - "micromate.opcodes; catalogue it first") diff --git a/tests/test_micromate_opcodes.py b/tests/test_micromate_opcodes.py index 336429f..b35edfe 100644 --- a/tests/test_micromate_opcodes.py +++ b/tests/test_micromate_opcodes.py @@ -15,7 +15,8 @@ from micromate.opcodes import ( # noqa: E4 ) from test_micromate_protocol import frame, proto # noqa: E402 -# THOR's captured end-call-home frame -- byte-identical to Series III's CONFIRM ERASE. +# THOR's captured end-call-home frame. Same SUB as Series III's CONFIRM ERASE, not the +# same bytes (S3 carries offset 0x0000 and token 0xFE; this carries offset 0xFFFF). A2_WIRE = bytes.fromhex("4102101000a200ffff00000000000000000000b003") @@ -120,3 +121,8 @@ def test_a_bytearray_frame_is_checked_and_written_as_the_same_bytes(): p, t = proto([]) p._send(bytearray(build_request(0x5B, 0x0030))) assert t.written == [build_request(0x5B, 0x0030)] + + +def test_an_uncatalogued_sub_is_refused_even_when_explicitly_allowed(): + with pytest.raises(OpcodeRefused): + check_transmit(0xEE, frozenset({0xEE}))