From 50ca7f03410fc030f0e3783e1e4670fc9135816a Mon Sep 17 00:00:00 2001 From: Jason Woltje Date: Thu, 19 Nov 2026 17:46:21 -0600 Subject: [PATCH] =?UTF-8?q?fix(webui):=20settings-s4=20shots=20round:=20a?= =?UTF-8?q?=20progress=20line=20reads=20what=20happened=20at=20each=20step?= =?UTF-8?q?=20(done,=20under=20way,=20not=20started,=20or=20"did=20not=20f?= =?UTF-8?q?inish"=20where=20the=20run=20stopped),=20so=20a=20failed=20step?= =?UTF-8?q?=20no=20longer=20reads=20"Starting=20the=20service=E2=80=A6";?= =?UTF-8?q?=20an=20account's=20health=20badge=20keeps=20its=20own=20width?= =?UTF-8?q?=20on=20a=20phone;=20the=20model=20search=20box=20has=20a=20pla?= =?UTF-8?q?ceholder;=20the=20slice=204=20test=20file=20takes=20shots=20at?= =?UTF-8?q?=20390=20and=201440,=20light=20and=20dark,=20with=20MOSAIC=5FUX?= =?UTF-8?q?=5FSHOTS=20set,=20and=20checks=20sideways=20scroll,=20select=20?= =?UTF-8?q?fit=20and=20a=20visible=20focus=20ring=20on=20every=20control?= =?UTF-8?q?=20it=20tabs=20to=20(#1873,=20lane=20settings-s4)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/webui/src/public/display.js | 10 +- packages/webui/src/public/shell.css | 2 +- .../webui/tests/settings-s4-browser.test.mjs | 111 +++++++++++++++++- 3 files changed, 113 insertions(+), 10 deletions(-) diff --git a/packages/webui/src/public/display.js b/packages/webui/src/public/display.js index 9b2a76598..fd3a8855d 100644 --- a/packages/webui/src/public/display.js +++ b/packages/webui/src/public/display.js @@ -827,7 +827,7 @@ if (document.documentElement.hasAttribute('data-settings-proxy-document') && !lo label.append(box2, ` ${m.model}${m.reason === 'unverified' ? ' (unverified)' : ''}`); li.dataset.model = String(m.model).toLowerCase(); li.append(label, el('span', 'Coming later', 'small muted')); return li; })); if (mine.length > 8) { const field = el('div', undefined, 'field'), id = `proxy-find-${norm(provider)}`, label = el('label', `Find a ${name} model`), input = document.createElement('input'); - label.htmlFor = id; input.id = id; input.type = 'search'; input.autocomplete = 'off'; + label.htmlFor = id; input.id = id; input.type = 'search'; input.autocomplete = 'off'; input.placeholder = 'Part of a name'; input.addEventListener('input', () => { const q = input.value.trim().toLowerCase(); list.querySelectorAll('li').forEach(li => { li.hidden = Boolean(q) && !li.dataset.model.includes(q); }); }); field.append(label, input); inside.append(field); } @@ -993,7 +993,11 @@ if (document.documentElement.hasAttribute('data-settings-proxy-document') && !lo // settings-p3 (re-check 3 P3-1): where the hand steps for a held init lock or a partial init are written. const README_STEPS = ['The hand steps for a stale init lock and a partial init are in ', 'packages/model-proxy/README.md']; const CHAIN = ['fetch', 'init', 'unit-install', 'unit-start']; - const PROGRESS = [['fetch', 'Downloaded and checked'], ['init', 'Configured'], ['start', 'Starting the service…'], ['answer', 'Checking it answers']]; + // Each line reads as what happened: done, under way, not started, or the step where the run stopped. + const PROGRESS = [['fetch', { ok: 'Downloaded and checked', run: 'Downloading and checking…', todo: 'Download and check', bad: 'Download and check: did not finish' }], + ['init', { ok: 'Configured', run: 'Configuring…', todo: 'Configure', bad: 'Configure: did not finish' }], + ['start', { ok: 'Started the service', run: 'Starting the service…', todo: 'Start the service', bad: 'Start the service: did not finish' }], + ['answer', { ok: 'Answers on this machine', run: 'Checking it answers…', todo: 'Check it answers', bad: 'Check it answers: no answer yet' }]]; const stageOf = step => step === 'fetch' || step === 'init' ? step : step === 'unit-install' || step === 'unit-start' ? 'start' : 'answer'; // Each line is done only when the status read says so. function progressDone() { @@ -1009,7 +1013,7 @@ if (document.documentElement.hasAttribute('data-settings-proxy-document') && !lo if (!ok[key] && chain?.failed && stageOf(chain.failed.at) === key) cls = 'bad'; else if (!ok[key] && first && (chain?.running || state.fetch?.state === 'running')) cls = 'run'; if (!ok[key]) first = false; - const li = el('li', text, cls); li.dataset.stage = key; li.append(el('span', ` (${words[cls]})`, 'sr-only')); return li; + const li = el('li', text[cls], cls); li.dataset.stage = key; li.append(el('span', ` (${words[cls]})`, 'sr-only')); return li; })); } function goButton(label, next, disabled, action) { diff --git a/packages/webui/src/public/shell.css b/packages/webui/src/public/shell.css index 6f4ae1256..a7f1a2cb8 100644 --- a/packages/webui/src/public/shell.css +++ b/packages/webui/src/public/shell.css @@ -346,7 +346,7 @@ button:disabled,[aria-disabled=true]{cursor:not-allowed} .err-line{color:var(--danger)} .settings-content details{margin-top:var(--gap,12px)} .settings-content details>.inside{margin-top:var(--gap,12px)} -@media(max-width:759px){.rows li{grid-template-columns:1fr}.setup-step .summary,.setup-step .body{margin-left:0}.settings-form{max-width:none}.settings-form .w-num{max-width:none}} +@media(max-width:759px){.rows li{grid-template-columns:1fr}.rows li>.badge{justify-self:start}.setup-step .summary,.setup-step .body{margin-left:0}.settings-form{max-width:none}.settings-form .w-num{max-width:none}} @media(max-width:959px) and (min-width:760px){.settings-layout{grid-template-columns:180px minmax(0,1fr);gap:24px}} @media(max-width:759px){.settings-layout{display:block}.settings-layout>div:first-child{margin-bottom:20px}#settings-disclosure{width:100%;min-height:44px;display:flex;align-items:center;gap:12px;padding:6px 12px;border:1px solid var(--border);border-radius:var(--r);background:var(--surface);color:var(--text);text-align:left}#settings-disclosure small{color:var(--muted)}#settings-disclosure span{margin-left:auto}#settings-disclosure[aria-expanded=false]+#settings-nav{display:none}#settings-nav{padding:12px 0}.settings-content>h2{font-size:21px}.palette-grid{grid-template-columns:repeat(3,minmax(0,1fr));gap:11px}.palette-content{min-height:64px;padding:7px}.palette-tile input:checked+.palette-content{padding:6px}.settings-segments{display:flex;width:100%}.settings-segments label{flex:1;min-width:0}.settings-segments span,.settings-appearance .panel:last-child .settings-segments span{min-width:0;padding:0 4px}.settings-content .table-wrap{max-width:100%}} .settings-content [aria-invalid=true]{border:2px solid var(--danger)!important} diff --git a/packages/webui/tests/settings-s4-browser.test.mjs b/packages/webui/tests/settings-s4-browser.test.mjs index 644d2a0f3..e72e290a6 100644 --- a/packages/webui/tests/settings-s4-browser.test.mjs +++ b/packages/webui/tests/settings-s4-browser.test.mjs @@ -58,31 +58,34 @@ async function orgFixture() { // scopes some reads under /api/orgs//). Everything else is the real server. const SERVICE_UP = { next: ['accounts'], init: { initialized: true, files: [] }, release: { fetched: true, verified: true, version: '8.0.42', panelVersion: '1.26.7' }, unit: { unit: 'mosaic-proxy.service', installed: true, active: 'active', port: 18432, listening: true }, fence: { set: false }, initLock: { present: false, blockers: [] }, fetch: { state: 'idle' }, organizations: [], ride: [] }; -const ownerStub = (service = SERVICE_UP) => `(() => { - const real = window.fetch.bind(window); window.__s4 = ${JSON.stringify({ service })}; +const ownerStub = (service = SERVICE_UP, extra = {}) => `(() => { + const real = window.fetch.bind(window); window.__s4 = ${JSON.stringify({ service, accounts: [], routes: null, posts: {}, ...extra })}; window.__writes = []; const json = (body, status = 200) => new Response(JSON.stringify(body), { status, headers: { 'content-type': 'application/json' } }); window.fetch = async (input, init = {}) => { const url = new URL(typeof input === 'string' ? input : input.url, location.href), path = url.pathname, method = (init.method || 'GET').toUpperCase(); + if (method !== 'GET' && /\\/proxy\\//.test(path)) { window.__writes.push(path); const key = Object.keys(__s4.posts).find(k => path.endsWith(k)); const a = key ? __s4.posts[key] : { status: 500, body: { error: 'stub' } }; + if (a === 'hang') return new Promise(() => {}); if (a.service) __s4.service = a.service; return json(a.body ?? {}, a.status ?? 200); } if (method !== 'GET') return real(input, init); + if (__s4.routes && /\\/bus\\/routes$/.test(path)) return json(__s4.routes); if (/\\/api\\/(orgs\\/[^/]+\\/)?config$/.test(path)) { const c = await (await real(input, init)).json(); return json({ ...c, orgSetup: true, proxyAdmin: true, proxyAdminSend: true, ...(/\\/orgs\\//.test(path) ? { settingsSend: true } : {}) }); } if (path.endsWith('/proxy/admin/status')) return json(__s4.service); - if (path.endsWith('/proxy/accounts')) return json({ accounts: [] }); + if (path.endsWith('/proxy/accounts')) return json({ accounts: __s4.accounts }); if (path.endsWith('/proxy/keys')) return json({ keys: [] }); if (path.endsWith('/triage/route')) return json({ route: null }); return real(input, init); }; })();`; -async function orgSetup(t, { path, viewport = [1440, 900], service } = {}) { +async function orgSetup(t, { path, viewport = [1440, 900], service, extra } = {}) { const { organizations, agentLevels } = await orgFixture(); const server = await startServer({ port: 0, sso: createDevOwner(), organizations, agentLevels, triage: null, send: async () => ({}), log: () => {} }); t.after(() => close(server)); const b = await browser({ machine: false }); t.after(() => b.close()); await b.viewport(...viewport); - await b.call('Page.addScriptToEvaluateOnNewDocument', { source: ownerStub(service) }); + await b.call('Page.addScriptToEvaluateOnNewDocument', { source: ownerStub(service, extra) }); await b.navigate(`http://127.0.0.1:${server.address().port}${path}`); const wait = expression => b.evaluate(`(async()=>{for(let i=0;i<250;i++){if(${expression})return true;await new Promise(r=>setTimeout(r,30))}throw Error("wait failed: "+${JSON.stringify(expression)}+" HASH "+location.hash)})()`); - return { b, wait, text: sel => b.evaluate(`document.querySelector(${JSON.stringify(sel)})?.textContent ?? null`) }; + return { b, wait, base: `http://127.0.0.1:${server.address().port}`, text: sel => b.evaluate(`document.querySelector(${JSON.stringify(sel)})?.textContent ?? null`) }; } test('settings-s4: the nav has four groups, the organization pages carry ?org=, the picker switches organization, and there is no Members row', { timeout: 90000 }, async t => { @@ -215,6 +218,7 @@ test('settings-s4: a step that fails stops the run with Try again, keeps the fin assert.deepEqual(await admin(b), ['init', 'unit/install'], 'nothing is retried by itself'); assert.equal(await b.evaluate('document.querySelector("#setup-step-service [data-step-badge]").textContent'), 'Setup stopped'); assert.deepEqual(await b.evaluate('[...document.querySelectorAll("#proxy-setup-progress li")].map(li => li.className)'), ['ok', 'ok', 'bad', 'todo']); + assert.deepEqual(await b.evaluate('[...document.querySelectorAll("#proxy-setup-progress li")].map(li => li.firstChild.textContent)'), ['Downloaded and checked', 'Configured', 'Start the service: did not finish', 'Check it answers']); assert.equal(await b.evaluate('document.querySelector("#proxy-setup-lines").checkVisibility() && document.querySelector("#proxy-setup-lines summary").textContent'), "The service's last lines"); assert.deepEqual(await primaries(b), ['proxy-setup-go']); assert.equal(await b.evaluate('document.querySelector("#proxy-setup-advanced summary").textContent'), 'Advanced: programs, port, timeouts'); @@ -301,3 +305,98 @@ test('settings-s4 P3: the done line names an organization that turned the model assert.deepEqual(await primaries(b), [], 'nothing left to do: no primary button'); assert.deepEqual(await b.evaluate('window.__unexpected'), []); }); + +// Shots for the build report, beside the mockups: run with MOSAIC_UX_SHOTS=. Each page is shot whole +// at 390 and 1440, light and dark. Every page is measured: nothing scrolls sideways, every visible select +// shows its chosen text, and every visible control shows a focus ring when it takes keyboard focus. +test('shots', { timeout: 900000, skip: !process.env.MOSAIC_UX_SHOTS }, async t => { + const { mkdir, writeFile } = await import('node:fs/promises'); + const { join } = await import('node:path'); + const dir = process.env.MOSAIC_UX_SHOTS; await mkdir(dir, { recursive: true }); + const settle = () => new Promise(r => setTimeout(r, 1200)); + const fresh = { ...SERVICE_UP, release: { ...SERVICE_UP.release, fetched: false, verified: false }, init: { initialized: false, partial: false, files: [] }, + unit: { unit: 'mosaic-proxy.service', installed: false, active: 'inactive' }, fetch: { state: 'idle' }, organizations: [{ id: 'acme', proxy: 'shared', catalogue: null }, { id: 'north', proxy: 'shared', catalogue: null }], next: ['fetch'] }; + const fetched = { ...fresh, release: { ...fresh.release, fetched: true, verified: true }, next: ['init'] }; + const configured = { ...fetched, init: { initialized: true, partial: false, settings: { port: 18432 }, files: [] }, next: ['unit-install'] }; + const ready = [{ id: 'acme', proxy: 'shared', catalogue: { status: 'ready', models: 12 } }, { id: 'north', proxy: 'shared', catalogue: { status: 'ready', models: 12 } }]; + const up = { ...SERVICE_UP, organizations: ready, ride: [{ id: 'acme', state: 'already' }, { id: 'north', state: 'already' }, { id: 'gamma', state: 'bus-down' }] }; + const accounts = [{ accountId: 'a1', provider: 'claude', displayName: 'Claude work', status: 'active', priority: 1 }, { accountId: 'a2', provider: 'codex', displayName: 'Codex home', status: 'active', priority: 0 }]; + const models = Array.from({ length: 10 }, (_, i) => ({ module: 'cliproxy', upstream: 'claude', model: `claude-sonnet-4-${i}`, available: true })) + .concat(['gpt-5.1', 'gpt-5.1-codex'].map(model => ({ module: 'cliproxy', upstream: 'codex', model, available: true }))); + const routes = { rows: [{ ...VIEW, catalogue: { status: 'ready', observedAt: new Date().toISOString(), models, notices: [] } }] }; + const go = 'document.querySelector("#proxy-setup-go").click(); true'; + const PAGES = [ + { name: 'nav-open', path: '/#/settings/routing?org=acme', ready: 'document.querySelector("#org-pick")', after: async (b, wait, width) => { + if (width === 390) { await b.evaluate('document.querySelector("#settings-disclosure").click(); true'); await wait('document.querySelector("#settings-nav a").checkVisibility()'); } } }, + { name: 'models-nothing', path: '/#/settings/model-setup', service: fresh, ready: 'document.querySelector("#proxy-setup-go")?.dataset.next === "fetch"' }, + { name: 'models-setting-up', path: '/#/settings/model-setup', service: fetched, extra: { posts: { '/admin/init': { body: { receipt: { op: 'init' } }, service: configured }, '/admin/unit/install': 'hang' } }, + ready: 'document.querySelector("#proxy-setup-go")?.dataset.next === "init"', after: async (b, wait) => { await b.evaluate(go); await wait('document.querySelector("#proxy-setup-progress li.run")'); } }, + { name: 'models-setup-failed', path: '/#/settings/model-setup', service: fetched, extra: { posts: { '/admin/init': { body: { receipt: { op: 'init' } }, service: configured }, '/admin/unit/install': { status: 500, body: { error: 'unit-install-failed' } } } }, + ready: 'document.querySelector("#proxy-setup-go")?.dataset.next === "init"', after: async (b, wait) => { await b.evaluate(go); await wait('document.querySelector("#proxy-setup-go").textContent === "Try again"'); } }, + { name: 'models-running', path: '/#/settings/model-setup', service: { ...SERVICE_UP, organizations: [{ id: 'acme', proxy: 'shared', catalogue: { status: 'ready', models: 0 } }] }, ready: 'document.querySelector("#setup-step-accounts")?.dataset.state === "next"' }, + { name: 'models-accounts', path: '/#/settings/model-setup?step=accounts', service: up, extra: { accounts, routes }, ready: 'document.querySelectorAll("#proxy-accounts li[data-account]").length === 2' }, + { name: 'models-accounts-signin', path: '/#/settings/model-setup?step=accounts', service: up, extra: { accounts, routes, posts: { '/login/start': { body: { url: 'https://claude.ai/oauth/authorize?state=shot', state: 'shot' } }, '/login/status': { body: { status: 'wait' } } } }, + ready: 'document.querySelectorAll("#proxy-accounts li[data-account]").length === 2', after: async (b, wait) => { + await b.evaluate('window.open = () => null; document.querySelector("#proxy-add-box").open = true; document.querySelector("#proxy-login-start").requestSubmit(); true'); await wait('!document.querySelector("#proxy-signin").hidden'); } }, + { name: 'models-accounts-key', path: '/#/settings/model-setup?step=accounts', service: up, extra: { accounts, routes }, ready: 'document.querySelectorAll("#proxy-accounts li[data-account]").length === 2', after: async b => { + await b.evaluate('(() => { document.querySelector("#proxy-add-box").open = true; const s = document.querySelector("#proxy-provider"); s.value = "z.ai"; s.dispatchEvent(new Event("change")); return true; })()'); } }, + { name: 'models-offered', path: '/#/settings/model-setup?step=accounts', service: up, extra: { accounts, routes }, ready: 'document.querySelectorAll("#proxy-accounts li[data-account]").length === 2', after: async (b, wait) => { + await b.evaluate('document.querySelector("#proxy-offered").open = true; true'); await wait('document.querySelector("#proxy-offered-list details[data-offered=claude]")'); + await b.evaluate('document.querySelector("#proxy-offered-list details[data-offered=claude]").open = true; true'); } }, + { name: 'models-problems', path: '/#/settings/model-setup', service: { ...up, organizations: [{ id: 'acme', proxy: 'shared', catalogue: { status: 'ready', launchRestart: true } }, { id: 'north', proxy: 'shared', catalogue: { status: 'ready', models: 12 } }], + ride: [{ id: 'acme', state: 'already' }, { id: 'north', state: 'already' }, { id: 'gamma', state: 'fixture', running: false }] }, extra: { accounts: [accounts[0], { ...accounts[1], status: 'error' }], routes }, + ready: 'document.querySelector("#setup-step-accounts")?.dataset.state === "bad"' }, + { name: 'models-advanced', path: '/#/settings/model-setup', service: up, extra: { accounts, routes }, ready: 'document.querySelector("#setup-step-service")?.dataset.state === "done"', after: async b => { + await b.evaluate('document.querySelector("#proxy-setup-advanced").open = true; document.querySelector("#proxy-setup-tech").open = true; true'); } }, + { name: 'org-models', path: '/#/settings/routing?org=acme', service: up, ready: 'document.querySelector(".routing-panel select, .routing-panel")' }, + { name: 'sidebar-marks', path: '/#/dashboard', service: { ...up, organizations: [{ id: 'acme', proxy: 'shared', catalogue: { status: 'ready', launchRestart: true } }], ride: [{ id: 'gamma', state: 'fixture', running: false }] }, + ready: `${mark('acme')} === 'needs restart'`, viewportOnly: true }, + ]; + const report = []; + for (const page of PAGES) for (const scheme of ['light', 'dark']) for (const width of [390, 1440]) { + const f = await orgSetup(t, { path: '/', service: page.service ?? up, extra: page.extra, viewport: [width, width === 390 ? 844 : 900] }); + await f.b.call('Emulation.setScrollbarsHidden', { hidden: true }); + await f.b.call('Emulation.setEmulatedMedia', { features: [{ name: 'prefers-color-scheme', value: scheme }] }); + await f.b.navigate(`${f.base}/?shot=${page.name}-${scheme}-${width}${page.path.slice(1)}`); + await f.wait(`(${page.ready}) && !!window.MosaicAppearance`); + await f.b.evaluate(`window.MosaicAppearance.ready.then(() => window.MosaicAppearance.set({ mode: ${JSON.stringify(scheme)} }))`); + if (page.after) await page.after(f.b, f.wait, width); + await settle(); + const fit = await f.b.evaluate(`(() => { + const out = [], probe = document.createElement('span'); probe.style.cssText = 'position:absolute;visibility:hidden;white-space:nowrap'; document.body.append(probe); + for (const s of document.querySelectorAll('select')) { if (!s.checkVisibility()) continue; const cs = getComputedStyle(s), r = s.getBoundingClientRect(); + probe.style.font = cs.font; probe.textContent = s.selectedOptions[0]?.textContent ?? ''; + out.push({ label: s.id || s.name, text: probe.textContent, need: Math.ceil(probe.getBoundingClientRect().width), room: Math.floor(s.clientWidth - parseFloat(cs.paddingLeft) - parseFloat(cs.paddingRight)), inside: r.left >= 0 && r.right <= innerWidth + 0.5 }); } + probe.remove(); return { selects: out, sideways: document.documentElement.scrollWidth > document.documentElement.clientWidth }; + })()`); + // Keyboard focus: Tab through the page and note any control whose ring is not visible. + const noRing = [], seen = new Set(); + for (let i = 0; i < 120; i++) { + await f.b.call('Input.dispatchKeyEvent', { type: 'keyDown', key: 'Tab', code: 'Tab', windowsVirtualKeyCode: 9 }); + await f.b.call('Input.dispatchKeyEvent', { type: 'keyUp', key: 'Tab', code: 'Tab', windowsVirtualKeyCode: 9 }); + const r = await f.b.evaluate(`(() => { const e = document.activeElement; if (!e || e === document.body) return null; const cs = getComputedStyle(e); + const ring = (cs.outlineStyle !== 'none' && parseFloat(cs.outlineWidth) > 0) || (cs.boxShadow && cs.boxShadow !== 'none'); + return { key: e.id || e.getAttribute('href') || e.tagName + ':' + (e.textContent || '').trim().slice(0, 30), ring }; })()`); + if (!r || seen.has(r.key)) break; seen.add(r.key); + if (!r.ring) noRing.push(r.key); + } + await f.b.evaluate('document.activeElement?.blur(); window.scrollTo(0, 0); true'); await settle(); + const shot = `${page.name}-${width}-${scheme}.png`; + if (page.viewportOnly) await f.b.screenshot(join(dir, shot)); + else { + let metrics = await f.b.call('Page.getLayoutMetrics'), size = metrics.cssContentSize || metrics.contentSize; + await f.b.viewport(width, Math.ceil(size.height)); await settle(); + metrics = await f.b.call('Page.getLayoutMetrics'); size = metrics.cssContentSize || metrics.contentSize; + const { data } = await f.b.call('Page.captureScreenshot', { format: 'png', captureBeyondViewport: true, clip: { x: 0, y: 0, width: Math.ceil(size.width), height: Math.ceil(size.height), scale: 1 } }); + await writeFile(join(dir, shot), Buffer.from(data, 'base64')); + } + report.push({ page: page.name, width, scheme, shot, ...fit, noRing }); + await f.b.close(); + } + await writeFile(join(dir, 'measure.json'), JSON.stringify(report, null, 1)); + for (const r of report) { + assert.equal(r.sideways, false, `${r.shot} scrolls sideways`); + assert.deepEqual(r.noRing, [], `${r.shot}: controls with no visible focus ring`); + if (r.width === 390) for (const s of r.selects) { assert.ok(s.inside, `${r.shot}: ${s.label} runs off screen`); assert.ok(s.need <= s.room, `${r.shot}: ${s.label} cuts "${s.text}" (${s.need} > ${s.room})`); } + } +});