test(sfm): pin the ring-on-follow-up and calling-home poll exits; narrow the refusal clause
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
14ea80f5a4
commit
78c3d568d5
3 files changed
+39
-1
No files matched your search
@@ -91,6 +91,8 @@ class DeviceAccess:
|
||||
even_if_already=even_if_already, caller=caller)
|
||||
|
||||
def _change_monitoring(self, address, serial, *, start, dry_run, even_if_already, caller):
|
||||
serial = normalise_serial(serial)
|
||||
series_for_serial(serial) # BadRequest (422) before the audit check
|
||||
if not dry_run and self._audit is None:
|
||||
raise NotSupported("no audit log is configured -- SFM refuses to change a unit "
|
||||
"without one (nothing sent)")
|
||||
|
||||
@@ -366,7 +366,7 @@ def s4_change_monitoring(client: Any, serial: str, *, start: bool, dry_run: bool
|
||||
|
||||
try:
|
||||
acks = client.protocol.execute(plan)
|
||||
except (OpcodeRefused, TypeError) as exc: # refused by the gate: nothing went out
|
||||
except OpcodeRefused as exc: # refused by the gate: nothing went out
|
||||
audit.finish(cid, outcome="failed", verified="not_checked", ack=None,
|
||||
error=f"refused before sending: {exc}")
|
||||
raise
|
||||
|
||||
@@ -177,6 +177,7 @@ def test_calling_home_seen_while_polling_releases_the_line():
|
||||
with pytest.raises(CallHomeInProgress):
|
||||
da.start_monitoring(ADDR, "UM20147")
|
||||
assert len(fake.executed) == 1
|
||||
assert fake.calls.count("read_run_state") == 2 # the read before + the one poll
|
||||
assert fake.is_open() is False and ADDR.key not in da._sessions
|
||||
(row,) = da._audit.rows.values()
|
||||
assert (row["outcome"], row["verified"]) == ("sent", "not_checked")
|
||||
@@ -247,3 +248,38 @@ def test_bad_verify_timings_are_rejected():
|
||||
DeviceAccess(start_reaper=False, verify_interval_s=0)
|
||||
with pytest.raises(ValueError):
|
||||
DeviceAccess(start_reaper=False, verify_interval_s=5, verify_timeout_s=2)
|
||||
|
||||
|
||||
def test_a_ring_on_the_follow_up_read_after_a_lost_ack_finishes_the_row():
|
||||
fake = FakeMicromateClient(run_states=[0x00], execute_error=mm_proto.TimeoutError("no ack"))
|
||||
da = access(fake)
|
||||
orig, n = fake.read_run_state, []
|
||||
|
||||
def ringing():
|
||||
n.append(1)
|
||||
if len(n) == 2: # the first follow-up read
|
||||
raise RingDetected("RADIO RING")
|
||||
return orig()
|
||||
fake.read_run_state = ringing
|
||||
with pytest.raises(CallHomeInProgress):
|
||||
da.start_monitoring(ADDR, "UM20147")
|
||||
assert len(fake.executed) == 1
|
||||
(row,) = da._audit.rows.values()
|
||||
assert (row["outcome"], row["verified"]) == ("failed", "not_checked")
|
||||
assert "a call-home began" in row["error"]
|
||||
assert fake.is_open() is False and ADDR.key not in da._sessions
|
||||
|
||||
|
||||
def test_a_type_error_after_sending_is_recorded_as_no_clean_ack():
|
||||
fake = FakeMicromateClient(run_states=[0x00, 0x02], execute_error=TypeError("parser bug"))
|
||||
da = access(fake)
|
||||
r = da.start_monitoring(ADDR, "UM20147")
|
||||
assert len(fake.executed) == 1 and r.sent is True
|
||||
assert "no clean ack" in da._audit.rows[r.audit_id]["error"]
|
||||
assert "refused before sending" not in da._audit.rows[r.audit_id]["error"]
|
||||
|
||||
|
||||
def test_a_malformed_serial_is_422_even_without_an_audit_sink():
|
||||
from sfm.device_access.errors import BadRequest
|
||||
with pytest.raises(BadRequest):
|
||||
access(FakeMicromateClient(), audit=None).start_monitoring(ADDR, "XX123")
|
||||
Reference in new issue
Block a user