From 453d42e32af11ddd61722f93e7761b9891fb1e74 Mon Sep 17 00:00:00 2001 From: serversdown Date: Mon, 2 Nov 2026 16:59:15 -0500 Subject: [PATCH] test(s3): SFM's call-home write equals Blastware's, frame for frame -- opens the live send Ground truth: Blastware changing BE11529's call-home settings on 2026-04-20 (Remote Access -> Setup Unit), paired raw files of what it sent and what the unit answered: the read, the enable (read 0x00 -> wrote 0x01), the disable (read 0x01 -> wrote 0x00). From the unit's own read before each write, SFM's 0x7E frame (call_home_image + build_bw_write_frame) is Blastware's byte for byte -- nothing but byte 5 differs from the read -- and the 0x7F confirm too. Mutation-checked: inverting the byte SFM writes fails the test. S3_CALL_HOME_FRAME_VERIFIED is now True; the gate stays tested shut by monkeypatch, and a test pins that its comment names this proof. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01SyJ2ip3Krb6dtdv2cXua44 --- sfm/device_access/s3.py | 8 ++- ...20260420_162148_pull_call_home_options.bin | Bin 0 -> 736 bytes ..._20260420_162221_enable_auto_call_home.bin | Bin 0 -> 219 bytes ...20260420_162255_disable_auto_call_home.bin | Bin 0 -> 955 bytes ...20260420_162148_pull_call_home_options.bin | Bin 0 -> 1502 bytes ..._20260420_162221_enable_auto_call_home.bin | Bin 0 -> 107 bytes ...20260420_162255_disable_auto_call_home.bin | Bin 0 -> 1609 bytes tests/test_s3_call_home.py | 8 ++- tests/test_s3_call_home_bw_frames.py | 64 ++++++++++++++++++ 9 files changed, 76 insertions(+), 4 deletions(-) create mode 100644 tests/fixtures/s3-call-home-bw/raw_bw_20260420_162148_pull_call_home_options.bin create mode 100644 tests/fixtures/s3-call-home-bw/raw_bw_20260420_162221_enable_auto_call_home.bin create mode 100644 tests/fixtures/s3-call-home-bw/raw_bw_20260420_162255_disable_auto_call_home.bin create mode 100644 tests/fixtures/s3-call-home-bw/raw_s3_20260420_162148_pull_call_home_options.bin create mode 100644 tests/fixtures/s3-call-home-bw/raw_s3_20260420_162221_enable_auto_call_home.bin create mode 100644 tests/fixtures/s3-call-home-bw/raw_s3_20260420_162255_disable_auto_call_home.bin create mode 100644 tests/test_s3_call_home_bw_frames.py diff --git a/sfm/device_access/s3.py b/sfm/device_access/s3.py index c122223..6e5b6ed 100644 --- a/sfm/device_access/s3.py +++ b/sfm/device_access/s3.py @@ -33,9 +33,11 @@ S3_MODES = {0x00: "Single Shot", 0x01: "Continuous", 0x03: "Histogram", 0x04: "H S3_EVENT_TIMEOUT = 120.0 # what the legacy event-download routes use # A MiniMate call-home write goes out only once SFM's 0x7E / 0x7F frames are -# reproduced from Blastware's own (tests/test_s3_call_home_bw_frames.py). Until -# then a live change is refused before any connection; a dry run still works. -S3_CALL_HOME_FRAME_VERIFIED = False +# reproduced from Blastware's own; shut, a live change is refused before any +# connection (a dry run still works). OPEN since 2026-11-02: +# tests/test_s3_call_home_bw_frames.py rebuilds Blastware's enable and disable +# writes (BE11529, 2026-04-20) byte for byte from the unit's own reads. +S3_CALL_HOME_FRAME_VERIFIED = True # The 0x1C flag byte (section[1]): the only values ever measured. 0x10 is # BE11529 monitoring (2026-04-08); 0x0B is BE9441 recording a histogram, diff --git a/tests/fixtures/s3-call-home-bw/raw_bw_20260420_162148_pull_call_home_options.bin b/tests/fixtures/s3-call-home-bw/raw_bw_20260420_162148_pull_call_home_options.bin new file mode 100644 index 0000000000000000000000000000000000000000..b437853930b9aad86e5493ebcd3c6fa4ff0e7a15 GIT binary patch literal 736 zcmZ={c4QI|U=U?M2CB@CaA7Wlgg#6-8X*Q`Wg`h2AY^7E2_r;DRfEHumLWJ)ma2m1_m2gVgm}-AY^th0{~LzFR=gs literal 0 HcmV?d00001 diff --git a/tests/fixtures/s3-call-home-bw/raw_bw_20260420_162221_enable_auto_call_home.bin b/tests/fixtures/s3-call-home-bw/raw_bw_20260420_162221_enable_auto_call_home.bin new file mode 100644 index 0000000000000000000000000000000000000000..43561c2ced0c5f1b498316753611cac7d7532bae GIT binary patch literal 219 zcmZ={c4QI|U=U?M2CB@CaA7Wlgg#8Tj)4J);GpIX0|R4_ql>4%LXfAQJ6s$)BP7_s z)`-EwfY%Yi0;$s0*46=Y4G?-5flNjqgaBc4gbau!z|6qUU;~5<^)Oe}qp0X-1^^Pl B5Iq0@ literal 0 HcmV?d00001 diff --git a/tests/fixtures/s3-call-home-bw/raw_bw_20260420_162255_disable_auto_call_home.bin b/tests/fixtures/s3-call-home-bw/raw_bw_20260420_162255_disable_auto_call_home.bin new file mode 100644 index 0000000000000000000000000000000000000000..af09d21c1531c1311a0a1e05f835c9519a3dd00d GIT binary patch literal 955 zcmZ={c4QI|U=U?M2CB@CaA7Wlgg#6-8X*Q`Wg`h2AY^7E2_r;DRfEHumLWJ)ma2m1_m2gVgm}-AY^vHgh?~Ij)4J);GpIXkQwCY;_0st8F vb%d}$sp<)mj z1`f}>;*!L?lGGfi0EF_*%**smEJ;-e$SEy`%akFT0}>rIe>8kXWcnG+nl#J$6a?*M zNJ&)#q2l4C6;K>129~M01Ehi+T|E62f;|1)A*ykbA;AW=MhqSXyp9kSNTIg2whow! dRG2aX#TkJR0))+>3@9bQ%)rlJ!(elf830QoyuAPb literal 0 HcmV?d00001 diff --git a/tests/fixtures/s3-call-home-bw/raw_s3_20260420_162221_enable_auto_call_home.bin b/tests/fixtures/s3-call-home-bw/raw_s3_20260420_162221_enable_auto_call_home.bin new file mode 100644 index 0000000000000000000000000000000000000000..81bc99d0044641f3e85e34b08ce95ea543af5996 GIT binary patch literal 107 zcmZ={b`)S@5D<9900vwTN`Qsg5g`E;1W7r$8XB4!Suzv|^1)R!Li9k%iE!}-6!8hn E00Myt9{>OV literal 0 HcmV?d00001 diff --git a/tests/fixtures/s3-call-home-bw/raw_s3_20260420_162255_disable_auto_call_home.bin b/tests/fixtures/s3-call-home-bw/raw_s3_20260420_162255_disable_auto_call_home.bin new file mode 100644 index 0000000000000000000000000000000000000000..08c2c38ec0e2eb55f61d322812fe1abc1c7eda1c GIT binary patch literal 1609 zcmZ={b`)S@5D<9900vwTN`Qsg5g`E;1W7r$8XB4!Suzv|^1)Rsf#@-SP*0G>p<)mj z1`f}>;*!L?lGGfi0EF_*%**smEJ;-e$SEy`%akFT0}>rIe>8kXWcnG+nl#J$6a?*M zNJ&)#q2l4C6;K>129~M0!@$58 Setup Unit), recorded as paired raw files -- what Blastware +sent (raw_bw_*) and what the unit answered (raw_s3_*). Copied from +bridges/captures/4-20-26/call home settings/: the read, the enable, the disable. +For each 0x7E, SFM builds its frame from the unit's own read just before it and +the value Blastware asked for; it must equal Blastware's frame byte for byte. +This test is what opens sfm.device_access.s3.S3_CALL_HOME_FRAME_VERIFIED. +""" +from __future__ import annotations + +import os +import sys +from pathlib import Path + +sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) + +from test_minimate_write_frames import _frames, _payload # noqa: E402 +from minimateplus.framing import S3FrameParser, build_bw_write_frame # noqa: E402 +from minimateplus.protocol import ( # noqa: E402 + SUB_CALL_HOME, SUB_CALL_HOME_CONFIRM, SUB_CALL_HOME_WRITE, call_home_image, write_image, +) + +FIX = Path(__file__).parent / "fixtures" / "s3-call-home-bw" +ACTIONS = ["162148_pull_call_home_options", "162221_enable_auto_call_home", "162255_disable_auto_call_home"] + + +def _action(tag): + bw = _frames((FIX / f"raw_bw_20260420_{tag}.bin").read_bytes()) + requests = [(_payload(f)[2], f) for f in bw] + reads = [bytes(f.data)[11:] for f in S3FrameParser().feed((FIX / f"raw_s3_20260420_{tag}.bin").read_bytes()) + if f.sub == 0xFF - SUB_CALL_HOME and len(f.data) > 100] + return requests, reads + + +def test_sfm_builds_blastwares_call_home_write(): + last_read, asserted, confirms = None, [], 0 + for tag in ACTIONS: + requests, reads = _action(tag) + subs = [s for s, _ in requests] + if reads and SUB_CALL_HOME_WRITE in subs: + # this action's read went out before its write + last_2c = max(i for i, s in enumerate(subs) if s == SUB_CALL_HOME) + assert last_2c < subs.index(SUB_CALL_HOME_WRITE) + last_read = reads[-1] + for sub, frame in requests: + if sub == SUB_CALL_HOME_WRITE: + bw_image = _payload(frame)[16:] + wanted = bw_image[5] + base = write_image(SUB_CALL_HOME_WRITE, last_read) + assert wanted in (0x00, 0x01) + assert [i for i in range(len(base)) if base[i] != bw_image[i] and i != 5] == [] + assert build_bw_write_frame(SUB_CALL_HOME_WRITE, call_home_image(last_read, wanted == 0x01)) == frame + asserted.append((tag, base[5], wanted)) + elif sub == SUB_CALL_HOME_CONFIRM: + assert build_bw_write_frame(SUB_CALL_HOME_CONFIRM, b"") == frame + confirms += 1 + if reads and SUB_CALL_HOME_WRITE not in subs: + last_read = reads[-1] + # Blastware turned call-home on (read 0x00 -> 0x01), then off (read 0x01 -> 0x00). + assert asserted == [("162221_enable_auto_call_home", 0x00, 0x01), + ("162255_disable_auto_call_home", 0x01, 0x00)] + assert confirms == 2