diff --git a/packages/webui/src/public/display.js b/packages/webui/src/public/display.js index dcb762341..c33e0a817 100644 --- a/packages/webui/src/public/display.js +++ b/packages/webui/src/public/display.js @@ -638,9 +638,8 @@ if (document.documentElement.hasAttribute('data-settings-proxy-document') && !lo + '
Changing these after setup is not built yet.
'; const tech = 'Not read yet.
' + '' @@ -986,6 +985,8 @@ if (document.documentElement.hasAttribute('data-settings-proxy-document') && !lo function paintLog() { for (const box of root.querySelectorAll('[data-log]')) { if (!logAnswer) { box.replaceChildren(el('p', 'Reading the service\'s lines…', 'small muted')); continue; } + // An uninstalled service has no lines: a plain line, not a fault. + if (logAnswer.none) { box.replaceChildren(el('p', LOG_WORDS['not-configured'], 'small muted'), retryButton(null, readLog)); continue; } if (logAnswer.error) { box.replaceChildren(el('p', `The service's lines could not be read. ${logAnswer.error}`, 'banner err'), retryButton(null, readLog)); continue; } const { lines, redacted, dropped } = logAnswer, notes = ['Mosaic removes anything that looks like a key.']; if (redacted) notes.push(`It removed something from ${plural(redacted, 'line')}.`); @@ -1006,18 +1007,28 @@ if (document.documentElement.hasAttribute('data-settings-proxy-document') && !lo const value = await admin('log?lines=20'); if (!value || !Array.isArray(value.lines)) throw Object.assign(new Error('The answer could not be read.'), { code: 'outcome-unknown' }); answer = { lines: value.lines.filter(line => typeof line === 'string'), redacted: count(value.redacted), dropped: count(value.dropped) }; - } catch (error) { answer = { error: failText(error, LOG_WORDS) }; } + } catch (error) { answer = error?.code === 'not-configured' ? { none: true } : { error: failText(error, LOG_WORDS) }; } if (round !== logRound || !enabled) return; logAnswer = answer; paintLog(); from?.querySelector('button')?.focus(); } // When the service key was made. Never the key: the answer has no key, and this shows only its time. + // It is the last row of the state list; paintState redraws that list, so the row paints from keyView. const KEY_WORDS = { 'not-configured': 'Model service setup is not available on this Console.', 'outcome-unknown': 'The host could not check the key.' }; - let keyRound = 0; + let keyRound = 0, keyView = { text: 'Not read yet.', failed: false }; + function paintKey() { + const dd = $('proxy-setup-keymade-text')?.parentElement; if (!dd) return; + const line = el(keyView.failed ? 'p' : 'span', keyView.text, keyView.failed ? 'banner err' : keyView.reading ? 'muted' : undefined); line.id = 'proxy-setup-keymade-text'; + dd.replaceChildren(line, ...(keyView.failed ? [retryButton('proxy-setup-keymade-retry', readKey)] : [])); + } + function keyRow(dl) { + const dt = document.createElement('dt'), dd = document.createElement('dd'), span = el('span'); span.id = 'proxy-setup-keymade-text'; + dt.textContent = 'Service key'; dd.append(span); dl.append(dt, dd); paintKey(); + } async function readKey() { if (!enabled) return; - const round = ++keyRound, dd = $('proxy-setup-keymade-text').parentElement, refocus = document.activeElement?.id === 'proxy-setup-keymade-retry'; - dd.replaceChildren(el('span', 'Reading…', 'muted')); dd.firstChild.id = 'proxy-setup-keymade-text'; + const round = ++keyRound, refocus = document.activeElement?.id === 'proxy-setup-keymade-retry'; + keyView = { text: 'Reading…', failed: false, reading: true }; paintKey(); let text, failed = false; try { const value = await admin('service-key'); @@ -1029,9 +1040,8 @@ if (document.documentElement.hasAttribute('data-settings-proxy-document') && !lo else text = `When it was made is not known. You never see it.${renewed}`; } catch (error) { failed = true; text = `When it was made could not be read. ${failText(error, KEY_WORDS)}`; } if (round !== keyRound || !enabled) return; - const span = el('span', text, failed ? 'err-line' : undefined); span.id = 'proxy-setup-keymade-text'; - dd.replaceChildren(span, ...(failed ? [' ', retryButton('proxy-setup-keymade-retry', readKey)] : [])); - if (refocus) { if (failed) $('proxy-setup-keymade-retry').focus(); else { span.tabIndex = -1; span.focus(); } } + keyView = { text, failed }; paintKey(); + if (refocus) { if (failed) $('proxy-setup-keymade-retry')?.focus(); else { const line = $('proxy-setup-keymade-text'); line.tabIndex = -1; line.focus(); } } } // Setup history, a page at a time. The first page holds the newest entries, oldest first within // it; the list shows newest first. A page can be empty and still name an older one. @@ -1046,7 +1056,7 @@ if (document.documentElement.hasAttribute('data-settings-proxy-document') && !lo if (!entry || typeof entry !== 'object' || entry.withheld === true) return null; const org = orgName(entry.org), provider = providerOf(entry.provider), some = org ?? 'An organization'; const n = (v, word) => Number.isInteger(v) && v >= 0 ? plural(v, word) : null; - const label = { + const labels = { 'account.proxy.apikey.add': provider ? `${provider} account added` : 'Account added', 'account.proxy.login.complete': 'Signed in to an account', 'account.proxy.priority.set': Number.isInteger(entry.priority) ? `Account order changed, priority ${entry.priority}` : 'Account order changed', @@ -1055,9 +1065,10 @@ if (document.documentElement.hasAttribute('data-settings-proxy-document') && !lo 'unit.install': 'Service installed', 'unit.start': 'Started', 'unit.stop': 'Stopped', 'unit.restart': 'Restarted', 'ride-all': 'Organizations switched to your models', 'ride-move': `${some} switched to your models`, 'ride-intent': `Switching ${org ?? 'an organization'} to your models`, 'ride-not-added': `${some} was not switched to your models`, 'ride-removed': `${some} stopped using your models`, - }[entry.op] ?? 'Other setup action'; + }; + const label = typeof entry.op === 'string' && Object.hasOwn(labels, entry.op) ? labels[entry.op] : 'Other setup action'; const inOrg = org && String(entry.op).startsWith('account.') ? ` in ${org}` : ''; - const user = entry.user === '[redacted]' ? 'someone whose name looked like an email address, so it is hidden' : shownName(entry.user); + const user = entry.user === '[redacted]' ? 'someone whose name Mosaic hid' : shownName(entry.user); return `${label}${inOrg} · ${window.MosaicLocalTime(entry.time)}${user ? ` · by ${user}` : ''}`; } function paintHistory() { @@ -1068,9 +1079,11 @@ if (document.documentElement.hasAttribute('data-settings-proxy-document') && !lo li.hidden = !hist.expanded && i >= FEW; return li; })); const more = hist.next !== null; - all.hidden = !hist.read || (hist.entries.length <= FEW && !more); + // Show all only when some entries are folded away; Show older whenever there is an older page and + // nothing read is folded away, so an empty page offers it at once. + all.hidden = !hist.read || hist.entries.length <= FEW; all.textContent = hist.expanded ? 'Show fewer' : 'Show all'; all.setAttribute('aria-expanded', String(hist.expanded)); - older.hidden = !hist.expanded || !more || Boolean(hist.error); + older.hidden = !more || Boolean(hist.error) || (!hist.expanded && hist.entries.length > FEW); older.disabled = hist.loading; older.textContent = hist.loading ? 'Reading…' : 'Show older'; retry.hidden = !hist.error; msg.className = hist.error ? 'banner err' : 'small muted'; @@ -1088,17 +1101,20 @@ if (document.documentElement.hasAttribute('data-settings-proxy-document') && !lo try { const value = await admin(`history?limit=25${before === null ? '' : `&before=${encodeURIComponent(before)}`}`); const next = value?.next; - if (!value || !Array.isArray(value.entries) || !(next === null || (Number.isInteger(next) && next >= 0))) throw Object.assign(new Error('The answer could not be read.'), { code: 'outcome-unknown' }); + // An older page is further back than the one asked for; one that is not would repeat entries. + if (!value || !Array.isArray(value.entries) || !(next === null || (Number.isInteger(next) && next >= 0 && (before === null || next < before)))) throw Object.assign(new Error('The answer could not be read.'), { code: 'outcome-unknown' }); if (round !== hist.round || !enabled) return; hist.entries.push(...value.entries.slice().reverse()); Object.assign(hist, { next, read: true, emptyPage: value.entries.length === 0 }); } catch (error) { if (round !== hist.round || !enabled) return; hist.error = failText(error, HISTORY_WORDS); } hist.loading = false; paintHistory(); - // The button pressed keeps focus while it stays; when it goes, focus lands on Show fewer or the heading. - if (from) { const back = [$(from), $('proxy-setup-history-all')].find(b => !b.hidden); if (back) back.focus(); else { const h = $('proxy-setup-history-title'); h.tabIndex = -1; h.focus(); } } + // The button pressed keeps focus while it stays; when it goes, focus lands on Read again, Show older, + // Show fewer or the heading, in that order. + if (from) { const back = [$(from), $('proxy-setup-history-retry'), $('proxy-setup-history-older'), $('proxy-setup-history-all')].find(b => !b.hidden); if (back) back.focus(); else { const h = $('proxy-setup-history-title'); h.tabIndex = -1; h.focus(); } } } $('proxy-setup-history-all').addEventListener('click', () => { hist.expanded = !hist.expanded; paintHistory(); }); - $('proxy-setup-history-older').addEventListener('click', () => { if (!hist.loading && hist.next !== null) readHistory(false); }); + // Show older shows what it reads: the list stays open from then on. + $('proxy-setup-history-older').addEventListener('click', () => { if (!hist.loading && hist.next !== null) { hist.expanded = true; readHistory(false); } }); $('proxy-setup-history-retry').addEventListener('click', () => readHistory(!hist.read)); $('proxy-setup-tech').addEventListener('toggle', () => { if (techOpen() && enabled) { readKey(); readHistory(true); } }); $('proxy-setup-tech-lines').addEventListener('toggle', () => { if ($('proxy-setup-tech-lines').open && enabled) readLog(); }); @@ -1115,6 +1131,7 @@ if (document.documentElement.hasAttribute('data-settings-proxy-document') && !lo row(dl, 'Fence', !fence.set ? 'Clear' : fence.invalid ? 'Set (unreadable fence file)' : `Set after ${fence.op ?? 'a key write'}${fence.org ? ` for ${fence.org}` : ''}${fence.time ? ` at ${window.MosaicLocalTime(fence.time)}` : ''}`); row(dl, 'Init lock', !initLock.present ? 'None' : initLock.clearable ? 'Stale: the bus is stopped and no model service files exist' : `Held: ${initLock.blockers.join('; ')}`); if (state.restart?.confirmed) row(dl, 'Last restart', `Confirmed at ${window.MosaicLocalTime(state.restart.observedAt)}, new pid ${state.restart.pid}`); + if (enabled) keyRow(dl); } // 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']; diff --git a/packages/webui/tests/settings-s5b-browser.test.mjs b/packages/webui/tests/settings-s5b-browser.test.mjs index 34d309c39..ca42fcb4d 100644 --- a/packages/webui/tests/settings-s5b-browser.test.mjs +++ b/packages/webui/tests/settings-s5b-browser.test.mjs @@ -56,6 +56,9 @@ const SERVICE_UP = { next: ['accounts'], init: { initialized: true, partial: fal const SERVICE_FAILED = { ...SERVICE_UP, next: ['fetch'], release: { fetched: false, verified: false, version: '8.0.42', panelVersion: '1.26.7' }, init: { initialized: false, partial: false, problem: null, files: [] }, unit: { unit: 'mosaic-proxy.service', installed: false, active: 'inactive' }, fetch: { state: 'failed', error: 'proxy-install-invalid' } }; +// Setup stopped at the start step: the service is installed but did not answer, so the start was refused. +const SERVICE_START = { ...SERVICE_UP, next: ['unit-start'], unit: { unit: 'mosaic-proxy.service', installed: true, active: 'inactive', port: 18432, listening: false, healthy: false } }; +const START_REFUSED = { 'POST unit/start': { status: 503, body: { error: 'proxy-unit-unhealthy' } } }; const LOG_OK = { unit: 'mosaic-proxy.service', lines: ['Nov 19 10:00:01 host proxy[4242]: listening on 127.0.0.1:18432', 'Nov 19 10:00:02 host proxy[4242]: loaded key [redacted]'], redacted: 1, dropped: 2 }; const KEY_OK = { madeAt: T(3), renewedAt: null, renewal: 'not-built', problem: null }; // Three pages, newest first: the first holds four entries (one withheld), the second is empty but @@ -70,19 +73,21 @@ const OK = { [LOG]: LOG_OK, 'service-key': KEY_OK, ...PAGES }; // The instance owner's flags (or not), the setup status, and the three reads by name and query. An // answer may be a list: each read takes the next one and the last one stays. window.__admin records -// every /api/proxy/admin/ request the page sends, window.__holds pauses a read by name. +// every /api/proxy/admin/ request the page sends, window.__holds pauses a read by name, and window.__queue +// pauses every request to a name, each until its own resolver runs. A write answers from admin['POST name']. const stub = ({ owner = true, service = SERVICE_UP, admin = OK } = {}) => `(() => { const real = window.fetch.bind(window); - window.__s5b = ${JSON.stringify({ owner, service, admin })}; window.__admin = []; window.__writes = []; window.__holds = {}; + window.__s5b = ${JSON.stringify({ owner, service, admin })}; window.__admin = []; window.__writes = []; window.__holds = {}; window.__queue = {}; 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(); const at = path.indexOf('/proxy/admin/'); if (at >= 0) { const name = path.slice(at + 13) + url.search; window.__admin.push(method + ' ' + name); - if (method !== 'GET') { window.__writes.push(path); return json({ error: 'stub' }, 500); } + if (method !== 'GET') { window.__writes.push(path); const w = __s5b.admin[method + ' ' + name]; return w ? json(w.body, w.status) : json({ error: 'stub' }, 500); } if (name === 'status') return json(__s5b.service); if (window.__holds[name]) await new Promise(r => { window.__holds[name] = r; }); + if (window.__queue[name]) await new Promise(r => window.__queue[name].push(r)); let a = __s5b.admin[name]; if (Array.isArray(a)) a = a.length > 1 ? a.shift() : a[0]; if (!a) return json({ error: 'fixture-unexpected-api' }, 403); @@ -127,7 +132,9 @@ test('settings-s5b: Technical details shows when the service key was made, the s await openTech(b); await wait('/Mosaic made it on/.test(document.querySelector("#proxy-setup-keymade-text")?.textContent ?? "") && document.querySelectorAll("#proxy-setup-history li").length === 4'); // The service key: when it was made, that renewal is not built, never the key. - assert.equal(await text('#proxy-setup-keymade dt'), 'Service key'); + // It is the last row of the state list, after Release and Service, as models-advanced shows it. + assert.equal(await b.evaluate('[...document.querySelectorAll("#proxy-setup-state dt")].at(-1).textContent'), 'Service key'); + assert.equal(await b.evaluate('document.querySelector("#proxy-setup-keymade-text").closest("dl").id'), 'proxy-setup-state'); const key = await text('#proxy-setup-keymade-text'); assert.match(key, /^Mosaic made it on .+\. You never see it\. Renewing it is not built yet\.$/); assert.equal(key.includes(await b.evaluate(`window.MosaicLocalTime(${JSON.stringify(T(3))})`)), true); @@ -137,7 +144,7 @@ test('settings-s5b: Technical details shows when the service key was made, the s assert.match(list[0].text, /^Account added in Acme Studio · .+ · by jason$/); assert.equal(list[1].text, 'Withheld. The Console kept this entry back because it may hold a secret.'); assert.equal(list[1].withheld, true); - assert.match(list[2].text, /^Set up · .+ · by someone whose name looked like an email address, so it is hidden$/); + assert.match(list[2].text, /^Set up · .+ · by someone whose name Mosaic hid$/); assert.match(list[3].text, /^Started · .+ · by jason$/); assert.equal(await text('#proxy-setup-history-all'), 'Show all'); assert.equal(await b.evaluate('document.querySelector("#proxy-setup-history-older").hidden'), true); @@ -155,8 +162,11 @@ test('settings-s5b: Technical details shows when the service key was made, the s }); test('settings-s5b: when setup stops, step 1 opens the service\'s last lines from the log read', { timeout: 90000 }, async t => { - const { b, wait, text, reads } = await setup(t, { service: SERVICE_FAILED }); - await wait('document.querySelector("#proxy-setup-go")?.textContent === "Try again" && document.querySelector("#proxy-setup-lines pre.setup-log")'); + const { b, wait, text, reads } = await setup(t, { service: SERVICE_START, admin: { ...OK, ...START_REFUSED } }); + await wait(READY + ' && document.querySelector("#proxy-setup-go") && !document.querySelector("#proxy-setup-go").hidden'); + await b.evaluate('document.querySelector("#proxy-setup-go").click(); true'); + await wait('document.querySelector("#proxy-setup-lines pre.setup-log")'); + assert.deepEqual(await b.evaluate('window.__writes.map(p => p.slice(p.indexOf("/proxy/admin/") + 13))'), ['unit/start']); assert.equal(await b.evaluate('document.querySelector("#proxy-setup-lines").hidden'), false); assert.equal(await b.evaluate('document.querySelector("#proxy-setup-lines").open'), true); assert.equal(await text('#proxy-setup-lines pre.setup-log'), LOG_OK.lines.join('\n')); @@ -164,7 +174,17 @@ test('settings-s5b: when setup stops, step 1 opens the service\'s last lines fro assert.doesNotMatch(await text('#proxy-setup-lines'), /can't read the service's lines yet|Nothing reported/); // The status read polls; the lines are read once, not on every paint. await new Promise(r => setTimeout(r, 1500)); - assert.deepEqual(await reads(), ['GET log?lines=20']); + assert.deepEqual(await reads(), ['POST unit/start', 'GET log?lines=20']); +}); + +test('settings-s5b: a service that is not installed has no lines, and step 1 says so plainly, not as a failed read', { timeout: 90000 }, async t => { + const { b, wait, text } = await setup(t, { service: SERVICE_FAILED, admin: { ...OK, [LOG]: { status: 503, body: { error: 'not-configured' } } } }); + await wait('document.querySelector("#proxy-setup-lines [data-log] p")'); + assert.equal(await b.evaluate('document.querySelector("#proxy-setup-lines").open'), true); + assert.equal(await text('#proxy-setup-lines [data-log] p'), 'The model service is not installed, so it has no lines yet.'); + assert.equal(await b.evaluate('document.querySelector("#proxy-setup-lines [data-log] p").className'), 'small muted'); + assert.equal(await b.evaluate('!!document.querySelector("#proxy-setup-lines .banner.err")'), false); + assert.doesNotMatch(await text('#proxy-setup-lines'), /could not be read/); }); test('settings-s5b: a service key that is not made yet, or that cannot be checked, says so', { timeout: 90000 }, async t => { @@ -187,7 +207,7 @@ test('settings-s5b: each failed read shows its line with Read again, and Read ag // The service key. await wait('document.querySelector("#proxy-setup-keymade-retry")'); assert.equal(await text('#proxy-setup-keymade-text'), 'When it was made could not be read. Model service setup is not available on this Console. (not-configured)'); - assert.equal(await b.evaluate('document.querySelector("#proxy-setup-keymade-text").classList.contains("err-line")'), true); + assert.equal(await b.evaluate('document.querySelector("#proxy-setup-keymade-text").className'), 'banner err', 'the same failure style as the history and the lines'); await b.evaluate('document.querySelector("#proxy-setup-keymade-retry").focus(); document.querySelector("#proxy-setup-keymade-retry").click(); true'); await wait('/Mosaic made it on/.test(document.querySelector("#proxy-setup-keymade-text")?.textContent ?? "")'); assert.equal(await b.evaluate('!!document.querySelector("#proxy-setup-keymade-retry")'), false); @@ -229,7 +249,8 @@ test('settings-s5b: a page that is not the instance owner\'s shows none of the t await new Promise(r => setTimeout(r, 800)); assert.deepEqual(await b.evaluate('window.__admin'), []); const shown = sel => b.evaluate(`(() => { const e = document.querySelector(${JSON.stringify(sel)}); return !!e && e.getClientRects().length > 0; })()`); - for (const sel of ['#proxy-setup-keymade', '#proxy-setup-keymade-text', '#proxy-setup-tech-lines', '#proxy-setup-lines', '#proxy-setup-history', '#proxy-setup-history-message', '#proxy-setup-history-all']) + assert.equal(await b.evaluate('[...document.querySelectorAll("#proxy-setup dt")].some(d => d.textContent === "Service key")'), false); + for (const sel of ['#proxy-setup-keymade-text', '#proxy-setup-keymade-retry', '#proxy-setup-tech-lines', '#proxy-setup-lines', '#proxy-setup-history', '#proxy-setup-history-message', '#proxy-setup-history-all']) assert.equal(await shown(sel), false, `${sel} is not shown`); assert.equal(await b.evaluate('document.querySelectorAll("[data-log] pre, [data-log] .banner, #proxy-setup-history li").length'), 0); }); @@ -284,8 +305,8 @@ test('settings-s5b: a history with no entries says so, and a first page that is await new Promise(r => setTimeout(r, 100)); await openTech(b); await wait('/no entries to show/.test(document.querySelector("#proxy-setup-history-message").textContent)'); - assert.equal(await b.evaluate('document.querySelector("#proxy-setup-history-all").hidden'), false); - await click('#proxy-setup-history-all'); + // Nothing is folded away, so there is no Show all, and Show older is offered at once. + assert.equal(await b.evaluate('document.querySelector("#proxy-setup-history-all").hidden'), true); assert.equal(await b.evaluate('document.querySelector("#proxy-setup-history-older").hidden'), false); await click('#proxy-setup-history-older'); await wait('document.querySelectorAll("#proxy-setup-history li").length === 1'); @@ -293,6 +314,61 @@ test('settings-s5b: a history with no entries says so, and a first page that is assert.equal(await text('#proxy-setup-history-message'), ''); }); +test('settings-s5b: a short first page offers Show older at once, and what it reads stays open', { timeout: 90000 }, async t => { + const e = (op, n) => ({ op, time: T(n), user: 'jason' }); + const { b, wait, click } = await setup(t, { admin: { ...OK, 'history?limit=25': { entries: [e('unit.start', 8), e('unit.stop', 9)], next: 7 }, 'history?limit=25&before=7': { entries: [e('init', 4), e('unit.install', 5), e('unit.restart', 6)], next: null } } }); + await wait(READY); await openTech(b); + await wait('document.querySelectorAll("#proxy-setup-history li").length === 2'); + assert.equal(await b.evaluate('document.querySelector("#proxy-setup-history-all").hidden'), true); + assert.equal(await b.evaluate('document.querySelector("#proxy-setup-history-older").hidden'), false); + await click('#proxy-setup-history-older'); + await wait('document.querySelectorAll("#proxy-setup-history li").length === 5'); + assert.deepEqual((await items(b)).map(i => i.hidden), [false, false, false, false, false], 'the older entries it read are shown'); + assert.equal(await b.evaluate('document.querySelector("#proxy-setup-history-all").textContent'), 'Show fewer'); +}); + +test('settings-s5b: an older page that is not further back than the one asked for is not shown', { timeout: 90000 }, async t => { + const { b, wait, text, click } = await setup(t, { admin: { ...OK, 'history?limit=25&before=3': { entries: [{ op: 'init', time: T(2), user: 'jason' }], next: 3 } } }); + await wait(READY); await openTech(b); + await wait('document.querySelectorAll("#proxy-setup-history li").length === 4'); + await click('#proxy-setup-history-all'); + await b.evaluate('document.querySelector("#proxy-setup-history-older").focus(); document.querySelector("#proxy-setup-history-older").click(); true'); + await wait('!document.querySelector("#proxy-setup-history-retry").hidden'); + assert.match(await text('#proxy-setup-history-message'), /^History could not be read\./); + assert.equal(await b.evaluate('document.querySelectorAll("#proxy-setup-history li").length'), 4, 'the repeated page adds nothing'); + // The pressed button went away, so focus lands on Read again. + assert.equal(await b.evaluate('document.activeElement?.id'), 'proxy-setup-history-retry'); +}); + +test('settings-s5b: a history answer from before Technical details was closed and opened again is dropped', { timeout: 90000 }, async t => { + const STALE = { entries: [{ op: 'init', time: T(1), user: 'stale' }], next: null }; + const { b, wait } = await setup(t, { admin: { ...OK, 'history?limit=25': [PAGE1, STALE] } }); + await wait(READY); + await b.evaluate('window.__queue["history?limit=25"] = []; true'); + await openTech(b); + await wait('window.__queue["history?limit=25"].length === 1'); + await b.evaluate('document.querySelector("#proxy-setup-tech").open = false; true'); + await new Promise(r => setTimeout(r, 100)); + await openTech(b); + await wait('window.__queue["history?limit=25"].length === 2'); + // The newer read answers first, then the older one. + await b.evaluate('window.__queue["history?limit=25"][1](); true'); + await wait('document.querySelectorAll("#proxy-setup-history li").length === 4'); + await b.evaluate('window.__queue["history?limit=25"][0](); true'); + await new Promise(r => setTimeout(r, 500)); + const list = await items(b); + assert.equal(list.length, 4); + assert.equal(list.some(i => /stale/.test(i.text)), false, 'the older answer is not painted'); + assert.equal(new Set(list.map(i => i.text)).size, 4, 'one copy of each entry'); +}); + +test('settings-s5b: a history entry whose action is not a known one reads Other setup action', { timeout: 90000 }, async t => { + const { b, wait } = await setup(t, { admin: { ...OK, 'history?limit=25': { entries: [{ op: 'toString', time: T(1), user: 'jason' }, { op: 'constructor', time: T(2), user: 'jason' }, { op: 'something.new', time: T(3), user: 'jason' }], next: null } } }); + await wait(READY); await openTech(b); + await wait('document.querySelectorAll("#proxy-setup-history li").length === 3'); + for (const item of await items(b)) assert.match(item.text, /^Other setup action · .+ · by jason$/); +}); + test('settings-s5b: a withheld entry shows as withheld and nothing else from it', { timeout: 90000 }, async t => { const { b, wait } = await setup(t, { admin: { ...OK, 'history?limit=25': { entries: [{ withheld: true, op: 'init', time: T(2), user: 'jason', org: 'acme' }, { withheld: true }], next: null } } }); await wait(READY); await openTech(b); @@ -377,7 +453,9 @@ test('shots', { timeout: 900000, skip: !process.env.MOSAIC_UX_SHOTS }, async t = const settle = () => new Promise(r => setTimeout(r, 1000)); const fail = { status: 503, body: { error: 'outcome-unknown' } }; const SHOTS = [ - { name: 'setup-failed-lines', options: { service: SERVICE_FAILED }, ready: 'document.querySelector("#proxy-setup-lines pre.setup-log")' }, + { name: 'setup-start-failed', options: { service: SERVICE_START, admin: { ...OK, ...START_REFUSED } }, ready: READY + ' && document.querySelector("#proxy-setup-go") && !document.querySelector("#proxy-setup-go").hidden', + after: async (b, wait) => { await b.evaluate('document.querySelector("#proxy-setup-go").click(); true'); await wait('document.querySelector("#proxy-setup-lines pre.setup-log")'); } }, + { name: 'setup-failed-no-lines', options: { service: SERVICE_FAILED, admin: { ...OK, [LOG]: { status: 503, body: { error: 'not-configured' } } } }, ready: 'document.querySelector("#proxy-setup-lines [data-log] p")' }, { name: 'technical-details', ready: READY, after: async (b, wait) => { await b.evaluate('document.querySelector("#proxy-setup-tech").open = true; true'); await wait('document.querySelectorAll("#proxy-setup-history li").length === 4 && /Mosaic made it/.test(document.querySelector("#proxy-setup-keymade-text").textContent)'); } },