fix(minimateplus): a built call-home image is framed once, never unescaped again (phase-4 review)
call_home_image returns the unescaped N + 2 image, but the send path handed it to write_call_home_config, whose write_image unescapes again -- and unescaping is not idempotent: a real 0x10 before 02/03/04 loses its 0x10. A call-in time of 16:02-16:04 (hour 0x10) is exactly that. One such time made the send refuse before the wire yet audited as 'sent, acknowledgement lost'; two made it send a block shifted by two bytes from [101] (num_retries and the time fields wrong). The Blastware-frame test could not see it: it checked the image builder, not the bytes the protocol framed. - MiniMateProtocol.write_call_home_image(image) frames a built image once (0x7E, ack 0x81, 0x7F, ack 0x80), raising ImageRefused before any byte when it is not a whole block; write_call_home_config (the legacy multi-field path) is write_image once + that. Its stale 127-byte docstring is gone. - MiniMateClient.write_call_home_image uses it. - The Series-3 change passes is_refusal=ImageRefused, so a pre-wire refusal is audited as nothing sent (sent = 0), not as a lost ack. Tests drive the real client -> protocol over a stub answering with BE11529's recorded acks: the unit's own read, a 16:02 time, and 16:03 + 16:04 all go out exactly as built; a short image is refused with nothing written. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SyJ2ip3Krb6dtdv2cXua44
This commit is contained in:
1 parent
3e1d42e04b
commit
bdd76b8f74
5 files changed
+186
-36
No files matched your search
@@ -127,3 +127,21 @@ def test_s3_dry_run_with_an_unknown_byte_5_shows_no_frames():
|
||||
fake = FakeMiniMateClient(call_home_raw=s3_call_home_raw(0x07))
|
||||
r = change(adapter(fake), enabled=False, dry_run=True)
|
||||
assert r.plan["steps"] == [] and any("0x07" in w for w in r.plan["warnings"])
|
||||
|
||||
|
||||
|
||||
def test_a_pre_wire_refusal_is_recorded_as_nothing_sent():
|
||||
# Final review #2: a refusal raised before the frame went out must not be
|
||||
# audited as "sent, acknowledgement lost".
|
||||
from minimateplus.protocol import ImageRefused
|
||||
audit = Audit()
|
||||
fake = FakeMiniMateClient(write_error=ImageRefused("write SUB 0x7E: not a whole block"))
|
||||
from sfm.device_access.errors import DeviceError
|
||||
with pytest.raises(DeviceError) as e: # the adapter wraps it, as it does OpcodeRefused
|
||||
adapter(fake).change_call_home(TCP, "BE18193", enabled=False, dry_run=False, even_if_already=False,
|
||||
audit=audit, caller="test", sleep=lambda s: None,
|
||||
verify_timeout_s=3.0, verify_interval_s=1.0)
|
||||
assert isinstance(e.value.__cause__, ImageRefused)
|
||||
((_, row),) = audit.rows.items()
|
||||
assert (row["outcome"], row["sent"]) == ("failed", 0)
|
||||
assert row["error"].startswith("refused before sending")
|
||||
Reference in new issue
Block a user