fix(micromate): a plan step is immutable once validated; setup push checks each block's own header
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
b7b054aee9
commit
137aa699c7
3 files changed
+81
No files matched your search
@@ -212,3 +212,56 @@ def test_thors_own_call_home_writes_carry_no_unobserved_warning(read_idx, enable
|
||||
assert not any("unobserved" in w for w in plan.warnings)
|
||||
assert plan.warnings == ()
|
||||
assert plan_stop_monitoring().describe()["warnings"] == []
|
||||
|
||||
|
||||
# ── a step is immutable after validation ──────────────────────────────────────
|
||||
|
||||
def test_a_step_built_from_a_bytearray_cannot_change_afterwards():
|
||||
data, params = bytearray(b"\x01\x02\x03"), bytearray(10)
|
||||
step = WriteStep(0x7E, 0x007E, data, params)
|
||||
plan = WritePlan("x", (step,))
|
||||
frame, desc = step.frame, plan.describe()
|
||||
data[0] = 0xFF
|
||||
params[0] = 0xFF
|
||||
assert isinstance(step.data, bytes) and isinstance(step.params, bytes)
|
||||
assert step.frame == frame and plan.describe() == desc
|
||||
|
||||
|
||||
@pytest.mark.parametrize("kw", [{"params": bytes(9)}, {"params": bytes(11)},
|
||||
{"offset": 0x10000}, {"offset": -1},
|
||||
{"sub": 0x100}, {"sub": -1}])
|
||||
def test_a_malformed_step_is_refused_at_construction(kw):
|
||||
args = {"sub": 0x96, "offset": 0xFFFF}
|
||||
args.update(kw)
|
||||
with pytest.raises(ValueError):
|
||||
WriteStep(**args)
|
||||
|
||||
|
||||
def test_a_plan_refuses_a_step_that_is_not_a_writestep():
|
||||
with pytest.raises(TypeError, match="WriteStep"):
|
||||
WritePlan("x", (object(),))
|
||||
with pytest.raises(TypeError, match="WriteStep"):
|
||||
WritePlan("x", ((0x96, 0xFFFF),))
|
||||
|
||||
|
||||
def _multi_step_plans():
|
||||
reads, _ = _first_push("setup-push-multiday")
|
||||
return [plan_setup_push(reads[0x08], reads[0x2E], reads[0x1A], "x.mmb"),
|
||||
plan_call_home_enabled(_call_home_reads()[0], True)]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("i", [0, 1])
|
||||
def test_describe_frames_match_frames_for_every_step(i):
|
||||
plan = _multi_step_plans()[i]
|
||||
d, frames = plan.describe()["steps"], plan.frames()
|
||||
assert len(d) == len(frames) > 1
|
||||
for j, f in enumerate(frames):
|
||||
assert d[j]["frame"] == f.hex()
|
||||
|
||||
|
||||
def test_setup_push_refuses_a_block_whose_own_length_header_is_wrong():
|
||||
reads, _ = _first_push("setup-push-multiday")
|
||||
bad = bytearray(reads[0x1A])
|
||||
bad[0:2] = (int.from_bytes(bad[0:2], "big") + 1).to_bytes(2, "big")
|
||||
with pytest.raises(ValueError, match="header"):
|
||||
plan_setup_push(reads[0x08], reads[0x2E], bytes(bad), "x.mmb")
|
||||
Reference in new issue
Block a user