diff --git a/packages/webui/src/public/display.js b/packages/webui/src/public/display.js index 8aa8a9f6d..1cd772693 100644 --- a/packages/webui/src/public/display.js +++ b/packages/webui/src/public/display.js @@ -1501,9 +1501,9 @@ if (document.documentElement.hasAttribute('data-settings-proxy-document') && !lo const view = offView; if (!view) return; view.reread = 'reading'; paintOffResult(); while (loading) await pause(50); - const before = state; await load(); + const painted = await load(); if (offView !== view) return; - view.reread = state !== before ? 'ok' : 'failed'; paintOffResult(); + view.reread = painted ? 'ok' : 'failed'; paintOffResult(); const box = $('proxy-setup-programs-result'); if (fromButton || document.activeElement === document.body || !document.activeElement) (view.reread === 'failed' ? $('proxy-setup-programs-reread') : box)?.focus(); } @@ -1666,11 +1666,13 @@ if (document.documentElement.hasAttribute('data-settings-proxy-document') && !lo document.dispatchEvent(new CustomEvent('mosaic-proxy-status', { detail: state })); focusStep(); } + // True once the answer is painted, so a caller can say the list on the page is the new one. async function load() { - if (!enabled || loading) return; loading = true; - try { state = await admin('status'); causeRound++; if (state.next?.[0] === 'accounts' && triageSet === null) await readTriage(); paint(); if (state.init.initialized) await accountsReady(); } + if (!enabled || loading) return false; loading = true; let painted = false; + try { state = await admin('status'); causeRound++; if (state.next?.[0] === 'accounts' && triageSet === null) await readTriage(); paint(); painted = true; if (state.init.initialized) await accountsReady(); } catch (error) { say(error.message, 'error'); } finally { loading = false; } + return painted; } async function act(label, action) { if (!sendOk || state?.busy || chain?.running) return; diff --git a/packages/webui/tests/settings-s5c-browser.test.mjs b/packages/webui/tests/settings-s5c-browser.test.mjs index a0452b109..8d5402c29 100644 --- a/packages/webui/tests/settings-s5c-browser.test.mjs +++ b/packages/webui/tests/settings-s5c-browser.test.mjs @@ -85,7 +85,7 @@ const stub = ({ owner = true, status = SERVICE_UP, admin = {} } = {}) => `(() => if (at >= 0) { const name = path.slice(at + 13) + url.search; window.__admin.push(method + ' ' + name); if (method !== 'GET') window.__writes.push({ path, body: init.body ?? null }); - if (name === 'status') { const s = next(__s5c.status); return s.status ? json(s.body, s.status) : json(s); } + if (name === 'status') { const s = next(__s5c.status); if (s === null || typeof s !== 'object') return json(s); if (typeof s.raw === 'string') return new Response(s.raw, { status: 200, headers: { 'content-type': 'text/html' } }); return s.status ? json(s.body, s.status) : json(s); } const a = next(__s5c.admin[method === 'GET' ? name : method + ' ' + name]); if (!a) return json({ error: 'fixture-unexpected-api' }, 403); if (a.throws) throw new TypeError('Failed to fetch'); @@ -277,8 +277,9 @@ test('settings-s5c: focus goes to the result after a busy answer too', { timeout assert.equal(await b.evaluate('document.activeElement?.id'), 'proxy-setup-programs-result'); }); -test('settings-s5c: when the status read after an off fails, the result says the list may be out of date, and Read again reads it', { timeout: 90000 }, async t => { - const down = { status: 503, body: { error: 'outcome-unknown' } }; +test('settings-s5c: when the status read after an off fails, or answers with no status, the result says the list may be out of date, and Read again reads it', { timeout: 180000 }, async t => { + // A refusal, and three answers that are 200 but not a status: null, an empty object, a page that is not JSON. + for (const down of [{ status: 503, body: { error: 'outcome-unknown' } }, null, {}, { raw: 'Gateway' }]) { const { b, wait, click, admin } = await setup(t, { admin: { 'POST programs/off': { name: 'zeta-runner', results: [{ id: 'acme', outcome: 'failed:outcome-unknown' }], receipt: null } } }); await wait(READY); await openAdvanced(b); await wait('document.querySelector("[data-program-off=zeta-runner]")'); @@ -297,6 +298,7 @@ test('settings-s5c: when the status read after an off fails, the result says the assert.equal((await programs(b))[1].text, 'On in no organization. Off in Acme Studio and Lab Bench. Not known in Gamma Home: its list could not be read.'); assert.equal(await b.evaluate('document.querySelector("#proxy-setup-programs-reread")'), null); assert.equal(await b.evaluate('document.activeElement?.id'), 'proxy-setup-programs-result'); + } }); test('settings-s5c: a status read that drops the program being asked about, or cannot list programs, drops the question and frees the buttons', { timeout: 90000 }, async t => {