test(minimateplus): each strict-stream refusal has its own test; a re-poll always follows a SESSION_RESET
Review of75d79ec/d73a27d(mutation): removing the chunk-timeout raise went unnoticed because the TERM raise also said 'ended early', and the no-STRT, metadata-page, mid-stream-terminator and chunk-cap raises had no test at all; a re-poll without SESSION_RESET passed because the test double ignored it. Each refusal is now pinned by its own message, each verified by removing it (bytecode caching off -- same-second, same-size rewrites reuse a stale .pyc). The strict tests use the shared replay helpers, which load either fixture. 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
a7214c50de
commit
78617d47ce
3 files changed
+60
-50
No files matched your search
@@ -10,16 +10,18 @@ from pathlib import Path
|
|||||||
import minimateplus.protocol as mp
|
import minimateplus.protocol as mp
|
||||||
from minimateplus.framing import S3FrameParser
|
from minimateplus.framing import S3FrameParser
|
||||||
|
|
||||||
FIX = Path(__file__).parent / "fixtures" / "minimate-bench-10-25-26" / "BE9441_event1_0111646a_rx.bin"
|
_DIR = Path(__file__).parent / "fixtures" / "minimate-bench-10-25-26"
|
||||||
|
FIX = _DIR / "BE9441_event1_0111646a_rx.bin" # event 1 (non-first): no metadata pages
|
||||||
|
FIX_EVENT0 = _DIR / "BE9441_event0_01110000_rx.bin" # event 0: metadata pages 0x1002 / 0x1004
|
||||||
KEY = bytes.fromhex("0111646a")
|
KEY = bytes.fromhex("0111646a")
|
||||||
STAMP = "2026-10-25T14:10:49"
|
STAMP = "2026-10-25T14:10:49"
|
||||||
UNIT_PEAKS = {"Tran": 0.030, "Vert": 0.095, "Long": 0.020} # the unit's own 0C peaks, in/s
|
UNIT_PEAKS = {"Tran": 0.030, "Vert": 0.095, "Long": 0.020} # the unit's own 0C peaks, in/s
|
||||||
SESSION_RESET = b"\x41\x03"
|
SESSION_RESET = b"\x41\x03"
|
||||||
|
|
||||||
|
|
||||||
def recorded_replies():
|
def recorded_replies(path=None):
|
||||||
"""[(sub, raw_bytes)] for every frame of the session, in order."""
|
"""[(sub, raw_bytes)] for every frame of the session, in order."""
|
||||||
raw, out, start, p = FIX.read_bytes(), [], 0, S3FrameParser()
|
raw, out, start, p = (path or FIX).read_bytes(), [], 0, S3FrameParser()
|
||||||
for i in range(len(raw)):
|
for i in range(len(raw)):
|
||||||
for f in p.feed(raw[i:i + 1]):
|
for f in p.feed(raw[i:i + 1]):
|
||||||
out.append((f.sub, raw[start:i + 1]))
|
out.append((f.sub, raw[start:i + 1]))
|
||||||
|
|||||||
@@ -1,42 +1,41 @@
|
|||||||
"""A one-event download must not keep an event whose 5A stream ended early.
|
"""A one-event download must not keep an event whose 5A stream ended early.
|
||||||
|
|
||||||
BE9441 rebooted mid-download at the bench (2026-10-25): the chunk at 0x7D06 got
|
BE9441 rebooted mid-download at the bench (2026-10-25): the chunk at 0x7D06 got
|
||||||
no reply, the loop logged "unexpected end-of-stream -- proceeding to TERM", the
|
one stray byte and then silence, the loop logged "unexpected end-of-stream --
|
||||||
TERM got no reply either, and the short event was stored as a success. In
|
proceeding to TERM", the TERM got no reply either, and the short event was
|
||||||
strict mode (the one-event download) every early end now raises; the legacy
|
stored as a success. In strict mode (the one-event download) every early end
|
||||||
full walk keeps its tolerance. Driven by BE9441's recorded replies for event 1.
|
now raises, each with its own message; the legacy full walk keeps its
|
||||||
|
tolerance. Driven by BE9441's recorded A5 replies.
|
||||||
"""
|
"""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||||
|
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
||||||
|
|
||||||
import minimateplus.protocol as mp # noqa: E402
|
import minimateplus.protocol as mp # noqa: E402
|
||||||
from minimateplus.framing import S3FrameParser # noqa: E402
|
from minimate_replay import FIX, FIX_EVENT0, fast_clock, recorded_replies # noqa: E402
|
||||||
|
|
||||||
FIX = Path(__file__).parent / "fixtures" / "minimate-bench-10-25-26" / "BE9441_event1_0111646a_rx.bin"
|
|
||||||
KEY = bytes.fromhex("0111646a")
|
KEY = bytes.fromhex("0111646a")
|
||||||
|
KEY0 = bytes.fromhex("01110000")
|
||||||
|
|
||||||
|
|
||||||
def a5_replies() -> list:
|
@pytest.fixture(autouse=True)
|
||||||
"""The raw bytes of each A5 reply, in order (the parser fed one byte at a time)."""
|
def _fast(monkeypatch):
|
||||||
raw, out, start, p = FIX.read_bytes(), [], 0, S3FrameParser()
|
fast_clock(monkeypatch)
|
||||||
for i in range(len(raw)):
|
|
||||||
for f in p.feed(raw[i:i + 1]):
|
|
||||||
if f.sub == 0xA5:
|
def a5_replies(path=FIX) -> list:
|
||||||
out.append(raw[start:i + 1])
|
return [raw for sub, raw in recorded_replies(path) if sub == 0xA5]
|
||||||
start = i + 1
|
|
||||||
return out
|
|
||||||
|
|
||||||
|
|
||||||
class Replay:
|
class Replay:
|
||||||
"""One recorded reply per 5A request; from request number `silent_from` on, one
|
"""One recorded A5 reply per 5A request, in order. From request `silent_from`
|
||||||
stray 0x41 and then silence -- what BE9441 sent as it rebooted."""
|
on: one stray 0x41 and then silence -- what BE9441 sent as it rebooted."""
|
||||||
|
|
||||||
def __init__(self, replies, silent_from=None):
|
def __init__(self, replies, silent_from=None):
|
||||||
self.replies, self.silent_from, self.sent, self._buf = list(replies), silent_from, 0, b""
|
self.replies, self.silent_from, self.sent, self._buf = list(replies), silent_from, 0, b""
|
||||||
@@ -53,45 +52,50 @@ class Replay:
|
|||||||
return out
|
return out
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(autouse=True)
|
def stream(replies, key=KEY, silent_from=None, **kw):
|
||||||
def fast_clock(monkeypatch):
|
|
||||||
t = [0.0]
|
|
||||||
|
|
||||||
def tick():
|
|
||||||
t[0] += 0.5
|
|
||||||
return t[0]
|
|
||||||
monkeypatch.setattr(mp.time, "monotonic", tick)
|
|
||||||
monkeypatch.setattr(mp.time, "sleep", lambda s: None)
|
|
||||||
|
|
||||||
|
|
||||||
def proto(silent_from=None):
|
|
||||||
replies = a5_replies()
|
|
||||||
p = mp.MiniMateProtocol(Replay(replies, silent_from))
|
p = mp.MiniMateProtocol(Replay(replies, silent_from))
|
||||||
return p, len(replies)
|
return p.read_bulk_waveform_stream(key, stop_after_metadata=False, include_terminator=True, **kw)
|
||||||
|
|
||||||
|
|
||||||
def test_the_recorded_stream_replays_whole():
|
def test_the_recorded_stream_replays_whole():
|
||||||
p, n = proto()
|
assert len(stream(a5_replies(), strict=True)) == 51
|
||||||
frames = p.read_bulk_waveform_stream(KEY, stop_after_metadata=False, include_terminator=True,
|
|
||||||
strict=True)
|
|
||||||
assert len(frames) == n == 51
|
|
||||||
|
|
||||||
|
|
||||||
def test_strict_raises_when_a_chunk_gets_no_reply():
|
def test_strict_raises_when_a_chunk_gets_no_reply():
|
||||||
p, _ = proto(silent_from=40)
|
with pytest.raises(mp.ProtocolError, match="no reply for the chunk at 0x"):
|
||||||
with pytest.raises(mp.ProtocolError, match="ended early"):
|
stream(a5_replies(), silent_from=40, strict=True)
|
||||||
p.read_bulk_waveform_stream(KEY, stop_after_metadata=False, include_terminator=True,
|
|
||||||
strict=True)
|
|
||||||
|
|
||||||
|
|
||||||
def test_strict_raises_when_the_term_gets_no_reply():
|
def test_strict_raises_when_the_term_gets_no_reply():
|
||||||
p, n = proto(silent_from=50) # every chunk answered, the TERM not
|
with pytest.raises(mp.ProtocolError, match="no reply to the TERM request"):
|
||||||
with pytest.raises(mp.ProtocolError, match="TERM"):
|
stream(a5_replies(), silent_from=50, strict=True) # every chunk answered, the TERM not
|
||||||
p.read_bulk_waveform_stream(KEY, stop_after_metadata=False, include_terminator=True,
|
|
||||||
strict=True)
|
|
||||||
|
def test_strict_raises_when_a_metadata_page_gets_no_reply():
|
||||||
|
with pytest.raises(mp.ProtocolError, match="metadata page 0x1002 got no reply"):
|
||||||
|
stream(a5_replies(FIX_EVENT0), key=KEY0, silent_from=1, strict=True)
|
||||||
|
|
||||||
|
|
||||||
|
def test_strict_raises_on_a_terminator_mid_stream():
|
||||||
|
r = a5_replies()
|
||||||
|
r[10] = r[-1] # the TERM reply in place of chunk 10
|
||||||
|
with pytest.raises(mp.ProtocolError, match="sent its terminator"):
|
||||||
|
stream(r, strict=True)
|
||||||
|
|
||||||
|
|
||||||
|
def test_strict_raises_at_the_chunk_cap():
|
||||||
|
with pytest.raises(mp.ProtocolError, match="chunk cap"):
|
||||||
|
stream(a5_replies(), max_chunks=5, strict=True)
|
||||||
|
|
||||||
|
|
||||||
|
def test_strict_raises_when_the_probe_has_no_strt():
|
||||||
|
r = a5_replies()
|
||||||
|
assert b"STRT" in r[0]
|
||||||
|
r[0] = r[0].replace(b"STRT", b"XXXX")
|
||||||
|
with pytest.raises(mp.ProtocolError, match="no STRT record"):
|
||||||
|
stream(r, strict=True)
|
||||||
|
|
||||||
|
|
||||||
def test_the_legacy_walk_keeps_its_tolerance():
|
def test_the_legacy_walk_keeps_its_tolerance():
|
||||||
p, _ = proto(silent_from=40)
|
frames = stream(a5_replies(), silent_from=40)
|
||||||
frames = p.read_bulk_waveform_stream(KEY, stop_after_metadata=False, include_terminator=True)
|
|
||||||
assert 0 < len(frames) < 51 # short, returned, not raised -- as before
|
assert 0 < len(frames) < 51 # short, returned, not raised -- as before
|
||||||
@@ -42,6 +42,7 @@ class Booting(SessionReplay):
|
|||||||
|
|
||||||
def write(self, data):
|
def write(self, data):
|
||||||
data = bytes(data)
|
data = bytes(data)
|
||||||
|
self.log = getattr(self, "log", []) + [data]
|
||||||
if data[:2] == b"\x41\x02" and data[5] == 0x5B and data[8] == 0x00: # the POLL probe
|
if data[:2] == b"\x41\x02" and data[5] == 0x5B and data[8] == 0x00: # the POLL probe
|
||||||
self.polls += 1
|
self.polls += 1
|
||||||
if self.polls == 1:
|
if self.polls == 1:
|
||||||
@@ -64,6 +65,9 @@ def test_a_unit_booting_on_connect_is_waited_for():
|
|||||||
_client, info = connect(t)
|
_client, info = connect(t)
|
||||||
assert info.serial == "BE9441"
|
assert info.serial == "BE9441"
|
||||||
assert t.polls == 4 # the lost one, two while booting, the answered one
|
assert t.polls == 4 # the lost one, two while booting, the answered one
|
||||||
|
probes = [i for i, w in enumerate(t.log) if w[5:6] == b"\x5b" and w[8] == 0x00]
|
||||||
|
assert all(t.log[i - 1] == b"\x41\x03" for i in probes) # every POLL follows a SESSION_RESET
|
||||||
|
assert {w[5] for w in t.log if w[:2] == b"\x41\x02"} <= {0x5B, 0x15, 0x01, 0x1A, 0x08} # reads only
|
||||||
|
|
||||||
|
|
||||||
def test_a_unit_that_boots_but_never_answers_says_so():
|
def test_a_unit_that_boots_but_never_answers_says_so():
|
||||||
|
|||||||
Reference in new issue
Block a user