feat(sfm): POST /device/settings/change; retire the legacy config write
DeviceAccess.change_settings refuses before any I/O a request with no changes, a live change without its preview's revision, or no audit log, then dispatches the series' change (never retried). The route returns the preview (fields old -> new, warnings, blocked, revision) or the result (fields old/new/now), statuses as the other changes, and marks the cached by-host config dirty after a live change. /device/config and /device/config/project now answer 410 with a pointer. Deleted with them: MiniMateClient.apply_config / set_project_info and the raw-offset _encode_compliance_config (#46 found it wrong), the lab script poc_set_project.py and experiments.py's EXP6, both of which wrote a live unit through it. Git keeps them. 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
66bb29b9d4
commit
e8eabee4a2
10 files changed
+316
-749
No files matched your search
@@ -0,0 +1,70 @@
|
||||
"""DeviceAccess.change_settings (phase 5): the series-independent entry point --
|
||||
what it refuses before any I/O, and that it dispatches a change (never retried)."""
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
import pytest
|
||||
|
||||
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
|
||||
from device_access_fakes import FakeMiniMateClient, FakeMicromateClient # noqa: E402
|
||||
from sfm.device_access.access import DeviceAccess # noqa: E402
|
||||
from sfm.device_access.errors import BadRequest, NotSupported # noqa: E402
|
||||
from sfm.device_access.models import UnitAddress # noqa: E402
|
||||
|
||||
ADDR = UnitAddress(host="10.0.0.5", tcp_port=9034, port=None, baud=None)
|
||||
|
||||
|
||||
class Audit:
|
||||
def __init__(self):
|
||||
self.rows = {}
|
||||
|
||||
def begin(self, **f):
|
||||
cid = f"c{len(self.rows) + 1}"
|
||||
self.rows[cid] = dict(f, outcome="pending")
|
||||
return cid
|
||||
|
||||
def finish(self, cid, **f):
|
||||
self.rows[cid].update(f)
|
||||
|
||||
|
||||
def _never(*a, **kw):
|
||||
raise AssertionError("no connection may be opened")
|
||||
|
||||
|
||||
def _access(s3=_never, s4=_never, audit="default"):
|
||||
return DeviceAccess(s3_client_factory=s3, s4_client_factory=s4, start_reaper=False,
|
||||
audit=Audit() if audit == "default" else audit, sleep=lambda s: None)
|
||||
|
||||
|
||||
def test_live_change_without_revision_is_refused_before_io():
|
||||
with pytest.raises(BadRequest, match="preview first"):
|
||||
_access().change_settings(ADDR, "UM20147", changes={"job_number": 7}, revision=None)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("changes", [{}, None, "job_number=7"])
|
||||
def test_empty_changes_is_a_bad_request(changes):
|
||||
with pytest.raises(BadRequest):
|
||||
_access().change_settings(ADDR, "BE18193", changes=changes, revision="r", dry_run=True)
|
||||
|
||||
|
||||
def test_a_live_change_without_an_audit_log_is_refused():
|
||||
with pytest.raises(NotSupported, match="audit"):
|
||||
_access(audit=None).change_settings(ADDR, "BE18193", changes={"job_number": 7}, revision="r")
|
||||
|
||||
|
||||
def test_change_settings_dispatches_by_series_with_change_true(monkeypatch):
|
||||
access = _access(s3=lambda a, **kw: FakeMiniMateClient(), s4=lambda a, **kw: FakeMicromateClient())
|
||||
seen = []
|
||||
real = access._dispatch
|
||||
|
||||
def spy(address, serial, s3_op, s4_op, *, change=False):
|
||||
seen.append((serial, change))
|
||||
return real(address, serial, s3_op, s4_op, change=change)
|
||||
monkeypatch.setattr(access, "_dispatch", spy)
|
||||
r3 = access.change_settings(ADDR, "be18193", changes={"job_number": 7}, revision=None, dry_run=True)
|
||||
r4 = access.change_settings(ADDR, "UM20147", changes={"job_number": 7}, revision=None, dry_run=True)
|
||||
assert (r3.series, r4.series) == (3, 4) and r3.outcome == r4.outcome == "dry_run"
|
||||
assert seen == [("BE18193", True), ("UM20147", True)]
|
||||
Reference in new issue
Block a user