fix(micromate): the write ceiling is enforced at the wire; allowed_writes retired; execute takes only real plans

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SyJ2ip3Krb6dtdv2cXua44
This commit is contained in:
serversdownandClaude Opus 5.5 committed 2026-10-23 16:06:24 -04:00
1 parent 8daf413fe3
commit a90b8158b6
5 files changed
+150 -40

No files matched your search

+21 -11
View File
@@ -13,6 +13,7 @@ from micromate.framing import build_request # noqa: E4
from micromate.opcodes import ( # noqa: E402
CROSS_SERIES_COLLISIONS, READ_SUBS, WRITE_SUBS, OpcodeRefused, check_transmit,
)
from micromate.writes import plan_start_monitoring # noqa: E402
from test_micromate_protocol import frame, proto # noqa: E402
# THOR's captured end-call-home frame. Same SUB as Series III's CONFIRM ERASE, not the
@@ -51,15 +52,17 @@ def test_the_protocol_refuses_a_write_and_writes_nothing():
def test_the_protocol_refuses_the_captured_0xa2_frame_byte_for_byte():
p, t = proto([], allowed_writes=frozenset({0xA2}))
p, t = proto([])
with pytest.raises(OpcodeRefused):
p._send(A2_WIRE)
p._send(A2_WIRE, permit=frozenset({0xA2}))
assert t.written == []
def test_an_explicitly_allowed_write_goes_out_on_a_scripted_transport():
p, t = proto([frame(0x69, bytes(11))], allowed_writes=frozenset({0x96}))
p._exchange(0x96, offset=0xFFFF)
def test_a_write_goes_out_only_through_execute_on_a_scripted_transport():
p, t = proto([frame(0xA4, bytes(48)), frame(0x69, bytes(11))])
p.poll()
t.written.clear()
p.execute(plan_start_monitoring())
assert t.written == [build_request(0x96, 0xFFFF)]
@@ -95,10 +98,17 @@ def test_an_unknown_opcode_is_refused_and_nothing_is_written(sub):
assert t.written == []
def test_allowed_writes_may_only_name_catalogued_writes():
for bad in (frozenset({0xEE}), frozenset({0x5B})):
with pytest.raises(ValueError):
proto([], allowed_writes=bad)
@pytest.mark.parametrize("sub", [0xEE, 0x7E, 0xA8])
def test_a_permit_beyond_the_ceiling_is_refused_at_the_wire(sub):
p, t = proto([])
with pytest.raises(OpcodeRefused):
p._send(build_request(sub, 0), permit=frozenset({sub}))
assert t.written == []
def test_allowed_writes_is_retired():
with pytest.raises(TypeError):
proto([], allowed_writes=frozenset({0x96}))
def test_the_tables_are_read_only():
@@ -111,9 +121,9 @@ def test_the_tables_are_read_only():
@pytest.mark.parametrize("tail", [build_request(0x96, 0xFFFF), A2_WIRE])
def test_a_read_followed_by_a_write_in_one_send_is_refused(tail):
p, t = proto([], allowed_writes=frozenset({0x96}))
p, t = proto([])
with pytest.raises(ValueError):
p._send(build_request(0x5B, 0x0030) + tail)
p._send(build_request(0x5B, 0x0030) + tail, permit=frozenset({0x96}))
assert t.written == []