360 lines
39 KiB
JavaScript
360 lines
39 KiB
JavaScript
// #1873 the Proxy setup panel in a real browser: the next step is one button, init sends a
|
|
// generated-key request unless the owner pastes a key on loopback, and pasted fields are cleared.
|
|
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { w15Fixture } from './w15-fixture.mjs';
|
|
|
|
const T = '2026-11-11T12:00:00.000Z';
|
|
const base = {
|
|
release: { fetched: false, verified: false, version: '8.0.42', panelVersion: '1.26.7' },
|
|
init: { initialized: false, partial: false, files: [{ label: 'proxy settings', present: false }, { label: 'management key', present: false }] },
|
|
unit: { unit: 'mosaic-proxy.service', installed: false, active: 'inactive' },
|
|
fence: { set: false }, initLock: { present: false, clearable: false, blockers: [] },
|
|
fetch: { state: 'idle' }, restart: null, busy: null,
|
|
organizations: [{ id: 'acme', proxy: 'shared', catalogue: null }],
|
|
ownProxy: { available: false, state: 'not built', reason: 'The configuration has one proxy per instance.' },
|
|
next: ['fetch'],
|
|
};
|
|
const fetched = { ...base, release: { ...base.release, fetched: true, verified: true }, next: ['init'] };
|
|
const fenced = { ...base, release: fetched.release, init: { initialized: true, partial: false, settings: { port: 18432 }, files: [] },
|
|
unit: { unit: 'mosaic-proxy.service', installed: true, active: 'active', pid: 4242, port: 18432, listening: true },
|
|
fence: { set: true, op: 'apikey.add', org: 'acme', time: T }, restart: { confirmed: true, pid: 4242, observedAt: T }, next: ['fence-clear'] };
|
|
const unconfigured = { 'GET /api/proxy/accounts': { status: 503, body: { error: 'not-configured' } }, 'GET /api/proxy/keys': { status: 503, body: { error: 'not-configured' } } };
|
|
const scenario = (status, config = {}) => ({ '/api/config': { send: true, devOwner: true, proxyAdmin: true, proxyAdminSend: true, ...config }, '/api/proxy/admin/status': status, ...unconfigured });
|
|
const writes = b => b.evaluate('window.__writes.filter(w=>w.path.startsWith("/api/proxy/admin/")).map(w=>({path:w.path,body:JSON.parse(w.body)}))');
|
|
|
|
test('a fresh instance shows the fetch step as one button, the not-built own proxy, and no terminal note', { timeout: 90000 }, async t => {
|
|
const { f, b, wait } = await w15Fixture(t, { scenario: { ...scenario(base), 'POST /api/proxy/admin/fetch': { status: 202, body: { state: 'running' } } } });
|
|
await b.navigate(f.base + '/#/settings/model-proxy');
|
|
await wait('document.querySelector("#proxy-setup-go")?.dataset.next==="fetch"');
|
|
assert.equal(await b.evaluate('document.querySelector("#proxy-setup").hidden'), false);
|
|
assert.equal(await b.evaluate('document.querySelector("#proxy-setup-go").textContent'), 'Fetch the pinned release');
|
|
assert.match(await b.evaluate('document.querySelector("#proxy-setup-next p").textContent'), /CLIProxyAPI 8\.0\.42/);
|
|
assert.match(await b.evaluate('document.querySelector("#proxy-setup-own").textContent'), /not built/);
|
|
assert.equal(await b.evaluate('document.querySelector("#proxy-setup-orgs td").textContent'), 'acme');
|
|
await wait('document.querySelector("#proxy-message")?.textContent.includes("Follow the next step under Set up the model service")');
|
|
assert.equal(await b.evaluate('!!document.querySelector("#proxy-dev-setup")'), false, 'the page replaces the terminal note');
|
|
assert.equal(await b.evaluate('document.querySelectorAll("#proxy-setup-init [data-setup-write]:not([disabled])").length'), 0, 'init waits for a verified release');
|
|
await b.evaluate('document.querySelector("#proxy-setup-go").click()');
|
|
await wait('window.__writes.some(w=>w.path==="/api/proxy/admin/fetch")');
|
|
assert.deepEqual(await writes(b), [{ path: '/api/proxy/admin/fetch', body: {} }]);
|
|
assert.deepEqual(await b.evaluate('window.__unexpected'), []);
|
|
});
|
|
|
|
test('without send the next-step button is disabled and nothing is posted', { timeout: 90000 }, async t => {
|
|
const { f, b, wait } = await w15Fixture(t, { scenario: scenario(base, { send: false, proxyAdminSend: false }) });
|
|
await b.navigate(f.base + '/#/settings/model-proxy');
|
|
await wait('document.querySelector("#proxy-setup-go")?.dataset.next==="fetch"');
|
|
assert.equal(await b.evaluate('document.querySelector("#proxy-setup-go").disabled'), true);
|
|
await b.evaluate('document.querySelector("#proxy-setup-go").click()');
|
|
assert.deepEqual(await writes(b), []);
|
|
});
|
|
|
|
test('init sends generate by default; a pasted key on loopback is sent with its confirmation and the fields are cleared', { timeout: 90000 }, async t => {
|
|
const { f, b, wait } = await w15Fixture(t, { scenario: { ...scenario(fetched), 'POST /api/proxy/admin/init': { body: { settings: { port: 18432 }, receipt: { op: 'init', time: T, port: 18432, generated: true } } } } });
|
|
await b.navigate(f.base + '/#/settings/model-proxy');
|
|
await wait('document.querySelector("#proxy-setup-go")?.dataset.next==="init"');
|
|
await b.evaluate('document.querySelector("#proxy-setup-go").click()');
|
|
await wait('document.querySelector("#proxy-setup-init-box").open===true');
|
|
assert.equal(await b.evaluate('document.querySelector("#proxy-setup-paste-choice").hidden'), false, 'loopback page offers the paste choice');
|
|
assert.equal(await b.evaluate('document.querySelector("#proxy-setup-paste").hidden'), true);
|
|
await b.evaluate('(()=>{const f=document.querySelector("#proxy-setup-init");f.elements.port.value="18432";f.requestSubmit();})()');
|
|
await wait('window.__writes.some(w=>w.path==="/api/proxy/admin/init")');
|
|
await wait('document.querySelector("#proxy-setup-message").textContent.includes("with a generated key")');
|
|
assert.deepEqual(await writes(b), [{ path: '/api/proxy/admin/init', body: { port: 18432, generate: true } }]);
|
|
assert.match(await b.evaluate('document.querySelector("#proxy-setup-receipts").textContent'), /init/);
|
|
await wait('!document.querySelector("#proxy-setup-init [data-setup-write]").disabled');
|
|
await b.evaluate('(()=>{const f=document.querySelector("#proxy-setup-init");f.elements.keySource.value="paste";f.querySelector("[value=paste]").dispatchEvent(new Event("change"));f.elements.port.value="";f.elements.key.value="pa-browser-sentinel-0001";f.elements.confirm.value="pa-browser-sentinel-0002";f.requestSubmit();})()');
|
|
await wait('document.querySelector("#proxy-setup-message").textContent.includes("proxy-key-mismatch")');
|
|
assert.equal((await writes(b)).length, 1, 'a mismatch is refused in the page');
|
|
assert.equal(await b.evaluate('document.querySelector("#proxy-setup-init").elements.key.value'), '', 'the key field is cleared on submit');
|
|
await b.evaluate('(()=>{const f=document.querySelector("#proxy-setup-init");f.elements.key.value="pa-browser-sentinel-0001";f.elements.confirm.value="pa-browser-sentinel-0001";f.requestSubmit();})()');
|
|
await wait('window.__writes.filter(w=>w.path==="/api/proxy/admin/init").length===2');
|
|
assert.deepEqual((await writes(b))[1], { path: '/api/proxy/admin/init', body: { key: 'pa-browser-sentinel-0001', confirm: 'pa-browser-sentinel-0001' } });
|
|
assert.equal(await b.evaluate('[...document.querySelectorAll("#proxy-setup-init input[type=password]")].every(i=>i.value==="")'), true);
|
|
assert.equal(await b.evaluate('document.body.innerText.includes("pa-browser-sentinel")'), false);
|
|
});
|
|
|
|
test('after a confirmed restart the next step clears the fence and shows the receipt', { timeout: 90000 }, async t => {
|
|
const { f, b, wait } = await w15Fixture(t, { scenario: { ...scenario(fenced), 'POST /api/proxy/admin/fence/clear': { body: { cleared: true, receipt: { op: 'fence.clear', time: T, pid: 4242 } } } } });
|
|
await b.navigate(f.base + '/#/settings/model-proxy');
|
|
await wait('document.querySelector("#proxy-setup-go")?.dataset.next==="fence-clear"');
|
|
assert.match(await b.evaluate('document.querySelector("#proxy-setup-state").textContent'), /new pid 4242/);
|
|
await b.evaluate('document.querySelector("#proxy-setup-go").click()');
|
|
await wait('document.querySelector("#proxy-setup-message").textContent.includes("Fence cleared")');
|
|
assert.deepEqual(await writes(b), [{ path: '/api/proxy/admin/fence/clear', body: {} }]);
|
|
assert.match(await b.evaluate('document.querySelector("#proxy-setup-receipts").textContent'), /fence\.clear.*pid: 4242/);
|
|
});
|
|
|
|
test('a stopped proxy hides the account panels with a setup note, and starting the service brings them back', { timeout: 90000 }, async t => {
|
|
const installed = { ...base, release: fetched.release, init: { initialized: true, partial: false, settings: { port: 18432 }, files: [] },
|
|
unit: { unit: 'mosaic-proxy.service', installed: true, active: 'inactive' }, next: ['unit-start'] };
|
|
const down = { 'GET /api/proxy/accounts': { status: 503, body: { error: 'proxy-down' } }, 'GET /api/proxy/keys': { status: 503, body: { error: 'proxy-down' } } };
|
|
const { f, b, wait } = await w15Fixture(t, { scenario: { ...scenario(installed), ...down, 'POST /api/proxy/admin/unit/start': { body: { receipt: { op: 'unit.start', time: T, pid: 4242 } } } } });
|
|
await b.navigate(f.base + '/#/settings/model-proxy');
|
|
await wait('document.querySelector("#proxy-setup-go")?.dataset.next==="unit-start"');
|
|
await wait('document.querySelector("#proxy-message").textContent.includes("not running yet")');
|
|
assert.equal(await b.evaluate('document.querySelector("[aria-labelledby=proxy-apikey-title]").hidden'), true);
|
|
await b.evaluate(`Object.assign(window.__scenario, {
|
|
'GET /api/proxy/accounts': { body: { accounts: [] } }, 'GET /api/proxy/keys': { body: { keys: [] } },
|
|
'/api/proxy/admin/status': ${JSON.stringify({ ...base, release: fetched.release, init: { initialized: true, partial: false, settings: { port: 18432 }, files: [] },
|
|
unit: { unit: 'mosaic-proxy.service', installed: true, active: 'active', pid: 4242, port: 18432, listening: true }, next: ['accounts'] })} })`);
|
|
await b.evaluate('document.querySelector("#proxy-setup-go").click()');
|
|
await wait('window.__writes.some(w=>w.path==="/api/proxy/admin/unit/start")');
|
|
await wait('document.querySelector("#proxy-message").textContent.includes("Accounts and client keys loaded")');
|
|
assert.equal(await b.evaluate('document.querySelector("[aria-labelledby=proxy-apikey-title]").hidden'), false);
|
|
assert.equal(await b.evaluate('document.querySelector("[aria-labelledby=proxy-accounts-title]").hidden'), false);
|
|
});
|
|
|
|
test('an initialized proxy whose accounts read fails with another code also hides the panels until it answers', { timeout: 90000 }, async t => {
|
|
const installed = { ...base, release: fetched.release, init: { initialized: true, partial: false, settings: { port: 18432 }, files: [] },
|
|
unit: { unit: 'mosaic-proxy.service', installed: true, active: 'inactive' }, next: ['unit-start'] };
|
|
const failing = { 'GET /api/proxy/accounts': { status: 503, body: { error: 'outcome-unknown' } }, 'GET /api/proxy/keys': { status: 503, body: { error: 'outcome-unknown' } } };
|
|
const { f, b, wait } = await w15Fixture(t, { scenario: { ...scenario(installed), ...failing, 'POST /api/proxy/admin/unit/start': { body: { receipt: { op: 'unit.start', time: T, pid: 4242 } } } } });
|
|
await b.navigate(f.base + '/#/settings/model-proxy');
|
|
await wait('document.querySelector("#proxy-setup-go")?.dataset.next==="unit-start"');
|
|
await wait('document.querySelector("#proxy-message").textContent.includes("the account panels return once the service answers")');
|
|
assert.equal(await b.evaluate('document.querySelector("[aria-labelledby=proxy-accounts-title]").hidden'), true);
|
|
await b.evaluate(`Object.assign(window.__scenario, {
|
|
'GET /api/proxy/accounts': { body: { accounts: [] } }, 'GET /api/proxy/keys': { body: { keys: [] } },
|
|
'/api/proxy/admin/status': ${JSON.stringify({ ...base, release: fetched.release, init: { initialized: true, partial: false, settings: { port: 18432 }, files: [] },
|
|
unit: { unit: 'mosaic-proxy.service', installed: true, active: 'active', pid: 4242, port: 18432, listening: true }, next: ['accounts'] })} })`);
|
|
await b.evaluate('document.querySelector("#proxy-setup-go").click()');
|
|
await wait('document.querySelector("#proxy-message").textContent.includes("Accounts and client keys loaded")');
|
|
assert.equal(await b.evaluate('document.querySelector("[aria-labelledby=proxy-accounts-title]").hidden'), false);
|
|
});
|
|
|
|
test('a fence with no readable time names the --proxy-restarted path instead of a page restart', { timeout: 90000 }, async t => {
|
|
const timeless = { ...fenced, fence: { set: true, invalid: true }, restart: null, next: ['unit-restart'] };
|
|
const { f, b, wait } = await w15Fixture(t, { scenario: scenario(timeless) });
|
|
await b.navigate(f.base + '/#/settings/model-proxy');
|
|
await wait('document.querySelector("#proxy-setup-go")?.dataset.next==="unit-restart"');
|
|
const text = await b.evaluate('document.querySelector("#proxy-setup-next > p").textContent');
|
|
assert.match(text, /no readable time.*restart the model service, confirm it answers, then clear the fence\./);
|
|
assert.doesNotMatch(text, /proxy/i, 'owner text says model service');
|
|
// The exact command sits under Technical details, folded, with where to run it.
|
|
assert.equal(await b.evaluate('document.querySelector("#proxy-setup-next details.proxy-setup-cli").open'), false);
|
|
assert.equal(await b.evaluate('document.querySelector("#proxy-setup-next details.proxy-setup-cli summary").textContent'), 'Technical details');
|
|
assert.equal(await b.evaluate('document.querySelector("#proxy-setup-next details.proxy-setup-cli p").textContent'), 'Run this in a terminal on this machine: mosaic proxy fence clear --proxy-restarted');
|
|
});
|
|
|
|
test('after a reload the receipts come from status, and an initialized proxy folds the init form', { timeout: 90000 }, async t => {
|
|
const initialized = { ...base, release: fetched.release, init: { initialized: true, partial: false, settings: { port: 18432 }, files: [] },
|
|
receipts: [{ op: 'fetch', time: T, version: '8.0.42' }, { op: 'init', time: T, generated: true, port: 18432 }], next: ['unit-install'] };
|
|
const { f, b, wait } = await w15Fixture(t, { scenario: { ...scenario(initialized), 'POST /api/proxy/admin/unit/install': { body: { receipt: { op: 'unit.install', time: T } } } } });
|
|
await b.navigate(f.base + '/#/settings/model-proxy');
|
|
await wait('document.querySelector("#proxy-setup-go")?.dataset.next==="unit-install"');
|
|
assert.deepEqual(await b.evaluate('[...document.querySelectorAll("#proxy-setup-receipts li strong")].map(s=>s.textContent)'), ['init', 'fetch'], 'newest first, from proxy-admin.jsonl');
|
|
await b.evaluate('document.querySelector("#proxy-setup-init-box").open = true');
|
|
await b.evaluate('document.querySelector("#proxy-setup-go").click()');
|
|
await wait('window.__writes.some(w=>w.path==="/api/proxy/admin/unit/install")');
|
|
await wait('document.querySelector("#proxy-setup-init-box").open===false');
|
|
});
|
|
|
|
// #1873 ride-default: the Ride all box. The confirm names the stricter admission, the answer's
|
|
// skips and stand-in organizations are painted even while an earlier load still waits on the
|
|
// accounts read, and the move confirm says the organization spends real tokens after it.
|
|
test('Ride all confirms the stricter admission, paints skips and stand-in organizations while a load waits, and the move warns of real tokens', { timeout: 90000 }, async t => {
|
|
const running = { ...fenced, fence: { set: false }, restart: null, next: ['ride-all'],
|
|
ride: [{ id: 'north', state: 'ready' }, { id: 'south', state: 'ready' }, { id: 'west', state: 'fixture' }] };
|
|
const { f, b, wait } = await w15Fixture(t, { scenario: { ...scenario(running),
|
|
'POST /api/proxy/admin/ride-all': { body: { added: ['south'], already: [], skipped: [], fixtures: [{ id: 'west' }], receipt: { op: 'ride.all', time: T } } },
|
|
'POST /api/proxy/admin/ride-move': { body: { moved: false, reason: 'bus-running' } } } });
|
|
// The first accounts and keys reads answer not-configured; every later pair never answers, so a load stays in flight.
|
|
await b.call('Page.addScriptToEvaluateOnNewDocument', { source: `(() => { const inner = window.fetch; let n = 0; window.__confirms = [];
|
|
window.confirm = text => { window.__confirms.push(text); return true; };
|
|
window.fetch = (input, init) => { const url = String(typeof input === 'string' ? input : input.url);
|
|
if (url.includes('/api/proxy/accounts') && n++ > 0) return new Promise(() => {});
|
|
if (url.includes('/api/proxy/keys') && n > 1) return new Promise(() => {});
|
|
return inner(input, init); }; })();` });
|
|
await b.navigate(f.base + '/#/settings/model-proxy');
|
|
await wait('document.querySelector("#proxy-ride")?.hidden===false && document.querySelector("#proxy-setup-go")?.dataset.next==="ride-all"');
|
|
assert.match(await b.evaluate('document.querySelector("#proxy-ride-text").textContent'), /every launch route is checked, direct Anthropic routes too.*2 organizations can ride now/);
|
|
assert.match(await b.evaluate('document.querySelector("#proxy-ride-fixtures li").textContent'), /^west uses stand-in models, can be moved to the owner's models\./);
|
|
// The first Ride all's own reload paints, then waits on the accounts read for good.
|
|
await b.evaluate('document.querySelector("#proxy-ride-go").click()');
|
|
await wait('window.__writes.some(w=>w.path==="/api/proxy/admin/ride-all")');
|
|
assert.match(await b.evaluate('window.__confirms[0]'), /Admission gets stricter there: every launch route is checked, direct Anthropic routes too, and while the proxy is down or fenced every launch in that organization is refused/);
|
|
await wait('document.querySelector("#proxy-ride-message").textContent.includes("Added to 1")');
|
|
await wait('document.querySelector("#proxy-ride-go").disabled===false');
|
|
// The second answer lands while that load is still in flight.
|
|
await b.evaluate(`window.__scenario['POST /api/proxy/admin/ride-all'] = { body: ${JSON.stringify({ added: [], already: ['south'], skipped: [{ id: 'north', reason: 'no-proxy-client' }], fixtures: [{ id: 'west', running: true }], receipt: { op: 'ride.all', time: T } })} }`);
|
|
await b.evaluate('document.querySelector("#proxy-ride-go").click()');
|
|
await wait('window.__writes.filter(w=>w.path==="/api/proxy/admin/ride-all").length===2');
|
|
await wait('document.querySelector("#proxy-ride-message").textContent.includes("skipped 1")');
|
|
await wait('document.querySelectorAll("#proxy-ride-skips li").length===1');
|
|
assert.equal(await b.evaluate('document.querySelector("#proxy-ride-skips li").textContent'), 'Skipped north: Its bus started before the proxy was set up. Restart its bus, then ride again.');
|
|
assert.match(await b.evaluate('document.querySelector("#proxy-ride-fixtures li").textContent'), /Its bus is running: stop it first\./);
|
|
assert.equal(await b.evaluate('document.querySelector("#proxy-ride-go").disabled'), false, 'the box is not left busy');
|
|
await b.evaluate('document.querySelector("[data-ride-move=west]").click()');
|
|
await wait('window.__writes.some(w=>w.path==="/api/proxy/admin/ride-move")');
|
|
assert.match(await b.evaluate('window.__confirms[2]'), /^Move west to your models\?.*its agents spend real tokens on your account/);
|
|
assert.deepEqual(JSON.parse(await b.evaluate('window.__writes.find(w=>w.path==="/api/proxy/admin/ride-move").body')), { org: 'west' });
|
|
// Re-check 3 (P3-2): a running bus and a bus whose state cannot be read get the same refusal, in words that fit both.
|
|
await wait(`document.querySelector("#proxy-ride-message").textContent===${JSON.stringify('west was not moved. Its bus is running, or its state could not be read. Stop or recover its bus, then move it.')}`);
|
|
// Round 3 (P3): an SSO Console's org-forbidden in plain words, and the neutral fallback for a code the page does not know.
|
|
for (const [n, reason, text] of [[2, 'org-forbidden', 'west was not moved. Moving organizations is not available on this Console yet. It works on a local development Console.'],
|
|
[3, 'frobnicated', 'west was not moved. The change was refused (frobnicated).']]) {
|
|
await b.evaluate(`window.__scenario['POST /api/proxy/admin/ride-move'] = { body: ${JSON.stringify({ moved: false, reason })} }`);
|
|
await wait('document.querySelector("[data-ride-move=west]")?.disabled===false');
|
|
await b.evaluate('document.querySelector("[data-ride-move=west]").click()');
|
|
await wait(`window.__writes.filter(w=>w.path==="/api/proxy/admin/ride-move").length===${n}`);
|
|
await wait(`document.querySelector("#proxy-ride-message").textContent===${JSON.stringify(text)}`);
|
|
}
|
|
// Round 3: an organization the proxy was or may have been on, and an add the receipt could not record first.
|
|
await b.evaluate(`window.__scenario['POST /api/proxy/admin/ride-all'] = { body: ${JSON.stringify({ added: [], already: [], skipped: [{ id: 'north', reason: 'removed' }, { id: 'south', reason: 'not-recorded' }, { id: 'east', reason: 'unreadable' }], fixtures: [], receipt: { op: 'ride.all', time: T } })} }`);
|
|
await wait('document.querySelector("#proxy-ride-go").disabled===false');
|
|
await b.evaluate('document.querySelector("#proxy-ride-go").click()');
|
|
await wait('window.__writes.filter(w=>w.path==="/api/proxy/admin/ride-all").length===3');
|
|
await wait('document.querySelectorAll("#proxy-ride-skips li").length===3');
|
|
assert.deepEqual(JSON.parse(await b.evaluate('JSON.stringify([...document.querySelectorAll("#proxy-ride-skips li")].map(li=>li.textContent))')), [
|
|
'Skipped north: The model proxy was on it, or Ride all may have added it, and it is off now. Ride all leaves it off. Add it on its Settings page to use it.',
|
|
'Skipped south: The proxy could not record the change first, so it was not made.',
|
|
// Re-check 3 (P3-3): a damaged receipts line stops every add until someone repairs it.
|
|
'Skipped east: Its organization file, its change log or the proxy\'s receipts could not be read. A damaged line in the proxy\'s receipts must be repaired by hand before Ride all adds again.']);
|
|
assert.deepEqual(await b.evaluate('window.__unexpected'), []);
|
|
});
|
|
|
|
// #1873 settings slice 1 (DESIGN.md sections 4 and 9, D1, D3, D4). The service runs ("accounts" is the
|
|
// server's next step); the steps after it come from what the page reads: accounts, organizations, Triage route.
|
|
const running = { ...base, release: fetched.release, init: { initialized: true, partial: false, settings: { port: 18432 }, files: [] },
|
|
unit: { unit: 'mosaic-proxy.service', installed: true, active: 'active', pid: 4242, port: 18432, listening: true }, next: ['accounts'] };
|
|
const account = { accountId: 'a1', displayName: 'Claude work', provider: 'claude', status: 'active', priority: 0 };
|
|
const answering = (n = 1) => ({ 'GET /api/proxy/accounts': { body: { accounts: Array.from({ length: n }, () => account) } }, 'GET /api/proxy/keys': { body: { keys: [] } } });
|
|
// An organization's own routes read, the one Routing uses: its catalogue and the bus's cause lines.
|
|
const routes = (notices = [], status = 'unavailable', reason) => ({ rows: [{ catalogue: { status, models: [], notices, ...(reason ? { reason } : {}) } }] });
|
|
const FIXTURE = 'This organization routes launches to the dev fixture, which the host refuses next to a model proxy (fixture-proxy-configured). Remove the fixture or stop using it here.';
|
|
const savedRoute = { route: { model: 'm', harness: 'claude-code', cap: 1000, reset: '00:00', timeZone: 'UTC', revision: 1, updatedAt: T } };
|
|
const restarted = { body: { outcome: 'done', step: 'bus-restart', restarted: true, healthy: true } };
|
|
const visible = sel => `[...document.querySelectorAll(${JSON.stringify(sel)})].filter(e=>e.checkVisibility())`;
|
|
|
|
test('settings-s1 B2: once the service runs, the organizations that cannot see the models stay listed, each with its own Restart', { timeout: 90000 }, async t => {
|
|
const orgs = [{ id: 'acme', proxy: 'shared', catalogue: { status: 'unavailable', models: 0 } }, { id: 'beta', proxy: 'shared', catalogue: { status: 'bus-unavailable' } },
|
|
{ id: 'gamma', proxy: 'shared', catalogue: { status: 'ready', models: 3 } }, { id: 'delta', proxy: 'shared', catalogue: { status: 'disabled' } }];
|
|
const { f, b, wait } = await w15Fixture(t, { scenario: { ...scenario({ ...running, organizations: orgs }, { orgSetup: true }), ...answering(), '/api/triage/route': savedRoute, '/api/orgs/acme/bus/routes': routes(), 'POST /api/orgs/acme/restart/bus': restarted } });
|
|
await b.navigate(f.base + '/#/settings/model-proxy');
|
|
await wait('document.querySelectorAll("#proxy-setup-restart-list li").length===2');
|
|
assert.equal(await b.evaluate('document.querySelector("#proxy-setup-restart").checkVisibility()'), true);
|
|
assert.deepEqual(await b.evaluate('[...document.querySelectorAll("#proxy-setup-restart-list li")].map(li=>[li.dataset.restartOrg, li.querySelector(".badge").className, li.querySelector(".badge").textContent, li.querySelector("[data-org-restart]")?.textContent ?? null])'),
|
|
[['acme', 'badge badge-attn', "Can't see models", 'Restart acme'], ['beta', 'badge badge-danger', 'Not running', 'Restart beta']]);
|
|
assert.equal(await b.evaluate('document.querySelector("#proxy-setup-go")'), null, 'the next step is the list, so no second button');
|
|
// acme's bus names no cause, so a restart connects it. beta is not running: it keeps its Restart
|
|
// and its refusal, and does not hold the next step.
|
|
assert.match(await b.evaluate('document.querySelector("#proxy-setup-next").textContent'), /^Next: restart acme\. It has a Restart button under Organizations that can't see your models\./);
|
|
assert.equal(await b.evaluate('document.querySelector("#proxy-setup-restart-title").textContent'), "Organizations that can't see your models");
|
|
// A restart reads the status again; the organization stays on the list, now ready, so the owner sees it worked.
|
|
await b.evaluate(`window.__scenario['/api/proxy/admin/status'] = ${JSON.stringify({ ...running, organizations: [{ ...orgs[0], catalogue: { status: 'ready', models: 3 } }, ...orgs.slice(1)] })}`);
|
|
await b.evaluate('document.querySelector("[data-org-restart=acme]").focus()');
|
|
assert.notEqual(await b.evaluate('getComputedStyle(document.activeElement).outlineStyle'), 'none', 'the focused Restart shows a focus ring');
|
|
await b.key('Enter', 'Enter');
|
|
await wait('document.querySelector("[data-restart-org=acme] .badge")?.textContent==="Ready"');
|
|
assert.deepEqual(await b.evaluate('window.__writes.map(w=>w.method+" "+w.path)'), ['POST /api/orgs/acme/restart/bus']);
|
|
assert.equal(await b.evaluate('document.querySelector("[data-restart-org=acme] [data-org-restart]")'), null, 'a ready organization has no Restart');
|
|
assert.equal(await b.evaluate('document.querySelector("[data-restart-org=acme] .badge").className'), 'badge badge-ok');
|
|
assert.match(await b.evaluate('document.querySelector("#proxy-setup-next").textContent'), /^The model service is set up\. Some organizations still can't see your models\./);
|
|
assert.deepEqual(await b.evaluate('window.__unexpected'), []);
|
|
});
|
|
|
|
test('settings-s1 B2: Restart shows only where the organization\'s own cause allows it; the dev fixture and a model-key collision get their plain lines, and neither holds the next step', { timeout: 90000 }, async t => {
|
|
const orgs = [{ id: 'acme', proxy: 'shared', catalogue: { status: 'unavailable', models: 0 } }, { id: 'lab', proxy: 'shared', catalogue: { status: 'unavailable', models: 0 } },
|
|
{ id: 'lock', proxy: 'shared', catalogue: { status: 'unavailable', models: 0 } }, { id: 'odd', proxy: 'shared', catalogue: { status: 'unavailable', models: 0 } },
|
|
{ id: 'clash', proxy: 'shared', catalogue: { status: 'unavailable', models: 0 } }];
|
|
const lock = 'The shared proxy lock does not load (proxy-lock-invalid). Check the proxy state for this instance, then restart this bus.';
|
|
const { f, b, wait } = await w15Fixture(t, { scenario: { ...scenario({ ...running, organizations: orgs }, { orgSetup: true }), ...answering(), '/api/triage/route': savedRoute,
|
|
'/api/orgs/acme/bus/routes': routes(), '/api/orgs/lab/bus/routes': routes([FIXTURE]), '/api/orgs/lock/bus/routes': routes([lock]), 'GET /api/orgs/odd/bus/routes': { status: 500, body: { error: 'x' } },
|
|
'/api/orgs/clash/bus/routes': routes([], 'unavailable', 'model-key-collision') } });
|
|
await b.navigate(f.base + '/#/settings/model-proxy');
|
|
await wait('document.querySelectorAll("#proxy-setup-restart-list li").length===5 && !/Checking why/.test(document.querySelector("#proxy-setup-restart-list").textContent)');
|
|
const rows = await b.evaluate('Object.fromEntries([...document.querySelectorAll("#proxy-setup-restart-list li")].map(li=>[li.dataset.restartOrg, {badge: li.querySelector(".badge").className, why: li.querySelector(":scope > .small").textContent, restart: li.querySelector("[data-org-restart]")?.textContent ?? null, link: li.querySelector(":scope > .small a")?.getAttribute("href") ?? null, detail: li.querySelector("details summary")?.textContent ?? null}]))');
|
|
assert.deepEqual(rows.acme, { badge: 'badge badge-attn', why: "acme can't read your models from the model service yet. A restart connects it.", restart: 'Restart acme', link: null, detail: null });
|
|
// Saving routes does not remove the fixture provider, so lab gets no Routing link (review 2, P2-B).
|
|
assert.deepEqual(rows.lab, { badge: 'badge badge-attn', why: "lab runs on test models, which can't share this machine with your model service. This can't be changed from Console yet.", restart: null, link: null, detail: 'Technical details' });
|
|
assert.deepEqual(rows.lock, { badge: 'badge badge-attn', why: "lock can't open the model service's shared lock. A restart opens it again.", restart: 'Restart lock', link: null, detail: 'Technical details' });
|
|
// Two models that slug to one key: a restart reads the same catalogue again (review 2, P2-A).
|
|
assert.deepEqual(rows.clash, { badge: 'badge badge-attn', why: "Two of your models get the same short name, so clash can't tell them apart. A restart won't change that.", restart: null, link: null, detail: 'Technical details' });
|
|
assert.deepEqual(rows.odd, { badge: 'badge badge-attn', why: "odd can't see your models, and its reason could not be read. Open odd's Routing", restart: null, link: '#/orgs/odd/settings/routing', detail: null });
|
|
assert.equal(await b.evaluate('document.querySelector("[data-restart-org=lab] details").textContent.includes("fixture-proxy-configured")'), true, 'the bus line is kept under Technical details');
|
|
assert.match(await b.evaluate('document.querySelector("#proxy-setup-next").textContent'), /^Next: restart acme and lock\./);
|
|
assert.doesNotMatch(await b.evaluate('document.querySelector("#proxy-setup-restart-list").innerText'), /model proxy/i, 'the bus line shows only once Technical details is opened');
|
|
// Once acme and lock see the models, only the fixture, the collision and the unread one are left, and none holds a step.
|
|
await b.evaluate(`window.__scenario['/api/proxy/admin/status'] = ${JSON.stringify({ ...running, organizations: [{ ...orgs[0], catalogue: { status: 'ready', models: 2 } }, orgs[1], { ...orgs[2], catalogue: { status: 'ready', models: 2 } }, orgs[3], orgs[4]] })}`);
|
|
await b.evaluate('document.dispatchEvent(new CustomEvent("mosaic-org-restarted", { detail: { id: "acme" } })); true');
|
|
await wait('/^The model service is set up\\. Some organizations still/.test(document.querySelector("#proxy-setup-next").textContent)');
|
|
assert.equal(await b.evaluate('document.querySelector("#proxy-setup-go")'), null);
|
|
assert.deepEqual(await b.evaluate('window.__writes.map(w=>w.method+" "+w.path)'), [], 'nothing restarts by itself');
|
|
});
|
|
|
|
test('settings-s1 B2: a refused restart keeps its reason on the list across the status read that follows', { timeout: 90000 }, async t => {
|
|
const orgs = [{ id: 'lab', proxy: 'shared', catalogue: { status: 'bus-unavailable' } }];
|
|
const refusal = { status: 409, body: { error: 'bus-start-refused', message: 'bus start refused: fixture-proxy-configured' } };
|
|
const { f, b, wait } = await w15Fixture(t, { scenario: { ...scenario({ ...running, organizations: orgs }, { orgSetup: true }), ...answering(), '/api/triage/route': savedRoute, 'POST /api/orgs/lab/restart/bus': refusal } });
|
|
await b.navigate(f.base + '/#/settings/model-proxy');
|
|
await wait('document.querySelector("[data-org-restart=lab]")');
|
|
await b.evaluate('document.querySelector("[data-org-restart=lab]").click()');
|
|
await wait('document.querySelector("[data-restart-org=lab] .org-restart-refused")');
|
|
await new Promise(r => setTimeout(r, 300));
|
|
assert.equal(await b.evaluate('document.querySelector("[data-restart-org=lab] [data-org-restart-receipt] strong").textContent'), "lab runs on test models, which can't share this machine with your model service. It did not start.");
|
|
assert.equal(await b.evaluate('document.querySelector("[data-restart-org=lab] .badge").className'), 'badge badge-danger', 'a refused organization is never green');
|
|
});
|
|
|
|
test('settings-s1 B3: a sign-in reads the whole status again and the next step follows accounts, organizations, then the Triage route', { timeout: 90000 }, async t => {
|
|
const { f, b, wait } = await w15Fixture(t, { scenario: { ...scenario({ ...running, organizations: [{ id: 'acme', proxy: 'shared', catalogue: null }] }, { orgSetup: true }), ...answering(0), '/api/triage/route': { route: null }, '/api/orgs/acme/bus/routes': routes(),
|
|
'POST /api/proxy/login/status': { body: { status: 'error', reason: 'login-timeout' } } } });
|
|
await b.navigate(f.base + '/#/settings/model-proxy');
|
|
await wait('document.querySelector("#proxy-setup-go")?.dataset.next==="accounts"');
|
|
assert.equal(await b.evaluate('document.querySelector("#proxy-setup-go").textContent'), 'Add an account');
|
|
await b.evaluate(`window.open = () => null; window.__scenario['POST /api/proxy/login/start'] = { body: { url: location.origin + '/signin-stub', state: 's1' } }`);
|
|
// A sign-in that runs out of time says so plainly.
|
|
await b.evaluate('document.querySelector("#proxy-login-start").requestSubmit()');
|
|
await wait('document.querySelector("#proxy-login-message").textContent==="Sign-in took too long. Try again."');
|
|
// The next sign-in finishes. The status read after it is the one that names acme, so the step proves the reread.
|
|
await b.evaluate(`Object.assign(window.__scenario, ${JSON.stringify({ ...answering(1), 'POST /api/proxy/login/status': { body: { status: 'ok' } }, '/api/proxy/admin/status': { ...running, organizations: [{ id: 'acme', proxy: 'shared', catalogue: { status: 'unavailable', models: 0 } }] } })})`);
|
|
await b.evaluate('document.querySelector("#proxy-login-start").requestSubmit()');
|
|
await wait('document.querySelector("#proxy-setup-next [data-next]")?.dataset.next==="restart-orgs"');
|
|
assert.match(await b.evaluate('document.querySelector("#proxy-setup-next").textContent'), /^Next: restart acme\./);
|
|
assert.equal(await b.evaluate('document.querySelector("#proxy-login-message").textContent'), 'Account signed in.');
|
|
// acme restarts and can see the models; the Triage route is not set, so that is the step after.
|
|
await b.evaluate(`Object.assign(window.__scenario, ${JSON.stringify({ 'POST /api/orgs/acme/restart/bus': restarted, '/api/proxy/admin/status': { ...running, organizations: [{ id: 'acme', proxy: 'shared', catalogue: { status: 'ready', models: 2 } }] } })})`);
|
|
await b.evaluate('document.querySelector("[data-org-restart=acme]").click()');
|
|
await wait('document.querySelector("#proxy-setup-go")?.dataset.next==="triage-route"');
|
|
assert.equal(await b.evaluate('document.querySelector("#proxy-setup-go").textContent'), 'Open Triage settings');
|
|
assert.equal(await b.evaluate('document.querySelector("#proxy-setup-go").disabled'), false);
|
|
assert.deepEqual(await b.evaluate('window.__unexpected'), []);
|
|
});
|
|
|
|
// Rebase onto ride-default: with an account, Ride all is the step after accounts while an organization can
|
|
// ride now, and its box shows outside Technical details. Stand-in organizations alone do not hold the step.
|
|
test('settings-s1 B3 with ride-default: Ride all follows accounts while an organization can ride, and only then', { timeout: 90000 }, async t => {
|
|
const riding = { ...running, next: ['accounts', 'ride-all'], organizations: [{ id: 'acme', proxy: 'shared', catalogue: { status: 'ready', models: 2 } }],
|
|
ride: [{ id: 'north', state: 'ready' }, { id: 'west', state: 'fixture' }] };
|
|
const { f, b, wait } = await w15Fixture(t, { scenario: { ...scenario(riding), ...answering(1), '/api/triage/route': { route: null } } });
|
|
await b.navigate(f.base + '/#/settings/model-proxy');
|
|
await wait('document.querySelector("#proxy-setup-go")?.dataset.next==="ride-all"');
|
|
assert.equal(await b.evaluate('document.querySelector("#proxy-setup-go").textContent'), 'Ride all');
|
|
assert.equal(await b.evaluate('document.querySelector("#proxy-ride").checkVisibility()'), true, 'the Ride all box is not folded under Technical details');
|
|
assert.equal(await b.evaluate('document.querySelector("#proxy-ride-go").disabled'), false);
|
|
// Ride all adds north. Only a stand-in organization is left: the step moves on to the Triage route, and Move stays offered.
|
|
await b.evaluate(`window.confirm = () => true; Object.assign(window.__scenario, ${JSON.stringify({ '/api/proxy/admin/status': { ...riding, ride: [{ id: 'north', state: 'already' }, { id: 'west', state: 'fixture' }] },
|
|
'POST /api/proxy/admin/ride-all': { body: { added: ['north'], already: [], skipped: [], fixtures: [{ id: 'west' }], receipt: { op: 'ride.all', time: T } } } })})`);
|
|
await b.evaluate('document.querySelector("#proxy-ride-go").click()');
|
|
await wait('document.querySelector("#proxy-setup-go")?.dataset.next==="triage-route"');
|
|
assert.equal(await b.evaluate('document.querySelector("[data-ride-move=west]").checkVisibility()'), true);
|
|
assert.deepEqual(await b.evaluate('window.__unexpected'), []);
|
|
});
|
|
|
|
test('settings-s1 B4: only the next step has a button; done steps, Fence, Init lock and the service controls sit under Technical details', { timeout: 90000 }, async t => {
|
|
const { f, b, wait } = await w15Fixture(t, { scenario: { ...scenario(running), ...answering(0), '/api/triage/route': savedRoute } });
|
|
await b.navigate(f.base + '/#/settings/model-proxy');
|
|
await wait('document.querySelector("#proxy-setup-go")?.dataset.next==="accounts"');
|
|
assert.deepEqual(await b.evaluate(`${visible('#proxy-setup button')}.map(e=>e.id||e.textContent)`), ['proxy-setup-go'], 'one visible button in the setup panel');
|
|
assert.equal(await b.evaluate('document.querySelector("#proxy-setup-init-box").checkVisibility()'), false, 'init is done, so its form is gone');
|
|
const tech = await b.evaluate('(()=>{const d=document.querySelector("#proxy-setup-tech");return {summary:d.querySelector("summary").textContent,open:d.open,terms:[...d.querySelectorAll("dt")].map(x=>x.textContent),units:d.querySelectorAll("[data-unit]").length,receipts:!!d.querySelector("#proxy-setup-receipts")}})()');
|
|
assert.deepEqual(tech, { summary: 'Technical details', open: false, terms: ['Release', 'Initialized', 'Service', 'Fence', 'Init lock'], units: 4, receipts: true });
|
|
assert.equal(await b.evaluate(`${visible('#proxy-setup dt, #proxy-setup [data-unit]')}.length`), 0, 'nothing technical shows until it is opened');
|
|
// Technical details opens by keyboard and shows the controls.
|
|
await b.evaluate('document.querySelector("#proxy-setup-tech summary").focus()');
|
|
await b.key('Enter', 'Enter');
|
|
await wait('document.querySelector("#proxy-setup-tech").open');
|
|
assert.equal(await b.evaluate(`${visible('#proxy-setup [data-unit]')}.length`), 4);
|
|
});
|