From 4d378fc38bd63552b0ef2439499448143362ce88 Mon Sep 17 00:00:00 2001 From: Jason Woltje Date: Fri, 20 Nov 2026 01:31:50 -0600 Subject: [PATCH] fix(webui): settings-s5c review: an open Turn off question goes when a status read no longer lists that program or cannot list programs, so the buttons are not left disabled (P3-1); a refusal code named like an object property (constructor) shows as its code with the plain refused words, in failText and in the shared explain(), never as page source (P3-2); after an off the result says the list above was read again only when that read worked; when it failed it says the list may be out of date and gives Read again, which reads it and moves focus to the result (P3-3); invalid-request on an off says the program is not in the Console's installed list or that list could not be read (P3-4); the programs box keeps its own spacing inside the settings form (P3-5); tests red without each change (#1873, lane settings-s5c) --- packages/webui/src/public/display.js | 43 +++++++++--- packages/webui/src/public/shell.css | 4 +- .../webui/tests/settings-s5c-browser.test.mjs | 67 +++++++++++++++++-- 3 files changed, 94 insertions(+), 20 deletions(-) diff --git a/packages/webui/src/public/display.js b/packages/webui/src/public/display.js index a3f1ba7d3..8aa8a9f6d 100644 --- a/packages/webui/src/public/display.js +++ b/packages/webui/src/public/display.js @@ -962,7 +962,7 @@ if (document.documentElement.hasAttribute('data-settings-proxy-document') && !lo 'not-configured': 'Model service setup is not available on this Console.', 'outcome-unknown': 'The outcome is unknown. Check the status before retrying.', }; - const explain = code => `${REASONS[code] ?? 'The action was refused.'} (${code})`; + const explain = code => `${Object.hasOwn(REASONS, code) ? REASONS[code] : 'The action was refused.'} (${code})`; async function admin(path, args) { const response = await fetch('/api/proxy/admin/' + path, { cache: 'no-store', credentials: 'same-origin', redirect: 'manual', method: args === undefined ? 'GET' : 'POST', @@ -985,7 +985,7 @@ if (document.documentElement.hasAttribute('data-settings-proxy-document') && !lo // A failed read says what the answer's code means here; a request that got no answer says so. A code // shaped like a Mosaic key is not shown, even though it passes admin()'s letters-and-hyphens check. const failText = (error, words) => !error?.code ? (error instanceof TypeError ? 'The Console did not answer.' : String(error?.message ?? 'The Console did not answer.')) - : /ms[kotp][-_]/i.test(error.code) ? 'The Console refused the read.' : words[error.code] ? `${words[error.code]} (${error.code})` : error.message; + : /ms[kotp][-_]/i.test(error.code) ? 'The Console refused the read.' : Object.hasOwn(words, error.code) ? `${words[error.code]} (${error.code})` : error.message; const retryButton = (id, action) => { const button = el('button', 'Read again'); button.type = 'button'; if (id) button.id = id; button.addEventListener('click', action); return button; }; // The service's last lines: one read paints every box. The lines show as the answer has them: // the route removes key-shaped text; this page adds nothing and takes nothing away. @@ -1411,6 +1411,8 @@ if (document.documentElement.hasAttribute('data-settings-proxy-document') && !lo // A repaint while a control here holds focus puts focus back on the same control. const keep = had && list.contains(had) ? (had.id ? '#' + had.id : had.dataset.programOff ? `[data-program-off="${had.dataset.programOff}"]` : null) : null; const view = programsState(); + // A read that no longer lists the program being asked about drops the question. + if (offAsk !== null && (view.error || !view.names.includes(offAsk))) offAsk = null; if (view.error) { list.replaceChildren(el('li', view.error, 'muted')); return; } const items = view.names.map(name => { const li = el('li'); li.dataset.program = name; @@ -1453,7 +1455,7 @@ if (document.documentElement.hasAttribute('data-settings-proxy-document') && !lo 'bus-down': 'Not changed. Its programs could not be read.', unreadable: 'Not changed. Something Mosaic needed to check could not be read.', 'failed:revision-conflict': 'Not changed. It changed while Mosaic was checking. Try again.', - 'failed:outcome-unknown': 'May have changed. The change did not answer in time. The list above, read again, shows what is on now.', + 'failed:outcome-unknown': 'May have changed. The change did not answer in time.', }; if (typeof outcome !== 'string') return 'Not known. The answer did not say what happened.'; if (Object.hasOwn(words, outcome)) return words[outcome]; @@ -1464,7 +1466,7 @@ if (document.documentElement.hasAttribute('data-settings-proxy-document') && !lo return 'Not known. The answer did not say what happened.'; } const OFF_WORDS = { - 'invalid-request': 'The Console refused the request: it does not list that program as installed.', + 'invalid-request': 'The Console refused the request: the program is not in its installed list, or that list could not be read.', 'human-required': 'Only the instance owner can turn a program off.', 'proxy-admin-busy': 'Another setup action is running. Wait for it to finish, then try again.', }; @@ -1473,7 +1475,16 @@ if (document.documentElement.hasAttribute('data-settings-proxy-document') && !lo if (!offView) { box.hidden = true; box.replaceChildren(); return; } box.hidden = false; if (offView.working) { box.className = 'proxy-programs-result'; box.replaceChildren(el('p', `Turning off ${offView.name}…`, 'small muted')); return; } - if (offView.line) { box.className = `proxy-programs-result banner ${offView.kind === 'busy' ? 'ref' : 'err'}`; box.replaceChildren(el('p', offView.line)); return; } + // Whether the list above was read again after the answer: it says so, and never claims a list it did not get. + const reread = () => { + if (offView.reread === 'ok') return [el('p', 'The list above is read again and shows what is on now.', 'small proxy-programs-reread')]; + if (offView.reread === 'failed') { + const foot = el('p', '', 'proxy-setup-history-foot'); foot.append(retryButton('proxy-setup-programs-reread', () => rereadPrograms(true))); + return [el('p', 'The list above could not be read again, so it may be out of date.', 'small proxy-programs-reread'), foot]; + } + return [el('p', 'Reading the list again…', 'small muted proxy-programs-reread')]; + }; + if (offView.line) { box.className = `proxy-programs-result banner ${offView.kind === 'busy' ? 'ref' : 'err'}`; box.replaceChildren(el('p', offView.line), ...reread()); return; } box.className = 'proxy-programs-result banner'; const title = el('p', `Turn off ${offView.name}: what happened in each organization.`, 'proxy-programs-result-title'); const ul = el('ul', '', 'proxy-programs-outcomes'); @@ -1482,7 +1493,19 @@ if (document.documentElement.hasAttribute('data-settings-proxy-document') && !lo li.append(el('span', orgLabel(r?.id), 'proxy-outcome-org'), document.createTextNode(': '), el('span', offOutcome(r?.outcome))); ul.append(li); } - box.replaceChildren(title, offView.results.length ? ul : el('p', 'No organization was in the answer.', 'small muted')); + box.replaceChildren(title, offView.results.length ? ul : el('p', 'No organization was in the answer.', 'small muted'), ...reread()); + } + // Read the status again after a turn-off answer, after a read already under way. load() keeps the + // old state when its read fails, so a new state object is the sign the list was read again. + async function rereadPrograms(fromButton) { + const view = offView; if (!view) return; + view.reread = 'reading'; paintOffResult(); + while (loading) await pause(50); + const before = state; await load(); + if (offView !== view) return; + view.reread = state !== before ? '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(); } async function programsOff(name) { if (!sendOk || offBusy) return; @@ -1497,14 +1520,12 @@ if (document.documentElement.hasAttribute('data-settings-proxy-document') && !lo } catch (error) { if (error?.code === 'proxy-admin-busy') view = { name, kind: 'busy', line: `${name} was not turned off. ${OFF_WORDS['proxy-admin-busy']}` }; else if (error?.code === 'invalid-request' || error?.code === 'human-required') view = { name, line: `${name} was not turned off. ${failText(error, OFF_WORDS)}` }; - else view = { name, line: `Turning off ${name} may not have finished, so some organizations may have changed. ${failText(error, OFF_WORDS)} The list above, read again, shows what is on now.` }; + else view = { name, line: `Turning off ${name} may not have finished, so some organizations may have changed. ${failText(error, OFF_WORDS)}` }; } offView = view; offBusy = false; paintOffResult(); paintPrograms(); box.focus(); - // After any answer, read the status again, after a read already under way. - while (loading) await pause(50); - await load(); - if (document.activeElement === document.body || !document.activeElement) box.focus(); + // After any answer, read the status again. + await rereadPrograms(false); } // settings-s5c: access health per organization, read when Technical details opens (owner only). // Ready only for health ok whose every stack-managed key is active; never a key, a key id or the diff --git a/packages/webui/src/public/shell.css b/packages/webui/src/public/shell.css index 2c05ca5d4..4525e39a0 100644 --- a/packages/webui/src/public/shell.css +++ b/packages/webui/src/public/shell.css @@ -123,12 +123,12 @@ table.s1-table td code{font-size:12.5px;white-space:nowrap} #proxy-setup-history{list-style:none;padding-left:0;overflow-wrap:anywhere;font-size:13px;margin:0 0 8px}#proxy-setup-history li{padding:2px 0} .proxy-setup-history-foot{display:flex;flex-wrap:wrap;gap:8px;margin:0}.proxy-setup-history-foot button,[data-log] button,#proxy-setup-keymade-retry{min-height:44px} /* settings-s5c: Programs that drive models under Advanced, and Access under Technical details. */ -.proxy-programs{margin-bottom:20px}.proxy-programs-list{list-style:none;margin:8px 0 0;padding:0}.proxy-programs-list>li{padding:10px 0;border-top:1px solid var(--line);min-width:0} +.settings-form.proxy-programs{margin-bottom:20px;gap:8px}.proxy-programs-list{list-style:none;margin:8px 0 0;padding:0}.proxy-programs-list>li{padding:10px 0;border-top:1px solid var(--line);min-width:0} .proxy-program-head{display:flex;flex-wrap:wrap;align-items:center;justify-content:space-between;gap:8px 12px}.proxy-program-name{font-weight:600;color:var(--strong)} .proxy-program-head button,.proxy-program-confirm button,#proxy-setup-access-retry{min-height:44px}.proxy-program-orgs{margin:4px 0 0;overflow-wrap:anywhere} .proxy-program-confirm{margin:8px 0 0;padding:10px 12px;border:1px solid color-mix(in srgb,var(--danger) 50%,var(--line));border-radius:var(--r);background:color-mix(in srgb,var(--danger) 6%,var(--surface))}.proxy-program-confirm>p:first-child{margin:0 0 8px;overflow-wrap:anywhere} .proxy-program-confirm button.danger{color:var(--danger);border-color:color-mix(in srgb,var(--danger) 60%,var(--line))} -.proxy-programs-result{margin:12px 0 0;display:block}.proxy-programs-result[hidden]{display:none}.proxy-programs-result:focus-visible,#proxy-setup-access-title:focus-visible{outline:2px solid var(--focus);outline-offset:2px}.proxy-programs-result>p{margin:0}.proxy-programs-result-title{font-weight:600;color:var(--strong)} +.proxy-programs-result{margin:12px 0 0;display:block}.proxy-programs-result[hidden]{display:none}.proxy-programs-result:focus-visible,#proxy-setup-access-title:focus-visible{outline:2px solid var(--focus);outline-offset:2px}.proxy-programs-result>p{margin:0}.proxy-programs-result>.proxy-programs-reread{margin-top:8px}.proxy-programs-result-title{font-weight:600;color:var(--strong)} .proxy-programs-outcomes{margin:6px 0 0;padding-left:18px;overflow-wrap:anywhere}.proxy-programs-outcomes li{padding:2px 0}.proxy-outcome-org{font-weight:600} .proxy-setup-access{margin:12px 0}.proxy-setup-access h4{margin:0 0 2px}.proxy-access li>.badge{justify-self:start}.proxy-setup-access .rows{margin-top:4px}#proxy-setup-access-message:empty{display:none} [data-log] .setup-log{margin:8px 0}[data-log] p{margin:0 0 8px}#proxy-setup-history-message:empty{display:none} diff --git a/packages/webui/tests/settings-s5c-browser.test.mjs b/packages/webui/tests/settings-s5c-browser.test.mjs index 92bd0a6af..a0452b109 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') return json(next(__s5c.status)); + if (name === 'status') { const s = next(__s5c.status); 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'); @@ -205,6 +205,7 @@ test('settings-s5c: each outcome id renders its line, by display name', { timeou await wait('document.querySelectorAll("#proxy-setup-programs-result li").length === 11'); assert.equal(await b.evaluate('document.querySelector(".proxy-programs-result-title").textContent'), 'Turn off zeta-runner: what happened in each organization.'); const lines = await outcomes(b); + await wait('/The list above is read again and shows what is on now\./.test(document.querySelector("#proxy-setup-programs-result").textContent)'); assert.deepEqual(lines, [ 'Acme Studio: Turned off.', 'Gamma Home: It was already off. Nothing changed.', @@ -213,7 +214,7 @@ test('settings-s5c: each outcome id renders its line, by display name', { timeou 'o5: Not changed. Its programs could not be read.', 'o6: Not changed. Something Mosaic needed to check could not be read.', 'o7: Not changed. It changed while Mosaic was checking. Try again.', - 'o8: May have changed. The change did not answer in time. The list above, read again, shows what is on now.', + 'o8: May have changed. The change did not answer in time.', 'o9: Not changed. It refused the change (plugins-refused).', 'o10: Not known. The answer did not say what happened.', 'o11: Not known. The answer did not say what happened.', @@ -236,15 +237,15 @@ test('settings-s5c: busy and a failed request each render a plain line, and the await wait('document.querySelector("[data-program-off=pi]") && !document.querySelector("[data-program-off=pi]").disabled'); const before = (await admin()).filter(r => r === 'GET status').length; await click('[data-program-off=pi]'); await wait('document.querySelector("#proxy-setup-programs-yes")'); await click('#proxy-setup-programs-yes'); - await wait(`window.__admin.filter(r => r === "POST programs/off").length === ${i + 1} && window.__admin.lastIndexOf("GET status") > window.__admin.lastIndexOf("POST programs/off") && !/Turning off pi…/.test(document.querySelector("#proxy-setup-programs-result").textContent)`); + await wait(`window.__admin.filter(r => r === "POST programs/off").length === ${i + 1} && window.__admin.lastIndexOf("GET status") > window.__admin.lastIndexOf("POST programs/off") && /The list above is read again/.test(document.querySelector("#proxy-setup-programs-result").textContent)`); assert.equal((await admin()).filter(r => r === 'GET status').length, before + 1); lines.push([await b.evaluate('document.querySelector("#proxy-setup-programs-result").className'), await b.evaluate('document.querySelector("#proxy-setup-programs-result").textContent')]); } assert.deepEqual(lines, [ - ['proxy-programs-result banner ref', 'pi was not turned off. Another setup action is running. Wait for it to finish, then try again.'], - ['proxy-programs-result banner err', 'Turning off pi may not have finished, so some organizations may have changed. The outcome is unknown. Check the status before retrying. (outcome-unknown) The list above, read again, shows what is on now.'], - ['proxy-programs-result banner err', 'pi was not turned off. The Console refused the request: it does not list that program as installed. (invalid-request)'], - ['proxy-programs-result banner err', 'Turning off pi may not have finished, so some organizations may have changed. The Console did not answer. The list above, read again, shows what is on now.'], + ['proxy-programs-result banner ref', 'pi was not turned off. Another setup action is running. Wait for it to finish, then try again.The list above is read again and shows what is on now.'], + ['proxy-programs-result banner err', 'Turning off pi may not have finished, so some organizations may have changed. The outcome is unknown. Check the status before retrying. (outcome-unknown)The list above is read again and shows what is on now.'], + ['proxy-programs-result banner err', 'pi was not turned off. The Console refused the request: the program is not in its installed list, or that list could not be read. (invalid-request)The list above is read again and shows what is on now.'], + ['proxy-programs-result banner err', 'Turning off pi may not have finished, so some organizations may have changed. The Console did not answer.The list above is read again and shows what is on now.'], ]); }); @@ -276,6 +277,58 @@ 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' } }; + 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]")'); + const before = (await admin()).filter(r => r === 'GET status').length; + await b.evaluate(`window.__s5c.status = ${JSON.stringify([down, AFTER])}; true`); + await click('[data-program-off=zeta-runner]'); await wait('document.querySelector("#proxy-setup-programs-yes")'); await click('#proxy-setup-programs-yes'); + await wait('document.querySelector("#proxy-setup-programs-reread")'); + const shown = await b.evaluate('document.querySelector("#proxy-setup-programs-result").textContent'); + assert.match(shown, /The list above could not be read again, so it may be out of date\./); + assert.doesNotMatch(shown, /shows what is on now/); + // The old list still shows, and still says so only as what was last read. + assert.match((await programs(b))[1].text, /^On in Acme Studio\./); + await b.evaluate('document.querySelector("#proxy-setup-programs-reread").focus(); document.querySelector("#proxy-setup-programs-reread").click(); true'); + await wait('/The list above is read again and shows what is on now\./.test(document.querySelector("#proxy-setup-programs-result").textContent)'); + assert.equal((await admin()).filter(r => r === 'GET status').length, before + 2); + 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 => { + const RUNNING = { ...SERVICE_UP, fetch: { state: 'running', step: 'download' } }; + for (const dropped of [{ ...SERVICE_UP, programs: { ...PROGRAMS, installed: ['pi'] } }, { ...SERVICE_UP, programs: null }, { ...SERVICE_UP, programs: { ...PROGRAMS, installed: ['pi'] } }]) { + const { b, wait, click } = await setup(t, { status: [RUNNING, RUNNING, RUNNING, RUNNING, dropped] }); + await wait(READY); await openAdvanced(b); + await wait('document.querySelector("[data-program-off=zeta-runner]")'); + await click('[data-program-off=zeta-runner]'); await wait('document.querySelector("#proxy-setup-programs-yes")'); + assert.equal(await b.evaluate('document.querySelector("[data-program-off=pi]").disabled'), true); + await wait('!document.querySelector("li[data-program=zeta-runner]")'); + assert.equal(await b.evaluate('document.querySelector("#proxy-setup-programs-yes")'), null); + if (dropped.programs) { + assert.equal(await b.evaluate('document.querySelector("[data-program-off=pi]").disabled'), false); + await click('[data-program-off=pi]'); await wait('document.querySelector("#proxy-setup-programs-yes")'); + assert.equal(await b.evaluate('document.querySelector("#proxy-setup-programs-yes").closest("li").dataset.program'), 'pi'); + } + } +}); + +test('settings-s5c: a refusal code named like an object property shows as its code, never as page source', { timeout: 90000 }, async t => { + const refused = { status: 400, body: { error: 'constructor' } }; + const { b, wait, click, text } = await setup(t, { admin: { access: refused, 'POST programs/off': refused } }); + await wait(READY); await openAdvanced(b); await openTech(b); + await wait('!document.querySelector("#proxy-setup-access-retry").hidden && document.querySelector("[data-program-off=pi]")'); + await click('[data-program-off=pi]'); await wait('document.querySelector("#proxy-setup-programs-yes")'); await click('#proxy-setup-programs-yes'); + await wait('/may not have finished/.test(document.querySelector("#proxy-setup-programs-result").textContent)'); + const page = await b.evaluate('document.querySelector("#proxy-setup").textContent'); + assert.doesNotMatch(page, /function|native code|\[object/); + assert.match(await text('#proxy-setup-access-message'), /^Access could not be read\. /); +}); + // ---- Access ---------------------------------------------------------------------------------- test('settings-s5c: Technical details reads access when it opens and words each health; only ok with every key active reads Ready', { timeout: 90000 }, async t => { const { b, wait, admin } = await setup(t, { admin: { access: ACCESS } });