Files
seismo-relay/tests/test_5a_checksum_escape.py
T
serversdownandClaude Opus 5.5 8acb9512a9 fix(minimateplus): size the 5A chunk cap from STRT, refuse a misread STRT, TERM only a tail
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
2026-10-26 15:16:10 -04:00

38 lines
1.6 KiB
Python

"""A 5A request's checksum is DLE-escaped when it lands on 02 / 03 / 04 / 10.
BE9441 (bench, 2026-10-25/26) never answered the request for chunk 0x7D06 of
event 01122f06 -- twice, each time rebooting ~11 s later -- because the frame
ended `... 02 03`: a bare 0x02 checksum, the STX byte, before ETX. Sent with
the checksum escaped (`10 02 03`) it answered in 28 ms, as did chunks 0x7F06
(checksum 0x04) and 0x8B06 (0x10), and the event downloaded whole and verified.
The escape set is the one a Micromate uses for every byte (measured on 251/251
THOR requests); the MiniMate's own de-stuffing keeps `10 02/03/04` literal.
"""
from __future__ import annotations
import os
import sys
import pytest
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from minimateplus.framing import build_5a_request # noqa: E402
def chunk(counter: int) -> str:
# Event 01122f06's chunk reads, length 0x0200 (once read as an "offset 0x1002")
return build_5a_request(0x01120000 + counter, 0x0200).hex()
@pytest.mark.parametrize("counter,wire", [
# the wire bytes BE9441 answered, checksum escaped
(0x7D06, "41021010005a0010020001127d06000000000000100203"), # checksum 0x02
(0x7F06, "41021010005a0010020001127f06000000000000100403"), # checksum 0x04
(0x8B06, "41021010005a0010020001128b06000000000000101003"), # checksum 0x10
# an ordinary checksum is untouched
(0x7B06, "41021010005a0010020001127b060000000000000003"),
])
def test_the_checksum_is_escaped_only_when_it_is_a_framing_byte(counter, wire):
assert chunk(counter) == wire