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:
1 parent
073284fc88
commit
9082236c5e
3 files changed
+42
-9
No files matched your search
@@ -189,8 +189,8 @@ Read this first when picking the project back up.
|
|||||||
`stop_monitoring_blind`, `_slow_drip`, `_spam`) are exempt: 0x96/0x97 mean
|
`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
|
the same on both series, and the blind tools must reach a unit too wedged to
|
||||||
answer.
|
answer.
|
||||||
⚠ **Before serial mode is used on a unit that calls home to THOR, run the
|
⚠ **Before this branch merges, run the ring-path Runs A/B** -- the spec's
|
||||||
ring-path Runs A/B** (spec, *Open questions ... for the bench*): a held line
|
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
|
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
|
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.
|
once; whether a call-home still reaches THOR is unmeasured.
|
||||||
|
|||||||
+26
-6
@@ -1613,6 +1613,18 @@ function settingsRows(st) {
|
|||||||
return rows;
|
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 => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[c]));
|
||||||
|
}
|
||||||
|
|
||||||
function downloadSummary(body) {
|
function downloadSummary(body) {
|
||||||
if (body.inserted === false) return `already stored — ${body.stored_filename}`;
|
if (body.inserted === false) return `already stored — ${body.stored_filename}`;
|
||||||
return `stored ${body.stored_filename}, ${body.filesize} bytes, check: ${(body.detail || {}).check}`;
|
return `stored ${body.stored_filename}, ${body.filesize} bytes, check: ${(body.detail || {}).check}`;
|
||||||
@@ -1790,6 +1802,9 @@ function switchTab(name) {
|
|||||||
// ── Connect ────────────────────────────────────────────────────────────────────
|
// ── Connect ────────────────────────────────────────────────────────────────────
|
||||||
async function connectUnit() {
|
async function connectUnit() {
|
||||||
if (!devHost()) { setStatus('Enter a device host first.', 'error'); return; }
|
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');
|
const btn = document.getElementById('connect-btn');
|
||||||
btn.disabled = true;
|
btn.disabled = true;
|
||||||
@@ -1852,14 +1867,15 @@ function setEventButtonsEnabled() {
|
|||||||
// A list loaded by serial is downloaded row by row (by event_id); these
|
// A list loaded by serial is downloaded row by row (by event_id); these
|
||||||
// per-index buttons belong to the legacy list.
|
// per-index buttons belong to the legacy list.
|
||||||
const bySerial = eventsBySerial;
|
const bySerial = eventsBySerial;
|
||||||
|
const live = perIndexLive({ bySerial, count: n });
|
||||||
for (const id of ['load-btn', 'save-btn', 'download-btn']) {
|
for (const id of ['load-btn', 'save-btn', 'download-btn']) {
|
||||||
const el = document.getElementById(id);
|
const el = document.getElementById(id);
|
||||||
if (el.dataset.legacyTitle === undefined) el.dataset.legacyTitle = el.title;
|
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;
|
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('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) ──────────────────────────
|
// ── Event list (opt-in — this is the slow chain walk) ──────────────────────────
|
||||||
@@ -2083,7 +2099,9 @@ function populateDeviceTab() {
|
|||||||
for (const {label, value} of cardData) {
|
for (const {label, value} of cardData) {
|
||||||
const c = document.createElement('div');
|
const c = document.createElement('div');
|
||||||
c.className = 'dev-card';
|
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);
|
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` : '—'],
|
['ADC Scale Factor (geo)', cc.geo_adc_scale != null ? `${cc.geo_adc_scale.toFixed(4)} in/s` : '—'],
|
||||||
['Setup Name', cc.setup_name || '—'],
|
['Setup Name', cc.setup_name || '—'],
|
||||||
];
|
];
|
||||||
renderTable('compliance-table', complianceRows);
|
renderTextTable('compliance-table', complianceRows);
|
||||||
|
|
||||||
// Project table
|
// Project table
|
||||||
const projectRows = [
|
const projectRows = [
|
||||||
@@ -2111,7 +2129,7 @@ function populateDeviceTab() {
|
|||||||
['Sensor Location', cc.sensor_location || '—'],
|
['Sensor Location', cc.sensor_location || '—'],
|
||||||
['Notes', cc.notes || '—'],
|
['Notes', cc.notes || '—'],
|
||||||
];
|
];
|
||||||
renderTable('project-table', projectRows);
|
renderTextTable('project-table', projectRows);
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderTextTable(id, rows) {
|
function renderTextTable(id, rows) {
|
||||||
@@ -2192,7 +2210,7 @@ async function refreshDiagnostics() {
|
|||||||
|
|
||||||
if (!store._err) storageInfo = store;
|
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 = [];
|
const rows = [];
|
||||||
|
|
||||||
rows.push(['Monitoring', mon._err ? err(mon._err)
|
rows.push(['Monitoring', mon._err ? err(mon._err)
|
||||||
@@ -2589,6 +2607,8 @@ function populateSerialEventTable() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function selectEvent(idx) {
|
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;
|
currentEvent = idx;
|
||||||
document.querySelectorAll('.event-chip').forEach((c, i) => c.classList.toggle('active', i === idx));
|
document.querySelectorAll('.event-chip').forEach((c, i) => c.classList.toggle('active', i === idx));
|
||||||
document.getElementById('prev-btn').disabled = idx <= 0;
|
document.getElementById('prev-btn').disabled = idx <= 0;
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ PAGE = Path(__file__).resolve().parent.parent / "sfm" / "sfm_webapp.html"
|
|||||||
NODE = shutil.which("node")
|
NODE = shutil.which("node")
|
||||||
pytestmark = pytest.mark.skipif(NODE is None, reason="node is not installed; the page-logic tests need it")
|
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"]
|
"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", "—"],
|
assert b == [["Setup Name", "—"], ["Record Mode", "—"], ["Sample Rate", "—"], ["Record Time", "—"],
|
||||||
["Histogram Interval", "—"], ["Geo Trigger", "—"], ["Notes", "—"]]
|
["Histogram Interval", "—"], ["Geo Trigger", "—"], ["Notes", "—"]]
|
||||||
assert c[4] == ["Histogram Interval", "15 s"]
|
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 <b id="x">&'", "", "42"]
|
||||||
Reference in new issue
Block a user