fix(webapp): the final review's three page findings

- The arrow keys reached the legacy per-index waveform route in serial mode,
  even with no list loaded (an unlocked MiniMate chain walk + 5A on the same
  modem session).  perIndexLive() is now the one rule for the per-index
  buttons, the chips and the keyboard: live only for a list loaded without a
  serial that has events.
- A failed reconnect left the previous unit's confirmation live (badge,
  Diagnostics incl. the unguarded blind/slow-drip stops, call-home read).
  connectUnit() now drops it before it identifies; only this answer confirms.
- Unit strings reached innerHTML: the Device tab's cards (active_setup, new in
  1c) and its compliance/project tables now render as text, and Diagnostics'
  error spans go through escapeHtml().
- CLAUDE.md: the ring-path Runs A/B are a merge gate (the spec's prerequisite
  to a webapp sending serial), not only a use-time one.

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-29 12:16:49 -04:00
1 parent 073284fc88
commit 9082236c5e
3 files changed
+42 -9

No files matched your search

+2 -2
View File
@@ -189,8 +189,8 @@ Read this first when picking the project back up.
`stop_monitoring_blind`, `_slow_drip`, `_spam`) are exempt: 0x96/0x97 mean
the same on both series, and the blind tools must reach a unit too wedged to
answer.
⚠ **Before serial mode is used on a unit that calls home to THOR, run the
ring-path Runs A/B** (spec, *Open questions ... for the bench*): a held line
⚠ **Before this branch merges, run the ring-path Runs A/B** -- the spec's
prerequisite to a webapp sending `serial` (*Open questions ... for the bench*): a held line
holds the modem's single TCP session. The page never polls (every request is
a click), SFM hangs up on RADIO RING, and **Hang up** releases the line at
once; whether a call-home still reaches THOR is unmeasured.
+26 -6
View File
@@ -1613,6 +1613,18 @@ function settingsRows(st) {
return rows;
}
// The legacy per-index routes (Load / Save / Download, prev/next, the arrow
// keys) address events by position on the MiniMate path: live only for a list
// loaded without a serial that has events.
function perIndexLive({ bySerial, count }) { return !bySerial && count > 0; }
// A unit's own string (setup name, project, an error naming a serial) placed
// into markup must stay text.
function escapeHtml(v) {
return String(v ?? '').replace(/[&<>"']/g,
c => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' }[c]));
}
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}`;
@@ -1790,6 +1802,9 @@ function switchTab(name) {
// ── Connect ────────────────────────────────────────────────────────────────────
async function connectUnit() {
if (!devHost()) { setStatus('Enter a device host first.', 'error'); return; }
// Whatever answered last time no longer counts: only this identify confirms.
unitConfirmed = null;
applyControls();
const btn = document.getElementById('connect-btn');
btn.disabled = true;
@@ -1852,14 +1867,15 @@ function setEventButtonsEnabled() {
// A list loaded by serial is downloaded row by row (by event_id); these
// per-index buttons belong to the legacy list.
const bySerial = eventsBySerial;
const live = perIndexLive({ bySerial, count: n });
for (const id of ['load-btn', 'save-btn', 'download-btn']) {
const el = document.getElementById(id);
if (el.dataset.legacyTitle === undefined) el.dataset.legacyTitle = el.title;
el.disabled = n === 0 || bySerial;
el.disabled = !live;
el.title = bySerial ? 'For a list loaded without a serial — use a row\'s Download' : el.dataset.legacyTitle;
}
document.getElementById('prev-btn').disabled = true;
document.getElementById('next-btn').disabled = n <= 1 || bySerial;
document.getElementById('next-btn').disabled = !live || n <= 1;
}
// ── Event list (opt-in — this is the slow chain walk) ──────────────────────────
@@ -2083,7 +2099,9 @@ function populateDeviceTab() {
for (const {label, value} of cardData) {
const c = document.createElement('div');
c.className = 'dev-card';
c.innerHTML = `<div class="dev-card-label">${label}</div><div class="dev-card-value">${value}</div>`;
const l = document.createElement('div'); l.className = 'dev-card-label'; l.textContent = label;
const v = document.createElement('div'); v.className = 'dev-card-value'; v.textContent = value;
c.append(l, v);
cards.appendChild(c);
}
@@ -2101,7 +2119,7 @@ function populateDeviceTab() {
['ADC Scale Factor (geo)', cc.geo_adc_scale != null ? `${cc.geo_adc_scale.toFixed(4)} in/s` : '—'],
['Setup Name', cc.setup_name || '—'],
];
renderTable('compliance-table', complianceRows);
renderTextTable('compliance-table', complianceRows);
// Project table
const projectRows = [
@@ -2111,7 +2129,7 @@ function populateDeviceTab() {
['Sensor Location', cc.sensor_location || '—'],
['Notes', cc.notes || '—'],
];
renderTable('project-table', projectRows);
renderTextTable('project-table', projectRows);
}
function renderTextTable(id, rows) {
@@ -2192,7 +2210,7 @@ async function refreshDiagnostics() {
if (!store._err) storageInfo = store;
const err = v => `<span style="color:var(--red)">${v}</span>`;
const err = v => `<span style="color:var(--red)">${escapeHtml(v)}</span>`;
const rows = [];
rows.push(['Monitoring', mon._err ? err(mon._err)
@@ -2589,6 +2607,8 @@ function populateSerialEventTable() {
}
function selectEvent(idx) {
// The arrow keys reach here too: they obey the same rule as the buttons.
if (!perIndexLive({ bySerial: eventsBySerial, count: eventList.length })) return;
currentEvent = idx;
document.querySelectorAll('.event-chip').forEach((c, i) => c.classList.toggle('active', i === idx));
document.getElementById('prev-btn').disabled = idx <= 0;
+14 -1
View File
@@ -24,7 +24,7 @@ PAGE = Path(__file__).resolve().parent.parent / "sfm" / "sfm_webapp.html"
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",
EXPORTS = ["seriesFromSerial", "unitQuery", "deviceUrl", "confirmedSeries", "controlsFor", "eventView", "settingsRows", "perIndexLive", "escapeHtml",
"changeSummary", "downloadSummary"]
@@ -220,3 +220,16 @@ def test_settings_rows_show_unit_settings_with_a_dash_for_null():
assert b == [["Setup Name", "—"], ["Record Mode", "—"], ["Sample Rate", "—"], ["Record Time", "—"],
["Histogram Interval", "—"], ["Geo Trigger", "—"], ["Notes", "—"]]
assert c[4] == ["Histogram Interval", "15 s"]
def test_the_per_index_routes_follow_the_list_not_the_keyboard():
# the legacy per-index routes (Load / Save / Download / arrow keys) are live
# only for a list loaded without a serial that has events
r = run(["perIndexLive", [{"bySerial": False, "count": 2}]], ["perIndexLive", [{"bySerial": True, "count": 2}]],
["perIndexLive", [{"bySerial": False, "count": 0}]], ["perIndexLive", [{"bySerial": True, "count": 0}]])
assert r == [True, False, False, False]
def test_escape_html_makes_a_unit_string_inert():
r = run(["escapeHtml", ['Bench <b id="x">&\'']], ["escapeHtml", [None]], ["escapeHtml", [42]])
assert r == ["Bench &lt;b id=&quot;x&quot;&gt;&amp;&#39;", "", "42"]