- #6 Config tab by serial: the empty legacy edit form stays hidden (settings are read-only until phase 5); the settings box shows from the start, 'Not read yet', and a different unit's settings are never left on screen. - #10 A start/stop that went out but was not confirmed is no longer called 'failed'. The route now adds 'sent' (acknowledged / unknown) and 'audit_id' to a ChangeUnconfirmed -- same status, same message -- and the page says 'Start monitoring not confirmed: <what happened, audit record>'. - #12 Device tab by serial: the empty legacy Compliance/Project tables are hidden behind a pointer to the Config tab; a Micromate's Firmware card reads 'Thor line (version not read)' (its version string is in 0x01, undecoded). - #16 A 504 with nothing sent adds: the connection opened, so the modem is reachable -- another program (THOR or Blastware) may be holding the line, or the unit is busy. Measured 2026-10-29: THOR polling leaves SFM a 0-byte 504. New logic lives in sfm/static/device_routing.js (firmwareLabel, deviceErrorText, changeErrorText, serialPanes) under Node tests; the page glue in sfm_webapp.js only applies them. Checked in jsdom against the real page (served at a fake origin, /static from disk): all four, 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
2b886c4f39
commit
8123d75d72
7 files changed
+163
-22
No files matched your search
@@ -681,7 +681,9 @@ a short plan; #14 waits for the line-hold decision above.
|
||||
4. List vector sum 0 / −0 for three events whose peaks reach 1.08 in/s --
|
||||
suspected escapes in the `0C` record (not checked).
|
||||
5. Stored S3 event: client "Terra-Mechanic" (last letter missing) -- unexplained.
|
||||
6. Page: the Config tab shows the empty write form until Read in serial mode.
|
||||
6. ✅ **Fixed 2026-11-02 (Batch 2):** by serial the edit form stays hidden and the settings
|
||||
box shows from the start ("Not read yet"); another unit's settings are cleared.
|
||||
Page: the Config tab shows the empty write form until Read in serial mode.
|
||||
7. `/db/events` 500 "database is locked" on the first page load against a new DB.
|
||||
8. ✅ **Fixed `9492e49`**, plus `3a1d34a` ("already stored" also matches the Blastware
|
||||
name: a histogram's row sits a second off its 0C time). The download carries the assembled Blastware file and is
|
||||
@@ -704,10 +706,14 @@ a short plan; #14 waits for the line-hold decision above.
|
||||
**S3 start over a modem:** the line dropped during the sensor check, the
|
||||
read-back hit `Broken pipe` and did not reconnect → 503 though the start
|
||||
worked. Fix: reconnect for the read-back (reads only; the send stays single).
|
||||
10. Page: "Start monitoring failed:" on a sent-but-unconfirmed change -- wording.
|
||||
10. ✅ **Fixed 2026-11-02 (Batch 2):** the start/stop route adds `sent` + `audit_id` to a
|
||||
ChangeUnconfirmed (same status and message); the page says "… not confirmed:".
|
||||
Page: "Start monitoring failed:" on a sent-but-unconfirmed change -- wording.
|
||||
11. S3 stop ~19 s, 11.6 s of it the identity check (a full connect) vs ~1 s for a
|
||||
serial-only read. **Identified only** (speed is secondary to reliability).
|
||||
12. Page, serial mode: the Device tab's empty legacy compliance table; S4
|
||||
12. ✅ **Fixed 2026-11-02 (Batch 2):** by serial the legacy tables are hidden behind a
|
||||
pointer to the Config tab; a Micromate's Firmware reads "Thor line (version not read)".
|
||||
Page, serial mode: the Device tab's empty legacy compliance table; S4
|
||||
Firmware "—" (should say Thor line).
|
||||
13. S4 mic in the event's peaks "0.0 dBL" vs 96.54 dB(L) in the file -- the
|
||||
`0x0C` mic denormal parked above, now visible.
|
||||
@@ -717,7 +723,10 @@ a short plan; #14 waits for the line-hold decision above.
|
||||
**RETRACTED 2026-10-29: not a bug.** `sent` is documented as 1 acknowledged, 0
|
||||
nothing sent, NULL unknown (`sfm/database.py`, `change.py`); a frame answered by a
|
||||
ring instead of its ack is exactly unknown, and the row's `error` says it was sent.
|
||||
16. Page: a 504 on a unit THOR holds should say "connected, but no reply --
|
||||
16. ✅ **Fixed 2026-11-02 (Batch 2):** a 504 with nothing sent adds "the connection opened,
|
||||
so the modem is reachable — another program (THOR or Blastware) may be holding
|
||||
this unit's line, or the unit is busy".
|
||||
Page: a 504 on a unit THOR holds should say "connected, but no reply --
|
||||
another program may be holding this unit's line".
|
||||
17. ✅ **Range part fixed 2026-11-02:** a MiniMate downloaded *while monitoring*
|
||||
answers 1A with its device-info block, so no range was read and the stored
|
||||
|
||||
+14
-3
@@ -86,7 +86,7 @@ from sfm import db_snapshot
|
||||
from sfm.event_ingest import backfill_series3_event, persist_download
|
||||
import dataclasses
|
||||
from sfm.device_access import DeviceAccess, DeviceError, UnitAddress
|
||||
from sfm.device_access.errors import BadRequest
|
||||
from sfm.device_access.errors import BadRequest, ChangeUnconfirmed
|
||||
from sfm.device_access.series import normalise_serial, series_for_serial
|
||||
from sfm.audit import DbAudit
|
||||
|
||||
@@ -400,9 +400,20 @@ def _via_device_access(fn) -> dict:
|
||||
def _change_response(fn) -> JSONResponse:
|
||||
"""Run a start/stop; the ChangeResult is the body, its outcome picks the status.
|
||||
|
||||
DeviceError mapping is _via_device_access's -- not repeated here.
|
||||
DeviceError mapping is _via_device_access's -- not repeated here. A change
|
||||
that went out, or may have (ChangeUnconfirmed), keeps that status and message
|
||||
and adds `sent` ("acknowledged" / "unknown") and `audit_id`, so a client can
|
||||
tell it from a failure that sent nothing without matching the wording
|
||||
(bench finding #10, 2026-11-02).
|
||||
"""
|
||||
body = _via_device_access(fn)
|
||||
try:
|
||||
body = _via_device_access(fn)
|
||||
except HTTPException as exc:
|
||||
cause = exc.__cause__
|
||||
if not isinstance(cause, ChangeUnconfirmed):
|
||||
raise
|
||||
return JSONResponse(status_code=exc.status_code,
|
||||
content={"detail": exc.detail, "sent": cause.sent, "audit_id": cause.audit_id})
|
||||
# An allow-list: only a dry run, a skip, or a change read back as made is a 200.
|
||||
ok = (body["outcome"] in ("dry_run", "skipped")
|
||||
or (body["outcome"] == "sent" and body["verified"] == "ok"))
|
||||
|
||||
+7
-4
@@ -952,11 +952,14 @@
|
||||
|
||||
<div class="dev-grid" id="dev-cards"></div>
|
||||
|
||||
<div class="dev-section-title">Compliance Config</div>
|
||||
<div class="dev-table" id="compliance-table"></div>
|
||||
<div id="dev-serial-note" class="dev-section-title" hidden>Settings: Config tab → Read from Device</div>
|
||||
<div id="dev-legacy-tables">
|
||||
<div class="dev-section-title">Compliance Config</div>
|
||||
<div class="dev-table" id="compliance-table"></div>
|
||||
|
||||
<div class="dev-section-title">Project Info</div>
|
||||
<div class="dev-table" id="project-table"></div>
|
||||
<div class="dev-section-title">Project Info</div>
|
||||
<div class="dev-table" id="project-table"></div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -154,4 +154,42 @@ function downloadSummary(body) {
|
||||
if (body.inserted === false) return `already stored — ${body.stored_filename}`;
|
||||
return `stored ${body.stored_filename}, ${body.filesize} bytes, check: ${(body.detail || {}).check}`;
|
||||
}
|
||||
|
||||
// A Micromate's version string lives in 0x01, undecoded; which firmware line it
|
||||
// runs comes free with every reply (bench finding #12).
|
||||
const FIRMWARE_LINES = { thor: 'Thor line (version not read)', blastware: 'Blastware line (version not read)' };
|
||||
function firmwareLabel(info) {
|
||||
const i = info || {};
|
||||
return i.firmware_version || i.firmware || FIRMWARE_LINES[(i.detail || {}).firmware_line] || '—';
|
||||
}
|
||||
|
||||
// A failed device request's message. A 504 is a unit that took the connection
|
||||
// but never answered: while THOR polls a Micromate, SFM's connection is accepted
|
||||
// and gets 0 bytes (measured 2026-10-29, bench finding #16). The hint is left
|
||||
// off once a change was sent -- its own message says what happened.
|
||||
const NO_REPLY_HINT = 'the connection opened, so the modem is reachable — another program (THOR or '
|
||||
+ "Blastware) may be holding this unit's line, or the unit is busy (e.g. its sensor check)";
|
||||
function errorDetail(body, statusText) {
|
||||
const b = body || {}, d = b.detail;
|
||||
return b.outcome ? changeSummary(b) : typeof d === 'string' ? d : d ? (d.message || JSON.stringify(d)) : statusText;
|
||||
}
|
||||
function deviceErrorText(status, body, unit, statusText) {
|
||||
const text = errorDetail(body, statusText);
|
||||
return status === 504 && !(body || {}).sent && unit && unit.host ? `${text} — ${NO_REPLY_HINT}` : text;
|
||||
}
|
||||
|
||||
// A start/stop that went out (or may have) is not "failed": its body carries
|
||||
// `sent` (ChangeUnconfirmed, bench finding #10), and its message says what the
|
||||
// unit did and names the audit record.
|
||||
function changeErrorText(verb, status, body, unit, statusText) {
|
||||
if ((body || {}).sent) return `${verb} monitoring not confirmed: ${errorDetail(body, statusText)}`;
|
||||
return `${verb} monitoring failed: ${deviceErrorText(status, body, unit, statusText)}`;
|
||||
}
|
||||
|
||||
// By serial, settings are read-only until phase 5: no empty legacy edit form or
|
||||
// legacy tables, and the settings box shows from the start (#6, #12).
|
||||
function serialPanes(bySerial, settingsRead) {
|
||||
return { configForm: !bySerial, settingsBox: bySerial, settingsPlaceholder: bySerial && !settingsRead,
|
||||
legacyDeviceTables: !bySerial };
|
||||
}
|
||||
/* </device-routing> */
|
||||
@@ -73,9 +73,7 @@ async function deviceFetch(action, params = {}, opts = {}) {
|
||||
const r = await deviceRequest(action, params, opts);
|
||||
const body = await r.json().catch(() => ({}));
|
||||
if (!r.ok) {
|
||||
const d = body.detail;
|
||||
const err = new Error(body.outcome ? changeSummary(body)
|
||||
: typeof d === 'string' ? d : d ? (d.message || JSON.stringify(d)) : r.statusText);
|
||||
const err = new Error(deviceErrorText(r.status, body, currentUnit(), r.statusText));
|
||||
err.status = r.status; err.body = body;
|
||||
throw err;
|
||||
}
|
||||
@@ -102,6 +100,22 @@ function applyControls() {
|
||||
chr.title = s4;
|
||||
document.getElementById('ch-series-note').textContent = s4;
|
||||
setMonitorButtons();
|
||||
applyConfigPanes();
|
||||
}
|
||||
|
||||
// The Config tab by serial (#6): settings are read-only until phase 5, so the
|
||||
// empty legacy edit form stays hidden and the settings box shows from the start.
|
||||
// A different unit's settings are never left on screen.
|
||||
let settingsShownFor = null;
|
||||
function applyConfigPanes() {
|
||||
const serial = normSerial(currentUnit().serial);
|
||||
const p = serialPanes(Boolean(serial), Boolean(serial) && settingsShownFor === serial);
|
||||
document.getElementById('cfg-form').style.display = p.configForm ? '' : 'none';
|
||||
document.getElementById('cfg-settings').style.display = p.settingsBox ? 'block' : 'none';
|
||||
if (p.settingsPlaceholder) {
|
||||
settingsShownFor = null;
|
||||
renderTextTable('cfg-settings-table', [['Settings', 'Not read yet — press Read from Device']]);
|
||||
}
|
||||
}
|
||||
|
||||
async function hangUp() {
|
||||
@@ -430,8 +444,7 @@ async function changeMonitoring(action) {
|
||||
if (body.outcome) {
|
||||
setStatus(changeSummary(body), r.ok ? 'ok' : 'error');
|
||||
} else {
|
||||
const d = body.detail;
|
||||
setStatus(`${verb} monitoring failed: ${typeof d === 'string' ? d : d ? JSON.stringify(d) : r.statusText}`, 'error');
|
||||
setStatus(changeErrorText(verb, r.status, body, currentUnit(), r.statusText), 'error');
|
||||
}
|
||||
} catch (e) {
|
||||
// No reply is not "nothing sent": the request may have reached the unit.
|
||||
@@ -454,7 +467,7 @@ function populateDeviceTab() {
|
||||
const cardData = [
|
||||
{ label:'Serial Number', value: unitInfo.serial || '—' },
|
||||
{ label:'Series', value: confirmedSeries(currentUnit()) ?? '—' },
|
||||
{ label:'Firmware', value: unitInfo.firmware_version || unitInfo.firmware || '—' },
|
||||
{ label:'Firmware', value: firmwareLabel(unitInfo) },
|
||||
{ label:'DSP', value: unitInfo.dsp_version || (unitInfo.detail || {}).dsp_version || '—' },
|
||||
{ label:'Model', value: unitInfo.model || '—' },
|
||||
{ label:'Manufacturer', value: unitInfo.manufacturer || (unitInfo.detail || {}).manufacturer || '—' },
|
||||
@@ -471,6 +484,11 @@ function populateDeviceTab() {
|
||||
cards.appendChild(c);
|
||||
}
|
||||
|
||||
// The legacy settings tables are empty by serial (#12); the Config tab reads them.
|
||||
const legacy = serialPanes(serialMode(), false).legacyDeviceTables;
|
||||
document.getElementById('dev-legacy-tables').hidden = !legacy;
|
||||
document.getElementById('dev-serial-note').hidden = legacy;
|
||||
|
||||
// Compliance table
|
||||
const cc = unitInfo.compliance_config || {};
|
||||
const RECORDING_MODE_LABELS = {0: 'Single Shot', 1: 'Continuous', 3: 'Histogram', 4: 'Histogram + Continuous'};
|
||||
@@ -713,6 +731,7 @@ async function readSettingsBySerial() {
|
||||
try {
|
||||
const st = await deviceFetch('settings');
|
||||
renderTextTable('cfg-settings-table', settingsRows(st));
|
||||
settingsShownFor = normSerial(st.serial);
|
||||
document.getElementById('cfg-settings').style.display = 'block';
|
||||
document.getElementById('cfg-form').style.display = 'none';
|
||||
setCfgStatus(`Settings read from ${st.serial}.`, 'ok');
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
FastAPI Query() defaults are FieldInfo objects, not values."""
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
@@ -418,10 +420,13 @@ def test_a_change_unconfirmed_keeps_its_cause_status_and_names_the_audit_record(
|
||||
"failed: silent -- audit record c7", audit_id="c7", sent="acknowledged",
|
||||
http_status=504)
|
||||
monkeypatch.setattr(srv, "_device_access_instance", Raises())
|
||||
with pytest.raises(HTTPException) as e:
|
||||
srv.device_monitor_start(**CH)
|
||||
assert e.value.status_code == 504
|
||||
assert "audit record c7" in e.value.detail
|
||||
resp = srv.device_monitor_start(**CH)
|
||||
assert resp.status_code == 504 # the cause's status, unchanged
|
||||
body = json.loads(resp.body)
|
||||
assert "audit record c7" in body["detail"]
|
||||
# #10 (2026-11-02): the page tells "may have been sent" from "nothing sent" by
|
||||
# these, not by matching the message.
|
||||
assert (body["sent"], body["audit_id"]) == ("acknowledged", "c7")
|
||||
|
||||
|
||||
def test_device_commands_normalises_the_serial(tmp_path, monkeypatch):
|
||||
|
||||
@@ -28,7 +28,7 @@ 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"]
|
||||
"changeSummary", "downloadSummary", "firmwareLabel", "deviceErrorText", "changeErrorText", "serialPanes"]
|
||||
|
||||
|
||||
def _block() -> str:
|
||||
@@ -234,3 +234,59 @@ def test_the_per_index_routes_follow_the_list_not_the_keyboard():
|
||||
def test_escape_html_makes_a_unit_string_inert():
|
||||
r = run(["escapeHtml", ['Bench <b id="x">&\'']], ["escapeHtml", [None]], ["escapeHtml", [42]])
|
||||
assert r == ["Bench <b id="x">&'", "", "42"]
|
||||
|
||||
|
||||
|
||||
# ── Batch 2 (1c bench polish, 2026-11-02) ─────────────────────────────────────
|
||||
|
||||
def test_firmware_label_says_which_line_a_micromate_runs():
|
||||
# #12: a Micromate's version string is in 0x01, undecoded; its firmware line is known.
|
||||
r = run(["firmwareLabel", [{"firmware": "S338.17"}]], ["firmwareLabel", [{"firmware_version": "S338.17"}]],
|
||||
["firmwareLabel", [{"firmware": None, "detail": {"firmware_line": "thor"}}]],
|
||||
["firmwareLabel", [{"firmware": None, "detail": {"firmware_line": "blastware"}}]],
|
||||
["firmwareLabel", [{"firmware": None, "detail": {"firmware_line": "unknown"}}]],
|
||||
["firmwareLabel", [{}]], ["firmwareLabel", [None]])
|
||||
assert r == ["S338.17", "S338.17", "Thor line (version not read)", "Blastware line (version not read)",
|
||||
"—", "—", "—"]
|
||||
|
||||
|
||||
HINT = ("the connection opened, so the modem is reachable — another program (THOR or Blastware) may be "
|
||||
"holding this unit's line, or the unit is busy (e.g. its sensor check)")
|
||||
|
||||
|
||||
def test_a_504_says_another_program_may_hold_the_line():
|
||||
# #16: measured 2026-10-29 -- while THOR polls a Micromate, SFM's connection is
|
||||
# accepted and gets 0 bytes, a 504. The hint is not added once a change was sent.
|
||||
silent = {"detail": "the unit did not answer: no reply"}
|
||||
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(["deviceErrorText", [504, silent, S4, "HTTP 504"]], ["deviceErrorText", [504, sent, S4, "HTTP 504"]],
|
||||
["deviceErrorText", [503, {"detail": "could not connect: refused"}, S4, "HTTP 503"]],
|
||||
["deviceErrorText", [504, silent, {"serial": "UM20147", "host": "", "tcpPort": 9034}, "HTTP 504"]],
|
||||
["deviceErrorText", [502, {}, S4, "HTTP 502"]])
|
||||
assert r == [f"the unit did not answer: no reply — {HINT}", sent["detail"], "could not connect: refused",
|
||||
"the unit did not answer: no reply", "HTTP 502"]
|
||||
|
||||
|
||||
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"]])
|
||||
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}"
|
||||
assert r[3] == "Stop monitoring failed: not BE9441: BE12599 answered"
|
||||
assert not any(x.startswith(("Start monitoring failed", "Stop monitoring failed")) for x in r[:2])
|
||||
|
||||
|
||||
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}]
|
||||
Reference in new issue
Block a user