fix(sfm): a stale Series-3 id is refused before the full download, not after
Series3Adapter.download_event compared the timestamp only after
download_event_by_key had run the whole 5A. A stale id cost a full
download of the wrong event (minutes on cellular), could surface the
64 KB-page 502 instead of 409, and a lost 0C reply was reported as "the
unit was erased".
- get_events() gains only_key_timestamp: with only_key, if the target's 0C
says another time (or none), the target takes the existing bypass --
no 1F(arm), no POLL, no 5A. A new branch only; it adds no command.
- download_event_by_key(key4, *, expected_timestamp=None) passes it on.
- The adapter converts the id's stamp to that ISO form and checks, in
order: no event -> 404; no readable 0C timestamp -> 502 MalformedReply
("could not read ... record (0C)"); a different time -> 409 StaleEvent;
no frames -> 502.
- The fake's download mirrors the real walk (no frames on a mismatch) and
records what it was asked for.
- Legacy get_events() (none of the new options) is pinned by a test of
its exact call sequence and 5A arguments, written before the change.
Read-only; nothing new on the wire. No codec, store or DB change.
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
157fcc51a7
commit
01b9188f25
5 files changed
+141
-12
No files matched your search
@@ -80,13 +80,29 @@ def test_a_key_that_is_not_stored_is_404():
|
||||
|
||||
|
||||
def test_a_stale_id_is_refused_rather_than_downloading_another_event():
|
||||
fake = FakeMiniMateClient()
|
||||
with pytest.raises(StaleEvent, match="20261001080000"):
|
||||
adapter(FakeMiniMateClient()).download_event(TCP, "BE18193", FIRST, "20250101000000")
|
||||
adapter(fake).download_event(TCP, "BE18193", FIRST, "20250101000000")
|
||||
# The walk was told what to expect, so it compared after 0C and sent no 5A.
|
||||
assert fake.download_requests == [(FIRST, "2025-01-01T00:00:00")]
|
||||
assert fake.last_download is not None and fake.last_download._a5_frames is None
|
||||
|
||||
|
||||
def test_an_id_without_a_timestamp_skips_the_check():
|
||||
dl = adapter(FakeMiniMateClient()).download_event(TCP, "BE18193", FIRST, None)
|
||||
fake = FakeMiniMateClient()
|
||||
dl = adapter(fake).download_event(TCP, "BE18193", FIRST, None)
|
||||
assert dl.event_id == "BE18193:01110000:20261001080000"
|
||||
assert fake.download_requests == [(FIRST, None)]
|
||||
|
||||
|
||||
def test_a_target_whose_record_could_not_be_read_is_not_called_stale():
|
||||
# A lost 0C reply leaves no timestamp to compare: that is a bad reply, not an erase.
|
||||
ev = s3_event(0, "01110000", datetime.datetime(2026, 10, 1, 8, 0, 0))
|
||||
ev.timestamp = None
|
||||
fake = FakeMiniMateClient(events=[ev])
|
||||
with pytest.raises(MalformedReply, match="0C"):
|
||||
adapter(fake).download_event(TCP, "BE18193", FIRST, "20261001080000")
|
||||
assert fake.last_download._a5_frames is None
|
||||
|
||||
|
||||
def test_a_failed_5a_is_a_clear_error():
|
||||
@@ -99,7 +115,7 @@ def test_a_failed_5a_is_a_clear_error():
|
||||
def test_the_64k_page_bug_is_named_not_a_bare_500():
|
||||
fake = FakeMiniMateClient()
|
||||
|
||||
def boom(key4):
|
||||
def boom(key4, **kw):
|
||||
raise struct.error("argument out of range")
|
||||
fake.download_event_by_key = boom
|
||||
with pytest.raises(MalformedReply, match="64 KB"):
|
||||
|
||||
Reference in new issue
Block a user