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 0000000..b437853 Binary files /dev/null and b/tests/fixtures/s3-call-home-bw/raw_bw_20260420_162148_pull_call_home_options.bin differ 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 0000000..43561c2 Binary files /dev/null and b/tests/fixtures/s3-call-home-bw/raw_bw_20260420_162221_enable_auto_call_home.bin differ 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 0000000..af09d21 Binary files /dev/null and b/tests/fixtures/s3-call-home-bw/raw_bw_20260420_162255_disable_auto_call_home.bin differ diff --git a/tests/fixtures/s3-call-home-bw/raw_s3_20260420_162148_pull_call_home_options.bin b/tests/fixtures/s3-call-home-bw/raw_s3_20260420_162148_pull_call_home_options.bin new file mode 100644 index 0000000..5f9743f Binary files /dev/null and b/tests/fixtures/s3-call-home-bw/raw_s3_20260420_162148_pull_call_home_options.bin differ 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 0000000..81bc99d Binary files /dev/null and b/tests/fixtures/s3-call-home-bw/raw_s3_20260420_162221_enable_auto_call_home.bin differ 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 0000000..08c2c38 Binary files /dev/null and b/tests/fixtures/s3-call-home-bw/raw_s3_20260420_162255_disable_auto_call_home.bin differ diff --git a/tests/test_s3_call_home.py b/tests/test_s3_call_home.py index 9fce3d9..d9271a4 100644 --- a/tests/test_s3_call_home.py +++ b/tests/test_s3_call_home.py @@ -84,7 +84,13 @@ def test_s3_call_home_state(): assert fake.calls.index("wake") < fake.calls.index("read_call_home_raw") -def test_s3_live_change_is_refused_until_the_frame_is_verified(): +def test_the_gate_is_open_and_names_its_proof(): + assert s3mod.S3_CALL_HOME_FRAME_VERIFIED is True + assert "tests/test_s3_call_home_bw_frames.py" in open(s3mod.__file__).read() + + +def test_s3_live_change_is_refused_while_the_gate_is_shut(monkeypatch): + monkeypatch.setattr(s3mod, "S3_CALL_HOME_FRAME_VERIFIED", False) a = adapter(FakeMiniMateClient()) with pytest.raises(NotSupported) as e: change(a, enabled=False) diff --git a/tests/test_s3_call_home_bw_frames.py b/tests/test_s3_call_home_bw_frames.py new file mode 100644 index 0000000..8861518 --- /dev/null +++ b/tests/test_s3_call_home_bw_frames.py @@ -0,0 +1,64 @@ +"""SFM's MiniMate call-home write is Blastware's, frame for frame (phase 4). + +Ground truth: Blastware changing BE11529's call-home settings on 2026-04-20 +(Remote Access -> 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