Follow-ups from the review of 887e75d (verdict: keep, with fixes; no critical).
- The cap: a caller's max_chunks (client.py passes 128) now bounds only a walk
whose end is unknown. With STRT it cut every event past ~66 KB short --
2,545 of 63,500 archived histograms are bigger (the review's count, DL2).
Strict raised; legacy sent a TERM for most of the event, or a bare ValueError.
- A STRT claiming less than one 0x200 chunk, or more than 4 MiB (a sanity bound,
not a measured limit), is refused as a misread, in both modes -- once a bare
ValueError and a 500.
- TERM is sent only for a true tail (< 0x200). After an early end the legacy
walk returns what arrived and sends none.
- build_5a_request wraps build_bw_frame; the old 5A helpers are marked
superseded (kept for tests/test_5a_protocol.py) and their imports dropped.
Tests: all 8 recorded events (were 4) walk exactly as Blastware and rebuild its
own files; an end key holding escaped bytes; a 300 KB event past a 128 cap; both
misread-STRT refusals; the 1A frames BE9441 answered post-fix; the checksum
vectors retargeted. Mutants the review saw survive (no STRT un-escape; a
standard-request escape revert) and 3 new ones are each caught.
Measured on the way: a reply's checksum is SUM8 of its unescaped payload,
748/748. The 'S3 checksums frequently fail' note was the parser summing its
own kept escape bytes; noted, parser unchanged.
Docs: the crossing count corrected to four (events 1, 3, 5, 7); the remaining
stale 5A sections in CLAUDE.md annotated; the write-frame suspicion recorded as
inferred only. No codec, store or DB change.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SyJ2ip3Krb6dtdv2cXua44
86 lines
2.9 KiB
Python
86 lines
2.9 KiB
Python
"""BE9441's recorded bench session (2026-10-25), replayed reply for reply.
|
|
|
|
Shared by the MiniMate download tests. See
|
|
tests/fixtures/minimate-bench-10-25-26/README.md for the provenance.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
|
|
import minimateplus.protocol as mp
|
|
from minimateplus.framing import S3FrameParser
|
|
|
|
_DIR = Path(__file__).parent / "fixtures" / "minimate-bench-10-25-26"
|
|
FIX = _DIR / "BE9441_event1_0111646a_rx.bin" # event 1 (non-first)
|
|
FIX_EVENT0 = _DIR / "BE9441_event0_01110000_rx.bin" # event 0 (its chunks at 0x0200 / 0x0400 were
|
|
# once read as "metadata pages 0x1002 / 0x1004")
|
|
KEY = bytes.fromhex("0111646a")
|
|
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
|
|
SESSION_RESET = b"\x41\x03"
|
|
|
|
|
|
def recorded_replies(path=None):
|
|
"""[(sub, raw_bytes)] for every frame of the session, in order."""
|
|
raw, out, start, p = (path or FIX).read_bytes(), [], 0, S3FrameParser()
|
|
for i in range(len(raw)):
|
|
for f in p.feed(raw[i:i + 1]):
|
|
out.append((f.sub, raw[start:i + 1]))
|
|
start = i + 1
|
|
return out
|
|
|
|
|
|
class SessionReplay:
|
|
"""Answers each request with the next recorded reply of its own SUB (reply =
|
|
0xFF - request). `quiet_5a_from`: from that 5A request on, the 5A stream gets
|
|
one stray 0x41 and then nothing, while every other request is still answered
|
|
-- BE9441 dropped out of the stream as it rebooted, then answered the walk."""
|
|
|
|
def __init__(self, replies, quiet_5a_from=None):
|
|
self.queues = {}
|
|
for sub, raw in replies:
|
|
self.queues.setdefault(sub, []).append(raw)
|
|
self.quiet_5a_from, self.n5a, self._buf, self.open_ = quiet_5a_from, 0, b"", False
|
|
|
|
def connect(self):
|
|
self.open_ = True
|
|
|
|
def disconnect(self):
|
|
self.open_ = False
|
|
|
|
def is_connected(self):
|
|
return self.open_
|
|
|
|
def write(self, data):
|
|
data = bytes(data)
|
|
if data == SESSION_RESET:
|
|
return
|
|
req = data[5] # 41 02 10 10 00 <SUB>
|
|
if req == 0x5A:
|
|
n, self.n5a = self.n5a, self.n5a + 1
|
|
if self.quiet_5a_from is not None and n >= self.quiet_5a_from:
|
|
if n == self.quiet_5a_from:
|
|
self._buf += b"\x41"
|
|
return
|
|
self._buf += self.queues[0xFF - req].pop(0)
|
|
|
|
def read(self, n):
|
|
out, self._buf = self._buf[:n], self._buf[n:]
|
|
return out
|
|
|
|
def read_until_idle(self, *a, **kw):
|
|
out, self._buf = self._buf, b""
|
|
return out
|
|
|
|
|
|
|
|
def fast_clock(monkeypatch):
|
|
"""Make the protocol's 10 s receive deadlines pass in a few loop turns."""
|
|
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)
|