From 66255c9bf217ffff46cceff6e21ff1933e01e1b1 Mon Sep 17 00:00:00 2001 From: Jason Woltje Date: Thu, 19 Nov 2026 19:50:32 -0600 Subject: [PATCH] feat(webui): settings-s5: an organization's Models page offers its one choice, "Where gets its models": Use your models (the cliproxy model-provider module, written through plugins.set after a fresh read, refused when the page is stale or a route draft is open) or Use its own model service, dashed, disabled and badged Coming later; the page says from the plugins read which one is in force and what a switch changes, Stop using your models is the way back, a refusal keeps the read's choice, a failed read offers Read again, and while the organization needs a restart its banner's Restart is the one primary and the choice waits; the sidebar marks read the status again after a switch; tests for slice 5 and the slice 4 items, red on 524132b42 except the no-Details control case (#1873, lane settings-s5) --- packages/webui/src/public/bus.js | 63 +++- packages/webui/src/public/shell.css | 12 + packages/webui/tests/routes-browser.test.mjs | 17 +- .../webui/tests/settings-s5-browser.test.mjs | 297 ++++++++++++++++++ 4 files changed, 369 insertions(+), 20 deletions(-) create mode 100644 packages/webui/tests/settings-s5-browser.test.mjs diff --git a/packages/webui/src/public/bus.js b/packages/webui/src/public/bus.js index 71d97d3ba..e948d8940 100644 --- a/packages/webui/src/public/bus.js +++ b/packages/webui/src/public/bus.js @@ -1306,6 +1306,9 @@ } const routesApplyMarkup=()=>routesApply?.length?``:''; let harnessSettings=null, harnessDraft=null, harnessLoading=false, harnessReceipt='', harnessBusy=false; + // #1873 settings slice 5: the organization's one choice, Use your models (the cliproxy module in + // its model-provider list, from the plugins read above) or its own model service (Coming later). + let modelsReceipt='', modelsReceiptKind='', modelsBusy=false; function readHarnesses(){ if(harnessLoading || harnessSettings !== null || !canSend || isTester)return; harnessLoading=true;const epoch=orgEpoch; fetch('/api/proxy/plugins',{cache:'no-store',redirect:'manual'}).then(async r=>{const v=await r.json();if(epoch!==orgEpoch)return;if(!r.ok || !/^[a-f0-9]{64}$/.test(v.revision??'') || !Array.isArray(v.available?.harness) || !v.available.harness.every(n=>typeof n==='string') || !Array.isArray(v.plugins?.harness??[]))throw Error();harnessSettings=v;}).catch(()=>{if(epoch!==orgEpoch)return;harnessSettings=false;harnessReceipt='Harnesses could not be read.';}).finally(()=>{if(epoch!==orgEpoch)return;harnessLoading=false;if(routeOf().split('?')[0]==='/settings/routing')render(false);}); @@ -1352,11 +1355,32 @@ if(owner&&serviceState==='not-running')return `

${lead} The model service is not running. ${setupLink('Open Model setup')}. ${thinking}

${words}`; if(owner&&(serviceLoading||(serviceState===null&&triageOwner)))return `

${lead} Checking the model service. ${thinking}

`; if(owner&&serviceState===false)return ``; - return `

${lead}${plain} ${thinking}${owner?' A new model needs the model service: ask the instance owner to set it up, or press Stop using the model service when this organization does not need it.':''}

${words}`; + return `

${lead}${plain} ${thinking}${owner?' A new model needs the model service: ask the instance owner to set it up, or press Stop using your models when this organization does not need it.':''}

${words}`; } // Check again rereads Routing; the bus looks for the model service at that read. A draft is kept. document.addEventListener('click',e=>{if(e.target.id!=='routes-recheck')return;e.target.disabled=true;serviceState=null;routesView=null;last.delete('routes');render(true);}); document.addEventListener('mosaic-org-restarted',e=>{if(e.detail?.id!==window.MosaicOrg?.id)return;serviceState=null;routesView=null;last.delete('routes');const path=routeOf().split('?')[0];if(path==='/settings/routing'||document.querySelector('[data-org-down]'))render(true);}); + // The choice reads only the plugins read: before it answers the radios wait, and a failed read + // says so with Read again. Use your models writes at once; Stop using your models is the way back. + // While the organization needs a restart, its banner's Restart is the one primary and the choice waits. + const modelsWho=()=>window.MosaicOrg?(window.MosaicOrg.label||window.MosaicOrg.id):'This business'; + const modelsWhose=()=>window.MosaicOrg?`${modelsWho()}'s`:"This business's"; + function modelsChoice(restartFirst){ + const who=txt(modelsWho()), whose=txt(modelsWhose()); + const names=harnessSettings&&Array.isArray(harnessSettings.plugins?.['model-provider'])?harnessSettings.plugins['model-provider']:[]; + const read=!!harnessSettings, on=read&&names.includes('cliproxy'), wait=!read||modelsBusy||restartFirst||out(); + const now=harnessSettings===false?`Which models ${who} uses could not be read.`:!read?`Reading ${whose} models…`:on?`Now: ${who} uses your models.`:`Now: ${who} does not use your models. Its agents use only the models in its own organization file.`; + const change=!read?'':restartFirst?`

You can change ${whose} models after it restarts.

` + :on?`

Its agents can use the models your accounts offer. To switch back, press Stop using your models. A route on one of your models then stops working until you change it.

` + :`

Choose Use your models to switch. ${whose} agents can then use the models your accounts offer. While your model service is down, a launch that needs it is refused. A running agent keeps its model until it starts again.

`; + const stop=on?``:''; + const again=harnessSettings===false?'':''; + return `
Where ${who} gets its models` + +`` + +`` + +`

${now}

${change}

${stop}${again}

` + +`

${txt(modelsReceipt)}

`; + } function routesSection(view,instanceInfo){ const title='

Routing

'; readHarnesses(); @@ -1388,7 +1412,7 @@ // settings-p3 (re-check 3 P3-5): a ready catalogue the bus picked up late says agents start on these // models after a restart; that notice gets the organization's Restart (not primary: Save routes is). const catalogueInfo=v.catalogue?.status==='ready'?`

Model catalogue, observed ${txt(window.MosaicLocalTime(v.catalogue.observedAt))}.

${(v.catalogue.notices??[]).map(n=>`

${txt(n)}${n===window.MosaicConsole?.RESTART_TO_LAUNCH&&window.MosaicOrg?.id?` ${window.MosaicConsole.orgRestartButton(window.MosaicOrg.id,{name:window.MosaicOrg.label||window.MosaicOrg.id})}`:''}

`).join('')}`:v.catalogue?.status==='unavailable'?catalogueLine(proxyOn,v.catalogue):'

Model catalogue not enabled.

'; - const providerControl=canSend&&!isTester?`

`:''; + const providerControl=canSend&&!isTester?modelsChoice(/ data-primary[ >]/.test(catalogueInfo)):''; const harnessControl=canSend&&!isTester?`
Harnesses${harnessSettings ? [...new Set([...harnessSettings.available.harness,...(harnessSettings.plugins.harness??[])])].map(name=>``).join('')+` ` : '

Harnesses unavailable.

'}

${txt(harnessReceipt)}

`:''; const off=v.harnesses.length?'':'

No harness is switched on for this organization, so every launch is refused, and so is a save that changes a harness. Switch one on under Harnesses.

'; return `
${title}${catalogueInfo}${providerControl}${harnessControl}${off}
${ROUTE_CELLS.map(([,l])=>``).join('')}${rows}
AgentPrimaryFallback
${l.replace('Fallback ','')}

${canSend || isTester?'Changes are checked and logged with your identity.':'Saving requires signed-in send mode.'}

${txt(routesReceipt)}

${routesApplyMarkup()}
`; @@ -1416,7 +1440,7 @@ const moved=Object.entries(routes).flatMap(([name,r])=>{const was=routesView?.instances?.[name]??{}; return [[r.harness,r.model,was.harness,was.model],[r.fallback?.harness,r.fallback?.model,was.fallback?.harness,was.fallback?.model]].filter(([h,m,wh,wm])=>m&&(h!==wh||m!==wm)).map(([,m])=>m);}); const module=key=>routesView?.providerModels?.[key]?.module; - return moved.length&&moved.every(key=>module(key)&&module(key)!=='cliproxy'&&names.includes(module(key)))?' This change does not need the model service: press Stop using the model service, then save again.':''; + return moved.length&&moved.every(key=>module(key)&&module(key)!=='cliproxy'&&names.includes(module(key)))?' This change does not need your models: press Stop using your models, then save again.':''; } const routesAnswer=r=>/^[a-f0-9]{64}$/.test(r?.revision??'')&&Array.isArray(r.harnesses)&&Array.isArray(r.models)&&[r.levels,r.instances].every(o=>o&&typeof o==='object'&&!Array.isArray(o)); for(const kind of ['input','change'])document.addEventListener(kind,e=>{const form=e.target?.closest?.('#routes-form');if(!form||!routesView)return;routesDraft=routesFields(form);routesEditVersion++;markSettingsDraft('routing',true);form.querySelector('.settings-actions')?.classList.add('has-draft');const discard=$('routes-reload');if(discard){discard.hidden=false;discard.disabled=false;} @@ -1436,17 +1460,28 @@ catch{if(epoch!==orgEpoch)return;harnessReceipt='Outcome unknown. Read the harnesses again before trying.';harnessSettings=false;} finally{if(epoch===orgEpoch){harnessBusy=false;if(!out())render(false);}} }); - document.addEventListener('click',async e=>{if(e.target.id!=='provider-switch'||!canSend||isTester)return; - const button=e.target,status=$('provider-switch-status');if(routesDraft){status.textContent='Save or discard the route draft first.';return;}button.disabled=true;const epoch=orgEpoch; - try {const read=await fetch('/api/proxy/plugins',{cache:'no-store'});const settings=await read.json();if(epoch!==orgEpoch)return;if(!read.ok||!/^[a-f0-9]{64}$/.test(settings.revision??''))throw Error('Could not read provider settings.'); - const names=Array.isArray(settings.plugins?.['model-provider'])?settings.plugins['model-provider']:[]; - // The fresh read decides: a stale label never turns the proxy module on when it meant off. - const on=names.includes('cliproxy');if(String(on)!==button.dataset.enabled){button.dataset.enabled=String(on);button.textContent=on?'Stop using the model service':'Use your models';button.disabled=false;status.textContent='The switch now shows the current setting. Press it again to change it.';return;} - const next=on?names.filter(n=>n!=='cliproxy'):[...names,'cliproxy']; + // The fresh read decides: a page that shows a stale choice is redrawn from it and nothing is written. + async function setModels(want){ + if(!canSend||isTester||modelsBusy||!harnessSettings)return; + const who=modelsWho(), shown=(harnessSettings.plugins?.['model-provider']??[]).includes('cliproxy'); + if(routesDraft){modelsReceipt='Save or discard the route draft first.';modelsReceiptKind='banner err';render(false);return;} + modelsBusy=true;modelsReceipt='';modelsReceiptKind='';render(false);const epoch=orgEpoch; + try{const read=await fetch('/api/proxy/plugins',{cache:'no-store',redirect:'manual'});const settings=await read.json();if(epoch!==orgEpoch)return; + if(!read.ok||!/^[a-f0-9]{64}$/.test(settings.revision??'')||!Array.isArray(settings.available?.harness))throw Error('read'); + const names=Array.isArray(settings.plugins?.['model-provider'])?settings.plugins['model-provider']:[], on=names.includes('cliproxy'); + if(on!==shown){harnessSettings=settings;modelsReceipt=`${modelsWhose()} models changed since this page read it. The page now shows the current choice; choose again to change it.`;modelsReceiptKind='banner ref';return;} + if(on===want)return; + const next=want?[...names,'cliproxy']:names.filter(n=>n!=='cliproxy'); const response=await fetch('/api/proxy/plugins/set',{method:'POST',headers:{'content-type':'application/json'},body:JSON.stringify({revision:settings.revision,plugins:{'model-provider':next}}),cache:'no-store',redirect:'manual'}); - if(epoch!==orgEpoch)return;if(!response.ok)throw Error('Provider setting was refused.');harnessSettings=null;routesView=null;last.delete('routes');render(true); - }catch(error){if(epoch!==orgEpoch)return;status.textContent=error.message;button.disabled=false;} - }); + const result=await response.json().catch(()=>({}));if(epoch!==orgEpoch)return; + if(!response.ok){modelsReceipt=`Not changed. ${result.message||result.error||'The change was refused.'}`;modelsReceiptKind='banner err';return;} + modelsReceipt=want?`Saved. ${who} uses your models. An agent picks them up the next time it starts.`:`Saved. ${who} no longer uses your models. An agent on one of them keeps it until it starts again.`;modelsReceiptKind='settings-success'; + harnessSettings=null;routesView=null;last.delete('routes');window.MosaicModelDots?.read?.(); + }catch{if(epoch!==orgEpoch)return;modelsReceipt='Outcome unknown. Read the page again before trying.';modelsReceiptKind='banner ref';harnessSettings=null;} + finally{if(epoch===orgEpoch){modelsBusy=false;if(!out())render(harnessSettings===null);}} + } + document.addEventListener('change',e=>{if(e.target.id==='models-yours'&&e.target.checked)setModels(true);}); + document.addEventListener('click',e=>{if(e.target.closest?.('#models-stop'))setModels(false);else if(e.target.id==='models-read'){harnessSettings=null;harnessReceipt='';modelsReceipt='';modelsReceiptKind='';render(false);}}); document.addEventListener('click',e=>{if(e.target.matches?.('.fallback-toggle'))e.target.closest('tr')?.classList.add('fallback-open');}); document.addEventListener('click',e=>{if(e.target.id!=='routes-reload')return;routesDraft=null;routesView=null;routesReceipt='';routesApply=null;last.delete('routes');render(true);}); document.addEventListener('submit',async e=>{ @@ -1532,6 +1567,7 @@ const notify = typeof n.binding==='string' ? `${txt(n.binding)}` : n.refused ? `Could not be read: ${txt(n.refused)}` : 'None set'; const contents={limits:()=>launchForm(s.launch),routing:()=>routesSection(routes,instances),agents:()=>agentsSection(instances)+agentLevels,assistant:()=>assistantSection(s.launch,names),tokens:()=>tokenLimits(limitRows,limitsRefused)+tokenUsage(usage),names:()=>testerNames(names,instances),about:()=>`
Address
${txt(s.address)||'unknown'}
Release
${txt(s.release)||'unknown'}
Business
${txt(s.business)||none}
Board
${txt(s.board)||'unknown'}
Notifier binding
${notify}
`}; const helpers={limits:'Leave a limit blank for no limit. Zero stops new launches. Running sessions keep running when limits or models change.',routing:"Each agent’s harness, model and thinking, and the fallback a launch takes when the primary harness fails its preflight. A fallback sets all three or none. Running sessions keep their route. The next launch reads the change. A harness is the program that runs the model. Preflight is the check a launch makes before it starts.",agents:'Each agent with its definition, launch membership and runs. A launch refuses until the agent has a route in Routing.',assistant:'The definition stays an assistant one. Holder and credentials stay hand edits.',tokens:'Token limits the bus checks, and token use read from session transcripts.'}; + if(window.MosaicOrg&&!isTester)helpers.routing=`The models ${modelsWhose()} agents use. They come from your accounts in Model setup. ${helpers.routing}`; return settingsShell(page,contents[page](),`${get.oldest()?`Read ${when(get.oldest())}.`: 'Reading…'} ${helpers[page]||''}`); } let settingsFocusDisclosure=false; @@ -2270,6 +2306,7 @@ instanceView = null; instanceDrafts = { add: null, change: null }; instanceReceipt = ''; instanceReceiptOp = null; instanceReceipts = Object.create(null); routesView = null; routesDraft = null; routesReceipt = ''; routesEditVersion++; harnessSettings = null; harnessDraft = null; harnessReceipt = ''; + modelsReceipt = ''; modelsReceiptKind = ''; modelsBusy = false; serviceState = null; serviceLoading = false; // A file draft is keyed by project and path only; the page reload that used to drop it is gone. docKey = null; docStates.clear(); pkAll = []; pkShown = []; pkAt = 0; diff --git a/packages/webui/src/public/shell.css b/packages/webui/src/public/shell.css index aa391ff0e..c84cb2037 100644 --- a/packages/webui/src/public/shell.css +++ b/packages/webui/src/public/shell.css @@ -375,6 +375,18 @@ button:disabled,[aria-disabled=true]{cursor:not-allowed} .settings-content fieldset.harness-control{display:flex;flex-wrap:wrap;align-items:center;gap:6px 12px} .settings-content fieldset.harness-control>legend{flex-basis:100%} .settings-content fieldset.harness-control>:is(button,p){flex-basis:100%} +/* #1873 settings slice 5: an organization's one choice (mockup org-models). A choice not built yet is dashed and disabled. */ +.settings-content fieldset.models-source{display:grid;gap:8px} +.settings-content fieldset.models-source>legend{font-size:14px;color:var(--strong);margin-bottom:8px} +.settings-content fieldset.models-source>p{margin:0} +.choice{display:grid;grid-template-columns:auto 1fr auto;gap:4px 10px;align-items:start;padding:12px;border:1px solid var(--border);border-radius:var(--r);cursor:pointer} +.choice input{margin-top:4px} +.choice:has(input:checked){border-color:var(--action);background:var(--raised)} +.choice:has(input:disabled){cursor:default} +.choice.off{color:var(--muted);cursor:not-allowed;border-style:dashed;background:transparent} +.choice strong{color:var(--strong)}.choice.off strong{color:var(--muted)} +.choice .small{grid-column:2/4;margin:0} +.choice:has(input:focus-visible){outline:2px solid var(--focus);outline-offset:2px} .settings-content :is(.instance-form,.level-form) textarea,.settings-content .assistant-form textarea{display:block;width:100%} .route-definition{display:none}.settings-spinner{display:inline-block;width:16px;height:16px;border:2px solid currentColor;border-right-color:transparent;border-radius:50%;vertical-align:middle;animation:settings-spin .8s linear infinite}@keyframes settings-spin{to{transform:rotate(360deg)}}@media(prefers-reduced-motion:reduce){.settings-spinner{animation:none}} @media(max-width:759px){#routes-table .route-definition{display:inline;float:right;color:var(--muted);font-size:12px;font-weight:400}} diff --git a/packages/webui/tests/routes-browser.test.mjs b/packages/webui/tests/routes-browser.test.mjs index 25e5ce038..d3d16c77b 100644 --- a/packages/webui/tests/routes-browser.test.mjs +++ b/packages/webui/tests/routes-browser.test.mjs @@ -197,8 +197,9 @@ test('Routing switch writes the model-provider setting and keeps other modules', await b.call('Page.addScriptToEvaluateOnNewDocument',{source:`const original=window.fetch;window.posts=[];window.fetch=async(url,options={})=>{if(url==='/api/config')return new Response(JSON.stringify({send:true}));if(url==='/api/proxy/plugins')return new Response(JSON.stringify(${JSON.stringify(settings)}));if(url==='/api/proxy/plugins/set'){posts.push(JSON.parse(options.body));return new Promise(r=>window.answer=(status,body)=>r(new Response(JSON.stringify(body),{status})));}return original(url,options);};`}); await b.navigate(`http://127.0.0.1:${web.address().port}/#/settings/routing`); const wait=expr=>b.evaluate(`(async()=>{for(let n=0;n<200;n++){if(${expr})return true;await new Promise(r=>setTimeout(r,30));}throw Error('wait failed');})()`); - await wait('document.querySelector("#provider-switch")?.textContent.startsWith("Use your models")'); - await b.evaluate('document.querySelector("#provider-switch").click();true'); + // settings-s5: the switch is the Use your models choice; choosing it writes at once. + await wait('document.querySelector("#models-in-force")?.textContent.includes("does not use your models")&&!document.querySelector("#models-yours").disabled'); + await b.evaluate('document.querySelector("#models-yours").click();true'); await wait('posts.length===1');const payload=await b.evaluate('posts[0]'); assert.deepEqual(payload.plugins,{'model-provider':['cliproxy']}); const before=JSON.parse(readFileSync(file,'utf8')).plugins; @@ -271,7 +272,7 @@ test('quick fallback edits survive the harness redraw', {timeout:60000}, async t // organization's catalogue is ready with no proxy, and its switch reads Enable. test('D3 Routing: with cliproxy listed and no model proxy the switch reads Disable and removes cliproxy only; a fixture-only org reads Enable', {timeout:90000}, async t => { for (const [providers, label, line, next] of [ - [['fixture','cliproxy'], 'Stop using the model service', /can't see your models yet\. Your model service isn't set up yet\. A change to thinking alone still saves\. A new model needs the model service: ask the instance owner to set it up, or press Stop using the model service when this organization does not need it\./, ['fixture']], + [['fixture','cliproxy'], 'Stop using your models', /can't see your models yet\. Your model service isn't set up yet\. A change to thinking alone still saves\. A new model needs the model service: ask the instance owner to set it up, or press Stop using your models when this organization does not need it\./, ['fixture']], [['fixture'], 'Use your models', /^Model catalogue, observed /, ['fixture','cliproxy']], ]) { const root=tmp(t,'d3-switch-'), f=fixture(root,'acme',doc=>{doc.plugins['model-provider']=providers;return doc;}); @@ -287,13 +288,15 @@ test('D3 Routing: with cliproxy listed and no model proxy the switch reads Disab await b.call('Page.addScriptToEvaluateOnNewDocument',{source:`const original=window.fetch;window.posts=[];window.fetch=async(url,options={})=>{if(url==='/api/config')return new Response(JSON.stringify({send:true}));if(url==='/api/proxy/plugins')return new Response(JSON.stringify(${JSON.stringify(settings)}));if(url==='/api/proxy/plugins/set'){posts.push(JSON.parse(options.body));return new Promise(r=>window.answer=(status,body)=>r(new Response(JSON.stringify(body),{status})));}return original(url,options);};`}); await b.navigate(`http://127.0.0.1:${web.address().port}/#/settings/routing`); const wait=expr=>b.evaluate(`(async()=>{for(let n=0;n<200;n++){if(${expr})return true;await new Promise(r=>setTimeout(r,30));}throw Error('wait failed');})()`); - await wait(`document.querySelector("#provider-switch")?.textContent.startsWith(${JSON.stringify(label)})&&!!document.querySelector('[data-harness]')`); + // settings-s5: in force, the way back is Stop using your models; not in force, the Use your models choice. + const control=label==='Stop using your models'?'#models-stop':'#models-yours'; + await wait(`!!document.querySelector(${JSON.stringify(control)})&&!document.querySelector(${JSON.stringify(control)}).disabled&&!!document.querySelector('[data-harness]')`); const [info,...notices]=await b.evaluate('[document.querySelector(".routing-panel > p.small")?.textContent,...[...document.querySelectorAll(".routing-panel > p.small.warn")].slice(1).map(p=>p.textContent)]'); assert.match(info,line,providers.join(',')); // proxy-pickup (#1873): the bus's cause reads as a plain line; its own words sit under Technical details. assert.deepEqual(notices,[],providers.join(',')); - assert.deepEqual(await b.evaluate('[...document.querySelectorAll(".routing-panel > details.routes-cause-detail p")].map(p=>p.textContent)'),label==='Stop using the model service'?['The model proxy has not been set up for this instance yet. Set it up on the Model proxy page.']:[],providers.join(',')); - await b.evaluate('document.querySelector("#provider-switch").click();true'); + assert.deepEqual(await b.evaluate('[...document.querySelectorAll(".routing-panel > details.routes-cause-detail p")].map(p=>p.textContent)'),label==='Stop using your models'?['The model proxy has not been set up for this instance yet. Set it up on the Model proxy page.']:[],providers.join(',')); + await b.evaluate(`document.querySelector(${JSON.stringify(control)}).click();true`); await wait('posts.length===1');const payload=await b.evaluate('posts[0]'); assert.deepEqual(payload.plugins,{'model-provider':next},providers.join(',')); const result=await call('plugins.set',payload);await b.evaluate(`window.answer(200,${JSON.stringify(result)});true`); @@ -309,7 +312,7 @@ test('D3 Routing: with cliproxy listed and no model proxy the switch reads Disab test('D3 Routing: a catalogue refusal names Disable only when it can make the save apply, and sends a tester to the owner', {timeout:90000}, async t => { const refusal=code=>({error:code,message:`${code}: the reason. Nothing changed.`,sent:false}); for (const [providers, tester, instance, code, expect] of [ - [['fixture','cliproxy'], false, 'coder', 'model-catalogue-unavailable', /Nothing changed\. This change does not need the model service: press Stop using the model service, then save again\. Draft kept\.$/], + [['fixture','cliproxy'], false, 'coder', 'model-catalogue-unavailable', /Nothing changed\. This change does not need your models: press Stop using your models, then save again\. Draft kept\.$/], [['fixture','cliproxy'], false, 'reviewer', 'model-catalogue-unavailable', /Nothing changed\. Draft kept\.$/], [['fixture'], false, 'reviewer', 'model-provider-unavailable', /Nothing changed\. Draft kept\.$/], [['fixture','cliproxy'], true, 'coder', 'model-catalogue-unavailable', /Nothing changed\. Ask the organization's owner to set up the model service, or to stop using it when the change does not need it\. Draft kept\.$/], diff --git a/packages/webui/tests/settings-s5-browser.test.mjs b/packages/webui/tests/settings-s5-browser.test.mjs new file mode 100644 index 000000000..ef5c50cca --- /dev/null +++ b/packages/webui/tests/settings-s5-browser.test.mjs @@ -0,0 +1,297 @@ +// #1873 settings slice 5 (DESIGN.md 3.4, 12 slice 5, mockups org-models and org-models-restart): an +// organization's Models page offers one choice, "Use your models" (the cliproxy model-provider module +// through plugins.set) or "Use its own model service" (Coming later), says from the plugins read which +// one is in force and what a switch changes, and switches both ways. Also the items slice 4 left: the +// Ride all lines name an organization by its display name, step 3 and the "can't start" mark agree +// before the first account, the sidebar marks follow a switch, a failed turn shows "Details:" once in +// Messages, the old Members addresses land on Agents, and Technical details shows the port and +// timeouts the status read carries. +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'; +import { ReadError } from '../src/reads.mjs'; + +const LIST = [ + { id: 'acme', label: 'Acme Studio', theme: 'cobalt', busHealthy: true }, + { id: 'gamma', label: 'Gamma Home', theme: 'rosewood', busHealthy: false, busStopped: true }, + { id: 'north', label: 'North Works', 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({ routes = {}, messages = [] } = {}) { + 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 () => (org.busHealthy ? { healthy: true, pid: 4242, boot: null } : { healthy: false, boot: { ok: false, at: new Date().toISOString(), lastGood: null, reason: 'stopped by the owner' } }), + 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; + if (!org.busHealthy) return { busHealthy: false, reads: { settings: async () => { throw new ReadError('bus-unavailable'); } }, bus: {}, chat: { projects: empty, threads: empty } }; + 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 }), agents: empty, 'thread.claims': empty, inbox: empty, tasks: empty, usage: async () => ({}), routes: async () => ({ ...VIEW, ...(routes[id] ?? {}), 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' } } }; +} + +// The model service is set up and answering. init.settings is what the status read carries after init +// (model-proxy admin.mjs initState). +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: [] }; +const SERVICE_DOWN = { ...SERVICE_UP, next: ['unit-start'], unit: { ...SERVICE_UP.unit, active: 'inactive', listening: false, healthy: false } }; +const REV = n => String(n).repeat(64).slice(0, 64); +const pluginsRead = providers => ({ revision: REV('b'), available: { harness: ['pi'], 'model-provider': ['fixture', 'cliproxy'] }, plugins: { harness: ['pi'], 'model-provider': providers } }); + +// The instance owner's flags and every model service read and write, by path suffix (display.js +// scopes some reads under /api/orgs//). plugins.set merges the module lists the way the bus does +// and may carry a new setup status (__s5.afterSet). window.confirm answers yes and records its text. +const ownerStub = ({ service = SERVICE_UP, plugins = pluginsRead(['fixture']), accounts = [], posts = {}, afterSet = null, setStatus = 200 } = {}) => `(() => { + const real = window.fetch.bind(window); + window.__s5 = ${JSON.stringify({ service, plugins, accounts, posts, afterSet, setStatus })}; window.__sets = []; window.__writes = []; window.__confirms = []; + window.confirm = text => { window.__confirms.push(text); return true; }; + const json = (body, status = 200) => new Response(JSON.stringify(body), { status, headers: { 'content-type': 'application/json' } }); + window.fetch = async (input, init = {}) => { + const url = new URL(typeof input === 'string' ? input : input.url, location.href), path = url.pathname, method = (init.method || 'GET').toUpperCase(); + if (method !== 'GET' && path.endsWith('/proxy/plugins/set')) { + const body = JSON.parse(init.body); window.__sets.push({ path, body }); + if (__s5.setStatus !== 200) return json({ error: 'plugins-refused', message: 'The bus refused the change (plugins-refused).' }, __s5.setStatus); + __s5.plugins = { ...__s5.plugins, revision: String(__s5.sets = (__s5.sets ?? 0) + 1).repeat(64).slice(0, 64), plugins: { ...__s5.plugins.plugins, ...body.plugins } }; + if (__s5.afterSet) __s5.service = __s5.afterSet; + return json({ revision: __s5.plugins.revision, plugins: __s5.plugins.plugins }); + } + if (method !== 'GET' && /\\/proxy\\//.test(path)) { window.__writes.push(path); const key = Object.keys(__s5.posts).find(k => path.endsWith(k)); const a = key ? __s5.posts[key] : { status: 500, body: { error: 'stub' } }; + if (a.service) __s5.service = a.service; return json(a.body ?? {}, a.status ?? 200); } + 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: true, proxyAdminSend: true, ...(/\\/orgs\\//.test(path) ? { settingsSend: true } : {}) }); } + if (path.endsWith('/proxy/plugins')) return json(__s5.plugins); + if (path.endsWith('/proxy/admin/status')) return json(__s5.service); + if (path.endsWith('/proxy/accounts')) return json({ accounts: __s5.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, viewport = [1440, 900], fixture = {}, stub = {} } = {}) { + const { organizations, agentLevels } = await orgFixture(fixture); + const server = await startServer({ port: 0, sso: createDevOwner(), organizations, agentLevels, triage: null, send: async () => ({}), log: () => {} }); + t.after(() => close(server)); + const b = await browser({ machine: false }); t.after(() => b.close()); + await b.viewport(...viewport); + await b.call('Page.addScriptToEvaluateOnNewDocument', { source: ownerStub(stub) }); + 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; })()`); + return { b, wait, text, click }; +} +const mark = id => `document.querySelector('[data-workspace-org=${id}] .ws-dot')?.title`; +const STEP3 = '#setup-step-organizations [data-step-summary]'; + +// ---- Organization > Models -------------------------------------------------------------------- +test('settings-s5: Acme Studio\'s models reads which choice is in force from the plugins read, switches to your models and back', { timeout: 90000 }, async t => { + const { b, wait, text, click } = await setup(t, { path: '/#/settings/routing?org=acme' }); + await wait('document.querySelector("#models-source") && document.querySelector("#models-in-force")?.textContent.includes("does not use")'); + assert.equal(await text('#settings-page-title'), "Acme Studio's models"); + assert.equal(await text('#models-source legend'), 'Where Acme Studio gets its models'); + assert.match(await text('.settings-helper'), /The models Acme Studio's agents use\. They come from your accounts in Model setup/); + // Not in force: the radio is not checked, and the line says what is in force and what a switch changes. + assert.equal(await b.evaluate('document.querySelector("#models-yours").checked'), false); + assert.equal(await text('#models-in-force'), "Now: Acme Studio does not use your models. Its agents use only the models in its own organization file."); + assert.match(await text('#models-change'), /^Choose Use your models to switch\. Acme Studio's agents can then use the models your accounts offer\./); + // Use its own model service: dashed, disabled, Coming later. + assert.equal(await b.evaluate('document.querySelector("#models-own").disabled'), true); + assert.equal(await b.evaluate('document.querySelector("#models-own").closest("label").classList.contains("off")'), true); + assert.equal(await b.evaluate('document.querySelector("#models-own").closest("label").querySelector(".badge").textContent'), 'Coming later'); + assert.match(await b.evaluate('document.querySelector("#models-own").closest("label").textContent'), /Planned, not built yet, so you can't choose it today\./); + assert.equal(await b.evaluate('getComputedStyle(document.querySelector("#models-own").closest("label")).borderTopStyle'), 'dashed'); + // The old button is gone. + assert.equal(await b.evaluate('!!document.querySelector("#provider-switch")'), false); + + // Switch to your models: one write, the model-provider list only, with cliproxy added. + await click('#models-yours'); + await wait('window.__sets.length === 1'); + assert.deepEqual(await b.evaluate('window.__sets[0].body'), { revision: REV_B, plugins: { 'model-provider': ['fixture', 'cliproxy'] } }); + await wait('document.querySelector("#models-in-force")?.textContent.startsWith("Now: Acme Studio uses your models")'); + assert.equal(await b.evaluate('document.querySelector("#models-yours").checked'), true); + assert.match(await text('#models-receipt'), /^Saved\. Acme Studio uses your models\./); + assert.equal(await b.evaluate('document.querySelector("#models-receipt").classList.contains("settings-success")'), true); + assert.match(await text('#models-change'), /Stop using your models/); + + // And back: Stop using your models removes cliproxy and keeps the other module. + await click('#models-stop'); + await wait('window.__sets.length === 2'); + assert.deepEqual(await b.evaluate('window.__sets[1].body.plugins'), { 'model-provider': ['fixture'] }); + await wait('document.querySelector("#models-in-force")?.textContent.includes("does not use your models")'); + assert.equal(await b.evaluate('document.querySelector("#models-yours").checked'), false); + assert.match(await text('#models-receipt'), /^Saved\. Acme Studio no longer uses your models\./); + assert.equal(await b.evaluate('!!document.querySelector("#models-stop")'), false); +}); +const REV_B = REV('b'); + +test('settings-s5: a refused switch says so and the page keeps the choice the read shows', { timeout: 90000 }, async t => { + const { b, wait, text, click } = await setup(t, { path: '/#/settings/routing?org=acme', stub: { setStatus: 409 } }); + await wait('document.querySelector("#models-in-force")?.textContent.includes("does not use")'); + await click('#models-yours'); + await wait('window.__sets.length === 1 && /refused/.test(document.querySelector("#models-receipt")?.textContent ?? "")'); + assert.equal(await text('#models-receipt'), 'Not changed. The bus refused the change (plugins-refused).'); + assert.equal(await b.evaluate('document.querySelector("#models-yours").checked'), false); + assert.match(await text('#models-in-force'), /does not use your models/); +}); + +test('settings-s5: a stale page does not write, it shows the current choice first', { timeout: 90000 }, async t => { + const { b, wait, click } = await setup(t, { path: '/#/settings/routing?org=acme' }); + await wait('document.querySelector("#models-in-force")?.textContent.includes("does not use")'); + // Someone else switched Acme Studio on since the page read it. + await b.evaluate('__s5.plugins = { ...__s5.plugins, plugins: { ...__s5.plugins.plugins, "model-provider": ["fixture", "cliproxy"] } }; true'); + await click('#models-yours'); + await wait('document.querySelector("#models-in-force")?.textContent.startsWith("Now: Acme Studio uses your models")'); + assert.equal(await b.evaluate('window.__sets.length'), 0); + assert.match(await b.evaluate('document.querySelector("#models-receipt").textContent'), /changed since this page read it/); +}); + +test('settings-s5: while the plugins read is out the choice waits, and a failed read says so with Read again', { timeout: 90000 }, async t => { + const { b, wait, text } = await setup(t, { path: '/#/settings/routing?org=acme', stub: { plugins: { broken: true } } }); + await wait('/could not be read/.test(document.querySelector("#models-in-force")?.textContent ?? "")'); + assert.equal(await text('#models-in-force'), "Which models Acme Studio uses could not be read."); + assert.equal(await b.evaluate('document.querySelector("#models-yours").disabled'), true); + assert.equal(await b.evaluate('!!document.querySelector("#models-read")'), true); +}); + +test('settings-s5: an organization that needs a restart shows the banner with Restart as the one primary, and the choice waits', { timeout: 90000 }, async t => { + const routes = { acme: { catalogue: { status: 'unavailable', notices: [], models: [] } } }; + const { b, wait, text } = await setup(t, { path: '/#/settings/routing?org=acme', fixture: { routes }, stub: { plugins: pluginsRead(['fixture', 'cliproxy']) } }); + await wait('document.querySelector("#routes-catalogue.banner [data-primary]") && document.querySelector("#models-in-force")?.textContent.startsWith("Now: Acme Studio uses")'); + assert.match(await text('#routes-catalogue'), /Acme Studio can't see your models yet\./); + assert.match(await text('#routes-catalogue [data-primary]'), /Restart Acme Studio/); + // The banner sits above the choice. + assert.equal(await b.evaluate('!!(document.querySelector("#routes-catalogue").compareDocumentPosition(document.querySelector("#models-source")) & Node.DOCUMENT_POSITION_FOLLOWING)'), true); + assert.equal(await b.evaluate('document.querySelector("#models-yours").checked && document.querySelector("#models-yours").disabled'), true); + assert.equal(await text('#models-wait'), "You can change Acme Studio's models after it restarts."); + // One primary: the routes Save is quiet. + assert.equal(await b.evaluate('document.querySelector("#routes-form [type=submit]").classList.contains("route-save-quiet")'), true); +}); + +test('settings-s5: at 390 the Models page does not scroll sideways and the choice takes a visible focus', { timeout: 90000 }, async t => { + const { b, wait } = await setup(t, { path: '/#/settings/routing?org=acme', viewport: [390, 844] }); + await wait('document.querySelector("#models-in-force")?.textContent.includes("does not use")'); + assert.equal(await b.evaluate('document.documentElement.scrollWidth <= document.documentElement.clientWidth'), true); + await b.evaluate('document.querySelector("#models-yours").focus(); true'); + assert.notEqual(await b.evaluate('getComputedStyle(document.activeElement).outlineStyle'), 'none'); +}); + +// ---- Sidebar marks follow a switch ------------------------------------------------------------- +test('settings-s5: the sidebar marks read the setup status again after an organization stops using your models', { timeout: 90000 }, async t => { + const paused = { ...SERVICE_DOWN, ride: [{ id: 'acme', state: 'already' }] }; + const after = { ...SERVICE_DOWN, ride: [{ id: 'acme', state: 'removed' }] }; + const { wait, click } = await setup(t, { path: '/#/settings/routing?org=acme', stub: { service: paused, plugins: pluginsRead(['fixture', 'cliproxy']), afterSet: after } }); + await wait(`${mark('acme')} === 'paused' && document.querySelector("#models-stop")`); + await click('#models-stop'); + await wait(`window.__sets.length === 1 && ${mark('acme')} === 'bus running'`); +}); + +// ---- Model setup: display names, step 3 and the mark ------------------------------------------ +test('settings-s5: Move, its result and the skipped lines name the organization by its display name, in the Ride line\'s words', { timeout: 90000 }, async t => { + const service = { ...SERVICE_UP, organizations: [{ id: 'acme', proxy: 'shared', catalogue: { status: 'ready' } }], + ride: [{ id: 'acme', state: 'already' }, { id: 'north', state: 'bus-down' }, { id: 'gamma', state: 'fixture', running: false }] }; + const moved = { ...service, ride: [{ id: 'acme', state: 'already' }, { id: 'north', state: 'bus-down' }, { id: 'gamma', state: 'already' }] }; + const accounts = [{ accountId: 'a1', provider: 'claude', displayName: 'Claude work', status: 'active', priority: 1 }]; + const { b, wait, text, click } = await setup(t, { path: '/#/settings/model-setup', stub: { service, accounts, posts: { '/admin/ride-move': { body: { moved: true, model: 'Claude Sonnet 5.5', receipt: { op: 'ride-move', time: '2026-11-19T10:00:00.000Z' } }, service: moved } } } }); + await wait('document.querySelector("[data-ride-move=gamma]")'); + assert.equal(await text('#proxy-ride-skips li'), 'Skipped North Works: Its bus is not running. Start it, then ride again.'); + const item = await b.evaluate('document.querySelector("#proxy-ride-fixtures li").firstChild.textContent.trim()'); + assert.equal(item, "Gamma Home can't start: it uses stand-in models and its bus is stopped. Move it to your models under Use your models in every organization, then start its bus."); + // Step 3 uses the same words. + assert.match(await text(STEP3), /Gamma Home can't start: it uses stand-in models and its bus is stopped\. Move it to your models under Use your models in every organization, then start its bus\./); + await click('[data-ride-move=gamma]'); + await wait('window.__confirms.length === 1'); + assert.match(await b.evaluate('window.__confirms[0]'), /^Move Gamma Home to your models\?/); + await wait('/now uses/.test(document.querySelector("#proxy-ride-message")?.textContent ?? "")'); + assert.equal(await text('#proxy-ride-message'), 'Gamma Home now uses Claude Sonnet 5.5. Start its bus when you are ready. It spends real tokens from now on.'); +}); + +test('settings-s5: a Move that is refused names the organization by its display name', { timeout: 90000 }, async t => { + const service = { ...SERVICE_UP, ride: [{ id: 'gamma', state: 'fixture', running: false }] }; + const accounts = [{ accountId: 'a1', provider: 'claude', displayName: 'Claude work', status: 'active', priority: 1 }]; + const { wait, text, click } = await setup(t, { path: '/#/settings/model-setup', stub: { service, accounts, posts: { '/admin/ride-move': { body: { moved: false, reason: 'bus-down' } } } } }); + await wait('document.querySelector("[data-ride-move=gamma]")'); + await click('[data-ride-move=gamma]'); + await wait('/not moved/.test(document.querySelector("#proxy-ride-message")?.textContent ?? "")'); + assert.equal(await text('#proxy-ride-message'), 'Gamma Home was not moved. Its bus is not running. Start it, then ride again.'); +}); + +test('settings-s5: before the first account, step 3 names the organization the sidebar marks "can\'t start"', { timeout: 90000 }, async t => { + const service = { ...SERVICE_UP, ride: [{ id: 'gamma', state: 'fixture', running: false }] }; + const { b, wait, text } = await setup(t, { path: '/#/settings/model-setup', stub: { service, accounts: [] } }); + await wait(`${mark('gamma')} === "can't start" && document.querySelector("#setup-step-organizations")?.dataset.state`); + await wait(`/Gamma Home/.test(document.querySelector(${JSON.stringify(STEP3)})?.textContent ?? "")`); + assert.equal(await text(STEP3), "Opens after your first account. Gamma Home can't start now: it uses stand-in models and its bus is stopped. After your first account, move it to your models under Use your models in every organization, then start its bus."); + // The card stays closed until there is an account to move it with, and its badge carries the mark's word. + assert.equal(await b.evaluate('document.querySelector("#setup-step-organizations").dataset.state'), 'wait'); + assert.equal(await text('#setup-step-organizations [data-step-badge]'), "Can't start"); + assert.equal(await b.evaluate('document.querySelector("#setup-step-organizations [data-step-badge]").classList.contains("badge-danger")'), true); +}); + +test('settings-s5: Technical details and Advanced show the port and timeouts the status read carries', { timeout: 90000 }, async t => { + const { b, wait } = await setup(t, { path: '/#/settings/model-setup' }); + await wait('document.querySelector("#proxy-setup-state dd")'); + const rows = await b.evaluate('Object.fromEntries([...document.querySelectorAll("#proxy-setup-state dt")].map(dt => [dt.textContent, dt.nextElementSibling.textContent]))'); + assert.equal(rows.Initialized, 'Yes, port 18432, wait for a first answer 90 seconds, old key kept 30 minutes after a new one'); + const advanced = await b.evaluate('Object.fromEntries([...document.querySelectorAll("#proxy-setup-settings dt")].map(dt => [dt.textContent, dt.nextElementSibling.textContent]))'); + assert.deepEqual(advanced, { Port: '18432', 'Wait for a first answer': '90 seconds', 'Old key kept after a new one': '30 minutes' }); +}); + +test('settings-s5: timeouts init left at the default read as the default', { timeout: 90000 }, async t => { + const service = { ...SERVICE_UP, init: { ...SERVICE_UP.init, settings: { port: 18432, rotateGraceMinutes: null, firstOutputSeconds: null } } }; + const { b, wait } = await setup(t, { path: '/#/settings/model-setup', stub: { service } }); + await wait('document.querySelector("#proxy-setup-state dd")'); + assert.equal(await b.evaluate('[...document.querySelectorAll("#proxy-setup-state dt")].find(dt => dt.textContent === "Initialized").nextElementSibling.textContent'), + 'Yes, port 18432, wait for a first answer: the default, old key kept after a new one: the default'); + const advanced = await b.evaluate('Object.fromEntries([...document.querySelectorAll("#proxy-setup-settings dt")].map(dt => [dt.textContent, dt.nextElementSibling.textContent]))'); + assert.deepEqual(advanced, { Port: '18432', 'Wait for a first answer': 'The default', 'Old key kept after a new one': 'The default' }); +}); + +// ---- Messages and the old Members addresses --------------------------------------------------- +test('settings-s5: a failed turn in Messages shows its cause, and "Details:" once', { timeout: 90000 }, async t => { + const messages = [{ id: 'm1', from_role: 'chief', to_role: 'human', class: 'reply', at: '2026-11-19T10:00:00.000Z', read: true, + body: 'The turn failed: Acme Studio can\'t see your models yet. Restart it in Settings.\nDetails: model-catalogue-unavailable' }]; + const { b, wait } = await setup(t, { path: '/#/orgs/acme/messages', fixture: { messages } }); + await wait('document.querySelector(".s1-message")'); + const shown = await b.evaluate('document.querySelector(".s1-message").textContent'); + assert.equal(shown.match(/Details:/g)?.length, 1, shown); + assert.match(shown, /^The assistant couldn't reply: Acme Studio can't see your models yet\. Restart it in Settings\.Details: model-catalogue-unavailable$/); +}); + +test('settings-s5: a failed turn without a Details part keeps the general line', { timeout: 90000 }, async t => { + const messages = [{ id: 'm1', from_role: 'chief', to_role: 'human', class: 'reply', at: '2026-11-19T10:00:00.000Z', read: true, body: 'The turn failed: spawn-refused' }]; + const { b, wait } = await setup(t, { path: '/#/orgs/acme/messages', fixture: { messages } }); + await wait('document.querySelector(".s1-message")'); + assert.equal(await b.evaluate('document.querySelector(".s1-message").textContent'), "The assistant couldn't reply. Try again, or check Agents.Details: spawn-refused"); +}); + +test('settings-s5: #/settings/members and #/orgs//settings/members land on that organization\'s Agents page', { timeout: 90000 }, async t => { + const { b, wait } = await setup(t, { path: '/#/orgs/north/settings/members' }); + await wait('location.hash === "#/settings/agents?org=north" && document.querySelector("#settings-nav a[href=\'#/settings/agents?org=north\'][aria-current=page]")'); + await b.evaluate('location.hash = "#/settings/members"; true'); + await wait('location.hash === "#/settings/agents?org=north" && document.querySelector("#settings-page-title")?.textContent === "Agents"'); +});