fix(minimateplus): push_config_raw checks every block before the first write goes out (#46 review)

Review of b5037b0 (measured on 12 recorded SFM compliance reads): the read
keeps three escape bytes from its reply headers, so every real config image is
refused by write_image -- correctly, but only after 68 and 73 had been sent,
with a message saying nothing was.  All four blocks are now checked first; the
test feeds the block exactly as SFM's read produces it and asserts no frame is
sent (two went out without the check).

Config push stays unusable on purpose: fixing that read alone would let the
compliance encoder write some fields to the wrong bytes (e.g. 4,096 sps as
4,112) while the image still passes.  The rework -- logical read, encoding at
measured offsets with #48, a diff check, N pinned per SUB, an idle check, the
start/stop safeguards on POST /device/config -- is recorded in the spec and on
#46.  Start/stop frames are unchanged (verified byte-identical by the review).

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-27 03:17:34 -04:00
1 parent 329f7f2abb
commit 20ea61e0e9
3 files changed
+45

No files matched your search

@@ -428,6 +428,21 @@ Each safety piece arrives with its first real use, so nothing sits untested.
value during a call-home is unmeasured** -- the change path would
refuse it as unknown. To measure: a MiniMate stop with ACH on, through
the bridge.
- ⚠ **MiniMate config push (#46): framing fixed (`b5037b0`), NOT
usable yet.** Review 2026-10-27, measured on recorded reads: (C1)
`read_compliance_config` keeps three escape bytes from its reply
headers, so every real config is refused -- now before any frame is
sent (`push_config_raw` checks all four blocks first); (C2) fixing that
read alone lets the encoder write some fields to the wrong bytes while
the image still passes the N+2 guard (e.g. 4,096 sps written as 4,112).
The rework: read the compliance block logically (reply page bytes +
data, unescaped), encode at the measured logical offsets (mode [5],
rate [6:8], interval [8:10], record time [18:22], trigger Tran+30,
alarm Tran+38) -- with #48 --, diff-check that only the requested
fields changed, pin N per SUB, refuse unless 0x1C reads idle, give
`POST /device/config` the start/stop safeguards, and test
`apply_config` from recorded replies. Review findings I2-I4, M1-M4
are in the #46 thread.
- Still owed:
- **before merging to dev, align `persist_download`'s already-stored
check with what v0.32.0 shipped** (dev `04acb99`; restamp `5737168`,
+11
View File
@@ -956,6 +956,17 @@ class MiniMateClient:
"""
proto = self._require_proto()
# Every block is checked before the first frame goes out (review of #46,
# 2026-10-27): a block refused after 68 + 73 had been sent left a partial
# write behind. write_image is the same check each write makes.
from .protocol import (SUB_COMPLIANCE_WRITE, SUB_EVENT_INDEX_WRITE,
SUB_TRIGGER_CONFIG_WRITE, SUB_WAVEFORM_DATA_WRITE, write_image)
for sub, data in ((SUB_EVENT_INDEX_WRITE, event_index_data),
(SUB_COMPLIANCE_WRITE, compliance_data),
(SUB_TRIGGER_CONFIG_WRITE, trigger_data),
(SUB_WAVEFORM_DATA_WRITE, waveform_data)):
write_image(sub, data)
# 68 → 73
log.info("push_config_raw: write event index (SUB 68)")
proto.write_event_index(event_index_data)
+19
View File
@@ -247,3 +247,22 @@ def test_apply_config_writes_the_units_own_trigger_block():
trig = [a[0] for n, a in c._proto.writes if n == "write_trigger_config"]
assert trig == [_image(0x82)[:-2]]
assert trig[0][5] == 0x01 # BE9441's; the March copy had 0x03
def test_a_bad_block_is_refused_before_the_first_write_goes_out():
"""Review of #46 (2026-10-27, measured on 12 recorded SFM reads): the compliance
read keeps three escape bytes from its reply headers and unescapes to
00 + cfg[0:1024] + 00 00 + cfg[1024:2090]. That block was refused -- but only
after 68 and 73 had been sent. push_config_raw now checks all four first.
(The read is deliberately not 'fixed' on its own: the encoder would then write
some fields to the wrong bytes while the image still passes -- see #46.)"""
from minimateplus.client import MiniMateClient
cfg = _image(0x71)[:-2]
as_sfm_reads_it = b"\x00" + cfg[:1024] + b"\x00\x00" + cfg[1024:]
p, t = _proto()
c = MiniMateClient(transport=object())
c._proto = p
with pytest.raises(ValueError, match="not a whole block"):
c.push_config_raw(_image(0x68)[:-2], as_sfm_reads_it + b"\x00\x00",
_image(0x82)[:-2], _image(0x69))
assert t.sent == []