fix(minimateplus): the boot-aware first POLL resets the parser; a drained or long-trailed banner is seen
Review of d73a27d: _await_poll_or_boot no longer reset the parser and pending
frames the way _recv_one(reset_parser=True) did, so a reused protocol object
with half a frame left over failed startup (UnexpectedResponse A4 vs A5).
Restored. Also: the banner check now runs before the tail is trimmed (a read
carrying >48 bytes after the banner lost it), and a banner caught during the
200 ms drain is reported, so startup goes straight to the re-poll loop instead
of the full timeout. Tests for all three.
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
151782365b
commit
f6166b4b04
2 files changed
+52
-6
No files matched your search
@@ -33,9 +33,12 @@ class Booting(SessionReplay):
|
||||
"""Banner instead of an answer to the first POLL; then `deaf` more POLL probes
|
||||
go unanswered (still booting); after that, the recorded session as normal."""
|
||||
|
||||
def __init__(self, replies, deaf=2, banner=True):
|
||||
def __init__(self, replies, deaf=2, banner=True, banner_on_open=False, noise_after=0):
|
||||
super().__init__(replies)
|
||||
self.deaf, self.banner, self.polls = deaf, banner, 0
|
||||
self.noise_after = noise_after # non-frame bytes sent after the banner
|
||||
if banner_on_open: # the banner lands inside the drain window
|
||||
self._buf, self.banner = BANNER, False
|
||||
|
||||
def write(self, data):
|
||||
data = bytes(data)
|
||||
@@ -43,7 +46,7 @@ class Booting(SessionReplay):
|
||||
self.polls += 1
|
||||
if self.polls == 1:
|
||||
if self.banner:
|
||||
self._buf += BANNER
|
||||
self._buf += BANNER + b"." * self.noise_after
|
||||
return
|
||||
if self.polls <= 1 + self.deaf:
|
||||
return
|
||||
@@ -75,3 +78,28 @@ def test_a_silent_unit_without_a_banner_fails_as_before():
|
||||
connect(t)
|
||||
assert "boot" not in str(e.value)
|
||||
assert t.polls == 1 # no re-polling without the banner
|
||||
|
||||
|
||||
def test_startup_on_a_reused_protocol_ignores_leftover_bytes():
|
||||
replies = recorded_replies()
|
||||
p = mp.MiniMateProtocol(SessionReplay(replies))
|
||||
a5 = next(raw for sub, raw in replies if sub == 0xA5)
|
||||
p._parser.feed(a5[:20]) # half a frame left over from an earlier exchange
|
||||
assert p.startup().sub == 0xA4
|
||||
|
||||
|
||||
def test_a_banner_followed_by_more_text_in_the_same_read_is_still_seen():
|
||||
t = Booting(recorded_replies(), deaf=1, noise_after=200)
|
||||
assert connect(t)[1].serial == "BE9441"
|
||||
|
||||
|
||||
def test_a_banner_caught_while_draining_is_acted_on(monkeypatch):
|
||||
t_now = [0.0]
|
||||
|
||||
def fine(): # fine enough that the 200 ms drain really reads
|
||||
t_now[0] += 0.01
|
||||
return t_now[0]
|
||||
monkeypatch.setattr(mp.time, "monotonic", fine)
|
||||
t = Booting(recorded_replies(), deaf=1, banner_on_open=True)
|
||||
assert connect(t)[1].serial == "BE9441"
|
||||
assert t._buf == b"" # the drain consumed the banner
|
||||
Reference in new issue
Block a user