Compare commits
9
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5a7e6765f8 | ||
|
|
69b3931c35 | ||
|
|
b7116be9c3 | ||
|
|
0f3135e36a | ||
|
|
b0dd4d3e2f | ||
|
|
e8c6c7e3a4 | ||
|
|
fe671844ea | ||
|
|
b3eaa8fd81 | ||
|
|
07baa87381 |
No files matched your search
@@ -108,7 +108,7 @@ export class ProxyPage {
|
||||
rows.push({ ...view(this.#providers, key.auth_index, provider, status, key.priority ?? group.priority), source: 'apikey', groupIndex, keyIndex, models: configured.map(m => m.alias || m.name) });
|
||||
}
|
||||
}
|
||||
return { rows, groups };
|
||||
return { rows, groups, credentialNames: response.files.map(row => row?.name).filter(identifier) };
|
||||
}
|
||||
#public(row) {
|
||||
const { accountId, provider, displayName, status, priority } = row;
|
||||
@@ -271,13 +271,13 @@ export class ProxyPage {
|
||||
fields(args, ['accountId', 'confirm']);
|
||||
if (typeof args.accountId !== 'string' || !/^[a-f0-9]{12}$/.test(args.accountId) || args.confirm !== true) refuse('invalid-request');
|
||||
return this.#write(async () => {
|
||||
const { rows, groups } = await this.#accounts();
|
||||
const { rows, groups, credentialNames } = await this.#accounts();
|
||||
const original = this.#lock ? structuredClone(groups) : null;
|
||||
const matches = rows.filter(row => row.accountId === args.accountId);
|
||||
if (matches.length !== 1) refuse('invalid-request');
|
||||
const row = matches[0];
|
||||
// The DELETE names a credential file; another listed account on the same name would go too.
|
||||
if (row.source === 'oauth' && rows.some(r => r !== row && r.source === 'oauth' && r.name === row.name)) refuse('invalid-request');
|
||||
if (row.source === 'oauth' && credentialNames.filter(name => name === row.name).length !== 1) refuse('invalid-request');
|
||||
if (this.#lock && !isDeepStrictEqual(await this.#client.getUpstreamGroups(), original)) refuse('proxy-down');
|
||||
this.#beforeMutation('proxy.account.remove');
|
||||
try {
|
||||
|
||||
@@ -223,6 +223,14 @@ test('remove: two listed accounts on one credential name, or one account id list
|
||||
await assert.rejects(d.call('proxy.account.remove', { accountId: id('oauth-one.json'), confirm: true }), { code: 'invalid-request' });
|
||||
for (const x of [s, d]) { assert.equal(x.state.calls.some(c => !c.startsWith('GET ')), false); assert.equal(x.state.files.length, 2); }
|
||||
});
|
||||
test('remove: a credential with an unusable id still prevents deleting its shared name', async t => {
|
||||
for (const badId of ['', null, 'x'.repeat(513)]) {
|
||||
const s = await fakeManagement(t, { files: [oauth(), oauth({ id: badId, name: 'oauth-one.json' })] });
|
||||
await assert.rejects(s.call('proxy.account.remove', { accountId: id('oauth-one.json'), confirm: true }), { code: 'invalid-request' });
|
||||
assert.equal(s.state.calls.some(c => !c.startsWith('GET ')), false);
|
||||
assert.equal(s.state.files.length, 2);
|
||||
}
|
||||
});
|
||||
test('remove: under the lock, key groups that change between the read and the write refuse with proxy-down before the fence', async t => {
|
||||
const fs = await import('node:fs'); const { join } = await import('node:path'); const { tmpdir } = await import('node:os');
|
||||
const { createProxyLock } = await import('../src/proxy-lock.mjs');
|
||||
|
||||
@@ -157,20 +157,25 @@ export function offeredControl({ dataRoot, riders, receipt, exclusive, rootAgent
|
||||
try { list = await riders(); } catch { throw failure('outcome-unknown'); }
|
||||
const named = (Array.isArray(list) ? list : []).filter(r => typeof r?.id === 'string' && ORG_ID.test(r.id));
|
||||
const riding = named.filter(r => r.cliproxy === true);
|
||||
if (!riding.length) throw failure('not-configured');
|
||||
const unanswered = new Set(named.filter(r => typeof r.cliproxy !== 'boolean').map(r => r.id));
|
||||
if (!riding.length) throw failure(unanswered.size ? 'proxy-down' : 'not-configured');
|
||||
let root;
|
||||
try { root = typeof rootAgents === 'function' ? await rootAgents() : undefined; } catch { root = undefined; }
|
||||
const answers = await Promise.all(riding.map(async r => {
|
||||
let routes = null, named = null;
|
||||
try { routes = await r.call('routes'); } catch { routes = null; }
|
||||
try { named = typeof r.file === 'function' ? modelsNamed((await r.file())?.document) : null; } catch { named = null; }
|
||||
let routes = null, named = null, noLaunchReply = false, document = null;
|
||||
try { routes = await r.call('routes'); } catch (error) { noLaunchReply = error?.code === 'launch-not-configured'; }
|
||||
try { document = typeof r.file === 'function' ? (await r.file())?.document : null; named = modelsNamed(document); } catch { named = null; }
|
||||
// A separate file read can observe a newer launch than the bus did. Treat that race and
|
||||
// unreadable files as unknown, never as proof that no model is in use.
|
||||
const noLaunch = noLaunchReply && named !== null && !Object.hasOwn(document, 'launch');
|
||||
const fromRoot = root === undefined ? null : rootModelsNamed(root, r.id);
|
||||
return { id: r.id, routes, named: named && fromRoot ? [...named, ...fromRoot] : null };
|
||||
return { id: r.id, routes, noLaunch, named: named && fromRoot ? [...named, ...fromRoot] : null };
|
||||
}));
|
||||
const providers = new Map(), usedBy = new Map();
|
||||
let ready = false;
|
||||
for (const { id, routes } of answers) {
|
||||
for (const { id, routes, noLaunch } of answers) {
|
||||
// routes explicitly refuses before reading a catalogue when the organization has no launch.
|
||||
if (noLaunch) continue;
|
||||
const c = routes?.catalogue;
|
||||
if (c?.status !== 'ready' || !Array.isArray(c.models)) { unanswered.add(id); continue; }
|
||||
ready = true;
|
||||
@@ -181,8 +186,9 @@ export function offeredControl({ dataRoot, riders, receipt, exclusive, rootAgent
|
||||
if (!providers.get(provider).includes(m.model)) providers.get(provider).push(m.model);
|
||||
}
|
||||
}
|
||||
if (!ready) throw failure('proxy-down');
|
||||
for (const { id, routes, named } of answers) {
|
||||
if (!ready) throw failure(!unanswered.size && answers.every(a => a.noLaunch) ? 'not-configured' : 'proxy-down');
|
||||
for (const { id, routes, named, noLaunch } of answers) {
|
||||
if (noLaunch) continue;
|
||||
if (!routes || typeof routes.instances !== 'object' || routes.instances === null || named === null) { unanswered.add(id); continue; }
|
||||
const table = routes.providerModels && typeof routes.providerModels === 'object' ? routes.providerModels : {};
|
||||
const legacy = routes.catalogue?.legacy && typeof routes.catalogue.legacy === 'object' ? routes.catalogue.legacy : {};
|
||||
|
||||
@@ -114,6 +114,38 @@ test('an organization whose usage is unknown (its file unreadable, its bus down,
|
||||
}
|
||||
});
|
||||
|
||||
test('a riding organization explicitly without launch is answered, while a bus failure remains unanswered', async t => {
|
||||
const noLaunch = { ...rider('bolt', []), call: async () => { throw Object.assign(new Error('no launch'), { code: 'launch-not-configured' }); } };
|
||||
const down = { ...rider('crux', []), call: async () => { throw new Error('down'); } };
|
||||
const c = control(t, { riders: [rider('acme', [entry('zai', 'glm-5')]), noLaunch, down] });
|
||||
assert.deepEqual((await c.models({ seed: true })).unanswered, ['crux']);
|
||||
const onlyAnswered = control(t, { riders: [rider('acme', [entry('zai', 'glm-5')]), noLaunch] });
|
||||
const view = await onlyAnswered.models({ seed: true });
|
||||
assert.deepEqual(view.unanswered, []);
|
||||
assert.equal(existsSync(offeredFile(onlyAnswered.dataRoot)), true);
|
||||
await onlyAnswered.modelsSet({ provider: 'z.ai', on: [], revision: view.revision });
|
||||
});
|
||||
|
||||
test('a no-launch response with a newer launch or unreadable file stays unanswered and blocks an unconfirmed switch off', async t => {
|
||||
const noLaunch = async () => { throw Object.assign(new Error('no launch'), { code: 'launch-not-configured' }); };
|
||||
for (const file of [async () => ({ document: { launch: { models: {} }, roles: {} } }), async () => { throw new Error('unreadable'); }, async () => ({ document: null })]) {
|
||||
const c = control(t, { riders: [rider('acme', [entry('zai', 'glm-5')]), { ...rider('bolt', []), call: noLaunch, file }] });
|
||||
const view = await c.models({ seed: true });
|
||||
assert.deepEqual(view.unanswered, ['bolt']);
|
||||
assert.equal(existsSync(offeredFile(c.dataRoot)), false);
|
||||
await assert.rejects(c.modelsSet({ provider: 'z.ai', on: [], revision: view.revision }), { code: 'models-in-use' });
|
||||
}
|
||||
});
|
||||
|
||||
test('all riders confirmed without launch are not configured; a failed read is proxy-down', async t => {
|
||||
const noLaunch = { ...rider('bolt', []), call: async () => { throw Object.assign(new Error('no launch'), { code: 'launch-not-configured' }); } };
|
||||
const configured = control(t, { riders: [noLaunch] });
|
||||
await assert.rejects(configured.models({ seed: true }), { code: 'not-configured' });
|
||||
assert.equal(existsSync(offeredFile(configured.dataRoot)), false);
|
||||
const down = control(t, { riders: [{ ...noLaunch, file: async () => { throw new Error('unreadable'); } }] });
|
||||
await assert.rejects(down.models({ seed: true }), { code: 'proxy-down' });
|
||||
});
|
||||
|
||||
test('in use counts every place the organization file names a model and the root agents it takes: project agents, root copies; not an excluded or assistant root agent, not launch.models itself', async t => {
|
||||
const models = [entry('zai', 'glm-5'), entry('zai', 'glm-4.6'), entry('codex', 'gpt-5'), entry('codex', 'gpt-5-mini')];
|
||||
const routes = { instances: { chief: { model: 'g5' } }, providerModels: { g5: entry('zai', 'glm-5'), g46: entry('zai', 'glm-4.6'), gpt: entry('codex', 'gpt-5'), mini: entry('codex', 'gpt-5-mini') } };
|
||||
@@ -166,6 +198,9 @@ test(`a model kept on while its account is signed out counts against the ${MAX_O
|
||||
// glm-0 is in use and this switches it off, but the list is too long first: no ask for a save that cannot be written.
|
||||
await assert.rejects(c.modelsSet({ provider: 'z.ai', on: all.slice(1), revision: before.revision }), { code: 'models-invalid' }, `${all.length - 1} on plus 10 kept is past ${MAX_ON}`);
|
||||
await assert.rejects(c.modelsSet({ provider: 'z.ai', on: all.slice(1), revision: before.revision, confirmInUse: true }), { code: 'models-invalid' });
|
||||
// Exactly 257 including the 10 kept models must refuse before asking about glm-0.
|
||||
assert.equal(all.slice(6).length + away.length, MAX_ON + 1);
|
||||
await assert.rejects(c.modelsSet({ provider: 'z.ai', on: all.slice(6), revision: before.revision }), { code: 'models-invalid' });
|
||||
assert.equal(readOffered(c.dataRoot).revision, before.revision);
|
||||
assert.deepEqual(c.receipts, []);
|
||||
const saved = await c.modelsSet({ provider: 'z.ai', on: all.slice(7), revision: before.revision, confirmInUse: true });
|
||||
@@ -228,6 +263,7 @@ test('a damaged file: the read and the write answer outcome-unknown and write no
|
||||
test('no organization riding is not-configured; none answering a ready catalogue is proxy-down; a busy lock refuses the write', async t => {
|
||||
await assert.rejects(control(t, { riders: [] }).models(), { code: 'not-configured' });
|
||||
await assert.rejects(control(t, { riders: [{ ...rider('acme', []), cliproxy: false }] }).models(), { code: 'not-configured' });
|
||||
await assert.rejects(control(t, { riders: [{ ...rider('acme', []), cliproxy: undefined }] }).models(), { code: 'proxy-down' });
|
||||
const down = { id: 'acme', cliproxy: true, call: async () => { throw new Error('down'); } };
|
||||
await assert.rejects(control(t, { riders: [down, rider('bolt', [], { catalogue: { status: 'unavailable', models: [] } })] }).models(), { code: 'proxy-down' });
|
||||
await assert.rejects(control(t, { riders: [rider('acme', [entry('zai', 'glm-5')])], busy: true }).modelsSet({ provider: 'z.ai', on: [], revision: 'a'.repeat(16) }), { code: 'proxy-admin-busy' });
|
||||
|
||||
@@ -767,7 +767,7 @@ if (document.documentElement.hasAttribute('data-settings-proxy-document') && !lo
|
||||
'proxy-uncertain': 'Mosaic could not confirm the remove: the model service is between writes. Check the service and the list before trying again.',
|
||||
'proxy-down': 'The model service stopped answering, so Mosaic could not confirm the remove. Check the service and the list before trying again.',
|
||||
'proxy-admin-busy': 'Another setup action is running. Try again when it finishes.',
|
||||
'invalid-request': 'The model service no longer lists this account. Read the accounts again.',
|
||||
'invalid-request': 'Mosaic could not identify one account to remove. It may no longer be listed, have a duplicate ID, or share a credential with another account. Read the accounts again.',
|
||||
'human-required': 'Only the instance owner removes an account.',
|
||||
};
|
||||
async function adminCall(path, args) {
|
||||
@@ -812,8 +812,10 @@ if (document.documentElement.hasAttribute('data-settings-proxy-document') && !lo
|
||||
removeBusy = true; removeAsk.error = null; paintAccounts();
|
||||
try {
|
||||
await adminCall('accounts/remove', { accountId: account.accountId });
|
||||
removeAsk = null; message(`${name} account removed.`);
|
||||
await refresh(); await setup.reread();
|
||||
let removalMessage = `${name} account removed.`;
|
||||
removeAsk = null; message(removalMessage);
|
||||
try { await refresh(); } catch (error) { removalMessage += ` The account list could not be refreshed: ${error.message}`; message(removalMessage); }
|
||||
await setup.reread({ onError: error => message(`${removalMessage} The setup status could not be refreshed: ${error.message}`) });
|
||||
} catch (error) {
|
||||
if (removeAsk) removeAsk.error = error.message; message(error.message);
|
||||
// The outcome may be unknown: read the list again so it shows what the service holds now.
|
||||
@@ -936,7 +938,7 @@ if (document.documentElement.hasAttribute('data-settings-proxy-document') && !lo
|
||||
'models-offered-conflict': 'The model list changed since this page read it. Read it again, then make your change.',
|
||||
'models-invalid': 'The model service no longer lists one of these models. Read the list again.',
|
||||
'proxy-down': 'No organization that uses your model service answered, so its models can\'t be listed now.',
|
||||
'not-configured': 'No organization uses your model service yet. Its models show here once one does.',
|
||||
'not-configured': 'No organization with a configured model launch uses your model service yet. Its models show here once one does.',
|
||||
'proxy-admin-busy': 'Another change to the model service is running. Try again in a moment.',
|
||||
'outcome-unknown': 'The outcome is unknown. Read the list again before you try again.',
|
||||
};
|
||||
@@ -953,8 +955,10 @@ if (document.documentElement.hasAttribute('data-settings-proxy-document') && !lo
|
||||
catch (error) { if (round === offeredRound) box.replaceChildren(el('p', offeredSays(error.code), 'small muted')); return; }
|
||||
if (round !== offeredRound) return;
|
||||
const providers = Array.isArray(view?.providers) ? view.providers : [];
|
||||
if (!providers.length) { box.replaceChildren(el('p', 'Your model service lists no models yet.', 'small muted')); return; }
|
||||
box.replaceChildren(...providers.map(p => offeredList(p, view.revision, open.has(p.provider), saved === p.provider)));
|
||||
const quiet = Array.isArray(view?.unanswered) ? view.unanswered.filter(id => typeof id === 'string').map(id => window.MosaicOrg?.row?.(id)?.label || id) : [];
|
||||
const notice = quiet.length ? [el('p', `Not answering now, so it is not known which models they use: ${quiet.join(', ')}. A model you switch off may stop working for them.`, 'offered-unanswered banner ref')] : [];
|
||||
if (!providers.length) { box.replaceChildren(...notice, el('p', 'Your model service lists no models yet.', 'small muted')); return; }
|
||||
box.replaceChildren(...notice, ...providers.map(p => offeredList(p, view.revision, open.has(p.provider), saved === p.provider)));
|
||||
}
|
||||
function offeredList(p, revision, open, saved) {
|
||||
const name = String(p.label), models = Array.isArray(p.models) ? p.models : [];
|
||||
@@ -1900,10 +1904,10 @@ if (document.documentElement.hasAttribute('data-settings-proxy-document') && !lo
|
||||
focusStep();
|
||||
}
|
||||
// True once the answer is painted, so a caller can say the list on the page is the new one.
|
||||
async function load() {
|
||||
async function load({ onError } = {}) {
|
||||
if (!enabled || loading) return false; loading = true; let painted = false;
|
||||
try { state = await admin('status'); setProviders(state.providers); causeRound++; if (state.next?.[0] === 'accounts' && triageSet === null) await readTriage(); paint(); painted = true; if (state.init.initialized) await accountsReady(); }
|
||||
catch (error) { say(error.message, 'error'); if (providerKey === null) setProviders(null); }
|
||||
catch (error) { say(error.message, 'error'); if (providerKey === null) setProviders(null); onError?.(error); }
|
||||
finally { loading = false; }
|
||||
return painted;
|
||||
}
|
||||
@@ -1978,7 +1982,7 @@ if (document.documentElement.hasAttribute('data-settings-proxy-document') && !lo
|
||||
start(config) { enabled = true; sendOk = config.proxyAdminSend === true; return load(); },
|
||||
accounts(n) { accountCount = n; if (state) { paintService(); paintRestart(); paintOrgsCard(); paintTriageCard(); } },
|
||||
// A sign-in, a key or a restart can change the next step: read the whole status again.
|
||||
async reread() { if (!enabled) return; triageSet = null; await load(); },
|
||||
async reread(options) { if (!enabled) return; triageSet = null; await load(options); },
|
||||
enabled: () => enabled,
|
||||
serviceDone: () => running(),
|
||||
// An organization whose model list is ready, for Models offered. The open one first.
|
||||
|
||||
@@ -62,21 +62,29 @@
|
||||
}
|
||||
// E2E6 P1-1, P2-2: a poll reloads the list but keeps the open preview, the project picked for each
|
||||
// pack and the last receipt. A kept preview applies by its digest, so a stale one is refused by the bus.
|
||||
// Each organization has one state object for the life of the page. A click keeps a reference to it
|
||||
// across its own request, so a load that ends meanwhile updates the read fields in place and never
|
||||
// swaps the object: the click's preview or receipt lands where the next draw reads it. A load that
|
||||
// began before the last applied one carries older reads, so its answer is dropped.
|
||||
async function load(org) {
|
||||
const prev = states.get(org);
|
||||
const s = { packs: null, applied: [], writable: false, error: null, projects: null, preview: prev?.preview ?? null, status: prev?.status ?? '', picks: prev?.picks ?? {} };
|
||||
if (!states.has(org)) states.set(org, { packs: null, applied: [], writable: false, error: 'Starter packs could not be read.', projects: null, preview: null, status: '', picks: {}, began: 0, shown: 0 });
|
||||
const s = states.get(org);
|
||||
const began = ++s.began;
|
||||
const read = { packs: null, applied: [], writable: false, error: null, projects: null };
|
||||
try {
|
||||
const value = await call(`${base(org)}/packs`);
|
||||
s.packs = Array.isArray(value?.packs) ? value.packs.filter(p => p && typeof p === 'object' && p.pack && typeof p.pack === 'object') : [];
|
||||
s.applied = Array.isArray(value?.applied) ? value.applied.filter(a => plainObj(a) && typeof a.id === 'string' && Array.isArray(a.hired) && Array.isArray(a.open)) : [];
|
||||
s.writable = value?.writable === true;
|
||||
} catch (error) { s.error = error.message; }
|
||||
read.packs = Array.isArray(value?.packs) ? value.packs.filter(p => p && typeof p === 'object' && p.pack && typeof p.pack === 'object') : [];
|
||||
read.applied = Array.isArray(value?.applied) ? value.applied.filter(a => plainObj(a) && typeof a.id === 'string' && Array.isArray(a.hired) && Array.isArray(a.open)) : [];
|
||||
read.writable = value?.writable === true;
|
||||
} catch (error) { read.error = error.message; }
|
||||
// A project pack needs a code project. The workflow read lists them; when it fails, a project pack
|
||||
// says so instead of guessing.
|
||||
if (s.packs?.some(p => p.pack.scope === 'project')) {
|
||||
try { const w = await call(`${base(org)}/workflows`); s.projects = w && typeof w.projects === 'object' ? Object.keys(w.projects).sort() : null; } catch { s.projects = null; }
|
||||
if (read.packs?.some(p => p.pack.scope === 'project')) {
|
||||
try { const w = await call(`${base(org)}/workflows`); read.projects = w && typeof w.projects === 'object' ? Object.keys(w.projects).sort() : null; } catch { read.projects = null; }
|
||||
}
|
||||
states.set(org, s);
|
||||
if (began < s.shown) return;
|
||||
s.shown = began;
|
||||
Object.assign(s, read);
|
||||
}
|
||||
const markText = m => MARKS[m] ?? m;
|
||||
function itemRow(item) {
|
||||
|
||||
@@ -35,7 +35,23 @@ const PREVIEW = {
|
||||
skills: { notEnabled: ['lint-fix'] }, chief: true, plan: {}, digest: REV('d'),
|
||||
};
|
||||
|
||||
async function fixture(t, { send = true } = {}) {
|
||||
// hold(verb) makes the next read of that verb wait: its answer is computed when the read arrives, then
|
||||
// held until release(). arrived resolves when the read has arrived.
|
||||
function holds() {
|
||||
const pending = new Map();
|
||||
return {
|
||||
hold(verb) {
|
||||
const h = {};
|
||||
h.arrived = new Promise(r => { h.reached = r; });
|
||||
h.wait = new Promise(r => { h.release = r; });
|
||||
pending.set(verb, [...(pending.get(verb) ?? []), h]);
|
||||
return h;
|
||||
},
|
||||
take: verb => pending.get(verb)?.shift(),
|
||||
};
|
||||
}
|
||||
|
||||
async function fixture(t, { send = true, gates = null, packs = () => PACKS } = {}) {
|
||||
const verbs = [];
|
||||
let flows = {
|
||||
revision: REV('a'),
|
||||
@@ -48,13 +64,18 @@ async function fixture(t, { send = true } = {}) {
|
||||
},
|
||||
templates: ['coder', 'reviewer'],
|
||||
};
|
||||
const read = async (verb, args) => {
|
||||
verbs.push([verb, args]);
|
||||
if (verb === 'packs.console') return { packs: PACKS };
|
||||
const answer = (verb, args) => {
|
||||
if (verb === 'packs.console') return { packs: packs() };
|
||||
if (verb === 'pack.preview.console') return { ...PREVIEW, project: args.project ?? null };
|
||||
if (verb === 'autonomy.get.console') return { revision: REV('e'), autonomy: {}, levels: {} };
|
||||
throw Object.assign(new Error('not-configured'), { code: 'not-configured' });
|
||||
};
|
||||
const read = async (verb, args) => {
|
||||
verbs.push([verb, args]);
|
||||
const value = answer(verb, args), held = gates?.take(verb);
|
||||
if (held) { held.reached(); await held.wait; }
|
||||
return value;
|
||||
};
|
||||
const write = async (verb, args) => {
|
||||
verbs.push([verb, args]);
|
||||
if (verb === 'pack.apply.console') return { revision: REV('f'), added: ['board', 'definitions.reviewer'], pack: { id: args.pack, version: '1.0.0' }, hires: [{ name: 'lead-reviewer', state: 'refused', code: 'definition-not-hireable' }] };
|
||||
@@ -128,6 +149,85 @@ test('SP6 pack picker: list, preview with marks, flagged, credential and noHire
|
||||
assert.deepEqual(verbs.filter(([v]) => v === 'pack.preview.console').at(-1)[1], { pack: 'web-project', project: 'site' });
|
||||
});
|
||||
|
||||
// The page reads the packs again on a poll and after any write that changes the organization
|
||||
// (mosaic-org-changed). A preview the owner asked for must survive a reload that overlaps it, in either
|
||||
// order, and an older reload that answers last must not put its older list back.
|
||||
const reload = b => b.evaluate(`document.dispatchEvent(new CustomEvent('mosaic-org-changed',{detail:{org:'acme'}}));true`);
|
||||
const markDrawn = b => b.evaluate(`document.querySelector('[data-packs]').dataset.drawn='before';true`);
|
||||
const redrawn = (b, what) => waitFor(b, `document.querySelector('[data-packs]') && !document.querySelector('[data-packs]').dataset.drawn`, what);
|
||||
|
||||
test('SP6 pack picker: a preview that overlaps a reload of the packs is kept, in either order', { timeout: 60000 }, async t => {
|
||||
const gates = holds();
|
||||
const { b, verbs } = await fixture(t, { gates });
|
||||
await waitFor(b, `document.querySelector('[data-pack="software-team"] [data-pack-preview-button]')`, 'pack list');
|
||||
// The reload's packs read starts first and answers after the preview has been drawn.
|
||||
const list = gates.hold('packs.console');
|
||||
await reload(b);
|
||||
await list.arrived;
|
||||
await b.evaluate(`document.querySelector('[data-pack="software-team"] [data-pack-preview-button]').click();true`);
|
||||
await waitFor(b, `document.querySelector('[data-pack-preview="software-team"]')`, 'preview');
|
||||
await markDrawn(b);
|
||||
list.release();
|
||||
await redrawn(b, 'page drawn again after the reload');
|
||||
assert.ok(await b.evaluate(`!!document.querySelector('[data-pack-preview="software-team"]')`), 'the reload kept the preview');
|
||||
// The preview's read starts first and answers after the reload has drawn the page.
|
||||
const preview = gates.hold('pack.preview.console');
|
||||
await b.evaluate(`document.querySelector('[data-pack="web-project"] [data-pack-preview-button]').click();true`);
|
||||
await preview.arrived;
|
||||
await markDrawn(b);
|
||||
await reload(b);
|
||||
await redrawn(b, 'page drawn again during the preview');
|
||||
preview.release();
|
||||
await waitFor(b, `/for project site/.test(document.querySelector('[data-pack-preview] h4')?.textContent??'')`, 'project preview after the reload');
|
||||
assert.deepEqual(verbs.filter(([v]) => v === 'pack.preview.console').map(([, a]) => a), [{ pack: 'software-team' }, { pack: 'web-project', project: 'site' }]);
|
||||
});
|
||||
|
||||
// Count each packs answer once the reading load has used it. With no project pack listed the load has
|
||||
// no further read, so a task queued after the answer runs after the load's last step.
|
||||
const countPacksAnswers = b => b.evaluate(`{const f=window.fetch;window.__packsDone=0;window.fetch=async(...a)=>{const r=await f(...a);if(String(a[0]).endsWith('/api/orgs/acme/packs')){const j=r.json.bind(r);r.json=()=>j().finally(()=>setTimeout(()=>{window.__packsDone++}))}return r}}true`);
|
||||
|
||||
test('SP6 pack picker: an older read of the packs that answers last does not replace a newer one', { timeout: 60000 }, async t => {
|
||||
const gates = holds();
|
||||
let packs = [PACKS[0]];
|
||||
const { b } = await fixture(t, { gates, packs: () => packs });
|
||||
await waitFor(b, `document.querySelector('[data-pack="software-team"] [data-pack-preview-button]')`, 'pack list');
|
||||
await countPacksAnswers(b);
|
||||
const older = gates.hold('packs.console');
|
||||
await reload(b);
|
||||
await older.arrived;
|
||||
packs = [PACKS[0], { id: 'later', origin: 'installed', pack: { label: 'Later pack', description: 'Installed after the first read.', version: '0.1.0', scope: 'organization' } }];
|
||||
await reload(b);
|
||||
await waitFor(b, `document.querySelector('[data-pack="later"]') && window.__packsDone===1`, 'newer list drawn');
|
||||
older.release();
|
||||
await waitFor(b, `window.__packsDone===2`, 'older read answered');
|
||||
assert.match(await b.evaluate(`window.MosaicPacks.section('acme')`), /data-pack="later"/, 'the older list was not put back');
|
||||
await b.evaluate(`document.querySelector('[data-pack="software-team"] [data-pack-preview-button]').click();true`);
|
||||
await waitFor(b, `document.querySelector('[data-pack-preview="software-team"]')`, 'preview');
|
||||
assert.ok(await b.evaluate(`!!document.querySelector('[data-pack="later"]')`), 'the drawn list is the newer one');
|
||||
});
|
||||
|
||||
test('SP6 pack picker: an apply receipt that lands while an earlier read of the packs is held is kept', { timeout: 60000 }, async t => {
|
||||
const gates = holds();
|
||||
const { b, verbs } = await fixture(t, { gates, packs: () => [PACKS[0]] });
|
||||
await waitFor(b, `document.querySelector('[data-pack="software-team"] [data-pack-preview-button]')`, 'pack list');
|
||||
await b.evaluate(`document.querySelector('[data-pack="software-team"] [data-pack-preview-button]').click();true`);
|
||||
await waitFor(b, `document.querySelector('[data-pack-apply]')`, 'preview');
|
||||
await countPacksAnswers(b);
|
||||
// A reload's packs read is held. The apply answers, reads the packs itself and asks the page to read
|
||||
// everything again; both of those reads answer first. Then the held read answers last.
|
||||
const earlier = gates.hold('packs.console');
|
||||
await reload(b);
|
||||
await earlier.arrived;
|
||||
await b.evaluate(`document.querySelector('[data-pack-apply]').click();true`);
|
||||
await waitFor(b, `/^Applied\./.test(document.querySelector('[data-packs-status]')?.textContent??'') && window.__packsDone===2`, 'apply status');
|
||||
assert.equal(verbs.filter(([v]) => v === 'pack.apply.console').length, 1);
|
||||
earlier.release();
|
||||
await waitFor(b, `window.__packsDone===3`, 'held read answered');
|
||||
const drawn = await b.evaluate(`window.MosaicPacks.section('acme')`);
|
||||
assert.match(drawn, /data-packs-status>Applied\. Added board, definitions\.reviewer\./, 'the receipt is kept');
|
||||
assert.doesNotMatch(drawn, /data-pack-preview=/, 'the applied preview does not come back');
|
||||
});
|
||||
|
||||
test('SP6 pack picker without send previews but offers no apply', { timeout: 60000 }, async t => {
|
||||
const { b } = await fixture(t, { send: false });
|
||||
await waitFor(b, `document.querySelector('[data-pack="software-team"] [data-pack-preview-button]')`, 'pack list');
|
||||
|
||||
@@ -89,12 +89,53 @@ test('account-remove: Remove posts exactly { accountId }, reads the list again a
|
||||
assert.deepEqual(await b.evaluate('window.__unexpected'), []);
|
||||
});
|
||||
|
||||
test('account-remove: a failed refresh after a successful remove keeps the success and the refresh error', { timeout: 90000 }, async t => {
|
||||
const { b, wait } = await open(t, { extra: { [impactKey(A)]: { body: IMPACT_ALL },
|
||||
'POST /api/proxy/admin/accounts/remove': { body: { accountId: A, provider: 'claude', removed: true } } } });
|
||||
await b.evaluate(`document.querySelector('[data-remove="${A}"]').click(); true`);
|
||||
await wait('!!document.querySelector("#proxy-remove-yes")');
|
||||
await b.evaluate(`window.__scenario['GET /api/proxy/accounts'] = { status: 503, body: { error: 'proxy-down' } }; document.querySelector('#proxy-remove-yes').click(); true`);
|
||||
await wait('document.querySelector("#proxy-message").textContent.includes("not answering")');
|
||||
assert.equal(await b.evaluate('document.querySelector("#proxy-message").textContent'), 'Claude account removed. The account list could not be refreshed: The model service is not answering.');
|
||||
assert.equal((await writes(b)).length, 1);
|
||||
});
|
||||
|
||||
test('account-remove: a failed setup status refresh remains visible beside successful removal', { timeout: 90000 }, async t => {
|
||||
const { b, wait } = await open(t, { extra: { [impactKey(A)]: { body: IMPACT_ALL },
|
||||
'POST /api/proxy/admin/accounts/remove': { body: { accountId: A, provider: 'claude', removed: true } } } });
|
||||
await b.evaluate(`document.querySelector('[data-remove="${A}"]').click(); true`);
|
||||
await wait('!!document.querySelector("#proxy-remove-yes")');
|
||||
await b.evaluate(`window.__scenario['GET /api/proxy/admin/status'] = { status: 503, body: { error: 'outcome-unknown' } }; document.querySelector('#proxy-remove-yes').click(); true`);
|
||||
await wait('document.querySelector("#proxy-setup-message").textContent.length > 0');
|
||||
assert.match(await b.evaluate('document.querySelector("#proxy-message").textContent'), /^Claude account removed\..*setup status could not be refreshed/i);
|
||||
assert.equal((await writes(b)).length, 1);
|
||||
});
|
||||
|
||||
test('account-remove: a late setup warning keeps the removal receipt when priority is saved meanwhile', { timeout: 90000 }, async t => {
|
||||
const { b, wait } = await open(t, { extra: { [impactKey(A)]: { body: IMPACT_ALL },
|
||||
'POST /api/proxy/admin/accounts/remove': { body: { accountId: A, provider: 'claude', removed: true } },
|
||||
'POST /api/proxy/priority/set': { body: { accountId: B, priority: 0 } } } });
|
||||
await b.evaluate(`document.querySelector('[data-remove="${A}"]').click(); true`);
|
||||
await wait('!!document.querySelector("#proxy-remove-yes")');
|
||||
await b.evaluate(`(() => { const real = window.fetch; window.__held = false; window.fetch = (input, init) => {
|
||||
if (String(input) === '/api/proxy/admin/status') { window.__held = true; return new Promise(resolve => { window.__releaseStatus = () => resolve(new Response(JSON.stringify({ error: 'outcome-unknown' }), { status: 503, headers: { 'Content-Type': 'application/json' } })); }); }
|
||||
return real(input, init); }; window.__scenario['GET /api/proxy/accounts'] = { body: { accounts: ${JSON.stringify(LIST.slice(1))} } }; document.querySelector('#proxy-remove-yes').click(); return true; })()`);
|
||||
await wait('window.__held');
|
||||
await b.evaluate('document.querySelector("#proxy-order form").requestSubmit(); true');
|
||||
await wait('document.querySelector("#proxy-message").textContent === "Priority saved."');
|
||||
await b.evaluate('window.__releaseStatus(); true');
|
||||
await wait('document.querySelector("#proxy-message").textContent.includes("setup status could not be refreshed")');
|
||||
assert.match(await b.evaluate('document.querySelector("#proxy-message").textContent'), /^Claude account removed\./);
|
||||
assert.equal(await b.evaluate('document.querySelector("#proxy-order [role=status]").textContent'), 'Priority saved.');
|
||||
});
|
||||
|
||||
test('account-remove: remove-write-refused and remove-unconfirmed are named in the ask and the account stays', { timeout: 90000 }, async t => {
|
||||
// No refusal says nothing was removed: a refused or unanswered write may still have taken effect.
|
||||
for (const [code, words] of [['remove-write-refused', 'The model service refused to remove the account. Check the list before trying again.'],
|
||||
['remove-unconfirmed', 'Mosaic asked the model service to remove the account, but it is still listed. Read the accounts again before trying again.'],
|
||||
['proxy-uncertain', 'Mosaic could not confirm the remove: the model service is between writes. Check the service and the list before trying again.'],
|
||||
['proxy-down', 'The model service stopped answering, so Mosaic could not confirm the remove. Check the service and the list before trying again.'],
|
||||
['invalid-request', 'Mosaic could not identify one account to remove. It may no longer be listed, have a duplicate ID, or share a credential with another account. Read the accounts again.'],
|
||||
['some-new-code', 'The remove could not be confirmed. Nothing was retried. Read the accounts again before trying again.']]) {
|
||||
const { b, wait } = await open(t, { extra: { [impactKey(A)]: { body: IMPACT_ALL }, 'POST /api/proxy/admin/accounts/remove': { status: 400, body: { error: code } } } });
|
||||
await b.evaluate(`document.querySelector('[data-remove="${A}"]').click(); true`);
|
||||
|
||||
@@ -202,6 +202,14 @@ test('models-offered page: an organization that is not answering is named in the
|
||||
assert.equal((await writes())[1].body.confirmInUse, true);
|
||||
});
|
||||
|
||||
test('models-offered page: unanswered organizations are visible before saving', { timeout: 90000 }, async t => {
|
||||
const { b, wait, writes } = await setup(t, { admin: { models: { ...VIEW, unanswered: ['lab', 'zeta'] } } });
|
||||
await openOffered(b, wait);
|
||||
assert.equal(await b.evaluate('document.querySelector("#proxy-offered-list .offered-unanswered")?.textContent'),
|
||||
'Not answering now, so it is not known which models they use: Lab Bench, zeta. A model you switch off may stop working for them.');
|
||||
assert.deepEqual(await writes(), []);
|
||||
});
|
||||
|
||||
test('models-offered page: a save after another change is refused as a conflict, worded, with Read the list again; a busy or unknown answer is worded too', { timeout: 90000 }, async t => {
|
||||
const conflict = { status: 409, body: { error: 'models-offered-conflict' } };
|
||||
const busy = { status: 409, body: { error: 'proxy-admin-busy' } };
|
||||
@@ -242,7 +250,7 @@ test('models-offered page: a page without proxyAdmin sends no /api/proxy/admin/
|
||||
test('models-offered page: a read the model service cannot answer is worded, never an empty list', { timeout: 90000 }, async t => {
|
||||
for (const [body, line] of [
|
||||
[{ error: 'proxy-down' }, /No organization that uses your model service answered/],
|
||||
[{ error: 'not-configured' }, /No organization uses your model service yet/],
|
||||
[{ error: 'not-configured' }, /No organization with a configured model launch uses your model service yet/],
|
||||
[{ error: 'outcome-unknown' }, /The outcome is unknown/],
|
||||
]) {
|
||||
const { b, wait } = await setup(t, { admin: { models: { status: 503, body } } });
|
||||
|
||||
Reference in new issue
Block a user