feat(sfm): the page's Call Home tab by serial -- state and audited On / Off (phase 4)
device_routing.js (Node-tested): call_home_state / call_home_on / call_home_off
routes (serial required); controlsFor gains callHomeChange (by serial, a
confirmed Series 3 or 4) and callHomeRead now covers a Series 4 by serial;
serialPanes gains callHomeForm / callHomeBox; callHomeRows renders the switch
(On / Off / 'Unknown (byte 5 = 0xNN)'), dial string and series;
changeErrorText takes the whole label ('Start monitoring', 'Enable call-home').
sfm_webapp.js: by serial the Call Home tab hides the legacy multi-field form
(Series 3 by host only) and shows the unit's switch with On / Off. Each asks
confirm(), sends one audited change, reports it with changeSummary /
changeErrorText, then re-reads quietly so the change's own result stays on
screen. A different unit's switch is never left showing. The new buttons are
wired with addEventListener, not onclick= (no inline JS).
Checked in jsdom against the real page: placeholder, read, Off (confirm, the
disable route, 'confirmed -- enabled -> disabled'), a serial edit clearing it,
legacy mode unchanged, no script errors.
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
06fa56db09
commit
84c142f36c
4 files changed
+151
-23
No files matched your search
@@ -28,7 +28,8 @@ NODE = shutil.which("node")
|
||||
pytestmark = pytest.mark.skipif(NODE is None, reason="node is not installed; the page-logic tests need it")
|
||||
|
||||
EXPORTS = ["seriesFromSerial", "unitQuery", "deviceUrl", "confirmedSeries", "controlsFor", "eventView", "settingsRows", "perIndexLive", "escapeHtml",
|
||||
"changeSummary", "downloadSummary", "firmwareLabel", "deviceErrorText", "changeErrorText", "serialPanes"]
|
||||
"changeSummary", "downloadSummary", "firmwareLabel", "deviceErrorText", "changeErrorText", "serialPanes",
|
||||
"callHomeRows"]
|
||||
|
||||
|
||||
def _block() -> str:
|
||||
@@ -108,7 +109,8 @@ def test_controls_confirmed_series3():
|
||||
|
||||
def test_controls_confirmed_series4():
|
||||
c = run(["controlsFor", [_with(S4, {"serial": "UM20147", "series": 4})]])[0]
|
||||
assert (c["hangup"], c["startStop"], c["diagnostics"], c["callHomeRead"]) == (True, True, False, False)
|
||||
# phase 4: by serial a Micromate's call-home reads through /device/call_home/state
|
||||
assert (c["hangup"], c["startStop"], c["diagnostics"], c["callHomeRead"]) == (True, True, False, True)
|
||||
|
||||
|
||||
def test_controls_confirmation_drops_when_the_serial_changes():
|
||||
@@ -124,11 +126,13 @@ 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_writes_wait_for_phases_4_and_5():
|
||||
def test_controls_config_waits_for_phase_5_and_the_legacy_call_home_form_stays_off():
|
||||
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)", "callHomeWrite": "Coming in phase 4"}
|
||||
assert c["reasons"] == {"configWrite": "Coming in phase 5 (#46)",
|
||||
"callHomeWrite": "By serial: use Call-home On / Off (audited). Other call-home "
|
||||
"fields wait for the THOR round."}
|
||||
|
||||
|
||||
def test_change_summary():
|
||||
@@ -272,10 +276,12 @@ def test_a_change_that_was_sent_is_not_called_failed():
|
||||
# #10: a ChangeUnconfirmed body carries `sent`; anything else is a real failure.
|
||||
sent = {"detail": "start monitoring was sent and acknowledged, but reading the state back failed: x "
|
||||
"-- audit record c7", "sent": "acknowledged", "audit_id": "c7"}
|
||||
r = run(["changeErrorText", ["Start", 504, sent, S3, "HTTP 504"]],
|
||||
["changeErrorText", ["Stop", 503, {**sent, "sent": "unknown"}, S3, "HTTP 503"]],
|
||||
["changeErrorText", ["Start", 504, {"detail": "the unit did not answer: no reply"}, S3, "HTTP 504"]],
|
||||
["changeErrorText", ["Stop", 409, {"detail": "not BE9441: BE12599 answered"}, S3, "HTTP 409"]])
|
||||
r = run(["changeErrorText", ["Start monitoring", 504, sent, S3, "HTTP 504"]],
|
||||
["changeErrorText", ["Stop monitoring", 503, {**sent, "sent": "unknown"}, S3, "HTTP 503"]],
|
||||
["changeErrorText", ["Start monitoring", 504, {"detail": "the unit did not answer: no reply"}, S3,
|
||||
"HTTP 504"]],
|
||||
["changeErrorText", ["Stop monitoring", 409, {"detail": "not BE9441: BE12599 answered"}, S3,
|
||||
"HTTP 409"]])
|
||||
assert r[0] == f"Start monitoring not confirmed: {sent['detail']}"
|
||||
assert r[1] == f"Stop monitoring not confirmed: {sent['detail']}"
|
||||
assert r[2] == f"Start monitoring failed: the unit did not answer: no reply — {HINT}"
|
||||
@@ -287,6 +293,37 @@ def test_serial_mode_hides_the_legacy_forms():
|
||||
# #6 / #12: by serial, settings are read-only until phase 5 -- no empty edit
|
||||
# form, no empty legacy tables; the settings box shows from the start.
|
||||
r = run(["serialPanes", [True, False]], ["serialPanes", [True, True]], ["serialPanes", [False, False]])
|
||||
assert r == [{"configForm": False, "settingsBox": True, "settingsPlaceholder": True, "legacyDeviceTables": False},
|
||||
{"configForm": False, "settingsBox": True, "settingsPlaceholder": False, "legacyDeviceTables": False},
|
||||
{"configForm": True, "settingsBox": False, "settingsPlaceholder": False, "legacyDeviceTables": True}]
|
||||
serial = {"configForm": False, "settingsBox": True, "legacyDeviceTables": False,
|
||||
"callHomeForm": False, "callHomeBox": True}
|
||||
legacy = {"configForm": True, "settingsBox": False, "settingsPlaceholder": False, "legacyDeviceTables": True,
|
||||
"callHomeForm": True, "callHomeBox": False}
|
||||
assert r == [{**serial, "settingsPlaceholder": True}, {**serial, "settingsPlaceholder": False}, legacy]
|
||||
|
||||
|
||||
|
||||
# ── Call home by serial (phase 4) ─────────────────────────────────────────────
|
||||
|
||||
def test_call_home_routes_need_a_serial():
|
||||
r = run(["deviceUrl", ["call_home_on", BLANK]], ["deviceUrl", ["call_home_on", S4]],
|
||||
["deviceUrl", ["call_home_off", S3]], ["deviceUrl", ["call_home_state", S4]])
|
||||
assert r[0] is None
|
||||
assert r[1] == {"method": "POST", "path": "/device/call_home/enable?serial=UM20147&host=h&tcp_port=9034"}
|
||||
assert r[2] == {"method": "POST", "path": "/device/call_home/disable?serial=BE9441&host=h&tcp_port=9034"}
|
||||
assert r[3] == {"method": "GET", "path": "/device/call_home/state?serial=UM20147&host=h&tcp_port=9034"}
|
||||
|
||||
|
||||
def test_call_home_change_needs_a_confirmed_series():
|
||||
r = run(["controlsFor", [S3]], ["controlsFor", [_with(S3, {"serial": "BE9441", "series": 3})]],
|
||||
["controlsFor", [_with(S4, {"serial": "UM20147", "series": 4})]],
|
||||
["controlsFor", [_with(BLANK, {"serial": "BE9441", "series": 3})]])
|
||||
assert [c["callHomeChange"] for c in r] == [False, True, True, False]
|
||||
|
||||
|
||||
def test_call_home_rows():
|
||||
r = run(["callHomeRows", [{"enabled": True, "dial_string": "RADIO RING", "series": 4}]],
|
||||
["callHomeRows", [{"enabled": False, "dial_string": None, "series": 3}]],
|
||||
["callHomeRows", [{"enabled": None, "dial_string": "RADIO RING", "series": 3,
|
||||
"detail": {"byte5": "0x07"}}]])
|
||||
assert r[0] == [["Call-home", "On"], ["Dial string", "RADIO RING"], ["Series", 4]]
|
||||
assert r[1] == [["Call-home", "Off"], ["Dial string", "—"], ["Series", 3]]
|
||||
assert r[2][0] == ["Call-home", "Unknown (byte 5 = 0x07)"]
|
||||
Reference in new issue
Block a user