fix(sfm): a Micromate in an unknown run state gets no call-home write, and a lost ack keeps its snapshot (phase-4 review)

- s4_change_call_home's read_state now returns an unknown(0xNN) run state as
  it is, so the change core refuses it (UnitStateUnknown, nothing sent), as
  start/stop already does; it checked only for calling_home.
- run_change records the snapshot on the lost-ack path too: after an ack is
  lost, what the unit now holds (and, on Series 4, whether [118:120] moved) is
  what tells whether the write landed.

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-11-02 17:23:59 -05:00
1 parent bdd76b8f74
commit 9e03b3f0ab
3 files changed
+30 -4

No files matched your search

+20
View File
@@ -94,3 +94,23 @@ def test_s4_even_if_already_sends_the_no_op_write():
r = change(fake, enabled=True, even_if_already=True)
assert len(fake.executed) == 1
assert any("changes nothing" in w for w in r.plan["warnings"])
def test_s4_unknown_run_state_sends_nothing():
# Final review #3: a run state never measured is refused, as start/stop does.
from sfm.device_access.errors import UnitStateUnknown
fake = FakeMicromateClient(run_states=[0x07])
with pytest.raises(UnitStateUnknown):
change(fake, enabled=False)
assert fake.executed == []
def test_a_lost_ack_still_records_what_the_unit_holds():
# Final review #4: the lost-ack path is where the operator most needs it.
import micromate.protocol as mm_proto
fake = FakeMicromateClient(execute_error=mm_proto.TimeoutError("lost"))
r = change(fake, enabled=False)
assert (r.outcome, r.sent) == ("failed", True)
snap = r.detail["snapshot"]
assert snap["changed_offsets"] == [] and snap["before"] == snap["after"] # the write did not land