|
|
|
@@ -0,0 +1,515 @@
|
|
|
|
|
// #1873 settings-s5c (DESIGN.md, mockup models-advanced): Model setup, Advanced, lists the installed
|
|
|
|
|
// programs from the status read's programs field and which organizations have each one on; one
|
|
|
|
|
// program can be turned off in every organization (POST /api/proxy/admin/programs/off), and the page
|
|
|
|
|
// words each organization's outcome. Technical details reads access health per organization
|
|
|
|
|
// (GET /api/proxy/admin/access) when it opens. All of it is the instance owner's: a page without
|
|
|
|
|
// proxyAdmin shows none of it and sends no /api/proxy/admin/ request.
|
|
|
|
|
import { test } from 'node:test';
|
|
|
|
|
import assert from 'node:assert/strict';
|
|
|
|
|
import { fileURLToPath } from 'node:url';
|
|
|
|
|
import { startServer } from '../src/serve.mjs';
|
|
|
|
|
import { createDevOwner } from '../src/dev-owner.mjs';
|
|
|
|
|
import { browser } from './browser.mjs';
|
|
|
|
|
import { close } from './fixture.mjs';
|
|
|
|
|
|
|
|
|
|
const LIST = [
|
|
|
|
|
{ id: 'acme', label: 'Acme Studio', theme: 'cobalt', busHealthy: true },
|
|
|
|
|
{ id: 'gamma', label: 'Gamma Home', theme: 'rosewood', busHealthy: true },
|
|
|
|
|
{ id: 'lab', label: 'Lab Bench', theme: 'cobalt', busHealthy: true },
|
|
|
|
|
];
|
|
|
|
|
const VIEW = {
|
|
|
|
|
business: 'acme', revision: 'a'.repeat(64), harnesses: ['pi'], models: ['fixture-deterministic'],
|
|
|
|
|
providerModels: { 'fixture-deterministic': { module: 'fixture', upstream: 'fixture', model: 'fixture-deterministic' } },
|
|
|
|
|
levels: { pi: ['off', 'low'] }, instances: {}, catalogue: { status: 'ready', observedAt: new Date().toISOString(), models: [], notices: [] },
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
async function orgFixture() {
|
|
|
|
|
const { checkRootAgents } = await import('../../organization/src/index.mjs');
|
|
|
|
|
const rolesDir = fileURLToPath(new URL('../../../roles', import.meta.url));
|
|
|
|
|
const root = { state: 'ok', ...checkRootAgents({ agentsVersion: 1, agents: {} }, { rolesDir }) };
|
|
|
|
|
const empty = () => Promise.resolve([]);
|
|
|
|
|
const member = org => ({
|
|
|
|
|
id: org.id, doc: { appearance: { theme: org.theme }, roles: { chief: { definition: 'chief-of-staff' } }, projects: {} },
|
|
|
|
|
status: async () => ({ healthy: true, pid: 4242, boot: null }),
|
|
|
|
|
options: () => ({ bus: { inbox: empty, agents: empty, 'thread.claims': empty, tasks: empty, usage: () => Promise.resolve({}), limits: () => Promise.resolve({}), decisions: empty }, chat: { threads: empty, projects: empty } }),
|
|
|
|
|
});
|
|
|
|
|
const organizations = {
|
|
|
|
|
list: async () => LIST,
|
|
|
|
|
members: async () => LIST.map(member),
|
|
|
|
|
resolve: async id => {
|
|
|
|
|
const org = LIST.find(o => o.id === id); if (!org) return null;
|
|
|
|
|
return {
|
|
|
|
|
busHealthy: true,
|
|
|
|
|
reads: { business: async () => ({ business: { id, human: 'jason', projects: [], appearance: { theme: org.theme } } }), settings: async () => ({ business: id, release: 'fixture', notifier: {} }), queue: async () => ({ rows: [] }), busStatus: async () => ({}) },
|
|
|
|
|
bus: { messages: async () => ({ messages: [], unread: 0, total: 0 }), agents: empty, 'thread.claims': empty, inbox: empty, tasks: empty, usage: async () => ({}), routes: async () => ({ ...VIEW, business: id }), instances: async () => ({ business: id, revision: 'a'.repeat(64), launch: true, noHire: [], retired: [], definitions: {}, instances: {} }) },
|
|
|
|
|
chat: { projects: empty, threads: empty },
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
return { organizations, agentLevels: { loadRoot: () => root, rolesDir, ctx: { configDir: '/cfg', dataRoot: '/data', instance: 'test' } } };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Program names are the read's, not a list the page holds: one of them is made up.
|
|
|
|
|
const PROGRAMS = { installed: ['pi', 'zeta-runner'], organizations: [{ id: 'acme', on: ['pi', 'zeta-runner'] }, { id: 'gamma', on: null }, { id: 'lab', on: ['pi'] }] };
|
|
|
|
|
const SERVICE_UP = { next: ['accounts'], init: { initialized: true, partial: false, problem: null, settings: { port: 18432, rotateGraceMinutes: 30, firstOutputSeconds: 90 }, 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, healthy: true }, fence: { set: false }, initLock: { present: false, blockers: [] }, fetch: { state: 'idle' },
|
|
|
|
|
organizations: [], ride: [], programs: PROGRAMS };
|
|
|
|
|
const AFTER = { ...SERVICE_UP, programs: { ...PROGRAMS, organizations: [{ id: 'acme', on: ['pi'] }, { id: 'gamma', on: null }, { id: 'lab', on: ['pi'] }] } };
|
|
|
|
|
const ACCESS = { organizations: [
|
|
|
|
|
{ id: 'acme', health: 'ok', keys: [{ keyId: 'kid-AAAA1111', agent: 'chief', state: 'active', issuedAt: null }], other: 4242, sentinel: 1 },
|
|
|
|
|
{ id: 'gamma', health: 'attention', reason: 'proxy-uncertain', keys: [] },
|
|
|
|
|
{ id: 'lab', health: 'attention', keys: [{ keyId: 'kid-BBBB2222', agent: 'chief', state: 'active', issuedAt: null }, { keyId: 'kid-CCCC3333', agent: 'writer', state: 'expired', issuedAt: null }], other: 4242 },
|
|
|
|
|
{ id: 'north', health: 'missing', keys: [], other: 4242 },
|
|
|
|
|
{ id: 'south', health: 'not-riding', keys: [] },
|
|
|
|
|
{ id: 'east', health: 'unreadable', reason: 'bus-down', keys: [] },
|
|
|
|
|
{ id: 'west', health: 'unreadable', reason: 'no-proxy-client', keys: [] },
|
|
|
|
|
{ id: 'up', health: 'unreadable', reason: 'unreadable', keys: [] },
|
|
|
|
|
{ id: 'down', keys: [{ keyId: 'kid-DDDD4444', agent: 'chief', state: 'active', issuedAt: null }] },
|
|
|
|
|
{ id: 'left', health: 'ok', reason: 'proxy-uncertain', keys: [{ keyId: 'kid-EEEE5555', agent: 'chief', state: 'active', issuedAt: null }] },
|
|
|
|
|
{ id: 'right', health: 'ok', keys: [] },
|
|
|
|
|
{ id: 'top', health: 'great', keys: [] },
|
|
|
|
|
] };
|
|
|
|
|
|
|
|
|
|
// The owner's flags (or not), the status (a list: each read takes the next one and the last one stays),
|
|
|
|
|
// and the admin reads and writes by name. window.__admin records every /api/proxy/admin/ request,
|
|
|
|
|
// window.__writes every write anywhere under /proxy/.
|
|
|
|
|
const stub = ({ owner = true, status = SERVICE_UP, admin = {} } = {}) => `(() => {
|
|
|
|
|
const real = window.fetch.bind(window);
|
|
|
|
|
window.__s5c = ${JSON.stringify({ owner, status: Array.isArray(status) ? status : [status], admin })}; window.__admin = []; window.__writes = [];
|
|
|
|
|
const json = (body, status = 200) => new Response(JSON.stringify(body), { status, headers: { 'content-type': 'application/json' } });
|
|
|
|
|
const next = list => Array.isArray(list) ? (list.length > 1 ? list.shift() : list[0]) : list;
|
|
|
|
|
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, body: init.body ?? null });
|
|
|
|
|
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');
|
|
|
|
|
return a.status ? json(a.body, a.status) : json(a);
|
|
|
|
|
}
|
|
|
|
|
if (method !== 'GET' && /\\/proxy\\//.test(path)) { window.__writes.push({ path, body: init.body ?? null }); return json({ error: 'stub' }, 500); }
|
|
|
|
|
if (method !== 'GET') return real(input, init);
|
|
|
|
|
if (/\\/api\\/(orgs\\/[^/]+\\/)?config$/.test(path)) { const c = await (await real(input, init)).json(); return json({ ...c, orgSetup: true, proxyAdmin: __s5c.owner, proxyAdminSend: __s5c.owner }); }
|
|
|
|
|
if (path.endsWith('/proxy/plugins')) return json({ revision: 'b'.repeat(64), available: { harness: ['pi'], 'model-provider': ['fixture', 'cliproxy'] }, plugins: { harness: ['pi'], 'model-provider': ['fixture'] } });
|
|
|
|
|
if (path.endsWith('/proxy/accounts')) return json({ accounts: [] });
|
|
|
|
|
if (path.endsWith('/proxy/keys')) return json({ keys: [] });
|
|
|
|
|
if (path.endsWith('/triage/route')) return json({ route: null });
|
|
|
|
|
return real(input, init);
|
|
|
|
|
};
|
|
|
|
|
})();`;
|
|
|
|
|
|
|
|
|
|
async function setup(t, { path = '/#/settings/model-setup', viewport = [1440, 900], ...options } = {}) {
|
|
|
|
|
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: stub(options) });
|
|
|
|
|
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)})()`);
|
|
|
|
|
const text = sel => b.evaluate(`document.querySelector(${JSON.stringify(sel)})?.textContent ?? null`);
|
|
|
|
|
const click = sel => b.evaluate(`(() => { const el = document.querySelector(${JSON.stringify(sel)}); if (!el) throw Error("no ${sel.replace(/"/g, '')}"); el.click(); return true; })()`);
|
|
|
|
|
const admin = () => b.evaluate('window.__admin');
|
|
|
|
|
return { b, wait, text, click, admin };
|
|
|
|
|
}
|
|
|
|
|
const READY = 'document.querySelector("#proxy-setup-state dd") && !document.querySelector("#setup-step-service").hidden && !document.querySelector("#proxy-setup-advanced").hidden';
|
|
|
|
|
const openAdvanced = b => b.evaluate('(() => { document.querySelector("#proxy-setup-advanced").open = true; return true; })()');
|
|
|
|
|
const openTech = b => b.evaluate('(() => { document.querySelector("#proxy-setup-tech").open = true; return true; })()');
|
|
|
|
|
const programs = b => b.evaluate('[...document.querySelectorAll("#proxy-setup-programs > li")].map(li => ({ name: li.dataset.program ?? null, text: li.querySelector(".proxy-program-orgs")?.textContent ?? li.textContent }))');
|
|
|
|
|
const outcomes = b => b.evaluate('[...document.querySelectorAll("#proxy-setup-programs-result li")].map(li => li.textContent)');
|
|
|
|
|
const access = b => b.evaluate('[...document.querySelectorAll("#proxy-setup-access li")].map(li => ({ text: li.textContent, ready: li.dataset.access }))');
|
|
|
|
|
const KEY_TEXT = /ms[kotp]-[A-Za-z0-9_-]{4,}/i;
|
|
|
|
|
// Technical details' other reads, so a shot shows them as they read.
|
|
|
|
|
const T = n => new Date(Date.UTC(2026, 10, 19, 9, n)).toISOString();
|
|
|
|
|
const TECH = { 'service-key': { madeAt: T(3), renewedAt: null, renewal: 'not-built', problem: null }, 'history?limit=25': { entries: [{ op: 'unit.start', time: T(4), user: 'jason' }, { op: 'init', time: T(2), user: 'jason' }], next: null } };
|
|
|
|
|
const OFF_PI = { name: 'pi', results: [{ id: 'acme', outcome: 'in-use' }, { id: 'gamma', outcome: 'bus-down' }, { id: 'lab', outcome: 'last-program' }], receipt: null };
|
|
|
|
|
|
|
|
|
|
// ---- The list -------------------------------------------------------------------------------
|
|
|
|
|
test('settings-s5c: Advanced lists the installed programs from the status read and which organizations have each one on, by display name', { timeout: 90000 }, async t => {
|
|
|
|
|
const { b, wait, admin } = await setup(t);
|
|
|
|
|
await wait(READY); await openAdvanced(b);
|
|
|
|
|
await wait('document.querySelectorAll("#proxy-setup-programs > li[data-program]").length === 2');
|
|
|
|
|
assert.deepEqual(await programs(b), [
|
|
|
|
|
{ name: 'pi', text: 'On in Acme Studio and Lab Bench. Not known in Gamma Home: its list could not be read.' },
|
|
|
|
|
{ name: 'zeta-runner', text: 'On in Acme Studio. Off in Lab Bench. Not known in Gamma Home: its list could not be read.' },
|
|
|
|
|
]);
|
|
|
|
|
assert.deepEqual(await b.evaluate('[...document.querySelectorAll("#proxy-setup-programs .proxy-program-name")].map(n => n.textContent)'), ['pi', 'zeta-runner']);
|
|
|
|
|
assert.deepEqual(await b.evaluate('[...document.querySelectorAll("[data-program-off]")].map(n => n.getAttribute("aria-label"))'), ['Turn off pi for every organization', 'Turn off zeta-runner for every organization']);
|
|
|
|
|
assert.doesNotMatch(await b.evaluate('document.querySelector("#proxy-setup-advanced").textContent'), /Turning a program off for every organization is not built/);
|
|
|
|
|
// Opening Advanced reads nothing more: the list is the status read's.
|
|
|
|
|
assert.deepEqual((await admin()).filter(r => r !== 'GET status'), []);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('settings-s5c: a null list reads as not known, never off; a list the read could not give says so', { timeout: 90000 }, async t => {
|
|
|
|
|
{
|
|
|
|
|
const status = { ...SERVICE_UP, programs: { installed: ['pi'], organizations: [{ id: 'gamma', on: null }, { id: 'acme', on: ['pi'] }] } };
|
|
|
|
|
const { b, wait } = await setup(t, { status });
|
|
|
|
|
await wait(READY); await openAdvanced(b);
|
|
|
|
|
await wait('document.querySelector("#proxy-setup-programs > li[data-program]")');
|
|
|
|
|
const [pi] = await programs(b);
|
|
|
|
|
assert.equal(pi.text, 'On in Acme Studio. Not known in Gamma Home: its list could not be read.');
|
|
|
|
|
assert.doesNotMatch(pi.text, /Off in/);
|
|
|
|
|
}
|
|
|
|
|
for (const [programsField, line] of [
|
|
|
|
|
[{ installed: ['pi'], organizations: null }, 'Which organizations have it on could not be read.'],
|
|
|
|
|
[{ installed: null, organizations: [] }, 'The installed programs could not be read.'],
|
|
|
|
|
[undefined, 'The programs could not be read.'],
|
|
|
|
|
[{ installed: [], organizations: [] }, 'No programs are installed.'],
|
|
|
|
|
]) {
|
|
|
|
|
const { b, wait } = await setup(t, { status: { ...SERVICE_UP, programs: programsField } });
|
|
|
|
|
await wait(READY); await openAdvanced(b);
|
|
|
|
|
await wait(`document.querySelector("#proxy-setup-programs")?.textContent.includes(${JSON.stringify(line)})`);
|
|
|
|
|
assert.doesNotMatch(await b.evaluate('document.querySelector("#proxy-setup-programs").textContent'), /Off in|On in no/);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// ---- Turn off for every organization ----------------------------------------------------------
|
|
|
|
|
test('settings-s5c: the confirm names the program, and Cancel sends nothing', { timeout: 90000 }, async t => {
|
|
|
|
|
const { b, wait, text, click, admin } = await setup(t, { admin: { 'POST programs/off': OFF_PI } });
|
|
|
|
|
await wait(READY); await openAdvanced(b);
|
|
|
|
|
await wait('document.querySelector("[data-program-off=pi]")');
|
|
|
|
|
await click('[data-program-off=pi]');
|
|
|
|
|
await wait('document.querySelector("#proxy-setup-programs-yes")');
|
|
|
|
|
assert.match(await text('#proxy-setup-programs-ask'), /^Turn off pi in every organization\?/);
|
|
|
|
|
assert.equal(await text('#proxy-setup-programs-yes'), 'Turn off pi');
|
|
|
|
|
assert.equal(await b.evaluate('document.querySelector("#proxy-setup-programs-yes").closest("li").dataset.program'), 'pi');
|
|
|
|
|
assert.equal(await b.evaluate('document.activeElement?.id'), 'proxy-setup-programs-yes');
|
|
|
|
|
await click('#proxy-setup-programs-no');
|
|
|
|
|
await wait('!document.querySelector("#proxy-setup-programs-yes")');
|
|
|
|
|
await new Promise(r => setTimeout(r, 300));
|
|
|
|
|
assert.deepEqual(await b.evaluate('window.__writes'), []);
|
|
|
|
|
assert.deepEqual((await admin()).filter(r => r !== 'GET status'), []);
|
|
|
|
|
assert.equal(await b.evaluate('document.activeElement?.dataset.programOff'), 'pi', 'focus goes back to the button');
|
|
|
|
|
// Confirming sends the one name.
|
|
|
|
|
await click('[data-program-off=pi]'); await wait('document.querySelector("#proxy-setup-programs-yes")');
|
|
|
|
|
await click('#proxy-setup-programs-yes');
|
|
|
|
|
await wait('document.querySelectorAll("#proxy-setup-programs-result li").length === 3');
|
|
|
|
|
assert.deepEqual(await b.evaluate('window.__writes.map(w => [w.path.replace(/^.*(\\/proxy\\/admin\\/)/, "$1"), JSON.parse(w.body)])'), [['/proxy/admin/programs/off', { name: 'pi' }]]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('settings-s5c: each outcome id renders its line, by display name', { timeout: 90000 }, async t => {
|
|
|
|
|
const results = [
|
|
|
|
|
{ id: 'acme', outcome: 'off' }, { id: 'gamma', outcome: 'already-off' }, { id: 'lab', outcome: 'in-use' },
|
|
|
|
|
{ id: 'o4', outcome: 'last-program' }, { id: 'o5', outcome: 'bus-down' }, { id: 'o6', outcome: 'unreadable' },
|
|
|
|
|
{ id: 'o7', outcome: 'failed:revision-conflict' }, { id: 'o8', outcome: 'failed:outcome-unknown' }, { id: 'o9', outcome: 'failed:plugins-refused' },
|
|
|
|
|
{ id: 'o10', outcome: 'sideways' }, { id: 'o11' },
|
|
|
|
|
];
|
|
|
|
|
const { b, wait, click } = await setup(t, { admin: { 'POST programs/off': { name: 'zeta-runner', results, receipt: null } } });
|
|
|
|
|
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")'); await click('#proxy-setup-programs-yes');
|
|
|
|
|
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.',
|
|
|
|
|
'Lab Bench: Kept on. Something there still uses it: a role route, a fallback or an agent.',
|
|
|
|
|
'o4: Kept on. It is the only program on there.',
|
|
|
|
|
'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.',
|
|
|
|
|
'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.',
|
|
|
|
|
]);
|
|
|
|
|
// bus-down does not say the organization is stopped.
|
|
|
|
|
assert.doesNotMatch(lines[4], /stop|not running|down/i);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('settings-s5c: busy and a failed request each render a plain line, and the status is read again after each', { timeout: 90000 }, async t => {
|
|
|
|
|
const answers = [
|
|
|
|
|
{ status: 409, body: { error: 'proxy-admin-busy' } },
|
|
|
|
|
{ status: 500, body: { error: 'outcome-unknown' } },
|
|
|
|
|
{ status: 400, body: { error: 'invalid-request' } },
|
|
|
|
|
{ throws: true },
|
|
|
|
|
];
|
|
|
|
|
const { b, wait, click, admin } = await setup(t, { admin: { 'POST programs/off': answers } });
|
|
|
|
|
await wait(READY); await openAdvanced(b);
|
|
|
|
|
const lines = [];
|
|
|
|
|
for (let i = 0; i < answers.length; i++) {
|
|
|
|
|
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") && /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.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.'],
|
|
|
|
|
]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('settings-s5c: after an off the page reads the status again and shows the new list; focus goes to the result', { timeout: 90000 }, async t => {
|
|
|
|
|
const { b, wait, click, admin } = await setup(t, { status: [SERVICE_UP, SERVICE_UP, AFTER], admin: { 'POST programs/off': { name: 'zeta-runner', results: [{ id: 'acme', outcome: 'off' }, { id: 'gamma', outcome: 'bus-down' }, { id: 'lab', outcome: 'already-off' }], 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 click('[data-program-off=zeta-runner]'); await wait('document.querySelector("#proxy-setup-programs-yes")');
|
|
|
|
|
await b.evaluate('document.querySelector("#proxy-setup-programs-yes").focus(); document.querySelector("#proxy-setup-programs-yes").click(); true');
|
|
|
|
|
await wait('document.querySelectorAll("#proxy-setup-programs-result li").length === 3');
|
|
|
|
|
await wait(`window.__admin.filter(r => r === "GET status").length > ${before}`);
|
|
|
|
|
const order = await admin();
|
|
|
|
|
assert.ok(order.lastIndexOf('GET status') > order.indexOf('POST programs/off'), JSON.stringify(order));
|
|
|
|
|
await wait('document.querySelector("li[data-program=zeta-runner] .proxy-program-orgs")?.textContent.startsWith("On in no organization.")');
|
|
|
|
|
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.');
|
|
|
|
|
await new Promise(r => setTimeout(r, 300));
|
|
|
|
|
assert.equal(await b.evaluate('document.activeElement?.id'), 'proxy-setup-programs-result');
|
|
|
|
|
assert.equal(await b.evaluate('document.querySelector("#proxy-setup-programs-result").tabIndex'), -1);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('settings-s5c: focus goes to the result after a busy answer too', { timeout: 90000 }, async t => {
|
|
|
|
|
const { b, wait, click } = await setup(t, { admin: { 'POST programs/off': { status: 409, body: { error: 'proxy-admin-busy' } } } });
|
|
|
|
|
await wait(READY); await openAdvanced(b);
|
|
|
|
|
await wait('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('/was not turned off/.test(document.querySelector("#proxy-setup-programs-result").textContent)');
|
|
|
|
|
await new Promise(r => setTimeout(r, 300));
|
|
|
|
|
assert.equal(await b.evaluate('document.activeElement?.id'), 'proxy-setup-programs-result');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
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: '<html><body>Gateway</body></html>' }]) {
|
|
|
|
|
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 } });
|
|
|
|
|
await wait(READY);
|
|
|
|
|
await new Promise(r => setTimeout(r, 300));
|
|
|
|
|
assert.equal((await admin()).includes('GET access'), false, 'access is not read before Technical details opens');
|
|
|
|
|
await openTech(b);
|
|
|
|
|
await wait(`document.querySelectorAll("#proxy-setup-access li").length === ${ACCESS.organizations.length}`);
|
|
|
|
|
assert.equal((await admin()).filter(r => r === 'GET access').length, 1);
|
|
|
|
|
assert.deepEqual(await access(b), [
|
|
|
|
|
{ text: 'Acme StudioReady', ready: 'ready' },
|
|
|
|
|
{ text: 'Gamma HomeNot sureThe model service did not answer clearly, so Mosaic can\'t tell whether its access works.', ready: 'not-ready' },
|
|
|
|
|
{ text: 'Lab BenchNeeds attentionSome of its access is not active.', ready: 'not-ready' },
|
|
|
|
|
{ text: 'northNone yetNo agent here has access to your models yet.', ready: 'not-ready' },
|
|
|
|
|
{ text: 'southNot usedIt does not use your models.', ready: 'not-ready' },
|
|
|
|
|
{ text: 'eastCould not be readIts bus did not answer.', ready: 'not-ready' },
|
|
|
|
|
{ text: 'westCould not be readIts bus has no model service client set up.', ready: 'not-ready' },
|
|
|
|
|
{ text: 'upCould not be readIts answer about access could not be read.', ready: 'not-ready' },
|
|
|
|
|
{ text: 'downNot knownThe answer did not say.', ready: 'not-ready' },
|
|
|
|
|
{ text: 'leftNot knownThe answer did not agree with itself.', ready: 'not-ready' },
|
|
|
|
|
{ text: 'rightNot knownThe answer did not agree with itself.', ready: 'not-ready' },
|
|
|
|
|
{ text: 'topNot knownThe answer did not say.', ready: 'not-ready' },
|
|
|
|
|
]);
|
|
|
|
|
const shown = await b.evaluate('document.querySelector(".proxy-setup-access").textContent');
|
|
|
|
|
assert.equal((shown.match(/Ready/g) ?? []).length, 1);
|
|
|
|
|
assert.doesNotMatch(shown, /kid-|4242|sentinel|chief|writer|expired/);
|
|
|
|
|
assert.doesNotMatch(await b.evaluate('document.querySelector(".proxy-setup-access").textContent'), /bus is (stopped|down)|stopped/i);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('settings-s5c: a failed access read shows a plain line with Read again, and Read again reads it', { timeout: 90000 }, async t => {
|
|
|
|
|
const { b, wait, text, admin } = await setup(t, { admin: { access: [{ status: 503, body: { error: 'outcome-unknown' } }, { status: 200, body: { organizations: 'nope' } }, ACCESS] } });
|
|
|
|
|
await wait(READY); await openTech(b);
|
|
|
|
|
await wait('!document.querySelector("#proxy-setup-access-retry").hidden');
|
|
|
|
|
assert.equal(await text('#proxy-setup-access-message'), 'Access could not be read. The host could not read access. (outcome-unknown)');
|
|
|
|
|
assert.equal(await b.evaluate('document.querySelector("#proxy-setup-access-message").className'), 'banner err');
|
|
|
|
|
assert.equal(await b.evaluate('document.querySelectorAll("#proxy-setup-access li").length'), 0);
|
|
|
|
|
await b.evaluate('document.querySelector("#proxy-setup-access-retry").focus(); document.querySelector("#proxy-setup-access-retry").click(); true');
|
|
|
|
|
await wait('window.__admin.filter(r => r === "GET access").length === 2'); await new Promise(r => setTimeout(r, 400));
|
|
|
|
|
assert.equal(await b.evaluate('document.querySelector("#proxy-setup-access-retry").hidden'), false);
|
|
|
|
|
assert.equal(await text('#proxy-setup-access-message'), 'Access could not be read. The host could not read access. (outcome-unknown)');
|
|
|
|
|
assert.equal(await b.evaluate('document.querySelectorAll("#proxy-setup-access li").length'), 0, 'a shape the page does not know never reads as Ready');
|
|
|
|
|
assert.equal(await b.evaluate('document.activeElement?.id'), 'proxy-setup-access-retry');
|
|
|
|
|
await b.evaluate('document.querySelector("#proxy-setup-access-retry").focus(); document.querySelector("#proxy-setup-access-retry").click(); true');
|
|
|
|
|
await wait(`document.querySelectorAll("#proxy-setup-access li").length === ${ACCESS.organizations.length}`);
|
|
|
|
|
assert.equal(await b.evaluate('document.querySelector("#proxy-setup-access-retry").hidden'), true);
|
|
|
|
|
assert.equal(await b.evaluate('document.activeElement?.id'), 'proxy-setup-access-title', 'focus lands on the answer');
|
|
|
|
|
assert.equal((await admin()).filter(r => r === 'GET access').length, 3);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// ---- Owner only ------------------------------------------------------------------------------
|
|
|
|
|
test('settings-s5c: a page that is not the instance owner\'s shows none of it and sends no request to programs or access', { timeout: 90000 }, async t => {
|
|
|
|
|
// The owner's page, as the control.
|
|
|
|
|
{
|
|
|
|
|
const { b, wait } = await setup(t, { admin: { access: ACCESS } });
|
|
|
|
|
await wait(READY); await openAdvanced(b); await openTech(b);
|
|
|
|
|
await wait(`document.querySelectorAll("[data-program-off]").length === 2 && document.querySelectorAll("#proxy-setup-access li").length === ${ACCESS.organizations.length}`);
|
|
|
|
|
}
|
|
|
|
|
const { b, wait } = await setup(t, { owner: false, admin: { access: ACCESS, 'POST programs/off': OFF_PI } });
|
|
|
|
|
await wait('window.MosaicProxy && document.querySelector("#proxy-setup") && document.querySelector("#settings-page-title")');
|
|
|
|
|
await new Promise(r => setTimeout(r, 800));
|
|
|
|
|
await b.evaluate('document.querySelectorAll("#proxy-setup details").forEach(d => { d.open = true; }); true');
|
|
|
|
|
await new Promise(r => setTimeout(r, 800));
|
|
|
|
|
const sent = await b.evaluate('window.__admin');
|
|
|
|
|
assert.deepEqual(sent, []);
|
|
|
|
|
assert.equal(sent.some(r => /programs|access/.test(r)), false);
|
|
|
|
|
const shown = sel => b.evaluate(`(() => { const e = document.querySelector(${JSON.stringify(sel)}); return !!e && e.getClientRects().length > 0; })()`);
|
|
|
|
|
for (const sel of ['#proxy-setup-programs', '#proxy-setup-programs-result', '#proxy-setup-access', '#proxy-setup-access-message', '#proxy-setup-access-retry', '.proxy-setup-access'])
|
|
|
|
|
assert.equal(await shown(sel), false, `${sel} is not shown`);
|
|
|
|
|
assert.equal(await b.evaluate('document.querySelectorAll("[data-program-off], #proxy-setup-access li").length'), 0);
|
|
|
|
|
assert.doesNotMatch(await b.evaluate('document.body.innerText'), /Turn off for every organization|Programs that drive models|Access/);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// ---- No key text -----------------------------------------------------------------------------
|
|
|
|
|
test('settings-s5c: no key text reaches the page, even from a fixture answer that holds it in an unexpected field', { timeout: 90000 }, async t => {
|
|
|
|
|
const K = s => `${s}-abcdefghijklmnop`;
|
|
|
|
|
const status = { ...SERVICE_UP, programs: { installed: ['pi', K('msk')], organizations: [{ id: 'acme', on: ['pi', K('msk')] }, { id: K('mso'), on: ['pi'] }] } };
|
|
|
|
|
const off = { name: 'pi', receipt: { time: 'x', op: 'programs.off', name: K('mst'), results: [] }, results: [{ id: K('msp'), outcome: 'off' }, { id: 'acme', outcome: `failed:${K('msk')}` }, { id: 'gamma', outcome: K('mso') }] };
|
|
|
|
|
const accessAnswer = { organizations: [
|
|
|
|
|
{ id: K('msk'), health: 'ok', keys: [{ keyId: K('msk'), agent: K('msp'), state: 'active', issuedAt: null }] },
|
|
|
|
|
{ id: 'acme', health: K('mso'), reason: K('mst'), keys: [], other: 3 },
|
|
|
|
|
{ id: 'gamma', health: 'unreadable', reason: K('msk'), keys: [{ keyId: K('mst') }] },
|
|
|
|
|
] };
|
|
|
|
|
const { b, wait, click } = await setup(t, { status, admin: { access: accessAnswer, 'POST programs/off': off } });
|
|
|
|
|
await wait(READY); await openAdvanced(b); await openTech(b);
|
|
|
|
|
await wait('document.querySelectorAll("#proxy-setup-access li").length === 3 && 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('document.querySelectorAll("#proxy-setup-programs-result li").length === 3');
|
|
|
|
|
const page = await b.evaluate('document.querySelector("#proxy-setup").textContent + "\\n" + document.body.innerText + "\\n" + [...document.querySelectorAll("#proxy-setup [aria-label], #proxy-setup [data-program], #proxy-setup [data-program-off], #proxy-setup [data-outcome]")].map(e => [e.getAttribute("aria-label"), e.dataset.program, e.dataset.programOff, e.dataset.outcome].join(" ")).join("\\n")');
|
|
|
|
|
assert.doesNotMatch(page, KEY_TEXT);
|
|
|
|
|
// What the page shows in their place.
|
|
|
|
|
assert.equal(await b.evaluate('document.querySelectorAll("#proxy-setup-programs > li[data-program]").length'), 1);
|
|
|
|
|
assert.match(await b.evaluate('document.querySelector("#proxy-setup-programs").textContent'), /One or more programs have a name this page does not show\./);
|
|
|
|
|
assert.match((await programs(b))[0].text, /^On in Acme Studio and An organization Mosaic can't name\.$/);
|
|
|
|
|
assert.deepEqual(await outcomes(b), [
|
|
|
|
|
'An organization Mosaic can\'t name: Turned off.',
|
|
|
|
|
'Acme Studio: Not changed. It refused the change, with a code this page does not show.',
|
|
|
|
|
'Gamma Home: Not known. The answer did not say what happened.',
|
|
|
|
|
]);
|
|
|
|
|
assert.deepEqual(await access(b), [
|
|
|
|
|
{ text: 'An organization Mosaic can\'t nameReady', ready: 'ready' },
|
|
|
|
|
{ text: 'Acme StudioNot knownThe answer did not say.', ready: 'not-ready' },
|
|
|
|
|
{ text: 'Gamma HomeCould not be read', ready: 'not-ready' },
|
|
|
|
|
]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('settings-s5c: a refusal whose code is shaped like a key is not shown', { timeout: 90000 }, async t => {
|
|
|
|
|
const refused = { status: 400, body: { error: 'msk-abcdefghijklmnop' } };
|
|
|
|
|
const { b, wait, click } = 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('/turned off|may not have finished/.test(document.querySelector("#proxy-setup-programs-result").textContent)');
|
|
|
|
|
const page = await b.evaluate('document.querySelector("#proxy-setup").textContent + "\\n" + document.body.innerText');
|
|
|
|
|
assert.doesNotMatch(page, KEY_TEXT);
|
|
|
|
|
assert.equal(await b.evaluate('document.querySelector("#proxy-setup-access-message").textContent'), 'Access could not be read. The Console refused the read.');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// ---- Shots ------------------------------------------------------------------------------------
|
|
|
|
|
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, 1000));
|
|
|
|
|
const mixed = { name: 'zeta-runner', results: [{ id: 'acme', outcome: 'off' }, { id: 'gamma', outcome: 'bus-down' }, { id: 'lab', outcome: 'failed:outcome-unknown' }], receipt: null };
|
|
|
|
|
const off = async (b, wait, name) => {
|
|
|
|
|
await wait(`document.querySelector("[data-program-off=${name}]")`);
|
|
|
|
|
await b.evaluate(`document.querySelector("[data-program-off=${name}]").click(); true`);
|
|
|
|
|
await wait('document.querySelector("#proxy-setup-programs-yes")');
|
|
|
|
|
};
|
|
|
|
|
const SHOTS = [
|
|
|
|
|
{ name: 'advanced-programs', after: async b => openAdvanced(b), ready: 'document.querySelector("[data-program-off]")' },
|
|
|
|
|
{ name: 'advanced-confirm', after: async (b, wait) => { await openAdvanced(b); await off(b, wait, 'zeta-runner'); } },
|
|
|
|
|
{ name: 'advanced-result', options: { status: [SERVICE_UP, SERVICE_UP, AFTER], admin: { 'POST programs/off': mixed } },
|
|
|
|
|
after: async (b, wait) => { await openAdvanced(b); await off(b, wait, 'zeta-runner'); await b.evaluate('document.querySelector("#proxy-setup-programs-yes").click(); true'); await wait('document.querySelectorAll("#proxy-setup-programs-result li").length === 3'); } },
|
|
|
|
|
{ name: 'advanced-busy', options: { admin: { 'POST programs/off': { status: 409, body: { error: 'proxy-admin-busy' } } } },
|
|
|
|
|
after: async (b, wait) => { await openAdvanced(b); await off(b, wait, 'pi'); await b.evaluate('document.querySelector("#proxy-setup-programs-yes").click(); true'); await wait('/was not turned off/.test(document.querySelector("#proxy-setup-programs-result").textContent)'); } },
|
|
|
|
|
{ name: 'technical-access', options: { admin: { ...TECH, access: ACCESS } },
|
|
|
|
|
after: async (b, wait) => { await openTech(b); await wait(`document.querySelectorAll("#proxy-setup-access li").length === ${ACCESS.organizations.length}`); } },
|
|
|
|
|
{ name: 'technical-access-failed', options: { admin: { ...TECH, access: { status: 503, body: { error: 'outcome-unknown' } } } },
|
|
|
|
|
after: async (b, wait) => { await openTech(b); await wait('!document.querySelector("#proxy-setup-access-retry").hidden'); } },
|
|
|
|
|
];
|
|
|
|
|
const report = [];
|
|
|
|
|
for (const shot of SHOTS) for (const scheme of ['light', 'dark']) for (const width of [390, 1440]) {
|
|
|
|
|
const { b, wait } = await setup(t, { ...(shot.options ?? {}), viewport: [width, width === 390 ? 844 : 900] });
|
|
|
|
|
await b.call('Emulation.setScrollbarsHidden', { hidden: true });
|
|
|
|
|
await b.call('Emulation.setEmulatedMedia', { features: [{ name: 'prefers-color-scheme', value: scheme }] });
|
|
|
|
|
await wait(`(${READY}) && !!window.MosaicAppearance`);
|
|
|
|
|
await b.evaluate(`window.MosaicAppearance.ready.then(() => window.MosaicAppearance.set({ mode: ${JSON.stringify(scheme)} }))`);
|
|
|
|
|
await shot.after(b, wait);
|
|
|
|
|
if (shot.ready) await wait(shot.ready);
|
|
|
|
|
await settle();
|
|
|
|
|
const sideways = await b.evaluate('document.documentElement.scrollWidth > document.documentElement.clientWidth');
|
|
|
|
|
const noRing = [], seen = new Set();
|
|
|
|
|
for (let i = 0; i < 200; i++) {
|
|
|
|
|
await b.call('Input.dispatchKeyEvent', { type: 'keyDown', key: 'Tab', code: 'Tab', windowsVirtualKeyCode: 9 });
|
|
|
|
|
await b.call('Input.dispatchKeyEvent', { type: 'keyUp', key: 'Tab', code: 'Tab', windowsVirtualKeyCode: 9 });
|
|
|
|
|
const r = await 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.dataset.programOff || 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);
|
|
|
|
|
}
|
|
|
|
|
// The result box takes focus from code, not Tab: check its ring too.
|
|
|
|
|
const resultRing = await b.evaluate(`(() => { const e = document.querySelector("#proxy-setup-programs-result"); if (e.hidden) return null; e.focus(); const cs = getComputedStyle(e);
|
|
|
|
|
return (cs.outlineStyle !== 'none' && parseFloat(cs.outlineWidth) > 0) || (cs.boxShadow && cs.boxShadow !== 'none'); })()`);
|
|
|
|
|
if (resultRing === false) noRing.push('proxy-setup-programs-result');
|
|
|
|
|
await b.evaluate('document.activeElement?.blur(); window.scrollTo(0, 0); true'); await settle();
|
|
|
|
|
const file = `${shot.name}-${width}-${scheme}.png`;
|
|
|
|
|
let metrics = await b.call('Page.getLayoutMetrics'), size = metrics.cssContentSize || metrics.contentSize;
|
|
|
|
|
await b.viewport(width, Math.ceil(size.height)); await settle();
|
|
|
|
|
metrics = await b.call('Page.getLayoutMetrics'); size = metrics.cssContentSize || metrics.contentSize;
|
|
|
|
|
const { data } = await 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, file), Buffer.from(data, 'base64'));
|
|
|
|
|
report.push({ page: shot.name, width, scheme, shot: file, sideways, noRing });
|
|
|
|
|
await 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`);
|
|
|
|
|
}
|
|
|
|
|
});
|