feat(webapp): edit a unit's settings by serial: preview, send, read back

The Config tab by serial is now the unit's edit form, headed 'On the
unit <serial> -- read HH:MM' and built from the server's editable
fields.  Preview runs a dry run and shows old -> new, notes and anything
that blocks the change; Send (confirm) sends exactly what was previewed,
with its revision, then shows what the unit now holds and re-reads it.
An edit after a preview disables Send until the next preview.  The
by-host form loses its write button; the read stays.  Logic in
device_routing.js (Node-tested), glue in sfm_webapp.js, no inline JS.

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-11-03 21:57:17 -05:00
1 parent e8eabee4a2
commit 385716d8e1
7 files changed
+351 -77

No files matched your search

+71 -6
View File
@@ -29,7 +29,8 @@ pytestmark = pytest.mark.skipif(NODE is None, reason="node is not installed; the
EXPORTS = ["seriesFromSerial", "unitQuery", "deviceUrl", "confirmedSeries", "controlsFor", "eventView", "settingsRows", "perIndexLive", "escapeHtml",
"changeSummary", "downloadSummary", "firmwareLabel", "deviceErrorText", "changeErrorText", "serialPanes",
"callHomeRows"]
"callHomeRows", "settingsFormFields", "settingsChanges",
"settingsPreviewRows", "settingsBlockedText", "settingsResultRows"]
def _block() -> str:
@@ -77,7 +78,8 @@ def test_device_url():
["deviceUrl", ["start", S4]], ["deviceUrl", ["stop", S3]],
["deviceUrl", ["erase", S3]], ["deviceUrl", ["call_home_read", BLANK]],
["deviceUrl", ["config_write", S3]], ["deviceUrl", ["nonsense", S3]],
["deviceUrl", ["download", BLANK, {"event_id": "x"}]], ["deviceUrl", ["hangup", BLANK]])
["deviceUrl", ["download", BLANK, {"event_id": "x"}]], ["deviceUrl", ["hangup", BLANK]],
["deviceUrl", ["settings_change", S4, {"dry_run": "true"}]], ["deviceUrl", ["settings_change", BLANK]])
assert r[0] == {"method": "GET", "path": "/device/info?serial=BE9441&host=h&tcp_port=9034"}
assert r[1] == {"method": "GET", "path": "/device/monitor/status?serial=UM20147&host=h&tcp_port=9034"}
assert r[2] == {"method": "POST", "path": "/device/hangup?host=h&tcp_port=9034"}
@@ -88,9 +90,12 @@ def test_device_url():
assert r[6] == {"method": "POST", "path": "/device/monitor/stop?serial=BE9441&host=h&tcp_port=9034"}
assert r[7] == {"method": "POST", "path": "/device/events/erase?serial=BE9441&host=h&tcp_port=9034"}
assert r[8] == {"method": "GET", "path": "/device/call_home?host=h&tcp_port=9034"}
assert r[9] == {"method": "POST", "path": "/device/config?serial=BE9441&host=h&tcp_port=9034"}
assert "throws" in r[9] # /device/config is retired (phase 5)
assert "throws" in r[10]
assert r[11] is None and r[12] is None
assert r[13] == {"method": "POST", "path": "/device/settings/change?serial=UM20147&host=h&tcp_port=9034"
"&dry_run=true"}
assert r[14] is None # by serial only
def _with(unit, confirmed):
@@ -126,13 +131,62 @@ def test_controls_a_legacy_identify_confirms_without_a_typed_serial():
assert s == 3 and c["diagnostics"] is True and c["startStop"] is False # start/stop needs a serial
def test_controls_config_waits_for_phase_5_and_the_legacy_call_home_form_stays_off():
def test_controls_config_write_is_by_serial_for_both_series():
for unit in (_with(S3, {"serial": "BE9441", "series": 3}), _with(S4, {"serial": "UM20147", "series": 4})):
c = run(["controlsFor", [unit]])[0]
assert c["configWrite"] is False and c["callHomeWrite"] is False
assert c["reasons"] == {"configWrite": "Coming in phase 5 (#46)",
assert c["configWrite"] is True and c["callHomeWrite"] is False
assert c["reasons"] == {"configWrite": "By serial only: Preview, then Send (audited).",
"callHomeWrite": "By serial: use Call-home On / Off (audited). Other call-home "
"fields wait for the THOR round."}
c = run(["controlsFor", [_with(BLANK, {"serial": "BE9441", "series": 3})]])[0]
assert c["configWrite"] is False # by host: the legacy form is read-only
EDITABLE = [
{"field": "record_mode", "label": "Record mode", "kind": "choice", "value": "histogram",
"choices": [{"value": "histogram", "label": "Histogram"}, {"value": "waveform", "label": "Waveform"}]},
{"field": "sample_rate", "label": "Sample rate", "kind": "choice", "value": 1024, "unit": "sps",
"choices": [{"value": 1024, "label": "1024 sps"}, {"value": 4096, "label": "4096 sps"}]},
{"field": "geo_trigger_ips", "label": "Geophone trigger", "kind": "number", "value": 0.3,
"unit": "in/s", "min": 0.005, "max": 10.0, "step": 0.001},
{"field": "geo_alarm_ips", "label": "Geophone alarm", "kind": "number", "value": 1.0, "readonly": True},
{"field": "job_number_shown", "label": "Job number on report", "kind": "bool", "value": False},
{"field": "note_1", "label": "Project", "kind": "text", "value": "Bridge", "maxlength": 41},
]
def test_settings_form_fields_come_from_the_servers_list_in_order():
(f,) = run(["settingsFormFields", [{"detail": {"editable": EDITABLE}}]])
assert [x["field"] for x in f] == [e["field"] for e in EDITABLE]
assert f[2] == EDITABLE[2] and f[3]["readonly"] is True
assert run(["settingsFormFields", [{"detail": {}}]]) == [[]]
def test_settings_changes_are_only_what_differs():
same = {"record_mode": "histogram", "sample_rate": "1024", "geo_trigger_ips": "0.30",
"geo_alarm_ips": "2.0", "job_number_shown": False, "note_1": "Bridge"}
edited = {**same, "sample_rate": "4096", "geo_trigger_ips": "0.25", "job_number_shown": True,
"note_1": "Bridge 2"}
a, b = run(["settingsChanges", [EDITABLE, same]], ["settingsChanges", [EDITABLE, edited]])
assert a == {} # 0.30 == 0.3; the read-only alarm is ignored
assert b == {"sample_rate": 4096, "geo_trigger_ips": 0.25, "job_number_shown": True, "note_1": "Bridge 2"}
PREVIEW = {"outcome": "dry_run", "plan": {
"fields": {"geo_trigger_ips": {"label": "Geophone trigger", "old": 0.5, "new": 0.3},
"note_1": {"label": "Project", "old": "", "new": "Bridge"}},
"blocked": ["this unit's schedule loads other.mmb at 07:00, which would replace this change"],
"revision": "0123456789abcdef"}}
RESULT = {"outcome": "sent", "verified": "ok", "detail": {"snapshot": {"fields": {
"geo_trigger_ips": {"label": "Geophone trigger", "old": 0.5, "new": 0.3, "now": 0.3}}}}}
def test_settings_preview_result_and_blocked_text():
rows, blocked, none, result = run(["settingsPreviewRows", [PREVIEW]], ["settingsBlockedText", [PREVIEW]],
["settingsBlockedText", [RESULT]], ["settingsResultRows", [RESULT]])
assert rows == [["Geophone trigger", 0.5, 0.3], ["Project", "—", "Bridge"]]
assert "other.mmb" in blocked and none == ""
assert result == [["Geophone trigger", 0.5, 0.3, 0.3]]
def test_change_summary():
@@ -334,3 +388,14 @@ def test_call_home_rows_say_why_a_switch_did_not_read():
r = run(["callHomeRows", [{"enabled": None, "dial_string": None, "series": 3,
"detail": {"byte5": "0x6E", "reason": "not readable while monitoring -- stop it first"}}]])
assert r[0][0] == ["Call-home", "not readable while monitoring -- stop it first"]
def test_change_summary_for_settings_says_it_plainly():
base = {"action": "change settings", "audit_id": "cb540970-5e17", "state_before": "unchanged"}
ok, skip, mism = run(
["changeSummary", [{**base, "outcome": "sent", "verified": "ok", "state_after": "as asked"}]],
["changeSummary", [{**base, "outcome": "skipped", "verified": "not_checked", "state_before": "as asked"}]],
["changeSummary", [{**base, "outcome": "failed", "verified": "mismatch", "state_after": "differs"}]])
assert ok == "change settings: confirmed — the unit holds what was sent (audit cb540970)"
assert skip == "change settings: the unit already holds these — nothing sent"
assert "unit reads differs" in mism and "cb540970" in mism