fix(sfm): any request taking the legacy path is refused beside a held line

The /device guard let every non-UM serial through before its held-line
check.  FastAPI drops an undeclared `serial`, so `?serial=BE18193` on a
legacy route still ran Series-3 code at an address holding a Series-4
line -- the hole the guard exists to close.  Serial-aware routes go
straight to DeviceAccess, which refuses that case itself; everything
else is checked.  baud is no longer parsed (it is not in the address
key, and pydantic's coercion made "38400.0" a second way past).

Also, from the same review:
- RingWatchTransport clears its frame state on every write, so a stray
  STX on an idle line cannot hide the ring that answers the next request.
- Series4Session.is_open reads _client once; held_serial() calls it
  without the unit lock, and a concurrent hang-up between two reads was
  an AttributeError (a 500).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SyJ2ip3Krb6dtdv2cXua44
This commit is contained in:
serversdownandClaude Opus 5.5 committed 2026-10-21 01:58:57 -04:00
1 parent 080e8f4704
commit 278921796a
6 files changed
+71 -11

No files matched your search

+30
View File
@@ -290,3 +290,33 @@ def test_s4_settings_maps_the_decoded_setup():
assert s.detail["mic_type"] == "linear"
assert s.detail["mic_trigger_db"] == pytest.approx(131.0, abs=0.01)
assert s.detail["geo_trigger_ips_per_channel"] == pytest.approx([0.5, 0.5, 0.5], abs=1e-6)
def test_a_new_request_clears_frame_state_left_by_a_stray_stx():
# A stray STX on an idle line would otherwise hide the ring that answers the
# next request. MicromateProtocol resets its own parser at every request too.
t = RingWatchTransport(ScriptedInner([b"\x02stray", b"\r\nRADIO RING\r\n"]))
t.connect()
t.read(64)
t.write(b"x")
with pytest.raises(RingDetected):
t.read(64)
def test_is_open_survives_a_hang_up_between_its_two_reads():
# held_serial() calls is_open without the unit lock; a concurrent hang-up can
# clear _client between the None check and the method call.
class Racy(Series4Session):
_reads = 0
@property
def _client(self):
Racy._reads += 1
return object.__new__(type("C", (), {"is_open": lambda s: True})) if Racy._reads == 1 else None
@_client.setter
def _client(self, value):
pass
s = Racy(ADDR, "UM20147", client_factory=lambda a: None)
assert s.is_open in (True, False)