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

+22
View File
@@ -135,3 +135,25 @@ def test_guard_ignores_non_device_paths(da):
def test_guard_allows_an_unbuildable_address_through(da):
assert srv._device_guard("/device/monitor/stop", {}) is None
@pytest.mark.parametrize("serial", ["BE18193", "BA1", "nonsense"])
def test_guard_refuses_any_non_um_serial_on_a_legacy_route_at_a_held_address(da, serial):
# FastAPI drops the undeclared serial, so the legacy Series-3 handler would run
# at the held Series-4 address -- the same hole as a serial-less request.
da.status(ADDR, "UM20147")
out = srv._device_guard("/device/events/erase", {"serial": serial, **Q_TCP})
assert out is not None and out[0] == 409 and "UM20147" in out[1]
def test_guard_leaves_serial_aware_routes_to_device_access_at_a_held_address(da):
# DeviceAccess routes by series and refuses a Series-3 serial beside a held line itself.
da.status(ADDR, "UM20147")
assert srv._device_guard("/device/info", {"serial": "BE18193", **Q_TCP}) is None
def test_guard_ignores_an_unparseable_baud_when_checking_for_a_held_line(da):
# baud is not part of the address key; pydantic would coerce "38400.0" and run the handler.
da.status(ADDR, "UM20147")
out = srv._device_guard("/device/monitor/stop", {"baud": "38400.0", **Q_TCP})
assert out is not None and out[0] == 409